linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 01/10] staging:iio: Add wrapper functions around buffer access ops
@ 2011-12-01 14:19 Lars-Peter Clausen
  2011-12-01 14:19 ` [PATCH 02/10] staging:iio: Setup buffer access functions when allocating the buffer Lars-Peter Clausen
                   ` (9 more replies)
  0 siblings, 10 replies; 22+ messages in thread
From: Lars-Peter Clausen @ 2011-12-01 14:19 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, linux-iio, device-drivers-devel, drivers,
	Lars-Peter Clausen

Add some convenience wrapper functions around the buffer access operations. This
makes the resulting code both a bit easier to read and to write.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
The patches in this series depend on Jonathans buffer cleanup patches.
---
 drivers/staging/iio/buffer.h              |   68 +++++++++++++++++++++++++++++
 drivers/staging/iio/industrialio-buffer.c |   63 +++++++++++---------------
 2 files changed, 95 insertions(+), 36 deletions(-)

diff --git a/drivers/staging/iio/buffer.h b/drivers/staging/iio/buffer.h
index c697099..9383d2d 100644
--- a/drivers/staging/iio/buffer.h
+++ b/drivers/staging/iio/buffer.h
@@ -194,6 +194,74 @@ ssize_t iio_buffer_show_enable(struct device *dev,
 
 int iio_sw_buffer_preenable(struct iio_dev *indio_dev);
 
+static inline void buffer_mark_in_use(struct iio_buffer *buffer)
+{
+	if (buffer->access->mark_in_use)
+		buffer->access->mark_in_use(buffer);
+}
+
+static inline void buffer_unmark_in_use(struct iio_buffer *buffer)
+{
+	if (buffer->access->unmark_in_use)
+		buffer->access->unmark_in_use(buffer);
+}
+
+static inline int buffer_store_to(struct iio_buffer *buffer, u8 *data,
+	s64 timestamp)
+{
+	return buffer->access->store_to(buffer, data, timestamp);
+}
+
+static inline int buffer_read_first_n(struct iio_buffer *buffer, size_t n,
+	char __user *buf)
+{
+	return buffer->access->read_first_n(buffer, n, buf);
+}
+
+static inline int buffer_mark_param_change(struct iio_buffer *buffer)
+{
+	if (buffer->access->mark_param_change)
+		return buffer->access->mark_param_change(buffer);
+
+	return 0;
+}
+
+static inline int buffer_request_update(struct iio_buffer *buffer)
+{
+	if (buffer->access->request_update)
+		return buffer->access->request_update(buffer);
+
+	return 0;
+}
+
+static inline int buffer_get_bytes_per_datum(struct iio_buffer *buffer)
+{
+	return buffer->access->get_bytes_per_datum(buffer);
+}
+
+static inline int buffer_set_bytes_per_datum(struct iio_buffer *buffer,
+	size_t bpd)
+{
+	return buffer->access->set_bytes_per_datum(buffer, bpd);
+}
+
+static inline int buffer_get_length(struct iio_buffer *buffer)
+{
+	if (buffer->access->get_length)
+		return buffer->access->get_length(buffer);
+
+	return -ENOSYS;
+}
+
+static inline int buffer_set_length(struct iio_buffer *buffer,
+	int length)
+{
+	if (buffer->access->set_length)
+		return buffer->access->set_length(buffer, length);
+
+	return -ENOSYS;
+}
+
 #else /* CONFIG_IIO_BUFFER */
 
 static inline int iio_buffer_register(struct iio_dev *indio_dev,
diff --git a/drivers/staging/iio/industrialio-buffer.c b/drivers/staging/iio/industrialio-buffer.c
index f131088..165c88e 100644
--- a/drivers/staging/iio/industrialio-buffer.c
+++ b/drivers/staging/iio/industrialio-buffer.c
@@ -43,9 +43,9 @@ ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
 	struct iio_dev *indio_dev = filp->private_data;
 	struct iio_buffer *rb = indio_dev->buffer;
 
-	if (!rb || !rb->access->read_first_n)
+	if (!rb)
 		return -EINVAL;
-	return rb->access->read_first_n(rb, n, buf);
+	return buffer_read_first_n(rb, n, buf);
 }
 
 /**
@@ -69,8 +69,7 @@ int iio_chrdev_buffer_open(struct iio_dev *indio_dev)
 	struct iio_buffer *rb = indio_dev->buffer;
 	if (!rb)
 		return 0;
-	if (rb->access->mark_in_use)
-		rb->access->mark_in_use(rb);
+	buffer_mark_in_use(rb);
 	return 0;
 }
 
@@ -81,8 +80,7 @@ void iio_chrdev_buffer_release(struct iio_dev *indio_dev)
 	if (!rb)
 		return;
 	clear_bit(IIO_BUSY_BIT_POS, &rb->flags);
-	if (rb->access->unmark_in_use)
-		rb->access->unmark_in_use(rb);
+	buffer_unmark_in_use(rb);
 }
 
 void iio_buffer_init(struct iio_buffer *buffer)
@@ -371,12 +369,13 @@ ssize_t iio_buffer_read_length(struct device *dev,
 {
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct iio_buffer *buffer = indio_dev->buffer;
+	int len;
 
-	if (buffer->access->get_length)
-		return sprintf(buf, "%d\n",
-			       buffer->access->get_length(buffer));
+	len = buffer_get_length(buffer);
+	if (len < 0)
+		return 0;
 
-	return 0;
+	return sprintf(buf, "%d\n", len);
 }
 EXPORT_SYMBOL(iio_buffer_read_length);
 
@@ -394,15 +393,13 @@ ssize_t iio_buffer_write_length(struct device *dev,
 	if (ret)
 		return ret;
 
-	if (buffer->access->get_length)
-		if (val == buffer->access->get_length(buffer))
-			return len;
+	ret = buffer_get_length(buffer);
+	if (ret >= 0 && ret == val)
+		return len;
 
-	if (buffer->access->set_length) {
-		buffer->access->set_length(buffer, val);
-		if (buffer->access->mark_param_change)
-			buffer->access->mark_param_change(buffer);
-	}
+	ret = buffer_set_length(buffer, val);
+	if (ret)
+		buffer_mark_param_change(buffer);
 
 	return len;
 }
@@ -437,25 +434,21 @@ ssize_t iio_buffer_store_enable(struct device *dev,
 				goto error_ret;
 			}
 		}
-		if (buffer->access->request_update) {
-			ret = buffer->access->request_update(buffer);
-			if (ret) {
-				printk(KERN_INFO
-				       "Buffer not started:"
-				       "buffer parameter update failed\n");
-				goto error_ret;
-			}
+		ret = buffer_request_update(buffer);
+		if (ret) {
+			printk(KERN_INFO
+				   "Buffer not started:"
+				   "buffer parameter update failed\n");
+			goto error_ret;
 		}
-		if (buffer->access->mark_in_use)
-			buffer->access->mark_in_use(buffer);
+		buffer_mark_in_use(buffer);
 		/* Definitely possible for devices to support both of these.*/
 		if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) {
 			if (!indio_dev->trig) {
 				printk(KERN_INFO
 				       "Buffer not started: no trigger\n");
 				ret = -EINVAL;
-				if (buffer->access->unmark_in_use)
-					buffer->access->unmark_in_use(buffer);
+				buffer_unmark_in_use(buffer);
 				goto error_ret;
 			}
 			indio_dev->currentmode = INDIO_BUFFER_TRIGGERED;
@@ -472,8 +465,7 @@ ssize_t iio_buffer_store_enable(struct device *dev,
 				printk(KERN_INFO
 				       "Buffer not started:"
 				       "postenable failed\n");
-				if (buffer->access->unmark_in_use)
-					buffer->access->unmark_in_use(buffer);
+				buffer_unmark_in_use(buffer);
 				indio_dev->currentmode = previous_mode;
 				if (indio_dev->setup_ops->postdisable)
 					indio_dev->setup_ops->
@@ -487,8 +479,7 @@ ssize_t iio_buffer_store_enable(struct device *dev,
 			if (ret)
 				goto error_ret;
 		}
-		if (buffer->access->unmark_in_use)
-			buffer->access->unmark_in_use(buffer);
+		buffer_unmark_in_use(buffer);
 		indio_dev->currentmode = INDIO_DIRECT_MODE;
 		if (indio_dev->setup_ops->postdisable) {
 			ret = indio_dev->setup_ops->postdisable(indio_dev);
@@ -556,7 +547,7 @@ int iio_sw_buffer_preenable(struct iio_dev *indio_dev)
 			bytes += length - bytes % length;
 		bytes += length;
 	}
-	buffer->access->set_bytes_per_datum(buffer, bytes);
+	buffer_set_bytes_per_datum(buffer, bytes);
 
 	/* What scan mask do we actually have ?*/
 	if (indio_dev->available_scan_masks)
@@ -674,7 +665,7 @@ int iio_push_to_buffer(struct iio_buffer *buffer, unsigned char *data,
 {
 	unsigned char *dataout = iio_demux(buffer, data);
 
-	return buffer->access->store_to(buffer, dataout, timestamp);
+	return buffer_store_to(buffer, dataout, timestamp);
 }
 EXPORT_SYMBOL_GPL(iio_push_to_buffer);
 
-- 
1.7.7.3

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

* [PATCH 02/10] staging:iio: Setup buffer access functions when allocating the buffer
  2011-12-01 14:19 [PATCH 01/10] staging:iio: Add wrapper functions around buffer access ops Lars-Peter Clausen
@ 2011-12-01 14:19 ` Lars-Peter Clausen
  2011-12-01 20:48   ` Jonathan Cameron
  2011-12-01 14:19 ` [PATCH 03/10] staging:iio:ring_sw: Add helper function for initializing simple setups Lars-Peter Clausen
                   ` (8 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Lars-Peter Clausen @ 2011-12-01 14:19 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, linux-iio, device-drivers-devel, drivers,
	Lars-Peter Clausen

Setup the buffer access functions in the buffer allocate function. There is no
need to let each driver handle this on its own.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/accel/adis16201_ring.c      |    2 --
 drivers/staging/iio/accel/adis16203_ring.c      |    2 --
 drivers/staging/iio/accel/adis16204_ring.c      |    2 --
 drivers/staging/iio/accel/adis16209_ring.c      |    2 --
 drivers/staging/iio/accel/adis16240_ring.c      |    2 --
 drivers/staging/iio/accel/lis3l02dq.h           |    2 --
 drivers/staging/iio/accel/lis3l02dq_ring.c      |    2 --
 drivers/staging/iio/adc/ad7192.c                |    2 --
 drivers/staging/iio/adc/ad7298_ring.c           |    3 ---
 drivers/staging/iio/adc/ad7476_ring.c           |    2 --
 drivers/staging/iio/adc/ad7606_ring.c           |    2 --
 drivers/staging/iio/adc/ad7793.c                |    2 --
 drivers/staging/iio/adc/ad7887_ring.c           |    2 --
 drivers/staging/iio/adc/ad799x_ring.c           |    2 --
 drivers/staging/iio/adc/max1363_ring.c          |    2 --
 drivers/staging/iio/gyro/adis16260_ring.c       |    2 --
 drivers/staging/iio/iio_simple_dummy_buffer.c   |    2 --
 drivers/staging/iio/impedance-analyzer/ad5933.c |    3 ---
 drivers/staging/iio/imu/adis16400_ring.c        |    2 --
 drivers/staging/iio/kfifo_buf.c                 |    1 +
 drivers/staging/iio/meter/ade7758_ring.c        |    2 --
 drivers/staging/iio/ring_sw.c                   |    1 +
 22 files changed, 2 insertions(+), 42 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201_ring.c b/drivers/staging/iio/accel/adis16201_ring.c
index 26c610f..97f9e6b 100644
--- a/drivers/staging/iio/accel/adis16201_ring.c
+++ b/drivers/staging/iio/accel/adis16201_ring.c
@@ -115,9 +115,7 @@ int adis16201_configure_ring(struct iio_dev *indio_dev)
 		return ret;
 	}
 	indio_dev->buffer = ring;
-	/* Effectively select the ring buffer implementation */
 	ring->scan_timestamp = true;
-	ring->access = &ring_sw_access_funcs;
 	indio_dev->setup_ops = &adis16201_ring_setup_ops;
 
 	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
diff --git a/drivers/staging/iio/accel/adis16203_ring.c b/drivers/staging/iio/accel/adis16203_ring.c
index 064640d..6a8963d 100644
--- a/drivers/staging/iio/accel/adis16203_ring.c
+++ b/drivers/staging/iio/accel/adis16203_ring.c
@@ -117,9 +117,7 @@ int adis16203_configure_ring(struct iio_dev *indio_dev)
 		return ret;
 	}
 	indio_dev->buffer = ring;
-	/* Effectively select the ring buffer implementation */
 	ring->scan_timestamp = true;
-	ring->access = &ring_sw_access_funcs;
 	indio_dev->setup_ops = &adis16203_ring_setup_ops;
 
 	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
diff --git a/drivers/staging/iio/accel/adis16204_ring.c b/drivers/staging/iio/accel/adis16204_ring.c
index 4081179..5c8ab73 100644
--- a/drivers/staging/iio/accel/adis16204_ring.c
+++ b/drivers/staging/iio/accel/adis16204_ring.c
@@ -112,8 +112,6 @@ int adis16204_configure_ring(struct iio_dev *indio_dev)
 		return ret;
 	}
 	indio_dev->buffer = ring;
-	/* Effectively select the ring buffer implementation */
-	ring->access = &ring_sw_access_funcs;
 	ring->scan_timestamp = true;
 	indio_dev->setup_ops = &adis16204_ring_setup_ops;
 
diff --git a/drivers/staging/iio/accel/adis16209_ring.c b/drivers/staging/iio/accel/adis16209_ring.c
index 2a6fd334..57254b6 100644
--- a/drivers/staging/iio/accel/adis16209_ring.c
+++ b/drivers/staging/iio/accel/adis16209_ring.c
@@ -113,8 +113,6 @@ int adis16209_configure_ring(struct iio_dev *indio_dev)
 		return ret;
 	}
 	indio_dev->buffer = ring;
-	/* Effectively select the ring buffer implementation */
-	ring->access = &ring_sw_access_funcs;
 	ring->scan_timestamp = true;
 	indio_dev->setup_ops = &adis16209_ring_setup_ops;
 
diff --git a/drivers/staging/iio/accel/adis16240_ring.c b/drivers/staging/iio/accel/adis16240_ring.c
index e23622d..43ba84e 100644
--- a/drivers/staging/iio/accel/adis16240_ring.c
+++ b/drivers/staging/iio/accel/adis16240_ring.c
@@ -110,8 +110,6 @@ int adis16240_configure_ring(struct iio_dev *indio_dev)
 		return ret;
 	}
 	indio_dev->buffer = ring;
-	/* Effectively select the ring buffer implementation */
-	ring->access = &ring_sw_access_funcs;
 	ring->scan_timestamp = true;
 	indio_dev->setup_ops = &adis16240_ring_setup_ops;
 
diff --git a/drivers/staging/iio/accel/lis3l02dq.h b/drivers/staging/iio/accel/lis3l02dq.h
index 2db383f..ae5f225 100644
--- a/drivers/staging/iio/accel/lis3l02dq.h
+++ b/drivers/staging/iio/accel/lis3l02dq.h
@@ -187,12 +187,10 @@ void lis3l02dq_unconfigure_buffer(struct iio_dev *indio_dev);
 #ifdef CONFIG_LIS3L02DQ_BUF_RING_SW
 #define lis3l02dq_free_buf iio_sw_rb_free
 #define lis3l02dq_alloc_buf iio_sw_rb_allocate
-#define lis3l02dq_access_funcs ring_sw_access_funcs
 #endif
 #ifdef CONFIG_LIS3L02DQ_BUF_KFIFO
 #define lis3l02dq_free_buf iio_kfifo_free
 #define lis3l02dq_alloc_buf iio_kfifo_allocate
-#define lis3l02dq_access_funcs kfifo_access_funcs
 #endif
 irqreturn_t lis3l02dq_data_rdy_trig_poll(int irq, void *private);
 #define lis3l02dq_th lis3l02dq_data_rdy_trig_poll
diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c
index c81d0e2..1cf53d7 100644
--- a/drivers/staging/iio/accel/lis3l02dq_ring.c
+++ b/drivers/staging/iio/accel/lis3l02dq_ring.c
@@ -406,8 +406,6 @@ int lis3l02dq_configure_buffer(struct iio_dev *indio_dev)
 		return -ENOMEM;
 
 	indio_dev->buffer = buffer;
-	/* Effectively select the buffer implementation */
-	indio_dev->buffer->access = &lis3l02dq_access_funcs;
 
 	buffer->scan_timestamp = true;
 	indio_dev->setup_ops = &lis3l02dq_buffer_setup_ops;
diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
index 66cc507..ab0cd10 100644
--- a/drivers/staging/iio/adc/ad7192.c
+++ b/drivers/staging/iio/adc/ad7192.c
@@ -561,8 +561,6 @@ static int ad7192_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 		ret = -ENOMEM;
 		goto error_ret;
 	}
-	/* Effectively select the ring buffer implementation */
-	indio_dev->buffer->access = &ring_sw_access_funcs;
 	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
 						 &ad7192_trigger_handler,
 						 IRQF_ONESHOT,
diff --git a/drivers/staging/iio/adc/ad7298_ring.c b/drivers/staging/iio/adc/ad7298_ring.c
index d1a12dd..feeb0ee 100644
--- a/drivers/staging/iio/adc/ad7298_ring.c
+++ b/drivers/staging/iio/adc/ad7298_ring.c
@@ -131,9 +131,6 @@ int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 		ret = -ENOMEM;
 		goto error_ret;
 	}
-	/* Effectively select the ring buffer implementation */
-	indio_dev->buffer->access = &ring_sw_access_funcs;
-
 	indio_dev->pollfunc = iio_alloc_pollfunc(NULL,
 						 &ad7298_trigger_handler,
 						 IRQF_ONESHOT,
diff --git a/drivers/staging/iio/adc/ad7476_ring.c b/drivers/staging/iio/adc/ad7476_ring.c
index 4e298b2..35a8576 100644
--- a/drivers/staging/iio/adc/ad7476_ring.c
+++ b/drivers/staging/iio/adc/ad7476_ring.c
@@ -98,8 +98,6 @@ int ad7476_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 		ret = -ENOMEM;
 		goto error_ret;
 	}
