NFS: Don't clear desc->pg_moreio in nfs_do_recoalesce()
[linux/fpc-iii.git] / drivers / iio / magnetometer / st_magn_buffer.c
blobbf427dc0d226c40de9adc92257ece78ab6b14de6
1 /*
2 * STMicroelectronics magnetometers driver
4 * Copyright 2012-2013 STMicroelectronics Inc.
6 * Denis Ciocca <denis.ciocca@st.com>
8 * Licensed under the GPL-2.
9 */
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/slab.h>
14 #include <linux/stat.h>
15 #include <linux/interrupt.h>
16 #include <linux/i2c.h>
17 #include <linux/delay.h>
18 #include <linux/iio/iio.h>
19 #include <linux/iio/buffer.h>
20 #include <linux/iio/trigger_consumer.h>
21 #include <linux/iio/triggered_buffer.h>
23 #include <linux/iio/common/st_sensors.h>
24 #include "st_magn.h"
26 static int st_magn_buffer_preenable(struct iio_dev *indio_dev)
28 return st_sensors_set_enable(indio_dev, true);
31 static int st_magn_buffer_postenable(struct iio_dev *indio_dev)
33 int err;
34 struct st_sensor_data *mdata = iio_priv(indio_dev);
36 mdata->buffer_data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
37 if (mdata->buffer_data == NULL) {
38 err = -ENOMEM;
39 goto allocate_memory_error;
42 err = iio_triggered_buffer_postenable(indio_dev);
43 if (err < 0)
44 goto st_magn_buffer_postenable_error;
46 return err;
48 st_magn_buffer_postenable_error:
49 kfree(mdata->buffer_data);
50 allocate_memory_error:
51 return err;
54 static int st_magn_buffer_predisable(struct iio_dev *indio_dev)
56 int err;
57 struct st_sensor_data *mdata = iio_priv(indio_dev);
59 err = iio_triggered_buffer_predisable(indio_dev);
60 if (err < 0)
61 goto st_magn_buffer_predisable_error;
63 err = st_sensors_set_enable(indio_dev, false);
65 st_magn_buffer_predisable_error:
66 kfree(mdata->buffer_data);
67 return err;
70 static const struct iio_buffer_setup_ops st_magn_buffer_setup_ops = {
71 .preenable = &st_magn_buffer_preenable,
72 .postenable = &st_magn_buffer_postenable,
73 .predisable = &st_magn_buffer_predisable,
76 int st_magn_allocate_ring(struct iio_dev *indio_dev)
78 return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
79 &st_sensors_trigger_handler, &st_magn_buffer_setup_ops);
82 void st_magn_deallocate_ring(struct iio_dev *indio_dev)
84 iio_triggered_buffer_cleanup(indio_dev);
87 MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
88 MODULE_DESCRIPTION("STMicroelectronics magnetometers buffer");
89 MODULE_LICENSE("GPL v2");