All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index
@ 2012-06-18 11:44 Lars-Peter Clausen
  2012-06-18 11:44 ` [PATCH v4 02/10] iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
                   ` (9 more replies)
  0 siblings, 10 replies; 15+ messages in thread
From: Lars-Peter Clausen @ 2012-06-18 11:44 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen

It is not always the case that all channels can be used in buffered mode. This
patch allows channels, which can not be used in buffered mode, to set their scan
index to a negative number, which will cause iio_buffer_register to ignore the
channel.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
This patch is new in v4

Sorry for the extra noise, I should have noticed the problem with the ad7298
driver earlier.
---
 drivers/iio/industrialio-buffer.c |    3 +++
 1 file changed, 3 insertions(+)

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)
-- 
1.7.10


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

* [PATCH v4 02/10] iio: Add helper function for initializing triggered buffers
  2012-06-18 11:44 [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index Lars-Peter Clausen
@ 2012-06-18 11:44 ` Lars-Peter Clausen
  2012-06-18 11:44 ` [PATCH v4 03/10] iio:adc:at91: Use new triggered buffer setup helper Lars-Peter Clausen
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Lars-Peter Clausen @ 2012-06-18 11:44 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>
Acked-by: Jonathan Cameron <jic23@kernel.org>
---
Changes since v2:
	* Add missing header...

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..46c619b
--- /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 the 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 call
+ * iio_triggered_buffer_cleanup().
+ */
+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] 15+ messages in thread