-	/* Effectively select the ring buffer implementation */
-	indio_dev->buffer->access = &ring_sw_access_funcs;
 	indio_dev->pollfunc
 		= iio_alloc_pollfunc(NULL,
 				     &ad7476_trigger_handler,
diff --git a/drivers/staging/iio/adc/ad7606_ring.c b/drivers/staging/iio/adc/ad7606_ring.c
index e8f94a1..1ef9fbc 100644
--- a/drivers/staging/iio/adc/ad7606_ring.c
+++ b/drivers/staging/iio/adc/ad7606_ring.c
@@ -110,8 +110,6 @@ int ad7606_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 		goto error_ret;
 	}
 
-	/* Effectively select the ring buffer implementation */
-	indio_dev->buffer->access = &ring_sw_access_funcs;
 	indio_dev->pollfunc = iio_alloc_pollfunc(&ad7606_trigger_handler_th_bh,
 						 &ad7606_trigger_handler_th_bh,
 						 0,
diff --git a/drivers/staging/iio/adc/ad7793.c b/drivers/staging/iio/adc/ad7793.c
index f2f1081..deb2c17 100644
--- a/drivers/staging/iio/adc/ad7793.c
+++ b/drivers/staging/iio/adc/ad7793.c
@@ -427,8 +427,6 @@ static int ad7793_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 		ret = -ENOMEM;
 		goto error_ret;
 	}
-	/* Effectively select the ring buffer implementation */
-	indio_dev->buffer->access = &ring_sw_access_funcs;
 	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
 						 &ad7793_trigger_handler,
 						 IRQF_ONESHOT,
diff --git a/drivers/staging/iio/adc/ad7887_ring.c b/drivers/staging/iio/adc/ad7887_ring.c
index 85076cd..d180907 100644
--- a/drivers/staging/iio/adc/ad7887_ring.c
+++ b/drivers/staging/iio/adc/ad7887_ring.c
@@ -131,8 +131,6 @@ int ad7887_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 		ret = -ENOMEM;
 		goto error_ret;
 	}
-	/* Effectively select the ring buffer implementation */
-	indio_dev->buffer->access = &ring_sw_access_funcs;
 	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
 						 &ad7887_trigger_handler,
 						 IRQF_ONESHOT,
diff --git a/drivers/staging/iio/adc/ad799x_ring.c b/drivers/staging/iio/adc/ad799x_ring.c
index 5dded9e..28e9a41 100644
--- a/drivers/staging/iio/adc/ad799x_ring.c
+++ b/drivers/staging/iio/adc/ad799x_ring.c
@@ -141,8 +141,6 @@ int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 		ret = -ENOMEM;
 		goto error_ret;
 	}
-	/* Effectively select the ring buffer implementation */
-	indio_dev->buffer->access = &ring_sw_access_funcs;
 	indio_dev->pollfunc = iio_alloc_pollfunc(NULL,
 						 &ad799x_trigger_handler,
 						 IRQF_ONESHOT,
diff --git a/drivers/staging/iio/adc/max1363_ring.c b/drivers/staging/iio/adc/max1363_ring.c
index f730b3f..d0a60a3 100644
--- a/drivers/staging/iio/adc/max1363_ring.c
+++ b/drivers/staging/iio/adc/max1363_ring.c
@@ -116,8 +116,6 @@ int max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 		ret = -ENOMEM;
 		goto error_deallocate_sw_rb;
 	}
-	/* Effectively select the ring buffer implementation */
-	indio_dev->buffer->access = &ring_sw_access_funcs;
 	/* Ring buffer functions - here trigger setup related */
 	indio_dev->setup_ops = &max1363_ring_setup_ops;
 
diff --git a/drivers/staging/iio/gyro/adis16260_ring.c b/drivers/staging/iio/gyro/adis16260_ring.c
index 699a615..711f151 100644
--- a/drivers/staging/iio/gyro/adis16260_ring.c
+++ b/drivers/staging/iio/gyro/adis16260_ring.c
@@ -115,8 +115,6 @@ int adis16260_configure_ring(struct iio_dev *indio_dev)
 		return ret;
 	}
 	indio_dev->buffer = ring;
-	/* Effectively select the ring buffer implementation */
-	ring->access = &ring_sw_access_funcs;
 	ring->scan_timestamp = true;
 	indio_dev->setup_ops = &adis16260_ring_setup_ops;
 
diff --git a/drivers/staging/iio/iio_simple_dummy_buffer.c b/drivers/staging/iio/iio_simple_dummy_buffer.c
index d6a1c0e..bb4daf7 100644
--- a/drivers/staging/iio/iio_simple_dummy_buffer.c
+++ b/drivers/staging/iio/iio_simple_dummy_buffer.c
@@ -142,8 +142,6 @@ int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
 	}
 
 	indio_dev->buffer = buffer;
-	/* Tell the core how to access the buffer */
-	buffer->access = &kfifo_access_funcs;
 
 	/* Enable timestamps by default */
 	buffer->scan_timestamp = true;
diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index f02d1c0..4138082 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -607,9 +607,6 @@ static int ad5933_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 	if (!indio_dev->buffer)
 		return -ENOMEM;
 
-	/* Effectively select the ring buffer implementation */
-	indio_dev->buffer->access = &ring_sw_access_funcs;
-
 	/* Ring buffer functions - here trigger setup related */
 	indio_dev->setup_ops = &ad5933_ring_setup_ops;
 
diff --git a/drivers/staging/iio/imu/adis16400_ring.c b/drivers/staging/iio/imu/adis16400_ring.c
index ac22de5..8daa038 100644
--- a/drivers/staging/iio/imu/adis16400_ring.c
+++ b/drivers/staging/iio/imu/adis16400_ring.c
@@ -187,8 +187,6 @@ int adis16400_configure_ring(struct iio_dev *indio_dev)
 		return ret;
 	}
 	indio_dev->buffer = ring;
-	/* Effectively select the ring buffer implementation */
-	ring->access = &ring_sw_access_funcs;
 	ring->scan_timestamp = true;
 	indio_dev->setup_ops = &adis16400_ring_setup_ops;
 
diff --git a/drivers/staging/iio/kfifo_buf.c b/drivers/staging/iio/kfifo_buf.c
index d8867ab..a64ebbf 100644
--- a/drivers/staging/iio/kfifo_buf.c
+++ b/drivers/staging/iio/kfifo_buf.c
@@ -98,6 +98,7 @@ struct iio_buffer *iio_kfifo_allocate(struct iio_dev *indio_dev)
 	kf->update_needed = true;
 	iio_buffer_init(&kf->buffer);
 	kf->buffer.attrs = &iio_kfifo_attribute_group;
+	kf->buffer->access = kfifo_access_funcs;
 	__iio_init_kfifo(kf);
 
 	return &kf->buffer;
diff --git a/drivers/staging/iio/meter/ade7758_ring.c b/drivers/staging/iio/meter/ade7758_ring.c
index f29f2b2..c5c522b 100644
--- a/drivers/staging/iio/meter/ade7758_ring.c
+++ b/drivers/staging/iio/meter/ade7758_ring.c
@@ -144,8 +144,6 @@ int ade7758_configure_ring(struct iio_dev *indio_dev)
 		return ret;
 	}
 
-	/* Effectively select the ring buffer implementation */
-	indio_dev->buffer->access = &ring_sw_access_funcs;
 	indio_dev->setup_ops = &ade7758_ring_setup_ops;
 
 	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
diff --git a/drivers/staging/iio/ring_sw.c b/drivers/staging/iio/ring_sw.c
index a541a73..879c709 100644
--- a/drivers/staging/iio/ring_sw.c
+++ b/drivers/staging/iio/ring_sw.c
@@ -388,6 +388,7 @@ struct iio_buffer *iio_sw_rb_allocate(struct iio_dev *indio_dev)
 	iio_buffer_init(buf);
 	__iio_init_sw_ring_buffer(ring);
 	buf->attrs = &iio_ring_attribute_group;
+	buf->access = &ring_sw_access_funcs;
 
 	return buf;
 }
-- 
1.7.7.3

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

* [PATCH 03/10] staging:iio:ring_sw: Add helper function for initializing simple setups
  2011-12-01 14:19 [PATCH 01/10] staging:iio: Add wrapper functions around buffer access ops Lars-Peter Clausen
  2011-12-01 14:19 ` [PATCH 02/10] staging:iio: Setup buffer access functions when allocating the buffer Lars-Peter Clausen
@ 2011-12-01 14:19 ` Lars-Peter Clausen
  2011-12-01 20:51   ` Jonathan Cameron
  2011-12-01 14:19 ` [PATCH 04/10] staging:iio:imu:adis16400: Use new ringbuffer setup helper function Lars-Peter Clausen
                   ` (7 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Lars-Peter Clausen @ 2011-12-01 14:19 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, linux-iio, device-drivers-devel, drivers,
	Lars-Peter Clausen

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

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/ring_sw.c |   83 ++++++++++++++++++++++++++++++++++++++++-
 drivers/staging/iio/ring_sw.h |    8 ++++
 2 files changed, 90 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/iio/ring_sw.c b/drivers/staging/iio/ring_sw.c
index 879c709..c93b069 100644
--- a/drivers/staging/iio/ring_sw.c
+++ b/drivers/staging/iio/ring_sw.c
@@ -15,7 +15,8 @@
 #include <linux/sched.h>
 #include <linux/poll.h>
 #include "ring_sw.h"
-#include "trigger.h"
+#include "buffer.h"
+#include "trigger_consumer.h"
 
 /**
  * struct iio_sw_ring_buffer - software ring buffer
@@ -414,5 +415,85 @@ const struct iio_buffer_access_funcs ring_sw_access_funcs = {
 };
 EXPORT_SYMBOL(ring_sw_access_funcs);
 
+static const struct iio_buffer_setup_ops iio_sw_rb_simple_setup_ops = {
+	.preenable = &iio_sw_buffer_preenable,
+	.postenable = &iio_triggered_buffer_postenable,
+	.predisable = &iio_triggered_buffer_predisable,
+};
+
+/*
+ * iio_sw_rb_simple_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
+ *
+ * This function combines some common tasks which will normally be performed
+ * when setting up a simple software ringbuffer. It will allocate the ringbuffer
+ * 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_sw_rb_simple_cleanup
+ * should be called.
+ */
+int iio_sw_rb_simple_setup(struct iio_dev *indio_dev,
+	irqreturn_t (*pollfunc_bh)(int irq, void *p),
+	irqreturn_t (*pollfunc_th)(int irq, void *p))
+{
+	int ret;
+
+	indio_dev->buffer = iio_sw_rb_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 */
+	indio_dev->setup_ops = &iio_sw_rb_simple_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_sw_rb_free(indio_dev->buffer);
+error_ret:
+	return ret;
+}
+EXPORT_SYMBOL(iio_sw_rb_simple_setup);
+
+/*
+ * iio_sw_rb_simple_cleanup - Free resources allocated by iio_sw_rb_simple_setup
+ * @indio_dev:		IIO device structure
+ */
+void iio_sw_rb_simple_cleanup(struct iio_dev *indio_dev)
+{
+	iio_buffer_unregister(indio_dev);
+	iio_dealloc_pollfunc(indio_dev->pollfunc);
+	iio_sw_rb_free(indio_dev->buffer);
+}
+EXPORT_SYMBOL(iio_sw_rb_simple_cleanup);
+
 MODULE_DESCRIPTION("Industrialio I/O software ring buffer");
 MODULE_LICENSE("GPL");
diff --git a/drivers/staging/iio/ring_sw.h b/drivers/staging/iio/ring_sw.h
index e6a6e2c..69ed561 100644
--- a/drivers/staging/iio/ring_sw.h
+++ b/drivers/staging/iio/ring_sw.h
@@ -23,6 +23,8 @@
 
 #ifndef _IIO_RING_SW_H_
 #define _IIO_RING_SW_H_
+
+#include <linux/interrupt.h>
 #include "buffer.h"
 
 /**
@@ -32,4 +34,10 @@ extern const struct iio_buffer_access_funcs ring_sw_access_funcs;
 
 struct iio_buffer *iio_sw_rb_allocate(struct iio_dev *indio_dev);
 void iio_sw_rb_free(struct iio_buffer *ring);
+
+int iio_sw_rb_simple_setup(struct iio_dev *indio_dev,
+	irqreturn_t (*pollfunc_bh)(int irq, void *p),
+	irqreturn_t (*pollfunc_th)(int irq, void *p));
+void iio_sw_rb_simple_cleanup(struct iio_dev *indio_dev);
+
 #endif /* _IIO_RING_SW_H_ */
-- 
1.7.7.3

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

* [PATCH 04/10] staging:iio:imu:adis16400: Use new ringbuffer setup helper function
  2011-12-01 14:19 [PATCH 01/10] staging:iio: Add wrapper functions around buffer access ops Lars-Peter Clausen
  2011-12-01 14:19 ` [PATCH 02/10] staging:iio: Setup buffer access functions when allocating the buffer Lars-Peter Clausen
  2011-12-01 14:19 ` [PATCH 03/10] staging:iio:ring_sw: Add helper function for initializing simple setups Lars-Peter Clausen
@ 2011-12-01 14:19 ` Lars-Peter Clausen
  2011-12-01 20:53   ` Jonathan Cameron
  2011-12-01 14:19 ` [PATCH 05/10] staging:iio:gyro:adis16260: " Lars-Peter Clausen
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Lars-Peter Clausen @ 2011-12-01 14:19 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, linux-iio, device-drivers-devel, drivers,
	Lars-Peter Clausen

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

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/imu/adis16400_core.c |   11 --------
 drivers/staging/iio/imu/adis16400_ring.c |   40 ++---------------------------
 2 files changed, 3 insertions(+), 48 deletions(-)

diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c
index de12f9a..f90ede6 100644
--- a/drivers/staging/iio/imu/adis16400_core.c
+++ b/drivers/staging/iio/imu/adis16400_core.c
@@ -1147,14 +1147,6 @@ static int __devinit adis16400_probe(struct spi_device *spi)
 	if (ret)
 		goto error_free_dev;
 
-	ret = iio_buffer_register(indio_dev,
-				  st->variant->channels,
-				  st->variant->num_channels);
-	if (ret) {
-		dev_err(&spi->dev, "failed to initialize the ring\n");
-		goto error_unreg_ring_funcs;
-	}
-
 	if (spi->irq) {
 		ret = adis16400_probe_trigger(indio_dev);
 		if (ret)
@@ -1175,8 +1167,6 @@ error_remove_trigger:
 	if (indio_dev->modes & INDIO_BUFFER_TRIGGERED)
 		adis16400_remove_trigger(indio_dev);
 error_uninitialize_ring:
-	iio_buffer_unregister(indio_dev);
-error_unreg_ring_funcs:
 	adis16400_unconfigure_ring(indio_dev);
 error_free_dev:
 	iio_free_device(indio_dev);
@@ -1196,7 +1186,6 @@ static int adis16400_remove(struct spi_device *spi)
 		goto err_ret;
 
 	adis16400_remove_trigger(indio_dev);
-	iio_buffer_unregister(indio_dev);
 	adis16400_unconfigure_ring(indio_dev);
 	iio_free_device(indio_dev);
 
diff --git a/drivers/staging/iio/imu/adis16400_ring.c b/drivers/staging/iio/imu/adis16400_ring.c
index 8daa038..4dde936 100644
--- a/drivers/staging/iio/imu/adis16400_ring.c
+++ b/drivers/staging/iio/imu/adis16400_ring.c
@@ -166,45 +166,11 @@ err:
 
 void adis16400_unconfigure_ring(struct iio_dev *indio_dev)
 {
-	iio_dealloc_pollfunc(indio_dev->pollfunc);
-	iio_sw_rb_free(indio_dev->buffer);
+	iio_sw_rb_simple_cleanup(indio_dev);
 }
 
-static const struct iio_buffer_setup_ops adis16400_ring_setup_ops = {
-	.preenable = &iio_sw_buffer_preenable,
-	.postenable = &iio_triggered_buffer_postenable,
-	.predisable = &iio_triggered_buffer_predisable,
-};
-
 int adis16400_configure_ring(struct iio_dev *indio_dev)
 {
-	int ret = 0;
-	struct iio_buffer *ring;
-
-	ring = iio_sw_rb_allocate(indio_dev);
-	if (!ring) {
-		ret = -ENOMEM;
-		return ret;
-	}
-	indio_dev->buffer = ring;
-	ring->scan_timestamp = true;
-	indio_dev->setup_ops = &adis16400_ring_setup_ops;
-
-	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
-						 &adis16400_trigger_handler,
-						 IRQF_ONESHOT,
-						 indio_dev,
-						 "%s_consumer%d",
-						 indio_dev->name,
-						 indio_dev->id);
-	if (indio_dev->pollfunc == NULL) {
-		ret = -ENOMEM;
-		goto error_iio_sw_rb_free;
-	}
-
-	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
-	return 0;
-error_iio_sw_rb_free:
-	iio_sw_rb_free(indio_dev->buffer);
-	return ret;
+	return iio_sw_rb_simple_setup(indio_dev, &iio_pollfunc_store_time,
+		&adis16400_trigger_handler);
 }
-- 
1.7.7.3

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

* [PATCH 05/10] staging:iio:gyro:adis16260: Use new ringbuffer setup helper function
  2011-12-01 14:19 [PATCH 01/10] staging:iio: Add wrapper functions around buffer access ops Lars-Peter Clausen
                   ` (2 preceding siblings ...)
  2011-12-01 14:19 ` [PATCH 04/10] staging:iio:imu:adis16400: Use new ringbuffer setup helper function Lars-Peter Clausen
