All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer.
@ 2012-04-18 13:13 Jonathan Cameron
  2012-04-18 13:13 ` [PATCH 01/14] staging:iio:buffer trivial use of strtobool to remove dodgy equivalent Jonathan Cameron
                   ` (14 more replies)
  0 siblings, 15 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-04-18 13:13 UTC (permalink / raw)
  To: linux-iio; +Cc: lars, Jonathan Cameron

Sits on top of the series

[PATCH 00/16 V3] IIO: Make the value attribute optional for channels
 
This series consists of the first chunk of what was
[PATCH 1/4] staging:iio: make all buffer access pass through the buffer_list
As Lars-Peter rightly pointed out that patch was a whole mess of different
elements all bunged in together.

I believe this lot are all fairly uncontroversial unless I have trashed
a driver by accident. (which is entirely plausible).

There are a few temporary frigs in here to ensure some of the cached
values are correct before we put the real change in place.
For example the scan_timestamp gets cached both in the core and in the
buffers. For this change it would have made sense to drop it from the
buffers but then we'd just end up putting it back again a few patches
later.

Anyhow, please do take a look at what we have here.  Some are
trivial, but there are a good few driver reworks that could do
with testing (as I'll almost guarantee I've messed something up
ripping the original large patch apart!)

Thanks,

Jonathan Cameron 

Jonathan Cameron (14):
  staging:iio:buffer trivial use of strtobool to remove dodgy
    equivalent.
  staging:iio:buffer: pull computation of scan length into a utility
    function.
  staging:iio: scan_index_timestamp move to iio_dev from buffer
  staging:iio: add caching of the number of bytes in a scan.
  staging:iio:adc:ad7192 make use of iio_sw_buffer_preenable.
  staging:iio:adc:ad7298 use iio_sw_buffer_preenable to avoid code
    repitition.
  staging:iio:adc:ad7476 use iio_sw_buffer_preenable instead of local
    version.
  staging:iio:adc:ad7793 use iio_sw_buffer_preenable to avoid
    repitition.
  staging:iio:adc:ad7887 make use of iio_sw_buffer_preenable.
  staging:iio:adc:ad799x use iio_sw_buffer_preenable to avoid code
    repitiion
  staging:iio:meter:ad7758 use iio_sw_buffer_preenable to avoid code
    repition
  staging:iio:impedance-analyser make use of iio_sw_buffer_preenable
  staging:iio: Add caching of scan_timestamp to the core as well as
    buffers.
  staging:iio: pull out demux cleanup for a particular buffer.

 drivers/staging/iio/accel/adis16201_ring.c      |    5 +-
 drivers/staging/iio/accel/adis16203_ring.c      |    5 +-
 drivers/staging/iio/accel/adis16204_ring.c      |    5 +-
 drivers/staging/iio/accel/adis16209_ring.c      |    6 +-
 drivers/staging/iio/accel/adis16240_ring.c      |    5 +-
 drivers/staging/iio/accel/lis3l02dq_ring.c      |    6 +-
 drivers/staging/iio/adc/ad7192.c                |   24 ++------
 drivers/staging/iio/adc/ad7298.h                |    1 -
 drivers/staging/iio/adc/ad7298_ring.c           |   26 +++------
 drivers/staging/iio/adc/ad7476.h                |    1 -
 drivers/staging/iio/adc/ad7476_ring.c           |   38 +-----------
 drivers/staging/iio/adc/ad7606_ring.c           |    8 +--
 drivers/staging/iio/adc/ad7793.c                |   23 ++------
 drivers/staging/iio/adc/ad7887.h                |    1 -
 drivers/staging/iio/adc/ad7887_ring.c           |   25 ++------
 drivers/staging/iio/adc/ad799x.h                |    1 -
 drivers/staging/iio/adc/ad799x_ring.c           |   24 +-------
 drivers/staging/iio/adc/max1363_ring.c          |    4 +-
 drivers/staging/iio/buffer.h                    |    2 -
 drivers/staging/iio/gyro/adis16260_ring.c       |    5 +-
 drivers/staging/iio/iio.h                       |    6 ++
 drivers/staging/iio/iio_simple_dummy_buffer.c   |   11 +--
 drivers/staging/iio/impedance-analyzer/ad5933.c |   11 +---
 drivers/staging/iio/imu/adis16400_ring.c        |    4 +-
 drivers/staging/iio/industrialio-buffer.c       |   69 +++++++++++++++--------
 drivers/staging/iio/meter/ade7758_ring.c        |   22 ++-----
 26 files changed, 121 insertions(+), 217 deletions(-)


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

