* [PATCH 0/9] iio: Add helper function for initializing triggered buffers
@ 2012-06-06 11:55 Lars-Peter Clausen
2012-06-06 11:55 ` [PATCH 1/9] staging:iio: " Lars-Peter Clausen
` (8 more replies)
0 siblings, 9 replies; 23+ messages in thread
From: Lars-Peter Clausen @ 2012-06-06 11:55 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen
This series revives some older patches from a few months back which somehow fell
off the table. It introduces two helper functions for managing triggered
buffers, since almost all drivers which use triggered buffers have the same
code for setting up and registering the pollfunc and trigger. New in this series
is that the helper functions now only support kfifo buffers. So only these
drivers which do use a kfifo buffer have been converted. There are a few more
drivers which could make use of these helper functions if we switch them from
the swring buffer to the kfifo buffer. Also new in this series is that the
helper functions are now in their own module, since it has dependencies on
IIO_BUFFER, IIO_KFIFO_BUF and IIO_TRIGGER_BUF but neither of these have
on each other. So putting the helper functions in one of these
modules would add a dependency of the other modules to that module.
- Lars
Lars-Peter Clausen (9):
iio: Add helper function for initializing triggered buffers
iio:adc:at91: Use new triggered buffer setup helper
staging:iio:adc:ad7192: Use new triggered buffer setup helper function
staging:iio:adc:ad7298: Use new triggered buffer setup helper function
staging:iio:adc:ad7476: Use new triggered buffer setup helper function
staging:iio:adc:ad7606: Use new triggered buffer setup helper function
staging:iio:adc:ad7793: Use new triggered buffer setup helper function
staging:iio:adc:ad7887: Use new triggered buffer setup helper function
staging:iio:adc:ad799x: Use new triggered buffer setup helper function
drivers/iio/Kconfig | 7 ++
drivers/iio/Makefile | 1 +
drivers/iio/adc/Kconfig | 2 +-
drivers/iio/adc/at91_adc.c | 49 +-----------
drivers/iio/industrialio-triggered-buffer.c | 109 +++++++++++++++++++++++++++
drivers/staging/iio/adc/Kconfig | 7 ++
drivers/staging/iio/adc/ad7192.c | 47 ++----------
drivers/staging/iio/adc/ad7298.h | 5 ++
drivers/staging/iio/adc/ad7298_core.c | 11 +--
drivers/staging/iio/adc/ad7298_ring.c | 62 +++------------
drivers/staging/iio/adc/ad7476_core.c | 9 ---
drivers/staging/iio/adc/ad7476_ring.c | 44 +----------
drivers/staging/iio/adc/ad7606_core.c | 9 ---
drivers/staging/iio/adc/ad7606_ring.c | 44 +----------
drivers/staging/iio/adc/ad7793.c | 47 ++----------
drivers/staging/iio/adc/ad7887_core.c | 9 ---
drivers/staging/iio/adc/ad7887_ring.c | 33 +-------
drivers/staging/iio/adc/ad799x.h | 2 -
drivers/staging/iio/adc/ad799x_core.c | 25 +++---
drivers/staging/iio/adc/ad799x_ring.c | 63 +---------------
include/linux/iio/buffer.h | 7 ++
21 files changed, 189 insertions(+), 403 deletions(-)
create mode 100644 drivers/iio/industrialio-triggered-buffer.c
--
1.7.10
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH 1/9] staging:iio: Add helper function for initializing triggered buffers
2012-06-06 11:55 [PATCH 0/9] iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
@ 2012-06-06 11:55 ` Lars-Peter Clausen
2012-06-07 19:09 ` Jonathan Cameron
2012-06-06 11:55 ` [PATCH 2/9] iio:adc:at91: Use new triggered buffer setup helper Lars-Peter Clausen
` (7 subsequent siblings)
8 siblings, 1 reply; 23+ messages in thread
From: Lars-Peter Clausen @ 2012-06-06 11:55 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 triggered buffer. It will allocate the buffer, allocate
the pollfunc and register the buffer.
Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
drivers/iio/Kconfig | 7 ++
drivers/iio/Makefile | 1 +
drivers/iio/industrialio-triggered-buffer.c | 109 +++++++++++++++++++++++++++
include/linux/iio/buffer.h | 7 ++
4 files changed, 124 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..653ebe5
--- /dev/null
+++ b/drivers/iio/industrialio-triggered-buffer.c
@@ -0,0 +1,109 @@
+ /*
+ * 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/trigger_consumer.h>
+#include <linux/iio/kfifo_buf.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 simple software ringbuffer 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
+ * completly initzialized but not yet registered.
+ *
+ * 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_deallocate_sw_rb;
+ }
+
+ /* 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_deallocate_sw_rb:
+ 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/buffer.h b/include/linux/iio/buffer.h
index fb0fe46..1b3d3eb 100644
--- a/include/linux/iio/buffer.h
+++ b/include/linux/iio/buffer.h
@@ -10,6 +10,7 @@
#ifndef _IIO_BUFFER_GENERIC_H_
#define _IIO_BUFFER_GENERIC_H_
#include <linux/sysfs.h>
+#include <linux/interrupt.h>
#include <linux/iio/iio.h>
#ifdef CONFIG_IIO_BUFFER
@@ -174,6 +175,12 @@ ssize_t iio_buffer_show_enable(struct device *dev,
int iio_sw_buffer_preenable(struct iio_dev *indio_dev);
+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);
+
#else /* CONFIG_IIO_BUFFER */
static inline int iio_buffer_register(struct iio_dev *indio_dev,
--
1.7.10
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH 2/9] iio:adc:at91: Use new triggered buffer setup helper
2012-06-06 11:55 [PATCH 0/9] iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
2012-06-06 11:55 ` [PATCH 1/9] staging:iio: " Lars-Peter Clausen
@ 2012-06-06 11:55 ` Lars-Peter Clausen
2012-06-07 20:02 ` Jonathan Cameron
2012-06-06 11:55 ` [PATCH 3/9] staging:iio:adc:ad7192: Use new triggered buffer setup helper function Lars-Peter Clausen
` (6 subsequent siblings)
8 siblings, 1 reply; 23+ messages in thread
From: Lars-Peter Clausen @ 2012-06-06 11:55 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>
---
drivers/iio/adc/Kconfig | 2 +-
drivers/iio/adc/at91_adc.c | 49 +++-----------------------------------------
2 files changed, 4 insertions(+), 47 deletions(-)
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 9a0df81..bbd2291 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -7,7 +7,7 @@ config AT91_ADC
tristate "Atmel AT91 ADC"
depends on ARCH_AT91
select IIO_BUFFER
- select IIO_KFIFO_BUF
+ select IIO_TRIGGERED_BUFFER
select IIO_TRIGGER
select SYSFS
help
diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
index f18a95d..ad2934a 100644
--- a/drivers/iio/adc/at91_adc.c
+++ b/drivers/iio/adc/at91_adc.c
@@ -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] 23+ messages in thread
* [PATCH 3/9] staging:iio:adc:ad7192: Use new triggered buffer setup helper function
2012-06-06 11:55 [PATCH 0/9] iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
2012-06-06 11:55 ` [PATCH 1/9] staging:iio: " Lars-Peter Clausen
2012-06-06 11:55 ` [PATCH 2/9] iio:adc:at91: Use new triggered buffer setup helper Lars-Peter Clausen
@ 2012-06-06 11:55 ` Lars-Peter Clausen
2012-06-07 20:06 ` Jonathan Cameron
2012-06-06 11:55 ` [PATCH 4/9] staging:iio:adc:ad7298: " Lars-Peter Clausen
` (5 subsequent siblings)
8 siblings, 1 reply; 23+ messages in thread
From: Lars-Peter Clausen @ 2012-06-06 11:55 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>
---
drivers/staging/iio/adc/Kconfig | 1 +
drivers/staging/iio/adc/ad7192.c | 47 ++++----------------------------------
2 files changed, 6 insertions(+), 42 deletions(-)
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 2490dd2..8958fca 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -137,6 +137,7 @@ config AD7192
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..548c8bf 100644
--- a/drivers/staging/iio/adc/ad7192.c
+++ b/drivers/staging/iio/adc/ad7192.c
@@ -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] 23+ messages in thread
* [PATCH 4/9] staging:iio:adc:ad7298: Use new triggered buffer setup helper function
2012-06-06 11:55 [PATCH 0/9] iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
` (2 preceding siblings ...)
2012-06-06 11:55 ` [PATCH 3/9] staging:iio:adc:ad7192: Use new triggered buffer setup helper function Lars-Peter Clausen
@ 2012-06-06 11:55 ` Lars-Peter Clausen
2012-06-07 20:11 ` Jonathan Cameron
2012-06-06 11:55 ` [PATCH 5/9] staging:iio:adc:ad7476: " Lars-Peter Clausen
` (4 subsequent siblings)
8 siblings, 1 reply; 23+ messages in thread
From: Lars-Peter Clausen @ 2012-06-06 11:55 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 | 1 +
drivers/staging/iio/adc/ad7298.h | 5 +++
drivers/staging/iio/adc/ad7298_core.c | 11 ++----
drivers/staging/iio/adc/ad7298_ring.c | 62 +++++----------------------------
4 files changed, 17 insertions(+), 62 deletions(-)
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 8958fca..b9ff3d3 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..597a78f 100644
--- a/drivers/staging/iio/adc/ad7298_ring.c
+++ b/drivers/staging/iio/adc/ad7298_ring.c
@@ -19,31 +19,23 @@
#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] 23+ messages in thread
* [PATCH 5/9] staging:iio:adc:ad7476: Use new triggered buffer setup helper function
2012-06-06 11:55 [PATCH 0/9] iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
` (3 preceding siblings ...)
2012-06-06 11:55 ` [PATCH 4/9] staging:iio:adc:ad7298: " Lars-Peter Clausen
@ 2012-06-06 11:55 ` Lars-Peter Clausen
2012-06-07 20:12 ` Jonathan Cameron
2012-06-06 11:55 ` [PATCH 6/9] staging:iio:adc:ad7606: " Lars-Peter Clausen
` (3 subsequent siblings)
8 siblings, 1 reply; 23+ messages in thread
From: Lars-Peter Clausen @ 2012-06-06 11:55 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 | 1 +
drivers/staging/iio/adc/ad7476_core.c | 9 -------
drivers/staging/iio/adc/ad7476_ring.c | 44 +++------------------------------
3 files changed, 4 insertions(+), 50 deletions(-)
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index b9ff3d3..2f057e4 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -75,6 +75,7 @@ config AD7476
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..176c050 100644
--- a/drivers/staging/iio/adc/ad7476_ring.c
+++ b/drivers/staging/iio/adc/ad7476_ring.c
@@ -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] 23+ messages in thread
* [PATCH 6/9] staging:iio:adc:ad7606: Use new triggered buffer setup helper function
2012-06-06 11:55 [PATCH 0/9] iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
` (4 preceding siblings ...)
2012-06-06 11:55 ` [PATCH 5/9] staging:iio:adc:ad7476: " Lars-Peter Clausen
@ 2012-06-06 11:55 ` Lars-Peter Clausen
2012-06-07 20:13 ` Jonathan Cameron
2012-06-06 11:55 ` [PATCH 7/9] staging:iio:adc:ad7793: " Lars-Peter Clausen
` (2 subsequent siblings)
8 siblings, 1 reply; 23+ messages in thread
From: Lars-Peter Clausen @ 2012-06-06 11:55 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 | 1 +
drivers/staging/iio/adc/ad7606_core.c | 9 -------
drivers/staging/iio/adc/ad7606_ring.c | 44 +++------------------------------
3 files changed, 5 insertions(+), 49 deletions(-)
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 2f057e4..4761c58 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -27,6 +27,7 @@ config AD7606
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..8637d99 100644
--- a/drivers/staging/iio/adc/ad7606_ring.c
+++ b/drivers/staging/iio/adc/ad7606_ring.c
@@ -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] 23+ messages in thread
* [PATCH 7/9] staging:iio:adc:ad7793: Use new triggered buffer setup helper function
2012-06-06 11:55 [PATCH 0/9] iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
` (5 preceding siblings ...)
2012-06-06 11:55 ` [PATCH 6/9] staging:iio:adc:ad7606: " Lars-Peter Clausen
@ 2012-06-06 11:55 ` Lars-Peter Clausen
2012-06-07 20:14 ` Jonathan Cameron
2012-06-06 11:55 ` [PATCH 8/9] staging:iio:adc:ad7887: " Lars-Peter Clausen
2012-06-06 11:55 ` [PATCH 9/9] staging:iio:adc:ad799x: " Lars-Peter Clausen
8 siblings, 1 reply; 23+ messages in thread
From: Lars-Peter Clausen @ 2012-06-06 11:55 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>
---
drivers/staging/iio/adc/Kconfig | 1 +
drivers/staging/iio/adc/ad7793.c | 47 ++++----------------------------------
2 files changed, 6 insertions(+), 42 deletions(-)
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 4761c58..d654cd3 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -118,6 +118,7 @@ config AD7793
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..6c70914 100644
--- a/drivers/staging/iio/adc/ad7793.c
+++ b/drivers/staging/iio/adc/ad7793.c
@@ -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] 23+ messages in thread
* [PATCH 8/9] staging:iio:adc:ad7887: Use new triggered buffer setup helper function
2012-06-06 11:55 [PATCH 0/9] iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
` (6 preceding siblings ...)
2012-06-06 11:55 ` [PATCH 7/9] staging:iio:adc:ad7793: " Lars-Peter Clausen
@ 2012-06-06 11:55 ` Lars-Peter Clausen
2012-06-07 20:15 ` Jonathan Cameron
2012-06-06 11:55 ` [PATCH 9/9] staging:iio:adc:ad799x: " Lars-Peter Clausen
8 siblings, 1 reply; 23+ messages in thread
From: Lars-Peter Clausen @ 2012-06-06 11:55 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>
---
drivers/staging/iio/adc/Kconfig | 1 +
drivers/staging/iio/adc/ad7887_core.c | 9 ---------
drivers/staging/iio/adc/ad7887_ring.c | 33 +++------------------------------
3 files changed, 4 insertions(+), 39 deletions(-)
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index d654cd3..36cca0e 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -92,6 +92,7 @@ config AD7887
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..bd48810 100644
--- a/drivers/staging/iio/adc/ad7887_ring.c
+++ b/drivers/staging/iio/adc/ad7887_ring.c
@@ -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] 23+ messages in thread
* [PATCH 9/9] staging:iio:adc:ad799x: Use new triggered buffer setup helper function
2012-06-06 11:55 [PATCH 0/9] iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
` (7 preceding siblings ...)
2012-06-06 11:55 ` [PATCH 8/9] staging:iio:adc:ad7887: " Lars-Peter Clausen
@ 2012-06-06 11:55 ` Lars-Peter Clausen
2012-06-07 20:18 ` Jonathan Cameron
8 siblings, 1 reply; 23+ messages in thread
From: Lars-Peter Clausen @ 2012-06-06 11:55 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 | 1 +
drivers/staging/iio/adc/ad799x.h | 2 --
drivers/staging/iio/adc/ad799x_core.c | 25 +++++++------
drivers/staging/iio/adc/ad799x_ring.c | 63 ++-------------------------------
4 files changed, 19 insertions(+), 72 deletions(-)
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index 36cca0e..6fa3264 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -66,6 +66,7 @@ config AD799X_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..da8d468 100644
--- a/drivers/staging/iio/adc/ad799x_ring.c
+++ b/drivers/staging/iio/adc/ad799x_ring.c
@@ -24,27 +24,6 @@
#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] 23+ messages in thread
* Re: [PATCH 1/9] staging:iio: Add helper function for initializing triggered buffers
2012-06-06 11:55 ` [PATCH 1/9] staging:iio: " Lars-Peter Clausen
@ 2012-06-07 19:09 ` Jonathan Cameron
2012-06-08 7:47 ` Lars-Peter Clausen
0 siblings, 1 reply; 23+ messages in thread
From: Jonathan Cameron @ 2012-06-07 19:09 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio
On 06/06/2012 12:55 PM, Lars-Peter Clausen wrote:
> Add a helper function for executing the common tasks which are usually involved
> in setting up a simple triggered buffer. It will allocate the buffer, allocate
> the pollfunc and register the buffer.
Hi Lars-Peter,
Sorry for the delay in reviewing this.
I'm not entirely sure how this will stand in the long run but the stats
speak for themselves...
Pain that it has to be yet another module but your logic is sound.
Perhaps naming it industrialio-triggered-buffer-helper might
make it's purpose a tiny bit clearer?
Otherwise, this needs it's own header for point of view of code
separation (as it's a separate module).
Beyond that fine by me.
>
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> ---
> drivers/iio/Kconfig | 7 ++
> drivers/iio/Makefile | 1 +
> drivers/iio/industrialio-triggered-buffer.c | 109 +++++++++++++++++++++++++++
> include/linux/iio/buffer.h | 7 ++
> 4 files changed, 124 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..653ebe5
> --- /dev/null
> +++ b/drivers/iio/industrialio-triggered-buffer.c
> @@ -0,0 +1,109 @@
> + /*
> + * 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.
> + *
Nitpick, but loose the bonus white line.
> + */
> +
> +#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/trigger_consumer.h>
> +#include <linux/iio/kfifo_buf.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 simple software ringbuffer 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
> + * completly initzialized but not yet registered.
I'd rather you listed exactly what needs to have happened.
iio_device_alloc I think...
> + *
> + * 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;
the label could do with an update :)
> + goto error_deallocate_sw_rb;
> + }
> +
> + /* 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_deallocate_sw_rb:
> + 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/buffer.h b/include/linux/iio/buffer.h
> index fb0fe46..1b3d3eb 100644
> --- a/include/linux/iio/buffer.h
> +++ b/include/linux/iio/buffer.h
> @@ -10,6 +10,7 @@
> #ifndef _IIO_BUFFER_GENERIC_H_
> #define _IIO_BUFFER_GENERIC_H_
> #include <linux/sysfs.h>
> +#include <linux/interrupt.h>
> #include <linux/iio/iio.h>
>
> #ifdef CONFIG_IIO_BUFFER
> @@ -174,6 +175,12 @@ ssize_t iio_buffer_show_enable(struct device *dev,
>
> int iio_sw_buffer_preenable(struct iio_dev *indio_dev);
>
Break these out to another header. Cleaner separation that way...
> +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);
> +
> #else /* CONFIG_IIO_BUFFER */
>
> static inline int iio_buffer_register(struct iio_dev *indio_dev,
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 2/9] iio:adc:at91: Use new triggered buffer setup helper
2012-06-06 11:55 ` [PATCH 2/9] iio:adc:at91: Use new triggered buffer setup helper Lars-Peter Clausen
@ 2012-06-07 20:02 ` Jonathan Cameron
2012-06-08 7:57 ` Lars-Peter Clausen
0 siblings, 1 reply; 23+ messages in thread
From: Jonathan Cameron @ 2012-06-07 20:02 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio, Maxime Ripard
On 06/06/2012 12:55 PM, Lars-Peter Clausen wrote:
> Use the new triggered buffer setup helper function to allocate and register
> buffer and pollfunc.
>
Other than dropping IIO_TRIGGER select this is fine.
> 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 | 2 +-
> drivers/iio/adc/at91_adc.c | 49 +++-----------------------------------------
> 2 files changed, 4 insertions(+), 47 deletions(-)
>
> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
> index 9a0df81..bbd2291 100644
> --- a/drivers/iio/adc/Kconfig
> +++ b/drivers/iio/adc/Kconfig
> @@ -7,7 +7,7 @@ config AT91_ADC
> tristate "Atmel AT91 ADC"
> depends on ARCH_AT91
> select IIO_BUFFER
> - select IIO_KFIFO_BUF
> + select IIO_TRIGGERED_BUFFER
> select IIO_TRIGGER
given IIO_TRIGGERED_BUFFER selects IIO_TRIGGER, drop that as well.
> select SYSFS
> help
> diff --git a/drivers/iio/adc/at91_adc.c b/drivers/iio/adc/at91_adc.c
> index f18a95d..ad2934a 100644
> --- a/drivers/iio/adc/at91_adc.c
> +++ b/drivers/iio/adc/at91_adc.c
> @@ -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] 23+ messages in thread
* Re: [PATCH 3/9] staging:iio:adc:ad7192: Use new triggered buffer setup helper function
2012-06-06 11:55 ` [PATCH 3/9] staging:iio:adc:ad7192: Use new triggered buffer setup helper function Lars-Peter Clausen
@ 2012-06-07 20:06 ` Jonathan Cameron
0 siblings, 0 replies; 23+ messages in thread
From: Jonathan Cameron @ 2012-06-07 20:06 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio
On 06/06/2012 12:55 PM, Lars-Peter Clausen wrote:
> Use the new triggered buffer setup helper function to allocate and register
> buffer and pollfunc.
Same comment about the select IIO_TRIGGER
>
> 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/ad7192.c | 47 ++++----------------------------------
> 2 files changed, 6 insertions(+), 42 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
> index 2490dd2..8958fca 100644
> --- a/drivers/staging/iio/adc/Kconfig
> +++ b/drivers/staging/iio/adc/Kconfig
> @@ -137,6 +137,7 @@ config AD7192
> 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..548c8bf 100644
> --- a/drivers/staging/iio/adc/ad7192.c
> +++ b/drivers/staging/iio/adc/ad7192.c
> @@ -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);
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 4/9] staging:iio:adc:ad7298: Use new triggered buffer setup helper function
2012-06-06 11:55 ` [PATCH 4/9] staging:iio:adc:ad7298: " Lars-Peter Clausen
@ 2012-06-07 20:11 ` Jonathan Cameron
0 siblings, 0 replies; 23+ messages in thread
From: Jonathan Cameron @ 2012-06-07 20:11 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio
On 06/06/2012 12:55 PM, 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>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 5/9] staging:iio:adc:ad7476: Use new triggered buffer setup helper function
2012-06-06 11:55 ` [PATCH 5/9] staging:iio:adc:ad7476: " Lars-Peter Clausen
@ 2012-06-07 20:12 ` Jonathan Cameron
0 siblings, 0 replies; 23+ messages in thread
From: Jonathan Cameron @ 2012-06-07 20:12 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio
On 06/06/2012 12:55 PM, 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.
Drop the excess select statements and I'm happy...
>
> 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/ad7476_core.c | 9 -------
> drivers/staging/iio/adc/ad7476_ring.c | 44 +++------------------------------
> 3 files changed, 4 insertions(+), 50 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
> index b9ff3d3..2f057e4 100644
> --- a/drivers/staging/iio/adc/Kconfig
> +++ b/drivers/staging/iio/adc/Kconfig
> @@ -75,6 +75,7 @@ config AD7476
> select IIO_BUFFER
> select IIO_KFIFO_BUF
> select IIO_TRIGGER
here again and IIO_KFIFO_BUF as well this time...
> + 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..176c050 100644
> --- a/drivers/staging/iio/adc/ad7476_ring.c
> +++ b/drivers/staging/iio/adc/ad7476_ring.c
> @@ -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);
> }
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 6/9] staging:iio:adc:ad7606: Use new triggered buffer setup helper function
2012-06-06 11:55 ` [PATCH 6/9] staging:iio:adc:ad7606: " Lars-Peter Clausen
@ 2012-06-07 20:13 ` Jonathan Cameron
2012-06-07 20:14 ` Jonathan Cameron
0 siblings, 1 reply; 23+ messages in thread
From: Jonathan Cameron @ 2012-06-07 20:13 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio
On 06/06/2012 12:55 PM, 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/ad7606_core.c | 9 -------
> drivers/staging/iio/adc/ad7606_ring.c | 44 +++------------------------------
> 3 files changed, 5 insertions(+), 49 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
> index 2f057e4..4761c58 100644
> --- a/drivers/staging/iio/adc/Kconfig
> +++ b/drivers/staging/iio/adc/Kconfig
> @@ -27,6 +27,7 @@ config AD7606
> 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..8637d99 100644
> --- a/drivers/staging/iio/adc/ad7606_ring.c
> +++ b/drivers/staging/iio/adc/ad7606_ring.c
> @@ -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);
> }
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 7/9] staging:iio:adc:ad7793: Use new triggered buffer setup helper function
2012-06-06 11:55 ` [PATCH 7/9] staging:iio:adc:ad7793: " Lars-Peter Clausen
@ 2012-06-07 20:14 ` Jonathan Cameron
0 siblings, 0 replies; 23+ messages in thread
From: Jonathan Cameron @ 2012-06-07 20:14 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio
On 06/06/2012 12:55 PM, Lars-Peter Clausen wrote:
> Use the new triggered buffer setup helper function to allocate and register
> buffer and pollfunc.
>
same select issue to fix before sending to Greg...
> 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/ad7793.c | 47 ++++----------------------------------
> 2 files changed, 6 insertions(+), 42 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
> index 4761c58..d654cd3 100644
> --- a/drivers/staging/iio/adc/Kconfig
> +++ b/drivers/staging/iio/adc/Kconfig
> @@ -118,6 +118,7 @@ config AD7793
> select IIO_BUFFER
> select IIO_KFIFO_BUF
> select IIO_TRIGGER
Again, excess select statements...
> + 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..6c70914 100644
> --- a/drivers/staging/iio/adc/ad7793.c
> +++ b/drivers/staging/iio/adc/ad7793.c
> @@ -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);
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 6/9] staging:iio:adc:ad7606: Use new triggered buffer setup helper function
2012-06-07 20:13 ` Jonathan Cameron
@ 2012-06-07 20:14 ` Jonathan Cameron
0 siblings, 0 replies; 23+ messages in thread
From: Jonathan Cameron @ 2012-06-07 20:14 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio
On 06/07/2012 09:13 PM, Jonathan Cameron wrote:
> On 06/06/2012 12:55 PM, 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.
Oops, forgot the same excess select statements issue is here too..
>>
>> 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/ad7606_core.c | 9 -------
>> drivers/staging/iio/adc/ad7606_ring.c | 44 +++------------------------------
>> 3 files changed, 5 insertions(+), 49 deletions(-)
>>
>> diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
>> index 2f057e4..4761c58 100644
>> --- a/drivers/staging/iio/adc/Kconfig
>> +++ b/drivers/staging/iio/adc/Kconfig
>> @@ -27,6 +27,7 @@ config AD7606
>> 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..8637d99 100644
>> --- a/drivers/staging/iio/adc/ad7606_ring.c
>> +++ b/drivers/staging/iio/adc/ad7606_ring.c
>> @@ -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);
>> }
>
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 8/9] staging:iio:adc:ad7887: Use new triggered buffer setup helper function
2012-06-06 11:55 ` [PATCH 8/9] staging:iio:adc:ad7887: " Lars-Peter Clausen
@ 2012-06-07 20:15 ` Jonathan Cameron
0 siblings, 0 replies; 23+ messages in thread
From: Jonathan Cameron @ 2012-06-07 20:15 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio
On 06/06/2012 12:55 PM, Lars-Peter Clausen wrote:
> Use the new triggered buffer setup helper function to allocate and register
> buffer and pollfunc.
>
I'm bored now and will assume you'll deal with the excess select
statements throughout or argue why you didn't in one place!
> 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/ad7887_core.c | 9 ---------
> drivers/staging/iio/adc/ad7887_ring.c | 33 +++------------------------------
> 3 files changed, 4 insertions(+), 39 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
> index d654cd3..36cca0e 100644
> --- a/drivers/staging/iio/adc/Kconfig
> +++ b/drivers/staging/iio/adc/Kconfig
> @@ -92,6 +92,7 @@ config AD7887
> 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..bd48810 100644
> --- a/drivers/staging/iio/adc/ad7887_ring.c
> +++ b/drivers/staging/iio/adc/ad7887_ring.c
> @@ -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);
> }
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 9/9] staging:iio:adc:ad799x: Use new triggered buffer setup helper function
2012-06-06 11:55 ` [PATCH 9/9] staging:iio:adc:ad799x: " Lars-Peter Clausen
@ 2012-06-07 20:18 ` Jonathan Cameron
0 siblings, 0 replies; 23+ messages in thread
From: Jonathan Cameron @ 2012-06-07 20:18 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio
On 06/06/2012 12:55 PM, 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/ad799x.h | 2 --
> drivers/staging/iio/adc/ad799x_core.c | 25 +++++++------
> drivers/staging/iio/adc/ad799x_ring.c | 63 ++-------------------------------
> 4 files changed, 19 insertions(+), 72 deletions(-)
>
> diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
> index 36cca0e..6fa3264 100644
> --- a/drivers/staging/iio/adc/Kconfig
> +++ b/drivers/staging/iio/adc/Kconfig
> @@ -66,6 +66,7 @@ config AD799X_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..da8d468 100644
> --- a/drivers/staging/iio/adc/ad799x_ring.c
> +++ b/drivers/staging/iio/adc/ad799x_ring.c
> @@ -24,27 +24,6 @@
> #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);
> }
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 1/9] staging:iio: Add helper function for initializing triggered buffers
2012-06-07 19:09 ` Jonathan Cameron
@ 2012-06-08 7:47 ` Lars-Peter Clausen
0 siblings, 0 replies; 23+ messages in thread
From: Lars-Peter Clausen @ 2012-06-08 7:47 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: Jonathan Cameron, linux-iio
On 06/07/2012 09:09 PM, Jonathan Cameron wrote:
> On 06/06/2012 12:55 PM, Lars-Peter Clausen wrote:
>> Add a helper function for executing the common tasks which are usually involved
>> in setting up a simple triggered buffer. It will allocate the buffer, allocate
>> the pollfunc and register the buffer.
>
> Hi Lars-Peter,
>
> Sorry for the delay in reviewing this.
>
I usually need longer to respond than you do, so no problem.
> I'm not entirely sure how this will stand in the long run but the stats
> speak for themselves...
>
> Pain that it has to be yet another module but your logic is sound.
> Perhaps naming it industrialio-triggered-buffer-helper might
> make it's purpose a tiny bit clearer?
Yeah, I had that name going through my mind as well but decided against it,
because it is rather long.
>
> Otherwise, this needs it's own header for point of view of code
> separation (as it's a separate module).
Yep, already had that on my todolist for v2.
>
> Beyond that fine by me.
Thanks.
>
> [...]
>> diff --git a/drivers/iio/industrialio-triggered-buffer.c b/drivers/iio/industrialio-triggered-buffer.c
>> new file mode 100644
>> index 0000000..653ebe5
>> --- /dev/null
>> +++ b/drivers/iio/industrialio-triggered-buffer.c
[...]
>> +/**
>> + * iio_triggered_buffer_setup() - Setup simple software ringbuffer 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
>> + * completly initzialized but not yet registered.
> I'd rather you listed exactly what needs to have happened.
> iio_device_alloc I think...
Everything needs to have happened, except for iio_device_register. I'll add
a sentence which that the function should be called right before
iio_device_register.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 2/9] iio:adc:at91: Use new triggered buffer setup helper
2012-06-07 20:02 ` Jonathan Cameron
@ 2012-06-08 7:57 ` Lars-Peter Clausen
2012-06-08 7:59 ` Jonathan Cameron
0 siblings, 1 reply; 23+ messages in thread
From: Lars-Peter Clausen @ 2012-06-08 7:57 UTC (permalink / raw)
To: Jonathan Cameron; +Cc: Jonathan Cameron, linux-iio, Maxime Ripard
On 06/07/2012 10:02 PM, Jonathan Cameron wrote:
> On 06/06/2012 12:55 PM, Lars-Peter Clausen wrote:
>> Use the new triggered buffer setup helper function to allocate and register
>> buffer and pollfunc.
>>
> Other than dropping IIO_TRIGGER select this is fine.
>> 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 | 2 +-
>> drivers/iio/adc/at91_adc.c | 49 +++-----------------------------------------
>> 2 files changed, 4 insertions(+), 47 deletions(-)
>>
>> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
>> index 9a0df81..bbd2291 100644
>> --- a/drivers/iio/adc/Kconfig
>> +++ b/drivers/iio/adc/Kconfig
>> @@ -7,7 +7,7 @@ config AT91_ADC
>> tristate "Atmel AT91 ADC"
>> depends on ARCH_AT91
>> select IIO_BUFFER
>> - select IIO_KFIFO_BUF
>> + select IIO_TRIGGERED_BUFFER
>> select IIO_TRIGGER
> given IIO_TRIGGERED_BUFFER selects IIO_TRIGGER, drop that as well.
The reasoning for keeping it was, that the driver registers it's own trigger
and as such has a direct dependency on the trigger code. Whereas the kfifo
dependency is now implicit. But I can remove the 'select IIO_TRIGGER' if you
prefer it.
Thanks,
- Lars
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH 2/9] iio:adc:at91: Use new triggered buffer setup helper
2012-06-08 7:57 ` Lars-Peter Clausen
@ 2012-06-08 7:59 ` Jonathan Cameron
0 siblings, 0 replies; 23+ messages in thread
From: Jonathan Cameron @ 2012-06-08 7:59 UTC (permalink / raw)
To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio, Maxime Ripard
On 6/8/2012 8:57 AM, Lars-Peter Clausen wrote:
> On 06/07/2012 10:02 PM, Jonathan Cameron wrote:
>> On 06/06/2012 12:55 PM, Lars-Peter Clausen wrote:
>>> Use the new triggered buffer setup helper function to allocate and register
>>> buffer and pollfunc.
>>>
>> Other than dropping IIO_TRIGGER select this is fine.
>>> 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 | 2 +-
>>> drivers/iio/adc/at91_adc.c | 49 +++-----------------------------------------
>>> 2 files changed, 4 insertions(+), 47 deletions(-)
>>>
>>> diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
>>> index 9a0df81..bbd2291 100644
>>> --- a/drivers/iio/adc/Kconfig
>>> +++ b/drivers/iio/adc/Kconfig
>>> @@ -7,7 +7,7 @@ config AT91_ADC
>>> tristate "Atmel AT91 ADC"
>>> depends on ARCH_AT91
>>> select IIO_BUFFER
>>> - select IIO_KFIFO_BUF
>>> + select IIO_TRIGGERED_BUFFER
>>> select IIO_TRIGGER
>> given IIO_TRIGGERED_BUFFER selects IIO_TRIGGER, drop that as well.
>
> The reasoning for keeping it was, that the driver registers it's own trigger
> and as such has a direct dependency on the trigger code. Whereas the kfifo
> dependency is now implicit. But I can remove the 'select IIO_TRIGGER' if you
> prefer it.
I'd argue that your TRIGGERED_BUFFER encapsulates it anyway in a fairly
obvious fashion. Hence yes, I'd prefer it is removed.
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2012-06-08 7:59 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-06 11:55 [PATCH 0/9] iio: Add helper function for initializing triggered buffers Lars-Peter Clausen
2012-06-06 11:55 ` [PATCH 1/9] staging:iio: " Lars-Peter Clausen
2012-06-07 19:09 ` Jonathan Cameron
2012-06-08 7:47 ` Lars-Peter Clausen
2012-06-06 11:55 ` [PATCH 2/9] iio:adc:at91: Use new triggered buffer setup helper Lars-Peter Clausen
2012-06-07 20:02 ` Jonathan Cameron
2012-06-08 7:57 ` Lars-Peter Clausen
2012-06-08 7:59 ` Jonathan Cameron
2012-06-06 11:55 ` [PATCH 3/9] staging:iio:adc:ad7192: Use new triggered buffer setup helper function Lars-Peter Clausen
2012-06-07 20:06 ` Jonathan Cameron
2012-06-06 11:55 ` [PATCH 4/9] staging:iio:adc:ad7298: " Lars-Peter Clausen
2012-06-07 20:11 ` Jonathan Cameron
2012-06-06 11:55 ` [PATCH 5/9] staging:iio:adc:ad7476: " Lars-Peter Clausen
2012-06-07 20:12 ` Jonathan Cameron
2012-06-06 11:55 ` [PATCH 6/9] staging:iio:adc:ad7606: " Lars-Peter Clausen
2012-06-07 20:13 ` Jonathan Cameron
2012-06-07 20:14 ` Jonathan Cameron
2012-06-06 11:55 ` [PATCH 7/9] staging:iio:adc:ad7793: " Lars-Peter Clausen
2012-06-07 20:14 ` Jonathan Cameron
2012-06-06 11:55 ` [PATCH 8/9] staging:iio:adc:ad7887: " Lars-Peter Clausen
2012-06-07 20:15 ` Jonathan Cameron
2012-06-06 11:55 ` [PATCH 9/9] staging:iio:adc:ad799x: " Lars-Peter Clausen
2012-06-07 20:18 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).