@ 2011-12-01 14:19 ` Lars-Peter Clausen
  2011-12-01 20:55   ` Jonathan Cameron
  2011-12-01 14:19 ` [PATCH 06/10] staging:iio:accel:adis16201: " Lars-Peter Clausen
                   ` (5 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Lars-Peter Clausen @ 2011-12-01 14:19 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, linux-iio, device-drivers-devel, drivers,
	Lars-Peter Clausen

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

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/gyro/adis16260_core.c |   10 -------
 drivers/staging/iio/gyro/adis16260_ring.c |   39 ++++------------------------
 2 files changed, 6 insertions(+), 43 deletions(-)

diff --git a/drivers/staging/iio/gyro/adis16260_core.c b/drivers/staging/iio/gyro/adis16260_core.c
index 871f76b..1e77eae 100644
--- a/drivers/staging/iio/gyro/adis16260_core.c
+++ b/drivers/staging/iio/gyro/adis16260_core.c
@@ -623,13 +623,6 @@ static int __devinit adis16260_probe(struct spi_device *spi)
 	if (ret)
 		goto error_free_dev;
 
-	ret = iio_buffer_register(indio_dev,
-				  indio_dev->channels,
-				  ARRAY_SIZE(adis16260_channels_x));
-	if (ret) {
-		printk(KERN_ERR "failed to initialize the ring\n");
-		goto error_unreg_ring_funcs;
-	}
 	if (indio_dev->buffer) {
 		/* Set default scan mode */
 		iio_scan_mask_set(indio_dev, indio_dev->buffer,
@@ -662,8 +655,6 @@ static int __devinit adis16260_probe(struct spi_device *spi)
 error_remove_trigger:
 	adis16260_remove_trigger(indio_dev);
 error_uninitialize_ring:
-	iio_buffer_unregister(indio_dev);
-error_unreg_ring_funcs:
 	adis16260_unconfigure_ring(indio_dev);
 error_free_dev:
 	iio_free_device(indio_dev);
@@ -685,7 +676,6 @@ static int adis16260_remove(struct spi_device *spi)
 	flush_scheduled_work();
 
 	adis16260_remove_trigger(indio_dev);
-	iio_buffer_unregister(indio_dev);
 	adis16260_unconfigure_ring(indio_dev);
 	iio_free_device(indio_dev);
 
diff --git a/drivers/staging/iio/gyro/adis16260_ring.c b/drivers/staging/iio/gyro/adis16260_ring.c
index 711f151..c2f5022 100644
--- a/drivers/staging/iio/gyro/adis16260_ring.c
+++ b/drivers/staging/iio/gyro/adis16260_ring.c
@@ -94,45 +94,18 @@ static irqreturn_t adis16260_trigger_handler(int irq, void *p)
 
 void adis16260_unconfigure_ring(struct iio_dev *indio_dev)
 {
-	iio_dealloc_pollfunc(indio_dev->pollfunc);
-	iio_sw_rb_free(indio_dev->buffer);
+	iio_sw_rb_simple_cleanup(indio_dev);
 }
 
-static const struct iio_buffer_setup_ops adis16260_ring_setup_ops = {
-	.preenable = &iio_sw_buffer_preenable,
-	.postenable = &iio_triggered_buffer_postenable,
-	.predisable = &iio_triggered_buffer_predisable,
-};
-
 int adis16260_configure_ring(struct iio_dev *indio_dev)
 {
-	int ret = 0;
-	struct iio_buffer *ring;
+	int ret;
 
-	ring = iio_sw_rb_allocate(indio_dev);
-	if (!ring) {
-		ret = -ENOMEM;
+	ret = iio_sw_rb_simple_setup(indio_dev, &iio_pollfunc_store_time,
+		&adis16260_trigger_handler);
+	if (ret)
 		return ret;
-	}
-	indio_dev->buffer = ring;
-	ring->scan_timestamp = true;
-	indio_dev->setup_ops = &adis16260_ring_setup_ops;
-
-	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
-						 &adis16260_trigger_handler,
-						 IRQF_ONESHOT,
-						 indio_dev,
-						 "adis16260_consumer%d",
-						 indio_dev->id);
-	if (indio_dev->pollfunc == NULL) {
-		ret = -ENOMEM;
-		goto error_iio_sw_rb_free;
-	}
 
-	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
+	indio_dev->buffer->scan_timestamp = true;
 	return 0;
-
-error_iio_sw_rb_free:
-	iio_sw_rb_free(indio_dev->buffer);
-	return ret;
 }
-- 
1.7.7.3



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

* [PATCH 06/10] staging:iio:accel:adis16201: Use new ringbuffer setup helper function
  2011-12-01 14:19 [PATCH 01/10] staging:iio: Add wrapper functions around buffer access ops Lars-Peter Clausen
                   ` (3 preceding siblings ...)
  2011-12-01 14:19 ` [PATCH 05/10] staging:iio:gyro:adis16260: " Lars-Peter Clausen
@ 2011-12-01 14:19 ` Lars-Peter Clausen
  2011-12-01 20:56   ` Jonathan Cameron
  2011-12-01 14:19 ` [PATCH 07/10] staging:iio:adc:max1363: " Lars-Peter Clausen
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Lars-Peter Clausen @ 2011-12-01 14:19 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, linux-iio, device-drivers-devel, drivers,
	Lars-Peter Clausen

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

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/accel/adis16201_core.c |   11 --------
 drivers/staging/iio/accel/adis16201_ring.c |   38 ++++-----------------------
 2 files changed, 6 insertions(+), 43 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201_core.c b/drivers/staging/iio/accel/adis16201_core.c
index ed97da2..29e3c91 100644
--- a/drivers/staging/iio/accel/adis16201_core.c
+++ b/drivers/staging/iio/accel/adis16201_core.c
@@ -491,14 +491,6 @@ static int __devinit adis16201_probe(struct spi_device *spi)
 	if (ret)
 		goto error_free_dev;
 
-	ret = iio_buffer_register(indio_dev,
-				  adis16201_channels,
-				  ARRAY_SIZE(adis16201_channels));
-	if (ret) {
-		printk(KERN_ERR "failed to initialize the ring\n");
-		goto error_unreg_ring_funcs;
-	}
-
 	if (spi->irq) {
 		ret = adis16201_probe_trigger(indio_dev);
 		if (ret)
@@ -518,8 +510,6 @@ static int __devinit adis16201_probe(struct spi_device *spi)
 error_remove_trigger:
 	adis16201_remove_trigger(indio_dev);
 error_uninitialize_ring:
-	iio_buffer_unregister(indio_dev);
-error_unreg_ring_funcs:
 	adis16201_unconfigure_ring(indio_dev);
 error_free_dev:
 	iio_free_device(indio_dev);
@@ -533,7 +523,6 @@ static int adis16201_remove(struct spi_device *spi)
 
 	iio_device_unregister(indio_dev);
 	adis16201_remove_trigger(indio_dev);
-	iio_buffer_unregister(indio_dev);
 	adis16201_unconfigure_ring(indio_dev);
 	iio_free_device(indio_dev);
 
diff --git a/drivers/staging/iio/accel/adis16201_ring.c b/drivers/staging/iio/accel/adis16201_ring.c
index 97f9e6b..882a1e3 100644
--- a/drivers/staging/iio/accel/adis16201_ring.c
+++ b/drivers/staging/iio/accel/adis16201_ring.c
@@ -94,44 +94,18 @@ static irqreturn_t adis16201_trigger_handler(int irq, void *p)
 
 void adis16201_unconfigure_ring(struct iio_dev *indio_dev)
 {
-	iio_dealloc_pollfunc(indio_dev->pollfunc);
-	iio_sw_rb_free(indio_dev->buffer);
+	iio_sw_rb_simple_cleanup(indio_dev);
 }
 
-static const struct iio_buffer_setup_ops adis16201_ring_setup_ops = {
-	.preenable = &iio_sw_buffer_preenable,
-	.postenable = &iio_triggered_buffer_postenable,
-	.predisable = &iio_triggered_buffer_predisable,
-};
-
 int adis16201_configure_ring(struct iio_dev *indio_dev)
 {
-	int ret = 0;
-	struct iio_buffer *ring;
+	int ret;
 
-	ring = iio_sw_rb_allocate(indio_dev);
-	if (!ring) {
-		ret = -ENOMEM;
+	ret = iio_sw_rb_simple_setup(indio_dev, &iio_pollfunc_store_time,
+		&adis16201_trigger_handler);
+	if (ret)
 		return ret;
-	}
-	indio_dev->buffer = ring;
-	ring->scan_timestamp = true;
-	indio_dev->setup_ops = &adis16201_ring_setup_ops;
-
-	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
-						 &adis16201_trigger_handler,
-						 IRQF_ONESHOT,
-						 indio_dev,
-						 "adis16201_consumer%d",
-						 indio_dev->id);
-	if (indio_dev->pollfunc == NULL) {
-		ret = -ENOMEM;
-		goto error_iio_sw_rb_free;
-	}
 
-	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
+	indio_dev->buffer->scan_timestamp = true;
 	return 0;
-error_iio_sw_rb_free:
-	iio_sw_rb_free(indio_dev->buffer);
-	return ret;
 }
-- 
1.7.7.3

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

* [PATCH 07/10] staging:iio:adc:max1363: Use new ringbuffer setup helper function
  2011-12-01 14:19 [PATCH 01/10] staging:iio: Add wrapper functions around buffer access ops Lars-Peter Clausen
                   ` (4 preceding siblings ...)
  2011-12-01 14:19 ` [PATCH 06/10] staging:iio:accel:adis16201: " Lars-Peter Clausen
@ 2011-12-01 14:19 ` Lars-Peter Clausen
  2011-12-01 20:58   ` Jonathan Cameron
  2011-12-01 14:19 ` [PATCH 08/10] staging:iio:adc:ad7476: " Lars-Peter Clausen
                   ` (3 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Lars-Peter Clausen @ 2011-12-01 14:19 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, linux-iio, device-drivers-devel, drivers,
	Lars-Peter Clausen

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

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/adc/max1363_core.c |    9 ------
 drivers/staging/iio/adc/max1363_ring.c |   43 ++-----------------------------
 2 files changed, 3 insertions(+), 49 deletions(-)

diff --git a/drivers/staging/iio/adc/max1363_core.c b/drivers/staging/iio/adc/max1363_core.c
index 1ce89ef..a14329e 100644
--- a/drivers/staging/iio/adc/max1363_core.c
+++ b/drivers/staging/iio/adc/max1363_core.c
@@ -1306,12 +1306,6 @@ static int __devinit max1363_probe(struct i2c_client *client,
 	if (ret)
 		goto error_free_available_scan_masks;
 
-	ret = iio_buffer_register(indio_dev,
-				  st->chip_info->channels,
-				  st->chip_info->num_channels);
-	if (ret)
-		goto error_cleanup_ring;
-
 	if (client->irq) {
 		ret = request_threaded_irq(st->client->irq,
 					   NULL,
@@ -1332,8 +1326,6 @@ static int __devinit max1363_probe(struct i2c_client *client,
 error_free_irq:
 	free_irq(st->client->irq, indio_dev);
 error_uninit_ring:
-	iio_buffer_unregister(indio_dev);
-error_cleanup_ring:
 	max1363_ring_cleanup(indio_dev);
 error_free_available_scan_masks:
 	kfree(indio_dev->available_scan_masks);
@@ -1356,7 +1348,6 @@ static int max1363_remove(struct i2c_client *client)
 	iio_device_unregister(indio_dev);
 	if (client->irq)
 		free_irq(st->client->irq, indio_dev);
-	iio_buffer_unregister(indio_dev);
 	max1363_ring_cleanup(indio_dev);
 	kfree(indio_dev->available_scan_masks);
 	if (!IS_ERR(reg)) {
diff --git a/drivers/staging/iio/adc/max1363_ring.c b/drivers/staging/iio/adc/max1363_ring.c
index d0a60a3..7a81070 100644
--- a/drivers/staging/iio/adc/max1363_ring.c
+++ b/drivers/staging/iio/adc/max1363_ring.c
@@ -89,50 +89,13 @@ done:
 	return IRQ_HANDLED;
 }
 
-static const struct iio_buffer_setup_ops max1363_ring_setup_ops = {
-	.postenable = &iio_triggered_buffer_postenable,
-	.preenable = &iio_sw_buffer_preenable,
-	.predisable = &iio_triggered_buffer_predisable,
-};
-
 int max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 {
-	struct max1363_state *st = iio_priv(indio_dev);
-	int ret = 0;
-
-	indio_dev->buffer = iio_sw_rb_allocate(indio_dev);
-	if (!indio_dev->buffer) {
-		ret = -ENOMEM;
-		goto error_ret;
-	}
-	indio_dev->pollfunc = iio_alloc_pollfunc(NULL,
-						 &max1363_trigger_handler,
-						 IRQF_ONESHOT,
-						 indio_dev,
-						 "%s_consumer%d",
-						 st->client->name,
-						 indio_dev->id);
-	if (indio_dev->pollfunc == NULL) {
-		ret = -ENOMEM;
-		goto error_deallocate_sw_rb;
-	}
-	/* Ring buffer functions - here trigger setup related */
-	indio_dev->setup_ops = &max1363_ring_setup_ops;
-
-	/* Flag that polled ring buffering is possible */
-	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
-
-	return 0;
-
-error_deallocate_sw_rb:
-	iio_sw_rb_free(indio_dev->buffer);
-error_ret:
-	return ret;
+	return iio_sw_rb_simple_setup(indio_dev, NULL,
+	    &max1363_trigger_handler);
 }
 
 void max1363_ring_cleanup(struct iio_dev *indio_dev)
 {
-	/* ensure that the trigger has been detached */
-	iio_dealloc_pollfunc(indio_dev->pollfunc);
-	iio_sw_rb_free(indio_dev->buffer);
+	iio_sw_rb_simple_cleanup(indio_dev);
 }
-- 
1.7.7.3

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

* [PATCH 08/10] staging:iio:adc:ad7476: Use new ringbuffer setup helper function
  2011-12-01 14:19 [PATCH 01/10] staging:iio: Add wrapper functions around buffer access ops Lars-Peter Clausen
                   ` (5 preceding siblings ...)
  2011-12-01 14:19 ` [PATCH 07/10] staging:iio:adc:max1363: " Lars-Peter Clausen
@ 2011-12-01 14:19 ` Lars-Peter Clausen
  2011-12-01 20:59   ` Jonathan Cameron
  2011-12-01 14:19 ` [PATCH 09/10] staging:iio:adc:ad799x: " Lars-Peter Clausen
                   ` (2 subsequent siblings)
  9 siblings, 1 reply; 22+ messages in thread
From: Lars-Peter Clausen @ 2011-12-01 14:19 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, linux-iio, device-drivers-devel, drivers,
	Lars-Peter Clausen

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

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/adc/ad7476.h      |    1 -
 drivers/staging/iio/adc/ad7476_core.c |    9 ----
 drivers/staging/iio/adc/ad7476_ring.c |   77 +++-----------------------------
 3 files changed, 8 insertions(+), 79 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7476.h b/drivers/staging/iio/adc/ad7476.h
index 27f696c..b1dd931 100644
--- a/drivers/staging/iio/adc/ad7476.h
+++ b/drivers/staging/iio/adc/ad7476.h
@@ -27,7 +27,6 @@ struct ad7476_state {
 	struct spi_device		*spi;
 	const struct ad7476_chip_info	*chip_info;
 	struct regulator		*reg;
-	size_t				d_size;
 	u16				int_vref_mv;
 	struct spi_transfer		xfer;
 	struct spi_message		msg;
diff --git a/drivers/staging/iio/adc/ad7476_core.c b/drivers/staging/iio/adc/ad7476_core.c
index 447fdbe..b27785b 100644
--- a/drivers/staging/iio/adc/ad7476_core.c
+++ b/drivers/staging/iio/adc/ad7476_core.c
@@ -179,20 +179,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))
@@ -212,7 +204,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 35a8576..bd3e3ba 100644
--- a/drivers/staging/iio/adc/ad7476_ring.c
+++ b/drivers/staging/iio/adc/ad7476_ring.c
@@ -20,46 +20,17 @@
 
 #include "ad7476.h"
 
-/**
- * ad7476_ring_preenable() setup the parameters of the ring before enabling
- *
- * The complex nature of the setting of the nuber of bytes per datum is due
- * to this driver currently ensuring that the timestamp is stored at an 8
- * byte boundary.
- **/
-static int ad7476_ring_preenable(struct iio_dev *indio_dev)
-{
-	struct ad7476_state *st = iio_priv(indio_dev);
-	struct iio_buffer *ring = indio_dev->buffer;
-
-	st->d_size = bitmap_weight(indio_dev->active_scan_mask,
-				   indio_dev->masklength) *
-		st->chip_info->channel[0].scan_type.storagebits / 8;
-
-	if (ring->scan_timestamp) {
-		st->d_size += sizeof(s64);
-
-		if (st->d_size % sizeof(s64))
-			st->d_size += sizeof(s64) - (st->d_size % sizeof(s64));
-	}
-
-	if (indio_dev->buffer->access->set_bytes_per_datum)
-		indio_dev->buffer->access->
-			set_bytes_per_datum(indio_dev->buffer, st->d_size);
-
-	return 0;
-}
-
 static irqreturn_t ad7476_trigger_handler(int irq, void  *p)
 {
 	struct iio_poll_func *pf = p;
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct ad7476_state *st = iio_priv(indio_dev);
+	unsigned int bpd = buffer_get_bytes_per_datum(indio_dev->buffer);
 	s64 time_ns;
 	__u8 *rxbuf;
 	int b_sent;
 
-	rxbuf = kzalloc(st->d_size, GFP_KERNEL);
+	rxbuf = kzalloc(bpd, GFP_KERNEL);
 	if (rxbuf == NULL)
 		return -ENOMEM;
 
@@ -71,7 +42,7 @@ static irqreturn_t ad7476_trigger_handler(int irq, void  *p)
 	time_ns = iio_get_time_ns();
 
 	if (indio_dev->buffer->scan_timestamp)
-		memcpy(rxbuf + st->d_size - sizeof(s64),
+		memcpy(rxbuf + bpd - sizeof(s64),
 			&time_ns, sizeof(time_ns));
 
 	indio_dev->buffer->access->store_to(indio_dev->buffer, rxbuf, time_ns);
@@ -82,51 +53,19 @@ done:
 	return IRQ_HANDLED;
 }
 
-static const struct iio_buffer_setup_ops ad7476_ring_setup_ops = {
-	.preenable = &ad7476_ring_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;
+	int ret;
 
-	indio_dev->buffer = iio_sw_rb_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_sw_rb;
-	}
+	ret = iio_sw_rb_simple_setup(indio_dev, NULL, &ad7476_trigger_handler);
+	if (ret)
+		return ret;
 
-	/* 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_sw_rb:
-	iio_sw_rb_free(indio_dev->buffer);
-error_ret:
-	return ret;
 }
 
 void ad7476_ring_cleanup(struct iio_dev *indio_dev)
 {
-	iio_dealloc_pollfunc(indio_dev->pollfunc);
-	iio_sw_rb_free(indio_dev->buffer);
+	iio_sw_rb_simple_cleanup(indio_dev);
 }
-- 
1.7.7.3

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

* [PATCH 09/10] staging:iio:adc:ad799x: Use new ringbuffer setup helper function
  2011-12-01 14:19 [PATCH 01/10] staging:iio: Add wrapper functions around buffer access ops Lars-Peter Clausen
                   ` (6 preceding siblings ...)
  2011-12-01 14:19 ` [PATCH 08/10] staging:iio:adc:ad7476: " Lars-Peter Clausen
@ 2011-12-01 14:19 ` Lars-Peter Clausen
  2011-12-01 21:00   ` Jonathan Cameron
  2011-12-01 14:19 ` [PATCH 10/10] staging:iio:adc:ad7298: " Lars-Peter Clausen
  2011-12-01 20:40 ` [PATCH 01/10] staging:iio: Add wrapper functions around buffer access ops Jonathan Cameron
  9 siblings, 1 reply; 22+ messages in thread
From: Lars-Peter Clausen @ 2011-12-01 14:19 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, linux-iio, device-drivers-devel, drivers,
	Lars-Peter Clausen

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

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

diff --git a/drivers/staging/iio/adc/ad799x.h b/drivers/staging/iio/adc/ad799x.h
index 356f690..883ad43 100644
--- a/drivers/staging/iio/adc/ad799x.h
+++ b/drivers/staging/iio/adc/ad799x.h
@@ -104,7 +104,6 @@ struct ad799x_chip_info {
 struct ad799x_state {
 	struct i2c_client		*client;
 	const struct ad799x_chip_info	*chip_info;
-	size_t				d_size;
 	struct iio_trigger		*trig;
 	struct regulator		*reg;
 	u16				int_vref_mv;
@@ -121,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);
@@ -137,5 +134,6 @@ ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev)
 static inline void ad799x_ring_cleanup(struct iio_dev *indio_dev)
 {
 }
+
 #endif /* CONFIG_AD799X_RING_BUFFER */
 #endif /* _AD799X_H_ */
diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
index 815e6b9..11313d8 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) | \
@@ -849,12 +861,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,
@@ -896,7 +902,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 28e9a41..42b6618 100644
--- a/drivers/staging/iio/adc/ad799x_ring.c
+++ b/drivers/staging/iio/adc/ad799x_ring.c
@@ -24,43 +24,6 @@
 #include "ad799x.h"
 
 /**
- * ad799x_ring_preenable() setup the parameters of the ring before enabling
- *
- * The complex nature of the setting of the nuber 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 iio_buffer *ring = indio_dev->buffer;
-	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);
-
-	st->d_size = bitmap_weight(indio_dev->active_scan_mask,
-				   indio_dev->masklength) * 2;
-
-	if (ring->scan_timestamp) {
-		st->d_size += sizeof(s64);
-
-		if (st->d_size % sizeof(s64))
-			st->d_size += sizeof(s64) - (st->d_size % sizeof(s64));
-	}
-
-	if (indio_dev->buffer->access->set_bytes_per_datum)
-		indio_dev->buffer->access->
-			set_bytes_per_datum(indio_dev->buffer, st->d_size);
-
-	return 0;
-}
-
-/**
  * ad799x_trigger_handler() bh of trigger launched polling to ring buffer
  *
  * Currently there is no option in this driver to disable the saving of
@@ -73,12 +36,13 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct ad799x_state *st = iio_priv(indio_dev);
 	struct iio_buffer *ring = indio_dev->buffer;
+	unsigned int bpd = buffer_get_bytes_per_datum(ring);
 	s64 time_ns;
 	__u8 *rxbuf;
 	int b_sent;
 	u8 cmd;
 
-	rxbuf = kmalloc(st->d_size, GFP_KERNEL);
+	rxbuf = kmalloc(bpd, GFP_KERNEL);
 	if (rxbuf == NULL)
 		goto out;
 
@@ -112,7 +76,7 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
 	time_ns = iio_get_time_ns();
 
 	if (ring->scan_timestamp)
-		memcpy(rxbuf + st->d_size - sizeof(s64),
+		memcpy(rxbuf + bpd - sizeof(s64),
 			&time_ns, sizeof(time_ns));
 
 	ring->access->store_to(indio_dev->buffer, rxbuf, time_ns);
@@ -126,49 +90,19 @@ 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;
+	int ret;
 
-	indio_dev->buffer = iio_sw_rb_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_sw_rb;
-	}
+	ret = iio_sw_rb_simple_setup(indio_dev, NULL, &ad799x_trigger_handler);
+	if (ret)
+		return ret;
 
-	/* 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_sw_rb:
-	iio_sw_rb_free(indio_dev->buffer);
-error_ret:
-	return ret;
 }
 
 void ad799x_ring_cleanup(struct iio_dev *indio_dev)
 {
-	iio_dealloc_pollfunc(indio_dev->pollfunc);
-	iio_sw_rb_free(indio_dev->buffer);
+	iio_sw_rb_simple_cleanup(indio_dev);
 }
-- 
1.7.7.3

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

* [PATCH 10/10] staging:iio:adc:ad7298: Use new ringbuffer setup helper function
  2011-12-01 14:19 [PATCH 01/10] staging:iio: Add wrapper functions around buffer access ops Lars-Peter Clausen
                   ` (7 preceding siblings ...)
  2011-12-01 14:19 ` [PATCH 09/10] staging:iio:adc:ad799x: " Lars-Peter Clausen
@ 2011-12-01 14:19 ` Lars-Peter Clausen
  2011-12-01 21:02   ` Jonathan Cameron
  2011-12-01 20:40 ` [PATCH 01/10] staging:iio: Add wrapper functions around buffer access ops Jonathan Cameron
  9 siblings, 1 reply; 22+ messages in thread
From: Lars-Peter Clausen @ 2011-12-01 14:19 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Michael Hennerich, linux-iio, device-drivers-devel, drivers,
	Lars-Peter Clausen

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

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/staging/iio/adc/ad7298.h      |    6 ++-
 drivers/staging/iio/adc/ad7298_core.c |   11 +----
 drivers/staging/iio/adc/ad7298_ring.c |   69 +++++---------------------------
 3 files changed, 18 insertions(+), 68 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7298.h b/drivers/staging/iio/adc/ad7298.h
index a0e5dea..18f2787 100644
--- a/drivers/staging/iio/adc/ad7298.h
+++ b/drivers/staging/iio/adc/ad7298.h
@@ -38,7 +38,6 @@ struct ad7298_platform_data {
 struct ad7298_state {
 	struct spi_device		*spi;
 	struct regulator		*reg;
-	size_t				d_size;
 	u16				int_vref_mv;
 	unsigned			ext_ref;
 	struct spi_transfer		ring_xfer[10];
@@ -56,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
@@ -67,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 6e184ea..b9cb85d 100644
--- a/drivers/staging/iio/adc/ad7298_core.c
+++ b/drivers/staging/iio/adc/ad7298_core.c
@@ -160,6 +160,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,
 };
 
@@ -220,19 +221,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:
@@ -252,7 +246,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 feeb0ee..baa8b39 100644
--- a/drivers/staging/iio/adc/ad7298_ring.c
+++ b/drivers/staging/iio/adc/ad7298_ring.c
@@ -19,39 +19,21 @@
 #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);
-	struct iio_buffer *ring = indio_dev->buffer;
-	size_t d_size;
 	int i, m;
 	unsigned short command;
-	int scan_count = bitmap_weight(indio_dev->active_scan_mask,
+	int scan_count = bitmap_weight(active_scan_mask,
 				       indio_dev->masklength);
-	d_size = scan_count * (AD7298_STORAGE_BITS / 8);
-
-	if (ring->scan_timestamp) {
-		d_size += sizeof(s64);
-
-		if (d_size % sizeof(s64))
-			d_size += sizeof(s64) - (d_size % sizeof(s64));
-	}
-
-	if (ring->access->set_bytes_per_datum)
-		ring->access->set_bytes_per_datum(ring, d_size);
-
-	st->d_size = d_size;
 
 	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);
@@ -92,6 +74,7 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct ad7298_state *st = iio_priv(indio_dev);
 	struct iio_buffer *ring = indio_dev->buffer;
+	unsigned int bpd = buffer_get_bytes_per_datum(ring);
 	s64 time_ns;
 	__u16 buf[16];
 	int b_sent, i;
@@ -102,7 +85,7 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
 
 	if (ring->scan_timestamp) {
 		time_ns = iio_get_time_ns();
-		memcpy((u8 *)buf + st->d_size - sizeof(s64),
+		memcpy((u8 *)buf + bpd - sizeof(s64),
 			&time_ns, sizeof(time_ns));
 	}
 
@@ -116,49 +99,19 @@ 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_sw_rb_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_sw_rb;
-	}
+	ret = iio_sw_rb_simple_setup(indio_dev, NULL, &ad7298_trigger_handler);
+	if (ret)
+		return ret;
 
-	/* 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_sw_rb:
-	iio_sw_rb_free(indio_dev->buffer);
-error_ret:
-	return ret;
 }
 
 void ad7298_ring_cleanup(struct iio_dev *indio_dev)
 {
-	iio_dealloc_pollfunc(indio_dev->pollfunc);
-	iio_sw_rb_free(indio_dev->buffer);
+	iio_sw_rb_simple_cleanup(indio_dev);
 }
-- 
1.7.7.3

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

* Re: [PATCH 01/10] staging:iio: Add wrapper functions around buffer access ops
  2011-12-01 14:19 [PATCH 01/10] staging:iio: Add wrapper functions around buffer access ops Lars-Peter Clausen
                   ` (8 preceding siblings ...)
  2011-12-01 14:19 ` [PATCH 10/10] staging:iio:adc:ad7298: " Lars-Peter Clausen
@ 2011-12-01 20:40 ` Jonathan Cameron
  9 siblings, 0 replies; 22+ messages in thread
From: Jonathan Cameron @ 2011-12-01 20:40 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Michael Hennerich, linux-iio,
	device-drivers-devel, drivers

On 12/01/2011 02:19 PM, Lars-Peter Clausen wrote:
> Add some convenience wrapper functions around the buffer access operations. This
> makes the resulting code both a bit easier to read and to write.
>
Reasonable clean up.

> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
> ---
> The patches in this series depend on Jonathans buffer cleanup patches.
> ---
>  drivers/staging/iio/buffer.h              |   68 +++++++++++++++++++++++++++++
>  drivers/staging/iio/industrialio-buffer.c |   63 +++++++++++---------------
>  2 files changed, 95 insertions(+), 36 deletions(-)
> 
> diff --git a/drivers/staging/iio/buffer.h b/drivers/staging/iio/buffer.h
> index c697099..9383d2d 100644
> --- a/drivers/staging/iio/buffer.h
> +++ b/drivers/staging/iio/buffer.h
> @@ -194,6 +194,74 @@ ssize_t iio_buffer_show_enable(struct device *dev,
>  
>  int iio_sw_buffer_preenable(struct iio_dev *indio_dev);
>  
> +static inline void buffer_mark_in_use(struct iio_buffer *buffer)
> +{
> +	if (buffer->access->mark_in_use)
> +		buffer->access->mark_in_use(buffer);
> +}
> +
> +static inline void buffer_unmark_in_use(struct iio_buffer *buffer)
> +{
> +	if (buffer->access->unmark_in_use)
> +		buffer->access->unmark_in_use(buffer);
> +}
> +
> +static inline int buffer_store_to(struct iio_buffer *buffer, u8 *data,
> +	s64 timestamp)
> +{
> +	return buffer->access->store_to(buffer, data, timestamp);
> +}
> +
> +static inline int buffer_read_first_n(struct iio_buffer *buffer, size_t n,
> +	char __user *buf)
> +{
> +	return buffer->access->read_first_n(buffer, n, buf);
> +}
> +
> +static inline int buffer_mark_param_change(struct iio_buffer *buffer)
> +{
> +	if (buffer->access->mark_param_change)
> +		return buffer->access->mark_param_change(buffer);
> +
> +	return 0;
> +}
> +
> +static inline int buffer_request_update(struct iio_buffer *buffer)
> +{
> +	if (buffer->access->request_update)
> +		return buffer->access->request_update(buffer);
> +
> +	return 0;
> +}
> +
> +static inline int buffer_get_bytes_per_datum(struct iio_buffer *buffer)
> +{
> +	return buffer->access->get_bytes_per_datum(buffer);
> +}
> +
> +static inline int buffer_set_bytes_per_datum(struct iio_buffer *buffer,
> +	size_t bpd)
> +{
> +	return buffer->access->set_bytes_per_datum(buffer, bpd);
> +}
> +
> +static inline int buffer_get_length(struct iio_buffer *buffer)
> +{
> +	if (buffer->access->get_length)
> +		return buffer->access->get_length(buffer);
> +
> +	return -ENOSYS;
> +}
> +
> +static inline int buffer_set_length(struct iio_buffer *buffer,
> +	int length)
> +{
> +	if (buffer->access->set_length)
> +		return buffer->access->set_length(buffer, length);
> +
> +	return -ENOSYS;
> +}
> +
>  #else /* CONFIG_IIO_BUFFER */
>  
>  static inline int iio_buffer_register(struct iio_dev *indio_dev,
> diff --git a/drivers/staging/iio/industrialio-buffer.c b/drivers/staging/iio/industrialio-buffer.c
> index f131088..165c88e 100644
> --- a/drivers/staging/iio/industrialio-buffer.c
> +++ b/drivers/staging/iio/industrialio-buffer.c
> @@ -43,9 +43,9 @@ ssize_t iio_buffer_read_first_n_outer(struct file *filp, char __user *buf,
>  	struct iio_dev *indio_dev = filp->private_data;
>  	struct iio_buffer *rb = indio_dev->buffer;
>  
> -	if (!rb || !rb->access->read_first_n)
> +	if (!rb)
>  		return -EINVAL;
> -	return rb->access->read_first_n(rb, n, buf);
> +	return buffer_read_first_n(rb, n, buf);
>  }
>  
>  /**
> @@ -69,8 +69,7 @@ int iio_chrdev_buffer_open(struct iio_dev *indio_dev)
>  	struct iio_buffer *rb = indio_dev->buffer;
>  	if (!rb)
>  		return 0;
> -	if (rb->access->mark_in_use)
> -		rb->access->mark_in_use(rb);
> +	buffer_mark_in_use(rb);
>  	return 0;
>  }
>  
> @@ -81,8 +80,7 @@ void iio_chrdev_buffer_release(struct iio_dev *indio_dev)
>  	if (!rb)
>  		return;
>  	clear_bit(IIO_BUSY_BIT_POS, &rb->flags);
> -	if (rb->access->unmark_in_use)
> -		rb->access->unmark_in_use(rb);
> +	buffer_unmark_in_use(rb);
>  }
>  
>  void iio_buffer_init(struct iio_buffer *buffer)
> @@ -371,12 +369,13 @@ ssize_t iio_buffer_read_length(struct device *dev,
>  {
>  	struct iio_dev *indio_dev = dev_get_drvdata(dev);
>  	struct iio_buffer *buffer = indio_dev->buffer;
> +	int len;
>  
> -	if (buffer->access->get_length)
> -		return sprintf(buf, "%d\n",
> -			       buffer->access->get_length(buffer));
> +	len = buffer_get_length(buffer);
> +	if (len < 0)
> +		return 0;
>  
> -	return 0;
> +	return sprintf(buf, "%d\n", len);
>  }
>  EXPORT_SYMBOL(iio_buffer_read_length);
>  
> @@ -394,15 +393,13 @@ ssize_t iio_buffer_write_length(struct device *dev,
>  	if (ret)
>  		return ret;
>  
> -	if (buffer->access->get_length)
> -		if (val == buffer->access->get_length(buffer))
> -			return len;
> +	ret = buffer_get_length(buffer);
> +	if (ret >= 0 && ret == val)
> +		return len;
>  
> -	if (buffer->access->set_length) {
> -		buffer->access->set_length(buffer, val);
> -		if (buffer->access->mark_param_change)
> -			buffer->access->mark_param_change(buffer);
> -	}
> +	ret = buffer_set_length(buffer, val);
> +	if (ret)
> +		buffer_mark_param_change(buffer);
>  
>  	return len;
>  }
> @@ -437,25 +434,21 @@ ssize_t iio_buffer_store_enable(struct device *dev,
>  				goto error_ret;
>  			}
>  		}
> -		if (buffer->access->request_update) {
> -			ret = buffer->access->request_update(buffer);
> -			if (ret) {
> -				printk(KERN_INFO
> -				       "Buffer not started:"
> -				       "buffer parameter update failed\n");
> -				goto error_ret;
> -			}
> +		ret = buffer_request_update(buffer);
> +		if (ret) {
> +			printk(KERN_INFO
> +				   "Buffer not started:"
> +				   "buffer parameter update failed\n");
> +			goto error_ret;
>  		}
> -		if (buffer->access->mark_in_use)
> -			buffer->access->mark_in_use(buffer);
> +		buffer_mark_in_use(buffer);
>  		/* Definitely possible for devices to support both of these.*/
>  		if (indio_dev->modes & INDIO_BUFFER_TRIGGERED) {
>  			if (!indio_dev->trig) {
>  				printk(KERN_INFO
>  				       "Buffer not started: no trigger\n");
>  				ret = -EINVAL;
> -				if (buffer->access->unmark_in_use)
> -					buffer->access->unmark_in_use(buffer);
> +				buffer_unmark_in_use(buffer);
>  				goto error_ret;
>  			}
>  			indio_dev->currentmode = INDIO_BUFFER_TRIGGERED;
> @@ -472,8 +465,7 @@ ssize_t iio_buffer_store_enable(struct device *dev,
>  				printk(KERN_INFO
>  				       "Buffer not started:"
>  				       "postenable failed\n");
> -				if (buffer->access->unmark_in_use)
> -					buffer->access->unmark_in_use(buffer);
> +				buffer_unmark_in_use(buffer);
>  				indio_dev->currentmode = previous_mode;
>  				if (indio_dev->setup_ops->postdisable)
>  					indio_dev->setup_ops->
> @@ -487,8 +479,7 @@ ssize_t iio_buffer_store_enable(struct device *dev,
>  			if (ret)
>  				goto error_ret;
>  		}
> -		if (buffer->access->unmark_in_use)
> -			buffer->access->unmark_in_use(buffer);
> +		buffer_unmark_in_use(buffer);
>  		indio_dev->currentmode = INDIO_DIRECT_MODE;
>  		if (indio_dev->setup_ops->postdisable) {
>  			ret = indio_dev->setup_ops->postdisable(indio_dev);
> @@ -556,7 +547,7 @@ int iio_sw_buffer_preenable(struct iio_dev *indio_dev)
>  			bytes += length - bytes % length;
>  		bytes += length;
>  	}
> -	buffer->access->set_bytes_per_datum(buffer, bytes);
> +	buffer_set_bytes_per_datum(buffer, bytes);
>  
>  	/* What scan mask do we actually have ?*/
>  	if (indio_dev->available_scan_masks)
> @@ -674,7 +665,7 @@ int iio_push_to_buffer(struct iio_buffer *buffer, unsigned char *data,
>  {
>  	unsigned char *dataout = iio_demux(buffer, data);
>  
> -	return buffer->access->store_to(buffer, dataout, timestamp);
> +	return buffer_store_to(buffer, dataout, timestamp);
>  }
>  EXPORT_SYMBOL_GPL(iio_push_to_buffer);
>  

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

* Re: [PATCH 02/10] staging:iio: Setup buffer access functions when allocating the buffer
  2011-12-01 14:19 ` [PATCH 02/10] staging:iio: Setup buffer access functions when allocating the buffer Lars-Peter Clausen
@ 2011-12-01 20:48   ` Jonathan Cameron
  0 siblings, 0 replies; 22+ messages in thread
From: Jonathan Cameron @ 2011-12-01 20:48 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Michael Hennerich, linux-iio,
	device-drivers-devel, drivers

On 12/01/2011 02:19 PM, Lars-Peter Clausen wrote:
> Setup the buffer access functions in the buffer allocate function. There is no
> need to let each driver handle this on its own.
Good idea, thanks.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
> ---
>  drivers/staging/iio/accel/adis16201_ring.c      |    2 --
>  drivers/staging/iio/accel/adis16203_ring.c      |    2 --
>  drivers/staging/iio/accel/adis16204_ring.c      |    2 --
>  drivers/staging/iio/accel/adis16209_ring.c      |    2 --
>  drivers/staging/iio/accel/adis16240_ring.c      |    2 --
>  drivers/staging/iio/accel/lis3l02dq.h           |    2 --
>  drivers/staging/iio/accel/lis3l02dq_ring.c      |    2 --
>  drivers/staging/iio/adc/ad7192.c                |    2 --
>  drivers/staging/iio/adc/ad7298_ring.c           |    3 ---
>  drivers/staging/iio/adc/ad7476_ring.c           |    2 --
>  drivers/staging/iio/adc/ad7606_ring.c           |    2 --
>  drivers/staging/iio/adc/ad7793.c                |    2 --
>  drivers/staging/iio/adc/ad7887_ring.c           |    2 --
>  drivers/staging/iio/adc/ad799x_ring.c           |    2 --
>  drivers/staging/iio/adc/max1363_ring.c          |    2 --
>  drivers/staging/iio/gyro/adis16260_ring.c       |    2 --
>  drivers/staging/iio/iio_simple_dummy_buffer.c   |    2 --
>  drivers/staging/iio/impedance-analyzer/ad5933.c |    3 ---
>  drivers/staging/iio/imu/adis16400_ring.c        |    2 --
>  drivers/staging/iio/kfifo_buf.c                 |    1 +
>  drivers/staging/iio/meter/ade7758_ring.c        |    2 --
>  drivers/staging/iio/ring_sw.c                   |    1 +
>  22 files changed, 2 insertions(+), 42 deletions(-)
> 
> diff --git a/drivers/staging/iio/accel/adis16201_ring.c b/drivers/staging/iio/accel/adis16201_ring.c
> index 26c610f..97f9e6b 100644
> --- a/drivers/staging/iio/accel/adis16201_ring.c
> +++ b/drivers/staging/iio/accel/adis16201_ring.c
> @@ -115,9 +115,7 @@ int adis16201_configure_ring(struct iio_dev *indio_dev)
>  		return ret;
>  	}
>  	indio_dev->buffer = ring;
> -	/* Effectively select the ring buffer implementation */
>  	ring->scan_timestamp = true;
> -	ring->access = &ring_sw_access_funcs;
>  	indio_dev->setup_ops = &adis16201_ring_setup_ops;
>  
>  	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
> diff --git a/drivers/staging/iio/accel/adis16203_ring.c b/drivers/staging/iio/accel/adis16203_ring.c
> index 064640d..6a8963d 100644
> --- a/drivers/staging/iio/accel/adis16203_ring.c
> +++ b/drivers/staging/iio/accel/adis16203_ring.c
> @@ -117,9 +117,7 @@ int adis16203_configure_ring(struct iio_dev *indio_dev)
>  		return ret;
>  	}
>  	indio_dev->buffer = ring;
> -	/* Effectively select the ring buffer implementation */
>  	ring->scan_timestamp = true;
> -	ring->access = &ring_sw_access_funcs;
>  	indio_dev->setup_ops = &adis16203_ring_setup_ops;
>  
>  	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
> diff --git a/drivers/staging/iio/accel/adis16204_ring.c b/drivers/staging/iio/accel/adis16204_ring.c
> index 4081179..5c8ab73 100644
> --- a/drivers/staging/iio/accel/adis16204_ring.c
> +++ b/drivers/staging/iio/accel/adis16204_ring.c
> @@ -112,8 +112,6 @@ int adis16204_configure_ring(struct iio_dev *indio_dev)
>  		return ret;
>  	}
>  	indio_dev->buffer = ring;
> -	/* Effectively select the ring buffer implementation */
> -	ring->access = &ring_sw_access_funcs;
>  	ring->scan_timestamp = true;
>  	indio_dev->setup_ops = &adis16204_ring_setup_ops;
>  
> diff --git a/drivers/staging/iio/accel/adis16209_ring.c b/drivers/staging/iio/accel/adis16209_ring.c
> index 2a6fd334..57254b6 100644
> --- a/drivers/staging/iio/accel/adis16209_ring.c
> +++ b/drivers/staging/iio/accel/adis16209_ring.c
> @@ -113,8 +113,6 @@ int adis16209_configure_ring(struct iio_dev *indio_dev)
>  		return ret;
>  	}
>  	indio_dev->buffer = ring;
> -	/* Effectively select the ring buffer implementation */
> -	ring->access = &ring_sw_access_funcs;
>  	ring->scan_timestamp = true;
>  	indio_dev->setup_ops = &adis16209_ring_setup_ops;
>  
> diff --git a/drivers/staging/iio/accel/adis16240_ring.c b/drivers/staging/iio/accel/adis16240_ring.c
> index e23622d..43ba84e 100644
> --- a/drivers/staging/iio/accel/adis16240_ring.c
> +++ b/drivers/staging/iio/accel/adis16240_ring.c
> @@ -110,8 +110,6 @@ int adis16240_configure_ring(struct iio_dev *indio_dev)
>  		return ret;
>  	}
>  	indio_dev->buffer = ring;
> -	/* Effectively select the ring buffer implementation */
> -	ring->access = &ring_sw_access_funcs;
>  	ring->scan_timestamp = true;
>  	indio_dev->setup_ops = &adis16240_ring_setup_ops;
>  
> diff --git a/drivers/staging/iio/accel/lis3l02dq.h b/drivers/staging/iio/accel/lis3l02dq.h
> index 2db383f..ae5f225 100644
> --- a/drivers/staging/iio/accel/lis3l02dq.h
> +++ b/drivers/staging/iio/accel/lis3l02dq.h
> @@ -187,12 +187,10 @@ void lis3l02dq_unconfigure_buffer(struct iio_dev *indio_dev);
>  #ifdef CONFIG_LIS3L02DQ_BUF_RING_SW
>  #define lis3l02dq_free_buf iio_sw_rb_free
>  #define lis3l02dq_alloc_buf iio_sw_rb_allocate
> -#define lis3l02dq_access_funcs ring_sw_access_funcs
>  #endif
>  #ifdef CONFIG_LIS3L02DQ_BUF_KFIFO
>  #define lis3l02dq_free_buf iio_kfifo_free
>  #define lis3l02dq_alloc_buf iio_kfifo_allocate
> -#define lis3l02dq_access_funcs kfifo_access_funcs
>  #endif
>  irqreturn_t lis3l02dq_data_rdy_trig_poll(int irq, void *private);
>  #define lis3l02dq_th lis3l02dq_data_rdy_trig_poll
> diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c
> index c81d0e2..1cf53d7 100644
> --- a/drivers/staging/iio/accel/lis3l02dq_ring.c
> +++ b/drivers/staging/iio/accel/lis3l02dq_ring.c
> @@ -406,8 +406,6 @@ int lis3l02dq_configure_buffer(struct iio_dev *indio_dev)
>  		return -ENOMEM;
>  
>  	indio_dev->buffer = buffer;
> -	/* Effectively select the buffer implementation */
> -	indio_dev->buffer->access = &lis3l02dq_access_funcs;
>  
>  	buffer->scan_timestamp = true;
>  	indio_dev->setup_ops = &lis3l02dq_buffer_setup_ops;
> diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
> index 66cc507..ab0cd10 100644
> --- a/drivers/staging/iio/adc/ad7192.c
> +++ b/drivers/staging/iio/adc/ad7192.c
> @@ -561,8 +561,6 @@ static int ad7192_register_ring_funcs_and_init(struct iio_dev *indio_dev)
>  		ret = -ENOMEM;
>  		goto error_ret;
>  	}
> -	/* Effectively select the ring buffer implementation */
> -	indio_dev->buffer->access = &ring_sw_access_funcs;
>  	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
>  						 &ad7192_trigger_handler,
>  						 IRQF_ONESHOT,
> diff --git a/drivers/staging/iio/adc/ad7298_ring.c b/drivers/staging/iio/adc/ad7298_ring.c
> index d1a12dd..feeb0ee 100644
> --- a/drivers/staging/iio/adc/ad7298_ring.c
> +++ b/drivers/staging/iio/adc/ad7298_ring.c
> @@ -131,9 +131,6 @@ int ad7298_register_ring_funcs_and_init(struct iio_dev *indio_dev)
>  		ret = -ENOMEM;
>  		goto error_ret;
>  	}
> -	/* Effectively select the ring buffer implementation */
> -	indio_dev->buffer->access = &ring_sw_access_funcs;
> -
>  	indio_dev->pollfunc = iio_alloc_pollfunc(NULL,
>  						 &ad7298_trigger_handler,
>  						 IRQF_ONESHOT,
> diff --git a/drivers/staging/iio/adc/ad7476_ring.c b/drivers/staging/iio/adc/ad7476_ring.c
> index 4e298b2..35a8576 100644
> --- a/drivers/staging/iio/adc/ad7476_ring.c
> +++ b/drivers/staging/iio/adc/ad7476_ring.c
> @@ -98,8 +98,6 @@ int ad7476_register_ring_funcs_and_init(struct iio_dev *indio_dev)
>  		ret = -ENOMEM;
>  		goto error_ret;
>  	}
> -	/* Effectively select the ring buffer implementation */
> -	indio_dev->buffer->access = &ring_sw_access_funcs;
>  	indio_dev->pollfunc
>  		= iio_alloc_pollfunc(NULL,
>  				     &ad7476_trigger_handler,
> diff --git a/drivers/staging/iio/adc/ad7606_ring.c b/drivers/staging/iio/adc/ad7606_ring.c
> index e8f94a1..1ef9fbc 100644
> --- a/drivers/staging/iio/adc/ad7606_ring.c
> +++ b/drivers/staging/iio/adc/ad7606_ring.c
> @@ -110,8 +110,6 @@ int ad7606_register_ring_funcs_and_init(struct iio_dev *indio_dev)
>  		goto error_ret;
>  	}
>  
> -	/* Effectively select the ring buffer implementation */
> -	indio_dev->buffer->access = &ring_sw_access_funcs;
>  	indio_dev->pollfunc = iio_alloc_pollfunc(&ad7606_trigger_handler_th_bh,
>  						 &ad7606_trigger_handler_th_bh,
>  						 0,
> diff --git a/drivers/staging/iio/adc/ad7793.c b/drivers/staging/iio/adc/ad7793.c
> index f2f1081..deb2c17 100644
> --- a/drivers/staging/iio/adc/ad7793.c
> +++ b/drivers/staging/iio/adc/ad7793.c
> @@ -427,8 +427,6 @@ static int ad7793_register_ring_funcs_and_init(struct iio_dev *indio_dev)
>  		ret = -ENOMEM;
>  		goto error_ret;
>  	}
> -	/* Effectively select the ring buffer implementation */
> -	indio_dev->buffer->access = &ring_sw_access_funcs;
>  	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
>  						 &ad7793_trigger_handler,
>  						 IRQF_ONESHOT,
> diff --git a/drivers/staging/iio/adc/ad7887_ring.c b/drivers/staging/iio/adc/ad7887_ring.c
> index 85076cd..d180907 100644
> --- a/drivers/staging/iio/adc/ad7887_ring.c
> +++ b/drivers/staging/iio/adc/ad7887_ring.c
> @@ -131,8 +131,6 @@ int ad7887_register_ring_funcs_and_init(struct iio_dev *indio_dev)
>  		ret = -ENOMEM;
>  		goto error_ret;
>  	}
> -	/* Effectively select the ring buffer implementation */
> -	indio_dev->buffer->access = &ring_sw_access_funcs;
>  	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
>  						 &ad7887_trigger_handler,
>  						 IRQF_ONESHOT,
> diff --git a/drivers/staging/iio/adc/ad799x_ring.c b/drivers/staging/iio/adc/ad799x_ring.c
> index 5dded9e..28e9a41 100644
> --- a/drivers/staging/iio/adc/ad799x_ring.c
> +++ b/drivers/staging/iio/adc/ad799x_ring.c
> @@ -141,8 +141,6 @@ int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev)
>  		ret = -ENOMEM;
>  		goto error_ret;
>  	}
> -	/* Effectively select the ring buffer implementation */
> -	indio_dev->buffer->access = &ring_sw_access_funcs;
>  	indio_dev->pollfunc = iio_alloc_pollfunc(NULL,
>  						 &ad799x_trigger_handler,
>  						 IRQF_ONESHOT,
> diff --git a/drivers/staging/iio/adc/max1363_ring.c b/drivers/staging/iio/adc/max1363_ring.c
> index f730b3f..d0a60a3 100644
> --- a/drivers/staging/iio/adc/max1363_ring.c
> +++ b/drivers/staging/iio/adc/max1363_ring.c
> @@ -116,8 +116,6 @@ int max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev)
>  		ret = -ENOMEM;
>  		goto error_deallocate_sw_rb;
>  	}
> -	/* Effectively select the ring buffer implementation */
> -	indio_dev->buffer->access = &ring_sw_access_funcs;
>  	/* Ring buffer functions - here trigger setup related */
>  	indio_dev->setup_ops = &max1363_ring_setup_ops;
>  
> diff --git a/drivers/staging/iio/gyro/adis16260_ring.c b/drivers/staging/iio/gyro/adis16260_ring.c
> index 699a615..711f151 100644
> --- a/drivers/staging/iio/gyro/adis16260_ring.c
> +++ b/drivers/staging/iio/gyro/adis16260_ring.c
> @@ -115,8 +115,6 @@ int adis16260_configure_ring(struct iio_dev *indio_dev)
>  		return ret;
>  	}
>  	indio_dev->buffer = ring;
> -	/* Effectively select the ring buffer implementation */
> -	ring->access = &ring_sw_access_funcs;
>  	ring->scan_timestamp = true;
>  	indio_dev->setup_ops = &adis16260_ring_setup_ops;
>  
> diff --git a/drivers/staging/iio/iio_simple_dummy_buffer.c b/drivers/staging/iio/iio_simple_dummy_buffer.c
> index d6a1c0e..bb4daf7 100644
> --- a/drivers/staging/iio/iio_simple_dummy_buffer.c
> +++ b/drivers/staging/iio/iio_simple_dummy_buffer.c
> @@ -142,8 +142,6 @@ int iio_simple_dummy_configure_buffer(struct iio_dev *indio_dev)
>  	}
>  
>  	indio_dev->buffer = buffer;
> -	/* Tell the core how to access the buffer */
> -	buffer->access = &kfifo_access_funcs;
>  
>  	/* Enable timestamps by default */
>  	buffer->scan_timestamp = true;
> diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
> index f02d1c0..4138082 100644
> --- a/drivers/staging/iio/impedance-analyzer/ad5933.c
> +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
> @@ -607,9 +607,6 @@ static int ad5933_register_ring_funcs_and_init(struct iio_dev *indio_dev)
>  	if (!indio_dev->buffer)
>  		return -ENOMEM;
>  
> -	/* Effectively select the ring buffer implementation */
> -	indio_dev->buffer->access = &ring_sw_access_funcs;
> -
>  	/* Ring buffer functions - here trigger setup related */
>  	indio_dev->setup_ops = &ad5933_ring_setup_ops;
>  
> diff --git a/drivers/staging/iio/imu/adis16400_ring.c b/drivers/staging/iio/imu/adis16400_ring.c
> index ac22de5..8daa038 100644
> --- a/drivers/staging/iio/imu/adis16400_ring.c
> +++ b/drivers/staging/iio/imu/adis16400_ring.c
> @@ -187,8 +187,6 @@ int adis16400_configure_ring(struct iio_dev *indio_dev)
>  		return ret;
>  	}
>  	indio_dev->buffer = ring;
> -	/* Effectively select the ring buffer implementation */
> -	ring->access = &ring_sw_access_funcs;
>  	ring->scan_timestamp = true;
>  	indio_dev->setup_ops = &adis16400_ring_setup_ops;
>  
> diff --git a/drivers/staging/iio/kfifo_buf.c b/drivers/staging/iio/kfifo_buf.c
> index d8867ab..a64ebbf 100644
> --- a/drivers/staging/iio/kfifo_buf.c
> +++ b/drivers/staging/iio/kfifo_buf.c
> @@ -98,6 +98,7 @@ struct iio_buffer *iio_kfifo_allocate(struct iio_dev *indio_dev)
>  	kf->update_needed = true;
>  	iio_buffer_init(&kf->buffer);
>  	kf->buffer.attrs = &iio_kfifo_attribute_group;
> +	kf->buffer->access = kfifo_access_funcs;
>  	__iio_init_kfifo(kf);
>  
>  	return &kf->buffer;
> diff --git a/drivers/staging/iio/meter/ade7758_ring.c b/drivers/staging/iio/meter/ade7758_ring.c
> index f29f2b2..c5c522b 100644
> --- a/drivers/staging/iio/meter/ade7758_ring.c
> +++ b/drivers/staging/iio/meter/ade7758_ring.c
> @@ -144,8 +144,6 @@ int ade7758_configure_ring(struct iio_dev *indio_dev)
>  		return ret;
>  	}
>  
> -	/* Effectively select the ring buffer implementation */
> -	indio_dev->buffer->access = &ring_sw_access_funcs;
>  	indio_dev->setup_ops = &ade7758_ring_setup_ops;
>  
>  	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
> diff --git a/drivers/staging/iio/ring_sw.c b/drivers/staging/iio/ring_sw.c
> index a541a73..879c709 100644
> --- a/drivers/staging/iio/ring_sw.c
> +++ b/drivers/staging/iio/ring_sw.c
> @@ -388,6 +388,7 @@ struct iio_buffer *iio_sw_rb_allocate(struct iio_dev *indio_dev)
>  	iio_buffer_init(buf);
>  	__iio_init_sw_ring_buffer(ring);
>  	buf->attrs = &iio_ring_attribute_group;
> +	buf->access = &ring_sw_access_funcs;
>  
>  	return buf;
>  }

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

