1 // SPDX-License-Identifier: GPL-2.0-only
3 * STMicroelectronics accelerometers driver
5 * Copyright 2012-2013 STMicroelectronics Inc.
7 * Denis Ciocca <denis.ciocca@st.com>
10 #include <linux/kernel.h>
11 #include <linux/iio/iio.h>
12 #include <linux/iio/buffer.h>
13 #include <linux/iio/trigger.h>
14 #include <linux/iio/triggered_buffer.h>
16 #include <linux/iio/common/st_sensors.h>
19 int st_accel_trig_set_state(struct iio_trigger
*trig
, bool state
)
21 struct iio_dev
*indio_dev
= iio_trigger_get_drvdata(trig
);
23 return st_sensors_set_dataready_irq(indio_dev
, state
);
26 static int st_accel_buffer_postenable(struct iio_dev
*indio_dev
)
30 err
= st_sensors_set_axis_enable(indio_dev
, indio_dev
->active_scan_mask
[0]);
34 err
= st_sensors_set_enable(indio_dev
, true);
36 goto st_accel_buffer_enable_all_axis
;
40 st_accel_buffer_enable_all_axis
:
41 st_sensors_set_axis_enable(indio_dev
, ST_SENSORS_ENABLE_ALL_AXIS
);
45 static int st_accel_buffer_predisable(struct iio_dev
*indio_dev
)
49 err
= st_sensors_set_enable(indio_dev
, false);
53 return st_sensors_set_axis_enable(indio_dev
,
54 ST_SENSORS_ENABLE_ALL_AXIS
);
57 static const struct iio_buffer_setup_ops st_accel_buffer_setup_ops
= {
58 .postenable
= &st_accel_buffer_postenable
,
59 .predisable
= &st_accel_buffer_predisable
,
62 int st_accel_allocate_ring(struct iio_dev
*indio_dev
)
64 return devm_iio_triggered_buffer_setup(indio_dev
->dev
.parent
, indio_dev
,
65 NULL
, &st_sensors_trigger_handler
, &st_accel_buffer_setup_ops
);