diff options
author | Jonathan Cameron <jic23@kernel.org> | 2012-04-21 05:09:33 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2012-04-24 14:23:36 -0400 |
commit | 6b3b58ed15cdc27b1ded4487d74c1b7ae04aa162 (patch) | |
tree | 49d212dd4715aad07bd182c7e963d722d1341f70 | |
parent | a714af276f5002b44e97a2d6d03f85bdae627c41 (diff) |
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>
-rw-r--r-- | 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 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, | |||
508 | return NULL; | 508 | return NULL; |
509 | } | 509 | } |
510 | 510 | ||
511 | int iio_sw_buffer_preenable(struct iio_dev *indio_dev) | 511 | static int iio_compute_scan_bytes(struct iio_dev *indio_dev, const long *mask, |
512 | bool timestamp) | ||
512 | { | 513 | { |
513 | struct iio_buffer *buffer = indio_dev->buffer; | ||
514 | const struct iio_chan_spec *ch; | 514 | const struct iio_chan_spec *ch; |
515 | unsigned bytes = 0; | 515 | unsigned bytes = 0; |
516 | int length, i; | 516 | int length, i; |
517 | dev_dbg(&indio_dev->dev, "%s\n", __func__); | ||
518 | 517 | ||
519 | /* How much space will the demuxed element take? */ | 518 | /* How much space will the demuxed element take? */ |
520 | for_each_set_bit(i, buffer->scan_mask, | 519 | for_each_set_bit(i, mask, |
521 | indio_dev->masklength) { | 520 | indio_dev->masklength) { |
522 | ch = iio_find_channel_from_si(indio_dev, i); | 521 | ch = iio_find_channel_from_si(indio_dev, i); |
523 | length = ch->scan_type.storagebits/8; | 522 | length = ch->scan_type.storagebits / 8; |
524 | bytes = ALIGN(bytes, length); | 523 | bytes = ALIGN(bytes, length); |
525 | bytes += length; | 524 | bytes += length; |
526 | } | 525 | } |
527 | if (buffer->scan_timestamp) { | 526 | if (timestamp) { |
528 | ch = iio_find_channel_from_si(indio_dev, | 527 | ch = iio_find_channel_from_si(indio_dev, |
529 | buffer->scan_index_timestamp); | 528 | indio_dev |
530 | length = ch->scan_type.storagebits/8; | 529 | ->buffer->scan_index_timestamp); |
530 | length = ch->scan_type.storagebits / 8; | ||
531 | bytes = ALIGN(bytes, length); | 531 | bytes = ALIGN(bytes, length); |
532 | bytes += length; | 532 | bytes += length; |
533 | } | 533 | } |
534 | return bytes; | ||
535 | } | ||
536 | |||
537 | int iio_sw_buffer_preenable(struct iio_dev *indio_dev) | ||
538 | { | ||
539 | struct iio_buffer *buffer = indio_dev->buffer; | ||
540 | unsigned bytes; | ||
541 | dev_dbg(&indio_dev->dev, "%s\n", __func__); | ||
542 | |||
543 | /* How much space will the demuxed element take? */ | ||
544 | bytes = iio_compute_scan_bytes(indio_dev, buffer->scan_mask, | ||
545 | buffer->scan_timestamp); | ||
534 | buffer->access->set_bytes_per_datum(buffer, bytes); | 546 | buffer->access->set_bytes_per_datum(buffer, bytes); |
535 | 547 | ||
536 | /* What scan mask do we actually have ?*/ | 548 | /* What scan mask do we actually have ?*/ |