* Re: [PATCH 03/10] staging:iio:ring_sw: Add helper function for initializing simple setups
  2011-12-01 14:19 ` [PATCH 03/10] staging:iio:ring_sw: Add helper function for initializing simple setups Lars-Peter Clausen
@ 2011-12-01 20:51   ` Jonathan Cameron
  0 siblings, 0 replies; 22+ messages in thread
From: Jonathan Cameron @ 2011-12-01 20:51 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Michael Hennerich, linux-iio,
	device-drivers-devel, drivers

On 12/01/2011 02:19 PM, Lars-Peter Clausen wrote:
> Add a helper function for executing the common tasks which are usually involved
> in setting up a simple software ringbuffer. It will allocate the buffer,
> allocate the pollfunc and register the buffer.
> 
Hmm. this does hide a bit how to typically do it for other buffers, but
I guess it is easy enough for people to look in here.
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>

> ---
>  drivers/staging/iio/ring_sw.c |   83 ++++++++++++++++++++++++++++++++++++++++-
>  drivers/staging/iio/ring_sw.h |    8 ++++
>  2 files changed, 90 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/staging/iio/ring_sw.c b/drivers/staging/iio/ring_sw.c
> index 879c709..c93b069 100644
> --- a/drivers/staging/iio/ring_sw.c
> +++ b/drivers/staging/iio/ring_sw.c
> @@ -15,7 +15,8 @@
>  #include <linux/sched.h>
>  #include <linux/poll.h>
>  #include "ring_sw.h"
> -#include "trigger.h"
> +#include "buffer.h"
> +#include "trigger_consumer.h"
>  
>  /**
>   * struct iio_sw_ring_buffer - software ring buffer
> @@ -414,5 +415,85 @@ const struct iio_buffer_access_funcs ring_sw_access_funcs = {
>  };
>  EXPORT_SYMBOL(ring_sw_access_funcs);
>  
> +static const struct iio_buffer_setup_ops iio_sw_rb_simple_setup_ops = {
> +	.preenable = &iio_sw_buffer_preenable,
> +	.postenable = &iio_triggered_buffer_postenable,
> +	.predisable = &iio_triggered_buffer_predisable,
> +};
> +
> +/*
> + * iio_sw_rb_simple_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
> + *
> + * This function combines some common tasks which will normally be performed
> + * when setting up a simple software ringbuffer. It will allocate the ringbuffer
> + * 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_sw_rb_simple_cleanup
> + * should be called.
> + */
> +int iio_sw_rb_simple_setup(struct iio_dev *indio_dev,
> +	irqreturn_t (*pollfunc_bh)(int irq, void *p),
> +	irqreturn_t (*pollfunc_th)(int irq, void *p))
> +{
> +	int ret;
> +
> +	indio_dev->buffer = iio_sw_rb_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 */
> +	indio_dev->setup_ops = &iio_sw_rb_simple_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_sw_rb_free(indio_dev->buffer);
> +error_ret:
> +	return ret;
> +}
> +EXPORT_SYMBOL(iio_sw_rb_simple_setup);
> +
> +/*
> + * iio_sw_rb_simple_cleanup - Free resources allocated by iio_sw_rb_simple_setup
> + * @indio_dev:		IIO device structure
> + */
> +void iio_sw_rb_simple_cleanup(struct iio_dev *indio_dev)
> +{
> +	iio_buffer_unregister(indio_dev);
> +	iio_dealloc_pollfunc(indio_dev->pollfunc);
> +	iio_sw_rb_free(indio_dev->buffer);
> +}
> +EXPORT_SYMBOL(iio_sw_rb_simple_cleanup);
> +
>  MODULE_DESCRIPTION("Industrialio I/O software ring buffer");
>  MODULE_LICENSE("GPL");
> diff --git a/drivers/staging/iio/ring_sw.h b/drivers/staging/iio/ring_sw.h
> index e6a6e2c..69ed561 100644
> --- a/drivers/staging/iio/ring_sw.h
> +++ b/drivers/staging/iio/ring_sw.h
> @@ -23,6 +23,8 @@
>  
>  #ifndef _IIO_RING_SW_H_
>  #define _IIO_RING_SW_H_
> +
> +#include <linux/interrupt.h>
>  #include "buffer.h"
>  
>  /**
> @@ -32,4 +34,10 @@ extern const struct iio_buffer_access_funcs ring_sw_access_funcs;
>  
>  struct iio_buffer *iio_sw_rb_allocate(struct iio_dev *indio_dev);
>  void iio_sw_rb_free(struct iio_buffer *ring);
> +
> +int iio_sw_rb_simple_setup(struct iio_dev *indio_dev,
> +	irqreturn_t (*pollfunc_bh)(int irq, void *p),
> +	irqreturn_t (*pollfunc_th)(int irq, void *p));
> +void iio_sw_rb_simple_cleanup(struct iio_dev *indio_dev);
> +
>  #endif /* _IIO_RING_SW_H_ */

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

