Merge tag 'regmap-fix-v5.11-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux/fpc-iii.git] / drivers / iio / gyro / st_gyro_buffer.c
blob4feb7ada71953bbaf91d8e646c5cb79b77ce8bc0
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * STMicroelectronics gyroscopes driver
5 * Copyright 2012-2013 STMicroelectronics Inc.
7 * Denis Ciocca <denis.ciocca@st.com>
8 */
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/slab.h>
13 #include <linux/stat.h>
14 #include <linux/interrupt.h>
15 #include <linux/i2c.h>
16 #include <linux/delay.h>
17 #include <linux/iio/iio.h>
18 #include <linux/iio/buffer.h>
19 #include <linux/iio/trigger_consumer.h>
20 #include <linux/iio/triggered_buffer.h>
22 #include <linux/iio/common/st_sensors.h>
23 #include "st_gyro.h"
25 int st_gyro_trig_set_state(struct iio_trigger *trig, bool state)
27 struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
29 return st_sensors_set_dataready_irq(indio_dev, state);
32 static int st_gyro_buffer_postenable(struct iio_dev *indio_dev)
34 int err;
36 err = st_sensors_set_axis_enable(indio_dev, indio_dev->active_scan_mask[0]);
37 if (err < 0)
38 return err;
40 err = st_sensors_set_enable(indio_dev, true);
41 if (err < 0)
42 goto st_gyro_buffer_enable_all_axis;
44 return 0;
46 st_gyro_buffer_enable_all_axis:
47 st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
48 return err;
51 static int st_gyro_buffer_predisable(struct iio_dev *indio_dev)
53 int err;
55 err = st_sensors_set_enable(indio_dev, false);
56 if (err < 0)
57 return err;
59 return st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
62 static const struct iio_buffer_setup_ops st_gyro_buffer_setup_ops = {
63 .postenable = &st_gyro_buffer_postenable,
64 .predisable = &st_gyro_buffer_predisable,
67 int st_gyro_allocate_ring(struct iio_dev *indio_dev)
69 return iio_triggered_buffer_setup(indio_dev, NULL,
70 &st_sensors_trigger_handler, &st_gyro_buffer_setup_ops);
73 void st_gyro_deallocate_ring(struct iio_dev *indio_dev)
75 iio_triggered_buffer_cleanup(indio_dev);
78 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
79 MODULE_DESCRIPTION("STMicroelectronics gyroscopes buffer");
80 MODULE_LICENSE("GPL v2");