All of lore.kernel.org
 help / color / mirror / Atom feed
* [v2 1/9] staging:iio: Add helper function for initializing triggered buffers
@ 2012-06-08  8:48 Lars-Peter Clausen
  2012-06-08  8:48 ` [v2 2/9] iio:adc:at91: Use new triggered buffer setup helper Lars-Peter Clausen
                   ` (9 more replies)
  0 siblings, 10 replies; 19+ messages in thread
From: Lars-Peter Clausen @ 2012-06-08  8:48 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Add a helper function for executing the common tasks which are usually involved
in setting up a simple software ringbuffer. It will allocate the buffer,
allocate the pollfunc and register the buffer.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>

---
Changes since v1:
	* Move function declarations to their own header
	* Mention that iio_triggered_buffer_setup should usually be called right
	  before iio_device_register
	* Minor code cleanups
---
 drivers/iio/Kconfig                         |    7 ++
 drivers/iio/Makefile                        |    1 +
 drivers/iio/industrialio-triggered-buffer.c |  110 +++++++++++++++++++++++++++
 3 files changed, 118 insertions(+)
 create mode 100644 drivers/iio/industrialio-triggered-buffer.c

diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
index 103349f..612073f 100644
--- a/drivers/iio/Kconfig
+++ b/drivers/iio/Kconfig
@@ -30,6 +30,13 @@ config IIO_KFIFO_BUF
 	  no buffer events so it is up to userspace to work out how
 	  often to read from the buffer.
 
+config IIO_TRIGGERED_BUFFER
+	tristate
+	select IIO_TRIGGER
+	select IIO_KFIFO_BUF
+	help
+	  Provides helper functions for setting up triggered buffers.
+
 endif # IIO_BUFFER
 
 config IIO_TRIGGER
diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
index c38fa2a..34309ab 100644
--- a/drivers/iio/Makefile
+++ b/drivers/iio/Makefile
@@ -7,6 +7,7 @@ industrialio-y := industrialio-core.o industrialio-event.o inkern.o
 industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o
 industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o
 
+obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o
 obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
 
 obj-y += adc/
diff --git a/drivers/iio/industrialio-triggered-buffer.c b/drivers/iio/industrialio-triggered-buffer.c
new file mode 100644
index 0000000..a462a57
--- /dev/null
+++ b/drivers/iio/industrialio-triggered-buffer.c
@@ -0,0 +1,110 @@
+ /*
+ * Copyright (c) 2012 Analog Devices, Inc.
+ *  Author: Lars-Peter Clausen <lars@metafoo.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/export.h>
+#include <linux/module.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/kfifo_buf.h>
+#include <linux/iio/triggered_buffer.h>
+#include <linux/iio/trigger_consumer.h>
+
+static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = {
+	.preenable = &iio_sw_buffer_preenable,
+	.postenable = &iio_triggered_buffer_postenable,
+	.predisable = &iio_triggered_buffer_predisable,
+};
+
+/**
+ * iio_triggered_buffer_setup() - Setup triggered buffer and pollfunc
+ * @indio_dev:		IIO device structure
+ * @pollfunc_bh:	Function which will be used as pollfunc bottom half
+ * @pollfunc_th:	Function which will be used as pollfunc top half
+ * @setup_ops:		Buffer setup functions to use for this device.
+ *			If NULL the default setup functions for triggered
+ *			buffers will be used.
+ *
+ * This function combines some common tasks which will normally be performed
+ * when setting up a triggered buffer. It will allocate the buffer and the
+ * pollfunc, as well as register the buffer with IIO core.
+ *
+ * Before calling this function the indio_dev structure should already be
+ * completely initialized but not yet registered. In practice this means that
+ * this function should be called right before iio_device_register().
+ *
+ * To free the resources allocated by this function
+ * iio_triggered_buffer_cleanup() should be called.
+ */
+int iio_triggered_buffer_setup(struct iio_dev *indio_dev,
+	irqreturn_t (*pollfunc_bh)(int irq, void *p),
+	irqreturn_t (*pollfunc_th)(int irq, void *p),
+	const struct iio_buffer_setup_ops *setup_ops)
+{
+	int ret;
+
+	indio_dev->buffer = iio_kfifo_allocate(indio_dev);
+	if (!indio_dev->buffer) {
+		ret = -ENOMEM;
+		goto error_ret;
+	}
+
+	indio_dev->pollfunc = iio_alloc_pollfunc(pollfunc_bh,
+						 pollfunc_th,
+						 IRQF_ONESHOT,
+						 indio_dev,
+						 "%s_consumer%d",
+						 indio_dev->name,
+						 indio_dev->id);
+	if (indio_dev->pollfunc == NULL) {
+		ret = -ENOMEM;
+		goto error_kfifo_free;
+	}
+
+	/* Ring buffer functions - here trigger setup related */
+	if (setup_ops)
+		indio_dev->setup_ops = setup_ops;
+	else
+		indio_dev->setup_ops = &iio_triggered_buffer_setup_ops;
+
+	/* Flag that polled ring buffering is possible */
+	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
+
+	ret = iio_buffer_register(indio_dev,
+				  indio_dev->channels,
+				  indio_dev->num_channels);
+	if (ret)
+		goto error_dealloc_pollfunc;
+
+	return 0;
+
+error_dealloc_pollfunc:
+	iio_dealloc_pollfunc(indio_dev->pollfunc);
+error_kfifo_free:
+	iio_kfifo_free(indio_dev->buffer);
+error_ret:
+	return ret;
+}
+EXPORT_SYMBOL(iio_triggered_buffer_setup);
+
+/**
+ * iio_triggered_buffer_cleanup() - Free resources allocated by iio_triggered_buffer_setup()
+ * @indio_dev: IIO device structure
+ */
+void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev)
+{
+	iio_buffer_unregister(indio_dev);
+	iio_dealloc_pollfunc(indio_dev->pollfunc);
+	iio_kfifo_free(indio_dev->buffer);
+}
+EXPORT_SYMBOL(iio_triggered_buffer_cleanup);
+
+MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
+MODULE_DESCRIPTION("IIO helper functions for setting up triggered buffers");
+MODULE_LICENSE("GPL");
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [v2 2/9] iio:adc:at91: Use new triggered buffer setup helper
  2012-06-08  8:48 [v2 1/9] staging:iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
@ 2012-06-08  8:48 ` Lars-Peter Clausen
  2012-06-15 16:32   ` Lars-Peter Clausen
  2012-06-08  8:48 ` [v2 3/9] staging:iio:adc:ad7192: Use new triggered buffer setup helper function Lars-Peter Clausen
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 19+ messages in thread
From: Lars-Peter Clausen @ 2012-06-08  8:48 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen, Maxime Ripard

Use the new triggered buffer setup helper function to allocate and register
buffer and pollfunc.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
Acked-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/iio/adc/Kconfig    |    3 +--
 drivers/iio/adc/at91_adc.c |   51 ++++----------------------------------------
 2 files changed, 5 insertions(+), 49 deletions(-)

diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 9a0df81..4f7f584 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -7,8 +7,7 @@ config AT91_ADC
 	tristate "Atmel AT91 ADC"
 	depends on ARCH_AT91
 	select IIO_BUFFER
-	select IIO_KFIFO_BUF
-	select IIO_TRIGGER
+	select IIO_TRIGGERED_BUFFER
 	select SYSFS
 	help
 	  Say yes here to build support for Atmel AT91 ADC.
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index f18a95d..6a08469 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -26,9 +26,9 @@
 
 #include <linux/iio/iio.h>
 #include <linux/iio/buffer.h>
-#include <linux/iio/kfifo_buf.h>
 #include <linux/iio/trigger.h>
 #include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
 
 #include <mach/at91_adc.h>
 
@@ -318,58 +318,15 @@ static void at91_adc_trigger_remove(struct iio_dev *idev)
 	}
 }
 
-static const struct iio_buffer_setup_ops at91_adc_buffer_ops = {
-	.preenable = &iio_sw_buffer_preenable,
-	.postenable = &iio_triggered_buffer_postenable,
-	.predisable = &iio_triggered_buffer_predisable,
-};
-
 static int at91_adc_buffer_init(struct iio_dev *idev)
 {
-	int ret;
-
-	idev->buffer = iio_kfifo_allocate(idev);
-	if (!idev->buffer) {
-		ret = -ENOMEM;
-		goto error_ret;
-	}
-
-	idev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
-					    &at91_adc_trigger_handler,
-					    IRQF_ONESHOT,
-					    idev,
-					    "%s-consumer%d",
-					    idev->name,
-					    idev->id);
-	if (idev->pollfunc == NULL) {
-		ret = -ENOMEM;
-		goto error_pollfunc;
-	}
-
-	idev->setup_ops = &at91_adc_buffer_ops;
-	idev->modes |= INDIO_BUFFER_TRIGGERED;
-
-	ret = iio_buffer_register(idev,
-				  idev->channels,
-				  idev->num_channels);
-	if (ret)
-		goto error_register;
-
-	return 0;
-
-error_register:
-	iio_dealloc_pollfunc(idev->pollfunc);
-error_pollfunc:
-	iio_kfifo_free(idev->buffer);
-error_ret:
-	return ret;
+	return iio_triggered_buffer_setup(idev, &iio_pollfunc_store_time,
+		&at91_adc_trigger_handler, NULL);
 }
 
 static void at91_adc_buffer_remove(struct iio_dev *idev)
 {
-	iio_buffer_unregister(idev);
-	iio_dealloc_pollfunc(idev->pollfunc);
-	iio_kfifo_free(idev->buffer);
+	iio_triggered_buffer_cleanup(idev);
 }
 
 static int at91_adc_read_raw(struct iio_dev *idev,
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [v2 3/9] staging:iio:adc:ad7192: Use new triggered buffer setup helper function
  2012-06-08  8:48 [v2 1/9] staging:iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
  2012-06-08  8:48 ` [v2 2/9] iio:adc:at91: Use new triggered buffer setup helper Lars-Peter Clausen
@ 2012-06-08  8:48 ` Lars-Peter Clausen
  2012-06-08  8:48 ` [v2 4/9] staging:iio:adc:ad7298: " Lars-Peter Clausen
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: Lars-Peter Clausen @ 2012-06-08  8:48 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Use the new triggered buffer setup helper function to allocate and register
buffer and pollfunc.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/adc/Kconfig  |    3 +--
 drivers/staging/iio/adc/ad7192.c |   49 +++++---------------------------------
 2 files changed, 7 insertions(+), 45 deletions(-)

diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 2490dd2..c01df61 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -135,8 +135,7 @@ config AD7192
 	tristate "Analog Devices AD7190 AD7192 AD7195 ADC driver"
 	depends on SPI
 	select IIO_BUFFER
-	select IIO_KFIFO_BUF
-	select IIO_TRIGGER
+	select IIO_TRIGGERED_BUFFER
 	help
 	  Say yes here to build support for Analog Devices AD7190,
 	  AD7192 or AD7195 SPI analog to digital converters (ADC).
diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
index 5eaeaf1..839f17c 100644
--- a/drivers/staging/iio/adc/ad7192.c
+++ b/drivers/staging/iio/adc/ad7192.c
@@ -20,9 +20,9 @@
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
 #include <linux/iio/buffer.h>
-#include <linux/iio/kfifo_buf.h>
 #include <linux/iio/trigger.h>
 #include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
 
 #include "ad7192.h"
 
@@ -542,41 +542,13 @@ static const struct iio_buffer_setup_ops ad7192_ring_setup_ops = {
 
 static int ad7192_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 {
-	int ret;
-
-	indio_dev->buffer = iio_kfifo_allocate(indio_dev);
-	if (!indio_dev->buffer) {
-		ret = -ENOMEM;
-		goto error_ret;
-	}
-	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
-						 &ad7192_trigger_handler,
-						 IRQF_ONESHOT,
-						 indio_dev,
-						 "ad7192_consumer%d",
-						 indio_dev->id);
-	if (indio_dev->pollfunc == NULL) {
-		ret = -ENOMEM;
-		goto error_deallocate_kfifo;
-	}
-
-	/* Ring buffer functions - here trigger setup related */
-	indio_dev->setup_ops = &ad7192_ring_setup_ops;
-
-	/* Flag that polled ring buffering is possible */
-	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
-	return 0;
-
-error_deallocate_kfifo:
-	iio_kfifo_free(indio_dev->buffer);
-error_ret:
-	return ret;
+	return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
+			&ad7192_trigger_handler, &ad7192_ring_setup_ops);
 }
 
 static void ad7192_ring_cleanup(struct iio_dev *indio_dev)
 {
-	iio_dealloc_pollfunc(indio_dev->pollfunc);
-	iio_kfifo_free(indio_dev->buffer);
+	iio_triggered_buffer_cleanup(indio_dev);
 }
 
 /**
@@ -1077,23 +1049,15 @@ static int __devinit ad7192_probe(struct spi_device *spi)
 	if (ret)
 		goto error_ring_cleanup;
 
-	ret = iio_buffer_register(indio_dev,
-				  indio_dev->channels,
-				  indio_dev->num_channels);
-	if (ret)
-		goto error_remove_trigger;
-
 	ret = ad7192_setup(st);
 	if (ret)
-		goto error_unreg_ring;
+		goto error_remove_trigger;
 
 	ret = iio_device_register(indio_dev);
 	if (ret < 0)
-		goto error_unreg_ring;
+		goto error_remove_trigger;
 	return 0;
 
-error_unreg_ring:
-	iio_buffer_unregister(indio_dev);
 error_remove_trigger:
 	ad7192_remove_trigger(indio_dev);
 error_ring_cleanup:
@@ -1116,7 +1080,6 @@ static int ad7192_remove(struct spi_device *spi)
 	struct ad7192_state *st = iio_priv(indio_dev);
 
 	iio_device_unregister(indio_dev);
-	iio_buffer_unregister(indio_dev);
 	ad7192_remove_trigger(indio_dev);
 	ad7192_ring_cleanup(indio_dev);
 
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [v2 4/9] staging:iio:adc:ad7298: Use new triggered buffer setup helper function
  2012-06-08  8:48 [v2 1/9] staging:iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
  2012-06-08  8:48 ` [v2 2/9] iio:adc:at91: Use new triggered buffer setup helper Lars-Peter Clausen
  2012-06-08  8:48 ` [v2 3/9] staging:iio:adc:ad7192: Use new triggered buffer setup helper function Lars-Peter Clausen
@ 2012-06-08  8:48 ` Lars-Peter Clausen
  2012-06-18  9:45   ` Lars-Peter Clausen
  2012-06-08  8:48 ` [v2 5/9] staging:iio:adc:ad7476: " Lars-Peter Clausen
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 19+ messages in thread
From: Lars-Peter Clausen @ 2012-06-08  8:48 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Use the new triggered buffer setup helper function to allocate and register
buffer and pollfunc.

Also as part of the conversion drop scan_timestamp being enabled by default,
since it is a left over of an earlier cleanup.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/adc/Kconfig       |    1 +
 drivers/staging/iio/adc/ad7298.h      |    5 +++
 drivers/staging/iio/adc/ad7298_core.c |   11 ++----
 drivers/staging/iio/adc/ad7298_ring.c |   64 ++++++---------------------------
 4 files changed, 18 insertions(+), 63 deletions(-)

diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index c01df61..bb6fffd 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -13,6 +13,7 @@ config AD7291
 config AD7298
 	tristate "Analog Devices AD7298 ADC driver"
 	depends on SPI
+	select IIO_TRIGGERED_BUFFER if IIO_BUFFER
 	help
 	  Say yes here to build support for Analog Devices AD7298
 	  8 Channel ADC with temperature sensor.
diff --git a/drivers/staging/iio/adc/ad7298.h b/drivers/staging/iio/adc/ad7298.h
index 5051a7e..18f2787 100644
--- a/drivers/staging/iio/adc/ad7298.h
+++ b/drivers/staging/iio/adc/ad7298.h
@@ -55,6 +55,8 @@ struct ad7298_state {
 #ifdef CONFIG_IIO_BUFFER
 int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev);
 void ad7298_ring_cleanup(struct iio_dev *indio_dev);
+int ad7298_update_scan_mode(struct iio_dev *indio_dev,
+	const unsigned long *active_scan_mask);
 #else /* CONFIG_IIO_BUFFER */
 
 static inline int