* Re: [PATCH 04/10] staging:iio:imu:adis16400: Use new ringbuffer setup helper function
  2011-12-01 14:19 ` [PATCH 04/10] staging:iio:imu:adis16400: Use new ringbuffer setup helper function Lars-Peter Clausen
@ 2011-12-01 20:53   ` Jonathan Cameron
  0 siblings, 0 replies; 22+ messages in thread
From: Jonathan Cameron @ 2011-12-01 20:53 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Michael Hennerich, linux-iio,
	device-drivers-devel, drivers

On 12/01/2011 02:19 PM, Lars-Peter Clausen wrote:
> Use the new ringbuffer setup helper function to allocate and register buffer and
> pollfunc.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
> ---
>  drivers/staging/iio/imu/adis16400_core.c |   11 --------
>  drivers/staging/iio/imu/adis16400_ring.c |   40 ++---------------------------
>  2 files changed, 3 insertions(+), 48 deletions(-)
> 
> diff --git a/drivers/staging/iio/imu/adis16400_core.c b/drivers/staging/iio/imu/adis16400_core.c
> index de12f9a..f90ede6 100644
> --- a/drivers/staging/iio/imu/adis16400_core.c
> +++ b/drivers/staging/iio/imu/adis16400_core.c
> @@ -1147,14 +1147,6 @@ static int __devinit adis16400_probe(struct spi_device *spi)
>  	if (ret)
>  		goto error_free_dev;
>  
> -	ret = iio_buffer_register(indio_dev,
> -				  st->variant->channels,
> -				  st->variant->num_channels);
> -	if (ret) {
> -		dev_err(&spi->dev, "failed to initialize the ring\n");
> -		goto error_unreg_ring_funcs;
> -	}
> -
>  	if (spi->irq) {
>  		ret = adis16400_probe_trigger(indio_dev);
>  		if (ret)
> @@ -1175,8 +1167,6 @@ error_remove_trigger:
>  	if (indio_dev->modes & INDIO_BUFFER_TRIGGERED)
>  		adis16400_remove_trigger(indio_dev);
>  error_uninitialize_ring:
> -	iio_buffer_unregister(indio_dev);
> -error_unreg_ring_funcs:
>  	adis16400_unconfigure_ring(indio_dev);
>  error_free_dev:
>  	iio_free_device(indio_dev);
> @@ -1196,7 +1186,6 @@ static int adis16400_remove(struct spi_device *spi)
>  		goto err_ret;
>  
>  	adis16400_remove_trigger(indio_dev);
> -	iio_buffer_unregister(indio_dev);
>  	adis16400_unconfigure_ring(indio_dev);
>  	iio_free_device(indio_dev);
>  
> diff --git a/drivers/staging/iio/imu/adis16400_ring.c b/drivers/staging/iio/imu/adis16400_ring.c
> index 8daa038..4dde936 100644
> --- a/drivers/staging/iio/imu/adis16400_ring.c
> +++ b/drivers/staging/iio/imu/adis16400_ring.c
> @@ -166,45 +166,11 @@ err:
>  
>  void adis16400_unconfigure_ring(struct iio_dev *indio_dev)
>  {
> -	iio_dealloc_pollfunc(indio_dev->pollfunc);
> -	iio_sw_rb_free(indio_dev->buffer);
> +	iio_sw_rb_simple_cleanup(indio_dev);
>  }
>  
> -static const struct iio_buffer_setup_ops adis16400_ring_setup_ops = {
> -	.preenable = &iio_sw_buffer_preenable,
> -	.postenable = &iio_triggered_buffer_postenable,
> -	.predisable = &iio_triggered_buffer_predisable,
> -};
> -
>  int adis16400_configure_ring(struct iio_dev *indio_dev)
>  {
> -	int ret = 0;
> -	struct iio_buffer *ring;
> -
> -	ring = iio_sw_rb_allocate(indio_dev);
> -	if (!ring) {
> -		ret = -ENOMEM;
> -		return ret;
> -	}
> -	indio_dev->buffer = ring;
> -	ring->scan_timestamp = true;
> -	indio_dev->setup_ops = &adis16400_ring_setup_ops;
> -
> -	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
> -						 &adis16400_trigger_handler,
> -						 IRQF_ONESHOT,
> -						 indio_dev,
> -						 "%s_consumer%d",
> -						 indio_dev->name,
> -						 indio_dev->id);
> -	if (indio_dev->pollfunc == NULL) {
> -		ret = -ENOMEM;
> -		goto error_iio_sw_rb_free;
> -	}
> -
> -	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
> -	return 0;
> -error_iio_sw_rb_free:
> -	iio_sw_rb_free(indio_dev->buffer);
> -	return ret;
> +	return iio_sw_rb_simple_setup(indio_dev, &iio_pollfunc_store_time,
> +		&adis16400_trigger_handler);
>  }

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

