xref: /linux/drivers/iio/magnetometer/st_magn_buffer.c (revision c2f4954c2d3fc4f77b46c67585e17a58df4ba8e4)
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/module.h>
11 #include <linux/kernel.h>
12 #include <linux/iio/iio.h>
13 #include <linux/iio/buffer.h>
14 #include <linux/iio/trigger.h>
15 #include <linux/iio/triggered_buffer.h>
16 
17 #include <linux/iio/common/st_sensors.h>
18 #include "st_magn.h"
19 
20 int st_magn_trig_set_state(struct iio_trigger *trig, bool state)
21 {
22 	struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
23 
24 	return st_sensors_set_dataready_irq(indio_dev, state);
25 }
26 
27 static int st_magn_buffer_postenable(struct iio_dev *indio_dev)
28 {
29 	return st_sensors_set_enable(indio_dev, true);
30 }
31 
32 static int st_magn_buffer_predisable(struct iio_dev *indio_dev)
33 {
34 	return st_sensors_set_enable(indio_dev, false);
35 }
36 
37 static const struct iio_buffer_setup_ops st_magn_buffer_setup_ops = {
38 	.postenable = &st_magn_buffer_postenable,
39 	.predisable = &st_magn_buffer_predisable,
40 };
41 
42 int st_magn_allocate_ring(struct iio_dev *indio_dev)
43 {
44 	return devm_iio_triggered_buffer_setup(indio_dev->dev.parent, indio_dev,
45 		NULL, &st_sensors_trigger_handler, &st_magn_buffer_setup_ops);
46 }
47 
48 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
49 MODULE_DESCRIPTION("STMicroelectronics magnetometers buffer");
50 MODULE_LICENSE("GPL v2");
51