All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH 0/5] Refactoring of ring buffer elements of Barry's recent RFC
@ 2010-06-30 14:27 Jonathan Cameron
  2010-06-30 14:27 ` [PATCH 1/5] staging:iio: Add a bits per element element to ring_generic allowing a general ring_sw_preenable_function Jonathan Cameron
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Jonathan Cameron @ 2010-06-30 14:27 UTC (permalink / raw)
  To: linux-iio; +Cc: barry.song, Jonathan Cameron

Hi Barry,

This set are my follow up to my comments on your recent set.
What do you think of doing it this way round?

(the first is your code with a few minor edits, the second
makes use of it pretty much everywhere). The last 3 are the
refactored approach with the core work in patch 3 and
two example use cases (untested) in patches 4 and 5.

Jonathan

p.s. Thanks for all your ack's on the previous series, I'll
send them on to Greg KH shortly.

Barry Song (1):
  staging:iio: Add a bits per element element to ring_generic allowing 
       a general ring_sw_preenable_function.

Jonathan Cameron (4):
  staging:iio: Make extensive use of iio_sw_ring_preenable
  staging:iio: Add iio_sw_ring_helper_state and functions to cover
    common case.
  staging:iio:lis3l02dq use iio_sw_ring_helper_state and funcs
  staging:iio:adis16209 use iio_sw_ring_helper_state and funcs

 drivers/staging/iio/accel/adis16209.h         |    7 +-
 drivers/staging/iio/accel/adis16209_core.c    |   54 +++++----
 drivers/staging/iio/accel/adis16209_ring.c    |   95 +++-------------
 drivers/staging/iio/accel/adis16209_trigger.c |    8 +-
 drivers/staging/iio/accel/adis16240_ring.c    |   29 +-----
 drivers/staging/iio/accel/lis3l02dq.h         |   11 +-
 drivers/staging/iio/accel/lis3l02dq_core.c    |  116 +++++++++++--------
 drivers/staging/iio/accel/lis3l02dq_ring.c    |  152 +++++++------------------
 drivers/staging/iio/gyro/adis16260_ring.c     |   29 +-----
 drivers/staging/iio/imu/adis16300_ring.c      |   26 +----
 drivers/staging/iio/imu/adis16350_ring.c      |   29 +-----
 drivers/staging/iio/imu/adis16400_ring.c      |   26 +----
 drivers/staging/iio/ring_generic.h            |    2 +
 drivers/staging/iio/ring_sw.c                 |   68 +++++++++++
 drivers/staging/iio/ring_sw.h                 |   10 ++
 15 files changed, 257 insertions(+), 405 deletions(-)

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

* [PATCH 1/5] staging:iio: Add a bits per element element to ring_generic allowing a general ring_sw_preenable_function.
  2010-06-30 14:27 [RFC PATCH 0/5] Refactoring of ring buffer elements of Barry's recent RFC Jonathan Cameron
@ 2010-06-30 14:27 ` Jonathan Cameron
  2010-06-30 14:27 ` [PATCH 2/5] staging:iio: Make extensive use of iio_sw_ring_preenable Jonathan Cameron
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2010-06-30 14:27 UTC (permalink / raw)
  To: linux-iio; +Cc: barry.song, Barry Song, Jonathan Cameron

From: Barry Song <21cnbao@gmail.com>

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/ring_generic.h |    2 ++
 drivers/staging/iio/ring_sw.c      |   25 +++++++++++++++++++++++++
 drivers/staging/iio/ring_sw.h      |    2 +-
 3 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/drivers/staging/iio/ring_generic.h b/drivers/staging/iio/ring_generic.h
index dbf11e1..7ef94d7 100644
--- a/drivers/staging/iio/ring_generic.h
+++ b/drivers/staging/iio/ring_generic.h
@@ -100,6 +100,7 @@ struct iio_ring_access_funcs {
  * @access_id:		device id number
  * @length:		[DEVICE] number of datums in ring
  * @bpd:		[DEVICE] size of individual datum including timestamp
+ * @bpe:		[DEVICE] size of individual channel value
  * @loopcount:		[INTERN] number of times the ring has looped
  * @access_handler:	[INTERN] chrdev access handling
  * @ev_int:		[INTERN] chrdev interface for the event chrdev
@@ -121,6 +122,7 @@ struct iio_ring_buffer {
 	int				access_id;
 	int				length;
 	int				bpd;
+	int				bpe;
 	int				loopcount;
 	struct iio_handler		access_handler;
 	struct iio_event_interface	ev_int;
diff --git a/drivers/staging/iio/ring_sw.c b/drivers/staging/iio/ring_sw.c
index 294272d..ca0e79e 100644
--- a/drivers/staging/iio/ring_sw.c
+++ b/drivers/staging/iio/ring_sw.c
@@ -431,5 +431,30 @@ void iio_sw_rb_free(struct iio_ring_buffer *r)
 		iio_put_ring_buffer(r);
 }
 EXPORT_SYMBOL(iio_sw_rb_free);
+
+int iio_sw_ring_preenable(struct iio_dev *indio_dev)
+{
+	size_t size;
+	dev_dbg(&indio_dev->dev, "%s\n", __func__);
+	/* Check if there are any scan elements enabled, if not fail*/
+	if (!(indio_dev->scan_count || indio_dev->scan_timestamp))
+		return -EINVAL;
+	if (indio_dev->scan_timestamp)
+		if (indio_dev->scan_count)
+			/* Timestamp (aligned to s64) and data */
+			size = (((indio_dev->scan_count * indio_dev->ring->bpe)
+					+ sizeof(s64) - 1)
+				& ~(sizeof(s64) - 1))
+				+ sizeof(s64);
+		else /* Timestamp only  */
+			size = sizeof(s64);
+	else /* Data only */
+		size = indio_dev->scan_count * indio_dev->ring->bpe;
+	indio_dev->ring->access.set_bpd(indio_dev->ring, size);
+
+	return 0;
+}
+EXPORT_SYMBOL(iio_sw_ring_preenable);
+
 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 fd677f0..5c22936 100644
--- a/drivers/staging/iio/ring_sw.h
+++ b/drivers/staging/iio/ring_sw.h
@@ -207,7 +207,7 @@ struct iio_sw_ring_buffer {
 struct iio_ring_buffer *iio_sw_rb_allocate(struct iio_dev *indio_dev);
 void iio_sw_rb_free(struct iio_ring_buffer *ring);
 
-
+int iio_sw_ring_preenable(struct iio_dev *indio_dev);
 
 #else /* CONFIG_IIO_RING_BUFFER*/
 static inline void iio_ring_sw_register_funcs(struct iio_ring_access_funcs *ra)
-- 
1.7.0.4

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

* [PATCH 2/5] staging:iio: Make extensive use of iio_sw_ring_preenable
  2010-06-30 14:27 [RFC PATCH 0/5] Refactoring of ring buffer elements of Barry's recent RFC Jonathan Cameron
  2010-06-30 14:27 ` [PATCH 1/5] staging:iio: Add a bits per element element to ring_generic allowing a general ring_sw_preenable_function Jonathan Cameron