* Re: [PATCH 05/10] staging:iio:gyro:adis16260: Use new ringbuffer setup helper function
  2011-12-01 14:19 ` [PATCH 05/10] staging:iio:gyro:adis16260: " Lars-Peter Clausen
@ 2011-12-01 20:55   ` Jonathan Cameron
  2011-12-03 10:44     ` Lars-Peter Clausen
  0 siblings, 1 reply; 22+ messages in thread
From: Jonathan Cameron @ 2011-12-01 20:55 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Michael Hennerich, linux-iio,
	device-drivers-devel, drivers

On 12/01/2011 02:19 PM, Lars-Peter Clausen wrote:
> Use the new ringbuffer setup helper function to allocate and register buffer and
> pollfunc.
Obviously it's unrelated to this patch, but why do we enable the
timestamp by default for these?
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
> ---
>  drivers/staging/iio/gyro/adis16260_core.c |   10 -------
>  drivers/staging/iio/gyro/adis16260_ring.c |   39 ++++------------------------
>  2 files changed, 6 insertions(+), 43 deletions(-)
> 
> diff --git a/drivers/staging/iio/gyro/adis16260_core.c b/drivers/staging/iio/gyro/adis16260_core.c
> index 871f76b..1e77eae 100644
> --- a/drivers/staging/iio/gyro/adis16260_core.c
> +++ b/drivers/staging/iio/gyro/adis16260_core.c
> @@ -623,13 +623,6 @@ static int __devinit adis16260_probe(struct spi_device *spi)
>  	if (ret)
>  		goto error_free_dev;
>  
> -	ret = iio_buffer_register(indio_dev,
> -				  indio_dev->channels,
> -				  ARRAY_SIZE(adis16260_channels_x));
> -	if (ret) {
> -		printk(KERN_ERR "failed to initialize the ring\n");
> -		goto error_unreg_ring_funcs;
> -	}
>  	if (indio_dev->buffer) {
>  		/* Set default scan mode */
>  		iio_scan_mask_set(indio_dev, indio_dev->buffer,
> @@ -662,8 +655,6 @@ static int __devinit adis16260_probe(struct spi_device *spi)
>  error_remove_trigger:
>  	adis16260_remove_trigger(indio_dev);
>  error_uninitialize_ring:
> -	iio_buffer_unregister(indio_dev);
> -error_unreg_ring_funcs:
>  	adis16260_unconfigure_ring(indio_dev);
>  error_free_dev:
>  	iio_free_device(indio_dev);
> @@ -685,7 +676,6 @@ static int adis16260_remove(struct spi_device *spi)
>  	flush_scheduled_work();
>  
>  	adis16260_remove_trigger(indio_dev);
> -	iio_buffer_unregister(indio_dev);
>  	adis16260_unconfigure_ring(indio_dev);
>  	iio_free_device(indio_dev);
>  
> diff --git a/drivers/staging/iio/gyro/adis16260_ring.c b/drivers/staging/iio/gyro/adis16260_ring.c
> index 711f151..c2f5022 100644
> --- a/drivers/staging/iio/gyro/adis16260_ring.c
> +++ b/drivers/staging/iio/gyro/adis16260_ring.c
> @@ -94,45 +94,18 @@ static irqreturn_t adis16260_trigger_handler(int irq, void *p)
>  
>  void adis16260_unconfigure_ring(struct iio_dev *indio_dev)
>  {
> -	iio_dealloc_pollfunc(indio_dev->pollfunc);
> -	iio_sw_rb_free(indio_dev->buffer);
> +	iio_sw_rb_simple_cleanup(indio_dev);
>  }
>  
> -static const struct iio_buffer_setup_ops adis16260_ring_setup_ops = {
> -	.preenable = &iio_sw_buffer_preenable,
> -	.postenable = &iio_triggered_buffer_postenable,
> -	.predisable = &iio_triggered_buffer_predisable,
> -};
> -
>  int adis16260_configure_ring(struct iio_dev *indio_dev)
>  {
> -	int ret = 0;
> -	struct iio_buffer *ring;
> +	int ret;
>  
> -	ring = iio_sw_rb_allocate(indio_dev);
> -	if (!ring) {
> -		ret = -ENOMEM;
> +	ret = iio_sw_rb_simple_setup(indio_dev, &iio_pollfunc_store_time,
> +		&adis16260_trigger_handler);
> +	if (ret)
>  		return ret;
> -	}
> -	indio_dev->buffer = ring;
> -	ring->scan_timestamp = true;
> -	indio_dev->setup_ops = &adis16260_ring_setup_ops;
> -
> -	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
> -						 &adis16260_trigger_handler,
> -						 IRQF_ONESHOT,
> -						 indio_dev,
> -						 "adis16260_consumer%d",
> -						 indio_dev->id);
> -	if (indio_dev->pollfunc == NULL) {
> -		ret = -ENOMEM;
> -		goto error_iio_sw_rb_free;
> -	}
>  
> -	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
> +	indio_dev->buffer->scan_timestamp = true;
>  	return 0;
> -
> -error_iio_sw_rb_free:
> -	iio_sw_rb_free(indio_dev->buffer);
> -	return ret;
>  }

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

* Re: [PATCH 06/10] staging:iio:accel:adis16201: Use new ringbuffer setup helper function
  2011-12-01 14:19 ` [PATCH 06/10] staging:iio:accel:adis16201: " Lars-Peter Clausen
