summaryrefslogtreecommitdiffstats
path: root/drivers/staging/iio/industrialio-buffer.c
diff options
context:
space:
mode:
authorJonathan Cameron2012-04-21 11:09:33 +0200
committerGreg Kroah-Hartman2012-04-24 20:23:36 +0200
commit6b3b58ed15cdc27b1ded4487d74c1b7ae04aa162 (patch)
tree49d212dd4715aad07bd182c7e963d722d1341f70 /drivers/staging/iio/industrialio-buffer.c
parentstaging:iio:buffer trivial use of strtobool to remove dodgy equivalent. (diff)
downloadkernel-qcow2-linux-6b3b58ed15cdc27b1ded4487d74c1b7ae04aa162.tar.gz
kernel-qcow2-linux-6b3b58ed15cdc27b1ded4487d74c1b7ae04aa162.tar.xz
kernel-qcow2-linux-6b3b58ed15cdc27b1ded4487d74c1b7ae04aa162.zip
staging:iio:buffer: pull computation of scan length into a utility function.
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> Acked-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/iio/industrialio-buffer.c')
-rw-r--r--drivers/staging/iio/industrialio-buffer.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/drivers/staging/iio/industrialio-buffer.c b/drivers/staging/iio/industrialio-buffer.c
index 59b0caf5deab..389fe16872b4 100644
--- a/drivers/staging/iio/industrialio-buffer.c
+++ b/drivers/staging/iio/industrialio-buffer.c
@@ -508,29 +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 ?*/