* [PATCH 01/14] staging:iio:buffer trivial use of strtobool to remove dodgy equivalent.
  2012-04-18 13:13 [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer Jonathan Cameron
@ 2012-04-18 13:13 ` Jonathan Cameron
  2012-04-18 13:13 ` [PATCH 02/14] staging:iio:buffer: pull computation of scan length into a utility function Jonathan Cameron
                   ` (13 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-04-18 13:13 UTC (permalink / raw)
  To: linux-iio; +Cc: lars, Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/industrialio-buffer.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/iio/industrialio-buffer.c b/drivers/staging/iio/industrialio-buffer.c
index 386ba76..59b0caf 100644
--- a/drivers/staging/iio/industrialio-buffer.c
+++ b/drivers/staging/iio/industrialio-buffer.c
@@ -124,13 +124,15 @@ static ssize_t iio_scan_el_store(struct device *dev,
 				 const char *buf,
 				 size_t len)
 {
-	int ret = 0;
+	int ret;
 	bool state;
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	struct iio_buffer *buffer = indio_dev->buffer;
 	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
 
-	state = !(buf[0] == '0');
+	ret = strtobool(buf, &state);
+	if (ret < 0)
+		return ret;
 	mutex_lock(&indio_dev->mlock);
 	if (iio_buffer_enabled(indio_dev)) {
 		ret = -EBUSY;
@@ -169,11 +171,14 @@ static ssize_t iio_scan_el_ts_store(struct device *dev,
 				    const char *buf,
 				    size_t len)
 {
-	int ret = 0;
+	int ret;
 	struct iio_dev *indio_dev = dev_get_drvdata(dev);
 	bool state;
 
-	state = !(buf[0] == '0');
+	ret = strtobool(buf, &state);
+	if (ret < 0)
+		return ret;
+
 	mutex_lock(&indio_dev->mlock);
 	if (iio_buffer_enabled(indio_dev)) {
 		ret = -EBUSY;
-- 
1.7.0.4


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

* [PATCH 02/14] staging:iio:buffer: pull computation of scan length into a utility function.
  2012-04-18 13:13 [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer Jonathan Cameron
  2012-04-18 13:13 ` [PATCH 01/14] staging:iio:buffer trivial use of strtobool to remove dodgy equivalent Jonathan Cameron
@ 2012-04-18 13:13 ` Jonathan Cameron
  2012-04-18 13:13 ` [PATCH 03/14] staging:iio: scan_index_timestamp move to iio_dev from buffer Jonathan Cameron
                   ` (12 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-04-18 13:13 UTC (permalink / raw)
  To: linux-iio; +Cc: lars, Jonathan Cameron

Principal reason is to make later patches more coherent and easier to review
but this set in itself separates a logical entity out nicely wihin the code.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/industrialio-buffer.c |   28 ++++++++++++++++++++--------
 1 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/iio/industrialio-buffer.c b/drivers/staging/iio/industrialio-buffer.c
index 59b0caf..639b41a 100644
--- a/drivers/staging/iio/industrialio-buffer.c
+++ b/drivers/staging/iio/industrialio-buffer.c
@@ -508,30 +508,41 @@ static const unsigned long *iio_scan_mask_match(const unsigned long *av_masks,
 	return NULL;
 }
 
-int iio_sw_buffer_preenable(struct iio_dev *indio_dev)
+static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask,
+				  bool timestamp)
 {
-	struct iio_buffer *buffer = indio_dev->buffer;
 	const struct iio_chan_spec *ch;
 	unsigned bytes = 0;
 	int length, i;
-	dev_dbg(&indio_dev->dev, "%s\n", __func__);
 
 	/* How much space will the demuxed element take? */
-	for_each_set_bit(i, buffer->scan_mask,
+	for_each_set_bit(i, mask,
 			 indio_dev->masklength) {
 		ch = iio_find_channel_from_si(indio_dev, i);
-		length = ch->scan_type.storagebits/8;
+		length = ch->scan_type.storagebits / 8;
 		bytes = ALIGN(bytes, length);
 		bytes += length;
 	}
-	if (buffer->scan_timestamp) {
+	if (timestamp) {
 		ch = iio_find_channel_from_si(indio_dev,
-					      buffer->scan_index_timestamp);
-		length = ch->scan_type.storagebits/8;
+					      indio_dev
+					      ->buffer->scan_index_timestamp);
+		length = ch->scan_type.storagebits / 8;
 		bytes = ALIGN(bytes, length);
 		bytes += length;
 	}
+	return bytes;
+}
+
+int iio_sw_buffer_preenable(struct iio_dev *indio_dev)
+{
+	struct iio_buffer *buffer = indio_dev->buffer;
+	unsigned bytes;
+	dev_dbg(&indio_dev->dev, "%s\n", __func__);
+
+	/* How much space will the demuxed element take? */
+	bytes = iio_compute_scan_bytes(indio_dev, buffer->scan_mask,
+				       buffer->scan_timestamp);
 	buffer->access->set_bytes_per_datum(buffer, bytes);
 
 	/* What scan mask do we actually have ?*/
-- 
1.7.0.4


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

* [PATCH 03/14] staging:iio: scan_index_timestamp move to iio_dev from buffer
  2012-04-18 13:13 [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer Jonathan Cameron
  2012-04-18 13:13 ` [PATCH 01/14] staging:iio:buffer trivial use of strtobool to remove dodgy equivalent Jonathan Cameron
  2012-04-18 13:13 ` [PATCH 02/14] staging:iio:buffer: pull computation of scan length into a utility function Jonathan Cameron
@ 2012-04-18 13:13 ` Jonathan Cameron
  2012-04-18 13:13 ` [PATCH 04/14] staging:iio: add caching of the number of bytes in a scan Jonathan Cameron
                   ` (11 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-04-18 13:13 UTC (permalink / raw)
  To: linux-iio; +Cc: lars, Jonathan Cameron

This is just a locally cached value that is device specific (rather
than buffer specific.) Hence it wants to come out of the buffer before
we add multiple buffer support.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/buffer.h              |    2 --
 drivers/staging/iio/iio.h                 |    2 ++
 drivers/staging/iio/industrialio-buffer.c |    7 +++----
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/staging/iio/buffer.h b/drivers/staging/iio/buffer.h
index df2046d..3d3ea9e 100644
--- a/drivers/staging/iio/buffer.h
+++ b/drivers/staging/iio/buffer.h
@@ -56,7 +56,6 @@ struct iio_buffer_access_funcs {
  * @scan_el_attrs:	[DRIVER] control of scan elements if that scan mode
  *			control method is used
  * @scan_mask:		[INTERN] bitmask used in masking scan mode elements
- * @scan_index_timestamp:[INTERN] cache of the index to the timestamp
  * @scan_timestamp:	[INTERN] does the scan mode include a timestamp
  * @access:		[DRIVER] buffer access functions associated with the
  *			implementation.
@@ -74,7 +73,6 @@ struct iio_buffer {
 	struct attribute_group			*scan_el_attrs;
 	long					*scan_mask;
 	bool					scan_timestamp;
-	unsigned				scan_index_timestamp;
 	const struct iio_buffer_access_funcs	*access;
 	struct list_head			scan_el_dev_attr_list;
 	struct attribute_group			scan_el_group;
diff --git a/drivers/staging/iio/iio.h b/drivers/staging/iio/iio.h
index a562763..6832c98 100644
--- a/drivers/staging/iio/iio.h
+++ b/drivers/staging/iio/iio.h
@@ -305,6 +305,7 @@ struct iio_buffer_setup_ops {
  * @masklength:		[INTERN] the length of the mask established from
  *			channels
  * @active_scan_mask:	[INTERN] union of all scan masks requested by buffers
+ * @scan_index_timestamp:[INTERN] cache of the index to the timestamp
  * @trig:		[INTERN] current device trigger (buffer modes)
  * @pollfunc:		[DRIVER] function run on trigger being received
  * @channels:		[DRIVER] channel specification structure table
@@ -339,6 +340,7 @@ struct iio_dev {
 	const unsigned long		*available_scan_masks;
 	unsigned			masklength;
 	const unsigned long		*active_scan_mask;
+	unsigned			scan_index_timestamp;
 	struct iio_trigger		*trig;
 	struct iio_poll_func		*pollfunc;
 
diff --git a/drivers/staging/iio/industrialio-buffer.c b/drivers/staging/iio/industrialio-buffer.c
index 639b41a..efa44c4 100644
--- a/drivers/staging/iio/industrialio-buffer.c
+++ b/drivers/staging/iio/industrialio-buffer.c
@@ -296,7 +296,7 @@ int iio_buffer_register(struct iio_dev *indio_dev,
 				goto error_cleanup_dynamic;
 			attrcount += ret;
 			if (channels[i].type == IIO_TIMESTAMP)
-				buffer->scan_index_timestamp =
+				indio_dev->scan_index_timestamp =
 					channels[i].scan_index;
 		}
 		if (indio_dev->masklength && buffer->scan_mask == NULL) {
@@ -525,8 +525,7 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask,
 	}
 	if (timestamp) {
 		ch = iio_find_channel_from_si(indio_dev,
-					      indio_dev
-					      ->buffer->scan_index_timestamp);
+					      indio_dev->scan_index_timestamp);
 		length = ch->scan_type.storagebits / 8;
 		bytes = ALIGN(bytes, length);
 		bytes += length;
@@ -721,7 +720,7 @@ int iio_update_demux(struct iio_dev *indio_dev)
 			goto error_clear_mux_table;
 		}
 		ch = iio_find_channel_from_si(indio_dev,
-			buffer->scan_index_timestamp);
+			indio_dev->scan_index_timestamp);
 		length = ch->scan_type.storagebits/8;
 		if (out_loc % length)
 			out_loc += length - out_loc % length;
-- 
1.7.0.4


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

* [PATCH 04/14] staging:iio: add caching of the number of bytes in a scan.
  2012-04-18 13:13 [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer Jonathan Cameron
                   ` (2 preceding siblings ...)
  2012-04-18 13:13 ` [PATCH 03/14] staging:iio: scan_index_timestamp move to iio_dev from buffer Jonathan Cameron
@ 2012-04-18 13:13 ` Jonathan Cameron
       [not found]   ` <4F91944F.3070701@metafoo.de>
  2012-04-18 13:13 ` [PATCH 05/14] staging:iio:adc:ad7192 make use of iio_sw_buffer_preenable Jonathan Cameron
                   ` (10 subsequent siblings)
  14 siblings, 1 reply; 17+ messages in thread
From: Jonathan Cameron @ 2012-04-18 13:13 UTC (permalink / raw)
  To: linux-iio; +Cc: lars, Jonathan Cameron

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/adis16201_ring.c    |    3 +--
 drivers/staging/iio/accel/adis16203_ring.c    |    3 +--
 drivers/staging/iio/accel/adis16204_ring.c    |    3 +--
 drivers/staging/iio/accel/adis16209_ring.c    |    4 +---
 drivers/staging/iio/accel/adis16240_ring.c    |    3 +--
 drivers/staging/iio/accel/lis3l02dq_ring.c    |    4 ++--
 drivers/staging/iio/adc/ad7606_ring.c         |    3 +--
 drivers/staging/iio/gyro/adis16260_ring.c     |    3 +--
 drivers/staging/iio/iio.h                     |    2 ++
 drivers/staging/iio/iio_simple_dummy_buffer.c |    9 +++------
 drivers/staging/iio/imu/adis16400_ring.c      |    4 ++--
 drivers/staging/iio/industrialio-buffer.c     |    6 +++---
 12 files changed, 19 insertions(+), 28 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201_ring.c b/drivers/staging/iio/accel/adis16201_ring.c
index 97f9e6b..1370e32 100644
--- a/drivers/staging/iio/accel/adis16201_ring.c
+++ b/drivers/staging/iio/accel/adis16201_ring.c
@@ -66,9 +66,8 @@ static irqreturn_t adis16201_trigger_handler(int irq, void *p)
 
 	int i = 0;
 	s16 *data;
-	size_t datasize = ring->access->get_bytes_per_datum(ring);
 
-	data = kmalloc(datasize, GFP_KERNEL);
+	data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
 	if (data == NULL) {
 		dev_err(&st->us->dev, "memory alloc failed in ring bh");
 		return -ENOMEM;
diff --git a/drivers/staging/iio/accel/adis16203_ring.c b/drivers/staging/iio/accel/adis16203_ring.c
index 6a8963d..86f4efb 100644
--- a/drivers/staging/iio/accel/adis16203_ring.c
+++ b/drivers/staging/iio/accel/adis16203_ring.c
@@ -66,9 +66,8 @@ static irqreturn_t adis16203_trigger_handler(int irq, void *p)
 
 	int i = 0;
 	s16 *data;
-	size_t datasize = ring->access->get_bytes_per_datum(ring);
 
-	data = kmalloc(datasize, GFP_KERNEL);
+	data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
 	if (data == NULL) {
 		dev_err(&st->us->dev, "memory alloc failed in ring bh");
 		return -ENOMEM;
diff --git a/drivers/staging/iio/accel/adis16204_ring.c b/drivers/staging/iio/accel/adis16204_ring.c
index 5c8ab73..34ef11f 100644
--- a/drivers/staging/iio/accel/adis16204_ring.c
+++ b/drivers/staging/iio/accel/adis16204_ring.c
@@ -63,9 +63,8 @@ static irqreturn_t adis16204_trigger_handler(int irq, void *p)
 	struct iio_buffer *ring = indio_dev->buffer;
 	int i = 0;
 	s16 *data;
-	size_t datasize = ring->access->get_bytes_per_datum(ring);
 
-	data = kmalloc(datasize, GFP_KERNEL);
+	data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
 	if (data == NULL) {
 		dev_err(&st->us->dev, "memory alloc failed in ring bh");
 		return -ENOMEM;
diff --git a/drivers/staging/iio/accel/adis16209_ring.c b/drivers/staging/iio/accel/adis16209_ring.c
index 57254b6..1424d48 100644
--- a/drivers/staging/iio/accel/adis16209_ring.c
+++ b/drivers/staging/iio/accel/adis16209_ring.c
@@ -61,12 +61,10 @@ static irqreturn_t adis16209_trigger_handler(int irq, void *p)
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct adis16209_state *st = iio_priv(indio_dev);
 	struct iio_buffer *ring = indio_dev->buffer;
-
 	int i = 0;
 	s16 *data;
-	size_t datasize = ring->access->get_bytes_per_datum(ring);
 
-	data = kmalloc(datasize , GFP_KERNEL);
+	data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
 	if (data == NULL) {
 		dev_err(&st->us->dev, "memory alloc failed in ring bh");
 		return -ENOMEM;
diff --git a/drivers/staging/iio/accel/adis16240_ring.c b/drivers/staging/iio/accel/adis16240_ring.c
index 43ba84e..9ff0634 100644
--- a/drivers/staging/iio/accel/adis16240_ring.c
+++ b/drivers/staging/iio/accel/adis16240_ring.c
@@ -61,9 +61,8 @@ static irqreturn_t adis16240_trigger_handler(int irq, void *p)
 
 	int i = 0;
 	s16 *data;
-	size_t datasize = ring->access->get_bytes_per_datum(ring);
 
-	data = kmalloc(datasize, GFP_KERNEL);
+	data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
 	if (data == NULL) {
 		dev_err(&st->us->dev, "memory alloc failed in ring bh");
 		return -ENOMEM;
diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c
index 0fc3973..3bdc102 100644
--- a/drivers/staging/iio/accel/lis3l02dq_ring.c
+++ b/drivers/staging/iio/accel/lis3l02dq_ring.c
@@ -137,9 +137,9 @@ static irqreturn_t lis3l02dq_trigger_handler(int irq, void *p)
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct iio_buffer *buffer = indio_dev->buffer;
 	int len = 0;
-	size_t datasize = buffer->access->get_bytes_per_datum(buffer);
-	char *data = kmalloc(datasize, GFP_KERNEL);
+	char *data;
 
+	data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
 	if (data == NULL) {
 		dev_err(indio_dev->dev.parent,
 			"memory alloc failed in buffer bh");
diff --git a/drivers/staging/iio/adc/ad7606_ring.c b/drivers/staging/iio/adc/ad7606_ring.c
index 1ef9fbc..6cbf242 100644
--- a/drivers/staging/iio/adc/ad7606_ring.c
+++ b/drivers/staging/iio/adc/ad7606_ring.c
@@ -51,8 +51,7 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
 	__u8 *buf;
 	int ret;
 
-	buf = kzalloc(ring->access->get_bytes_per_datum(ring),
-		      GFP_KERNEL);
+	buf = kzalloc(indio_dev->scan_bytes, GFP_KERNEL);
 	if (buf == NULL)
 		return;
 
diff --git a/drivers/staging/iio/gyro/adis16260_ring.c b/drivers/staging/iio/gyro/adis16260_ring.c
index 711f151..18fc73c 100644
--- a/drivers/staging/iio/gyro/adis16260_ring.c
+++ b/drivers/staging/iio/gyro/adis16260_ring.c
@@ -66,9 +66,8 @@ static irqreturn_t adis16260_trigger_handler(int irq, void *p)
 	struct iio_buffer *ring = indio_dev->buffer;
 	int i = 0;
 	s16 *data;
-	size_t datasize = ring->access->get_bytes_per_datum(ring);
 
-	data = kmalloc(datasize , GFP_KERNEL);
+	data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
 	if (data == NULL) {
 		dev_err(&st->us->dev, "memory alloc failed in ring bh");
 		return -ENOMEM;
diff --git a/drivers/staging/iio/iio.h b/drivers/staging/iio/iio.h
index 6832c98..7a10aed 100644
--- a/drivers/staging/iio/iio.h
+++ b/drivers/staging/iio/iio.h
@@ -299,6 +299,7 @@ struct iio_buffer_setup_ops {
  *			and owner
  * @event_interface:	[INTERN] event chrdevs associated with interrupt lines
  * @buffer:		[DRIVER] any buffer present
+ * @scan_bytes:		[INTERN] num bytes captured to be fed to buffer demux
  * @mlock:		[INTERN] lock used to prevent simultaneous device state
  *			changes
  * @available_scan_masks: [DRIVER] optional array of allowed bitmasks
@@ -335,6 +336,7 @@ struct iio_dev {
 	struct iio_event_interface	*event_interface;
 
 	struct iio_buffer		*buffer;
+	int				scan_bytes;
 	struct mutex			mlock;
 
 	const unsigned long		*available_scan_masks;
diff --git a/drivers/staging/iio/iio_simple_dummy_buffer.c b/drivers/staging/iio/iio_simple_dummy_buffer.c
index bb4daf7..61a2622 100644
--- a/drivers/staging/iio/iio_simple_dummy_buffer.c
+++ b/drivers/staging/iio/iio_simple_dummy_buffer.c
@@ -48,12 +48,9 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
 	struct iio_dev *indio_dev = pf->indio_dev;
 	struct iio_buffer *buffer = indio_dev->buffer;
 	int len = 0;
-	/*
-	 * The datasize is obtained from the buffer. It was stored when
-	 * the preenable setup function was called.
-	 */
-	size_t datasize = buffer->access->get_bytes_per_datum(buffer);
-	u16 *data = kmalloc(datasize, GFP_KERNEL);
+	u16 *data;
+
+	data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
 	if (data == NULL)
 		return -ENOMEM;
 
diff --git a/drivers/staging/iio/imu/adis16400_ring.c b/drivers/staging/iio/imu/adis16400_ring.c
index 8daa038..d964004 100644
--- a/drivers/staging/iio/imu/adis16400_ring.c
+++ b/drivers/staging/iio/imu/adis16400_ring.c
@@ -119,12 +119,12 @@ static irqreturn_t adis16400_trigger_handler(int irq, void *p)
 	struct iio_buffer *ring = indio_dev->buffer;
 	int i = 0, j, ret = 0;
 	s16 *data;
-	size_t datasize = ring->access->get_bytes_per_datum(ring);
+
 	/* Asumption that long is enough for maximum channels */
 	unsigned long mask = *indio_dev->active_scan_mask;
 	int scan_count = bitmap_weight(indio_dev->active_scan_mask,
 				       indio_dev->masklength);
-	data = kmalloc(datasize , GFP_KERNEL);
+	data = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
 	if (data == NULL) {
 		dev_err(&st->us->dev, "memory alloc failed in ring bh");
 		return -ENOMEM;
diff --git a/drivers/staging/iio/industrialio-buffer.c b/drivers/staging/iio/industrialio-buffer.c
index efa44c4..f6cb0ab 100644
--- a/drivers/staging/iio/industrialio-buffer.c
+++ b/drivers/staging/iio/industrialio-buffer.c
@@ -536,13 +536,13 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask,
 int iio_sw_buffer_preenable(struct iio_dev *indio_dev)
 {
 	struct iio_buffer *buffer = indio_dev->buffer;
-	unsigned bytes = 0;
 	dev_dbg(&indio_dev->dev, "%s\n", __func__);
 
 	/* How much space will the demuxed element take? */
-	bytes = iio_compute_scan_bytes(indio_dev, buffer->scan_mask,
+	indio_dev->scan_bytes =
+		iio_compute_scan_bytes(indio_dev, buffer->scan_mask,
 				       buffer->scan_timestamp);
-	buffer->access->set_bytes_per_datum(buffer, bytes);
+	buffer->access->set_bytes_per_datum(buffer, indio_dev->scan_bytes);
 
 	/* What scan mask do we actually have ?*/
 	if (indio_dev->available_scan_masks)
-- 
1.7.0.4


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

* [PATCH 05/14] staging:iio:adc:ad7192 make use of iio_sw_buffer_preenable.
  2012-04-18 13:13 [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer Jonathan Cameron
                   ` (3 preceding siblings ...)
  2012-04-18 13:13 ` [PATCH 04/14] staging:iio: add caching of the number of bytes in a scan Jonathan Cameron
@ 2012-04-18 13:13 ` Jonathan Cameron
  2012-04-18 13:13 ` [PATCH 06/14] staging:iio:adc:ad7298 use iio_sw_buffer_preenable to avoid code repitition Jonathan Cameron
                   ` (9 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-04-18 13:13 UTC (permalink / raw)
  To: linux-iio; +Cc: lars, Jonathan Cameron

This is not a fast path, so although the original code was more consise
use the generic case to cut down on code repitition.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/adc/ad7192.c |   22 +++++-----------------
 1 files changed, 5 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
index feb81f6..25ef3c3 100644
--- a/drivers/staging/iio/adc/ad7192.c
+++ b/drivers/staging/iio/adc/ad7192.c
@@ -456,31 +456,19 @@ out:
 static int ad7192_ring_preenable(struct iio_dev *indio_dev)
 {
 	struct ad7192_state *st = iio_priv(indio_dev);
-	struct iio_buffer *ring = indio_dev->buffer;
-	size_t d_size;
 	unsigned channel;
+	int ret;
 
 	if (bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
 		return -EINVAL;
 
+	ret = iio_sw_buffer_preenable(indio_dev);
+	if (ret < 0)
+		return ret;
+
 	channel = find_first_bit(indio_dev->active_scan_mask,
 				 indio_dev->masklength);
 
-	d_size = bitmap_weight(indio_dev->active_scan_mask,
-			       indio_dev->masklength) *
-		 indio_dev->channels[0].scan_type.storagebits / 8;
-
-	if (ring->scan_timestamp) {
-		d_size += sizeof(s64);
-
-		if (d_size % sizeof(s64))
-			d_size += sizeof(s64) - (d_size % sizeof(s64));
-	}
-
-	if (indio_dev->buffer->access->set_bytes_per_datum)
-		indio_dev->buffer->access->
-			set_bytes_per_datum(indio_dev->buffer, d_size);
-
 	st->mode  = (st->mode & ~AD7192_MODE_SEL(-1)) |
 		    AD7192_MODE_SEL(AD7192_MODE_CONT);
 	st->conf  = (st->conf & ~AD7192_CONF_CHAN(-1)) |
-- 
1.7.0.4


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

* [PATCH 06/14] staging:iio:adc:ad7298 use iio_sw_buffer_preenable to avoid code repitition.
  2012-04-18 13:13 [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer Jonathan Cameron
                   ` (4 preceding siblings ...)
  2012-04-18 13:13 ` [PATCH 05/14] staging:iio:adc:ad7192 make use of iio_sw_buffer_preenable Jonathan Cameron
@ 2012-04-18 13:13 ` Jonathan Cameron
  2012-04-18 13:13 ` [PATCH 07/14] staging:iio:adc:ad7476 use iio_sw_buffer_preenable instead of local version Jonathan Cameron
                   ` (8 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-04-18 13:13 UTC (permalink / raw)
  To: linux-iio; +Cc: lars, Jonathan Cameron

Here some addition elements are needed, but this generic function cuts
down on the amount of code.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/adc/ad7298.h      |    1 -
 drivers/staging/iio/adc/ad7298_ring.c |   24 ++++++++----------------
 2 files changed, 8 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7298.h b/drivers/staging/iio/adc/ad7298.h
index a0e5dea..5051a7e 100644
--- a/drivers/staging/iio/adc/ad7298.h
+++ b/drivers/staging/iio/adc/ad7298.h
@@ -38,7 +38,6 @@ struct ad7298_platform_data {
 struct ad7298_state {
 	struct spi_device		*spi;
 	struct regulator		*reg;
-	size_t				d_size;
 	u16				int_vref_mv;
 	unsigned			ext_ref;
 	struct spi_transfer		ring_xfer[10];
diff --git a/drivers/staging/iio/adc/ad7298_ring.c b/drivers/staging/iio/adc/ad7298_ring.c
index feeb0ee..5c13690 100644
--- a/drivers/staging/iio/adc/ad7298_ring.c
+++ b/drivers/staging/iio/adc/ad7298_ring.c
@@ -28,25 +28,17 @@
 static int ad7298_ring_preenable(struct iio_dev *indio_dev)
 {
 	struct ad7298_state *st = iio_priv(indio_dev);
-	struct iio_buffer *ring = indio_dev->buffer;
-	size_t d_size;
 	int i, m;
 	unsigned short command;
-	int scan_count = bitmap_weight(indio_dev->active_scan_mask,
-				       indio_dev->masklength);
-	d_size = scan_count * (AD7298_STORAGE_BITS / 8);
-
-	if (ring->scan_timestamp) {
-		d_size += sizeof(s64);
-
-		if (d_size % sizeof(s64))
-			d_size += sizeof(s64) - (d_size % sizeof(s64));
-	}
+	int scan_count, ret;
 
-	if (ring->access->set_bytes_per_datum)
-		ring->access->set_bytes_per_datum(ring, d_size);
+	ret = iio_sw_buffer_preenable(indio_dev);
+	if (ret < 0)
+		return ret;
 
-	st->d_size = d_size;
+	/* Now compute overall size */
+	scan_count = bitmap_weight(indio_dev->active_scan_mask,
+				   indio_dev->masklength);
 
 	command = AD7298_WRITE | st->ext_ref;
 
@@ -102,7 +94,7 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
 
 	if (ring->scan_timestamp) {
 		time_ns = iio_get_time_ns();
-		memcpy((u8 *)buf + st->d_size - sizeof(s64),
+		memcpy((u8 *)buf + indio_dev->scan_bytes - sizeof(s64),
 			&time_ns, sizeof(time_ns));
 	}
 
-- 
1.7.0.4


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

* [PATCH 07/14] staging:iio:adc:ad7476 use iio_sw_buffer_preenable instead of local version.
  2012-04-18 13:13 [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer Jonathan Cameron
                   ` (5 preceding siblings ...)
  2012-04-18 13:13 ` [PATCH 06/14] staging:iio:adc:ad7298 use iio_sw_buffer_preenable to avoid code repitition Jonathan Cameron
@ 2012-04-18 13:13 ` Jonathan Cameron
  2012-04-18 13:13 ` [PATCH 08/14] staging:iio:adc:ad7793 use iio_sw_buffer_preenable to avoid repitition Jonathan Cameron
                   ` (7 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-04-18 13:13 UTC (permalink / raw)
  To: linux-iio; +Cc: lars, Jonathan Cameron

Now the generic version caches the scan size the version in this driver
is redundant.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/adc/ad7476.h      |    1 -
 drivers/staging/iio/adc/ad7476_ring.c |   36 ++------------------------------
 2 files changed, 3 insertions(+), 34 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7476.h b/drivers/staging/iio/adc/ad7476.h
index 27f696c..b1dd931 100644
--- a/drivers/staging/iio/adc/ad7476.h
+++ b/drivers/staging/iio/adc/ad7476.h
@@ -27,7 +27,6 @@ struct ad7476_state {
 	struct spi_device		*spi;
 	const struct ad7476_chip_info	*chip_info;
 	struct regulator		*reg;
-	size_t				d_size;
 	u16				int_vref_mv;
 	struct spi_transfer		xfer;
 	struct spi_message		msg;
diff --git a/drivers/staging/iio/adc/ad7476_ring.c b/drivers/staging/iio/adc/ad7476_ring.c
index d6af6c0..a090bc3 100644
--- a/drivers/staging/iio/adc/ad7476_ring.c
+++ b/drivers/staging/iio/adc/ad7476_ring.c
@@ -20,36 +20,6 @@
 
 #include "ad7476.h"
 
-/**
- * ad7476_ring_preenable() setup the parameters of the ring before enabling
- *
- * The complex nature of the setting of the number of bytes per datum is due
- * to this driver currently ensuring that the timestamp is stored at an 8
- * byte boundary.
- **/
-static int ad7476_ring_preenable(struct iio_dev *indio_dev)
-{
-	struct ad7476_state *st = iio_priv(indio_dev);
-	struct iio_buffer *ring = indio_dev->buffer;
-
-	st->d_size = bitmap_weight(indio_dev->active_scan_mask,
-				   indio_dev->masklength) *
-		st->chip_info->channel[0].scan_type.storagebits / 8;
-
-	if (ring->scan_timestamp) {
-		st->d_size += sizeof(s64);
-
-		if (st->d_size % sizeof(s64))
-			st->d_size += sizeof(s64) - (st->d_size % sizeof(s64));
-	}
-
-	if (indio_dev->buffer->access->set_bytes_per_datum)
-		indio_dev->buffer->access->
-			set_bytes_per_datum(indio_dev->buffer, st->d_size);
-
-	return 0;
-}
-
 static irqreturn_t ad7476_trigger_handler(int irq, void  *p)
 {
 	struct iio_poll_func *pf = p;
@@ -59,7 +29,7 @@ static irqreturn_t ad7476_trigger_handler(int irq, void  *p)
 	__u8 *rxbuf;
 	int b_sent;
 
-	rxbuf = kzalloc(st->d_size, GFP_KERNEL);
+	rxbuf = kzalloc(indio_dev->scan_bytes, GFP_KERNEL);
 	if (rxbuf == NULL)
 		return -ENOMEM;
 
@@ -71,7 +41,7 @@ static irqreturn_t ad7476_trigger_handler(int irq, void  *p)
 	time_ns = iio_get_time_ns();
 
 	if (indio_dev->buffer->scan_timestamp)
-		memcpy(rxbuf + st->d_size - sizeof(s64),
+		memcpy(rxbuf + indio_dev->scan_bytes - sizeof(s64),
 			&time_ns, sizeof(time_ns));
 
 	indio_dev->buffer->access->store_to(indio_dev->buffer, rxbuf, time_ns);
@@ -83,7 +53,7 @@ done:
 }
 
 static const struct iio_buffer_setup_ops ad7476_ring_setup_ops = {
-	.preenable = &ad7476_ring_preenable,
+	.preenable = &iio_sw_buffer_preenable,
 	.postenable = &iio_triggered_buffer_postenable,
 	.predisable = &iio_triggered_buffer_predisable,
 };
-- 
1.7.0.4


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

* [PATCH 08/14] staging:iio:adc:ad7793 use iio_sw_buffer_preenable to avoid repitition.
  2012-04-18 13:13 [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer Jonathan Cameron
                   ` (6 preceding siblings ...)
  2012-04-18 13:13 ` [PATCH 07/14] staging:iio:adc:ad7476 use iio_sw_buffer_preenable instead of local version Jonathan Cameron
@ 2012-04-18 13:13 ` Jonathan Cameron
  2012-04-18 13:13 ` [PATCH 09/14] staging:iio:adc:ad7887 make use of iio_sw_buffer_preenable Jonathan Cameron
                   ` (6 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-04-18 13:13 UTC (permalink / raw)
  To: linux-iio; +Cc: lars, Jonathan Cameron

Now the generic function caches the scan size a lot of what was here
was redundant and is removed.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/adc/ad7793.c |   21 ++++-----------------
 1 files changed, 4 insertions(+), 17 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7793.c b/drivers/staging/iio/adc/ad7793.c
index 9d21e39..2aeeaa2 100644
--- a/drivers/staging/iio/adc/ad7793.c
+++ b/drivers/staging/iio/adc/ad7793.c
@@ -319,31 +319,18 @@ out:
 static int ad7793_ring_preenable(struct iio_dev *indio_dev)
 {
 	struct ad7793_state *st = iio_priv(indio_dev);
-	struct iio_buffer *ring = indio_dev->buffer;
-	size_t d_size;
 	unsigned channel;
+	int ret;
 
 	if (bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
 		return -EINVAL;
+	ret = iio_sw_buffer_preenable(indio_dev);
+	if (ret < 0)
+		return ret;
 
 	channel = find_first_bit(indio_dev->active_scan_mask,
 				 indio_dev->masklength);
 
-	d_size = bitmap_weight(indio_dev->active_scan_mask,
-			       indio_dev->masklength) *
-		indio_dev->channels[0].scan_type.storagebits / 8;
-
-	if (ring->scan_timestamp) {
-		d_size += sizeof(s64);
-
-		if (d_size % sizeof(s64))
-			d_size += sizeof(s64) - (d_size % sizeof(s64));
-	}
-
-	if (indio_dev->buffer->access->set_bytes_per_datum)
-		indio_dev->buffer->access->
-			set_bytes_per_datum(indio_dev->buffer, d_size);
-
 	st->mode  = (st->mode & ~AD7793_MODE_SEL(-1)) |
 		    AD7793_MODE_SEL(AD7793_MODE_CONT);
 	st->conf  = (st->conf & ~AD7793_CONF_CHAN(-1)) |
-- 
1.7.0.4


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

* [PATCH 09/14] staging:iio:adc:ad7887 make use of iio_sw_buffer_preenable.
  2012-04-18 13:13 [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer Jonathan Cameron
                   ` (7 preceding siblings ...)
  2012-04-18 13:13 ` [PATCH 08/14] staging:iio:adc:ad7793 use iio_sw_buffer_preenable to avoid repitition Jonathan Cameron
@ 2012-04-18 13:13 ` Jonathan Cameron
  2012-04-18 13:13 ` [PATCH 10/14] staging:iio:adc:ad799x use iio_sw_buffer_preenable to avoid code repitiion Jonathan Cameron
                   ` (5 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-04-18 13:13 UTC (permalink / raw)
  To: linux-iio; +Cc: lars, Jonathan Cameron

Using this generic function cuts down on repeated code at the cost
of some computation in a slow path.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/adc/ad7887.h      |    1 -
 drivers/staging/iio/adc/ad7887_ring.c |   23 ++++++-----------------
 2 files changed, 6 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/iio/adc/ad7887.h b/drivers/staging/iio/adc/ad7887.h
index bc53b65..2e09e54 100644
--- a/drivers/staging/iio/adc/ad7887.h
+++ b/drivers/staging/iio/adc/ad7887.h
@@ -63,7 +63,6 @@ struct ad7887_state {
 	struct spi_device		*spi;
 	const struct ad7887_chip_info	*chip_info;
 	struct regulator		*reg;
-	size_t				d_size;
 	u16				int_vref_mv;
 	struct spi_transfer		xfer[4];
 	struct spi_message		msg[3];
diff --git a/drivers/staging/iio/adc/ad7887_ring.c b/drivers/staging/iio/adc/ad7887_ring.c
index d180907..442994e 100644
--- a/drivers/staging/iio/adc/ad7887_ring.c
+++ b/drivers/staging/iio/adc/ad7887_ring.c
@@ -29,22 +29,11 @@
 static int ad7887_ring_preenable(struct iio_dev *indio_dev)
 {
 	struct ad7887_state *st = iio_priv(indio_dev);
-	struct iio_buffer *ring = indio_dev->buffer;
-
-	st->d_size = bitmap_weight(indio_dev->active_scan_mask,
-				   indio_dev->masklength) *
-		st->chip_info->channel[0].scan_type.storagebits / 8;
-
-	if (ring->scan_timestamp) {
-		st->d_size += sizeof(s64);
-
-		if (st->d_size % sizeof(s64))
-			st->d_size += sizeof(s64) - (st->d_size % sizeof(s64));
-	}
+	int ret;
 
-	if (indio_dev->buffer->access->set_bytes_per_datum)
-		indio_dev->buffer->access->
-			set_bytes_per_datum(indio_dev->buffer, st->d_size);
+	ret = iio_sw_buffer_preenable(indio_dev);
+	if (ret < 0)
+		return ret;
 
 	/* We know this is a single long so can 'cheat' */
 	switch (*indio_dev->active_scan_mask) {
@@ -92,7 +81,7 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p)
 					   indio_dev->masklength) *
 		st->chip_info->channel[0].scan_type.storagebits / 8;
 
-	buf = kzalloc(st->d_size, GFP_KERNEL);
+	buf = kzalloc(indio_dev->scan_bytes, GFP_KERNEL);
 	if (buf == NULL)
 		return -ENOMEM;
 
@@ -104,7 +93,7 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p)
 
 	memcpy(buf, st->data, bytes);
 	if (ring->scan_timestamp)
-		memcpy(buf + st->d_size - sizeof(s64),
+		memcpy(buf + indio_dev->scan_bytes - sizeof(s64),
 		       &time_ns, sizeof(time_ns));
 
 	indio_dev->buffer->access->store_to(indio_dev->buffer, buf, time_ns);
-- 
1.7.0.4


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

* [PATCH 10/14] staging:iio:adc:ad799x use iio_sw_buffer_preenable to avoid code repitiion
  2012-04-18 13:13 [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer Jonathan Cameron
                   ` (8 preceding siblings ...)
  2012-04-18 13:13 ` [PATCH 09/14] staging:iio:adc:ad7887 make use of iio_sw_buffer_preenable Jonathan Cameron
@ 2012-04-18 13:13 ` Jonathan Cameron
  2012-04-18 13:13 ` [PATCH 11/14] staging:iio:meter:ad7758 use iio_sw_buffer_preenable to avoid code repition Jonathan Cameron
                   ` (4 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-04-18 13:13 UTC (permalink / raw)
  To: linux-iio; +Cc: lars, Jonathan Cameron

Using this generic function cuts down on repeated code at the cost of
a little overhead in a slow path.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/adc/ad799x.h      |    1 -
 drivers/staging/iio/adc/ad799x_ring.c |   22 +++-------------------
 2 files changed, 3 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/iio/adc/ad799x.h b/drivers/staging/iio/adc/ad799x.h
index 356f690..99f8abe 100644
--- a/drivers/staging/iio/adc/ad799x.h
+++ b/drivers/staging/iio/adc/ad799x.h
@@ -104,7 +104,6 @@ struct ad799x_chip_info {
 struct ad799x_state {
 	struct i2c_client		*client;
 	const struct ad799x_chip_info	*chip_info;
-	size_t				d_size;
 	struct iio_trigger		*trig;
 	struct regulator		*reg;
 	u16				int_vref_mv;
diff --git a/drivers/staging/iio/adc/ad799x_ring.c b/drivers/staging/iio/adc/ad799x_ring.c
index 069765c..dfdbf92 100644
--- a/drivers/staging/iio/adc/ad799x_ring.c
+++ b/drivers/staging/iio/adc/ad799x_ring.c
@@ -32,9 +32,7 @@
  **/
 static int ad799x_ring_preenable(struct iio_dev *indio_dev)
 {
-	struct iio_buffer *ring = indio_dev->buffer;
 	struct ad799x_state *st = iio_priv(indio_dev);
-
 	/*
 	 * Need to figure out the current mode based upon the requested
 	 * scan mask in iio_dev
@@ -43,21 +41,7 @@ static int ad799x_ring_preenable(struct iio_dev *indio_dev)
 	if (st->id == ad7997 || st->id == ad7998)
 		ad7997_8_set_scan_mode(st, *indio_dev->active_scan_mask);
 
-	st->d_size = bitmap_weight(indio_dev->active_scan_mask,
-				   indio_dev->masklength) * 2;
-
-	if (ring->scan_timestamp) {
-		st->d_size += sizeof(s64);
-
-		if (st->d_size % sizeof(s64))
-			st->d_size += sizeof(s64) - (st->d_size % sizeof(s64));
-	}
-
-	if (indio_dev->buffer->access->set_bytes_per_datum)
-		indio_dev->buffer->access->
-			set_bytes_per_datum(indio_dev->buffer, st->d_size);
-
-	return 0;
+	return iio_sw_buffer_preenable(indio_dev);
 }
 
 /**
@@ -78,7 +62,7 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
 	int b_sent;
 	u8 cmd;
 
-	rxbuf = kmalloc(st->d_size, GFP_KERNEL);
+	rxbuf = kmalloc(indio_dev->scan_bytes, GFP_KERNEL);
 	if (rxbuf == NULL)
 		goto out;
 
@@ -112,7 +96,7 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
 	time_ns = iio_get_time_ns();
 
 	if (ring->scan_timestamp)
-		memcpy(rxbuf + st->d_size - sizeof(s64),
+		memcpy(rxbuf + indio_dev->scan_bytes - sizeof(s64),
 			&time_ns, sizeof(time_ns));
 
 	ring->access->store_to(indio_dev->buffer, rxbuf, time_ns);
-- 
1.7.0.4


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

* [PATCH 11/14] staging:iio:meter:ad7758 use iio_sw_buffer_preenable to avoid code repition
  2012-04-18 13:13 [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer Jonathan Cameron
                   ` (9 preceding siblings ...)
  2012-04-18 13:13 ` [PATCH 10/14] staging:iio:adc:ad799x use iio_sw_buffer_preenable to avoid code repitiion Jonathan Cameron
@ 2012-04-18 13:13 ` Jonathan Cameron
  2012-04-18 13:13 ` [PATCH 12/14] staging:iio:impedance-analyser make use of iio_sw_buffer_preenable Jonathan Cameron
                   ` (3 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-04-18 13:13 UTC (permalink / raw)
  To: linux-iio; +Cc: lars, Jonathan Cameron

Using this generic function adds a little overhead to a slow path but
reduces the amount of code repitition in exchange.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/meter/ade7758_ring.c |   20 +++++---------------
 1 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/drivers/staging/iio/meter/ade7758_ring.c b/drivers/staging/iio/meter/ade7758_ring.c
index c45b23b..3dfd788 100644
--- a/drivers/staging/iio/meter/ade7758_ring.c
+++ b/drivers/staging/iio/meter/ade7758_ring.c
@@ -92,29 +92,19 @@ static irqreturn_t ade7758_trigger_handler(int irq, void *p)
 static int ade7758_ring_preenable(struct iio_dev *indio_dev)
 {
 	struct ade7758_state *st = iio_priv(indio_dev);
-	struct iio_buffer *ring = indio_dev->buffer;
-	size_t d_size;
 	unsigned channel;
+	int ret;
 
 	if (!bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
 		return -EINVAL;
 
+	ret = iio_sw_buffer_preenable(indio_dev);
+	if (ret < 0)
+		return ret;
+
 	channel = find_first_bit(indio_dev->active_scan_mask,
 				 indio_dev->masklength);
 
-	d_size = st->ade7758_ring_channels[channel].scan_type.storagebits / 8;
-
-	if (ring->scan_timestamp) {
-		d_size += sizeof(s64);
-
-		if (d_size % sizeof(s64))
-			d_size += sizeof(s64) - (d_size % sizeof(s64));
-	}
-
-	if (indio_dev->buffer->access->set_bytes_per_datum)
-		indio_dev->buffer->access->
-			set_bytes_per_datum(indio_dev->buffer, d_size);
-
 	ade7758_write_waveform_type(&indio_dev->dev,
 		st->ade7758_ring_channels[channel].address);
 
-- 
1.7.0.4


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

* [PATCH 12/14] staging:iio:impedance-analyser make use of iio_sw_buffer_preenable
  2012-04-18 13:13 [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer Jonathan Cameron
                   ` (10 preceding siblings ...)
  2012-04-18 13:13 ` [PATCH 11/14] staging:iio:meter:ad7758 use iio_sw_buffer_preenable to avoid code repition Jonathan Cameron
@ 2012-04-18 13:13 ` Jonathan Cameron
  2012-04-18 13:13 ` [PATCH 13/14] staging:iio: Add caching of scan_timestamp to the core as well as buffers Jonathan Cameron
                   ` (2 subsequent siblings)
  14 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-04-18 13:13 UTC (permalink / raw)
  To: linux-iio; +Cc: lars, Jonathan Cameron

This avoids some code duplication by using the generic form
in a non performance critical place.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/impedance-analyzer/ad5933.c |   11 +++--------
 1 files changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c
index 93e5a71..8a0485e 100644
--- a/drivers/staging/iio/impedance-analyzer/ad5933.c
+++ b/drivers/staging/iio/impedance-analyzer/ad5933.c
@@ -569,19 +569,14 @@ static const struct iio_info ad5933_info = {
 static int ad5933_ring_preenable(struct iio_dev *indio_dev)
 {
 	struct ad5933_state *st = iio_priv(indio_dev);
-	size_t d_size;
 	int ret;
 
 	if (bitmap_empty(indio_dev->active_scan_mask, indio_dev->masklength))
 		return -EINVAL;
 
-	d_size = bitmap_weight(indio_dev->active_scan_mask,
-			       indio_dev->masklength) *
-		 ad5933_channels[1].scan_type.storagebits / 8;
-
-	if (indio_dev->buffer->access->set_bytes_per_datum)
-		indio_dev->buffer->access->
-			set_bytes_per_datum(indio_dev->buffer, d_size);
+	ret = iio_sw_buffer_preenable(indio_dev);
+	if (ret < 0)
+		return ret;
 
 	ret = ad5933_reset(st);
 	if (ret < 0)
-- 
1.7.0.4


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

* [PATCH 13/14] staging:iio: Add caching of scan_timestamp to the core as well as buffers.
  2012-04-18 13:13 [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer Jonathan Cameron
                   ` (11 preceding siblings ...)
  2012-04-18 13:13 ` [PATCH 12/14] staging:iio:impedance-analyser make use of iio_sw_buffer_preenable Jonathan Cameron
@ 2012-04-18 13:13 ` Jonathan Cameron
  2012-04-18 13:13 ` [PATCH 14/14] staging:iio: pull out demux cleanup for a particular buffer Jonathan Cameron
       [not found] ` <4F919648.2070503@metafoo.de>
  14 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-04-18 13:13 UTC (permalink / raw)
  To: linux-iio; +Cc: lars, Jonathan Cameron

This will be needed when multiple buffer support is added.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/accel/adis16201_ring.c    |    2 +-
 drivers/staging/iio/accel/adis16203_ring.c    |    2 +-
 drivers/staging/iio/accel/adis16204_ring.c    |    2 +-
 drivers/staging/iio/accel/adis16209_ring.c    |    2 +-
 drivers/staging/iio/accel/adis16240_ring.c    |    2 +-
 drivers/staging/iio/accel/lis3l02dq_ring.c    |    2 +-
 drivers/staging/iio/adc/ad7192.c              |    2 +-
 drivers/staging/iio/adc/ad7298_ring.c         |    2 +-
 drivers/staging/iio/adc/ad7476_ring.c         |    2 +-
 drivers/staging/iio/adc/ad7606_ring.c         |    5 ++---
 drivers/staging/iio/adc/ad7793.c              |    2 +-
 drivers/staging/iio/adc/ad7887_ring.c         |    2 +-
 drivers/staging/iio/adc/ad799x_ring.c         |    2 +-
 drivers/staging/iio/adc/max1363_ring.c        |    4 ++--
 drivers/staging/iio/gyro/adis16260_ring.c     |    2 +-
 drivers/staging/iio/iio.h                     |    2 ++
 drivers/staging/iio/iio_simple_dummy_buffer.c |    2 +-
 drivers/staging/iio/industrialio-buffer.c     |    1 +
 drivers/staging/iio/meter/ade7758_ring.c      |    2 +-
 19 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/drivers/staging/iio/accel/adis16201_ring.c b/drivers/staging/iio/accel/adis16201_ring.c
index 1370e32..49912e2 100644
--- a/drivers/staging/iio/accel/adis16201_ring.c
+++ b/drivers/staging/iio/accel/adis16201_ring.c
@@ -80,7 +80,7 @@ static irqreturn_t adis16201_trigger_handler(int irq, void *p)
 			data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
 
 	/* Guaranteed to be aligned with 8 byte boundary */
-	if (ring->scan_timestamp)
+	if (indio_dev->scan_timestamp)
 		*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
 
 	ring->access->store_to(ring, (u8 *)data, pf->timestamp);
diff --git a/drivers/staging/iio/accel/adis16203_ring.c b/drivers/staging/iio/accel/adis16203_ring.c
index 86f4efb..5c40f6c 100644
--- a/drivers/staging/iio/accel/adis16203_ring.c
+++ b/drivers/staging/iio/accel/adis16203_ring.c
@@ -80,7 +80,7 @@ static irqreturn_t adis16203_trigger_handler(int irq, void *p)
 			data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
 
 	/* Guaranteed to be aligned with 8 byte boundary */
-	if (ring->scan_timestamp)
+	if (indio_dev->scan_timestamp)
 		*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
 
 	ring->access->store_to(ring,
diff --git a/drivers/staging/iio/accel/adis16204_ring.c b/drivers/staging/iio/accel/adis16204_ring.c
index 34ef11f..bf5488e 100644
--- a/drivers/staging/iio/accel/adis16204_ring.c
+++ b/drivers/staging/iio/accel/adis16204_ring.c
@@ -77,7 +77,7 @@ static irqreturn_t adis16204_trigger_handler(int irq, void *p)
 			data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
 
 	/* Guaranteed to be aligned with 8 byte boundary */
-	if (ring->scan_timestamp)
+	if (indio_dev->scan_timestamp)
 		*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
 
 	ring->access->store_to(ring, (u8 *)data, pf->timestamp);
diff --git a/drivers/staging/iio/accel/adis16209_ring.c b/drivers/staging/iio/accel/adis16209_ring.c
index 1424d48..3101c53 100644
--- a/drivers/staging/iio/accel/adis16209_ring.c
+++ b/drivers/staging/iio/accel/adis16209_ring.c
@@ -77,7 +77,7 @@ static irqreturn_t adis16209_trigger_handler(int irq, void *p)
 			data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
 
 	/* Guaranteed to be aligned with 8 byte boundary */
-	if (ring->scan_timestamp)
+	if (indio_dev->scan_timestamp)
 		*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
 
 	ring->access->store_to(ring, (u8 *)data, pf->timestamp);
diff --git a/drivers/staging/iio/accel/adis16240_ring.c b/drivers/staging/iio/accel/adis16240_ring.c
index 9ff0634..c4459f7 100644
--- a/drivers/staging/iio/accel/adis16240_ring.c
+++ b/drivers/staging/iio/accel/adis16240_ring.c
@@ -75,7 +75,7 @@ static irqreturn_t adis16240_trigger_handler(int irq, void *p)
 			data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
 
 	/* Guaranteed to be aligned with 8 byte boundary */
-	if (ring->scan_timestamp)
+	if (indio_dev->scan_timestamp)
 		*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
 
 	ring->access->store_to(ring, (u8 *)data, pf->timestamp);
diff --git a/drivers/staging/iio/accel/lis3l02dq_ring.c b/drivers/staging/iio/accel/lis3l02dq_ring.c
index 3bdc102..ebd5b4d 100644
--- a/drivers/staging/iio/accel/lis3l02dq_ring.c
+++ b/drivers/staging/iio/accel/lis3l02dq_ring.c
@@ -150,7 +150,7 @@ static irqreturn_t lis3l02dq_trigger_handler(int irq, void *p)
 		len = lis3l02dq_get_buffer_element(indio_dev, data);
 
 	  /* Guaranteed to be aligned with 8 byte boundary */
-	if (buffer->scan_timestamp)
+	if (indio_dev->scan_timestamp)
 		*(s64 *)(((phys_addr_t)data + len
 				+ sizeof(s64) - 1) & ~(sizeof(s64) - 1))
 			= pf->timestamp;
diff --git a/drivers/staging/iio/adc/ad7192.c b/drivers/staging/iio/adc/ad7192.c
index 25ef3c3..5d31685 100644
--- a/drivers/staging/iio/adc/ad7192.c
+++ b/drivers/staging/iio/adc/ad7192.c
@@ -521,7 +521,7 @@ static irqreturn_t ad7192_trigger_handler(int irq, void *p)
 				  indio_dev->channels[0].scan_type.realbits/8);
 
 	/* Guaranteed to be aligned with 8 byte boundary */
-	if (ring->scan_timestamp)
+	if (indio_dev->scan_timestamp)
 		dat64[1] = pf->timestamp;
 
 	ring->access->store_to(ring, (u8 *)dat64, pf->timestamp);
diff --git a/drivers/staging/iio/adc/ad7298_ring.c b/drivers/staging/iio/adc/ad7298_ring.c
index 5c13690..538e3b3 100644
--- a/drivers/staging/iio/adc/ad7298_ring.c
+++ b/drivers/staging/iio/adc/ad7298_ring.c
@@ -92,7 +92,7 @@ static irqreturn_t ad7298_trigger_handler(int irq, void *p)
 	if (b_sent)
 		return b_sent;
 
-	if (ring->scan_timestamp) {
+	if (indio_dev->scan_timestamp) {
 		time_ns = iio_get_time_ns();
 		memcpy((u8 *)buf + indio_dev->scan_bytes - sizeof(s64),
 			&time_ns, sizeof(time_ns));
diff --git a/drivers/staging/iio/adc/ad7476_ring.c b/drivers/staging/iio/adc/ad7476_ring.c
index a090bc3..8534f6b 100644
--- a/drivers/staging/iio/adc/ad7476_ring.c
+++ b/drivers/staging/iio/adc/ad7476_ring.c
@@ -40,7 +40,7 @@ static irqreturn_t ad7476_trigger_handler(int irq, void  *p)
 
 	time_ns = iio_get_time_ns();
 
-	if (indio_dev->buffer->scan_timestamp)
+	if (indio_dev->scan_timestamp)
 		memcpy(rxbuf + indio_dev->scan_bytes - sizeof(s64),
 			&time_ns, sizeof(time_ns));
 
diff --git a/drivers/staging/iio/adc/ad7606_ring.c b/drivers/staging/iio/adc/ad7606_ring.c
index 6cbf242..007b600 100644
--- a/drivers/staging/iio/adc/ad7606_ring.c
+++ b/drivers/staging/iio/adc/ad7606_ring.c
@@ -81,9 +81,8 @@ static void ad7606_poll_bh_to_ring(struct work_struct *work_s)
 
 	time_ns = iio_get_time_ns();
 
-	if (ring->scan_timestamp)
-		*((s64 *)(buf + ring->access->get_bytes_per_datum(ring) -
-			  sizeof(s64))) = time_ns;
+	if (indio_dev->scan_timestamp)
+		*((s64 *)(buf + indio_dev->scan_bytes - sizeof(s64))) = time_ns;
 
 	ring->access->store_to(indio_dev->buffer, buf, time_ns);
 done:
diff --git a/drivers/staging/iio/adc/ad7793.c b/drivers/staging/iio/adc/ad7793.c
index 2aeeaa2..7f68c7c 100644
--- a/drivers/staging/iio/adc/ad7793.c
+++ b/drivers/staging/iio/adc/ad7793.c
@@ -386,7 +386,7 @@ static irqreturn_t ad7793_trigger_handler(int irq, void *p)
 				  indio_dev->channels[0].scan_type.realbits/8);
 
 	/* Guaranteed to be aligned with 8 byte boundary */
-	if (ring->scan_timestamp)
+	if (indio_dev->scan_timestamp)
 		dat64[1] = pf->timestamp;
 
 	ring->access->store_to(ring, (u8 *)dat64, pf->timestamp);
diff --git a/drivers/staging/iio/adc/ad7887_ring.c b/drivers/staging/iio/adc/ad7887_ring.c
index 442994e..d9f5264 100644
--- a/drivers/staging/iio/adc/ad7887_ring.c
+++ b/drivers/staging/iio/adc/ad7887_ring.c
@@ -92,7 +92,7 @@ static irqreturn_t ad7887_trigger_handler(int irq, void *p)
 	time_ns = iio_get_time_ns();
 
 	memcpy(buf, st->data, bytes);
-	if (ring->scan_timestamp)
+	if (indio_dev->scan_timestamp)
 		memcpy(buf + indio_dev->scan_bytes - sizeof(s64),
 		       &time_ns, sizeof(time_ns));
 
diff --git a/drivers/staging/iio/adc/ad799x_ring.c b/drivers/staging/iio/adc/ad799x_ring.c
index dfdbf92..5190e50 100644
--- a/drivers/staging/iio/adc/ad799x_ring.c
+++ b/drivers/staging/iio/adc/ad799x_ring.c
@@ -95,7 +95,7 @@ static irqreturn_t ad799x_trigger_handler(int irq, void *p)
 
 	time_ns = iio_get_time_ns();
 
-	if (ring->scan_timestamp)
+	if (indio_dev->scan_timestamp)
 		memcpy(rxbuf + indio_dev->scan_bytes - sizeof(s64),
 			&time_ns, sizeof(time_ns));
 
diff --git a/drivers/staging/iio/adc/max1363_ring.c b/drivers/staging/iio/adc/max1363_ring.c
index d0a60a3..8372e98 100644
--- a/drivers/staging/iio/adc/max1363_ring.c
+++ b/drivers/staging/iio/adc/max1363_ring.c
@@ -54,7 +54,7 @@ static irqreturn_t max1363_trigger_handler(int irq, void *p)
 		d_size = numvals*2;
 	else
 		d_size = numvals;
-	if (indio_dev->buffer->scan_timestamp) {
+	if (indio_dev->scan_timestamp) {
 		d_size += sizeof(s64);
 		if (d_size % sizeof(s64))
 			d_size += sizeof(s64) - (d_size % sizeof(s64));
@@ -78,7 +78,7 @@ static irqreturn_t max1363_trigger_handler(int irq, void *p)
 
 	time_ns = iio_get_time_ns();
 
-	if (indio_dev->buffer->scan_timestamp)
+	if (indio_dev->scan_timestamp)
 		memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns));
 	iio_push_to_buffer(indio_dev->buffer, rxbuf, time_ns);
 
diff --git a/drivers/staging/iio/gyro/adis16260_ring.c b/drivers/staging/iio/gyro/adis16260_ring.c
index 18fc73c..046f84d 100644
--- a/drivers/staging/iio/gyro/adis16260_ring.c
+++ b/drivers/staging/iio/gyro/adis16260_ring.c
@@ -80,7 +80,7 @@ static irqreturn_t adis16260_trigger_handler(int irq, void *p)
 			data[i] = be16_to_cpup((__be16 *)&(st->rx[i*2]));
 
 	/* Guaranteed to be aligned with 8 byte boundary */
-	if (ring->scan_timestamp)
+	if (indio_dev->scan_timestamp)
 		*((s64 *)(data + ((i + 3)/4)*4)) = pf->timestamp;
 
 	ring->access->store_to(ring, (u8 *)data, pf->timestamp);
diff --git a/drivers/staging/iio/iio.h b/drivers/staging/iio/iio.h
index 7a10aed..0770340 100644
--- a/drivers/staging/iio/iio.h
+++ b/drivers/staging/iio/iio.h
@@ -306,6 +306,7 @@ struct iio_buffer_setup_ops {
  * @masklength:		[INTERN] the length of the mask established from
  *			channels
  * @active_scan_mask:	[INTERN] union of all scan masks requested by buffers
+ * @scan_timestamp:	[INTERN] set if any buffers have requested timestamp
  * @scan_index_timestamp:[INTERN] cache of the index to the timestamp
  * @trig:		[INTERN] current device trigger (buffer modes)
  * @pollfunc:		[DRIVER] function run on trigger being received
@@ -342,6 +343,7 @@ struct iio_dev {
 	const unsigned long		*available_scan_masks;
 	unsigned			masklength;
 	const unsigned long		*active_scan_mask;
+	bool				scan_timestamp;
 	unsigned			scan_index_timestamp;
 	struct iio_trigger		*trig;
 	struct iio_poll_func		*pollfunc;
diff --git a/drivers/staging/iio/iio_simple_dummy_buffer.c b/drivers/staging/iio/iio_simple_dummy_buffer.c
index 61a2622..49e7aa1 100644
--- a/drivers/staging/iio/iio_simple_dummy_buffer.c
+++ b/drivers/staging/iio/iio_simple_dummy_buffer.c
@@ -84,7 +84,7 @@ static irqreturn_t iio_simple_dummy_trigger_h(int irq, void *p)
 		}
 	}
 	/* Store a timestampe at an 8 byte boundary */
-	if (buffer->scan_timestamp)
+	if (indio_dev->scan_timestamp)
 		*(s64 *)(((phys_addr_t)data + len
 				+ sizeof(s64) - 1) & ~(sizeof(s64) - 1))
 			= iio_get_time_ns();
diff --git a/drivers/staging/iio/industrialio-buffer.c b/drivers/staging/iio/industrialio-buffer.c
index f6cb0ab..6c329f9 100644
--- a/drivers/staging/iio/industrialio-buffer.c
+++ b/drivers/staging/iio/industrialio-buffer.c
@@ -185,6 +185,7 @@ static ssize_t iio_scan_el_ts_store(struct device *dev,
 		goto error_ret;
 	}
 	indio_dev->buffer->scan_timestamp = state;
+	indio_dev->scan_timestamp = state;
 error_ret:
 	mutex_unlock(&indio_dev->mlock);
 
diff --git a/drivers/staging/iio/meter/ade7758_ring.c b/drivers/staging/iio/meter/ade7758_ring.c
index 3dfd788..b37bc98 100644
--- a/drivers/staging/iio/meter/ade7758_ring.c
+++ b/drivers/staging/iio/meter/ade7758_ring.c
@@ -72,7 +72,7 @@ static irqreturn_t ade7758_trigger_handler(int irq, void *p)
 			*dat32 = get_unaligned_be32(&st->rx_buf[5]) & 0xFFFFFF;
 
 	/* Guaranteed to be aligned with 8 byte boundary */
-	if (ring->scan_timestamp)
+	if (indio_dev->scan_timestamp)
 		dat64[1] = pf->timestamp;
 
 	ring->access->store_to(ring, (u8 *)dat64, pf->timestamp);
-- 
1.7.0.4


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

* [PATCH 14/14] staging:iio: pull out demux cleanup for a particular buffer.
  2012-04-18 13:13 [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer Jonathan Cameron
                   ` (12 preceding siblings ...)
  2012-04-18 13:13 ` [PATCH 13/14] staging:iio: Add caching of scan_timestamp to the core as well as buffers Jonathan Cameron
@ 2012-04-18 13:13 ` Jonathan Cameron
       [not found] ` <4F919648.2070503@metafoo.de>
  14 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-04-18 13:13 UTC (permalink / raw)
  To: linux-iio; +Cc: lars, Jonathan Cameron

This will come in handy again when we move to multiple buffers
so lets pull it out into a little utility function now.

Signed-off-by: Jonathan Cameron <jic23@kernel.org>
---
 drivers/staging/iio/industrialio-buffer.c |   22 +++++++++++++---------
 1 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/iio/industrialio-buffer.c b/drivers/staging/iio/industrialio-buffer.c
index 6c329f9..b409b95 100644
--- a/drivers/staging/iio/industrialio-buffer.c
+++ b/drivers/staging/iio/industrialio-buffer.c
@@ -655,19 +655,25 @@ int iio_push_to_buffer(struct iio_buffer *buffer, unsigned char *data,
 }
 EXPORT_SYMBOL_GPL(iio_push_to_buffer);
 
+static void iio_buffer_demux_free(struct iio_buffer *buffer)
+{
+	struct iio_demux_table *p, *q;
+	list_for_each_entry_safe(p, q, &buffer->demux_list, l) {
+		list_del(&p->l);
+		kfree(p);
+	}
+}
+
 int iio_update_demux(struct iio_dev *indio_dev)
 {
 	const struct iio_chan_spec *ch;
 	struct iio_buffer *buffer = indio_dev->buffer;
 	int ret, in_ind = -1, out_ind, length;
 	unsigned in_loc = 0, out_loc = 0;
-	struct iio_demux_table *p, *q;
+	struct iio_demux_table *p;
 
 	/* Clear out any old demux */
-	list_for_each_entry_safe(p, q, &buffer->demux_list, l) {
-		list_del(&p->l);
-		kfree(p);
-	}
+	iio_buffer_demux_free(buffer);
 	kfree(buffer->demux_bounce);
 	buffer->demux_bounce = NULL;
 
@@ -742,10 +748,8 @@ int iio_update_demux(struct iio_dev *indio_dev)
 	return 0;
 
 error_clear_mux_table:
-	list_for_each_entry_safe(p, q, &buffer->demux_list, l) {
-		list_del(&p->l);
-		kfree(p);
-	}
+	iio_buffer_demux_free(buffer);
+
 	return ret;
 }
 EXPORT_SYMBOL_GPL(iio_update_demux);
-- 
1.7.0.4


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

* Re: [PATCH 04/14] staging:iio: add caching of the number of bytes in a scan.
       [not found]   ` <4F91944F.3070701@metafoo.de>
@ 2012-04-20 17:02     ` Jonathan Cameron
  0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-04-20 17:02 UTC (permalink / raw)
  To: Lars-Peter Clausen, Jonathan Cameron; +Cc: linux-iio

[-- Attachment #1: Type: text/plain, Size: 822 bytes --]


Odd will chase that down. Probably wasn't on a clean tree. Thanks!

--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

Lars-Peter Clausen <lars@metafoo.de> wrote:

On 04/18/2012 03:13 PM, Jonathan Cameron wrote:
> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
> ---
> [...]
> diff --git a/drivers/staging/iio/industrialio-buffer.c b/drivers/staging/iio/industrialio-buffer.c
> index efa44c4..f6cb0ab 100644
> --- a/drivers/staging/iio/industrialio-buffer.c
> +++ b/drivers/staging/iio/industrialio-buffer.c
> @@ -536,13 +536,13 @@ static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask,
> int iio_sw_buffer_preenable(struct iio_dev *indio_dev)
> {
> 	struct iio_buffer *buffer = indio_dev->buffer;
> -	unsigned bytes = 0;

This line didn't apply.


[-- Attachment #2: Type: text/html, Size: 1259 bytes --]

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

* Re: [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer.
       [not found] ` <4F919648.2070503@metafoo.de>
@ 2012-04-21  9:10   ` Jonathan Cameron
  0 siblings, 0 replies; 17+ messages in thread
From: Jonathan Cameron @ 2012-04-21  9:10 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: linux-iio

On 04/20/2012 06:00 PM, Lars-Peter Clausen wrote:
> On 04/18/2012 03:13 PM, Jonathan Cameron wrote:
>> Sits on top of the series
>>
>> [PATCH 00/16 V3] IIO: Make the value attribute optional for channels
>>  
>> This series consists of the first chunk of what was
>> [PATCH 1/4] staging:iio: make all buffer access pass through the buffer_list
>> As Lars-Peter rightly pointed out that patch was a whole mess of different
>> elements all bunged in together.
>>
>> I believe this lot are all fairly uncontroversial unless I have trashed
>> a driver by accident. (which is entirely plausible).
> 
> Yep, looks all pretty straight forward. With the compiler warning fixed:
> Acked-by: Lars-Peter Clausen <lars@metafoo.de>
Fixed up and sent on to Greg.
> 
>>
>> There are a few temporary frigs in here to ensure some of the cached
>> values are correct before we put the real change in place.
>> For example the scan_timestamp gets cached both in the core and in the
>> buffers. For this change it would have made sense to drop it from the
>> buffers but then we'd just end up putting it back again a few patches
>> later.
>>
>> Anyhow, please do take a look at what we have here.  Some are
>> trivial, but there are a good few driver reworks that could do
>> with testing (as I'll almost guarantee I've messed something up
>> ripping the original large patch apart!)
>>
>> Thanks,
>>
>> Jonathan Cameron 
>>
>> Jonathan Cameron (14):
>>   staging:iio:buffer trivial use of strtobool to remove dodgy
>>     equivalent.
>>   staging:iio:buffer: pull computation of scan length into a utility
>>     function.
>>   staging:iio: scan_index_timestamp move to iio_dev from buffer
>>   staging:iio: add caching of the number of bytes in a scan.
>>   staging:iio:adc:ad7192 make use of iio_sw_buffer_preenable.
>>   staging:iio:adc:ad7298 use iio_sw_buffer_preenable to avoid code
>>     repitition.
>>   staging:iio:adc:ad7476 use iio_sw_buffer_preenable instead of local
>>     version.
>>   staging:iio:adc:ad7793 use iio_sw_buffer_preenable to avoid
>>     repitition.
>>   staging:iio:adc:ad7887 make use of iio_sw_buffer_preenable.
>>   staging:iio:adc:ad799x use iio_sw_buffer_preenable to avoid code
>>     repitiion
>>   staging:iio:meter:ad7758 use iio_sw_buffer_preenable to avoid code
>>     repition
>>   staging:iio:impedance-analyser make use of iio_sw_buffer_preenable
>>   staging:iio: Add caching of scan_timestamp to the core as well as
>>     buffers.
>>   staging:iio: pull out demux cleanup for a particular buffer.
>>
>>  drivers/staging/iio/accel/adis16201_ring.c      |    5 +-
>>  drivers/staging/iio/accel/adis16203_ring.c      |    5 +-
>>  drivers/staging/iio/accel/adis16204_ring.c      |    5 +-
>>  drivers/staging/iio/accel/adis16209_ring.c      |    6 +-
>>  drivers/staging/iio/accel/adis16240_ring.c      |    5 +-
>>  drivers/staging/iio/accel/lis3l02dq_ring.c      |    6 +-
>>  drivers/staging/iio/adc/ad7192.c                |   24 ++------
>>  drivers/staging/iio/adc/ad7298.h                |    1 -
>>  drivers/staging/iio/adc/ad7298_ring.c           |   26 +++------
>>  drivers/staging/iio/adc/ad7476.h                |    1 -
>>  drivers/staging/iio/adc/ad7476_ring.c           |   38 +-----------
>>  drivers/staging/iio/adc/ad7606_ring.c           |    8 +--
>>  drivers/staging/iio/adc/ad7793.c                |   23 ++------
>>  drivers/staging/iio/adc/ad7887.h                |    1 -
>>  drivers/staging/iio/adc/ad7887_ring.c           |   25 ++------
>>  drivers/staging/iio/adc/ad799x.h                |    1 -
>>  drivers/staging/iio/adc/ad799x_ring.c           |   24 +-------
>>  drivers/staging/iio/adc/max1363_ring.c          |    4 +-
>>  drivers/staging/iio/buffer.h                    |    2 -
>>  drivers/staging/iio/gyro/adis16260_ring.c       |    5 +-
>>  drivers/staging/iio/iio.h                       |    6 ++
>>  drivers/staging/iio/iio_simple_dummy_buffer.c   |   11 +--
>>  drivers/staging/iio/impedance-analyzer/ad5933.c |   11 +---
>>  drivers/staging/iio/imu/adis16400_ring.c        |    4 +-
>>  drivers/staging/iio/industrialio-buffer.c       |   69 +++++++++++++++--------
>>  drivers/staging/iio/meter/ade7758_ring.c        |   22 ++-----
>>  26 files changed, 121 insertions(+), 217 deletions(-)
>>
> 
> --
> 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  http://vger.kernel.org/majordomo-info.html


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

end of thread, other threads:[~2012-04-21  9:10 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-18 13:13 [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer Jonathan Cameron
2012-04-18 13:13 ` [PATCH 01/14] staging:iio:buffer trivial use of strtobool to remove dodgy equivalent Jonathan Cameron
2012-04-18 13:13 ` [PATCH 02/14] staging:iio:buffer: pull computation of scan length into a utility function Jonathan Cameron
2012-04-18 13:13 ` [PATCH 03/14] staging:iio: scan_index_timestamp move to iio_dev from buffer Jonathan Cameron
2012-04-18 13:13 ` [PATCH 04/14] staging:iio: add caching of the number of bytes in a scan Jonathan Cameron
     [not found]   ` <4F91944F.3070701@metafoo.de>
2012-04-20 17:02     ` Jonathan Cameron
2012-04-18 13:13 ` [PATCH 05/14] staging:iio:adc:ad7192 make use of iio_sw_buffer_preenable Jonathan Cameron
2012-04-18 13:13 ` [PATCH 06/14] staging:iio:adc:ad7298 use iio_sw_buffer_preenable to avoid code repitition Jonathan Cameron
2012-04-18 13:13 ` [PATCH 07/14] staging:iio:adc:ad7476 use iio_sw_buffer_preenable instead of local version Jonathan Cameron
2012-04-18 13:13 ` [PATCH 08/14] staging:iio:adc:ad7793 use iio_sw_buffer_preenable to avoid repitition Jonathan Cameron
2012-04-18 13:13 ` [PATCH 09/14] staging:iio:adc:ad7887 make use of iio_sw_buffer_preenable Jonathan Cameron
2012-04-18 13:13 ` [PATCH 10/14] staging:iio:adc:ad799x use iio_sw_buffer_preenable to avoid code repitiion Jonathan Cameron
2012-04-18 13:13 ` [PATCH 11/14] staging:iio:meter:ad7758 use iio_sw_buffer_preenable to avoid code repition Jonathan Cameron
2012-04-18 13:13 ` [PATCH 12/14] staging:iio:impedance-analyser make use of iio_sw_buffer_preenable Jonathan Cameron
2012-04-18 13:13 ` [PATCH 13/14] staging:iio: Add caching of scan_timestamp to the core as well as buffers Jonathan Cameron
2012-04-18 13:13 ` [PATCH 14/14] staging:iio: pull out demux cleanup for a particular buffer Jonathan Cameron
     [not found] ` <4F919648.2070503@metafoo.de>
2012-04-21  9:10   ` [PATCH 00/14] Staging:iio: Cleanup and refactor pre multibuffer 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.