* [PATCH v4 03/10] iio:adc:at91: Use new triggered buffer setup helper
  2012-06-18 11:44 [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index Lars-Peter Clausen
  2012-06-18 11:44 ` [PATCH v4 02/10] iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
@ 2012-06-18 11:44 ` Lars-Peter Clausen
  2012-06-18 11:44 ` [PATCH v4 04/10] staging:iio:adc:ad7192: Use new triggered buffer setup helper function Lars-Peter Clausen
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Lars-Peter Clausen @ 2012-06-18 11:44 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>
Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
No changes in v4
---
 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] 15+ messages in thread

* [PATCH v4 04/10] staging:iio:adc:ad7192: Use new triggered buffer setup helper function
  2012-06-18 11:44 [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index Lars-Peter Clausen
  2012-06-18 11:44 ` [PATCH v4 02/10] iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
  2012-06-18 11:44 ` [PATCH v4 03/10] iio:adc:at91: Use new triggered buffer setup helper Lars-Peter Clausen
@ 2012-06-18 11:44 ` Lars-Peter Clausen
  2012-06-18 11:44 ` [PATCH v4 05/10] staging:iio:adc:ad7298: " Lars-Peter Clausen
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Lars-Peter Clausen @ 2012-06-18 11:44 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>
---
No changes in v4
---
 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 8f1b3af..7cdf421 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -136,8 +136,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] 15+ messages in thread

* [PATCH v4 05/10] staging:iio:adc:ad7298: Use new triggered buffer setup helper function
  2012-06-18 11:44 [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index Lars-Peter Clausen
                   ` (2 preceding siblings ...)
  2012-06-18 11:44 ` [PATCH v4 04/10] staging:iio:adc:ad7192: Use new triggered buffer setup helper function Lars-Peter Clausen
@ 2012-06-18 11:44 ` Lars-Peter Clausen
  2012-06-18 12:09   ` Jonathan Cameron
  2012-06-18 11:44 ` [PATCH v4 06/10] staging:iio:adc:ad7476: " Lars-Peter Clausen
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 15+ messages in thread
From: Lars-Peter Clausen @ 2012-06-18 11:44 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.

The previous code was not passing the temperature channel to iio_buffer_register
since the temperature channel can not be used in buffered mode. With the new
helper functions it is not possible to do this, instead the scan index for the
temperature channel is set to -1 which will cause iio_buffer_register to ignore
the channel. (Also While we are at it also assign the symbolic constant instead
of the raw value to the channel address for the temperature channel).

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>
---
Changes since v3:
	* Set temperature channel scan index to -1 so it can not be used in buffered
	  mode. This is the same behaviour as without this patch.
---
 drivers/staging/iio/adc/Kconfig       |    2 +-
 drivers/staging/iio/adc/ad7298.h      |    5 +++
 drivers/staging/iio/adc/ad7298_core.c |   15 +++-----
 drivers/staging/iio/adc/ad7298_ring.c |   64 ++++++---------------------------
 4 files changed, 20 insertions(+), 66 deletions(-)

diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 7cdf421..bb6fffd 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -13,7 +13,7 @@ config AD7291
 config AD7298
 	tristate "Analog Devices AD7298 ADC driver"
 	depends on SPI
-	select IIO_KFIFO_BUF if IIO_BUFFER
+	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..6141f4a 100644
--- a/drivers/staging/iio/adc/ad7298_core.c
+++ b/drivers/staging/iio/adc/ad7298_core.c
@@ -45,8 +45,8 @@ static struct iio_chan_spec ad7298_channels[] = {
 		.channel = 0,
 		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
 		IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
-		.address = 9,
-		.scan_index = AD7298_CH_TEMP,
+		.address = AD7298_CH_TEMP,
+		.scan_index = -1,
 		.scan_type = {
 			.sign = 's',
 			.realbits = 32,
@@ -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] 15+ messages in thread

* [PATCH v4 06/10] staging:iio:adc:ad7476: Use new triggered buffer setup helper function
  2012-06-18 11:44 [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index Lars-Peter Clausen
                   ` (3 preceding siblings ...)
  2012-06-18 11:44 ` [PATCH v4 05/10] staging:iio:adc:ad7298: " Lars-Peter Clausen
@ 2012-06-18 11:44 ` Lars-Peter Clausen
  2012-06-18 11:45 ` [PATCH v4 07/10] staging:iio:adc:ad7606: " Lars-Peter Clausen
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Lars-Peter Clausen @ 2012-06-18 11:44 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>
---
No changes in v4
---
 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] 15+ messages in thread

* [PATCH v4 07/10] staging:iio:adc:ad7606: Use new triggered buffer setup helper function
  2012-06-18 11:44 [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index Lars-Peter Clausen
                   ` (4 preceding siblings ...)
  2012-06-18 11:44 ` [PATCH v4 06/10] staging:iio:adc:ad7476: " Lars-Peter Clausen
@ 2012-06-18 11:45 ` Lars-Peter Clausen
  2012-06-18 11:45 ` [PATCH v4 08/10] staging:iio:adc:ad7793: " Lars-Peter Clausen
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Lars-Peter Clausen @ 2012-06-18 11:45 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>
---
No changes in v4
---
 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 a13afff..ccb97fe 100644
--- a/drivers/staging/iio/adc/ad7606_core.c
+++ b/drivers/staging/iio/adc/ad7606_core.c
@@ -533,20 +533,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:
@@ -571,7 +563,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] 15+ messages in thread

* [PATCH v4 08/10] staging:iio:adc:ad7793: Use new triggered buffer setup helper function
  2012-06-18 11:44 [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index Lars-Peter Clausen
                   ` (5 preceding siblings ...)
  2012-06-18 11:45 ` [PATCH v4 07/10] staging:iio:adc:ad7606: " Lars-Peter Clausen
@ 2012-06-18 11:45 ` Lars-Peter Clausen
  2012-06-18 11:45 ` [PATCH v4 09/10] staging:iio:adc:ad7887: " Lars-Peter Clausen
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 15+ messages in thread
From: Lars-Peter Clausen @ 2012-06-18 11:45 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>
---
No changes in v4
---
 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] 15+ messages in thread

* [PATCH v4 09/10] staging:iio:adc:ad7887: Use new triggered buffer setup helper function
  2012-06-18 11:44 [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index Lars-Peter Clausen
                   ` (6 preceding siblings ...)
  2012-06-18 11:45 ` [PATCH v4 08/10] staging:iio:adc:ad7793: " Lars-Peter Clausen
@ 2012-06-18 11:45 ` Lars-Peter Clausen
  2012-06-18 11:45 ` [PATCH v4 10/10] staging:iio:adc:ad799x: " Lars-Peter Clausen
  2012-06-18 12:08 ` [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index Jonathan Cameron
  9 siblings, 0 replies; 15+ messages in thread
From: Lars-Peter Clausen @ 2012-06-18 11:45 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>
---
No changes in v4
---
 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] 15+ messages in thread

* [PATCH v4 10/10] staging:iio:adc:ad799x: Use new triggered buffer setup helper function
  2012-06-18 11:44 [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index Lars-Peter Clausen
                   ` (7 preceding siblings ...)
  2012-06-18 11:45 ` [PATCH v4 09/10] staging:iio:adc:ad7887: " Lars-Peter Clausen
@ 2012-06-18 11:45 ` Lars-Peter Clausen
  2012-06-18 12:08 ` [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index Jonathan Cameron
  9 siblings, 0 replies; 15+ messages in thread
From: Lars-Peter Clausen @ 2012-06-18 11:45 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>
---
No changes in v4
---
 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] 15+ messages in thread

* Re: [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index
  2012-06-18 11:44 [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index Lars-Peter Clausen
                   ` (8 preceding siblings ...)
  2012-06-18 11:45 ` [PATCH v4 10/10] staging:iio:adc:ad799x: " Lars-Peter Clausen
@ 2012-06-18 12:08 ` Jonathan Cameron
  2012-06-18 12:15   ` Peter Meerwald
  9 siblings, 1 reply; 15+ messages in thread
From: Jonathan Cameron @ 2012-06-18 12:08 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: linux-iio

On 6/18/2012 12:44 PM, Lars-Peter Clausen wrote:
> It is not always the case that all channels can be used in buffered mode. This
> patch allows channels, which can not be used in buffered mode, to set their scan
> index to a negative number, which will cause iio_buffer_register to ignore the
> channel.
>
> Signed-off-by: Lars-Peter Clausen<lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
> ---
> This patch is new in v4
>
> Sorry for the extra noise, I should have noticed the problem with the ad7298
> driver earlier.
> ---
>   drivers/iio/industrialio-buffer.c |    3 +++
>   1 file changed, 3 insertions(+)
>
> 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] 15+ messages in thread

* Re: [PATCH v4 05/10] staging:iio:adc:ad7298: Use new triggered buffer setup helper function
  2012-06-18 11:44 ` [PATCH v4 05/10] staging:iio:adc:ad7298: " Lars-Peter Clausen
@ 2012-06-18 12:09   ` Jonathan Cameron
  0 siblings, 0 replies; 15+ messages in thread
From: Jonathan Cameron @ 2012-06-18 12:09 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: linux-iio

On 6/18/2012 12:44 PM, Lars-Peter Clausen wrote:
> Use the new triggered buffer setup helper function to allocate and register
> buffer and pollfunc.
>
> The previous code was not passing the temperature channel to iio_buffer_register
> since the temperature channel can not be used in buffered mode. With the new
> helper functions it is not possible to do this, instead the scan index for the
> temperature channel is set to -1 which will cause iio_buffer_register to ignore
> the channel. (Also While we are at it also assign the symbolic constant instead
> of the raw value to the channel address for the temperature channel).
>
> 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>
> ---
> Changes since v3:
> 	* Set temperature channel scan index to -1 so it can not be used in buffered
> 	  mode. This is the same behaviour as without this patch.
> ---
>   drivers/staging/iio/adc/Kconfig       |    2 +-
>   drivers/staging/iio/adc/ad7298.h      |    5 +++
>   drivers/staging/iio/adc/ad7298_core.c |   15 +++-----
>   drivers/staging/iio/adc/ad7298_ring.c |   64 ++++++---------------------------
>   4 files changed, 20 insertions(+), 66 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
> index 7cdf421..bb6fffd 100644
> --- a/drivers/staging/iio/adc/Kconfig
> +++ b/drivers/staging/iio/adc/Kconfig
> @@ -13,7 +13,7 @@ config AD7291
>   config AD7298
>   	tristate "Analog Devices AD7298 ADC driver"
>   	depends on SPI
> -	select IIO_KFIFO_BUF if IIO_BUFFER
> +	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..6141f4a 100644
> --- a/drivers/staging/iio/adc/ad7298_core.c
> +++ b/drivers/staging/iio/adc/ad7298_core.c
> @@ -45,8 +45,8 @@ static struct iio_chan_spec ad7298_channels[] = {
>   		.channel = 0,
>   		.info_mask = IIO_CHAN_INFO_RAW_SEPARATE_BIT |
>   		IIO_CHAN_INFO_SCALE_SEPARATE_BIT,
> -		.address = 9,
> -		.scan_index = AD7298_CH_TEMP,
> +		.address = AD7298_CH_TEMP,
> +		.scan_index = -1,
>   		.scan_type = {
>   			.sign = 's',
>   			.realbits = 32,
> @@ -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);
>   }


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

* Re: [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index
  2012-06-18 12:08 ` [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index Jonathan Cameron
@ 2012-06-18 12:15   ` Peter Meerwald
  2012-06-18 12:33     ` Lars-Peter Clausen
  0 siblings, 1 reply; 15+ messages in thread
From: Peter Meerwald @ 2012-06-18 12:15 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: linux-iio


> > index to a negative number, which will cause iio_buffer_register to ignore
> > the
> > channel.

ah, nice, I wondered about the same thing :)

> > --- 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)

whitespace before/after < could be improved

-- 

Peter Meerwald
+43-664-2444418 (mobile)

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

* Re: [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index
  2012-06-18 12:15   ` Peter Meerwald
@ 2012-06-18 12:33     ` Lars-Peter Clausen
  2012-06-18 12:47       ` Jonathan Cameron
  0 siblings, 1 reply; 15+ messages in thread
From: Lars-Peter Clausen @ 2012-06-18 12:33 UTC (permalink / raw)
  To: Peter Meerwald; +Cc: linux-iio, Jonathan Cameron

On 06/18/2012 02:15 PM, Peter Meerwald wrote:
> 
>>> index to a negative number, which will cause iio_buffer_register to ignore
>>> the
>>> channel.
> 
> ah, nice, I wondered about the same thing :)
> 
>>> --- 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)
> 
> whitespace before/after < could be improved
> 

That's not in the original patch, Jonathan's mail client seems to like to
mess-up whitespace when quoting a mail. You'll get used to it ;)

- Lars

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

* Re: [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index
  2012-06-18 12:33     ` Lars-Peter Clausen
@ 2012-06-18 12:47       ` Jonathan Cameron
  0 siblings, 0 replies; 15+ messages in thread
From: Jonathan Cameron @ 2012-06-18 12:47 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Peter Meerwald, linux-iio, Jonathan Cameron

On 6/18/2012 1:33 PM, Lars-Peter Clausen wrote:
> On 06/18/2012 02:15 PM, Peter Meerwald wrote:
>>
>>>> index to a negative number, which will cause iio_buffer_register to ignore
>>>> the
>>>> channel.
>>
>> ah, nice, I wondered about the same thing :)
>>
>>>> --- 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)
>>
>> whitespace before/after<  could be improved
>>
>
> That's not in the original patch, Jonathan's mail client seems to like to
> mess-up whitespace when quoting a mail. You'll get used to it ;)
>
Yeah, sorry about that.  No idea why it happens and only does it on my
work machine so never bothered chasing it up!

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

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

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-18 11:44 [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index Lars-Peter Clausen
2012-06-18 11:44 ` [PATCH v4 02/10] iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
2012-06-18 11:44 ` [PATCH v4 03/10] iio:adc:at91: Use new triggered buffer setup helper Lars-Peter Clausen
2012-06-18 11:44 ` [PATCH v4 04/10] staging:iio:adc:ad7192: Use new triggered buffer setup helper function Lars-Peter Clausen
2012-06-18 11:44 ` [PATCH v4 05/10] staging:iio:adc:ad7298: " Lars-Peter Clausen
2012-06-18 12:09   ` Jonathan Cameron
2012-06-18 11:44 ` [PATCH v4 06/10] staging:iio:adc:ad7476: " Lars-Peter Clausen
2012-06-18 11:45 ` [PATCH v4 07/10] staging:iio:adc:ad7606: " Lars-Peter Clausen
2012-06-18 11:45 ` [PATCH v4 08/10] staging:iio:adc:ad7793: " Lars-Peter Clausen
2012-06-18 11:45 ` [PATCH v4 09/10] staging:iio:adc:ad7887: " Lars-Peter Clausen
2012-06-18 11:45 ` [PATCH v4 10/10] staging:iio:adc:ad799x: " Lars-Peter Clausen
2012-06-18 12:08 ` [PATCH v4 01/10] iio: iio_buffer_register: Skip channels with negative scan index Jonathan Cameron
2012-06-18 12:15   ` Peter Meerwald
2012-06-18 12:33     ` Lars-Peter Clausen
2012-06-18 12:47       ` 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.