module: Convert symbol namespace to string literal
[linux.git] / drivers / iio / common / ssp_sensors / ssp_iio.c
blobcaa404edd9d045859a4f39bed5b8d70715770430
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2014, Samsung Electronics Co. Ltd. All Rights Reserved.
4 */
6 #include <linux/iio/common/ssp_sensors.h>
7 #include <linux/iio/buffer.h>
8 #include <linux/iio/kfifo_buf.h>
9 #include <linux/module.h>
10 #include <linux/slab.h>
11 #include "ssp_iio_sensor.h"
13 /**
14 * ssp_common_buffer_postenable() - generic postenable callback for ssp buffer
16 * @indio_dev: iio device
18 * Returns 0 or negative value in case of error
20 int ssp_common_buffer_postenable(struct iio_dev *indio_dev)
22 struct ssp_sensor_data *spd = iio_priv(indio_dev);
23 struct ssp_data *data = dev_get_drvdata(indio_dev->dev.parent->parent);
25 /* the allocation is made in post because scan size is known in this
26 * moment
27 * */
28 spd->buffer = kmalloc(indio_dev->scan_bytes, GFP_KERNEL | GFP_DMA);
29 if (!spd->buffer)
30 return -ENOMEM;
32 return ssp_enable_sensor(data, spd->type,
33 ssp_get_sensor_delay(data, spd->type));
35 EXPORT_SYMBOL_NS(ssp_common_buffer_postenable, "IIO_SSP_SENSORS");
37 /**
38 * ssp_common_buffer_postdisable() - generic postdisable callback for ssp buffer
40 * @indio_dev: iio device
42 * Returns 0 or negative value in case of error
44 int ssp_common_buffer_postdisable(struct iio_dev *indio_dev)
46 int ret;
47 struct ssp_sensor_data *spd = iio_priv(indio_dev);
48 struct ssp_data *data = dev_get_drvdata(indio_dev->dev.parent->parent);
50 ret = ssp_disable_sensor(data, spd->type);
51 if (ret < 0)
52 return ret;
54 kfree(spd->buffer);
56 return ret;
58 EXPORT_SYMBOL_NS(ssp_common_buffer_postdisable, "IIO_SSP_SENSORS");
60 /**
61 * ssp_common_process_data() - Common process data callback for ssp sensors
63 * @indio_dev: iio device
64 * @buf: source buffer
65 * @len: sensor data length
66 * @timestamp: system timestamp
68 * Returns 0 or negative value in case of error
70 int ssp_common_process_data(struct iio_dev *indio_dev, void *buf,
71 unsigned int len, int64_t timestamp)
73 __le32 time;
74 int64_t calculated_time = 0;
75 struct ssp_sensor_data *spd = iio_priv(indio_dev);
77 if (indio_dev->scan_bytes == 0)
78 return 0;
81 * it always sends full set of samples, remember about available masks
83 memcpy(spd->buffer, buf, len);
85 if (indio_dev->scan_timestamp) {
86 memcpy(&time, &((char *)buf)[len], SSP_TIME_SIZE);
87 calculated_time =
88 timestamp + (int64_t)le32_to_cpu(time) * 1000000;
91 return iio_push_to_buffers_with_timestamp(indio_dev, spd->buffer,
92 calculated_time);
94 EXPORT_SYMBOL_NS(ssp_common_process_data, "IIO_SSP_SENSORS");
96 MODULE_AUTHOR("Karol Wrona <k.wrona@samsung.com>");
97 MODULE_DESCRIPTION("Samsung sensorhub commons");
98 MODULE_LICENSE("GPL");
99 MODULE_IMPORT_NS("IIO_SSP_SENSORS");