@@ -66,5 +68,8 @@ ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 static inline void ad7298_ring_cleanup(struct iio_dev *indio_dev)
 {
 }
+
+#define ad7298_update_scan_mode NULL
+
 #endif /* CONFIG_IIO_BUFFER */
 #endif /* IIO_ADC_AD7298_H_ */
diff --git a/drivers/staging/iio/adc/ad7298_core.c b/drivers/staging/iio/adc/ad7298_core.c
index c90f2b3..5e68bad 100644
--- a/drivers/staging/iio/adc/ad7298_core.c
+++ b/drivers/staging/iio/adc/ad7298_core.c
@@ -171,6 +171,7 @@ static int ad7298_read_raw(struct iio_dev *indio_dev,
 
 static const struct iio_info ad7298_info = {
 	.read_raw = &ad7298_read_raw,
+	.update_scan_mode = ad7298_update_scan_mode,
 	.driver_module = THIS_MODULE,
 };
 
@@ -231,19 +232,12 @@ static int __devinit ad7298_probe(struct spi_device *spi)
 	if (ret)
 		goto error_disable_reg;
 
-	ret = iio_buffer_register(indio_dev,
-				  &ad7298_channels[1], /* skip temp0 */
-				  ARRAY_SIZE(ad7298_channels) - 1);
-	if (ret)
-		goto error_cleanup_ring;
 	ret = iio_device_register(indio_dev);
 	if (ret)
-		goto error_unregister_ring;
+		goto error_cleanup_ring;
 
 	return 0;
 
-error_unregister_ring:
-	iio_buffer_unregister(indio_dev);
 error_cleanup_ring:
 	ad7298_ring_cleanup(indio_dev);
 error_disable_reg:
@@ -263,7 +257,6 @@ static int __devexit ad7298_remove(struct spi_device *spi)
 	struct ad7298_state *st = iio_priv(indio_dev);
 
 	iio_device_unregister(indio_dev);
-	iio_buffer_unregister(indio_dev);
 	ad7298_ring_cleanup(indio_dev);
 	if (!IS_ERR(st->reg)) {
 		regulator_disable(st->reg);
diff --git a/drivers/staging/iio/adc/ad7298_ring.c b/drivers/staging/iio/adc/ad7298_ring.c
index 908a3e5..cd3e9cb 100644
--- a/drivers/staging/iio/adc/ad7298_ring.c
+++ b/drivers/staging/iio/adc/ad7298_ring.c
@@ -13,37 +13,29 @@
 
 #include <linux/iio/iio.h>
 #include <linux/iio/buffer.h>
-#include <linux/iio/kfifo_buf.h>
 #include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
 
 #include "ad7298.h"
 
 /**
- * ad7298_ring_preenable() setup the parameters of the ring before enabling
- *
- * The complex nature of the setting of the number of bytes per datum is due
- * to this driver currently ensuring that the timestamp is stored at an 8
- * byte boundary.
+ * ad7298_update_scan_mode() setup the spi transfer buffer for the new scan mask
  **/
-static int ad7298_ring_preenable(struct iio_dev *indio_dev)
+int ad7298_update_scan_mode(struct iio_dev *indio_dev,
+	const unsigned long *active_scan_mask)
 {
 	struct ad7298_state *st = iio_priv(indio_dev);
 	int i, m;
 	unsigned short command;
-	int scan_count, ret;
-
-	ret = iio_sw_buffer_preenable(indio_dev);
-	if (ret < 0)
-		return ret;
+	int scan_count;
 
 	/* Now compute overall size */
-	scan_count = bitmap_weight(indio_dev->active_scan_mask,
-				   indio_dev->masklength);
+	scan_count = bitmap_weight(active_scan_mask, indio_dev->masklength);
 
 	command = AD7298_WRITE | st->ext_ref;
 
 	for (i = 0, m = AD7298_CH(0); i < AD7298_MAX_CHAN; i++, m >>= 1)
-		if (test_bit(i, indio_dev->active_scan_mask))
+		if (test_bit(i, active_scan_mask))
 			command |= m;
 
 	st->tx_buf[0] = cpu_to_be16(command);
@@ -108,49 +100,13 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
 	return IRQ_HANDLED;
 }
 
-static const struct iio_buffer_setup_ops ad7298_ring_setup_ops = {
-	.preenable = &ad7298_ring_preenable,
-	.postenable = &iio_triggered_buffer_postenable,
-	.predisable = &iio_triggered_buffer_predisable,
-};
-
 int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 {
-	int ret;
-
-	indio_dev->buffer = iio_kfifo_allocate(indio_dev);
-	if (!indio_dev->buffer) {
-		ret = -ENOMEM;
-		goto error_ret;
-	}
-	indio_dev->pollfunc = iio_alloc_pollfunc(NULL,
-						 &ad7298_trigger_handler,
-						 IRQF_ONESHOT,
-						 indio_dev,
-						 "ad7298_consumer%d",
-						 indio_dev->id);
-
-	if (indio_dev->pollfunc == NULL) {
-		ret = -ENOMEM;
-		goto error_deallocate_kfifo;
-	}
-
-	/* Ring buffer functions - here trigger setup related */
-	indio_dev->setup_ops = &ad7298_ring_setup_ops;
-	indio_dev->buffer->scan_timestamp = true;
-
-	/* Flag that polled ring buffering is possible */
-	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
-	return 0;
-
-error_deallocate_kfifo:
-	iio_kfifo_free(indio_dev->buffer);
-error_ret:
-	return ret;
+	return iio_triggered_buffer_setup(indio_dev, NULL,
+			&ad7298_trigger_handler, NULL);
 }
 
 void ad7298_ring_cleanup(struct iio_dev *indio_dev)
 {
-	iio_dealloc_pollfunc(indio_dev->pollfunc);
-	iio_kfifo_free(indio_dev->buffer);
+	iio_triggered_buffer_cleanup(indio_dev);
 }
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [v2 5/9] staging:iio:adc:ad7476: Use new triggered buffer setup helper function
  2012-06-08  8:48 [v2 1/9] staging:iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
                   ` (2 preceding siblings ...)
  2012-06-08  8:48 ` [v2 4/9] staging:iio:adc:ad7298: " Lars-Peter Clausen
@ 2012-06-08  8:48 ` Lars-Peter Clausen
  2012-06-08  8:48 ` [v2 6/9] staging:iio:adc:ad7606: " Lars-Peter Clausen
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: Lars-Peter Clausen @ 2012-06-08  8:48 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Use the new triggered buffer setup helper function to allocate and register
buffer and pollfunc.

Also as part of the conversion drop scan_timestamp being enabled by default,
since it is a left over of an earlier cleanup.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/adc/Kconfig       |    3 +--
 drivers/staging/iio/adc/ad7476_core.c |    9 -------
 drivers/staging/iio/adc/ad7476_ring.c |   46 +++------------------------------
 3 files changed, 5 insertions(+), 53 deletions(-)

diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index bb6fffd..c5f5651 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -73,8 +73,7 @@ config AD7476
 	tristate "Analog Devices AD7475/6/7/8 AD7466/7/8 and AD7495 ADC driver"
 	depends on SPI
 	select IIO_BUFFER
-	select IIO_KFIFO_BUF
-	select IIO_TRIGGER
+	select IIO_TRIGGERED_BUFFER
 	help
 	  Say yes here to build support for Analog Devices
 	  AD7475, AD7476, AD7477, AD7478, AD7466, AD7467, AD7468, AD7495
diff --git a/drivers/staging/iio/adc/ad7476_core.c b/drivers/staging/iio/adc/ad7476_core.c
index be1c260..4d30a79 100644
--- a/drivers/staging/iio/adc/ad7476_core.c
+++ b/drivers/staging/iio/adc/ad7476_core.c
@@ -177,20 +177,12 @@ static int __devinit ad7476_probe(struct spi_device *spi)
 	if (ret)
 		goto error_disable_reg;
 
-	ret = iio_buffer_register(indio_dev,
-				  st->chip_info->channel,
-				  ARRAY_SIZE(st->chip_info->channel));
-	if (ret)
-		goto error_cleanup_ring;
-
 	ret = iio_device_register(indio_dev);
 	if (ret)
 		goto error_ring_unregister;
 	return 0;
 
 error_ring_unregister:
-	iio_buffer_unregister(indio_dev);
-error_cleanup_ring:
 	ad7476_ring_cleanup(indio_dev);
 error_disable_reg:
 	if (!IS_ERR(st->reg))
@@ -210,7 +202,6 @@ static int ad7476_remove(struct spi_device *spi)
 	struct ad7476_state *st = iio_priv(indio_dev);
 
 	iio_device_unregister(indio_dev);
-	iio_buffer_unregister(indio_dev);
 	ad7476_ring_cleanup(indio_dev);
 	if (!IS_ERR(st->reg)) {
 		regulator_disable(st->reg);
diff --git a/drivers/staging/iio/adc/ad7476_ring.c b/drivers/staging/iio/adc/ad7476_ring.c
index 383611b..10f8b8d 100644
--- a/drivers/staging/iio/adc/ad7476_ring.c
+++ b/drivers/staging/iio/adc/ad7476_ring.c
@@ -15,8 +15,8 @@
 
 #include <linux/iio/iio.h>
 #include <linux/iio/buffer.h>
-#include <linux/iio/kfifo_buf.h>
 #include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
 
 #include "ad7476.h"
 
@@ -52,51 +52,13 @@ done:
 	return IRQ_HANDLED;
 }
 
-static const struct iio_buffer_setup_ops ad7476_ring_setup_ops = {
-	.preenable = &iio_sw_buffer_preenable,
-	.postenable = &iio_triggered_buffer_postenable,
-	.predisable = &iio_triggered_buffer_predisable,
-};
-
 int ad7476_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 {
-	struct ad7476_state *st = iio_priv(indio_dev);
-	int ret = 0;
-
-	indio_dev->buffer = iio_kfifo_allocate(indio_dev);
-	if (!indio_dev->buffer) {
-		ret = -ENOMEM;
-		goto error_ret;
-	}
-	indio_dev->pollfunc
-		= iio_alloc_pollfunc(NULL,
-				     &ad7476_trigger_handler,
-				     IRQF_ONESHOT,
-				     indio_dev,
-				     "%s_consumer%d",
-				     spi_get_device_id(st->spi)->name,
-				     indio_dev->id);
-	if (indio_dev->pollfunc == NULL) {
-		ret = -ENOMEM;
-		goto error_deallocate_kfifo;
-	}
-
-	/* Ring buffer functions - here trigger setup related */
-	indio_dev->setup_ops = &ad7476_ring_setup_ops;
-	indio_dev->buffer->scan_timestamp = true;
-
-	/* Flag that polled ring buffering is possible */
-	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
-	return 0;
-
-error_deallocate_kfifo:
-	iio_kfifo_free(indio_dev->buffer);
-error_ret:
-	return ret;
+	return iio_triggered_buffer_setup(indio_dev, NULL,
+			&ad7476_trigger_handler, NULL);
 }
 
 void ad7476_ring_cleanup(struct iio_dev *indio_dev)
 {
-	iio_dealloc_pollfunc(indio_dev->pollfunc);
-	iio_kfifo_free(indio_dev->buffer);
+	iio_triggered_buffer_cleanup(indio_dev);
 }
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [v2 6/9] staging:iio:adc:ad7606: Use new triggered buffer setup helper function
  2012-06-08  8:48 [v2 1/9] staging:iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
                   ` (3 preceding siblings ...)
  2012-06-08  8:48 ` [v2 5/9] staging:iio:adc:ad7476: " Lars-Peter Clausen
@ 2012-06-08  8:48 ` Lars-Peter Clausen
  2012-06-08  8:48 ` [v2 7/9] staging:iio:adc:ad7793: " Lars-Peter Clausen
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: Lars-Peter Clausen @ 2012-06-08  8:48 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Use the new triggered buffer setup helper function to allocate and register
buffer and pollfunc.

Also as part of the conversion drop scan_timestamp being enabled by default,
since it is a left over of an earlier cleanup.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/adc/Kconfig       |    3 +--
 drivers/staging/iio/adc/ad7606_core.c |    9 -------
 drivers/staging/iio/adc/ad7606_ring.c |   46 ++++-----------------------------
 3 files changed, 6 insertions(+), 52 deletions(-)

diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index c5f5651..ca46627 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -25,8 +25,7 @@ config AD7606
 	tristate "Analog Devices AD7606 ADC driver"
 	depends on GPIOLIB
 	select IIO_BUFFER
-	select IIO_TRIGGER
-	select IIO_KFIFO_BUF
+	select IIO_TRIGGERED_BUFFER
 	help
 	  Say yes here to build support for Analog Devices:
 	  ad7606, ad7606-6, ad7606-4 analog to digital converters (ADC).
diff --git a/drivers/staging/iio/adc/ad7606_core.c b/drivers/staging/iio/adc/ad7606_core.c
index 10ab6dc..954ac3e 100644
--- a/drivers/staging/iio/adc/ad7606_core.c
+++ b/drivers/staging/iio/adc/ad7606_core.c
@@ -532,20 +532,12 @@ struct iio_dev *ad7606_probe(struct device *dev, int irq,
 	if (ret)
 		goto error_free_irq;
 
-	ret = iio_buffer_register(indio_dev,
-				  indio_dev->channels,
-				  indio_dev->num_channels);
-	if (ret)
-		goto error_cleanup_ring;
 	ret = iio_device_register(indio_dev);
 	if (ret)
 		goto error_unregister_ring;
 
 	return indio_dev;
 error_unregister_ring:
-	iio_buffer_unregister(indio_dev);
-
-error_cleanup_ring:
 	ad7606_ring_cleanup(indio_dev);
 
 error_free_irq:
@@ -570,7 +562,6 @@ int ad7606_remove(struct iio_dev *indio_dev, int irq)
 	struct ad7606_state *st = iio_priv(indio_dev);
 
 	iio_device_unregister(indio_dev);
-	iio_buffer_unregister(indio_dev);
 	ad7606_ring_cleanup(indio_dev);
 
 	free_irq(irq, indio_dev);
diff --git a/drivers/staging/iio/adc/ad7606_ring.c b/drivers/staging/iio/adc/ad7606_ring.c
index 24ce8fc..f15afe4 100644
--- a/drivers/staging/iio/adc/ad7606_ring.c
+++ b/drivers/staging/iio/adc/ad7606_ring.c
@@ -13,8 +13,8 @@
 
 #include <linux/iio/iio.h>
 #include <linux/iio/buffer.h>
-#include <linux/iio/kfifo_buf.h>
 #include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
 
 #include "ad7606.h"
 
@@ -91,54 +91,18 @@ done:
 	kfree(buf);
 }
 
-static const struct iio_buffer_setup_ops ad7606_ring_setup_ops = {
-	.preenable = &iio_sw_buffer_preenable,
-	.postenable = &iio_triggered_buffer_postenable,
-	.predisable = &iio_triggered_buffer_predisable,
-};
-
 int ad7606_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 {
 	struct ad7606_state *st = iio_priv(indio_dev);
-	int ret;
-
-	indio_dev->buffer = iio_kfifo_allocate(indio_dev);
-	if (!indio_dev->buffer) {
-		ret = -ENOMEM;
-		goto error_ret;
-	}
-
-	indio_dev->pollfunc = iio_alloc_pollfunc(&ad7606_trigger_handler_th_bh,
-						 &ad7606_trigger_handler_th_bh,
-						 0,
-						 indio_dev,
-						 "%s_consumer%d",
-						 indio_dev->name,
-						 indio_dev->id);
-	if (indio_dev->pollfunc == NULL) {
-		ret = -ENOMEM;
-		goto error_deallocate_kfifo;
-	}
-
-	/* Ring buffer functions - here trigger setup related */
-
-	indio_dev->setup_ops = &ad7606_ring_setup_ops;
-	indio_dev->buffer->scan_timestamp = true;
 
 	INIT_WORK(&st->poll_work, &ad7606_poll_bh_to_ring);
 
-	/* Flag that polled ring buffering is possible */
-	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
-	return 0;
-
-error_deallocate_kfifo:
-	iio_kfifo_free(indio_dev->buffer);
-error_ret:
-	return ret;
+	return iio_triggered_buffer_setup(indio_dev,
+		&ad7606_trigger_handler_th_bh, &ad7606_trigger_handler_th_bh,
+		NULL);
 }
 
 void ad7606_ring_cleanup(struct iio_dev *indio_dev)
 {
-	iio_dealloc_pollfunc(indio_dev->pollfunc);
-	iio_kfifo_free(indio_dev->buffer);
+	iio_triggered_buffer_cleanup(indio_dev);
 }
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [v2 7/9] staging:iio:adc:ad7793: Use new triggered buffer setup helper function
  2012-06-08  8:48 [v2 1/9] staging:iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
                   ` (4 preceding siblings ...)
  2012-06-08  8:48 ` [v2 6/9] staging:iio:adc:ad7606: " Lars-Peter Clausen
@ 2012-06-08  8:48 ` Lars-Peter Clausen
  2012-06-08  8:48 ` [v2 8/9] staging:iio:adc:ad7887: " Lars-Peter Clausen
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: Lars-Peter Clausen @ 2012-06-08  8:48 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Use the new triggered buffer setup helper function to allocate and register
buffer and pollfunc.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/adc/Kconfig  |    3 +--
 drivers/staging/iio/adc/ad7793.c |   49 +++++---------------------------------
 2 files changed, 7 insertions(+), 45 deletions(-)

diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index ca46627..4fcc4be 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -112,8 +112,7 @@ config AD7793
 	tristate "Analog Devices AD7792 AD7793 ADC driver"
 	depends on SPI
 	select IIO_BUFFER
-	select IIO_KFIFO_BUF
-	select IIO_TRIGGER
+	select IIO_TRIGGERED_BUFFER
 	help
 	  Say yes here to build support for Analog Devices
 	  AD7792 and AD7793 SPI analog to digital converters (ADC).
diff --git a/drivers/staging/iio/adc/ad7793.c b/drivers/staging/iio/adc/ad7793.c
index b36556f..2bb9f68 100644
--- a/drivers/staging/iio/adc/ad7793.c
+++ b/drivers/staging/iio/adc/ad7793.c
@@ -21,9 +21,9 @@
 #include <linux/iio/iio.h>
 #include <linux/iio/sysfs.h>
 #include <linux/iio/buffer.h>
-#include <linux/iio/kfifo_buf.h>
 #include <linux/iio/trigger.h>
 #include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
 
 #include "ad7793.h"
 
@@ -407,41 +407,13 @@ static const struct iio_buffer_setup_ops ad7793_ring_setup_ops = {
 
 static int ad7793_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 {
-	int ret;
-
-	indio_dev->buffer = iio_kfifo_allocate(indio_dev);
-	if (!indio_dev->buffer) {
-		ret = -ENOMEM;
-		goto error_ret;
-	}
-	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
-						 &ad7793_trigger_handler,
-						 IRQF_ONESHOT,
-						 indio_dev,
-						 "ad7793_consumer%d",
-						 indio_dev->id);
-	if (indio_dev->pollfunc == NULL) {
-		ret = -ENOMEM;
-		goto error_deallocate_kfifo;
-	}
-
-	/* Ring buffer functions - here trigger setup related */
-	indio_dev->setup_ops = &ad7793_ring_setup_ops;
-
-	/* Flag that polled ring buffering is possible */
-	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
-	return 0;
-
-error_deallocate_kfifo:
-	iio_kfifo_free(indio_dev->buffer);
-error_ret:
-	return ret;
+	return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
+			&ad7793_trigger_handler, &ad7793_ring_setup_ops);
 }
 
 static void ad7793_ring_cleanup(struct iio_dev *indio_dev)
 {
-	iio_dealloc_pollfunc(indio_dev->pollfunc);
-	iio_kfifo_free(indio_dev->buffer);
+	iio_triggered_buffer_cleanup(indio_dev);
 }
 
 /**
@@ -959,24 +931,16 @@ static int __devinit ad7793_probe(struct spi_device *spi)
 	if (ret)
 		goto error_unreg_ring;
 
-	ret = iio_buffer_register(indio_dev,
-				  indio_dev->channels,
-				  indio_dev->num_channels);
-	if (ret)
-		goto error_remove_trigger;
-
 	ret = ad7793_setup(st);
 	if (ret)
-		goto error_uninitialize_ring;
+		goto error_remove_trigger;
 
 	ret = iio_device_register(indio_dev);
 	if (ret)
-		goto error_uninitialize_ring;
+		goto error_remove_trigger;
 
 	return 0;
 
-error_uninitialize_ring:
-	iio_buffer_unregister(indio_dev);
 error_remove_trigger:
 	ad7793_remove_trigger(indio_dev);
 error_unreg_ring:
@@ -999,7 +963,6 @@ static int ad7793_remove(struct spi_device *spi)
 	struct ad7793_state *st = iio_priv(indio_dev);
 
 	iio_device_unregister(indio_dev);
-	iio_buffer_unregister(indio_dev);
 	ad7793_remove_trigger(indio_dev);
 	ad7793_ring_cleanup(indio_dev);
 
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [v2 8/9] staging:iio:adc:ad7887: Use new triggered buffer setup helper function
  2012-06-08  8:48 [v2 1/9] staging:iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
                   ` (5 preceding siblings ...)
  2012-06-08  8:48 ` [v2 7/9] staging:iio:adc:ad7793: " Lars-Peter Clausen
@ 2012-06-08  8:48 ` Lars-Peter Clausen
  2012-06-08  8:48 ` [v2 9/9] staging:iio:adc:ad799x: " Lars-Peter Clausen
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 19+ messages in thread
From: Lars-Peter Clausen @ 2012-06-08  8:48 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Use the new triggered buffer setup helper function to allocate and register
buffer and pollfunc.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/adc/Kconfig       |    3 +--
 drivers/staging/iio/adc/ad7887_core.c |    9 ---------
 drivers/staging/iio/adc/ad7887_ring.c |   35 ++++-----------------------------
 3 files changed, 5 insertions(+), 42 deletions(-)

diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 4fcc4be..e3fdb84 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -86,8 +86,7 @@ config AD7887
 	tristate "Analog Devices AD7887 ADC driver"
 	depends on SPI
 	select IIO_BUFFER
-	select IIO_KFIFO_BUF
-	select IIO_TRIGGER
+	select IIO_TRIGGERED_BUFFER
 	help
 	  Say yes here to build support for Analog Devices
 	  AD7887 SPI analog to digital converter (ADC).
diff --git a/drivers/staging/iio/adc/ad7887_core.c b/drivers/staging/iio/adc/ad7887_core.c
index 7186074..397b849 100644
--- a/drivers/staging/iio/adc/ad7887_core.c
+++ b/drivers/staging/iio/adc/ad7887_core.c
@@ -201,20 +201,12 @@ static int __devinit ad7887_probe(struct spi_device *spi)
 	if (ret)
 		goto error_disable_reg;
 
-	ret = iio_buffer_register(indio_dev,
-				  indio_dev->channels,
-				  indio_dev->num_channels);
-	if (ret)
-		goto error_cleanup_ring;
-
 	ret = iio_device_register(indio_dev);
 	if (ret)
 		goto error_unregister_ring;
 
 	return 0;
 error_unregister_ring:
-	iio_buffer_unregister(indio_dev);
-error_cleanup_ring:
 	ad7887_ring_cleanup(indio_dev);
 error_disable_reg:
 	if (!IS_ERR(st->reg))
@@ -233,7 +225,6 @@ static int ad7887_remove(struct spi_device *spi)
 	struct ad7887_state *st = iio_priv(indio_dev);
 
 	iio_device_unregister(indio_dev);
-	iio_buffer_unregister(indio_dev);
 	ad7887_ring_cleanup(indio_dev);
 	if (!IS_ERR(st->reg)) {
 		regulator_disable(st->reg);
diff --git a/drivers/staging/iio/adc/ad7887_ring.c b/drivers/staging/iio/adc/ad7887_ring.c
index fd91384..1c406da 100644
--- a/drivers/staging/iio/adc/ad7887_ring.c
+++ b/drivers/staging/iio/adc/ad7887_ring.c
@@ -14,8 +14,8 @@
 
 #include <linux/iio/iio.h>
 #include <linux/iio/buffer.h>
-#include <linux/iio/kfifo_buf.h>
 #include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
 
 #include "ad7887.h"
 
@@ -112,38 +112,11 @@ static const struct iio_buffer_setup_ops ad7887_ring_setup_ops = {
 
 int ad7887_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 {
-	int ret;
-
-	indio_dev->buffer = iio_kfifo_allocate(indio_dev);
-	if (!indio_dev->buffer) {
-		ret = -ENOMEM;
-		goto error_ret;
-	}
-	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
-						 &ad7887_trigger_handler,
-						 IRQF_ONESHOT,
-						 indio_dev,
-						 "ad7887_consumer%d",
-						 indio_dev->id);
-	if (indio_dev->pollfunc == NULL) {
-		ret = -ENOMEM;
-		goto error_deallocate_kfifo;
-	}
-	/* Ring buffer functions - here trigger setup related */
-	indio_dev->setup_ops = &ad7887_ring_setup_ops;
-
-	/* Flag that polled ring buffering is possible */
-	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
-	return 0;
-
-error_deallocate_kfifo:
-	iio_kfifo_free(indio_dev->buffer);
-error_ret:
-	return ret;
+	return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
+			&ad7887_trigger_handler, &ad7887_ring_setup_ops);
 }
 
 void ad7887_ring_cleanup(struct iio_dev *indio_dev)
 {
-	iio_dealloc_pollfunc(indio_dev->pollfunc);
-	iio_kfifo_free(indio_dev->buffer);
+	iio_triggered_buffer_cleanup(indio_dev);
 }
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [v2 9/9] staging:iio:adc:ad799x: Use new triggered buffer setup helper function
  2012-06-08  8:48 [v2 1/9] staging:iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
                   ` (6 preceding siblings ...)
  2012-06-08  8:48 ` [v2 8/9] staging:iio:adc:ad7887: " Lars-Peter Clausen