@ 2011-12-01 20:56   ` Jonathan Cameron
  0 siblings, 0 replies; 22+ messages in thread
From: Jonathan Cameron @ 2011-12-01 20:56 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Michael Hennerich, linux-iio,
	device-drivers-devel, drivers

On 12/01/2011 02:19 PM, Lars-Peter Clausen wrote:
> Use the new ringbuffer setup helper function to allocate and register buffer and
> pollfunc.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
> ---
>  drivers/staging/iio/accel/adis16201_core.c |   11 --------
>  drivers/staging/iio/accel/adis16201_ring.c |   38 ++++-----------------------
>  2 files changed, 6 insertions(+), 43 deletions(-)
> 
> diff --git a/drivers/staging/iio/accel/adis16201_core.c b/drivers/staging/iio/accel/adis16201_core.c
> index ed97da2..29e3c91 100644
> --- a/drivers/staging/iio/accel/adis16201_core.c
> +++ b/drivers/staging/iio/accel/adis16201_core.c
> @@ -491,14 +491,6 @@ static int __devinit adis16201_probe(struct spi_device *spi)
>  	if (ret)
>  		goto error_free_dev;
>  
> -	ret = iio_buffer_register(indio_dev,
> -				  adis16201_channels,
> -				  ARRAY_SIZE(adis16201_channels));
> -	if (ret) {
> -		printk(KERN_ERR "failed to initialize the ring\n");
> -		goto error_unreg_ring_funcs;
> -	}
> -
>  	if (spi->irq) {
>  		ret = adis16201_probe_trigger(indio_dev);
>  		if (ret)
> @@ -518,8 +510,6 @@ static int __devinit adis16201_probe(struct spi_device *spi)
>  error_remove_trigger:
>  	adis16201_remove_trigger(indio_dev);
>  error_uninitialize_ring:
> -	iio_buffer_unregister(indio_dev);
> -error_unreg_ring_funcs:
>  	adis16201_unconfigure_ring(indio_dev);
>  error_free_dev:
>  	iio_free_device(indio_dev);
> @@ -533,7 +523,6 @@ static int adis16201_remove(struct spi_device *spi)
>  
>  	iio_device_unregister(indio_dev);
>  	adis16201_remove_trigger(indio_dev);
> -	iio_buffer_unregister(indio_dev);
>  	adis16201_unconfigure_ring(indio_dev);
>  	iio_free_device(indio_dev);
>  
> diff --git a/drivers/staging/iio/accel/adis16201_ring.c b/drivers/staging/iio/accel/adis16201_ring.c
> index 97f9e6b..882a1e3 100644
> --- a/drivers/staging/iio/accel/adis16201_ring.c
> +++ b/drivers/staging/iio/accel/adis16201_ring.c
> @@ -94,44 +94,18 @@ static irqreturn_t adis16201_trigger_handler(int irq, void *p)
>  
>  void adis16201_unconfigure_ring(struct iio_dev *indio_dev)
>  {
> -	iio_dealloc_pollfunc(indio_dev->pollfunc);
> -	iio_sw_rb_free(indio_dev->buffer);
> +	iio_sw_rb_simple_cleanup(indio_dev);
>  }
>  
> -static const struct iio_buffer_setup_ops adis16201_ring_setup_ops = {
> -	.preenable = &iio_sw_buffer_preenable,
> -	.postenable = &iio_triggered_buffer_postenable,
> -	.predisable = &iio_triggered_buffer_predisable,
> -};
> -
>  int adis16201_configure_ring(struct iio_dev *indio_dev)
>  {
> -	int ret = 0;
> -	struct iio_buffer *ring;
> +	int ret;
>  
> -	ring = iio_sw_rb_allocate(indio_dev);
> -	if (!ring) {
> -		ret = -ENOMEM;
> +	ret = iio_sw_rb_simple_setup(indio_dev, &iio_pollfunc_store_time,
> +		&adis16201_trigger_handler);
> +	if (ret)
>  		return ret;
> -	}
> -	indio_dev->buffer = ring;
> -	ring->scan_timestamp = true;
> -	indio_dev->setup_ops = &adis16201_ring_setup_ops;
> -
> -	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
> -						 &adis16201_trigger_handler,
> -						 IRQF_ONESHOT,
> -						 indio_dev,
> -						 "adis16201_consumer%d",
> -						 indio_dev->id);
> -	if (indio_dev->pollfunc == NULL) {
> -		ret = -ENOMEM;
> -		goto error_iio_sw_rb_free;
> -	}
>  
> -	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
> +	indio_dev->buffer->scan_timestamp = true;
>  	return 0;
> -error_iio_sw_rb_free:
> -	iio_sw_rb_free(indio_dev->buffer);
> -	return ret;
>  }

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

* Re: [PATCH 07/10] staging:iio:adc:max1363: Use new ringbuffer setup helper function
  2011-12-01 14:19 ` [PATCH 07/10] staging:iio:adc:max1363: " Lars-Peter Clausen
@ 2011-12-01 20:58   ` Jonathan Cameron
  0 siblings, 0 replies; 22+ messages in thread
From: Jonathan Cameron @ 2011-12-01 20:58 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Michael Hennerich, linux-iio,
	device-drivers-devel, drivers

On 12/01/2011 02:19 PM, Lars-Peter Clausen wrote:
> Use the new ringbuffer setup helper function to allocate and register buffer and
> pollfunc.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
> ---
>  drivers/staging/iio/adc/max1363_core.c |    9 ------
>  drivers/staging/iio/adc/max1363_ring.c |   43 ++-----------------------------
>  2 files changed, 3 insertions(+), 49 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/max1363_core.c b/drivers/staging/iio/adc/max1363_core.c
> index 1ce89ef..a14329e 100644
> --- a/drivers/staging/iio/adc/max1363_core.c
> +++ b/drivers/staging/iio/adc/max1363_core.c
> @@ -1306,12 +1306,6 @@ static int __devinit max1363_probe(struct i2c_client *client,
>  	if (ret)
>  		goto error_free_available_scan_masks;
>  
> -	ret = iio_buffer_register(indio_dev,
> -				  st->chip_info->channels,
> -				  st->chip_info->num_channels);
> -	if (ret)
> -		goto error_cleanup_ring;
> -
>  	if (client->irq) {
>  		ret = request_threaded_irq(st->client->irq,
>  					   NULL,
> @@ -1332,8 +1326,6 @@ static int __devinit max1363_probe(struct i2c_client *client,
>  error_free_irq:
>  	free_irq(st->client->irq, indio_dev);
>  error_uninit_ring:
> -	iio_buffer_unregister(indio_dev);
> -error_cleanup_ring:
>  	max1363_ring_cleanup(indio_dev);
>  error_free_available_scan_masks:
>  	kfree(indio_dev->available_scan_masks);
> @@ -1356,7 +1348,6 @@ static int max1363_remove(struct i2c_client *client)
>  	iio_device_unregister(indio_dev);
>  	if (client->irq)
>  		free_irq(st->client->irq, indio_dev);
> -	iio_buffer_unregister(indio_dev);
>  	max1363_ring_cleanup(indio_dev);
>  	kfree(indio_dev->available_scan_masks);
>  	if (!IS_ERR(reg)) {
> diff --git a/drivers/staging/iio/adc/max1363_ring.c b/drivers/staging/iio/adc/max1363_ring.c
> index d0a60a3..7a81070 100644
> --- a/drivers/staging/iio/adc/max1363_ring.c
> +++ b/drivers/staging/iio/adc/max1363_ring.c
> @@ -89,50 +89,13 @@ done:
>  	return IRQ_HANDLED;
>  }
>  
> -static const struct iio_buffer_setup_ops max1363_ring_setup_ops = {
> -	.postenable = &iio_triggered_buffer_postenable,
> -	.preenable = &iio_sw_buffer_preenable,
> -	.predisable = &iio_triggered_buffer_predisable,
> -};
> -
>  int max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev)
>  {
> -	struct max1363_state *st = iio_priv(indio_dev);
> -	int ret = 0;
> -
> -	indio_dev->buffer = iio_sw_rb_allocate(indio_dev);
> -	if (!indio_dev->buffer) {
> -		ret = -ENOMEM;
> -		goto error_ret;
> -	}
> -	indio_dev->pollfunc = iio_alloc_pollfunc(NULL,
> -						 &max1363_trigger_handler,
> -						 IRQF_ONESHOT,
> -						 indio_dev,
> -						 "%s_consumer%d",
> -						 st->client->name,
> -						 indio_dev->id);
> -	if (indio_dev->pollfunc == NULL) {
> -		ret = -ENOMEM;
> -		goto error_deallocate_sw_rb;
> -	}
> -	/* Ring buffer functions - here trigger setup related */
> -	indio_dev->setup_ops = &max1363_ring_setup_ops;
> -
> -	/* Flag that polled ring buffering is possible */
> -	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
> -
> -	return 0;
> -
> -error_deallocate_sw_rb:
> -	iio_sw_rb_free(indio_dev->buffer);
> -error_ret:
> -	return ret;
> +	return iio_sw_rb_simple_setup(indio_dev, NULL,
> +	    &max1363_trigger_handler);
>  }
>  
>  void max1363_ring_cleanup(struct iio_dev *indio_dev)
>  {
> -	/* ensure that the trigger has been detached */
> -	iio_dealloc_pollfunc(indio_dev->pollfunc);
> -	iio_sw_rb_free(indio_dev->buffer);
> +	iio_sw_rb_simple_cleanup(indio_dev);
>  }

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

* Re: [PATCH 08/10] staging:iio:adc:ad7476: Use new ringbuffer setup helper function
  2011-12-01 14:19 ` [PATCH 08/10] staging:iio:adc:ad7476: " Lars-Peter Clausen
@ 2011-12-01 20:59   ` Jonathan Cameron
  0 siblings, 0 replies; 22+ messages in thread
From: Jonathan Cameron @ 2011-12-01 20:59 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Michael Hennerich, linux-iio,
	device-drivers-devel, drivers

On 12/01/2011 02:19 PM, Lars-Peter Clausen wrote:
> Use the new ringbuffer setup helper function to allocate and register buffer and
> pollfunc.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
> ---
>  drivers/staging/iio/adc/ad7476.h      |    1 -
>  drivers/staging/iio/adc/ad7476_core.c |    9 ----
>  drivers/staging/iio/adc/ad7476_ring.c |   77 +++-----------------------------
>  3 files changed, 8 insertions(+), 79 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad7476.h b/drivers/staging/iio/adc/ad7476.h
> index 27f696c..b1dd931 100644
> --- a/drivers/staging/iio/adc/ad7476.h
> +++ b/drivers/staging/iio/adc/ad7476.h
> @@ -27,7 +27,6 @@ struct ad7476_state {
>  	struct spi_device		*spi;
>  	const struct ad7476_chip_info	*chip_info;
>  	struct regulator		*reg;
> -	size_t				d_size;
>  	u16				int_vref_mv;
>  	struct spi_transfer		xfer;
>  	struct spi_message		msg;
> diff --git a/drivers/staging/iio/adc/ad7476_core.c b/drivers/staging/iio/adc/ad7476_core.c
> index 447fdbe..b27785b 100644
> --- a/drivers/staging/iio/adc/ad7476_core.c
> +++ b/drivers/staging/iio/adc/ad7476_core.c
> @@ -179,20 +179,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))
> @@ -212,7 +204,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 35a8576..bd3e3ba 100644
> --- a/drivers/staging/iio/adc/ad7476_ring.c
> +++ b/drivers/staging/iio/adc/ad7476_ring.c
> @@ -20,46 +20,17 @@
>  
>  #include "ad7476.h"
>  
> -/**
> - * ad7476_ring_preenable() setup the parameters of the ring before enabling
> - *
> - * The complex nature of the setting of the nuber of bytes per datum is due
> - * to this driver currently ensuring that the timestamp is stored at an 8
> - * byte boundary.
> - **/
> -static int ad7476_ring_preenable(struct iio_dev *indio_dev)
> -{
> -	struct ad7476_state *st = iio_priv(indio_dev);
> -	struct iio_buffer *ring = indio_dev->buffer;
> -
> -	st->d_size = bitmap_weight(indio_dev->active_scan_mask,
> -				   indio_dev->masklength) *
> -		st->chip_info->channel[0].scan_type.storagebits / 8;
> -
> -	if (ring->scan_timestamp) {
> -		st->d_size += sizeof(s64);
> -
> -		if (st->d_size % sizeof(s64))
> -			st->d_size += sizeof(s64) - (st->d_size % sizeof(s64));
> -	}
> -
> -	if (indio_dev->buffer->access->set_bytes_per_datum)
> -		indio_dev->buffer->access->
> -			set_bytes_per_datum(indio_dev->buffer, st->d_size);
> -
> -	return 0;
> -}
> -
>  static irqreturn_t ad7476_trigger_handler(int irq, void  *p)
>  {
>  	struct iio_poll_func *pf = p;
>  	struct iio_dev *indio_dev = pf->indio_dev;
>  	struct ad7476_state *st = iio_priv(indio_dev);
> +	unsigned int bpd = buffer_get_bytes_per_datum(indio_dev->buffer);
>  	s64 time_ns;
>  	__u8 *rxbuf;
>  	int b_sent;
>  
> -	rxbuf = kzalloc(st->d_size, GFP_KERNEL);
> +	rxbuf = kzalloc(bpd, GFP_KERNEL);
>  	if (rxbuf == NULL)
>  		return -ENOMEM;
>  
> @@ -71,7 +42,7 @@ static irqreturn_t ad7476_trigger_handler(int irq, void  *p)
>  	time_ns = iio_get_time_ns();
>  
>  	if (indio_dev->buffer->scan_timestamp)
> -		memcpy(rxbuf + st->d_size - sizeof(s64),
> +		memcpy(rxbuf + bpd - sizeof(s64),
>  			&time_ns, sizeof(time_ns));
>  
>  	indio_dev->buffer->access->store_to(indio_dev->buffer, rxbuf, time_ns);
> @@ -82,51 +53,19 @@ done:
>  	return IRQ_HANDLED;
>  }
>  
> -static const struct iio_buffer_setup_ops ad7476_ring_setup_ops = {
> -	.preenable = &ad7476_ring_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;
> +	int ret;
>  
> -	indio_dev->buffer = iio_sw_rb_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_sw_rb;
> -	}
> +	ret = iio_sw_rb_simple_setup(indio_dev, NULL, &ad7476_trigger_handler);
> +	if (ret)
> +		return ret;
>  
> -	/* 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_sw_rb:
> -	iio_sw_rb_free(indio_dev->buffer);
> -error_ret:
> -	return ret;
>  }
>  
>  void ad7476_ring_cleanup(struct iio_dev *indio_dev)
>  {
> -	iio_dealloc_pollfunc(indio_dev->pollfunc);
> -	iio_sw_rb_free(indio_dev->buffer);
> +	iio_sw_rb_simple_cleanup(indio_dev);
>  }

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

* Re: [PATCH 09/10] staging:iio:adc:ad799x: Use new ringbuffer setup helper function
  2011-12-01 14:19 ` [PATCH 09/10] staging:iio:adc:ad799x: " Lars-Peter Clausen
@ 2011-12-01 21:00   ` Jonathan Cameron
  0 siblings, 0 replies; 22+ messages in thread
From: Jonathan Cameron @ 2011-12-01 21:00 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Michael Hennerich, linux-iio,
	device-drivers-devel, drivers

On 12/01/2011 02:19 PM, Lars-Peter Clausen wrote:
> Use the new ringbuffer setup helper function to allocate and register buffer and
> pollfunc.
>
Good to see the update_scan_mode callback getting used.

> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonthan Cameron <jic23@kernel.org>
> ---
>  drivers/staging/iio/adc/ad799x.h      |    4 +-
>  drivers/staging/iio/adc/ad799x_core.c |   25 ++++++----
>  drivers/staging/iio/adc/ad799x_ring.c |   82 +++-----------------------------
>  3 files changed, 24 insertions(+), 87 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad799x.h b/drivers/staging/iio/adc/ad799x.h
> index 356f690..883ad43 100644
> --- a/drivers/staging/iio/adc/ad799x.h
> +++ b/drivers/staging/iio/adc/ad799x.h
> @@ -104,7 +104,6 @@ struct ad799x_chip_info {
>  struct ad799x_state {
>  	struct i2c_client		*client;
>  	const struct ad799x_chip_info	*chip_info;
> -	size_t				d_size;
>  	struct iio_trigger		*trig;
>  	struct regulator		*reg;
>  	u16				int_vref_mv;
> @@ -121,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);
> @@ -137,5 +134,6 @@ ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev)
>  static inline void ad799x_ring_cleanup(struct iio_dev *indio_dev)
>  {
>  }
> +
>  #endif /* CONFIG_AD799X_RING_BUFFER */
>  #endif /* _AD799X_H_ */
> diff --git a/drivers/staging/iio/adc/ad799x_core.c b/drivers/staging/iio/adc/ad799x_core.c
> index 815e6b9..11313d8 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) | \
> @@ -849,12 +861,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,
> @@ -896,7 +902,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 28e9a41..42b6618 100644
> --- a/drivers/staging/iio/adc/ad799x_ring.c
> +++ b/drivers/staging/iio/adc/ad799x_ring.c
> @@ -24,43 +24,6 @@
>  #include "ad799x.h"
>  
>  /**
> - * ad799x_ring_preenable() setup the parameters of the ring before enabling
> - *
> - * The complex nature of the setting of the nuber 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 iio_buffer *ring = indio_dev->buffer;
> -	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);
> -
> -	st->d_size = bitmap_weight(indio_dev->active_scan_mask,
> -				   indio_dev->masklength) * 2;
> -
> -	if (ring->scan_timestamp) {
> -		st->d_size += sizeof(s64);
> -
> -		if (st->d_size % sizeof(s64))
> -			st->d_size += sizeof(s64) - (st->d_size % sizeof(s64));
> -	}
> -
> -	if (indio_dev->buffer->access->set_bytes_per_datum)
> -		indio_dev->buffer->access->
> -			set_bytes_per_datum(indio_dev->buffer, st->d_size);
> -
> -	return 0;
> -}
> -
> -/**
>   * ad799x_trigger_handler() bh of trigger launched polling to ring buffer
>   *
>   * Currently there is no option in this driver to disable the saving of
> @@ -73,12 +36,13 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
>  	struct iio_dev *indio_dev = pf->indio_dev;
>  	struct ad799x_state *st = iio_priv(indio_dev);
>  	struct iio_buffer *ring = indio_dev->buffer;
> +	unsigned int bpd = buffer_get_bytes_per_datum(ring);
>  	s64 time_ns;
>  	__u8 *rxbuf;
>  	int b_sent;
>  	u8 cmd;
>  
> -	rxbuf = kmalloc(st->d_size, GFP_KERNEL);
> +	rxbuf = kmalloc(bpd, GFP_KERNEL);
>  	if (rxbuf == NULL)
>  		goto out;
>  
> @@ -112,7 +76,7 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
>  	time_ns = iio_get_time_ns();
>  
>  	if (ring->scan_timestamp)
> -		memcpy(rxbuf + st->d_size - sizeof(s64),
> +		memcpy(rxbuf + bpd - sizeof(s64),
>  			&time_ns, sizeof(time_ns));
>  
>  	ring->access->store_to(indio_dev->buffer, rxbuf, time_ns);
> @@ -126,49 +90,19 @@ 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;
> +	int ret;
>  
> -	indio_dev->buffer = iio_sw_rb_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_sw_rb;
> -	}
> +	ret = iio_sw_rb_simple_setup(indio_dev, NULL, &ad799x_trigger_handler);
> +	if (ret)
> +		return ret;
>  
> -	/* 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_sw_rb:
> -	iio_sw_rb_free(indio_dev->buffer);
> -error_ret:
> -	return ret;
>  }
>  
>  void ad799x_ring_cleanup(struct iio_dev *indio_dev)
>  {
> -	iio_dealloc_pollfunc(indio_dev->pollfunc);
> -	iio_sw_rb_free(indio_dev->buffer);
> +	iio_sw_rb_simple_cleanup(indio_dev);
>  }

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

* Re: [PATCH 10/10] staging:iio:adc:ad7298: Use new ringbuffer setup helper function
  2011-12-01 14:19 ` [PATCH 10/10] staging:iio:adc:ad7298: " Lars-Peter Clausen
