mmc: rtsx_pci: Enable MMC_CAP_ERASE to allow erase/discard/trim requests
[linux/fpc-iii.git] / drivers / iio / common / st_sensors / st_sensors_buffer.c
blobf1693dbebb8ac23359035786ef26b6607191058d
1 /*
2 * STMicroelectronics sensors buffer library driver
4 * Copyright 2012-2013 STMicroelectronics Inc.
6 * Denis Ciocca <denis.ciocca@st.com>
8 * Licensed under the GPL-2.
9 */
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/slab.h>
14 #include <linux/iio/iio.h>
15 #include <linux/iio/trigger.h>
16 #include <linux/interrupt.h>
17 #include <linux/iio/buffer.h>
18 #include <linux/iio/trigger_consumer.h>
19 #include <linux/iio/triggered_buffer.h>
20 #include <linux/irqreturn.h>
22 #include <linux/iio/common/st_sensors.h>
25 int st_sensors_get_buffer_element(struct iio_dev *indio_dev, u8 *buf)
27 int i, len;
28 int total = 0;
29 struct st_sensor_data *sdata = iio_priv(indio_dev);
30 unsigned int num_data_channels = sdata->num_data_channels;
32 for (i = 0; i < num_data_channels; i++) {
33 unsigned int bytes_to_read;
35 if (test_bit(i, indio_dev->active_scan_mask)) {
36 bytes_to_read = indio_dev->channels[i].scan_type.storagebits >> 3;
37 len = sdata->tf->read_multiple_byte(&sdata->tb,
38 sdata->dev, indio_dev->channels[i].address,
39 bytes_to_read,
40 buf + total, sdata->multiread_bit);
42 if (len < bytes_to_read)
43 return -EIO;
45 /* Advance the buffer pointer */
46 total += len;
50 return total;
52 EXPORT_SYMBOL(st_sensors_get_buffer_element);
54 irqreturn_t st_sensors_trigger_handler(int irq, void *p)
56 int len;
57 struct iio_poll_func *pf = p;
58 struct iio_dev *indio_dev = pf->indio_dev;
59 struct st_sensor_data *sdata = iio_priv(indio_dev);
60 s64 timestamp;
62 /* If we do timetamping here, do it before reading the values */
63 if (sdata->hw_irq_trigger)
64 timestamp = sdata->hw_timestamp;
65 else
66 timestamp = iio_get_time_ns();
68 len = st_sensors_get_buffer_element(indio_dev, sdata->buffer_data);
69 if (len < 0)
70 goto st_sensors_get_buffer_element_error;
72 iio_push_to_buffers_with_timestamp(indio_dev, sdata->buffer_data,
73 timestamp);
75 st_sensors_get_buffer_element_error:
76 iio_trigger_notify_done(indio_dev->trig);
78 return IRQ_HANDLED;
80 EXPORT_SYMBOL(st_sensors_trigger_handler);
82 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
83 MODULE_DESCRIPTION("STMicroelectronics ST-sensors buffer");
84 MODULE_LICENSE("GPL v2");