staging:iio:adis_lib: Use triggered buffer setup helper function
authorLars-Peter Clausen <lars@metafoo.de>
Tue, 13 Nov 2012 13:28:00 +0000 (13:28 +0000)
committerJonathan Cameron <jic23@kernel.org>
Mon, 19 Nov 2012 22:22:10 +0000 (22:22 +0000)
Use the triggered buffer helper functions to setup and tear down the buffer for
the adis library instead of doing this manually. This also means that we switch
away from the deprecated sw_ring buffer and use the kfifo buffer now instead.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
drivers/staging/iio/imu/Kconfig
drivers/staging/iio/imu/adis_buffer.c

index 89b9f2566b8d2e7f5263f4b68b7336227a3f9e33..2c564edeb1720c54420cd6ef462376115f18b70c 100644 (file)
@@ -23,8 +23,7 @@ config IIO_ADIS_LIB
 
 config IIO_ADIS_LIB_BUFFER
        bool
-       select IIO_TRIGGER
-       select IIO_SW_RING
+       select IIO_TRIGGERED_BUFFER
        help
          A set of buffer helper functions for the Analog Devices ADIS* device
          family.
index 47bdea09f681c0905a5ce9dca3166cb50c68a249..0fa8e80a54b3920668e634cfec61061f4e0b946d 100644 (file)
@@ -7,8 +7,8 @@
 
 #include <linux/iio/iio.h>
 #include <linux/iio/buffer.h>
-#include "../ring_sw.h"
 #include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
 
 #include  "adis.h"
 
@@ -83,56 +83,6 @@ static irqreturn_t adis_trigger_handler(int irq, void *p)
        return IRQ_HANDLED;
 }
 
-static const struct iio_buffer_setup_ops adis_buffer_setup_ops = {
-       .preenable = &iio_sw_buffer_preenable,
-       .postenable = &iio_triggered_buffer_postenable,
-       .predisable = &iio_triggered_buffer_predisable,
-};
-
-static int adis_buffer_setup(struct iio_dev *indio_dev,
-       irqreturn_t (*trigger_handler)(int, void *))
-{
-       int ret = 0;
-       struct iio_buffer *buffer;
-
-       if (!trigger_handler)
-               trigger_handler = &adis_trigger_handler;
-
-       buffer = iio_sw_rb_allocate(indio_dev);
-       if (!buffer) {
-               ret = -ENOMEM;
-               return ret;
-       }
-
-       indio_dev->buffer = buffer;
-       indio_dev->setup_ops = &adis_buffer_setup_ops;
-
-       indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
-                                                trigger_handler,
-                                                IRQF_ONESHOT,
-                                                indio_dev,
-                                                "%s_consumer%d",
-                                                indio_dev->name,
-                                                indio_dev->id);
-       if (indio_dev->pollfunc == NULL) {
-               ret = -ENOMEM;
-               goto error_iio_sw_rb_free;
-       }
-
-       indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
-       return 0;
-
-error_iio_sw_rb_free:
-       iio_sw_rb_free(indio_dev->buffer);
-       return ret;
-}
-
-static void adis_buffer_cleanup(struct iio_dev *indio_dev)
-{
-       iio_dealloc_pollfunc(indio_dev->pollfunc);
-       iio_sw_rb_free(indio_dev->buffer);
-}
-
 /**
  * adis_setup_buffer_and_trigger() - Sets up buffer and trigger for the adis device
  * @adis: The adis device.
@@ -154,30 +104,23 @@ int adis_setup_buffer_and_trigger(struct adis *adis, struct iio_dev *indio_dev,
 {
        int ret;
 
-       ret = adis_buffer_setup(indio_dev, trigger_handler);
+       if (!trigger_handler)
+               trigger_handler = adis_trigger_handler;
+
+       ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
+               trigger_handler, NULL);
        if (ret)
                return ret;
 
-       ret = iio_buffer_register(indio_dev,
-                                 indio_dev->channels,
-                                 indio_dev->num_channels);
-       if (ret) {
-               dev_err(&adis->spi->dev, "Failed to initialize buffer %d\n",
-                       ret);
-               goto error_unreg_buffer_funcs;
-       }
-
        if (adis->spi->irq) {
                ret = adis_probe_trigger(adis, indio_dev);
                if (ret)
-                       goto error_uninitialize_buffer;
+                       goto error_buffer_cleanup;
        }
        return 0;
 
-error_uninitialize_buffer:
-       iio_buffer_unregister(indio_dev);
-error_unreg_buffer_funcs:
-       adis_buffer_cleanup(indio_dev);
+error_buffer_cleanup:
+       iio_triggered_buffer_cleanup(indio_dev);
        return ret;
 }
 EXPORT_SYMBOL_GPL(adis_setup_buffer_and_trigger);
@@ -194,7 +137,6 @@ void adis_cleanup_buffer_and_trigger(struct adis *adis,
 {
        if (adis->spi->irq)
                adis_remove_trigger(adis);
-       iio_buffer_unregister(indio_dev);
-       adis_buffer_cleanup(indio_dev);
+       iio_triggered_buffer_cleanup(indio_dev);
 }
 EXPORT_SYMBOL_GPL(adis_cleanup_buffer_and_trigger);