@ 2010-06-30 14:27 ` Jonathan Cameron
  2010-07-07 10:59   ` Barry Song
  2010-06-30 14:27 ` [PATCH 3/5] staging:iio: Add iio_sw_ring_helper_state and functions to cover common case Jonathan Cameron
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Jonathan Cameron @ 2010-06-30 14:27 UTC (permalink / raw)
  To: linux-iio; +Cc: barry.song, Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/accel/adis16209_ring.c |   31 +--------------------------
 drivers/staging/iio/accel/adis16240_ring.c |   29 +------------------------
 drivers/staging/iio/accel/lis3l02dq_ring.c |   25 +--------------------
 drivers/staging/iio/gyro/adis16260_ring.c  |   29 +------------------------
 drivers/staging/iio/imu/adis16300_ring.c   |   26 +---------------------
 drivers/staging/iio/imu/adis16350_ring.c   |   29 +------------------------
 drivers/staging/iio/imu/adis16400_ring.c   |   26 +---------------------
 7 files changed, 14 insertions(+), 181 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16209_ring.c b/drivers/staging/iio/accel/adis16209_ring.c
index f3a9493..25fde65 100644
--- a/drivers/staging/iio/accel/adis16209_ring.c
+++ b/drivers/staging/iio/accel/adis16209_ring.c
@@ -147,34 +147,6 @@ static void adis16209_trigger_bh_to_ring(struct work_struct *work_s)
 	return;
 }
 
-/* in these circumstances is it better to go with unaligned packing and
- * deal with the cost?*/
-static int adis16209_data_rdy_ring_preenable(struct iio_dev *indio_dev)
-{
-	size_t size;
-	dev_dbg(&indio_dev->dev, "%s\n", __func__);
-	/* Check if there are any scan elements enabled, if not fail*/
-	if (!(indio_dev->scan_count || indio_dev->scan_timestamp))
-		return -EINVAL;
-
-	if (indio_dev->ring->access.set_bpd) {
-		if (indio_dev->scan_timestamp)
-			if (indio_dev->scan_count)
-				/* Timestamp (aligned to s64) and data */
-				size = (((indio_dev->scan_count * sizeof(s16))
-					 + sizeof(s64) - 1)
-					& ~(sizeof(s64) - 1))
-					+ sizeof(s64);
-			else /* Timestamp only  */
-				size = sizeof(s64);
-		else /* Data only */
-			size = indio_dev->scan_count*sizeof(s16);
-		indio_dev->ring->access.set_bpd(indio_dev->ring, size);
-	}
-
-	return 0;
-}
-
 void adis16209_unconfigure_ring(struct iio_dev *indio_dev)
 {
 	kfree(indio_dev->pollfunc);
@@ -209,7 +181,8 @@ int adis16209_configure_ring(struct iio_dev *indio_dev)
 	indio_dev->ring = ring;
 	/* Effectively select the ring buffer implementation */
 	iio_ring_sw_register_funcs(&ring->access);
-	ring->preenable = &adis16209_data_rdy_ring_preenable;
+	ring->bpe = 2;
+	ring->preenable = &iio_sw_ring_preenable;
 	ring->postenable = &iio_triggered_ring_postenable;
 	ring->predisable = &iio_triggered_ring_predisable;
 	ring->owner = THIS_MODULE;
diff --git a/drivers/staging/iio/accel/adis16240_ring.c b/drivers/staging/iio/accel/adis16240_ring.c
index a1611bb..cd69a2e 100644
--- a/drivers/staging/iio/accel/adis16240_ring.c
+++ b/drivers/staging/iio/accel/adis16240_ring.c
@@ -139,32 +139,6 @@ static void adis16240_trigger_bh_to_ring(struct work_struct *work_s)
 	return;
 }
 
-static int adis16240_data_rdy_ring_preenable(struct iio_dev *indio_dev)
-{
-	size_t size;
-	dev_dbg(&indio_dev->dev, "%s\n", __func__);
-	/* Check if there are any scan elements enabled, if not fail*/
-	if (!(indio_dev->scan_count || indio_dev->scan_timestamp))
-		return -EINVAL;
-
-	if (indio_dev->ring->access.set_bpd) {
-		if (indio_dev->scan_timestamp)
-			if (indio_dev->scan_count)
-				/* Timestamp (aligned sizeof(s64) and data */
-				size = (((indio_dev->scan_count * sizeof(s16))
-					 + sizeof(s64) - 1)
-					& ~(sizeof(s64) - 1))
-					+ sizeof(s64);
-			else /* Timestamp only  */
-				size = sizeof(s64);
-		else /* Data only */
-			size = indio_dev->scan_count*sizeof(s16);
-		indio_dev->ring->access.set_bpd(indio_dev->ring, size);
-	}
-
-	return 0;
-}
-
 void adis16240_unconfigure_ring(struct iio_dev *indio_dev)
 {
 	kfree(indio_dev->pollfunc);
@@ -197,7 +171,8 @@ int adis16240_configure_ring(struct iio_dev *indio_dev)
 	indio_dev->ring = ring;
 	/* Effectively select the ring buffer implementation */
 	iio_ring_sw_register_funcs(&ring->access);
-	ring->preenable = &adis16240_data_rdy_ring_preenable;
+	ring->bpe = 2;
+	ring->preenable = &iio_sw_ring_preenable;
 	ring->postenable = &iio_triggered_ring_postenable;
 	ring->predisable = &iio_triggered_ring_predisable;
 	ring->owner = THIS_MODULE;
diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c
index a506dab..2c11209 100644
--- a/drivers/staging/iio/accel/lis3l02dq_ring.c
+++ b/drivers/staging/iio/accel/lis3l02dq_ring.c
@@ -315,28 +315,6 @@ static void lis3l02dq_trigger_bh_to_ring(struct work_struct *work_s)
 
 	return;
 }
-/* in these circumstances is it better to go with unaligned packing and
- * deal with the cost?*/
-static int lis3l02dq_data_rdy_ring_preenable(struct iio_dev *indio_dev)
-{
-	size_t size;
-	/* Check if there are any scan elements enabled, if not fail*/
-	if (!(indio_dev->scan_count || indio_dev->scan_timestamp))
-		return -EINVAL;
-
-	if (indio_dev->ring->access.set_bpd) {
-		if (indio_dev->scan_timestamp)
-			if (indio_dev->scan_count) /* Timestamp and data */
-				size = 2*sizeof(s64);
-			else /* Timestamp only  */
-				size = sizeof(s64);
-		else /* Data only */
-			size = indio_dev->scan_count*sizeof(s16);
-		indio_dev->ring->access.set_bpd(indio_dev->ring, size);
-	}
-
-	return 0;
-}
 
 /* Caller responsible for locking as necessary. */
 static int
@@ -543,7 +521,8 @@ int lis3l02dq_configure_ring(struct iio_dev *indio_dev)
 	indio_dev->ring = ring;
 	/* Effectively select the ring buffer implementation */
 	iio_ring_sw_register_funcs(&ring->access);
-	ring->preenable = &lis3l02dq_data_rdy_ring_preenable;
+	ring->bpe = 2;
+	ring->preenable = &iio_sw_ring_preenable;
 	ring->postenable = &iio_triggered_ring_postenable;
 	ring->predisable = &iio_triggered_ring_predisable;
 	ring->owner = THIS_MODULE;
diff --git a/drivers/staging/iio/gyro/adis16260_ring.c b/drivers/staging/iio/gyro/adis16260_ring.c
index 94b4515..9ef7f90 100644
--- a/drivers/staging/iio/gyro/adis16260_ring.c
+++ b/drivers/staging/iio/gyro/adis16260_ring.c
@@ -142,32 +142,6 @@ static void adis16260_trigger_bh_to_ring(struct work_struct *work_s)
 	return;
 }
 
-static int adis16260_data_rdy_ring_preenable(struct iio_dev *indio_dev)
-{
-	size_t size;
-	dev_dbg(&indio_dev->dev, "%s\n", __func__);
-	/* Check if there are any scan elements enabled, if not fail*/
-	if (!(indio_dev->scan_count || indio_dev->scan_timestamp))
-		return -EINVAL;
-
-	if (indio_dev->ring->access.set_bpd) {
-		if (indio_dev->scan_timestamp)
-			if (indio_dev->scan_count)
-				/* Timestamp (aligned s64) and data */
-				size = (((indio_dev->scan_count * sizeof(s16))
-						+ sizeof(s64) - 1)
-					& ~(sizeof(s64) - 1))
-					+ sizeof(s64);
-			else /* Timestamp only  */
-				size = sizeof(s64);
-		else /* Data only */
-			size = indio_dev->scan_count*sizeof(s16);
-		indio_dev->ring->access.set_bpd(indio_dev->ring, size);
-	}
-
-	return 0;
-}
-
 void adis16260_unconfigure_ring(struct iio_dev *indio_dev)
 {
 	kfree(indio_dev->pollfunc);
@@ -199,7 +173,8 @@ int adis16260_configure_ring(struct iio_dev *indio_dev)
 	indio_dev->ring = ring;
 	/* Effectively select the ring buffer implementation */
 	iio_ring_sw_register_funcs(&ring->access);
-	ring->preenable = &adis16260_data_rdy_ring_preenable;
+	ring->bpe = 2;
+	ring->preenable = &iio_sw_ring_preenable;
 	ring->postenable = &iio_triggered_ring_postenable;
 	ring->predisable = &iio_triggered_ring_predisable;
 	ring->owner = THIS_MODULE;
diff --git a/drivers/staging/iio/imu/adis16300_ring.c b/drivers/staging/iio/imu/adis16300_ring.c
index 3bf9904..fc93160 100644
--- a/drivers/staging/iio/imu/adis16300_ring.c
+++ b/drivers/staging/iio/imu/adis16300_ring.c
@@ -165,29 +165,6 @@ static void adis16300_trigger_bh_to_ring(struct work_struct *work_s)
 
 	return;
 }
-/* in these circumstances is it better to go with unaligned packing and
- * deal with the cost?*/
-static int adis16300_data_rdy_ring_preenable(struct iio_dev *indio_dev)
-{
-	size_t size;
-	dev_dbg(&indio_dev->dev, "%s\n", __func__);
-	/* Check if there are any scan elements enabled, if not fail*/
-	if (!(indio_dev->scan_count || indio_dev->scan_timestamp))
-		return -EINVAL;
-
-	if (indio_dev->ring->access.set_bpd) {
-		if (indio_dev->scan_timestamp)
-			if (indio_dev->scan_count) /* Timestamp and data */
-				size = 4*sizeof(s64);
-			else /* Timestamp only  */
-				size = sizeof(s64);
-		else /* Data only */
-			size = indio_dev->scan_count*sizeof(s16);
-		indio_dev->ring->access.set_bpd(indio_dev->ring, size);
-	}
-
-	return 0;
-}
 
 void adis16300_unconfigure_ring(struct iio_dev *indio_dev)
 {
@@ -224,7 +201,8 @@ int adis16300_configure_ring(struct iio_dev *indio_dev)
 	indio_dev->ring = ring;
 	/* Effectively select the ring buffer implementation */
 	iio_ring_sw_register_funcs(&ring->access);
-	ring->preenable = &adis16300_data_rdy_ring_preenable;
+	ring->bpe = 2;
+	ring->preenable = &iio_sw_ring_preenable;
 	ring->postenable = &iio_triggered_ring_postenable;
 	ring->predisable = &iio_triggered_ring_predisable;
 	ring->owner = THIS_MODULE;
diff --git a/drivers/staging/iio/imu/adis16350_ring.c b/drivers/staging/iio/imu/adis16350_ring.c
index 319aa34..e053e9a 100644
--- a/drivers/staging/iio/imu/adis16350_ring.c
+++ b/drivers/staging/iio/imu/adis16350_ring.c
@@ -166,32 +166,6 @@ static void adis16350_trigger_bh_to_ring(struct work_struct *work_s)
 	return;
 }
 
-static int adis16350_data_rdy_ring_preenable(struct iio_dev *indio_dev)
-{
-	size_t size;
-	dev_dbg(&indio_dev->dev, "%s\n", __func__);
-	/* Check if there are any scan elements enabled, if not fail*/
-	if (!(indio_dev->scan_count || indio_dev->scan_timestamp))
-		return -EINVAL;
-
-	if (indio_dev->ring->access.set_bpd) {
-		if (indio_dev->scan_timestamp)
-			if (indio_dev->scan_count)
-				/* Timestamp (aligned sizeof(s64) and data */
-				size = (((indio_dev->scan_count * sizeof(s16))
-						+ sizeof(s64) - 1)
-					& ~(sizeof(s64) - 1))
-					+ sizeof(s64);
-			else /* Timestamp only  */
-				size = sizeof(s64);
-		else /* Data only */
-			size = indio_dev->scan_count*sizeof(s16);
-		indio_dev->ring->access.set_bpd(indio_dev->ring, size);
-	}
-
-	return 0;
-}
-
 void adis16350_unconfigure_ring(struct iio_dev *indio_dev)
 {
 	kfree(indio_dev->pollfunc);
@@ -229,7 +203,8 @@ int adis16350_configure_ring(struct iio_dev *indio_dev)
 	indio_dev->ring = ring;
 	/* Effectively select the ring buffer implementation */
 	iio_ring_sw_register_funcs(&ring->access);
-	ring->preenable = &adis16350_data_rdy_ring_preenable;
+	ring->bpe = 2;
+	ring->preenable = &iio_sw_ring_preenable;
 	ring->postenable = &iio_triggered_ring_postenable;
 	ring->predisable = &iio_triggered_ring_predisable;
 	ring->owner = THIS_MODULE;
diff --git a/drivers/staging/iio/imu/adis16400_ring.c b/drivers/staging/iio/imu/adis16400_ring.c
index c7744ef..949db76 100644
--- a/drivers/staging/iio/imu/adis16400_ring.c
+++ b/drivers/staging/iio/imu/adis16400_ring.c
@@ -174,29 +174,6 @@ static void adis16400_trigger_bh_to_ring(struct work_struct *work_s)
 
 	return;
 }
-/* in these circumstances is it better to go with unaligned packing and
- * deal with the cost?*/
-static int adis16400_data_rdy_ring_preenable(struct iio_dev *indio_dev)
-{
-	size_t size;
-	dev_dbg(&indio_dev->dev, "%s\n", __func__);
-	/* Check if there are any scan elements enabled, if not fail*/
-	if (!(indio_dev->scan_count || indio_dev->scan_timestamp))
-		return -EINVAL;
-
-	if (indio_dev->ring->access.set_bpd) {
-		if (indio_dev->scan_timestamp)
-			if (indio_dev->scan_count) /* Timestamp and data */
-				size = 6*sizeof(s64);
-			else /* Timestamp only  */
-				size = sizeof(s64);
-		else /* Data only */
-			size = indio_dev->scan_count*sizeof(s16);
-		indio_dev->ring->access.set_bpd(indio_dev->ring, size);
-	}
-
-	return 0;
-}
 
 void adis16400_unconfigure_ring(struct iio_dev *indio_dev)
 {
@@ -236,7 +213,8 @@ int adis16400_configure_ring(struct iio_dev *indio_dev)
 	indio_dev->ring = ring;
 	/* Effectively select the ring buffer implementation */
 	iio_ring_sw_register_funcs(&ring->access);
-	ring->preenable = &adis16400_data_rdy_ring_preenable;
+	ring->bpe = 2;
+	ring->preenable = &iio_sw_ring_preenable;
 	ring->postenable = &iio_triggered_ring_postenable;
 	ring->predisable = &iio_triggered_ring_predisable;
 	ring->owner = THIS_MODULE;
-- 
1.7.0.4

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

* [PATCH 3/5] staging:iio: Add iio_sw_ring_helper_state and functions to cover common case.
  2010-06-30 14:27 [RFC PATCH 0/5] Refactoring of ring buffer elements of Barry's recent RFC Jonathan Cameron
  2010-06-30 14:27 ` [PATCH 1/5] staging:iio: Add a bits per element element to ring_generic allowing a general ring_sw_preenable_function Jonathan Cameron
  2010-06-30 14:27 ` [PATCH 2/5] staging:iio: Make extensive use of iio_sw_ring_preenable Jonathan Cameron
@ 2010-06-30 14:27 ` Jonathan Cameron
  2010-07-08  9:28   ` Barry Song
  2010-06-30 14:27 ` [PATCH 4/5] staging:iio:lis3l02dq use iio_sw_ring_helper_state and funcs Jonathan Cameron
  2010-06-30 14:27 ` [PATCH 5/5] staging:iio:adis16209 " Jonathan Cameron
  4 siblings, 1 reply; 9+ messages in thread
From: Jonathan Cameron @ 2010-06-30 14:27 UTC (permalink / raw)
  To: linux-iio; +Cc: barry.song, Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/ring_sw.c |   43 +++++++++++++++++++++++++++++++++++++++++
 drivers/staging/iio/ring_sw.h |   10 +++++++++
 2 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/drivers/staging/iio/ring_sw.c b/drivers/staging/iio/ring_sw.c
index ca0e79e..293df5c 100644
--- a/drivers/staging/iio/ring_sw.c
+++ b/drivers/staging/iio/ring_sw.c
@@ -13,6 +13,7 @@
 #include <linux/device.h>
 #include <linux/workqueue.h>
 #include "ring_sw.h"
+#include "trigger.h"
 
 static inline int __iio_allocate_sw_ring_buffer(struct iio_sw_ring_buffer *ring,
 						int bytes_per_datum, int length)
@@ -456,5 +457,47 @@ int iio_sw_ring_preenable(struct iio_dev *indio_dev)
 }
 EXPORT_SYMBOL(iio_sw_ring_preenable);
 
+void iio_sw_trigger_bh_to_ring(struct work_struct *work_s)
+{
+	struct iio_sw_ring_helper_state *st
+		= container_of(work_s, struct iio_sw_ring_helper_state,
+			work_trigger_to_ring);
+	int len = 0;
+	size_t datasize = st->indio_dev
+		->ring->access.get_bpd(st->indio_dev->ring);
+	char *data = kmalloc(datasize, GFP_KERNEL);
+	
+	if (data == NULL) {
+		dev_err(st->indio_dev->dev.parent,
+			"memory alloc failed in ring bh");
+		return;
+	}
+
+	if (st->indio_dev->scan_count)
+		len = st->get_ring_element(st, data);
+	
+	  /* Guaranteed to be aligned with 8 byte boundary */
+	if (st->indio_dev->scan_timestamp)
+		*(s64 *)(((u32)data + len + sizeof(s64) - 1) & ~(sizeof(s64) - 1))
+			= st->last_timestamp;
+	  st->indio_dev->ring->access.store_to(st->indio_dev->ring,
+					(u8 *)data,
+			st->last_timestamp);
+
+	iio_trigger_notify_done(st->indio_dev->trig);
+	kfree(data);
+
+	return;
+}
+EXPORT_SYMBOL(iio_sw_trigger_bh_to_ring);
+
+void iio_sw_poll_func_th(struct iio_dev *indio_dev, s64 time)
+{	struct iio_sw_ring_helper_state *h
+		= iio_dev_get_devdata(indio_dev);
+	h->last_timestamp = time;
+	schedule_work(&h->work_trigger_to_ring);
+}
+EXPORT_SYMBOL(iio_sw_poll_func_th);
+
 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 5c22936..59c99c0 100644
--- a/drivers/staging/iio/ring_sw.h
+++ b/drivers/staging/iio/ring_sw.h
@@ -209,6 +209,16 @@ void iio_sw_rb_free(struct iio_ring_buffer *ring);
 
 int iio_sw_ring_preenable(struct iio_dev *indio_dev);
 
+struct iio_sw_ring_helper_state {
+	struct work_struct		work_trigger_to_ring;
+	struct iio_dev			*indio_dev;
+	int (*get_ring_element)(struct iio_sw_ring_helper_state *st, u8 *buf);
+	s64 				last_timestamp;
+};
+
+void iio_sw_poll_func_th(struct iio_dev *indio_dev, s64 time);
+void iio_sw_trigger_bh_to_ring(struct work_struct *work_s);
+
 #else /* CONFIG_IIO_RING_BUFFER*/
 static inline void iio_ring_sw_register_funcs(struct iio_ring_access_funcs *ra)
 {};
-- 
1.7.0.4

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

* [PATCH 4/5] staging:iio:lis3l02dq use iio_sw_ring_helper_state and funcs
  2010-06-30 14:27 [RFC PATCH 0/5] Refactoring of ring buffer elements of Barry's recent RFC Jonathan Cameron
                   ` (2 preceding siblings ...)
  2010-06-30 14:27 ` [PATCH 3/5] staging:iio: Add iio_sw_ring_helper_state and functions to cover common case Jonathan Cameron
@ 2010-06-30 14:27 ` Jonathan Cameron
  2010-06-30 15:16   ` Jonathan Cameron
  2010-06-30 14:27 ` [PATCH 5/5] staging:iio:adis16209 " Jonathan Cameron
  4 siblings, 1 reply; 9+ messages in thread
From: Jonathan Cameron @ 2010-06-30 14:27 UTC (permalink / raw)
  To: linux-iio; +Cc: barry.song, Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/accel/lis3l02dq.h      |   11 +--
 drivers/staging/iio/accel/lis3l02dq_core.c |  116 ++++++++++++++-----------
 drivers/staging/iio/accel/lis3l02dq_ring.c |  131 +++++++++-------------------
 3 files changed, 113 insertions(+), 145 deletions(-)

diff --git a/drivers/staging/iio/accel/lis3l02dq.h b/drivers/staging/iio/accel/lis3l02dq.h
index 6de172e..44669ee 100644
--- a/drivers/staging/iio/accel/lis3l02dq.h
+++ b/drivers/staging/iio/accel/lis3l02dq.h
@@ -148,30 +148,29 @@ Form of high byte dependant on justification set in ctrl reg */
 #define LIS3L02DQ_MAX_RX 12
 /**
  * struct lis3l02dq_state - device instance specific data
+ * @helper:		data and func pointer allowing generic functions
  * @us:			actual spi_device
- * @work_trigger_to_ring: bh for triggered event handling
  * @work_thresh:	bh for threshold events
  * @inter:		used to check if new interrupt has been triggered
- * @last_timestamp:	passing timestamp from th to bh of interrupt handler
- * @indio_dev:		industrial I/O device structure
  * @trig:		data ready trigger registered with iio
  * @tx:			transmit buffer
  * @rx:			recieve buffer
  * @buf_lock:		mutex to protect tx and rx
  **/
 struct lis3l02dq_state {
+	struct iio_sw_ring_helper_state	help;
 	struct spi_device		*us;
-	struct work_struct		work_trigger_to_ring;
 	struct work_struct		work_thresh;
 	bool				inter;
-	s64				last_timestamp;
-	struct iio_dev			*indio_dev;
 	struct iio_trigger		*trig;
 	u8				*tx;
 	u8				*rx;
 	struct mutex			buf_lock;
 };
 
+#define lis3l02dq_h_to_s(_h)				\
+	container_of(_h, struct lis3l02dq_state, help)
+
 int lis3l02dq_spi_read_reg_8(struct device *dev,
 			     u8 reg_address,
 			     u8 *val);
diff --git a/drivers/staging/iio/accel/lis3l02dq_core.c b/drivers/staging/iio/accel/lis3l02dq_core.c
index f86ffb8..2ce8d11 100644
--- a/drivers/staging/iio/accel/lis3l02dq_core.c
+++ b/drivers/staging/iio/accel/lis3l02dq_core.c
@@ -28,6 +28,8 @@
 #include "../iio.h"
 #include "../sysfs.h"
 #include "../ring_generic.h"
+#include "../ring_sw.h"
+
 #include "accel.h"
 
 #include "lis3l02dq.h"
