staging: rtl8188eu: rename HalSetBrateCfg() - style
[linux/fpc-iii.git] / drivers / iio / common / ssp_sensors / ssp_iio.c
blob645f2e3975db45e7edc1a3640ba600c39b64b1ea
1 /*
2 * Copyright (C) 2014, Samsung Electronics Co. Ltd. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
16 #include <linux/iio/common/ssp_sensors.h>
17 #include <linux/iio/buffer.h>
18 #include <linux/iio/kfifo_buf.h>
19 #include <linux/module.h>
20 #include <linux/slab.h>
21 #include "ssp_iio_sensor.h"
23 /**
24 * ssp_common_buffer_postenable() - generic postenable callback for ssp buffer
26 * @indio_dev: iio device
28 * Returns 0 or negative value in case of error
30 int ssp_common_buffer_postenable(struct iio_dev *indio_dev)
32 struct ssp_sensor_data *spd = iio_priv(indio_dev);
33 struct ssp_data *data = dev_get_drvdata(indio_dev->dev.parent->parent);
35 /* the allocation is made in post because scan size is known in this
36 * moment
37 * */
38 spd->buffer = kmalloc(indio_dev->scan_bytes, GFP_KERNEL | GFP_DMA);
39 if (!spd->buffer)
40 return -ENOMEM;
42 return ssp_enable_sensor(data, spd->type,
43 ssp_get_sensor_delay(data, spd->type));
45 EXPORT_SYMBOL(ssp_common_buffer_postenable);
47 /**
48 * ssp_common_buffer_postdisable() - generic postdisable callback for ssp buffer
50 * @indio_dev: iio device
52 * Returns 0 or negative value in case of error
54 int ssp_common_buffer_postdisable(struct iio_dev *indio_dev)
56 int ret;
57 struct ssp_sensor_data *spd = iio_priv(indio_dev);
58 struct ssp_data *data = dev_get_drvdata(indio_dev->dev.parent->parent);
60 ret = ssp_disable_sensor(data, spd->type);
61 if (ret < 0)
62 return ret;
64 kfree(spd->buffer);
66 return ret;
68 EXPORT_SYMBOL(ssp_common_buffer_postdisable);
70 /**
71 * ssp_common_process_data() - Common process data callback for ssp sensors
73 * @indio_dev: iio device
74 * @buf: source buffer
75 * @len: sensor data length
76 * @timestamp: system timestamp
78 * Returns 0 or negative value in case of error
80 int ssp_common_process_data(struct iio_dev *indio_dev, void *buf,
81 unsigned int len, int64_t timestamp)
83 __le32 time;
84 int64_t calculated_time;
85 struct ssp_sensor_data *spd = iio_priv(indio_dev);
87 if (indio_dev->scan_bytes == 0)
88 return 0;
91 * it always sends full set of samples, remember about available masks
93 memcpy(spd->buffer, buf, len);
95 if (indio_dev->scan_timestamp) {
96 memcpy(&time, &((char *)buf)[len], SSP_TIME_SIZE);
97 calculated_time =
98 timestamp + (int64_t)le32_to_cpu(time) * 1000000;
101 return iio_push_to_buffers_with_timestamp(indio_dev, spd->buffer,
102 calculated_time);
104 EXPORT_SYMBOL(ssp_common_process_data);
106 MODULE_AUTHOR("Karol Wrona <k.wrona@samsung.com>");
107 MODULE_DESCRIPTION("Samsung sensorhub commons");
108 MODULE_LICENSE("GPL");