0001
0002
0003
0004
0005
0006 #include <linux/iio/common/ssp_sensors.h>
0007 #include <linux/iio/buffer.h>
0008 #include <linux/iio/kfifo_buf.h>
0009 #include <linux/module.h>
0010 #include <linux/slab.h>
0011 #include "ssp_iio_sensor.h"
0012
0013
0014
0015
0016
0017
0018
0019
0020 int ssp_common_buffer_postenable(struct iio_dev *indio_dev)
0021 {
0022 struct ssp_sensor_data *spd = iio_priv(indio_dev);
0023 struct ssp_data *data = dev_get_drvdata(indio_dev->dev.parent->parent);
0024
0025
0026
0027
0028 spd->buffer = kmalloc(indio_dev->scan_bytes, GFP_KERNEL | GFP_DMA);
0029 if (!spd->buffer)
0030 return -ENOMEM;
0031
0032 return ssp_enable_sensor(data, spd->type,
0033 ssp_get_sensor_delay(data, spd->type));
0034 }
0035 EXPORT_SYMBOL_NS(ssp_common_buffer_postenable, IIO_SSP_SENSORS);
0036
0037
0038
0039
0040
0041
0042
0043
0044 int ssp_common_buffer_postdisable(struct iio_dev *indio_dev)
0045 {
0046 int ret;
0047 struct ssp_sensor_data *spd = iio_priv(indio_dev);
0048 struct ssp_data *data = dev_get_drvdata(indio_dev->dev.parent->parent);
0049
0050 ret = ssp_disable_sensor(data, spd->type);
0051 if (ret < 0)
0052 return ret;
0053
0054 kfree(spd->buffer);
0055
0056 return ret;
0057 }
0058 EXPORT_SYMBOL_NS(ssp_common_buffer_postdisable, IIO_SSP_SENSORS);
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070 int ssp_common_process_data(struct iio_dev *indio_dev, void *buf,
0071 unsigned int len, int64_t timestamp)
0072 {
0073 __le32 time;
0074 int64_t calculated_time = 0;
0075 struct ssp_sensor_data *spd = iio_priv(indio_dev);
0076
0077 if (indio_dev->scan_bytes == 0)
0078 return 0;
0079
0080
0081
0082
0083 memcpy(spd->buffer, buf, len);
0084
0085 if (indio_dev->scan_timestamp) {
0086 memcpy(&time, &((char *)buf)[len], SSP_TIME_SIZE);
0087 calculated_time =
0088 timestamp + (int64_t)le32_to_cpu(time) * 1000000;
0089 }
0090
0091 return iio_push_to_buffers_with_timestamp(indio_dev, spd->buffer,
0092 calculated_time);
0093 }
0094 EXPORT_SYMBOL_NS(ssp_common_process_data, IIO_SSP_SENSORS);
0095
0096 MODULE_AUTHOR("Karol Wrona <k.wrona@samsung.com>");
0097 MODULE_DESCRIPTION("Samsung sensorhub commons");
0098 MODULE_LICENSE("GPL");
0099 MODULE_IMPORT_NS(IIO_SSP_SENSORS);