@@ -48,7 +50,9 @@ int lis3l02dq_spi_read_reg_8(struct device *dev, u8 reg_address, u8 *val)
 	int ret;
 	struct spi_message msg;
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-	struct lis3l02dq_state *st = iio_dev_get_devdata(indio_dev);
+	struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev); 
+	struct lis3l02dq_state *st = lis3l02dq_h_to_s(h);
+
 	struct spi_transfer xfer = {
 		.tx_buf = st->tx,
 		.rx_buf = st->rx,
@@ -83,7 +87,9 @@ int lis3l02dq_spi_write_reg_8(struct device *dev,
 	int ret;
 	struct spi_message msg;
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-	struct lis3l02dq_state *st = iio_dev_get_devdata(indio_dev);
+	struct iio_sw_ring_helper_state *h
+		= iio_dev_get_devdata(indio_dev);
+	struct lis3l02dq_state *st = lis3l02dq_h_to_s(h);
 	struct spi_transfer xfer = {
 		.tx_buf = st->tx,
 		.bits_per_word = 8,
@@ -117,7 +123,9 @@ static int lis3l02dq_spi_write_reg_s16(struct device *dev,
 	int ret;
 	struct spi_message msg;
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-	struct lis3l02dq_state *st = iio_dev_get_devdata(indio_dev);
+	struct iio_sw_ring_helper_state *h
+		= iio_dev_get_devdata(indio_dev);
+	struct lis3l02dq_state *st = lis3l02dq_h_to_s(h);
 	struct spi_transfer xfers[] = { {
 			.tx_buf = st->tx,
 			.bits_per_word = 8,
@@ -159,7 +167,9 @@ static int lis3l02dq_spi_read_reg_s16(struct device *dev,
 {
 	struct spi_message msg;
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-	struct lis3l02dq_state *st = iio_dev_get_devdata(indio_dev);
+	struct iio_sw_ring_helper_state *h
+		= iio_dev_get_devdata(indio_dev);
+	struct lis3l02dq_state *st = lis3l02dq_h_to_s(h);
 	int ret;
 	struct spi_transfer xfers[] = { {
 			.tx_buf = st->tx,
@@ -412,7 +422,7 @@ static int lis3l02dq_initial_setup(struct lis3l02dq_state *st)
 
 	val = LIS3L02DQ_DEFAULT_CTRL1;
 	/* Write suitable defaults to ctrl1 */
-	ret = lis3l02dq_spi_write_reg_8(&st->indio_dev->dev,
+	ret = lis3l02dq_spi_write_reg_8(&st->help.indio_dev->dev,
 					LIS3L02DQ_REG_CTRL_1_ADDR,
 					&val);
 	if (ret) {
@@ -420,7 +430,7 @@ static int lis3l02dq_initial_setup(struct lis3l02dq_state *st)
 		goto err_ret;
 	}
 	/* Repeat as sometimes doesn't work first time?*/
-	ret = lis3l02dq_spi_write_reg_8(&st->indio_dev->dev,
+	ret = lis3l02dq_spi_write_reg_8(&st->help.indio_dev->dev,
 					LIS3L02DQ_REG_CTRL_1_ADDR,
 					&val);
 	if (ret) {
@@ -430,17 +440,17 @@ static int lis3l02dq_initial_setup(struct lis3l02dq_state *st)
 
 	/* Read back to check this has worked acts as loose test of correct
 	 * chip */
-	ret = lis3l02dq_spi_read_reg_8(&st->indio_dev->dev,
+	ret = lis3l02dq_spi_read_reg_8(&st->help.indio_dev->dev,
 				       LIS3L02DQ_REG_CTRL_1_ADDR,
 				       &valtest);
 	if (ret || (valtest != val)) {
-		dev_err(&st->indio_dev->dev, "device not playing ball");
+		dev_err(&st->help.indio_dev->dev, "device not playing ball");
 		ret = -EINVAL;
 		goto err_ret;
 	}
 
 	val = LIS3L02DQ_DEFAULT_CTRL2;
-	ret = lis3l02dq_spi_write_reg_8(&st->indio_dev->dev,
+	ret = lis3l02dq_spi_write_reg_8(&st->help.indio_dev->dev,
 					LIS3L02DQ_REG_CTRL_2_ADDR,
 					&val);
 	if (ret) {
@@ -449,7 +459,7 @@ static int lis3l02dq_initial_setup(struct lis3l02dq_state *st)
 	}
 
 	val = LIS3L02DQ_REG_WAKE_UP_CFG_LATCH_SRC;
-	ret = lis3l02dq_spi_write_reg_8(&st->indio_dev->dev,
+	ret = lis3l02dq_spi_write_reg_8(&st->help.indio_dev->dev,
 					LIS3L02DQ_REG_WAKE_UP_CFG_ADDR,
 					&val);
 	if (ret)
@@ -595,15 +605,17 @@ error_mutex_unlock:
 }
 
 
-static int lis3l02dq_thresh_handler_th(struct iio_dev *dev_info,
+static int lis3l02dq_thresh_handler_th(struct iio_dev *indio_dev,
 				       int index,
 				       s64 timestamp,
 				       int no_test)
 {
-	struct lis3l02dq_state *st = dev_info->dev_data;
+	struct iio_sw_ring_helper_state *h
+		= iio_dev_get_devdata(indio_dev);
+	struct lis3l02dq_state *st = lis3l02dq_h_to_s(h);
 
 	/* Stash the timestamp somewhere convenient for the bh */
-	st->last_timestamp = timestamp;
+	h->last_timestamp = timestamp;
 	schedule_work(&st->work_thresh);
 
 	return 0;
@@ -621,43 +633,43 @@ static void lis3l02dq_thresh_handler_bh_no_check(struct work_struct *work_s)
 
 	u8 t;
 
-	lis3l02dq_spi_read_reg_8(&st->indio_dev->dev,
+	lis3l02dq_spi_read_reg_8(&st->help.indio_dev->dev,
 				 LIS3L02DQ_REG_WAKE_UP_SRC_ADDR,
 				 &t);
 
 	if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_Z_HIGH)
-		iio_push_event(st->indio_dev, 0,
+		iio_push_event(st->help.indio_dev, 0,
 			       IIO_EVENT_CODE_ACCEL_Z_HIGH,
-			       st->last_timestamp);
+			       st->help.last_timestamp);
 
 	if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_Z_LOW)
-		iio_push_event(st->indio_dev, 0,
+		iio_push_event(st->help.indio_dev, 0,
 			       IIO_EVENT_CODE_ACCEL_Z_LOW,
-			       st->last_timestamp);
+			       st->help.last_timestamp);
 
 	if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_Y_HIGH)
-		iio_push_event(st->indio_dev, 0,
+		iio_push_event(st->help.indio_dev, 0,
 			       IIO_EVENT_CODE_ACCEL_Y_HIGH,
-			       st->last_timestamp);
+			       st->help.last_timestamp);
 
 	if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_Y_LOW)
-		iio_push_event(st->indio_dev, 0,
+		iio_push_event(st->help.indio_dev, 0,
 			       IIO_EVENT_CODE_ACCEL_Y_LOW,
-			       st->last_timestamp);
+			       st->help.last_timestamp);
 
 	if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_X_HIGH)
-		iio_push_event(st->indio_dev, 0,
+		iio_push_event(st->help.indio_dev, 0,
 			       IIO_EVENT_CODE_ACCEL_X_HIGH,
-			       st->last_timestamp);
+			       st->help.last_timestamp);
 
 	if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_X_LOW)
-		iio_push_event(st->indio_dev, 0,
+		iio_push_event(st->help.indio_dev, 0,
 			       IIO_EVENT_CODE_ACCEL_X_LOW,
-			       st->last_timestamp);
+			       st->help.last_timestamp);
 	/* reenable the irq */
 	enable_irq(st->us->irq);
 	/* Ack and allow for new interrupts */
-	lis3l02dq_spi_read_reg_8(&st->indio_dev->dev,
+	lis3l02dq_spi_read_reg_8(&st->help.indio_dev->dev,
 				 LIS3L02DQ_REG_WAKE_UP_ACK_ADDR,
 				 &t);
 
@@ -769,30 +781,30 @@ static int __devinit lis3l02dq_probe(struct spi_device *spi)
 	st->us = spi;
 	mutex_init(&st->buf_lock);
 	/* setup the industrialio driver allocated elements */
-	st->indio_dev = iio_allocate_device();
-	if (st->indio_dev == NULL) {
+	st->help.indio_dev = iio_allocate_device();
+	if (st->help.indio_dev == NULL) {
 		ret = -ENOMEM;
 		goto error_free_tx;
 	}
 
-	st->indio_dev->dev.parent = &spi->dev;
-	st->indio_dev->num_interrupt_lines = 1;
-	st->indio_dev->event_attrs = &lis3l02dq_event_attribute_group;
-	st->indio_dev->attrs = &lis3l02dq_attribute_group;
-	st->indio_dev->dev_data = (void *)(st);
-	st->indio_dev->driver_module = THIS_MODULE;
-	st->indio_dev->modes = INDIO_DIRECT_MODE;
+	st->help.indio_dev->dev.parent = &spi->dev;
+	st->help.indio_dev->num_interrupt_lines = 1;
+	st->help.indio_dev->event_attrs = &lis3l02dq_event_attribute_group;
+	st->help.indio_dev->attrs = &lis3l02dq_attribute_group;
+	st->help.indio_dev->dev_data = (void *)(&st->help);
+	st->help.indio_dev->driver_module = THIS_MODULE;
+	st->help.indio_dev->modes = INDIO_DIRECT_MODE;
 
-	ret = lis3l02dq_configure_ring(st->indio_dev);
+	ret = lis3l02dq_configure_ring(st->help.indio_dev);
 	if (ret)
 		goto error_free_dev;
 
-	ret = iio_device_register(st->indio_dev);
+	ret = iio_device_register(st->help.indio_dev);
 	if (ret)
 		goto error_unreg_ring_funcs;
 	regdone = 1;
 
-	ret = iio_ring_buffer_register(st->indio_dev->ring, 0);
+	ret = iio_ring_buffer_register(st->help.indio_dev->ring, 0);
 	if (ret) {
 		printk(KERN_ERR "failed to initialize the ring\n");
 		goto error_unreg_ring_funcs;
@@ -801,14 +813,14 @@ static int __devinit lis3l02dq_probe(struct spi_device *spi)
 	if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0) {
 		st->inter = 0;
 		ret = iio_register_interrupt_line(spi->irq,
-						  st->indio_dev,
+						  st->help.indio_dev,
 						  0,
 						  IRQF_TRIGGER_RISING,
 						  "lis3l02dq");
 		if (ret)
 			goto error_uninitialize_ring;
 
-		ret = lis3l02dq_probe_trigger(st->indio_dev);
+		ret = lis3l02dq_probe_trigger(st->help.indio_dev);
 		if (ret)
 			goto error_unregister_line;
 	}
@@ -820,20 +832,20 @@ static int __devinit lis3l02dq_probe(struct spi_device *spi)
 	return 0;
 
 error_remove_trigger:
-	if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
-		lis3l02dq_remove_trigger(st->indio_dev);
+	if (st->help.indio_dev->modes & INDIO_RING_TRIGGERED)
+		lis3l02dq_remove_trigger(st->help.indio_dev);
 error_unregister_line:
-	if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
-		iio_unregister_interrupt_line(st->indio_dev, 0);
+	if (st->help.indio_dev->modes & INDIO_RING_TRIGGERED)
+		iio_unregister_interrupt_line(st->help.indio_dev, 0);
 error_uninitialize_ring:
-	iio_ring_buffer_unregister(st->indio_dev->ring);
+	iio_ring_buffer_unregister(st->help.indio_dev->ring);
 error_unreg_ring_funcs:
-	lis3l02dq_unconfigure_ring(st->indio_dev);
+	lis3l02dq_unconfigure_ring(st->help.indio_dev);
 error_free_dev:
 	if (regdone)
-		iio_device_unregister(st->indio_dev);
+		iio_device_unregister(st->help.indio_dev);
 	else
-		iio_free_device(st->indio_dev);
+		iio_free_device(st->help.indio_dev);
 error_free_tx:
 	kfree(st->tx);
 error_free_rx:
@@ -848,7 +860,9 @@ error_ret:
 static int lis3l02dq_stop_device(struct iio_dev *indio_dev)
 {
 	int ret;
-	struct lis3l02dq_state *st = indio_dev->dev_data;
+	struct iio_sw_ring_helper_state *h
+		= iio_dev_get_devdata(indio_dev);
+	struct lis3l02dq_state *st = lis3l02dq_h_to_s(h);
 	u8 val = 0;
 
 	mutex_lock(&indio_dev->mlock);
@@ -875,7 +889,7 @@ static int lis3l02dq_remove(struct spi_device *spi)
 {
 	int ret;
 	struct lis3l02dq_state *st = spi_get_drvdata(spi);
-	struct iio_dev *indio_dev = st->indio_dev;
+	struct iio_dev *indio_dev = st->help.indio_dev;
 
 	ret = lis3l02dq_stop_device(indio_dev);
 	if (ret)
diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c
index 2c11209..48e0f21 100644
--- a/drivers/staging/iio/accel/lis3l02dq_ring.c
+++ b/drivers/staging/iio/accel/lis3l02dq_ring.c
@@ -105,11 +105,13 @@ static struct attribute_group lis3l02dq_scan_el_group = {
  **/
 static void lis3l02dq_poll_func_th(struct iio_dev *indio_dev, s64 time)
 {
-	struct lis3l02dq_state *st = iio_dev_get_devdata(indio_dev);
-	st->last_timestamp = time;
-	schedule_work(&st->work_trigger_to_ring);
-	/* Indicate that this interrupt is being handled */
+	struct iio_sw_ring_helper_state *h
+		= iio_dev_get_devdata(indio_dev);
+	struct lis3l02dq_state *st = lis3l02dq_h_to_s(h);
+	/* in this case we need to slightly extend the helper function */
+	iio_sw_poll_func_th(indio_dev, time);
 
+	/* Indicate that this interrupt is being handled */
 	/* Technically this is trigger related, but without this
 	 * handler running there is currently now way for the interrupt
 	 * to clear.
@@ -120,15 +122,16 @@ static void lis3l02dq_poll_func_th(struct iio_dev *indio_dev, s64 time)
 /**
  * lis3l02dq_data_rdy_trig_poll() the event handler for the data rdy trig
  **/
-static int lis3l02dq_data_rdy_trig_poll(struct iio_dev *dev_info,
+static int lis3l02dq_data_rdy_trig_poll(struct iio_dev *indio_dev,
 				       int index,
 				       s64 timestamp,
 				       int no_test)
 {
-	struct lis3l02dq_state *st = iio_dev_get_devdata(dev_info);
-	struct iio_trigger *trig = st->trig;
+	struct iio_sw_ring_helper_state *h
+		= iio_dev_get_devdata(indio_dev);
+	struct lis3l02dq_state *st = lis3l02dq_h_to_s(h);
 
-	iio_trigger_poll(trig, timestamp);
+	iio_trigger_poll(st->trig, timestamp);
 
 	return IRQ_HANDLED;
 }
@@ -212,7 +215,7 @@ static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array)
 	struct spi_message msg;
 	int ret, i, j = 0;
 
-	xfers = kzalloc((st->indio_dev->scan_count) * 2
+	xfers = kzalloc((st->help.indio_dev->scan_count) * 2
 			* sizeof(*xfers), GFP_KERNEL);
 	if (!xfers)
 		return -ENOMEM;
@@ -220,7 +223,7 @@ static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array)
 	mutex_lock(&st->buf_lock);
 
 	for (i = 0; i < ARRAY_SIZE(read_all_tx_array)/4; i++) {
-		if (st->indio_dev->scan_mask & (1 << i)) {
+		if (st->help.indio_dev->scan_mask & (1 << i)) {
 			/* lower byte */
 			xfers[j].tx_buf = st->tx + 2*j;
 			st->tx[2*j] = read_all_tx_array[i*4];
@@ -248,7 +251,7 @@ static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array)
 	 * values in alternate bytes
 	 */
 	spi_message_init(&msg);
-	for (j = 0; j < st->indio_dev->scan_count * 2; j++)
+	for (j = 0; j < st->help.indio_dev->scan_count * 2; j++)
 		spi_message_add_tail(&xfers[j], &msg);
 
 	ret = spi_sync(st->us, &msg);
@@ -258,62 +261,19 @@ static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array)
 	return ret;
 }
 
-
-/* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device
- * specific to be rolled into the core.
- */
-static void lis3l02dq_trigger_bh_to_ring(struct work_struct *work_s)
-{
-	struct lis3l02dq_state *st
-		= container_of(work_s, struct lis3l02dq_state,
-			       work_trigger_to_ring);
-
-	u8 *rx_array;
-	int i = 0;
-	u16 *data;
-	size_t datasize = st->indio_dev
-		->ring->access.get_bpd(st->indio_dev->ring);
-
-	data = kmalloc(datasize , GFP_KERNEL);
-	if (data == NULL) {
-		dev_err(&st->us->dev, "memory alloc failed in ring bh");
-		return;
-	}
-	/* Due to interleaved nature of transmission this buffer must be
-	 * twice the number of bytes, or 4 times the number of channels
-	 */
-	rx_array = kmalloc(4 * (st->indio_dev->scan_count), GFP_KERNEL);
-	if (rx_array == NULL) {
-		dev_err(&st->us->dev, "memory alloc failed in ring bh");
-		kfree(data);
-		return;
+static int lis3l02dq_get_ring_element(struct iio_sw_ring_helper_state *h,
+				u8 *buf) {
+	int ret, i;
+	u8 *rx_array = NULL;
+	ret = lis3l02dq_read_all(lis3l02dq_h_to_s(h), rx_array);
+	if (ret > 0) {
+		for (i = 0; i < h->indio_dev->scan_count; i++)
+			buf[i] = combine_8_to_16(rx_array[i*4+1],
+						rx_array[i*4+3]);
+		kfree(rx_array);
+		return 0;
 	}
-
-	/* whilst trigger specific, if this read does nto occur the data
-	   ready interrupt will not be cleared.  Need to add a mechanism
-	   to provide a dummy read function if this is not triggering on
-	   the data ready function but something else is.
-	*/
-	st->inter = 0;
-
-	if (st->indio_dev->scan_count)
-		if (lis3l02dq_read_all(st, rx_array) >= 0)
-			for (; i < st->indio_dev->scan_count; i++)
-				data[i] = combine_8_to_16(rx_array[i*4+1],
-							  rx_array[i*4+3]);
-	/* Guaranteed to be aligned with 8 byte boundary */
-	if (st->indio_dev->scan_timestamp)
-		*((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp;
-
-	st->indio_dev->ring->access.store_to(st->indio_dev->ring,
-					    (u8 *)data,
-					    st->last_timestamp);
-
-	iio_trigger_notify_done(st->indio_dev->trig);
-	kfree(rx_array);
-	kfree(data);
-
-	return;
+	return ret;
 }
 
 /* Caller responsible for locking as necessary. */
@@ -387,7 +347,7 @@ static int lis3l02dq_data_rdy_trigger_set_state(struct iio_trigger *trig,
 	struct lis3l02dq_state *st = trig->private_data;
 	int ret = 0;
 	u8 t;
-	__lis3l02dq_write_data_ready_config(&st->indio_dev->dev,
+	__lis3l02dq_write_data_ready_config(&st->help.indio_dev->dev,
 					    &iio_event_data_rdy_trig,
 					    state);
 	if (state == false) {
@@ -397,7 +357,7 @@ static int lis3l02dq_data_rdy_trigger_set_state(struct iio_trigger *trig,
 		/* Clear any outstanding ready events */
 		ret = lis3l02dq_read_all(st, NULL);
 	}
-	lis3l02dq_spi_read_reg_8(&st->indio_dev->dev,
+	lis3l02dq_spi_read_reg_8(&st->help.indio_dev->dev,
 				 LIS3L02DQ_REG_WAKE_UP_SRC_ADDR,
 				 &t);
 	return ret;
@@ -500,12 +460,12 @@ void lis3l02dq_unconfigure_ring(struct iio_dev *indio_dev)
 
 int lis3l02dq_configure_ring(struct iio_dev *indio_dev)
 {
-	int ret = 0;
-	struct lis3l02dq_state *st = indio_dev->dev_data;
-	struct iio_ring_buffer *ring;
-	INIT_WORK(&st->work_trigger_to_ring, lis3l02dq_trigger_bh_to_ring);
+	int ret;
+	struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev);
+	
+	INIT_WORK(&h->work_trigger_to_ring, iio_sw_trigger_bh_to_ring);
 	/* Set default scan mode */
-
+	h->get_ring_element = &lis3l02dq_get_ring_element;
 	iio_scan_mask_set(indio_dev, iio_scan_el_accel_x.number);
 	iio_scan_mask_set(indio_dev, iio_scan_el_accel_y.number);
 	iio_scan_mask_set(indio_dev, iio_scan_el_accel_z.number);
@@ -513,19 +473,17 @@ int lis3l02dq_configure_ring(struct iio_dev *indio_dev)
 
 	indio_dev->scan_el_attrs = &lis3l02dq_scan_el_group;
 
-	ring = iio_sw_rb_allocate(indio_dev);
-	if (!ring) {
-		ret = -ENOMEM;
-		return ret;
-	}
-	indio_dev->ring = ring;
+	indio_dev->ring = iio_sw_rb_allocate(indio_dev);
+	if (!indio_dev->ring)
+		return -ENOMEM;
+
 	/* Effectively select the ring buffer implementation */
-	iio_ring_sw_register_funcs(&ring->access);
-	ring->bpe = 2;
-	ring->preenable = &iio_sw_ring_preenable;
-	ring->postenable = &iio_triggered_ring_postenable;
-	ring->predisable = &iio_triggered_ring_predisable;
-	ring->owner = THIS_MODULE;
+	iio_ring_sw_register_funcs(&indio_dev->ring->access);
+	indio_dev->ring->bpe = 2;
+	indio_dev->ring->preenable = &iio_sw_ring_preenable;
+	indio_dev->ring->postenable = &iio_triggered_ring_postenable;
+	indio_dev->ring->predisable = &iio_triggered_ring_predisable;
+	indio_dev->ring->owner = THIS_MODULE;
 
 	ret = iio_alloc_pollfunc(indio_dev, NULL, &lis3l02dq_poll_func_th);
 	if (ret)
@@ -537,6 +495,3 @@ error_iio_sw_rb_free:
 	iio_sw_rb_free(indio_dev->ring);
 	return ret;
 }
-
-
-
-- 
1.7.0.4

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

* [PATCH 5/5]  staging:iio:adis16209 use iio_sw_ring_helper_state and funcs
  2010-06-30 14:27 [RFC PATCH 0/5] Refactoring of ring buffer elements of Barry's recent RFC Jonathan Cameron
                   ` (3 preceding siblings ...)
  2010-06-30 14:27 ` [PATCH 4/5] staging:iio:lis3l02dq use iio_sw_ring_helper_state and funcs Jonathan Cameron
@ 2010-06-30 14:27 ` Jonathan Cameron
  4 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2010-06-30 14:27 UTC (permalink / raw)
  To: linux-iio; +Cc: barry.song, Jonathan Cameron

 Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
---
 drivers/staging/iio/accel/adis16209.h         |    7 ++-
 drivers/staging/iio/accel/adis16209_core.c    |   54 +++++++++++---------
 drivers/staging/iio/accel/adis16209_ring.c    |   66 ++++++-------------------
 drivers/staging/iio/accel/adis16209_trigger.c |    8 ++-
 4 files changed, 53 insertions(+), 82 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16209.h b/drivers/staging/iio/accel/adis16209.h
index 92daf6f..84e1a2f 100644
--- a/drivers/staging/iio/accel/adis16209.h
+++ b/drivers/staging/iio/accel/adis16209.h
@@ -113,16 +113,17 @@
  * @buf_lock:		mutex to protect tx and rx
  **/
 struct adis16209_state {
+	struct iio_sw_ring_helper_state help;
 	struct spi_device		*us;
-	struct work_struct		work_trigger_to_ring;
-	s64				last_timestamp;
-	struct iio_dev			*indio_dev;
 	struct iio_trigger		*trig;
 	u8				*tx;
 	u8				*rx;
 	struct mutex			buf_lock;
 };
 
+#define adis16209_h_to_s(_h)				\
+	container_of(_h, struct adis16209_state, help)
+
 int adis16209_set_irq(struct device *dev, bool enable);
 
 #ifdef CONFIG_IIO_RING_BUFFER
diff --git a/drivers/staging/iio/accel/adis16209_core.c b/drivers/staging/iio/accel/adis16209_core.c
index 6c6923f..9c7aafe 100644
--- a/drivers/staging/iio/accel/adis16209_core.c
+++ b/drivers/staging/iio/accel/adis16209_core.c
@@ -21,6 +21,7 @@
 #include "../iio.h"
 #include "../sysfs.h"
 #include "../ring_generic.h"
+#include "../ring_sw.h"
 #include "accel.h"
 #include "inclinometer.h"
 #include "../gyro/gyro.h"
@@ -44,7 +45,8 @@ static int adis16209_spi_write_reg_8(struct device *dev,
 {
 	int ret;
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-	struct adis16209_state *st = iio_dev_get_devdata(indio_dev);
+	struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev);
+	struct adis16209_state *st = adis16209_h_to_s(h);
 
 	mutex_lock(&st->buf_lock);
 	st->tx[0] = ADIS16209_WRITE_REG(reg_address);
@@ -70,7 +72,8 @@ static int adis16209_spi_write_reg_16(struct device *dev,
 	int ret;
 	struct spi_message msg;
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-	struct adis16209_state *st = iio_dev_get_devdata(indio_dev);
+	struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev);
+	struct adis16209_state *st = adis16209_h_to_s(h);
 	struct spi_transfer xfers[] = {
 		{
 			.tx_buf = st->tx,
@@ -115,7 +118,8 @@ static int adis16209_spi_read_reg_16(struct device *dev,
 {
 	struct spi_message msg;
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
-	struct adis16209_state *st = iio_dev_get_devdata(indio_dev);
+	struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev);
+	struct adis16209_state *st = adis16209_h_to_s(h);
 	int ret;
 	struct spi_transfer xfers[] = {
 		{
@@ -355,7 +359,7 @@ err_ret:
 static int adis16209_initial_setup(struct adis16209_state *st)
 {
 	int ret;
-	struct device *dev = &st->indio_dev->dev;
+	struct device *dev = &st->help.indio_dev->dev;
 
 	/* Disable IRQ */
 	ret = adis16209_set_irq(dev, false);
@@ -498,30 +502,30 @@ static int __devinit adis16209_probe(struct spi_device *spi)
 	st->us = spi;
 	mutex_init(&st->buf_lock);
 	/* setup the industrialio driver allocated elements */
-	st->indio_dev = iio_allocate_device();
-	if (st->indio_dev == NULL) {
+	st->help.indio_dev = iio_allocate_device();
+	if (st->help.indio_dev == NULL) {
 		ret = -ENOMEM;
 		goto error_free_tx;
 	}
 
-	st->indio_dev->dev.parent = &spi->dev;
-	st->indio_dev->num_interrupt_lines = 1;
-	st->indio_dev->event_attrs = &adis16209_event_attribute_group;
-	st->indio_dev->attrs = &adis16209_attribute_group;
-	st->indio_dev->dev_data = (void *)(st);
-	st->indio_dev->driver_module = THIS_MODULE;
-	st->indio_dev->modes = INDIO_DIRECT_MODE;
+	st->help.indio_dev->dev.parent = &spi->dev;
+	st->help.indio_dev->num_interrupt_lines = 1;
+	st->help.indio_dev->event_attrs = &adis16209_event_attribute_group;
+	st->help.indio_dev->attrs = &adis16209_attribute_group;
+	st->help.indio_dev->dev_data = (void *)(&st->help);
+	st->help.indio_dev->driver_module = THIS_MODULE;
+	st->help.indio_dev->modes = INDIO_DIRECT_MODE;
 
-	ret = adis16209_configure_ring(st->indio_dev);
+	ret = adis16209_configure_ring(st->help.indio_dev);
 	if (ret)
 		goto error_free_dev;
 
-	ret = iio_device_register(st->indio_dev);
+	ret = iio_device_register(st->help.indio_dev);
 	if (ret)
 		goto error_unreg_ring_funcs;
 	regdone = 1;
 
-	ret = iio_ring_buffer_register(st->indio_dev->ring, 0);
+	ret = iio_ring_buffer_register(st->help.indio_dev->ring, 0);
 	if (ret) {
 		printk(KERN_ERR "failed to initialize the ring\n");
 		goto error_unreg_ring_funcs;
@@ -529,14 +533,14 @@ static int __devinit adis16209_probe(struct spi_device *spi)
 
 	if (spi->irq) {
 		ret = iio_register_interrupt_line(spi->irq,
-				st->indio_dev,
+				st->help.indio_dev,
 				0,
 				IRQF_TRIGGER_RISING,
 				"adis16209");
 		if (ret)
 			goto error_uninitialize_ring;
 
-		ret = adis16209_probe_trigger(st->indio_dev);
+		ret = adis16209_probe_trigger(st->help.indio_dev);
 		if (ret)
 			goto error_unregister_line;
 	}
@@ -548,19 +552,19 @@ static int __devinit adis16209_probe(struct spi_device *spi)
 	return 0;
 
 error_remove_trigger:
-	adis16209_remove_trigger(st->indio_dev);
+	adis16209_remove_trigger(st->help.indio_dev);
 error_unregister_line:
 	if (spi->irq)
-		iio_unregister_interrupt_line(st->indio_dev, 0);
+		iio_unregister_interrupt_line(st->help.indio_dev, 0);
 error_uninitialize_ring:
-	iio_ring_buffer_unregister(st->indio_dev->ring);
+	iio_ring_buffer_unregister(st->help.indio_dev->ring);
 error_unreg_ring_funcs:
-	adis16209_unconfigure_ring(st->indio_dev);
+	adis16209_unconfigure_ring(st->help.indio_dev);
 error_free_dev:
 	if (regdone)
-		iio_device_unregister(st->indio_dev);
+		iio_device_unregister(st->help.indio_dev);
 	else
-		iio_free_device(st->indio_dev);
+		iio_free_device(st->help.indio_dev);
 error_free_tx:
 	kfree(st->tx);
 error_free_rx:
@@ -574,7 +578,7 @@ error_ret:
 static int adis16209_remove(struct spi_device *spi)
 {
 	struct adis16209_state *st = spi_get_drvdata(spi);
-	struct iio_dev *indio_dev = st->indio_dev;
+	struct iio_dev *indio_dev = st->help.indio_dev;
 
 	flush_scheduled_work();
 
diff --git a/drivers/staging/iio/accel/adis16209_ring.c b/drivers/staging/iio/accel/adis16209_ring.c
index 25fde65..34f8258 100644
--- a/drivers/staging/iio/accel/adis16209_ring.c
+++ b/drivers/staging/iio/accel/adis16209_ring.c
@@ -55,17 +55,6 @@ static struct attribute_group adis16209_scan_el_group = {
 };
 
 /**
- * adis16209_poll_func_th() top half interrupt handler called by trigger
- * @private_data:	iio_dev
- **/
-static void adis16209_poll_func_th(struct iio_dev *indio_dev, s64 time)
-{
-	struct adis16209_state *st = iio_dev_get_devdata(indio_dev);
-	st->last_timestamp = time;
-	schedule_work(&st->work_trigger_to_ring);
-}
-
-/**
  * adis16209_read_ring_data() read data registers which will be placed into ring
  * @dev: device associated with child of actual device (iio_dev or iio_trig)
  * @rx: somewhere to pass back the value read
@@ -107,44 +96,19 @@ static int adis16209_read_ring_data(struct device *dev, u8 *rx)
 	return ret;
 }
 
-/* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device
- * specific to be rolled into the core.
- */
-static void adis16209_trigger_bh_to_ring(struct work_struct *work_s)
+static int adis16209_get_ring_element(struct iio_sw_ring_helper_state *h,
+				u8 *buf)
 {
-	struct adis16209_state *st
-		= container_of(work_s, struct adis16209_state,
-			       work_trigger_to_ring);
-
-	int i = 0;
-	s16 *data;
-	size_t datasize = st->indio_dev
-		->ring->access.get_bpd(st->indio_dev->ring);
-
-	data = kmalloc(datasize , GFP_KERNEL);
-	if (data == NULL) {
-		dev_err(&st->us->dev, "memory alloc failed in ring bh");
-		return;
-	}
-
-	if (st->indio_dev->scan_count)
-		if (adis16209_read_ring_data(&st->indio_dev->dev, st->rx) >= 0)
-			for (; i < st->indio_dev->scan_count; i++)
-				data[i] = be16_to_cpup(
-					(__be16 *)&(st->rx[i*2]));
-
-	/* Guaranteed to be aligned with 8 byte boundary */
-	if (st->indio_dev->scan_timestamp)
-		*((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp;
-
-	st->indio_dev->ring->access.store_to(st->indio_dev->ring,
-					    (u8 *)data,
-					    st->last_timestamp);
-
-	iio_trigger_notify_done(st->indio_dev->trig);
-	kfree(data);
+	int i;
+	s16 *data = (s16 *)buf;
 
-	return;
+	struct adis16209_state *st = adis16209_h_to_s(h);
+	int ret = adis16209_read_ring_data(&h->indio_dev->dev, st->rx);
+	if (ret < 0)
+		return ret;
+	for (i = 0; i < h->indio_dev->scan_count; i++)
+		data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
+	return 0;
 }
 
 void adis16209_unconfigure_ring(struct iio_dev *indio_dev)
@@ -156,11 +120,11 @@ void adis16209_unconfigure_ring(struct iio_dev *indio_dev)
 int adis16209_configure_ring(struct iio_dev *indio_dev)
 {
 	int ret = 0;
-	struct adis16209_state *st = indio_dev->dev_data;
 	struct iio_ring_buffer *ring;
-	INIT_WORK(&st->work_trigger_to_ring, adis16209_trigger_bh_to_ring);
+	struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev);
+	INIT_WORK(&h->work_trigger_to_ring, iio_sw_trigger_bh_to_ring);
 	/* Set default scan mode */
-
+	h->get_ring_element = &adis16209_get_ring_element;
 	iio_scan_mask_set(indio_dev, iio_scan_el_supply.number);
 	iio_scan_mask_set(indio_dev, iio_scan_el_rot.number);
 	iio_scan_mask_set(indio_dev, iio_scan_el_accel_x.number);
@@ -187,7 +151,7 @@ int adis16209_configure_ring(struct iio_dev *indio_dev)
 	ring->predisable = &iio_triggered_ring_predisable;
 	ring->owner = THIS_MODULE;
 
-	ret = iio_alloc_pollfunc(indio_dev, NULL, &adis16209_poll_func_th);
+	ret = iio_alloc_pollfunc(indio_dev, NULL, &iio_sw_poll_func_th);
 	if (ret)
 		goto error_iio_sw_rb_free;
 
diff --git a/drivers/staging/iio/accel/adis16209_trigger.c b/drivers/staging/iio/accel/adis16209_trigger.c
index 1487eff..51cdf4a 100644
--- a/drivers/staging/iio/accel/adis16209_trigger.c
+++ b/drivers/staging/iio/accel/adis16209_trigger.c
@@ -10,6 +10,7 @@
 #include "../iio.h"
 #include "../sysfs.h"
 #include "../trigger.h"
+#include "../ring_sw.h"
 #include "adis16209.h"
 
 /**
@@ -48,11 +49,11 @@ static int adis16209_data_rdy_trigger_set_state(struct iio_trigger *trig,
 						bool state)
 {
 	struct adis16209_state *st = trig->private_data;
-	struct iio_dev *indio_dev = st->indio_dev;
+	struct iio_dev *indio_dev = st->help.indio_dev;
 	int ret = 0;
 
 	dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state);
-	ret = adis16209_set_irq(&st->indio_dev->dev, state);
+	ret = adis16209_set_irq(&indio_dev->dev, state);
 	if (state == false) {
 		iio_remove_event_from_list(&iio_event_data_rdy_trig,
 					   &indio_dev->interrupts[0]
@@ -79,7 +80,8 @@ static int adis16209_trig_try_reen(struct iio_trigger *trig)
 int adis16209_probe_trigger(struct iio_dev *indio_dev)
 {
 	int ret;
-	struct adis16209_state *st = indio_dev->dev_data;
+	struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev);
+	struct adis16209_state *st = adis16209_h_to_s(h);
 
 	st->trig = iio_allocate_trigger();
 	st->trig->name = kasprintf(GFP_KERNEL,
-- 
1.7.0.4

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

* Re: [PATCH 4/5] staging:iio:lis3l02dq use iio_sw_ring_helper_state and funcs
  2010-06-30 14:27 ` [PATCH 4/5] staging:iio:lis3l02dq use iio_sw_ring_helper_state and funcs Jonathan Cameron
@ 2010-06-30 15:16   ` Jonathan Cameron
  0 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2010-06-30 15:16 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, barry.song

On 06/30/10 15:27, Jonathan Cameron wrote:
> Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
> ---
>  drivers/staging/iio/accel/lis3l02dq.h      |   11 +--
>  drivers/staging/iio/accel/lis3l02dq_core.c |  116 ++++++++++++++-----------
>  drivers/staging/iio/accel/lis3l02dq_ring.c |  131 +++++++++-------------------
>  3 files changed, 113 insertions(+), 145 deletions(-)
> 
> diff --git a/drivers/staging/iio/accel/lis3l02dq.h b/drivers/staging/iio/accel/lis3l02dq.h
> index 6de172e..44669ee 100644
> --- a/drivers/staging/iio/accel/lis3l02dq.h
> +++ b/drivers/staging/iio/accel/lis3l02dq.h
> @@ -148,30 +148,29 @@ Form of high byte dependant on justification set in ctrl reg */
>  #define LIS3L02DQ_MAX_RX 12
>  /**
>   * struct lis3l02dq_state - device instance specific data
> + * @helper:		data and func pointer allowing generic functions
>   * @us:			actual spi_device
> - * @work_trigger_to_ring: bh for triggered event handling
>   * @work_thresh:	bh for threshold events
>   * @inter:		used to check if new interrupt has been triggered
> - * @last_timestamp:	passing timestamp from th to bh of interrupt handler
> - * @indio_dev:		industrial I/O device structure
>   * @trig:		data ready trigger registered with iio
>   * @tx:			transmit buffer
>   * @rx:			recieve buffer
>   * @buf_lock:		mutex to protect tx and rx
>   **/
>  struct lis3l02dq_state {
> +	struct iio_sw_ring_helper_state	help;
>  	struct spi_device		*us;
> -	struct work_struct		work_trigger_to_ring;
>  	struct work_struct		work_thresh;
>  	bool				inter;
> -	s64				last_timestamp;
> -	struct iio_dev			*indio_dev;
>  	struct iio_trigger		*trig;
>  	u8				*tx;
>  	u8				*rx;
>  	struct mutex			buf_lock;
>  };
>  
> +#define lis3l02dq_h_to_s(_h)				\
> +	container_of(_h, struct lis3l02dq_state, help)
> +
>  int lis3l02dq_spi_read_reg_8(struct device *dev,
>  			     u8 reg_address,
>  			     u8 *val);
> diff --git a/drivers/staging/iio/accel/lis3l02dq_core.c b/drivers/staging/iio/accel/lis3l02dq_core.c
> index f86ffb8..2ce8d11 100644
> --- a/drivers/staging/iio/accel/lis3l02dq_core.c
> +++ b/drivers/staging/iio/accel/lis3l02dq_core.c
> @@ -28,6 +28,8 @@
>  #include "../iio.h"
>  #include "../sysfs.h"
>  #include "../ring_generic.h"
> +#include "../ring_sw.h"
> +
>  #include "accel.h"
>  
>  #include "lis3l02dq.h"
> @@ -48,7 +50,9 @@ int lis3l02dq_spi_read_reg_8(struct device *dev, u8 reg_address, u8 *val)
>  	int ret;
>  	struct spi_message msg;
>  	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> -	struct lis3l02dq_state *st = iio_dev_get_devdata(indio_dev);
> +	struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev); 
> +	struct lis3l02dq_state *st = lis3l02dq_h_to_s(h);
> +
>  	struct spi_transfer xfer = {
>  		.tx_buf = st->tx,
>  		.rx_buf = st->rx,
> @@ -83,7 +87,9 @@ int lis3l02dq_spi_write_reg_8(struct device *dev,
>  	int ret;
>  	struct spi_message msg;
>  	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> -	struct lis3l02dq_state *st = iio_dev_get_devdata(indio_dev);
> +	struct iio_sw_ring_helper_state *h
> +		= iio_dev_get_devdata(indio_dev);
> +	struct lis3l02dq_state *st = lis3l02dq_h_to_s(h);
>  	struct spi_transfer xfer = {
>  		.tx_buf = st->tx,
>  		.bits_per_word = 8,
> @@ -117,7 +123,9 @@ static int lis3l02dq_spi_write_reg_s16(struct device *dev,
>  	int ret;
>  	struct spi_message msg;
>  	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> -	struct lis3l02dq_state *st = iio_dev_get_devdata(indio_dev);
> +	struct iio_sw_ring_helper_state *h
> +		= iio_dev_get_devdata(indio_dev);
> +	struct lis3l02dq_state *st = lis3l02dq_h_to_s(h);
>  	struct spi_transfer xfers[] = { {
>  			.tx_buf = st->tx,
>  			.bits_per_word = 8,
> @@ -159,7 +167,9 @@ static int lis3l02dq_spi_read_reg_s16(struct device *dev,
>  {
>  	struct spi_message msg;
>  	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> -	struct lis3l02dq_state *st = iio_dev_get_devdata(indio_dev);
> +	struct iio_sw_ring_helper_state *h
> +		= iio_dev_get_devdata(indio_dev);
> +	struct lis3l02dq_state *st = lis3l02dq_h_to_s(h);
>  	int ret;
>  	struct spi_transfer xfers[] = { {
>  			.tx_buf = st->tx,
> @@ -412,7 +422,7 @@ static int lis3l02dq_initial_setup(struct lis3l02dq_state *st)
>  
>  	val = LIS3L02DQ_DEFAULT_CTRL1;
>  	/* Write suitable defaults to ctrl1 */
> -	ret = lis3l02dq_spi_write_reg_8(&st->indio_dev->dev,
> +	ret = lis3l02dq_spi_write_reg_8(&st->help.indio_dev->dev,
>  					LIS3L02DQ_REG_CTRL_1_ADDR,
>  					&val);
>  	if (ret) {
> @@ -420,7 +430,7 @@ static int lis3l02dq_initial_setup(struct lis3l02dq_state *st)
>  		goto err_ret;
>  	}
>  	/* Repeat as sometimes doesn't work first time?*/
> -	ret = lis3l02dq_spi_write_reg_8(&st->indio_dev->dev,
> +	ret = lis3l02dq_spi_write_reg_8(&st->help.indio_dev->dev,
>  					LIS3L02DQ_REG_CTRL_1_ADDR,
>  					&val);
>  	if (ret) {
> @@ -430,17 +440,17 @@ static int lis3l02dq_initial_setup(struct lis3l02dq_state *st)
>  
>  	/* Read back to check this has worked acts as loose test of correct
>  	 * chip */
> -	ret = lis3l02dq_spi_read_reg_8(&st->indio_dev->dev,
> +	ret = lis3l02dq_spi_read_reg_8(&st->help.indio_dev->dev,
>  				       LIS3L02DQ_REG_CTRL_1_ADDR,
>  				       &valtest);
>  	if (ret || (valtest != val)) {
> -		dev_err(&st->indio_dev->dev, "device not playing ball");
> +		dev_err(&st->help.indio_dev->dev, "device not playing ball");
>  		ret = -EINVAL;
>  		goto err_ret;
>  	}
>  
>  	val = LIS3L02DQ_DEFAULT_CTRL2;
> -	ret = lis3l02dq_spi_write_reg_8(&st->indio_dev->dev,
> +	ret = lis3l02dq_spi_write_reg_8(&st->help.indio_dev->dev,
>  					LIS3L02DQ_REG_CTRL_2_ADDR,
>  					&val);
>  	if (ret) {
> @@ -449,7 +459,7 @@ static int lis3l02dq_initial_setup(struct lis3l02dq_state *st)
>  	}
>  
>  	val = LIS3L02DQ_REG_WAKE_UP_CFG_LATCH_SRC;
> -	ret = lis3l02dq_spi_write_reg_8(&st->indio_dev->dev,
> +	ret = lis3l02dq_spi_write_reg_8(&st->help.indio_dev->dev,
>  					LIS3L02DQ_REG_WAKE_UP_CFG_ADDR,
>  					&val);
>  	if (ret)
> @@ -595,15 +605,17 @@ error_mutex_unlock:
>  }
>  
>  
> -static int lis3l02dq_thresh_handler_th(struct iio_dev *dev_info,
> +static int lis3l02dq_thresh_handler_th(struct iio_dev *indio_dev,
>  				       int index,
>  				       s64 timestamp,
>  				       int no_test)
>  {
> -	struct lis3l02dq_state *st = dev_info->dev_data;
> +	struct iio_sw_ring_helper_state *h
> +		= iio_dev_get_devdata(indio_dev);
> +	struct lis3l02dq_state *st = lis3l02dq_h_to_s(h);
>  
>  	/* Stash the timestamp somewhere convenient for the bh */
> -	st->last_timestamp = timestamp;
> +	h->last_timestamp = timestamp;
>  	schedule_work(&st->work_thresh);
>  
>  	return 0;
> @@ -621,43 +633,43 @@ static void lis3l02dq_thresh_handler_bh_no_check(struct work_struct *work_s)
>  
>  	u8 t;
>  
> -	lis3l02dq_spi_read_reg_8(&st->indio_dev->dev,
> +	lis3l02dq_spi_read_reg_8(&st->help.indio_dev->dev,
>  				 LIS3L02DQ_REG_WAKE_UP_SRC_ADDR,
>  				 &t);
>  
>  	if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_Z_HIGH)
> -		iio_push_event(st->indio_dev, 0,
> +		iio_push_event(st->help.indio_dev, 0,
>  			       IIO_EVENT_CODE_ACCEL_Z_HIGH,
> -			       st->last_timestamp);
> +			       st->help.last_timestamp);
>  
>  	if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_Z_LOW)
> -		iio_push_event(st->indio_dev, 0,
> +		iio_push_event(st->help.indio_dev, 0,
>  			       IIO_EVENT_CODE_ACCEL_Z_LOW,
> -			       st->last_timestamp);
> +			       st->help.last_timestamp);
>  
>  	if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_Y_HIGH)
> -		iio_push_event(st->indio_dev, 0,
> +		iio_push_event(st->help.indio_dev, 0,
>  			       IIO_EVENT_CODE_ACCEL_Y_HIGH,
> -			       st->last_timestamp);
> +			       st->help.last_timestamp);
>  
>  	if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_Y_LOW)
> -		iio_push_event(st->indio_dev, 0,
> +		iio_push_event(st->help.indio_dev, 0,
>  			       IIO_EVENT_CODE_ACCEL_Y_LOW,
> -			       st->last_timestamp);
> +			       st->help.last_timestamp);
>  
>  	if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_X_HIGH)
> -		iio_push_event(st->indio_dev, 0,
> +		iio_push_event(st->help.indio_dev, 0,
>  			       IIO_EVENT_CODE_ACCEL_X_HIGH,
> -			       st->last_timestamp);
> +			       st->help.last_timestamp);
>  
>  	if (t & LIS3L02DQ_REG_WAKE_UP_SRC_INTERRUPT_X_LOW)
> -		iio_push_event(st->indio_dev, 0,
> +		iio_push_event(st->help.indio_dev, 0,
>  			       IIO_EVENT_CODE_ACCEL_X_LOW,
> -			       st->last_timestamp);
> +			       st->help.last_timestamp);
>  	/* reenable the irq */
>  	enable_irq(st->us->irq);
>  	/* Ack and allow for new interrupts */
> -	lis3l02dq_spi_read_reg_8(&st->indio_dev->dev,
> +	lis3l02dq_spi_read_reg_8(&st->help.indio_dev->dev,
>  				 LIS3L02DQ_REG_WAKE_UP_ACK_ADDR,
>  				 &t);
>  
> @@ -769,30 +781,30 @@ static int __devinit lis3l02dq_probe(struct spi_device *spi)
>  	st->us = spi;
>  	mutex_init(&st->buf_lock);
>  	/* setup the industrialio driver allocated elements */
> -	st->indio_dev = iio_allocate_device();
> -	if (st->indio_dev == NULL) {
> +	st->help.indio_dev = iio_allocate_device();
> +	if (st->help.indio_dev == NULL) {
>  		ret = -ENOMEM;
>  		goto error_free_tx;
>  	}
>  
> -	st->indio_dev->dev.parent = &spi->dev;
> -	st->indio_dev->num_interrupt_lines = 1;
> -	st->indio_dev->event_attrs = &lis3l02dq_event_attribute_group;
> -	st->indio_dev->attrs = &lis3l02dq_attribute_group;
> -	st->indio_dev->dev_data = (void *)(st);
> -	st->indio_dev->driver_module = THIS_MODULE;
> -	st->indio_dev->modes = INDIO_DIRECT_MODE;
> +	st->help.indio_dev->dev.parent = &spi->dev;
> +	st->help.indio_dev->num_interrupt_lines = 1;
> +	st->help.indio_dev->event_attrs = &lis3l02dq_event_attribute_group;
> +	st->help.indio_dev->attrs = &lis3l02dq_attribute_group;
> +	st->help.indio_dev->dev_data = (void *)(&st->help);
> +	st->help.indio_dev->driver_module = THIS_MODULE;
> +	st->help.indio_dev->modes = INDIO_DIRECT_MODE;
>  
> -	ret = lis3l02dq_configure_ring(st->indio_dev);
> +	ret = lis3l02dq_configure_ring(st->help.indio_dev);
>  	if (ret)
>  		goto error_free_dev;
>  
> -	ret = iio_device_register(st->indio_dev);
> +	ret = iio_device_register(st->help.indio_dev);
>  	if (ret)
>  		goto error_unreg_ring_funcs;
>  	regdone = 1;
>  
> -	ret = iio_ring_buffer_register(st->indio_dev->ring, 0);
> +	ret = iio_ring_buffer_register(st->help.indio_dev->ring, 0);
>  	if (ret) {
>  		printk(KERN_ERR "failed to initialize the ring\n");
>  		goto error_unreg_ring_funcs;
> @@ -801,14 +813,14 @@ static int __devinit lis3l02dq_probe(struct spi_device *spi)
>  	if (spi->irq && gpio_is_valid(irq_to_gpio(spi->irq)) > 0) {
>  		st->inter = 0;
>  		ret = iio_register_interrupt_line(spi->irq,
> -						  st->indio_dev,
> +						  st->help.indio_dev,
>  						  0,
>  						  IRQF_TRIGGER_RISING,
>  						  "lis3l02dq");
>  		if (ret)
>  			goto error_uninitialize_ring;
>  
> -		ret = lis3l02dq_probe_trigger(st->indio_dev);
> +		ret = lis3l02dq_probe_trigger(st->help.indio_dev);
>  		if (ret)
>  			goto error_unregister_line;
>  	}
> @@ -820,20 +832,20 @@ static int __devinit lis3l02dq_probe(struct spi_device *spi)
>  	return 0;
>  
>  error_remove_trigger:
> -	if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
> -		lis3l02dq_remove_trigger(st->indio_dev);
> +	if (st->help.indio_dev->modes & INDIO_RING_TRIGGERED)
> +		lis3l02dq_remove_trigger(st->help.indio_dev);
>  error_unregister_line:
> -	if (st->indio_dev->modes & INDIO_RING_TRIGGERED)
> -		iio_unregister_interrupt_line(st->indio_dev, 0);
> +	if (st->help.indio_dev->modes & INDIO_RING_TRIGGERED)
> +		iio_unregister_interrupt_line(st->help.indio_dev, 0);
>  error_uninitialize_ring:
> -	iio_ring_buffer_unregister(st->indio_dev->ring);
> +	iio_ring_buffer_unregister(st->help.indio_dev->ring);
>  error_unreg_ring_funcs:
> -	lis3l02dq_unconfigure_ring(st->indio_dev);
> +	lis3l02dq_unconfigure_ring(st->help.indio_dev);
>  error_free_dev:
>  	if (regdone)
> -		iio_device_unregister(st->indio_dev);
> +		iio_device_unregister(st->help.indio_dev);
>  	else
> -		iio_free_device(st->indio_dev);
> +		iio_free_device(st->help.indio_dev);
>  error_free_tx:
>  	kfree(st->tx);
>  error_free_rx:
> @@ -848,7 +860,9 @@ error_ret:
>  static int lis3l02dq_stop_device(struct iio_dev *indio_dev)
>  {
>  	int ret;
> -	struct lis3l02dq_state *st = indio_dev->dev_data;
> +	struct iio_sw_ring_helper_state *h
> +		= iio_dev_get_devdata(indio_dev);
> +	struct lis3l02dq_state *st = lis3l02dq_h_to_s(h);
>  	u8 val = 0;
>  
>  	mutex_lock(&indio_dev->mlock);
> @@ -875,7 +889,7 @@ static int lis3l02dq_remove(struct spi_device *spi)
>  {
>  	int ret;
>  	struct lis3l02dq_state *st = spi_get_drvdata(spi);
> -	struct iio_dev *indio_dev = st->indio_dev;
> +	struct iio_dev *indio_dev = st->help.indio_dev;
>  
>  	ret = lis3l02dq_stop_device(indio_dev);
>  	if (ret)
> diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c
> index 2c11209..48e0f21 100644
> --- a/drivers/staging/iio/accel/lis3l02dq_ring.c
> +++ b/drivers/staging/iio/accel/lis3l02dq_ring.c
> @@ -105,11 +105,13 @@ static struct attribute_group lis3l02dq_scan_el_group = {
>   **/
>  static void lis3l02dq_poll_func_th(struct iio_dev *indio_dev, s64 time)
>  {
> -	struct lis3l02dq_state *st = iio_dev_get_devdata(indio_dev);
> -	st->last_timestamp = time;
> -	schedule_work(&st->work_trigger_to_ring);
> -	/* Indicate that this interrupt is being handled */
> +	struct iio_sw_ring_helper_state *h
> +		= iio_dev_get_devdata(indio_dev);
> +	struct lis3l02dq_state *st = lis3l02dq_h_to_s(h);
> +	/* in this case we need to slightly extend the helper function */
> +	iio_sw_poll_func_th(indio_dev, time);
>  
> +	/* Indicate that this interrupt is being handled */
>  	/* Technically this is trigger related, but without this
>  	 * handler running there is currently now way for the interrupt
>  	 * to clear.
> @@ -120,15 +122,16 @@ static void lis3l02dq_poll_func_th(struct iio_dev *indio_dev, s64 time)
>  /**
>   * lis3l02dq_data_rdy_trig_poll() the event handler for the data rdy trig
>   **/
> -static int lis3l02dq_data_rdy_trig_poll(struct iio_dev *dev_info,
> +static int lis3l02dq_data_rdy_trig_poll(struct iio_dev *indio_dev,
>  				       int index,
>  				       s64 timestamp,
>  				       int no_test)
>  {
> -	struct lis3l02dq_state *st = iio_dev_get_devdata(dev_info);
> -	struct iio_trigger *trig = st->trig;
> +	struct iio_sw_ring_helper_state *h
> +		= iio_dev_get_devdata(indio_dev);
> +	struct lis3l02dq_state *st = lis3l02dq_h_to_s(h);
>  
> -	iio_trigger_poll(trig, timestamp);
> +	iio_trigger_poll(st->trig, timestamp);
>  
>  	return IRQ_HANDLED;
>  }
> @@ -212,7 +215,7 @@ static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array)
>  	struct spi_message msg;
>  	int ret, i, j = 0;
>  
> -	xfers = kzalloc((st->indio_dev->scan_count) * 2
> +	xfers = kzalloc((st->help.indio_dev->scan_count) * 2
>  			* sizeof(*xfers), GFP_KERNEL);
>  	if (!xfers)
>  		return -ENOMEM;
> @@ -220,7 +223,7 @@ static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array)
>  	mutex_lock(&st->buf_lock);
>  
>  	for (i = 0; i < ARRAY_SIZE(read_all_tx_array)/4; i++) {
> -		if (st->indio_dev->scan_mask & (1 << i)) {
> +		if (st->help.indio_dev->scan_mask & (1 << i)) {
>  			/* lower byte */
>  			xfers[j].tx_buf = st->tx + 2*j;
>  			st->tx[2*j] = read_all_tx_array[i*4];
> @@ -248,7 +251,7 @@ static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array)
>  	 * values in alternate bytes
>  	 */
>  	spi_message_init(&msg);
> -	for (j = 0; j < st->indio_dev->scan_count * 2; j++)
> +	for (j = 0; j < st->help.indio_dev->scan_count * 2; j++)
>  		spi_message_add_tail(&xfers[j], &msg);
>  
>  	ret = spi_sync(st->us, &msg);
> @@ -258,62 +261,19 @@ static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array)
>  	return ret;
>  }
>  
> -
> -/* Whilst this makes a lot of calls to iio_sw_ring functions - it is to device
> - * specific to be rolled into the core.
> - */
> -static void lis3l02dq_trigger_bh_to_ring(struct work_struct *work_s)
> -{
> -	struct lis3l02dq_state *st
> -		= container_of(work_s, struct lis3l02dq_state,
> -			       work_trigger_to_ring);
> -
> -	u8 *rx_array;
> -	int i = 0;
> -	u16 *data;
> -	size_t datasize = st->indio_dev
> -		->ring->access.get_bpd(st->indio_dev->ring);
> -
> -	data = kmalloc(datasize , GFP_KERNEL);
> -	if (data == NULL) {
> -		dev_err(&st->us->dev, "memory alloc failed in ring bh");
> -		return;
> -	}
> -	/* Due to interleaved nature of transmission this buffer must be
> -	 * twice the number of bytes, or 4 times the number of channels
> -	 */
> -	rx_array = kmalloc(4 * (st->indio_dev->scan_count), GFP_KERNEL);
> -	if (rx_array == NULL) {
> -		dev_err(&st->us->dev, "memory alloc failed in ring bh");
> -		kfree(data);
> -		return;
> +static int lis3l02dq_get_ring_element(struct iio_sw_ring_helper_state *h,
> +				u8 *buf) {
> +	int ret, i;
> +	u8 *rx_array = NULL;
> +	ret = lis3l02dq_read_all(lis3l02dq_h_to_s(h), rx_array);
> +	if (ret > 0) {
> +		for (i = 0; i < h->indio_dev->scan_count; i++)

oops, this isn't going to work as I'm writing a s16 to a u8.

> +			buf[i] = combine_8_to_16(rx_array[i*4+1],
> +						rx_array[i*4+3]);
> +		kfree(rx_array);
> +		return 0;
>  	}
> -
> -	/* whilst trigger specific, if this read does nto occur the data
> -	   ready interrupt will not be cleared.  Need to add a mechanism
> -	   to provide a dummy read function if this is not triggering on
> -	   the data ready function but something else is.
> -	*/
> -	st->inter = 0;
> -
> -	if (st->indio_dev->scan_count)
> -		if (lis3l02dq_read_all(st, rx_array) >= 0)
> -			for (; i < st->indio_dev->scan_count; i++)
> -				data[i] = combine_8_to_16(rx_array[i*4+1],
> -							  rx_array[i*4+3]);
> -	/* Guaranteed to be aligned with 8 byte boundary */
> -	if (st->indio_dev->scan_timestamp)
> -		*((s64 *)(data + ((i + 3)/4)*4)) = st->last_timestamp;
> -
> -	st->indio_dev->ring->access.store_to(st->indio_dev->ring,
> -					    (u8 *)data,
> -					    st->last_timestamp);
> -
> -	iio_trigger_notify_done(st->indio_dev->trig);
> -	kfree(rx_array);
> -	kfree(data);
> -
> -	return;
> +	return ret;
>  }
>  
>  /* Caller responsible for locking as necessary. */
> @@ -387,7 +347,7 @@ static int lis3l02dq_data_rdy_trigger_set_state(struct iio_trigger *trig,
>  	struct lis3l02dq_state *st = trig->private_data;
>  	int ret = 0;
>  	u8 t;
> -	__lis3l02dq_write_data_ready_config(&st->indio_dev->dev,
> +	__lis3l02dq_write_data_ready_config(&st->help.indio_dev->dev,
>  					    &iio_event_data_rdy_trig,
>  					    state);
>  	if (state == false) {
> @@ -397,7 +357,7 @@ static int lis3l02dq_data_rdy_trigger_set_state(struct iio_trigger *trig,
>  		/* Clear any outstanding ready events */
>  		ret = lis3l02dq_read_all(st, NULL);
>  	}
> -	lis3l02dq_spi_read_reg_8(&st->indio_dev->dev,
> +	lis3l02dq_spi_read_reg_8(&st->help.indio_dev->dev,
>  				 LIS3L02DQ_REG_WAKE_UP_SRC_ADDR,
>  				 &t);
>  	return ret;
> @@ -500,12 +460,12 @@ void lis3l02dq_unconfigure_ring(struct iio_dev *indio_dev)
>  
>  int lis3l02dq_configure_ring(struct iio_dev *indio_dev)
>  {
> -	int ret = 0;
> -	struct lis3l02dq_state *st = indio_dev->dev_data;
> -	struct iio_ring_buffer *ring;
> -	INIT_WORK(&st->work_trigger_to_ring, lis3l02dq_trigger_bh_to_ring);
> +	int ret;
> +	struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev);
> +	
> +	INIT_WORK(&h->work_trigger_to_ring, iio_sw_trigger_bh_to_ring);
>  	/* Set default scan mode */
> -
> +	h->get_ring_element = &lis3l02dq_get_ring_element;
>  	iio_scan_mask_set(indio_dev, iio_scan_el_accel_x.number);
>  	iio_scan_mask_set(indio_dev, iio_scan_el_accel_y.number);
>  	iio_scan_mask_set(indio_dev, iio_scan_el_accel_z.number);
> @@ -513,19 +473,17 @@ int lis3l02dq_configure_ring(struct iio_dev *indio_dev)
>  
>  	indio_dev->scan_el_attrs = &lis3l02dq_scan_el_group;
>  
> -	ring = iio_sw_rb_allocate(indio_dev);
> -	if (!ring) {
> -		ret = -ENOMEM;
> -		return ret;
> -	}
> -	indio_dev->ring = ring;
> +	indio_dev->ring = iio_sw_rb_allocate(indio_dev);
> +	if (!indio_dev->ring)
> +		return -ENOMEM;
> +
>  	/* Effectively select the ring buffer implementation */
> -	iio_ring_sw_register_funcs(&ring->access);
> -	ring->bpe = 2;
> -	ring->preenable = &iio_sw_ring_preenable;
> -	ring->postenable = &iio_triggered_ring_postenable;
> -	ring->predisable = &iio_triggered_ring_predisable;
> -	ring->owner = THIS_MODULE;
> +	iio_ring_sw_register_funcs(&indio_dev->ring->access);
> +	indio_dev->ring->bpe = 2;
> +	indio_dev->ring->preenable = &iio_sw_ring_preenable;
> +	indio_dev->ring->postenable = &iio_triggered_ring_postenable;
> +	indio_dev->ring->predisable = &iio_triggered_ring_predisable;
> +	indio_dev->ring->owner = THIS_MODULE;
>  
>  	ret = iio_alloc_pollfunc(indio_dev, NULL, &lis3l02dq_poll_func_th);
>  	if (ret)
> @@ -537,6 +495,3 @@ error_iio_sw_rb_free:
>  	iio_sw_rb_free(indio_dev->ring);
>  	return ret;
>  }
> -
> -
> -

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

* Re: [PATCH 2/5] staging:iio: Make extensive use of iio_sw_ring_preenable
  2010-06-30 14:27 ` [PATCH 2/5] staging:iio: Make extensive use of iio_sw_ring_preenable Jonathan Cameron
@ 2010-07-07 10:59   ` Barry Song
  0 siblings, 0 replies; 9+ messages in thread
From: Barry Song @ 2010-07-07 10:59 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, barry.song

On Wed, Jun 30, 2010 at 10:27 PM, Jonathan Cameron <jic23@cam.ac.uk> wrote:
> Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Acked-by: Barry Song <21cnbao@gmail.com>
> ---
> =C2=A0drivers/staging/iio/accel/adis16209_ring.c | =C2=A0 31 +-----------=
---------------
> =C2=A0drivers/staging/iio/accel/adis16240_ring.c | =C2=A0 29 +-----------=
-------------
> =C2=A0drivers/staging/iio/accel/lis3l02dq_ring.c | =C2=A0 25 +-----------=
---------
> =C2=A0drivers/staging/iio/gyro/adis16260_ring.c =C2=A0| =C2=A0 29 +------=
------------------
> =C2=A0drivers/staging/iio/imu/adis16300_ring.c =C2=A0 | =C2=A0 26 +------=
---------------
> =C2=A0drivers/staging/iio/imu/adis16350_ring.c =C2=A0 | =C2=A0 29 +------=
------------------
> =C2=A0drivers/staging/iio/imu/adis16400_ring.c =C2=A0 | =C2=A0 26 +------=
---------------
> =C2=A07 files changed, 14 insertions(+), 181 deletions(-)
>
> diff --git a/drivers/staging/iio/accel/adis16209_ring.c b/drivers/staging=
/iio/accel/adis16209_ring.c
> index f3a9493..25fde65 100644
> --- a/drivers/staging/iio/accel/adis16209_ring.c
> +++ b/drivers/staging/iio/accel/adis16209_ring.c
> @@ -147,34 +147,6 @@ static void adis16209_trigger_bh_to_ring(struct work=
_struct *work_s)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0return;
> =C2=A0}
>
> -/* in these circumstances is it better to go with unaligned packing and
> - * deal with the cost?*/
> -static int adis16209_data_rdy_ring_preenable(struct iio_dev *indio_dev)
> -{
> - =C2=A0 =C2=A0 =C2=A0 size_t size;
> - =C2=A0 =C2=A0 =C2=A0 dev_dbg(&indio_dev->dev, "%s\n", __func__);
> - =C2=A0 =C2=A0 =C2=A0 /* Check if there are any scan elements enabled, i=
f not fail*/
> - =C2=A0 =C2=A0 =C2=A0 if (!(indio_dev->scan_count || indio_dev->scan_tim=
estamp))
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -EINVAL;
> -
> - =C2=A0 =C2=A0 =C2=A0 if (indio_dev->ring->access.set_bpd) {
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (indio_dev->scan_ti=
mestamp)
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 if (indio_dev->scan_count)
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* Timestamp (aligned to s64) and data *=
/
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size =3D (((indio_dev->scan_count * size=
of(s16))
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0+ size=
of(s64) - 1)
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 & ~(sizeof(s=
64) - 1))
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 + sizeof(s64=
);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 else /* Timestamp only =C2=A0*/
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size =3D sizeof(s64);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 else /* Data only */
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 size =3D indio_dev->scan_count*sizeof(s16);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 indio_dev->ring->acces=
s.set_bpd(indio_dev->ring, size);
> - =C2=A0 =C2=A0 =C2=A0 }
> -
> - =C2=A0 =C2=A0 =C2=A0 return 0;
> -}
> -
> =C2=A0void adis16209_unconfigure_ring(struct iio_dev *indio_dev)
> =C2=A0{
> =C2=A0 =C2=A0 =C2=A0 =C2=A0kfree(indio_dev->pollfunc);
> @@ -209,7 +181,8 @@ int adis16209_configure_ring(struct iio_dev *indio_de=
v)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0indio_dev->ring =3D ring;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Effectively select the ring buffer implemen=
tation */
> =C2=A0 =C2=A0 =C2=A0 =C2=A0iio_ring_sw_register_funcs(&ring->access);
> - =C2=A0 =C2=A0 =C2=A0 ring->preenable =3D &adis16209_data_rdy_ring_preen=
able;
> + =C2=A0 =C2=A0 =C2=A0 ring->bpe =3D 2;
> + =C2=A0 =C2=A0 =C2=A0 ring->preenable =3D &iio_sw_ring_preenable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->postenable =3D &iio_triggered_ring_poste=
nable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->predisable =3D &iio_triggered_ring_predi=
sable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->owner =3D THIS_MODULE;
> diff --git a/drivers/staging/iio/accel/adis16240_ring.c b/drivers/staging=
/iio/accel/adis16240_ring.c
> index a1611bb..cd69a2e 100644
> --- a/drivers/staging/iio/accel/adis16240_ring.c
> +++ b/drivers/staging/iio/accel/adis16240_ring.c
> @@ -139,32 +139,6 @@ static void adis16240_trigger_bh_to_ring(struct work=
_struct *work_s)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0return;
> =C2=A0}
>
> -static int adis16240_data_rdy_ring_preenable(struct iio_dev *indio_dev)
> -{
> - =C2=A0 =C2=A0 =C2=A0 size_t size;
> - =C2=A0 =C2=A0 =C2=A0 dev_dbg(&indio_dev->dev, "%s\n", __func__);
> - =C2=A0 =C2=A0 =C2=A0 /* Check if there are any scan elements enabled, i=
f not fail*/
> - =C2=A0 =C2=A0 =C2=A0 if (!(indio_dev->scan_count || indio_dev->scan_tim=
estamp))
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -EINVAL;
> -
> - =C2=A0 =C2=A0 =C2=A0 if (indio_dev->ring->access.set_bpd) {
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (indio_dev->scan_ti=
mestamp)
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 if (indio_dev->scan_count)
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* Timestamp (aligned sizeof(s64) and da=
ta */
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size =3D (((indio_dev->scan_count * size=
of(s16))
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0+ size=
of(s64) - 1)
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 & ~(sizeof(s=
64) - 1))
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 + sizeof(s64=
);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 else /* Timestamp only =C2=A0*/
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size =3D sizeof(s64);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 else /* Data only */
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 size =3D indio_dev->scan_count*sizeof(s16);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 indio_dev->ring->acces=
s.set_bpd(indio_dev->ring, size);
> - =C2=A0 =C2=A0 =C2=A0 }
> -
> - =C2=A0 =C2=A0 =C2=A0 return 0;
> -}
> -
> =C2=A0void adis16240_unconfigure_ring(struct iio_dev *indio_dev)
> =C2=A0{
> =C2=A0 =C2=A0 =C2=A0 =C2=A0kfree(indio_dev->pollfunc);
> @@ -197,7 +171,8 @@ int adis16240_configure_ring(struct iio_dev *indio_de=
v)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0indio_dev->ring =3D ring;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Effectively select the ring buffer implemen=
tation */
> =C2=A0 =C2=A0 =C2=A0 =C2=A0iio_ring_sw_register_funcs(&ring->access);
> - =C2=A0 =C2=A0 =C2=A0 ring->preenable =3D &adis16240_data_rdy_ring_preen=
able;
> + =C2=A0 =C2=A0 =C2=A0 ring->bpe =3D 2;
> + =C2=A0 =C2=A0 =C2=A0 ring->preenable =3D &iio_sw_ring_preenable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->postenable =3D &iio_triggered_ring_poste=
nable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->predisable =3D &iio_triggered_ring_predi=
sable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->owner =3D THIS_MODULE;
> diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging=
/iio/accel/lis3l02dq_ring.c
> index a506dab..2c11209 100644
> --- a/drivers/staging/iio/accel/lis3l02dq_ring.c
> +++ b/drivers/staging/iio/accel/lis3l02dq_ring.c
> @@ -315,28 +315,6 @@ static void lis3l02dq_trigger_bh_to_ring(struct work=
_struct *work_s)
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0return;
> =C2=A0}
> -/* in these circumstances is it better to go with unaligned packing and
> - * deal with the cost?*/
> -static int lis3l02dq_data_rdy_ring_preenable(struct iio_dev *indio_dev)
> -{
> - =C2=A0 =C2=A0 =C2=A0 size_t size;
> - =C2=A0 =C2=A0 =C2=A0 /* Check if there are any scan elements enabled, i=
f not fail*/
> - =C2=A0 =C2=A0 =C2=A0 if (!(indio_dev->scan_count || indio_dev->scan_tim=
estamp))
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -EINVAL;
> -
> - =C2=A0 =C2=A0 =C2=A0 if (indio_dev->ring->access.set_bpd) {
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (indio_dev->scan_ti=
mestamp)
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 if (indio_dev->scan_count) /* Timestamp and data */
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size =3D 2*sizeof(s64);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 else /* Timestamp only =C2=A0*/
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size =3D sizeof(s64);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 else /* Data only */
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 size =3D indio_dev->scan_count*sizeof(s16);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 indio_dev->ring->acces=
s.set_bpd(indio_dev->ring, size);
> - =C2=A0 =C2=A0 =C2=A0 }
> -
> - =C2=A0 =C2=A0 =C2=A0 return 0;
> -}
>
> =C2=A0/* Caller responsible for locking as necessary. */
> =C2=A0static int
> @@ -543,7 +521,8 @@ int lis3l02dq_configure_ring(struct iio_dev *indio_de=
v)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0indio_dev->ring =3D ring;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Effectively select the ring buffer implemen=
tation */
> =C2=A0 =C2=A0 =C2=A0 =C2=A0iio_ring_sw_register_funcs(&ring->access);
> - =C2=A0 =C2=A0 =C2=A0 ring->preenable =3D &lis3l02dq_data_rdy_ring_preen=
able;
> + =C2=A0 =C2=A0 =C2=A0 ring->bpe =3D 2;
> + =C2=A0 =C2=A0 =C2=A0 ring->preenable =3D &iio_sw_ring_preenable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->postenable =3D &iio_triggered_ring_poste=
nable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->predisable =3D &iio_triggered_ring_predi=
sable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->owner =3D THIS_MODULE;
> diff --git a/drivers/staging/iio/gyro/adis16260_ring.c b/drivers/staging/=
iio/gyro/adis16260_ring.c
> index 94b4515..9ef7f90 100644
> --- a/drivers/staging/iio/gyro/adis16260_ring.c
> +++ b/drivers/staging/iio/gyro/adis16260_ring.c
> @@ -142,32 +142,6 @@ static void adis16260_trigger_bh_to_ring(struct work=
_struct *work_s)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0return;
> =C2=A0}
>
> -static int adis16260_data_rdy_ring_preenable(struct iio_dev *indio_dev)
> -{
> - =C2=A0 =C2=A0 =C2=A0 size_t size;
> - =C2=A0 =C2=A0 =C2=A0 dev_dbg(&indio_dev->dev, "%s\n", __func__);
> - =C2=A0 =C2=A0 =C2=A0 /* Check if there are any scan elements enabled, i=
f not fail*/
> - =C2=A0 =C2=A0 =C2=A0 if (!(indio_dev->scan_count || indio_dev->scan_tim=
estamp))
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -EINVAL;
> -
> - =C2=A0 =C2=A0 =C2=A0 if (indio_dev->ring->access.set_bpd) {
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (indio_dev->scan_ti=
mestamp)
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 if (indio_dev->scan_count)
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* Timestamp (aligned s64) and data */
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size =3D (((indio_dev->scan_count * size=
of(s16))
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 + sizeof(s64) - 1)
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 & ~(sizeof(s=
64) - 1))
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 + sizeof(s64=
);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 else /* Timestamp only =C2=A0*/
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size =3D sizeof(s64);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 else /* Data only */
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 size =3D indio_dev->scan_count*sizeof(s16);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 indio_dev->ring->acces=
s.set_bpd(indio_dev->ring, size);
> - =C2=A0 =C2=A0 =C2=A0 }
> -
> - =C2=A0 =C2=A0 =C2=A0 return 0;
> -}
> -
> =C2=A0void adis16260_unconfigure_ring(struct iio_dev *indio_dev)
> =C2=A0{
> =C2=A0 =C2=A0 =C2=A0 =C2=A0kfree(indio_dev->pollfunc);
> @@ -199,7 +173,8 @@ int adis16260_configure_ring(struct iio_dev *indio_de=
v)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0indio_dev->ring =3D ring;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Effectively select the ring buffer implemen=
tation */
> =C2=A0 =C2=A0 =C2=A0 =C2=A0iio_ring_sw_register_funcs(&ring->access);
> - =C2=A0 =C2=A0 =C2=A0 ring->preenable =3D &adis16260_data_rdy_ring_preen=
able;
> + =C2=A0 =C2=A0 =C2=A0 ring->bpe =3D 2;
> + =C2=A0 =C2=A0 =C2=A0 ring->preenable =3D &iio_sw_ring_preenable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->postenable =3D &iio_triggered_ring_poste=
nable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->predisable =3D &iio_triggered_ring_predi=
sable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->owner =3D THIS_MODULE;
> diff --git a/drivers/staging/iio/imu/adis16300_ring.c b/drivers/staging/i=
io/imu/adis16300_ring.c
> index 3bf9904..fc93160 100644
> --- a/drivers/staging/iio/imu/adis16300_ring.c
> +++ b/drivers/staging/iio/imu/adis16300_ring.c
> @@ -165,29 +165,6 @@ static void adis16300_trigger_bh_to_ring(struct work=
_struct *work_s)
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0return;
> =C2=A0}
> -/* in these circumstances is it better to go with unaligned packing and
> - * deal with the cost?*/
> -static int adis16300_data_rdy_ring_preenable(struct iio_dev *indio_dev)
> -{
> - =C2=A0 =C2=A0 =C2=A0 size_t size;
> - =C2=A0 =C2=A0 =C2=A0 dev_dbg(&indio_dev->dev, "%s\n", __func__);
> - =C2=A0 =C2=A0 =C2=A0 /* Check if there are any scan elements enabled, i=
f not fail*/
> - =C2=A0 =C2=A0 =C2=A0 if (!(indio_dev->scan_count || indio_dev->scan_tim=
estamp))
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -EINVAL;
> -
> - =C2=A0 =C2=A0 =C2=A0 if (indio_dev->ring->access.set_bpd) {
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (indio_dev->scan_ti=
mestamp)
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 if (indio_dev->scan_count) /* Timestamp and data */
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size =3D 4*sizeof(s64);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 else /* Timestamp only =C2=A0*/
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size =3D sizeof(s64);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 else /* Data only */
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 size =3D indio_dev->scan_count*sizeof(s16);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 indio_dev->ring->acces=
s.set_bpd(indio_dev->ring, size);
> - =C2=A0 =C2=A0 =C2=A0 }
> -
> - =C2=A0 =C2=A0 =C2=A0 return 0;
> -}
>
> =C2=A0void adis16300_unconfigure_ring(struct iio_dev *indio_dev)
> =C2=A0{
> @@ -224,7 +201,8 @@ int adis16300_configure_ring(struct iio_dev *indio_de=
v)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0indio_dev->ring =3D ring;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Effectively select the ring buffer implemen=
tation */
> =C2=A0 =C2=A0 =C2=A0 =C2=A0iio_ring_sw_register_funcs(&ring->access);
> - =C2=A0 =C2=A0 =C2=A0 ring->preenable =3D &adis16300_data_rdy_ring_preen=
able;
> + =C2=A0 =C2=A0 =C2=A0 ring->bpe =3D 2;
> + =C2=A0 =C2=A0 =C2=A0 ring->preenable =3D &iio_sw_ring_preenable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->postenable =3D &iio_triggered_ring_poste=
nable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->predisable =3D &iio_triggered_ring_predi=
sable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->owner =3D THIS_MODULE;
> diff --git a/drivers/staging/iio/imu/adis16350_ring.c b/drivers/staging/i=
io/imu/adis16350_ring.c
> index 319aa34..e053e9a 100644
> --- a/drivers/staging/iio/imu/adis16350_ring.c
> +++ b/drivers/staging/iio/imu/adis16350_ring.c
> @@ -166,32 +166,6 @@ static void adis16350_trigger_bh_to_ring(struct work=
_struct *work_s)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0return;
> =C2=A0}
>
> -static int adis16350_data_rdy_ring_preenable(struct iio_dev *indio_dev)
> -{
> - =C2=A0 =C2=A0 =C2=A0 size_t size;
> - =C2=A0 =C2=A0 =C2=A0 dev_dbg(&indio_dev->dev, "%s\n", __func__);
> - =C2=A0 =C2=A0 =C2=A0 /* Check if there are any scan elements enabled, i=
f not fail*/
> - =C2=A0 =C2=A0 =C2=A0 if (!(indio_dev->scan_count || indio_dev->scan_tim=
estamp))
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -EINVAL;
> -
> - =C2=A0 =C2=A0 =C2=A0 if (indio_dev->ring->access.set_bpd) {
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (indio_dev->scan_ti=
mestamp)
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 if (indio_dev->scan_count)
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* Timestamp (aligned sizeof(s64) and da=
ta */
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size =3D (((indio_dev->scan_count * size=
of(s16))
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 + sizeof(s64) - 1)
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 & ~(sizeof(s=
64) - 1))
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 + sizeof(s64=
);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 else /* Timestamp only =C2=A0*/
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size =3D sizeof(s64);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 else /* Data only */
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 size =3D indio_dev->scan_count*sizeof(s16);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 indio_dev->ring->acces=
s.set_bpd(indio_dev->ring, size);
> - =C2=A0 =C2=A0 =C2=A0 }
> -
> - =C2=A0 =C2=A0 =C2=A0 return 0;
> -}
> -
> =C2=A0void adis16350_unconfigure_ring(struct iio_dev *indio_dev)
> =C2=A0{
> =C2=A0 =C2=A0 =C2=A0 =C2=A0kfree(indio_dev->pollfunc);
> @@ -229,7 +203,8 @@ int adis16350_configure_ring(struct iio_dev *indio_de=
v)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0indio_dev->ring =3D ring;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Effectively select the ring buffer implemen=
tation */
> =C2=A0 =C2=A0 =C2=A0 =C2=A0iio_ring_sw_register_funcs(&ring->access);
> - =C2=A0 =C2=A0 =C2=A0 ring->preenable =3D &adis16350_data_rdy_ring_preen=
able;
> + =C2=A0 =C2=A0 =C2=A0 ring->bpe =3D 2;
> + =C2=A0 =C2=A0 =C2=A0 ring->preenable =3D &iio_sw_ring_preenable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->postenable =3D &iio_triggered_ring_poste=
nable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->predisable =3D &iio_triggered_ring_predi=
sable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->owner =3D THIS_MODULE;
> diff --git a/drivers/staging/iio/imu/adis16400_ring.c b/drivers/staging/i=
io/imu/adis16400_ring.c
> index c7744ef..949db76 100644
> --- a/drivers/staging/iio/imu/adis16400_ring.c
> +++ b/drivers/staging/iio/imu/adis16400_ring.c
> @@ -174,29 +174,6 @@ static void adis16400_trigger_bh_to_ring(struct work=
_struct *work_s)
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0return;
> =C2=A0}
> -/* in these circumstances is it better to go with unaligned packing and
> - * deal with the cost?*/
> -static int adis16400_data_rdy_ring_preenable(struct iio_dev *indio_dev)
> -{
> - =C2=A0 =C2=A0 =C2=A0 size_t size;
> - =C2=A0 =C2=A0 =C2=A0 dev_dbg(&indio_dev->dev, "%s\n", __func__);
> - =C2=A0 =C2=A0 =C2=A0 /* Check if there are any scan elements enabled, i=
f not fail*/
> - =C2=A0 =C2=A0 =C2=A0 if (!(indio_dev->scan_count || indio_dev->scan_tim=
estamp))
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return -EINVAL;
> -
> - =C2=A0 =C2=A0 =C2=A0 if (indio_dev->ring->access.set_bpd) {
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (indio_dev->scan_ti=
mestamp)
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 if (indio_dev->scan_count) /* Timestamp and data */
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size =3D 6*sizeof(s64);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 else /* Timestamp only =C2=A0*/
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 size =3D sizeof(s64);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 else /* Data only */
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 size =3D indio_dev->scan_count*sizeof(s16);
> - =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 indio_dev->ring->acces=
s.set_bpd(indio_dev->ring, size);
> - =C2=A0 =C2=A0 =C2=A0 }
> -
> - =C2=A0 =C2=A0 =C2=A0 return 0;
> -}
>
> =C2=A0void adis16400_unconfigure_ring(struct iio_dev *indio_dev)
> =C2=A0{
> @@ -236,7 +213,8 @@ int adis16400_configure_ring(struct iio_dev *indio_de=
v)
> =C2=A0 =C2=A0 =C2=A0 =C2=A0indio_dev->ring =3D ring;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0/* Effectively select the ring buffer implemen=
tation */
> =C2=A0 =C2=A0 =C2=A0 =C2=A0iio_ring_sw_register_funcs(&ring->access);
> - =C2=A0 =C2=A0 =C2=A0 ring->preenable =3D &adis16400_data_rdy_ring_preen=
able;
> + =C2=A0 =C2=A0 =C2=A0 ring->bpe =3D 2;
> + =C2=A0 =C2=A0 =C2=A0 ring->preenable =3D &iio_sw_ring_preenable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->postenable =3D &iio_triggered_ring_poste=
nable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->predisable =3D &iio_triggered_ring_predi=
sable;
> =C2=A0 =C2=A0 =C2=A0 =C2=A0ring->owner =3D THIS_MODULE;
> --
> 1.7.0.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at =C2=A0http://vger.kernel.org/majordomo-info.html
>

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

* Re: [PATCH 3/5] staging:iio: Add iio_sw_ring_helper_state and functions to cover common case.
  2010-06-30 14:27 ` [PATCH 3/5] staging:iio: Add iio_sw_ring_helper_state and functions to cover common case Jonathan Cameron
@ 2010-07-08  9:28   ` Barry Song
  0 siblings, 0 replies; 9+ messages in thread
From: Barry Song @ 2010-07-08  9:28 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, barry.song

On Wed, Jun 30, 2010 at 10:27 PM, Jonathan Cameron <jic23@cam.ac.uk> wrote:
> Signed-off-by: Jonathan Cameron <jic23@cam.ac.uk>
Acked-by: Barry Song <21cnbao@gmail.com>
> ---
> =C2=A0drivers/staging/iio/ring_sw.c | =C2=A0 43 +++++++++++++++++++++++++=
++++++++++++++++
> =C2=A0drivers/staging/iio/ring_sw.h | =C2=A0 10 +++++++++
> =C2=A02 files changed, 53 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/staging/iio/ring_sw.c b/drivers/staging/iio/ring_sw.=
c
> index ca0e79e..293df5c 100644
> --- a/drivers/staging/iio/ring_sw.c
> +++ b/drivers/staging/iio/ring_sw.c
> @@ -13,6 +13,7 @@
> =C2=A0#include <linux/device.h>
> =C2=A0#include <linux/workqueue.h>
> =C2=A0#include "ring_sw.h"
> +#include "trigger.h"
>
> =C2=A0static inline int __iio_allocate_sw_ring_buffer(struct iio_sw_ring_=
buffer *ring,
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0int bytes_per_datum, int length)
> @@ -456,5 +457,47 @@ int iio_sw_ring_preenable(struct iio_dev *indio_dev)
> =C2=A0}
> =C2=A0EXPORT_SYMBOL(iio_sw_ring_preenable);
>
> +void iio_sw_trigger_bh_to_ring(struct work_struct *work_s)
> +{
> + =C2=A0 =C2=A0 =C2=A0 struct iio_sw_ring_helper_state *st
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D container_of(work_=
s, struct iio_sw_ring_helper_state,
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 work_trigger_to_ring);
> + =C2=A0 =C2=A0 =C2=A0 int len =3D 0;
> + =C2=A0 =C2=A0 =C2=A0 size_t datasize =3D st->indio_dev
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ->ring->access.get_bpd=
(st->indio_dev->ring);
> + =C2=A0 =C2=A0 =C2=A0 char *data =3D kmalloc(datasize, GFP_KERNEL);
> +
> + =C2=A0 =C2=A0 =C2=A0 if (data =3D=3D NULL) {
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 dev_err(st->indio_dev-=
>dev.parent,
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 "memory alloc failed in ring bh");
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return;
> + =C2=A0 =C2=A0 =C2=A0 }
> +
> + =C2=A0 =C2=A0 =C2=A0 if (st->indio_dev->scan_count)
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 len =3D st->get_ring_e=
lement(st, data);
> +
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* Guaranteed to be aligned with 8 byte bou=
ndary */
> + =C2=A0 =C2=A0 =C2=A0 if (st->indio_dev->scan_timestamp)
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 *(s64 *)(((u32)data + =
len + sizeof(s64) - 1) & ~(sizeof(s64) - 1))
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =3D st->last_timestamp;
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 st->indio_dev->ring->access.store_to(st->in=
dio_dev->ring,
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (u8 *)data,
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 st->last_timestamp);
> +
> + =C2=A0 =C2=A0 =C2=A0 iio_trigger_notify_done(st->indio_dev->trig);
> + =C2=A0 =C2=A0 =C2=A0 kfree(data);
> +
> + =C2=A0 =C2=A0 =C2=A0 return;
> +}
> +EXPORT_SYMBOL(iio_sw_trigger_bh_to_ring);
> +
> +void iio_sw_poll_func_th(struct iio_dev *indio_dev, s64 time)
> +{ =C2=A0 =C2=A0 =C2=A0struct iio_sw_ring_helper_state *h
> + =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D iio_dev_get_devdat=
a(indio_dev);
> + =C2=A0 =C2=A0 =C2=A0 h->last_timestamp =3D time;
> + =C2=A0 =C2=A0 =C2=A0 schedule_work(&h->work_trigger_to_ring);
> +}
> +EXPORT_SYMBOL(iio_sw_poll_func_th);
> +
> =C2=A0MODULE_DESCRIPTION("Industrialio I/O software ring buffer");
> =C2=A0MODULE_LICENSE("GPL");
> diff --git a/drivers/staging/iio/ring_sw.h b/drivers/staging/iio/ring_sw.=
h
> index 5c22936..59c99c0 100644
> --- a/drivers/staging/iio/ring_sw.h
> +++ b/drivers/staging/iio/ring_sw.h
> @@ -209,6 +209,16 @@ void iio_sw_rb_free(struct iio_ring_buffer *ring);
>
> =C2=A0int iio_sw_ring_preenable(struct iio_dev *indio_dev);
>
> +struct iio_sw_ring_helper_state {
> + =C2=A0 =C2=A0 =C2=A0 struct work_struct =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0work_trigger_to_ring;
> + =C2=A0 =C2=A0 =C2=A0 struct iio_dev =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0*indio_dev;
> + =C2=A0 =C2=A0 =C2=A0 int (*get_ring_element)(struct iio_sw_ring_helper_=
state *st, u8 *buf);
> + =C2=A0 =C2=A0 =C2=A0 s64 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 last_timestamp;
> +};
> +
> +void iio_sw_poll_func_th(struct iio_dev *indio_dev, s64 time);
> +void iio_sw_trigger_bh_to_ring(struct work_struct *work_s);
> +
> =C2=A0#else /* CONFIG_IIO_RING_BUFFER*/
> =C2=A0static inline void iio_ring_sw_register_funcs(struct iio_ring_acces=
s_funcs *ra)
> =C2=A0{};
> --
> 1.7.0.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at =C2=A0http://vger.kernel.org/majordomo-info.html
>

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

end of thread, other threads:[~2010-07-08  9:28 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-30 14:27 [RFC PATCH 0/5] Refactoring of ring buffer elements of Barry's recent RFC Jonathan Cameron
2010-06-30 14:27 ` [PATCH 1/5] staging:iio: Add a bits per element element to ring_generic allowing a general ring_sw_preenable_function Jonathan Cameron
2010-06-30 14:27 ` [PATCH 2/5] staging:iio: Make extensive use of iio_sw_ring_preenable Jonathan Cameron
2010-07-07 10:59   ` Barry Song
2010-06-30 14:27 ` [PATCH 3/5] staging:iio: Add iio_sw_ring_helper_state and functions to cover common case Jonathan Cameron
2010-07-08  9:28   ` Barry Song
2010-06-30 14:27 ` [PATCH 4/5] staging:iio:lis3l02dq use iio_sw_ring_helper_state and funcs Jonathan Cameron
2010-06-30 15:16   ` Jonathan Cameron
2010-06-30 14:27 ` [PATCH 5/5] staging:iio:adis16209 " Jonathan Cameron

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