@ 2012-06-08  8:48 ` Lars-Peter Clausen
  2012-06-08 11:36 ` [v2 1/9] staging:iio: Add helper function for initializing triggered buffers Jonathan Cameron
  2012-06-08 12:13 ` [PATCG v3 " Lars-Peter Clausen
  9 siblings, 0 replies; 19+ messages in thread
From: Lars-Peter Clausen @ 2012-06-08  8:48 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Use the new triggered buffer setup helper function to allocate and register
buffer and pollfunc.

Also as part of the conversion drop scan_timestamp being enabled by default,
since it is a left over of an earlier cleanup.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/adc/Kconfig       |    2 +-
 drivers/staging/iio/adc/ad799x.h      |    2 -
 drivers/staging/iio/adc/ad799x_core.c |   25 ++++++++-----
 drivers/staging/iio/adc/ad799x_ring.c |   65 ++-------------------------------
 4 files changed, 20 insertions(+), 74 deletions(-)

diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index e3fdb84..67711b7 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -63,7 +63,7 @@ config AD799X_RING_BUFFER
 	bool "Analog Devices AD799x: use ring buffer"
 	depends on AD799X
 	select IIO_BUFFER
-	select IIO_KFIFO_BUF
+	select IIO_TRIGGERED_BUFFER
 	help
 	  Say yes here to include ring buffer support in the AD799X
 	  ADC driver.
diff --git a/drivers/staging/iio/adc/ad799x.h b/drivers/staging/iio/adc/ad799x.h
index 99f8abe..3e363c4 100644
--- a/drivers/staging/iio/adc/ad799x.h
+++ b/drivers/staging/iio/adc/ad799x.h
@@ -120,8 +120,6 @@ struct ad799x_platform_data {
 	u16				vref_mv;
 };
 
-int ad7997_8_set_scan_mode(struct ad799x_state *st, unsigned mask);
-
 #ifdef CONFIG_AD799X_RING_BUFFER
 int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev);
 void ad799x_ring_cleanup(struct iio_dev *indio_dev);
diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
index 80e0c6e..2d4bda9 100644
--- a/drivers/staging/iio/adc/ad799x_core.c
+++ b/drivers/staging/iio/adc/ad799x_core.c
@@ -99,10 +99,21 @@ static int ad799x_i2c_write8(struct ad799x_state *st, u8 reg, u8 data)
 	return ret;
 }
 
-int ad7997_8_set_scan_mode(struct ad799x_state *st, unsigned mask)
+static int ad7997_8_update_scan_mode(struct iio_dev *indio_dev,
+	const unsigned long *scan_mask)
 {
-	return ad799x_i2c_write16(st, AD7998_CONF_REG,
-		st->config | (mask << AD799X_CHANNEL_SHIFT));
+	struct ad799x_state *st = iio_priv(indio_dev);
+
+	switch (st->id) {
+	case ad7997:
+	case ad7998:
+		return ad799x_i2c_write16(st, AD7998_CONF_REG,
+			st->config | (*scan_mask << AD799X_CHANNEL_SHIFT));
+	default:
+		break;
+	}
+
+	return 0;
 }
 
 static int ad799x_scan_direct(struct ad799x_state *st, unsigned ch)
@@ -442,6 +453,7 @@ static const struct iio_info ad7993_4_7_8_info = {
 	.read_event_value = &ad799x_read_event_value,
 	.write_event_value = &ad799x_write_event_value,
 	.driver_module = THIS_MODULE,
+	.update_scan_mode = ad7997_8_update_scan_mode,
 };
 
 #define AD799X_EV_MASK (IIO_EV_BIT(IIO_EV_TYPE_THRESH, IIO_EV_DIR_RISING) | \
@@ -887,12 +899,6 @@ static int __devinit ad799x_probe(struct i2c_client *client,
 	if (ret)
 		goto error_disable_reg;
 
-	ret = iio_buffer_register(indio_dev,
-				  indio_dev->channels,
-				  indio_dev->num_channels);
-	if (ret)
-		goto error_cleanup_ring;
-
 	if (client->irq > 0) {
 		ret = request_threaded_irq(client->irq,
 					   NULL,
@@ -934,7 +940,6 @@ static __devexit int ad799x_remove(struct i2c_client *client)
 	if (client->irq > 0)
 		free_irq(client->irq, indio_dev);
 
-	iio_buffer_unregister(indio_dev);
 	ad799x_ring_cleanup(indio_dev);
 	if (!IS_ERR(st->reg)) {
 		regulator_disable(st->reg);
diff --git a/drivers/staging/iio/adc/ad799x_ring.c b/drivers/staging/iio/adc/ad799x_ring.c
index 1c7ff44..0882c9e 100644
--- a/drivers/staging/iio/adc/ad799x_ring.c
+++ b/drivers/staging/iio/adc/ad799x_ring.c
@@ -18,33 +18,12 @@
 
 #include <linux/iio/iio.h>
 #include <linux/iio/buffer.h>
-#include <linux/iio/kfifo_buf.h>
 #include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
 
 #include "ad799x.h"
 
 /**
- * ad799x_ring_preenable() setup the parameters of the ring before enabling
- *
- * The complex nature of the setting of the number of bytes per datum is due
- * to this driver currently ensuring that the timestamp is stored at an 8
- * byte boundary.
- **/
-static int ad799x_ring_preenable(struct iio_dev *indio_dev)
-{
-	struct ad799x_state *st = iio_priv(indio_dev);
-	/*
-	 * Need to figure out the current mode based upon the requested
-	 * scan mask in iio_dev
-	 */
-
-	if (st->id == ad7997 || st->id == ad7998)
-		ad7997_8_set_scan_mode(st, *indio_dev->active_scan_mask);
-
-	return iio_sw_buffer_preenable(indio_dev);
-}
-
-/**
  * ad799x_trigger_handler() bh of trigger launched polling to ring buffer
  *
  * Currently there is no option in this driver to disable the saving of
@@ -110,49 +89,13 @@ out:
 	return IRQ_HANDLED;
 }
 
-static const struct iio_buffer_setup_ops ad799x_buf_setup_ops = {
-	.preenable = &ad799x_ring_preenable,
-	.postenable = &iio_triggered_buffer_postenable,
-	.predisable = &iio_triggered_buffer_predisable,
-};
-
 int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 {
-	int ret = 0;
-
-	indio_dev->buffer = iio_kfifo_allocate(indio_dev);
-	if (!indio_dev->buffer) {
-		ret = -ENOMEM;
-		goto error_ret;
-	}
-	indio_dev->pollfunc = iio_alloc_pollfunc(NULL,
-						 &ad799x_trigger_handler,
-						 IRQF_ONESHOT,
-						 indio_dev,
-						 "%s_consumer%d",
-						 indio_dev->name,
-						 indio_dev->id);
-	if (indio_dev->pollfunc == NULL) {
-		ret = -ENOMEM;
-		goto error_deallocate_kfifo;
-	}
-
-	/* Ring buffer functions - here trigger setup related */
-	indio_dev->setup_ops = &ad799x_buf_setup_ops;
-	indio_dev->buffer->scan_timestamp = true;
-
-	/* Flag that polled ring buffering is possible */
-	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
-	return 0;
-
-error_deallocate_kfifo:
-	iio_kfifo_free(indio_dev->buffer);
-error_ret:
-	return ret;
+	return iio_triggered_buffer_setup(indio_dev, NULL,
+		&ad799x_trigger_handler, NULL);
 }
 
 void ad799x_ring_cleanup(struct iio_dev *indio_dev)
 {
-	iio_dealloc_pollfunc(indio_dev->pollfunc);
-	iio_kfifo_free(indio_dev->buffer);
+	iio_triggered_buffer_cleanup(indio_dev);
 }
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [v2 1/9] staging:iio: Add helper function for initializing triggered buffers
  2012-06-08  8:48 [v2 1/9] staging:iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
                   ` (7 preceding siblings ...)
  2012-06-08  8:48 ` [v2 9/9] staging:iio:adc:ad799x: " Lars-Peter Clausen
@ 2012-06-08 11:36 ` Jonathan Cameron
  2012-06-08 12:13 ` [PATCG v3 " Lars-Peter Clausen
  9 siblings, 0 replies; 19+ messages in thread
From: Jonathan Cameron @ 2012-06-08 11:36 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: linux-iio

On 6/8/2012 9:48 AM, Lars-Peter Clausen wrote:
> Add a helper function for executing the common tasks which are usually involved
> in setting up a simple software ringbuffer. It will allocate the buffer,
> allocate the pollfunc and register the buffer.
>
> Signed-off-by: Lars-Peter Clausen<lars@metafoo.de>
>
> ---
> Changes since v1:
> 	* Move function declarations to their own header
And forgot to add said header...
> 	* Mention that iio_triggered_buffer_setup should usually be called right
> 	  before iio_device_register
> 	* Minor code cleanups
> ---
>   drivers/iio/Kconfig                         |    7 ++
>   drivers/iio/Makefile                        |    1 +
>   drivers/iio/industrialio-triggered-buffer.c |  110 +++++++++++++++++++++++++++
>   3 files changed, 118 insertions(+)
>   create mode 100644 drivers/iio/industrialio-triggered-buffer.c
>
> diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
> index 103349f..612073f 100644
> --- a/drivers/iio/Kconfig
> +++ b/drivers/iio/Kconfig
> @@ -30,6 +30,13 @@ config IIO_KFIFO_BUF
>   	  no buffer events so it is up to userspace to work out how
>   	  often to read from the buffer.
>
> +config IIO_TRIGGERED_BUFFER
> +	tristate
> +	select IIO_TRIGGER
> +	select IIO_KFIFO_BUF
> +	help
> +	  Provides helper functions for setting up triggered buffers.
> +
>   endif # IIO_BUFFER
>
>   config IIO_TRIGGER
> diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
> index c38fa2a..34309ab 100644
> --- a/drivers/iio/Makefile
> +++ b/drivers/iio/Makefile
> @@ -7,6 +7,7 @@ industrialio-y := industrialio-core.o industrialio-event.o inkern.o
>   industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o
>   industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o
>
> +obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o
>   obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
>
>   obj-y += adc/
> diff --git a/drivers/iio/industrialio-triggered-buffer.c b/drivers/iio/industrialio-triggered-buffer.c
> new file mode 100644
> index 0000000..a462a57
> --- /dev/null
> +++ b/drivers/iio/industrialio-triggered-buffer.c
> @@ -0,0 +1,110 @@
> + /*
> + * Copyright (c) 2012 Analog Devices, Inc.
> + *  Author: Lars-Peter Clausen<lars@metafoo.de>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License version 2 as published by
> + * the Free Software Foundation.
> + */
> +
> +#include<linux/kernel.h>
> +#include<linux/export.h>
> +#include<linux/module.h>
> +#include<linux/iio/iio.h>
> +#include<linux/iio/buffer.h>
> +#include<linux/iio/kfifo_buf.h>
> +#include<linux/iio/triggered_buffer.h>
> +#include<linux/iio/trigger_consumer.h>
> +
> +static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = {
> +	.preenable =&iio_sw_buffer_preenable,
> +	.postenable =&iio_triggered_buffer_postenable,
> +	.predisable =&iio_triggered_buffer_predisable,
> +};
> +
> +/**
> + * iio_triggered_buffer_setup() - Setup triggered buffer and pollfunc
> + * @indio_dev:		IIO device structure
> + * @pollfunc_bh:	Function which will be used as pollfunc bottom half
> + * @pollfunc_th:	Function which will be used as pollfunc top half
> + * @setup_ops:		Buffer setup functions to use for this device.
> + *			If NULL the default setup functions for triggered
> + *			buffers will be used.
> + *
> + * This function combines some common tasks which will normally be performed
> + * when setting up a triggered buffer. It will allocate the buffer and the
> + * pollfunc, as well as register the buffer with IIO core.
> + *
> + * Before calling this function the indio_dev structure should already be
> + * completely initialized but not yet registered. In practice this means that
> + * this function should be called right before iio_device_register().
> + *
> + * To free the resources allocated by this function
> + * iio_triggered_buffer_cleanup() should be called.
> + */
> +int iio_triggered_buffer_setup(struct iio_dev *indio_dev,
> +	irqreturn_t (*pollfunc_bh)(int irq, void *p),
> +	irqreturn_t (*pollfunc_th)(int irq, void *p),
> +	const struct iio_buffer_setup_ops *setup_ops)
> +{
> +	int ret;
> +
> +	indio_dev->buffer = iio_kfifo_allocate(indio_dev);
> +	if (!indio_dev->buffer) {
> +		ret = -ENOMEM;
> +		goto error_ret;
> +	}
> +
> +	indio_dev->pollfunc = iio_alloc_pollfunc(pollfunc_bh,
> +						 pollfunc_th,
> +						 IRQF_ONESHOT,
> +						 indio_dev,
> +						 "%s_consumer%d",
> +						 indio_dev->name,
> +						 indio_dev->id);
> +	if (indio_dev->pollfunc == NULL) {
> +		ret = -ENOMEM;
> +		goto error_kfifo_free;
> +	}
> +
> +	/* Ring buffer functions - here trigger setup related */
> +	if (setup_ops)
> +		indio_dev->setup_ops = setup_ops;
> +	else
> +		indio_dev->setup_ops =&iio_triggered_buffer_setup_ops;
> +
> +	/* Flag that polled ring buffering is possible */
> +	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
> +
> +	ret = iio_buffer_register(indio_dev,
> +				  indio_dev->channels,
> +				  indio_dev->num_channels);
> +	if (ret)
> +		goto error_dealloc_pollfunc;
> +
> +	return 0;
> +
> +error_dealloc_pollfunc:
> +	iio_dealloc_pollfunc(indio_dev->pollfunc);
> +error_kfifo_free:
> +	iio_kfifo_free(indio_dev->buffer);
> +error_ret:
> +	return ret;
> +}
> +EXPORT_SYMBOL(iio_triggered_buffer_setup);
> +
> +/**
> + * iio_triggered_buffer_cleanup() - Free resources allocated by iio_triggered_buffer_setup()
> + * @indio_dev: IIO device structure
> + */
> +void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev)
> +{
> +	iio_buffer_unregister(indio_dev);
> +	iio_dealloc_pollfunc(indio_dev->pollfunc);
> +	iio_kfifo_free(indio_dev->buffer);
> +}
> +EXPORT_SYMBOL(iio_triggered_buffer_cleanup);
> +
> +MODULE_AUTHOR("Lars-Peter Clausen<lars@metafoo.de>");
> +MODULE_DESCRIPTION("IIO helper functions for setting up triggered buffers");
> +MODULE_LICENSE("GPL");


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCG v3 1/9] staging:iio: Add helper function for initializing triggered buffers
  2012-06-08 12:13 ` [PATCG v3 " Lars-Peter Clausen
@ 2012-06-08 12:11   ` Jonathan Cameron
  0 siblings, 0 replies; 19+ messages in thread
From: Jonathan Cameron @ 2012-06-08 12:11 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: linux-iio

On 6/8/2012 1:13 PM, Lars-Peter Clausen wrote:
> Add a helper function for executing the common tasks which are usually involved
> in setting up a simple software ringbuffer. It will allocate the buffer,
> allocate the pollfunc and register the buffer.
>
> Signed-off-by: Lars-Peter Clausen<lars@metafoo.de>
Other than the patch title...

Acked-by: Jonathan Cameron <jic23@kernel.org>
>
> ---
> Changes since v2:
> 	* Add missing header...
>
> 	I've only resent this one patch for v3 since all the others are unchanged.
>
> Changes since v1:
> 	* Move function declarations to their own header
> 	* Mention that iio_triggered_buffer_setup should usually be called right
> 	  before iio_device_register
> 	* Minor code cleanups
> ---
>   drivers/iio/Kconfig                         |    7 ++
>   drivers/iio/Makefile                        |    1 +
>   drivers/iio/industrialio-triggered-buffer.c |  110 +++++++++++++++++++++++++++
>   include/linux/iio/triggered_buffer.h        |   15 ++++
>   4 files changed, 133 insertions(+)
>   create mode 100644 drivers/iio/industrialio-triggered-buffer.c
>   create mode 100644 include/linux/iio/triggered_buffer.h
>
> diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
> index 103349f..612073f 100644
> --- a/drivers/iio/Kconfig
> +++ b/drivers/iio/Kconfig
> @@ -30,6 +30,13 @@ config IIO_KFIFO_BUF
>   	  no buffer events so it is up to userspace to work out how
>   	  often to read from the buffer.
>
> +config IIO_TRIGGERED_BUFFER
> +	tristate
> +	select IIO_TRIGGER
> +	select IIO_KFIFO_BUF
> +	help
> +	  Provides helper functions for setting up triggered buffers.
> +
>   endif # IIO_BUFFER
>
>   config IIO_TRIGGER
> diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
> index c38fa2a..34309ab 100644
> --- a/drivers/iio/Makefile
> +++ b/drivers/iio/Makefile
> @@ -7,6 +7,7 @@ industrialio-y := industrialio-core.o industrialio-event.o inkern.o
>   industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o
>   industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o
>
> +obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o
>   obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
>
>   obj-y += adc/
> diff --git a/drivers/iio/industrialio-triggered-buffer.c b/drivers/iio/industrialio-triggered-buffer.c
> new file mode 100644
> index 0000000..a462a57
> --- /dev/null
> +++ b/drivers/iio/industrialio-triggered-buffer.c
> @@ -0,0 +1,110 @@
> + /*
> + * Copyright (c) 2012 Analog Devices, Inc.
> + *  Author: Lars-Peter Clausen<lars@metafoo.de>
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU General Public License version 2 as published by
> + * the Free Software Foundation.
> + */
> +
> +#include<linux/kernel.h>
> +#include<linux/export.h>
> +#include<linux/module.h>
> +#include<linux/iio/iio.h>
> +#include<linux/iio/buffer.h>
> +#include<linux/iio/kfifo_buf.h>
> +#include<linux/iio/triggered_buffer.h>
> +#include<linux/iio/trigger_consumer.h>
> +
> +static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = {
> +	.preenable =&iio_sw_buffer_preenable,
> +	.postenable =&iio_triggered_buffer_postenable,
> +	.predisable =&iio_triggered_buffer_predisable,
> +};
> +
> +/**
> + * iio_triggered_buffer_setup() - Setup triggered buffer and pollfunc
> + * @indio_dev:		IIO device structure
> + * @pollfunc_bh:	Function which will be used as pollfunc bottom half
> + * @pollfunc_th:	Function which will be used as pollfunc top half
> + * @setup_ops:		Buffer setup functions to use for this device.
> + *			If NULL the default setup functions for triggered
> + *			buffers will be used.
> + *
> + * This function combines some common tasks which will normally be performed
> + * when setting up a triggered buffer. It will allocate the buffer and the
> + * pollfunc, as well as register the buffer with IIO core.
> + *
> + * Before calling this function the indio_dev structure should already be
> + * completely initialized but not yet registered. In practice this means that
> + * this function should be called right before iio_device_register().
> + *
> + * To free the resources allocated by this function
> + * iio_triggered_buffer_cleanup() should be called.
> + */
> +int iio_triggered_buffer_setup(struct iio_dev *indio_dev,
> +	irqreturn_t (*pollfunc_bh)(int irq, void *p),
> +	irqreturn_t (*pollfunc_th)(int irq, void *p),
> +	const struct iio_buffer_setup_ops *setup_ops)
> +{
> +	int ret;
> +
> +	indio_dev->buffer = iio_kfifo_allocate(indio_dev);
> +	if (!indio_dev->buffer) {
> +		ret = -ENOMEM;
> +		goto error_ret;
> +	}
> +
> +	indio_dev->pollfunc = iio_alloc_pollfunc(pollfunc_bh,
> +						 pollfunc_th,
> +						 IRQF_ONESHOT,
> +						 indio_dev,
> +						 "%s_consumer%d",
> +						 indio_dev->name,
> +						 indio_dev->id);
> +	if (indio_dev->pollfunc == NULL) {
> +		ret = -ENOMEM;
> +		goto error_kfifo_free;
> +	}
> +
> +	/* Ring buffer functions - here trigger setup related */
> +	if (setup_ops)
> +		indio_dev->setup_ops = setup_ops;
> +	else
> +		indio_dev->setup_ops =&iio_triggered_buffer_setup_ops;
> +
> +	/* Flag that polled ring buffering is possible */
> +	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
> +
> +	ret = iio_buffer_register(indio_dev,
> +				  indio_dev->channels,
> +				  indio_dev->num_channels);
> +	if (ret)
> +		goto error_dealloc_pollfunc;
> +
> +	return 0;
> +
> +error_dealloc_pollfunc:
> +	iio_dealloc_pollfunc(indio_dev->pollfunc);
> +error_kfifo_free:
> +	iio_kfifo_free(indio_dev->buffer);
> +error_ret:
> +	return ret;
> +}
> +EXPORT_SYMBOL(iio_triggered_buffer_setup);
> +
> +/**
> + * iio_triggered_buffer_cleanup() - Free resources allocated by iio_triggered_buffer_setup()
> + * @indio_dev: IIO device structure
> + */
> +void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev)
> +{
> +	iio_buffer_unregister(indio_dev);
> +	iio_dealloc_pollfunc(indio_dev->pollfunc);
> +	iio_kfifo_free(indio_dev->buffer);
> +}
> +EXPORT_SYMBOL(iio_triggered_buffer_cleanup);
> +
> +MODULE_AUTHOR("Lars-Peter Clausen<lars@metafoo.de>");
> +MODULE_DESCRIPTION("IIO helper functions for setting up triggered buffers");
> +MODULE_LICENSE("GPL");
> diff --git a/include/linux/iio/triggered_buffer.h b/include/linux/iio/triggered_buffer.h
> new file mode 100644
> index 0000000..c378ebe
> --- /dev/null
> +++ b/include/linux/iio/triggered_buffer.h
> @@ -0,0 +1,15 @@
> +#ifndef _LINUX_IIO_TRIGGERED_BUFFER_H_
> +#define _LINUX_IIO_TRIGGERED_BUFFER_H_
> +
> +#include<linux/interrupt.h>
> +
> +struct iio_dev;
> +struct iio_buffer_setup_ops;
> +
> +int iio_triggered_buffer_setup(struct iio_dev *indio_dev,
> +	irqreturn_t (*pollfunc_bh)(int irq, void *p),
> +	irqreturn_t (*pollfunc_th)(int irq, void *p),
> +	const struct iio_buffer_setup_ops *setup_ops);
> +void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev);
> +
> +#endif


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCG v3 1/9] staging:iio: Add helper function for initializing triggered buffers
  2012-06-08  8:48 [v2 1/9] staging:iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
                   ` (8 preceding siblings ...)
  2012-06-08 11:36 ` [v2 1/9] staging:iio: Add helper function for initializing triggered buffers Jonathan Cameron
@ 2012-06-08 12:13 ` Lars-Peter Clausen
  2012-06-08 12:11   ` Jonathan Cameron
  9 siblings, 1 reply; 19+ messages in thread
From: Lars-Peter Clausen @ 2012-06-08 12:13 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

Add a helper function for executing the common tasks which are usually involved
in setting up a simple software ringbuffer. It will allocate the buffer,
allocate the pollfunc and register the buffer.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>

---
Changes since v2:
	* Add missing header...

	I've only resent this one patch for v3 since all the others are unchanged.

Changes since v1:
	* Move function declarations to their own header
	* Mention that iio_triggered_buffer_setup should usually be called right
	  before iio_device_register
	* Minor code cleanups
---
 drivers/iio/Kconfig                         |    7 ++
 drivers/iio/Makefile                        |    1 +
 drivers/iio/industrialio-triggered-buffer.c |  110 +++++++++++++++++++++++++++
 include/linux/iio/triggered_buffer.h        |   15 ++++
 4 files changed, 133 insertions(+)
 create mode 100644 drivers/iio/industrialio-triggered-buffer.c
 create mode 100644 include/linux/iio/triggered_buffer.h

diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
index 103349f..612073f 100644
--- a/drivers/iio/Kconfig
+++ b/drivers/iio/Kconfig
@@ -30,6 +30,13 @@ config IIO_KFIFO_BUF
 	  no buffer events so it is up to userspace to work out how
 	  often to read from the buffer.
 
+config IIO_TRIGGERED_BUFFER
+	tristate
+	select IIO_TRIGGER
+	select IIO_KFIFO_BUF
+	help
+	  Provides helper functions for setting up triggered buffers.
+
 endif # IIO_BUFFER
 
 config IIO_TRIGGER
diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
index c38fa2a..34309ab 100644
--- a/drivers/iio/Makefile
+++ b/drivers/iio/Makefile
@@ -7,6 +7,7 @@ industrialio-y := industrialio-core.o industrialio-event.o inkern.o
 industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o
 industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o
 
+obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o
 obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
 
 obj-y += adc/
diff --git a/drivers/iio/industrialio-triggered-buffer.c b/drivers/iio/industrialio-triggered-buffer.c
new file mode 100644
index 0000000..a462a57
--- /dev/null
+++ b/drivers/iio/industrialio-triggered-buffer.c
@@ -0,0 +1,110 @@
+ /*
+ * Copyright (c) 2012 Analog Devices, Inc.
+ *  Author: Lars-Peter Clausen <lars@metafoo.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/export.h>
+#include <linux/module.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/kfifo_buf.h>
+#include <linux/iio/triggered_buffer.h>
+#include <linux/iio/trigger_consumer.h>
+
+static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = {
+	.preenable = &iio_sw_buffer_preenable,
+	.postenable = &iio_triggered_buffer_postenable,
+	.predisable = &iio_triggered_buffer_predisable,
+};
+
+/**
+ * iio_triggered_buffer_setup() - Setup triggered buffer and pollfunc
+ * @indio_dev:		IIO device structure
+ * @pollfunc_bh:	Function which will be used as pollfunc bottom half
+ * @pollfunc_th:	Function which will be used as pollfunc top half
+ * @setup_ops:		Buffer setup functions to use for this device.
+ *			If NULL the default setup functions for triggered
+ *			buffers will be used.
+ *
+ * This function combines some common tasks which will normally be performed
+ * when setting up a triggered buffer. It will allocate the buffer and the
+ * pollfunc, as well as register the buffer with IIO core.
+ *
+ * Before calling this function the indio_dev structure should already be
+ * completely initialized but not yet registered. In practice this means that
+ * this function should be called right before iio_device_register().
+ *
+ * To free the resources allocated by this function
+ * iio_triggered_buffer_cleanup() should be called.
+ */
+int iio_triggered_buffer_setup(struct iio_dev *indio_dev,
+	irqreturn_t (*pollfunc_bh)(int irq, void *p),
+	irqreturn_t (*pollfunc_th)(int irq, void *p),
+	const struct iio_buffer_setup_ops *setup_ops)
+{
+	int ret;
+
+	indio_dev->buffer = iio_kfifo_allocate(indio_dev);
+	if (!indio_dev->buffer) {
+		ret = -ENOMEM;
+		goto error_ret;
+	}
+
+	indio_dev->pollfunc = iio_alloc_pollfunc(pollfunc_bh,
+						 pollfunc_th,
+						 IRQF_ONESHOT,
+						 indio_dev,
+						 "%s_consumer%d",
+						 indio_dev->name,
+						 indio_dev->id);
+	if (indio_dev->pollfunc == NULL) {
+		ret = -ENOMEM;
+		goto error_kfifo_free;
+	}
+
+	/* Ring buffer functions - here trigger setup related */
+	if (setup_ops)
+		indio_dev->setup_ops = setup_ops;
+	else
+		indio_dev->setup_ops = &iio_triggered_buffer_setup_ops;
+
+	/* Flag that polled ring buffering is possible */
+	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
+
+	ret = iio_buffer_register(indio_dev,
+				  indio_dev->channels,
+				  indio_dev->num_channels);
+	if (ret)
+		goto error_dealloc_pollfunc;
+
+	return 0;
+
+error_dealloc_pollfunc:
+	iio_dealloc_pollfunc(indio_dev->pollfunc);
+error_kfifo_free:
+	iio_kfifo_free(indio_dev->buffer);
+error_ret:
+	return ret;
+}
+EXPORT_SYMBOL(iio_triggered_buffer_setup);
+
+/**
+ * iio_triggered_buffer_cleanup() - Free resources allocated by iio_triggered_buffer_setup()
+ * @indio_dev: IIO device structure
+ */
+void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev)
+{
+	iio_buffer_unregister(indio_dev);
+	iio_dealloc_pollfunc(indio_dev->pollfunc);
+	iio_kfifo_free(indio_dev->buffer);
+}
+EXPORT_SYMBOL(iio_triggered_buffer_cleanup);
+
+MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
+MODULE_DESCRIPTION("IIO helper functions for setting up triggered buffers");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/iio/triggered_buffer.h b/include/linux/iio/triggered_buffer.h
new file mode 100644
index 0000000..c378ebe
--- /dev/null
+++ b/include/linux/iio/triggered_buffer.h
@@ -0,0 +1,15 @@
+#ifndef _LINUX_IIO_TRIGGERED_BUFFER_H_
+#define _LINUX_IIO_TRIGGERED_BUFFER_H_
+
+#include <linux/interrupt.h>
+
+struct iio_dev;
+struct iio_buffer_setup_ops;
+
+int iio_triggered_buffer_setup(struct iio_dev *indio_dev,
+	irqreturn_t (*pollfunc_bh)(int irq, void *p),
+	irqreturn_t (*pollfunc_th)(int irq, void *p),
+	const struct iio_buffer_setup_ops *setup_ops);
+void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev);
+
+#endif
-- 
1.7.10

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [v2 2/9] iio:adc:at91: Use new triggered buffer setup helper
  2012-06-08  8:48 ` [v2 2/9] iio:adc:at91: Use new triggered buffer setup helper Lars-Peter Clausen
@ 2012-06-15 16:32   ` Lars-Peter Clausen
  2012-06-18  7:56     ` Maxime Ripard
  0 siblings, 1 reply; 19+ messages in thread
From: Lars-Peter Clausen @ 2012-06-15 16:32 UTC (permalink / raw)
  To: Maxime Ripard; +Cc: Jonathan Cameron, linux-iio

On 06/08/2012 10:48 AM, Lars-Peter Clausen wrote:
> Use the new triggered buffer setup helper function to allocate and register
> buffer and pollfunc.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
> Acked-by: Jonathan Cameron <jic23@kernel.org>

Hi Maxime,

Can you take a look at this patch and say whether you are OK with it? I've
only compile tested it since I don't have the hardware, but I don't expect
any problems since the conversion is straight forward and a similar
conversion has been done for other drivers as well, which worked fine so far.

Thanks,
- Lars


> ---
>  drivers/iio/adc/Kconfig    |    3 +--
>  drivers/iio/adc/at91_adc.c |   51 ++++----------------------------------------
>  2 files changed, 5 insertions(+), 49 deletions(-)
> 
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index 9a0df81..4f7f584 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -7,8 +7,7 @@ config AT91_ADC
>  	tristate "Atmel AT91 ADC"
>  	depends on ARCH_AT91
>  	select IIO_BUFFER
> -	select IIO_KFIFO_BUF
> -	select IIO_TRIGGER
> +	select IIO_TRIGGERED_BUFFER
>  	select SYSFS
>  	help
>  	  Say yes here to build support for Atmel AT91 ADC.
> diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
> index f18a95d..6a08469 100644
> --- a/drivers/iio/adc/at91_adc.c
> +++ b/drivers/iio/adc/at91_adc.c
> @@ -26,9 +26,9 @@
>  
>  #include <linux/iio/iio.h>
>  #include <linux/iio/buffer.h>
> -#include <linux/iio/kfifo_buf.h>
>  #include <linux/iio/trigger.h>
>  #include <linux/iio/trigger_consumer.h>
> +#include <linux/iio/triggered_buffer.h>
>  
>  #include <mach/at91_adc.h>
>  
> @@ -318,58 +318,15 @@ static void at91_adc_trigger_remove(struct iio_dev *idev)
>  	}
>  }
>  
> -static const struct iio_buffer_setup_ops at91_adc_buffer_ops = {
> -	.preenable = &iio_sw_buffer_preenable,
> -	.postenable = &iio_triggered_buffer_postenable,
> -	.predisable = &iio_triggered_buffer_predisable,
> -};
> -
>  static int at91_adc_buffer_init(struct iio_dev *idev)
>  {
> -	int ret;
> -
> -	idev->buffer = iio_kfifo_allocate(idev);
> -	if (!idev->buffer) {
> -		ret = -ENOMEM;
> -		goto error_ret;
> -	}
> -
> -	idev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
> -					    &at91_adc_trigger_handler,
> -					    IRQF_ONESHOT,
> -					    idev,
> -					    "%s-consumer%d",
> -					    idev->name,
> -					    idev->id);
> -	if (idev->pollfunc == NULL) {
> -		ret = -ENOMEM;
> -		goto error_pollfunc;
> -	}
> -
> -	idev->setup_ops = &at91_adc_buffer_ops;
> -	idev->modes |= INDIO_BUFFER_TRIGGERED;
> -
> -	ret = iio_buffer_register(idev,
> -				  idev->channels,
> -				  idev->num_channels);
> -	if (ret)
> -		goto error_register;
> -
> -	return 0;
> -
> -error_register:
> -	iio_dealloc_pollfunc(idev->pollfunc);
> -error_pollfunc:
> -	iio_kfifo_free(idev->buffer);
> -error_ret:
> -	return ret;
> +	return iio_triggered_buffer_setup(idev, &iio_pollfunc_store_time,
> +		&at91_adc_trigger_handler, NULL);
>  }
>  
>  static void at91_adc_buffer_remove(struct iio_dev *idev)
>  {
> -	iio_buffer_unregister(idev);
> -	iio_dealloc_pollfunc(idev->pollfunc);
> -	iio_kfifo_free(idev->buffer);
> +	iio_triggered_buffer_cleanup(idev);
>  }
>  
>  static int at91_adc_read_raw(struct iio_dev *idev,

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [v2 2/9] iio:adc:at91: Use new triggered buffer setup helper
  2012-06-15 16:32   ` Lars-Peter Clausen
@ 2012-06-18  7:56     ` Maxime Ripard
  2012-06-18  8:23       ` Lars-Peter Clausen
  0 siblings, 1 reply; 19+ messages in thread
From: Maxime Ripard @ 2012-06-18  7:56 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio

Hi Lars-Peter,

Sorry, I thought Jonathan's Acked-by was enough.

I'm definitely ok with these changes, you can add my acked-by.

Maxime

Le 15/06/2012 18:32, Lars-Peter Clausen a =E9crit :
> On 06/08/2012 10:48 AM, Lars-Peter Clausen wrote:
>> Use the new triggered buffer setup helper function to allocate and reg=
ister
>> buffer and pollfunc.
>>
>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
>> Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
>> Acked-by: Jonathan Cameron <jic23@kernel.org>
>=20
> Hi Maxime,
>=20
> Can you take a look at this patch and say whether you are OK with it? I=
've
> only compile tested it since I don't have the hardware, but I don't exp=
ect
> any problems since the conversion is straight forward and a similar
> conversion has been done for other drivers as well, which worked fine s=
o far.
>=20
> Thanks,
> - Lars
>=20
>=20
>> ---
>>  drivers/iio/adc/Kconfig    |    3 +--
>>  drivers/iio/adc/at91_adc.c |   51 ++++-------------------------------=
---------
>>  2 files changed, 5 insertions(+), 49 deletions(-)
>>
>> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
>> index 9a0df81..4f7f584 100644
>> --- a/drivers/iio/adc/Kconfig
>> +++ b/drivers/iio/adc/Kconfig
>> @@ -7,8 +7,7 @@ config AT91_ADC
>>  	tristate "Atmel AT91 ADC"
>>  	depends on ARCH_AT91
>>  	select IIO_BUFFER
>> -	select IIO_KFIFO_BUF
>> -	select IIO_TRIGGER
>> +	select IIO_TRIGGERED_BUFFER
>>  	select SYSFS
>>  	help
>>  	  Say yes here to build support for Atmel AT91 ADC.
>> diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
>> index f18a95d..6a08469 100644
>> --- a/drivers/iio/adc/at91_adc.c
>> +++ b/drivers/iio/adc/at91_adc.c
>> @@ -26,9 +26,9 @@
>> =20
>>  #include <linux/iio/iio.h>
>>  #include <linux/iio/buffer.h>
>> -#include <linux/iio/kfifo_buf.h>
>>  #include <linux/iio/trigger.h>
>>  #include <linux/iio/trigger_consumer.h>
>> +#include <linux/iio/triggered_buffer.h>
>> =20
>>  #include <mach/at91_adc.h>
>> =20
>> @@ -318,58 +318,15 @@ static void at91_adc_trigger_remove(struct iio_d=
ev *idev)
>>  	}
>>  }
>> =20
>> -static const struct iio_buffer_setup_ops at91_adc_buffer_ops =3D {
>> -	.preenable =3D &iio_sw_buffer_preenable,
>> -	.postenable =3D &iio_triggered_buffer_postenable,
>> -	.predisable =3D &iio_triggered_buffer_predisable,
>> -};
>> -
>>  static int at91_adc_buffer_init(struct iio_dev *idev)
>>  {
>> -	int ret;
>> -
>> -	idev->buffer =3D iio_kfifo_allocate(idev);
>> -	if (!idev->buffer) {
>> -		ret =3D -ENOMEM;
>> -		goto error_ret;
>> -	}
>> -
>> -	idev->pollfunc =3D iio_alloc_pollfunc(&iio_pollfunc_store_time,
>> -					    &at91_adc_trigger_handler,
>> -					    IRQF_ONESHOT,
>> -					    idev,
>> -					    "%s-consumer%d",
>> -					    idev->name,
>> -					    idev->id);
>> -	if (idev->pollfunc =3D=3D NULL) {
>> -		ret =3D -ENOMEM;
>> -		goto error_pollfunc;
>> -	}
>> -
>> -	idev->setup_ops =3D &at91_adc_buffer_ops;
>> -	idev->modes |=3D INDIO_BUFFER_TRIGGERED;
>> -
>> -	ret =3D iio_buffer_register(idev,
>> -				  idev->channels,
>> -				  idev->num_channels);
>> -	if (ret)
>> -		goto error_register;
>> -
>> -	return 0;
>> -
>> -error_register:
>> -	iio_dealloc_pollfunc(idev->pollfunc);
>> -error_pollfunc:
>> -	iio_kfifo_free(idev->buffer);
>> -error_ret:
>> -	return ret;
>> +	return iio_triggered_buffer_setup(idev, &iio_pollfunc_store_time,
>> +		&at91_adc_trigger_handler, NULL);
>>  }
>> =20
>>  static void at91_adc_buffer_remove(struct iio_dev *idev)
>>  {
>> -	iio_buffer_unregister(idev);
>> -	iio_dealloc_pollfunc(idev->pollfunc);
>> -	iio_kfifo_free(idev->buffer);
>> +	iio_triggered_buffer_cleanup(idev);
>>  }
>> =20
>>  static int at91_adc_read_raw(struct iio_dev *idev,
>=20


--=20
Maxime Ripard, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [v2 2/9] iio:adc:at91: Use new triggered buffer setup helper
  2012-06-18  7:56     ` Maxime Ripard
@ 2012-06-18  8:23       ` Lars-Peter Clausen
  2012-06-18  8:38         ` Jonathan Cameron
  0 siblings, 1 reply; 19+ messages in thread
From: Lars-Peter Clausen @ 2012-06-18  8:23 UTC (permalink / raw)
  To: Maxime Ripard; +Cc: Jonathan Cameron, linux-iio

Hi,

On 06/18/2012 09:56 AM, Maxime Ripard wrote:
> Hi Lars-Peter,
> 
> Sorry, I thought Jonathan's Acked-by was enough.

No problem. I guess Jonathan's Acked-by is sort of enough, but having your
Acked-by as well is even better :). You are the author of that driver and
probably know the code better than anybody else.

