1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * STMicroelectronics magnetometers driver
4  *
5  * Copyright 2012-2013 STMicroelectronics Inc.
6  *
7  * Denis Ciocca <denis.ciocca@st.com>
8  */
9 
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>
15 
16 #include <linux/iio/common/st_sensors.h>
17 #include "st_magn.h"
18 
st_magn_trig_set_state(struct iio_trigger * trig,bool state)19 int st_magn_trig_set_state(struct iio_trigger *trig, bool state)
20 {
21 	struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
22 
23 	return st_sensors_set_dataready_irq(indio_dev, state);
24 }
25 
st_magn_buffer_postenable(struct iio_dev * indio_dev)26 static int st_magn_buffer_postenable(struct iio_dev *indio_dev)
27 {
28 	return st_sensors_set_enable(indio_dev, true);
29 }
30 
st_magn_buffer_predisable(struct iio_dev * indio_dev)31 static int st_magn_buffer_predisable(struct iio_dev *indio_dev)
32 {
33 	return st_sensors_set_enable(indio_dev, false);
34 }
35 
36 static const struct iio_buffer_setup_ops st_magn_buffer_setup_ops = {
37 	.postenable = &st_magn_buffer_postenable,
38 	.predisable = &st_magn_buffer_predisable,
39 };
40 
st_magn_allocate_ring(struct iio_dev * indio_dev)41 int st_magn_allocate_ring(struct iio_dev *indio_dev)
42 {
43 	return devm_iio_triggered_buffer_setup(indio_dev->dev.parent, indio_dev,
44 		NULL, &st_sensors_trigger_handler, &st_magn_buffer_setup_ops);
45 }
46 
47