mmc: rtsx_pci: Enable MMC_CAP_ERASE to allow erase/discard/trim requests
[linux/fpc-iii.git] / drivers / iio / gyro / st_gyro_buffer.c
bloba5377044e42f0ccf128f1fd9bfb0ce02bba0a0a8
1 /*
2 * STMicroelectronics gyroscopes driver
4 * Copyright 2012-2013 STMicroelectronics Inc.
6 * Denis Ciocca <denis.ciocca@st.com>
8 * Licensed under the GPL-2.
9 */
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/slab.h>
14 #include <linux/stat.h>
15 #include <linux/interrupt.h>
16 #include <linux/i2c.h>
17 #include <linux/delay.h>
18 #include <linux/iio/iio.h>
19 #include <linux/iio/buffer.h>
20 #include <linux/iio/trigger_consumer.h>
21 #include <linux/iio/triggered_buffer.h>
23 #include <linux/iio/common/st_sensors.h>
24 #include "st_gyro.h"
26 int st_gyro_trig_set_state(struct iio_trigger *trig, bool state)
28 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
30 return st_sensors_set_dataready_irq(indio_dev, state);
33 static int st_gyro_buffer_preenable(struct iio_dev *indio_dev)
35 return st_sensors_set_enable(indio_dev, true);
38 static int st_gyro_buffer_postenable(struct iio_dev *indio_dev)
40 int err;
41 struct st_sensor_data *gdata = iio_priv(indio_dev);
43 gdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
44 if (gdata->buffer_data == NULL) {
45 err = -ENOMEM;
46 goto allocate_memory_error;
49 err = st_sensors_set_axis_enable(indio_dev,
50 (u8)indio_dev->active_scan_mask[0]);
51 if (err < 0)
52 goto st_gyro_buffer_postenable_error;
54 err = iio_triggered_buffer_postenable(indio_dev);
55 if (err < 0)
56 goto st_gyro_buffer_postenable_error;
58 return err;
60 st_gyro_buffer_postenable_error:
61 kfree(gdata->buffer_data);
62 allocate_memory_error:
63 return err;
66 static int st_gyro_buffer_predisable(struct iio_dev *indio_dev)
68 int err;
69 struct st_sensor_data *gdata = iio_priv(indio_dev);
71 err = iio_triggered_buffer_predisable(indio_dev);
72 if (err < 0)
73 goto st_gyro_buffer_predisable_error;
75 err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
76 if (err < 0)
77 goto st_gyro_buffer_predisable_error;
79 err = st_sensors_set_enable(indio_dev, false);
81 st_gyro_buffer_predisable_error:
82 kfree(gdata->buffer_data);
83 return err;
86 static const struct iio_buffer_setup_ops st_gyro_buffer_setup_ops = {
87 .preenable = &st_gyro_buffer_preenable,
88 .postenable = &st_gyro_buffer_postenable,
89 .predisable = &st_gyro_buffer_predisable,
92 int st_gyro_allocate_ring(struct iio_dev *indio_dev)
94 return iio_triggered_buffer_setup(indio_dev, NULL,
95 &st_sensors_trigger_handler, &st_gyro_buffer_setup_ops);
98 void st_gyro_deallocate_ring(struct iio_dev *indio_dev)
100 iio_triggered_buffer_cleanup(indio_dev);
103 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
104 MODULE_DESCRIPTION("STMicroelectronics gyroscopes buffer");
105 MODULE_LICENSE("GPL v2");