> 
> I'm definitely ok with these changes, you can add my acked-by.
> 

Thanks,
- Lars

> Maxime
> 
> Le 15/06/2012 18:32, Lars-Peter Clausen a écrit :
>> On 06/08/2012 10:48 AM, Lars-Peter Clausen wrote:
>>> Use the new triggered buffer setup helper function to allocate and register
>>> buffer and pollfunc.
>>>
>>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
>>> Cc: Maxime Ripard <maxime.ripard@free-electrons.com>
>>> Acked-by: Jonathan Cameron <jic23@kernel.org>
>>
>> Hi Maxime,
>>
>> Can you take a look at this patch and say whether you are OK with it? I've
>> only compile tested it since I don't have the hardware, but I don't expect
>> any problems since the conversion is straight forward and a similar
>> conversion has been done for other drivers as well, which worked fine so far.
>>
>> Thanks,
>> - Lars
>>
>>
>>> ---
>>>  drivers/iio/adc/Kconfig    |    3 +--
>>>  drivers/iio/adc/at91_adc.c |   51 ++++----------------------------------------
>>>  2 files changed, 5 insertions(+), 49 deletions(-)
>>>
>>> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
>>> index 9a0df81..4f7f584 100644
>>> --- a/drivers/iio/adc/Kconfig
>>> +++ b/drivers/iio/adc/Kconfig
>>> @@ -7,8 +7,7 @@ config AT91_ADC
>>>  	tristate "Atmel AT91 ADC"
>>>  	depends on ARCH_AT91
>>>  	select IIO_BUFFER
>>> -	select IIO_KFIFO_BUF
>>> -	select IIO_TRIGGER
>>> +	select IIO_TRIGGERED_BUFFER
>>>  	select SYSFS
>>>  	help
>>>  	  Say yes here to build support for Atmel AT91 ADC.
>>> diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
>>> index f18a95d..6a08469 100644
>>> --- a/drivers/iio/adc/at91_adc.c
>>> +++ b/drivers/iio/adc/at91_adc.c
>>> @@ -26,9 +26,9 @@
>>>  
>>>  #include <linux/iio/iio.h>
>>>  #include <linux/iio/buffer.h>
>>> -#include <linux/iio/kfifo_buf.h>
>>>  #include <linux/iio/trigger.h>
>>>  #include <linux/iio/trigger_consumer.h>
>>> +#include <linux/iio/triggered_buffer.h>
>>>  
>>>  #include <mach/at91_adc.h>
>>>  
>>> @@ -318,58 +318,15 @@ static void at91_adc_trigger_remove(struct iio_dev *idev)
>>>  	}
>>>  }
>>>  
>>> -static const struct iio_buffer_setup_ops at91_adc_buffer_ops = {
>>> -	.preenable = &iio_sw_buffer_preenable,
>>> -	.postenable = &iio_triggered_buffer_postenable,
>>> -	.predisable = &iio_triggered_buffer_predisable,
>>> -};
>>> -
>>>  static int at91_adc_buffer_init(struct iio_dev *idev)
>>>  {
>>> -	int ret;
>>> -
>>> -	idev->buffer = iio_kfifo_allocate(idev);
>>> -	if (!idev->buffer) {
>>> -		ret = -ENOMEM;
>>> -		goto error_ret;
>>> -	}
>>> -
>>> -	idev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
>>> -					    &at91_adc_trigger_handler,
>>> -					    IRQF_ONESHOT,
>>> -					    idev,
>>> -					    "%s-consumer%d",
>>> -					    idev->name,
>>> -					    idev->id);
>>> -	if (idev->pollfunc == NULL) {
>>> -		ret = -ENOMEM;
>>> -		goto error_pollfunc;
>>> -	}
>>> -
>>> -	idev->setup_ops = &at91_adc_buffer_ops;
>>> -	idev->modes |= INDIO_BUFFER_TRIGGERED;
>>> -
>>> -	ret = iio_buffer_register(idev,
>>> -				  idev->channels,
>>> -				  idev->num_channels);
>>> -	if (ret)
>>> -		goto error_register;
>>> -
>>> -	return 0;
>>> -
>>> -error_register:
>>> -	iio_dealloc_pollfunc(idev->pollfunc);
>>> -error_pollfunc:
>>> -	iio_kfifo_free(idev->buffer);
>>> -error_ret:
>>> -	return ret;
>>> +	return iio_triggered_buffer_setup(idev, &iio_pollfunc_store_time,
>>> +		&at91_adc_trigger_handler, NULL);
>>>  }
>>>  
>>>  static void at91_adc_buffer_remove(struct iio_dev *idev)
>>>  {
>>> -	iio_buffer_unregister(idev);
>>> -	iio_dealloc_pollfunc(idev->pollfunc);
>>> -	iio_kfifo_free(idev->buffer);
>>> +	iio_triggered_buffer_cleanup(idev);
>>>  }
>>>  
>>>  static int at91_adc_read_raw(struct iio_dev *idev,
>>
> 
> 

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [v2 2/9] iio:adc:at91: Use new triggered buffer setup helper
  2012-06-18  8:23       ` Lars-Peter Clausen
@ 2012-06-18  8:38         ` Jonathan Cameron
  2012-06-18 12:07           ` Maxime Ripard
  0 siblings, 1 reply; 19+ messages in thread
From: Jonathan Cameron @ 2012-06-18  8:38 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Maxime Ripard, linux-iio

On 6/18/2012 9:23 AM, Lars-Peter Clausen wrote:
> Hi,
>
> On 06/18/2012 09:56 AM, Maxime Ripard wrote:
>> Hi Lars-Peter,
>>
>> Sorry, I thought Jonathan's Acked-by was enough.
>
> No problem. I guess Jonathan's Acked-by is sort of enough, but having=
 your
> Acked-by as well is even better :). You are the author of that driver=
 and
> probably know the code better than anybody else.
I have a definite preference for getting Acks from driver writers
where possible.  They always know their drivers better than Lars-Peter
or I do!
>
>>
>> I'm definitely ok with these changes, you can add my acked-by.
>>
>
> Thanks,
> - Lars
>
>> Maxime
>>
>> Le 15/06/2012 18:32, Lars-Peter Clausen a =E9crit :
>>> On 06/08/2012 10:48 AM, Lars-Peter Clausen wrote:
>>>> Use the new triggered buffer setup helper function to allocate and=
 register
>>>> buffer and pollfunc.
>>>>
>>>> Signed-off-by: Lars-Peter Clausen<lars@metafoo.de>
>>>> Cc: Maxime Ripard<maxime.ripard@free-electrons.com>
>>>> Acked-by: Jonathan Cameron<jic23@kernel.org>
>>>
>>> Hi Maxime,
>>>
>>> Can you take a look at this patch and say whether you are OK with i=
t? I've
>>> only compile tested it since I don't have the hardware, but I don't=
 expect
>>> any problems since the conversion is straight forward and a similar
>>> conversion has been done for other drivers as well, which worked fi=
ne so far.
>>>
>>> Thanks,
>>> - Lars
>>>
>>>
>>>> ---
>>>>   drivers/iio/adc/Kconfig    |    3 +--
>>>>   drivers/iio/adc/at91_adc.c |   51 ++++--------------------------=
--------------
>>>>   2 files changed, 5 insertions(+), 49 deletions(-)
>>>>
>>>> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
>>>> index 9a0df81..4f7f584 100644
>>>> --- a/drivers/iio/adc/Kconfig
>>>> +++ b/drivers/iio/adc/Kconfig
>>>> @@ -7,8 +7,7 @@ config AT91_ADC
>>>>   	tristate "Atmel AT91 ADC"
>>>>   	depends on ARCH_AT91
>>>>   	select IIO_BUFFER
>>>> -	select IIO_KFIFO_BUF
>>>> -	select IIO_TRIGGER
>>>> +	select IIO_TRIGGERED_BUFFER
>>>>   	select SYSFS
>>>>   	help
>>>>   	  Say yes here to build support for Atmel AT91 ADC.
>>>> diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc=
=2Ec
>>>> index f18a95d..6a08469 100644
>>>> --- a/drivers/iio/adc/at91_adc.c
>>>> +++ b/drivers/iio/adc/at91_adc.c
>>>> @@ -26,9 +26,9 @@
>>>>
>>>>   #include<linux/iio/iio.h>
>>>>   #include<linux/iio/buffer.h>
>>>> -#include<linux/iio/kfifo_buf.h>
>>>>   #include<linux/iio/trigger.h>
>>>>   #include<linux/iio/trigger_consumer.h>
>>>> +#include<linux/iio/triggered_buffer.h>
>>>>
>>>>   #include<mach/at91_adc.h>
>>>>
>>>> @@ -318,58 +318,15 @@ static void at91_adc_trigger_remove(struct i=
io_dev *idev)
>>>>   	}
>>>>   }
>>>>
>>>> -static const struct iio_buffer_setup_ops at91_adc_buffer_ops =3D =
{
>>>> -	.preenable =3D&iio_sw_buffer_preenable,
>>>> -	.postenable =3D&iio_triggered_buffer_postenable,
>>>> -	.predisable =3D&iio_triggered_buffer_predisable,
>>>> -};
>>>> -
>>>>   static int at91_adc_buffer_init(struct iio_dev *idev)
>>>>   {
>>>> -	int ret;
>>>> -
>>>> -	idev->buffer =3D iio_kfifo_allocate(idev);
>>>> -	if (!idev->buffer) {
>>>> -		ret =3D -ENOMEM;
>>>> -		goto error_ret;
>>>> -	}
>>>> -
>>>> -	idev->pollfunc =3D iio_alloc_pollfunc(&iio_pollfunc_store_time,
>>>> -					&at91_adc_trigger_handler,
>>>> -					    IRQF_ONESHOT,
>>>> -					    idev,
>>>> -					    "%s-consumer%d",
>>>> -					    idev->name,
>>>> -					    idev->id);
>>>> -	if (idev->pollfunc =3D=3D NULL) {
>>>> -		ret =3D -ENOMEM;
>>>> -		goto error_pollfunc;
>>>> -	}
>>>> -
>>>> -	idev->setup_ops =3D&at91_adc_buffer_ops;
>>>> -	idev->modes |=3D INDIO_BUFFER_TRIGGERED;
>>>> -
>>>> -	ret =3D iio_buffer_register(idev,
>>>> -				  idev->channels,
>>>> -				  idev->num_channels);
>>>> -	if (ret)
>>>> -		goto error_register;
>>>> -
>>>> -	return 0;
>>>> -
>>>> -error_register:
>>>> -	iio_dealloc_pollfunc(idev->pollfunc);
>>>> -error_pollfunc:
>>>> -	iio_kfifo_free(idev->buffer);
>>>> -error_ret:
>>>> -	return ret;
>>>> +	return iio_triggered_buffer_setup(idev,&iio_pollfunc_store_time,
>>>> +		&at91_adc_trigger_handler, NULL);
>>>>   }
>>>>
>>>>   static void at91_adc_buffer_remove(struct iio_dev *idev)
>>>>   {
>>>> -	iio_buffer_unregister(idev);
>>>> -	iio_dealloc_pollfunc(idev->pollfunc);
>>>> -	iio_kfifo_free(idev->buffer);
>>>> +	iio_triggered_buffer_cleanup(idev);
>>>>   }
>>>>
>>>>   static int at91_adc_read_raw(struct iio_dev *idev,
>>>
>>
>>
>


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [v2 4/9] staging:iio:adc:ad7298: Use new triggered buffer setup helper function
  2012-06-08  8:48 ` [v2 4/9] staging:iio:adc:ad7298: " Lars-Peter Clausen
@ 2012-06-18  9:45   ` Lars-Peter Clausen
  2012-06-18 11:06     ` Jonathan Cameron
  0 siblings, 1 reply; 19+ messages in thread
From: Lars-Peter Clausen @ 2012-06-18  9:45 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio

On 06/08/2012 10:48 AM, Lars-Peter Clausen wrote:
> Use the new triggered buffer setup helper function to allocate and register
> buffer and pollfunc.
> 
> Also as part of the conversion drop scan_timestamp being enabled by default,
> since it is a left over of an earlier cleanup.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Acked-by: Jonathan Cameron <jic23@kernel.org>
> ---
>  drivers/staging/iio/adc/Kconfig       |    1 +
>  drivers/staging/iio/adc/ad7298.h      |    5 +++
>  drivers/staging/iio/adc/ad7298_core.c |   11 ++----
>  drivers/staging/iio/adc/ad7298_ring.c |   64 ++++++---------------------------
>  4 files changed, 18 insertions(+), 63 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
> index c01df61..bb6fffd 100644
> --- a/drivers/staging/iio/adc/Kconfig
> +++ b/drivers/staging/iio/adc/Kconfig
> @@ -13,6 +13,7 @@ config AD7291
>  config AD7298
>  	tristate "Analog Devices AD7298 ADC driver"
>  	depends on SPI
> +	select IIO_TRIGGERED_BUFFER if IIO_BUFFER
>  	help
>  	  Say yes here to build support for Analog Devices AD7298
>  	  8 Channel ADC with temperature sensor.
> diff --git a/drivers/staging/iio/adc/ad7298.h b/drivers/staging/iio/adc/ad7298.h
> index 5051a7e..18f2787 100644
> --- a/drivers/staging/iio/adc/ad7298.h
> +++ b/drivers/staging/iio/adc/ad7298.h
> @@ -55,6 +55,8 @@ struct ad7298_state {
>  #ifdef CONFIG_IIO_BUFFER
>  int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev);
>  void ad7298_ring_cleanup(struct iio_dev *indio_dev);
> +int ad7298_update_scan_mode(struct iio_dev *indio_dev,
> +	const unsigned long *active_scan_mask);
>  #else /* CONFIG_IIO_BUFFER */
>  
>  static inline int
> @@ -66,5 +68,8 @@ ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev)
>  static inline void ad7298_ring_cleanup(struct iio_dev *indio_dev)
>  {
>  }
> +
> +#define ad7298_update_scan_mode NULL
> +
>  #endif /* CONFIG_IIO_BUFFER */
>  #endif /* IIO_ADC_AD7298_H_ */
> diff --git a/drivers/staging/iio/adc/ad7298_core.c b/drivers/staging/iio/adc/ad7298_core.c
> index c90f2b3..5e68bad 100644
> --- a/drivers/staging/iio/adc/ad7298_core.c
> +++ b/drivers/staging/iio/adc/ad7298_core.c
> @@ -171,6 +171,7 @@ static int ad7298_read_raw(struct iio_dev *indio_dev,
>  
>  static const struct iio_info ad7298_info = {
>  	.read_raw = &ad7298_read_raw,
> +	.update_scan_mode = ad7298_update_scan_mode,
>  	.driver_module = THIS_MODULE,
>  };
>  
> @@ -231,19 +232,12 @@ static int __devinit ad7298_probe(struct spi_device *spi)
>  	if (ret)
>  		goto error_disable_reg;
>  
> -	ret = iio_buffer_register(indio_dev,
> -				  &ad7298_channels[1], /* skip temp0 */
> -				  ARRAY_SIZE(ad7298_channels) - 1);

Ah, dammit... I guess it's always a good idea to do a final thorough review.

I think we had this discussion before and the reason why iio_buffer_register
take the channels and num_channels because the channels which can be used in
buffered mode maybe a subset of the total channels. But right now these
channels have to be either at the beginning or the end of the channel spec.
I wonder if the following might be a better alternative:

diff --git a/drivers/iio/industrialio-buffer.c
b/drivers/iio/industrialio-buffer.c
index 2f35db9..3d8d187 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -285,6 +285,9 @@ int iio_buffer_register(struct iio_dev *indio_dev,
 	if (channels) {
 		/* new magic */
 		for (i = 0; i < num_channels; i++) {
+			if (channels[i].scan_index < 0)
+				continue;
+
 			/* Establish necessary mask length */
 			if (channels[i].scan_index >
 			    (int)indio_dev->masklength - 1)

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [v2 4/9] staging:iio:adc:ad7298: Use new triggered buffer setup helper function
  2012-06-18  9:45   ` Lars-Peter Clausen
@ 2012-06-18 11:06     ` Jonathan Cameron
  0 siblings, 0 replies; 19+ messages in thread
From: Jonathan Cameron @ 2012-06-18 11:06 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: linux-iio

On 6/18/2012 10:45 AM, Lars-Peter Clausen wrote:
> On 06/08/2012 10:48 AM, Lars-Peter Clausen wrote:
>> Use the new triggered buffer setup helper function to allocate and register
>> buffer and pollfunc.
>>
>> Also as part of the conversion drop scan_timestamp being enabled by default,
>> since it is a left over of an earlier cleanup.
>>
>> Signed-off-by: Lars-Peter Clausen<lars@metafoo.de>
>> Acked-by: Jonathan Cameron<jic23@kernel.org>
>> ---
>>   drivers/staging/iio/adc/Kconfig       |    1 +
>>   drivers/staging/iio/adc/ad7298.h      |    5 +++
>>   drivers/staging/iio/adc/ad7298_core.c |   11 ++----
>>   drivers/staging/iio/adc/ad7298_ring.c |   64 ++++++---------------------------
>>   4 files changed, 18 insertions(+), 63 deletions(-)
>>
>> diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
>> index c01df61..bb6fffd 100644
>> --- a/drivers/staging/iio/adc/Kconfig
>> +++ b/drivers/staging/iio/adc/Kconfig
>> @@ -13,6 +13,7 @@ config AD7291
>>   config AD7298
>>   	tristate "Analog Devices AD7298 ADC driver"
>>   	depends on SPI
>> +	select IIO_TRIGGERED_BUFFER if IIO_BUFFER
>>   	help
>>   	  Say yes here to build support for Analog Devices AD7298
>>   	  8 Channel ADC with temperature sensor.
>> diff --git a/drivers/staging/iio/adc/ad7298.h b/drivers/staging/iio/adc/ad7298.h
>> index 5051a7e..18f2787 100644
>> --- a/drivers/staging/iio/adc/ad7298.h
>> +++ b/drivers/staging/iio/adc/ad7298.h
>> @@ -55,6 +55,8 @@ struct ad7298_state {
>>   #ifdef CONFIG_IIO_BUFFER
>>   int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev);
>>   void ad7298_ring_cleanup(struct iio_dev *indio_dev);
>> +int ad7298_update_scan_mode(struct iio_dev *indio_dev,
>> +	const unsigned long *active_scan_mask);
>>   #else /* CONFIG_IIO_BUFFER */
>>
>>   static inline int
>> @@ -66,5 +68,8 @@ ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev)
>>   static inline void ad7298_ring_cleanup(struct iio_dev *indio_dev)
>>   {
>>   }
>> +
>> +#define ad7298_update_scan_mode NULL
>> +
>>   #endif /* CONFIG_IIO_BUFFER */
>>   #endif /* IIO_ADC_AD7298_H_ */
>> diff --git a/drivers/staging/iio/adc/ad7298_core.c b/drivers/staging/iio/adc/ad7298_core.c
>> index c90f2b3..5e68bad 100644
>> --- a/drivers/staging/iio/adc/ad7298_core.c
>> +++ b/drivers/staging/iio/adc/ad7298_core.c
>> @@ -171,6 +171,7 @@ static int ad7298_read_raw(struct iio_dev *indio_dev,
>>
>>   static const struct iio_info ad7298_info = {
>>   	.read_raw =&ad7298_read_raw,
>> +	.update_scan_mode = ad7298_update_scan_mode,
>>   	.driver_module = THIS_MODULE,
>>   };
>>
>> @@ -231,19 +232,12 @@ static int __devinit ad7298_probe(struct spi_device *spi)
>>   	if (ret)
>>   		goto error_disable_reg;
>>
>> -	ret = iio_buffer_register(indio_dev,
>> -				&ad7298_channels[1], /* skip temp0 */
>> -				  ARRAY_SIZE(ad7298_channels) - 1);
>
> Ah, dammit... I guess it's always a good idea to do a final thorough review.
>
> I think we had this discussion before and the reason why iio_buffer_register
> take the channels and num_channels because the channels which can be used in
> buffered mode maybe a subset of the total channels. But right now these
> channels have to be either at the beginning or the end of the channel spec.
> I wonder if the following might be a better alternative:
Works for me.
>
> diff --git a/drivers/iio/industrialio-buffer.c
> b/drivers/iio/industrialio-buffer.c
> index 2f35db9..3d8d187 100644
> --- a/drivers/iio/industrialio-buffer.c
> +++ b/drivers/iio/industrialio-buffer.c
> @@ -285,6 +285,9 @@ int iio_buffer_register(struct iio_dev *indio_dev,
>   	if (channels) {
>   		/* new magic */
>   		for (i = 0; i<  num_channels; i++) {
> +			if (channels[i].scan_index<  0)
> +				continue;
> +
>   			/* Establish necessary mask length */
>   			if (channels[i].scan_index>
>   			(int)indio_dev->masklength - 1)


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [v2 2/9] iio:adc:at91: Use new triggered buffer setup helper
  2012-06-18  8:38         ` Jonathan Cameron
@ 2012-06-18 12:07           ` Maxime Ripard
  0 siblings, 0 replies; 19+ messages in thread
From: Maxime Ripard @ 2012-06-18 12:07 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Lars-Peter Clausen, linux-iio

Hi,

Le 18/06/2012 10:38, Jonathan Cameron a =E9crit :
> On 6/18/2012 9:23 AM, Lars-Peter Clausen wrote:
>> Hi,
>>
>> On 06/18/2012 09:56 AM, Maxime Ripard wrote:
>>> Hi Lars-Peter,
>>>
>>> Sorry, I thought Jonathan's Acked-by was enough.
>>
>> No problem. I guess Jonathan's Acked-by is sort of enough, but having
>> your
>> Acked-by as well is even better :). You are the author of that driver =
and
>> probably know the code better than anybody else.
> I have a definite preference for getting Acks from driver writers
> where possible.  They always know their drivers better than Lars-Peter
> or I do!

It makes sense. I'll know it for the next time :)

Maxime

>>
>>>
>>> I'm definitely ok with these changes, you can add my acked-by.
>>>
>>
>> Thanks,
>> - Lars
>>
>>> Maxime
>>>
>>> Le 15/06/2012 18:32, Lars-Peter Clausen a =E9crit :
>>>> On 06/08/2012 10:48 AM, Lars-Peter Clausen wrote:
>>>>> Use the new triggered buffer setup helper function to allocate and
>>>>> register
>>>>> buffer and pollfunc.
>>>>>
>>>>> Signed-off-by: Lars-Peter Clausen<lars@metafoo.de>
>>>>> Cc: Maxime Ripard<maxime.ripard@free-electrons.com>
>>>>> Acked-by: Jonathan Cameron<jic23@kernel.org>
>>>>
>>>> Hi Maxime,
>>>>
>>>> Can you take a look at this patch and say whether you are OK with
>>>> it? I've
>>>> only compile tested it since I don't have the hardware, but I don't
>>>> expect
>>>> any problems since the conversion is straight forward and a similar
>>>> conversion has been done for other drivers as well, which worked
>>>> fine so far.
>>>>
>>>> Thanks,
>>>> - Lars
>>>>
>>>>
>>>>> ---
>>>>>   drivers/iio/adc/Kconfig    |    3 +--
>>>>>   drivers/iio/adc/at91_adc.c |   51
>>>>> ++++----------------------------------------
>>>>>   2 files changed, 5 insertions(+), 49 deletions(-)
>>>>>
>>>>> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
>>>>> index 9a0df81..4f7f584 100644
>>>>> --- a/drivers/iio/adc/Kconfig
>>>>> +++ b/drivers/iio/adc/Kconfig
>>>>> @@ -7,8 +7,7 @@ config AT91_ADC
>>>>>       tristate "Atmel AT91 ADC"
>>>>>       depends on ARCH_AT91
>>>>>       select IIO_BUFFER
>>>>> -    select IIO_KFIFO_BUF
>>>>> -    select IIO_TRIGGER
>>>>> +    select IIO_TRIGGERED_BUFFER
>>>>>       select SYSFS
>>>>>       help
>>>>>         Say yes here to build support for Atmel AT91 ADC.
>>>>> diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.=
c
>>>>> index f18a95d..6a08469 100644
>>>>> --- a/drivers/iio/adc/at91_adc.c
>>>>> +++ b/drivers/iio/adc/at91_adc.c
>>>>> @@ -26,9 +26,9 @@
>>>>>
>>>>>   #include<linux/iio/iio.h>
>>>>>   #include<linux/iio/buffer.h>
>>>>> -#include<linux/iio/kfifo_buf.h>
>>>>>   #include<linux/iio/trigger.h>
>>>>>   #include<linux/iio/trigger_consumer.h>
>>>>> +#include<linux/iio/triggered_buffer.h>
>>>>>
>>>>>   #include<mach/at91_adc.h>
>>>>>
>>>>> @@ -318,58 +318,15 @@ static void at91_adc_trigger_remove(struct
>>>>> iio_dev *idev)
>>>>>       }
>>>>>   }
>>>>>
>>>>> -static const struct iio_buffer_setup_ops at91_adc_buffer_ops =3D {
>>>>> -    .preenable =3D&iio_sw_buffer_preenable,
>>>>> -    .postenable =3D&iio_triggered_buffer_postenable,
>>>>> -    .predisable =3D&iio_triggered_buffer_predisable,
>>>>> -};
>>>>> -
>>>>>   static int at91_adc_buffer_init(struct iio_dev *idev)
>>>>>   {
>>>>> -    int ret;
>>>>> -
>>>>> -    idev->buffer =3D iio_kfifo_allocate(idev);
>>>>> -    if (!idev->buffer) {
>>>>> -        ret =3D -ENOMEM;
>>>>> -        goto error_ret;
>>>>> -    }
>>>>> -
>>>>> -    idev->pollfunc =3D iio_alloc_pollfunc(&iio_pollfunc_store_time=
,
>>>>> -                    &at91_adc_trigger_handler,
>>>>> -                        IRQF_ONESHOT,
>>>>> -                        idev,
>>>>> -                        "%s-consumer%d",
>>>>> -                        idev->name,
>>>>> -                        idev->id);
>>>>> -    if (idev->pollfunc =3D=3D NULL) {
>>>>> -        ret =3D -ENOMEM;
>>>>> -        goto error_pollfunc;
>>>>> -    }
>>>>> -
>>>>> -    idev->setup_ops =3D&at91_adc_buffer_ops;
>>>>> -    idev->modes |=3D INDIO_BUFFER_TRIGGERED;
>>>>> -
>>>>> -    ret =3D iio_buffer_register(idev,
>>>>> -                  idev->channels,
>>>>> -                  idev->num_channels);
>>>>> -    if (ret)
>>>>> -        goto error_register;
>>>>> -
>>>>> -    return 0;
>>>>> -
>>>>> -error_register:
>>>>> -    iio_dealloc_pollfunc(idev->pollfunc);
>>>>> -error_pollfunc:
>>>>> -    iio_kfifo_free(idev->buffer);
>>>>> -error_ret:
>>>>> -    return ret;
>>>>> +    return iio_triggered_buffer_setup(idev,&iio_pollfunc_store_tim=
e,
>>>>> +        &at91_adc_trigger_handler, NULL);
>>>>>   }
>>>>>
>>>>>   static void at91_adc_buffer_remove(struct iio_dev *idev)
>>>>>   {
>>>>> -    iio_buffer_unregister(idev);
>>>>> -    iio_dealloc_pollfunc(idev->pollfunc);
>>>>> -    iio_kfifo_free(idev->buffer);
>>>>> +    iio_triggered_buffer_cleanup(idev);
>>>>>   }
>>>>>
>>>>>   static int at91_adc_read_raw(struct iio_dev *idev,
>>>>
>>>
>>>
>>
>=20


--=20
Maxime Ripard, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2012-06-18 12:07 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-08  8:48 [v2 1/9] staging:iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
2012-06-08  8:48 ` [v2 2/9] iio:adc:at91: Use new triggered buffer setup helper Lars-Peter Clausen
2012-06-15 16:32   ` Lars-Peter Clausen
2012-06-18  7:56     ` Maxime Ripard
2012-06-18  8:23       ` Lars-Peter Clausen
2012-06-18  8:38         ` Jonathan Cameron
2012-06-18 12:07           ` Maxime Ripard
2012-06-08  8:48 ` [v2 3/9] staging:iio:adc:ad7192: Use new triggered buffer setup helper function Lars-Peter Clausen
2012-06-08  8:48 ` [v2 4/9] staging:iio:adc:ad7298: " Lars-Peter Clausen
2012-06-18  9:45   ` Lars-Peter Clausen
2012-06-18 11:06     ` Jonathan Cameron
2012-06-08  8:48 ` [v2 5/9] staging:iio:adc:ad7476: " Lars-Peter Clausen
2012-06-08  8:48 ` [v2 6/9] staging:iio:adc:ad7606: " Lars-Peter Clausen
2012-06-08  8:48 ` [v2 7/9] staging:iio:adc:ad7793: " Lars-Peter Clausen
2012-06-08  8:48 ` [v2 8/9] staging:iio:adc:ad7887: " Lars-Peter Clausen
2012-06-08  8:48 ` [v2 9/9] staging:iio:adc:ad799x: " Lars-Peter Clausen
2012-06-08 11:36 ` [v2 1/9] staging:iio: Add helper function for initializing triggered buffers Jonathan Cameron
2012-06-08 12:13 ` [PATCG v3 " Lars-Peter Clausen
2012-06-08 12:11   ` Jonathan Cameron

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.