linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Jonathan Cameron <jic23@cam.ac.uk>
Cc: linux-iio@vger.kernel.org, drivers@analog.com,
	Lars-Peter Clausen <lars@metafoo.de>
Subject: [PATCH 09/11] staging:iio:adis_lib: Use triggered buffer setup helper function
Date: Tue, 13 Nov 2012 14:28:11 +0100	[thread overview]
Message-ID: <1352813293-17975-9-git-send-email-lars@metafoo.de> (raw)
In-Reply-To: <1352813293-17975-1-git-send-email-lars@metafoo.de>

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>
---
 drivers/staging/iio/imu/Kconfig       |  3 +-
 drivers/staging/iio/imu/adis_buffer.c | 78 +++++------------------------------
 2 files changed, 11 insertions(+), 70 deletions(-)

diff --git a/drivers/staging/iio/imu/Kconfig b/drivers/staging/iio/imu/Kconfig
index 89b9f25..2c564ed 100644
--- a/drivers/staging/iio/imu/Kconfig
+++ b/drivers/staging/iio/imu/Kconfig
@@ -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.
diff --git a/drivers/staging/iio/imu/adis_buffer.c b/drivers/staging/iio/imu/adis_buffer.c
index 47bdea0..0fa8e80a 100644
--- a/drivers/staging/iio/imu/adis_buffer.c
+++ b/drivers/staging/iio/imu/adis_buffer.c
@@ -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);
-- 
1.8.0


  parent reply	other threads:[~2012-11-13 13:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-13 13:28 [PATCH 01/11] staging:iio: Add common ADIS library Lars-Peter Clausen
2012-11-13 13:28 ` [PATCH 02/11] staging:iio:adis16201: Use adis library Lars-Peter Clausen
2012-11-13 13:28 ` [PATCH 03/11] staging:iio:adis16203: " Lars-Peter Clausen
2012-11-13 13:28 ` [PATCH 04/11] staging:iio:adis16204: " Lars-Peter Clausen
2012-11-13 13:28 ` [PATCH 05/11] staging:iio:adis16209: " Lars-Peter Clausen
2012-11-13 13:28 ` [PATCH 06/11] staging:iio:adis16220: " Lars-Peter Clausen
2012-11-13 13:28 ` [PATCH 07/11] staging:iio:adis16240: " Lars-Peter Clausen
2012-11-13 13:28 ` [PATCH 08/11] staging:iio:adis16260: " Lars-Peter Clausen
2012-11-13 13:28 ` Lars-Peter Clausen [this message]
2012-11-13 13:28 ` [PATCH 10/11] staging:iio:adis: Preallocate transfer message Lars-Peter Clausen
2012-11-13 13:28 ` [PATCH 11/11] staging:iio: Move adis library out of staging Lars-Peter Clausen
2012-11-17 11:00   ` Jonathan Cameron
2012-11-17 11:01 ` [PATCH 01/11] staging:iio: Add common ADIS library Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1352813293-17975-9-git-send-email-lars@metafoo.de \
    --to=lars@metafoo.de \
    --cc=drivers@analog.com \
    --cc=jic23@cam.ac.uk \
    --cc=linux-iio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).