1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2014, Samsung Electronics Co. Ltd. All Rights Reserved.
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"
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
28 spd
->buffer
= kmalloc(indio_dev
->scan_bytes
, GFP_KERNEL
| GFP_DMA
);
32 return ssp_enable_sensor(data
, spd
->type
,
33 ssp_get_sensor_delay(data
, spd
->type
));
35 EXPORT_SYMBOL(ssp_common_buffer_postenable
);
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
)
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
);
58 EXPORT_SYMBOL(ssp_common_buffer_postdisable
);
61 * ssp_common_process_data() - Common process data callback for ssp sensors
63 * @indio_dev: iio device
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
)
74 int64_t calculated_time
= 0;
75 struct ssp_sensor_data
*spd
= iio_priv(indio_dev
);
77 if (indio_dev
->scan_bytes
== 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
);
88 timestamp
+ (int64_t)le32_to_cpu(time
) * 1000000;
91 return iio_push_to_buffers_with_timestamp(indio_dev
, spd
->buffer
,
94 EXPORT_SYMBOL(ssp_common_process_data
);
96 MODULE_AUTHOR("Karol Wrona <k.wrona@samsung.com>");
97 MODULE_DESCRIPTION("Samsung sensorhub commons");
98 MODULE_LICENSE("GPL");