@ 2011-12-01 21:02   ` Jonathan Cameron
  0 siblings, 0 replies; 22+ messages in thread
From: Jonathan Cameron @ 2011-12-01 21:02 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Michael Hennerich, linux-iio,
	device-drivers-devel, drivers

On 12/01/2011 02:19 PM, Lars-Peter Clausen wrote:
> Use the new ringbuffer setup helper function to allocate and register buffer and
> pollfunc.
> 
> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Acked-by: Jonathan Cameron <jic23@kernel.org>
> ---
>  drivers/staging/iio/adc/ad7298.h      |    6 ++-
>  drivers/staging/iio/adc/ad7298_core.c |   11 +----
>  drivers/staging/iio/adc/ad7298_ring.c |   69 +++++---------------------------
>  3 files changed, 18 insertions(+), 68 deletions(-)
> 
> diff --git a/drivers/staging/iio/adc/ad7298.h b/drivers/staging/iio/adc/ad7298.h
> index a0e5dea..18f2787 100644
> --- a/drivers/staging/iio/adc/ad7298.h
> +++ b/drivers/staging/iio/adc/ad7298.h
> @@ -38,7 +38,6 @@ struct ad7298_platform_data {
>  struct ad7298_state {
>  	struct spi_device		*spi;
>  	struct regulator		*reg;
> -	size_t				d_size;
>  	u16				int_vref_mv;
>  	unsigned			ext_ref;
>  	struct spi_transfer		ring_xfer[10];
> @@ -56,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
> @@ -67,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 6e184ea..b9cb85d 100644
> --- a/drivers/staging/iio/adc/ad7298_core.c
> +++ b/drivers/staging/iio/adc/ad7298_core.c
> @@ -160,6 +160,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,
>  };
>  
> @@ -220,19 +221,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:
> @@ -252,7 +246,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 feeb0ee..baa8b39 100644
> --- a/drivers/staging/iio/adc/ad7298_ring.c
> +++ b/drivers/staging/iio/adc/ad7298_ring.c
> @@ -19,39 +19,21 @@
>  #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);
> -	struct iio_buffer *ring = indio_dev->buffer;
> -	size_t d_size;
>  	int i, m;
>  	unsigned short command;
> -	int scan_count = bitmap_weight(indio_dev->active_scan_mask,
> +	int scan_count = bitmap_weight(active_scan_mask,
>  				       indio_dev->masklength);
> -	d_size = scan_count * (AD7298_STORAGE_BITS / 8);
> -
> -	if (ring->scan_timestamp) {
> -		d_size += sizeof(s64);
> -
> -		if (d_size % sizeof(s64))
> -			d_size += sizeof(s64) - (d_size % sizeof(s64));
> -	}
> -
> -	if (ring->access->set_bytes_per_datum)
> -		ring->access->set_bytes_per_datum(ring, d_size);
> -
> -	st->d_size = d_size;
>  
>  	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);
> @@ -92,6 +74,7 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
>  	struct iio_dev *indio_dev = pf->indio_dev;
>  	struct ad7298_state *st = iio_priv(indio_dev);
>  	struct iio_buffer *ring = indio_dev->buffer;
> +	unsigned int bpd = buffer_get_bytes_per_datum(ring);
>  	s64 time_ns;
>  	__u16 buf[16];
>  	int b_sent, i;
> @@ -102,7 +85,7 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
>  
>  	if (ring->scan_timestamp) {
>  		time_ns = iio_get_time_ns();
> -		memcpy((u8 *)buf + st->d_size - sizeof(s64),
> +		memcpy((u8 *)buf + bpd - sizeof(s64),
>  			&time_ns, sizeof(time_ns));
>  	}
>  
> @@ -116,49 +99,19 @@ 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_sw_rb_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_sw_rb;
> -	}
> +	ret = iio_sw_rb_simple_setup(indio_dev, NULL, &ad7298_trigger_handler);
> +	if (ret)
> +		return ret;
>  
> -	/* 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_sw_rb:
> -	iio_sw_rb_free(indio_dev->buffer);
> -error_ret:
> -	return ret;
>  }
>  
>  void ad7298_ring_cleanup(struct iio_dev *indio_dev)
>  {
> -	iio_dealloc_pollfunc(indio_dev->pollfunc);
> -	iio_sw_rb_free(indio_dev->buffer);
> +	iio_sw_rb_simple_cleanup(indio_dev);
>  }

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

* Re: [PATCH 05/10] staging:iio:gyro:adis16260: Use new ringbuffer setup helper function
  2011-12-01 20:55   ` Jonathan Cameron
@ 2011-12-03 10:44     ` Lars-Peter Clausen
  2011-12-04 17:21       ` Jonathan Cameron
  0 siblings, 1 reply; 22+ messages in thread
From: Lars-Peter Clausen @ 2011-12-03 10:44 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Jonathan Cameron, Michael Hennerich, linux-iio,
	device-drivers-devel, drivers

On 12/01/2011 09:55 PM, Jonathan Cameron wrote:
> On 12/01/2011 02:19 PM, Lars-Peter Clausen wrote:
>> Use the new ringbuffer setup helper function to allocate and register buffer and
>> pollfunc.
> Obviously it's unrelated to this patch, but why do we enable the
> timestamp by default for these?

I have actually no idea. Probably makes sens to not bother keeping it.

>>
>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
> Acked-by: Jonathan Cameron <jic23@kernel.org>

Thanks.

Whats your plan for your buffer cleanup patches? They looked fine to me, except
the ones where I commented.

>> ---
>>  drivers/staging/iio/gyro/adis16260_core.c |   10 -------
>>  drivers/staging/iio/gyro/adis16260_ring.c |   39 ++++------------------------
>>  2 files changed, 6 insertions(+), 43 deletions(-)
>>
>> diff --git a/drivers/staging/iio/gyro/adis16260_core.c b/drivers/staging/iio/gyro/adis16260_core.c
>> index 871f76b..1e77eae 100644
>> --- a/drivers/staging/iio/gyro/adis16260_core.c
>> +++ b/drivers/staging/iio/gyro/adis16260_core.c
>> @@ -623,13 +623,6 @@ static int __devinit adis16260_probe(struct spi_device *spi)
>>  	if (ret)
>>  		goto error_free_dev;
>>  
>> -	ret = iio_buffer_register(indio_dev,
>> -				  indio_dev->channels,
>> -				  ARRAY_SIZE(adis16260_channels_x));
>> -	if (ret) {
>> -		printk(KERN_ERR "failed to initialize the ring\n");
>> -		goto error_unreg_ring_funcs;
>> -	}
>>  	if (indio_dev->buffer) {
>>  		/* Set default scan mode */
>>  		iio_scan_mask_set(indio_dev, indio_dev->buffer,
>> @@ -662,8 +655,6 @@ static int __devinit adis16260_probe(struct spi_device *spi)
>>  error_remove_trigger:
>>  	adis16260_remove_trigger(indio_dev);
>>  error_uninitialize_ring:
>> -	iio_buffer_unregister(indio_dev);
>> -error_unreg_ring_funcs:
>>  	adis16260_unconfigure_ring(indio_dev);
>>  error_free_dev:
>>  	iio_free_device(indio_dev);
>> @@ -685,7 +676,6 @@ static int adis16260_remove(struct spi_device *spi)
>>  	flush_scheduled_work();
>>  
>>  	adis16260_remove_trigger(indio_dev);
>> -	iio_buffer_unregister(indio_dev);
>>  	adis16260_unconfigure_ring(indio_dev);
>>  	iio_free_device(indio_dev);
>>  
>> diff --git a/drivers/staging/iio/gyro/adis16260_ring.c b/drivers/staging/iio/gyro/adis16260_ring.c
>> index 711f151..c2f5022 100644
>> --- a/drivers/staging/iio/gyro/adis16260_ring.c
>> +++ b/drivers/staging/iio/gyro/adis16260_ring.c
>> @@ -94,45 +94,18 @@ static irqreturn_t adis16260_trigger_handler(int irq, void *p)
>>  
>>  void adis16260_unconfigure_ring(struct iio_dev *indio_dev)
>>  {
>> -	iio_dealloc_pollfunc(indio_dev->pollfunc);
>> -	iio_sw_rb_free(indio_dev->buffer);
>> +	iio_sw_rb_simple_cleanup(indio_dev);
>>  }
>>  
>> -static const struct iio_buffer_setup_ops adis16260_ring_setup_ops = {
>> -	.preenable = &iio_sw_buffer_preenable,
>> -	.postenable = &iio_triggered_buffer_postenable,
>> -	.predisable = &iio_triggered_buffer_predisable,
>> -};
>> -
>>  int adis16260_configure_ring(struct iio_dev *indio_dev)
>>  {
>> -	int ret = 0;
>> -	struct iio_buffer *ring;
>> +	int ret;
>>  
>> -	ring = iio_sw_rb_allocate(indio_dev);
>> -	if (!ring) {
>> -		ret = -ENOMEM;
>> +	ret = iio_sw_rb_simple_setup(indio_dev, &iio_pollfunc_store_time,
>> +		&adis16260_trigger_handler);
>> +	if (ret)
>>  		return ret;
>> -	}
>> -	indio_dev->buffer = ring;
>> -	ring->scan_timestamp = true;
>> -	indio_dev->setup_ops = &adis16260_ring_setup_ops;
>> -
>> -	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
>> -						 &adis16260_trigger_handler,
>> -						 IRQF_ONESHOT,
>> -						 indio_dev,
>> -						 "adis16260_consumer%d",
>> -						 indio_dev->id);
>> -	if (indio_dev->pollfunc == NULL) {
>> -		ret = -ENOMEM;
>> -		goto error_iio_sw_rb_free;
>> -	}
>>  
>> -	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
>> +	indio_dev->buffer->scan_timestamp = true;
>>  	return 0;
>> -
>> -error_iio_sw_rb_free:
>> -	iio_sw_rb_free(indio_dev->buffer);
>> -	return ret;
>>  }
> 

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

* Re: [PATCH 05/10] staging:iio:gyro:adis16260: Use new ringbuffer setup helper function
  2011-12-03 10:44     ` Lars-Peter Clausen
@ 2011-12-04 17:21       ` Jonathan Cameron
  0 siblings, 0 replies; 22+ messages in thread
From: Jonathan Cameron @ 2011-12-04 17:21 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, Michael Hennerich, linux-iio,
	device-drivers-devel, drivers

On 12/03/2011 10:44 AM, Lars-Peter Clausen wrote:
> On 12/01/2011 09:55 PM, Jonathan Cameron wrote:
>> On 12/01/2011 02:19 PM, Lars-Peter Clausen wrote:
>>> Use the new ringbuffer setup helper function to allocate and register buffer and
>>> pollfunc.
>> Obviously it's unrelated to this patch, but why do we enable the
>> timestamp by default for these?
> 
> I have actually no idea. Probably makes sens to not bother keeping it.
Indeed. I guess these are left over from when we moved to a bitmap for
the scan mask (and hence removed almost defaults for channels in buffers
to make the code simpler).  Lets clear them out.

As ever I'm happy if someone else does this or anything else before I
get round to it!
> 
>>>
>>> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
>> Acked-by: Jonathan Cameron <jic23@kernel.org>
> 
> Thanks.
> 
> Whats your plan for your buffer cleanup patches? They looked fine to me, except
> the ones where I commented.
Will post a v2 shortly.  Please ack any that you are happy to do so.
Obviously I can cheat a bit and send things on to Greg if they haven't
had an Ack from anyone, but I only do that once they have been on list
for a decent period of time, or if they are urgent bug fixes.

Hence, if anyone has gone to the effort of reading a patch and checking
it is sensible, please let me know via ack or reviewed by tags!

Thanks,

Jonathan
> 
>>> ---
>>>  drivers/staging/iio/gyro/adis16260_core.c |   10 -------
>>>  drivers/staging/iio/gyro/adis16260_ring.c |   39 ++++------------------------
>>>  2 files changed, 6 insertions(+), 43 deletions(-)
>>>
>>> diff --git a/drivers/staging/iio/gyro/adis16260_core.c b/drivers/staging/iio/gyro/adis16260_core.c
>>> index 871f76b..1e77eae 100644
>>> --- a/drivers/staging/iio/gyro/adis16260_core.c
>>> +++ b/drivers/staging/iio/gyro/adis16260_core.c
>>> @@ -623,13 +623,6 @@ static int __devinit adis16260_probe(struct spi_device *spi)
>>>  	if (ret)
>>>  		goto error_free_dev;
>>>  
>>> -	ret = iio_buffer_register(indio_dev,
>>> -				  indio_dev->channels,
>>> -				  ARRAY_SIZE(adis16260_channels_x));
>>> -	if (ret) {
>>> -		printk(KERN_ERR "failed to initialize the ring\n");
>>> -		goto error_unreg_ring_funcs;
>>> -	}
>>>  	if (indio_dev->buffer) {
>>>  		/* Set default scan mode */
>>>  		iio_scan_mask_set(indio_dev, indio_dev->buffer,
>>> @@ -662,8 +655,6 @@ static int __devinit adis16260_probe(struct spi_device *spi)
>>>  error_remove_trigger:
>>>  	adis16260_remove_trigger(indio_dev);
>>>  error_uninitialize_ring:
>>> -	iio_buffer_unregister(indio_dev);
>>> -error_unreg_ring_funcs:
>>>  	adis16260_unconfigure_ring(indio_dev);
>>>  error_free_dev:
>>>  	iio_free_device(indio_dev);
>>> @@ -685,7 +676,6 @@ static int adis16260_remove(struct spi_device *spi)
>>>  	flush_scheduled_work();
>>>  
>>>  	adis16260_remove_trigger(indio_dev);
>>> -	iio_buffer_unregister(indio_dev);
>>>  	adis16260_unconfigure_ring(indio_dev);
>>>  	iio_free_device(indio_dev);
>>>  
>>> diff --git a/drivers/staging/iio/gyro/adis16260_ring.c b/drivers/staging/iio/gyro/adis16260_ring.c
>>> index 711f151..c2f5022 100644
>>> --- a/drivers/staging/iio/gyro/adis16260_ring.c
>>> +++ b/drivers/staging/iio/gyro/adis16260_ring.c
>>> @@ -94,45 +94,18 @@ static irqreturn_t adis16260_trigger_handler(int irq, void *p)
>>>  
>>>  void adis16260_unconfigure_ring(struct iio_dev *indio_dev)
>>>  {
>>> -	iio_dealloc_pollfunc(indio_dev->pollfunc);
>>> -	iio_sw_rb_free(indio_dev->buffer);
>>> +	iio_sw_rb_simple_cleanup(indio_dev);
>>>  }
>>>  
>>> -static const struct iio_buffer_setup_ops adis16260_ring_setup_ops = {
>>> -	.preenable = &iio_sw_buffer_preenable,
>>> -	.postenable = &iio_triggered_buffer_postenable,
>>> -	.predisable = &iio_triggered_buffer_predisable,
>>> -};
>>> -
>>>  int adis16260_configure_ring(struct iio_dev *indio_dev)
>>>  {
>>> -	int ret = 0;
>>> -	struct iio_buffer *ring;
>>> +	int ret;
>>>  
>>> -	ring = iio_sw_rb_allocate(indio_dev);
>>> -	if (!ring) {
>>> -		ret = -ENOMEM;
>>> +	ret = iio_sw_rb_simple_setup(indio_dev, &iio_pollfunc_store_time,
>>> +		&adis16260_trigger_handler);
>>> +	if (ret)
>>>  		return ret;
>>> -	}
>>> -	indio_dev->buffer = ring;
>>> -	ring->scan_timestamp = true;
>>> -	indio_dev->setup_ops = &adis16260_ring_setup_ops;
>>> -
>>> -	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
>>> -						 &adis16260_trigger_handler,
>>> -						 IRQF_ONESHOT,
>>> -						 indio_dev,
>>> -						 "adis16260_consumer%d",
>>> -						 indio_dev->id);
>>> -	if (indio_dev->pollfunc == NULL) {
>>> -		ret = -ENOMEM;
>>> -		goto error_iio_sw_rb_free;
>>> -	}
>>>  
>>> -	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
>>> +	indio_dev->buffer->scan_timestamp = true;
>>>  	return 0;
>>> -
>>> -error_iio_sw_rb_free:
>>> -	iio_sw_rb_free(indio_dev->buffer);
>>> -	return ret;
>>>  }
>>
> 

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

end of thread, other threads:[~2011-12-04 17:21 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-01 14:19 [PATCH 01/10] staging:iio: Add wrapper functions around buffer access ops Lars-Peter Clausen
2011-12-01 14:19 ` [PATCH 02/10] staging:iio: Setup buffer access functions when allocating the buffer Lars-Peter Clausen
2011-12-01 20:48   ` Jonathan Cameron
2011-12-01 14:19 ` [PATCH 03/10] staging:iio:ring_sw: Add helper function for initializing simple setups Lars-Peter Clausen
2011-12-01 20:51   ` Jonathan Cameron
2011-12-01 14:19 ` [PATCH 04/10] staging:iio:imu:adis16400: Use new ringbuffer setup helper function Lars-Peter Clausen
2011-12-01 20:53   ` Jonathan Cameron
2011-12-01 14:19 ` [PATCH 05/10] staging:iio:gyro:adis16260: " Lars-Peter Clausen
2011-12-01 20:55   ` Jonathan Cameron
2011-12-03 10:44     ` Lars-Peter Clausen
2011-12-04 17:21       ` Jonathan Cameron
2011-12-01 14:19 ` [PATCH 06/10] staging:iio:accel:adis16201: " Lars-Peter Clausen
2011-12-01 20:56   ` Jonathan Cameron
2011-12-01 14:19 ` [PATCH 07/10] staging:iio:adc:max1363: " Lars-Peter Clausen
2011-12-01 20:58   ` Jonathan Cameron
2011-12-01 14:19 ` [PATCH 08/10] staging:iio:adc:ad7476: " Lars-Peter Clausen
2011-12-01 20:59   ` Jonathan Cameron
2011-12-01 14:19 ` [PATCH 09/10] staging:iio:adc:ad799x: " Lars-Peter Clausen
2011-12-01 21:00   ` Jonathan Cameron
2011-12-01 14:19 ` [PATCH 10/10] staging:iio:adc:ad7298: " Lars-Peter Clausen
2011-12-01 21:02   ` Jonathan Cameron
2011-12-01 20:40 ` [PATCH 01/10] staging:iio: Add wrapper functions around buffer access ops 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).