gpio: rcar: Fix runtime PM imbalance on error
[linux/fpc-iii.git] / drivers / iio / accel / st_accel_buffer.c
blob9f2b40474b8ec7fb9e36e382cd0beedd55a2299d
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * STMicroelectronics accelerometers 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_accel.h"
25 int st_accel_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_accel_buffer_postenable(struct iio_dev *indio_dev)
34 int err;
36 err = iio_triggered_buffer_postenable(indio_dev);
37 if (err < 0)
38 return err;
40 err = st_sensors_set_axis_enable(indio_dev,
41 (u8)indio_dev->active_scan_mask[0]);
42 if (err < 0)
43 goto st_accel_buffer_predisable;
45 err = st_sensors_set_enable(indio_dev, true);
46 if (err < 0)
47 goto st_accel_buffer_enable_all_axis;
49 return 0;
51 st_accel_buffer_enable_all_axis:
52 st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
53 st_accel_buffer_predisable:
54 iio_triggered_buffer_predisable(indio_dev);
55 return err;
58 static int st_accel_buffer_predisable(struct iio_dev *indio_dev)
60 int err, err2;
62 err = st_sensors_set_enable(indio_dev, false);
63 if (err < 0)
64 goto st_accel_buffer_predisable;
66 err = st_sensors_set_axis_enable(indio_dev, ST_SENSORS_ENABLE_ALL_AXIS);
68 st_accel_buffer_predisable:
69 err2 = iio_triggered_buffer_predisable(indio_dev);
70 if (!err)
71 err = err2;
73 return err;
76 static const struct iio_buffer_setup_ops st_accel_buffer_setup_ops = {
77 .postenable = &st_accel_buffer_postenable,
78 .predisable = &st_accel_buffer_predisable,
81 int st_accel_allocate_ring(struct iio_dev *indio_dev)
83 return iio_triggered_buffer_setup(indio_dev, NULL,
84 &st_sensors_trigger_handler, &st_accel_buffer_setup_ops);
87 void st_accel_deallocate_ring(struct iio_dev *indio_dev)
89 iio_triggered_buffer_cleanup(indio_dev);
92 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
93 MODULE_DESCRIPTION("STMicroelectronics accelerometers buffer");
94 MODULE_LICENSE("GPL v2");