aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2012-07-09 05:00:00 -0400
committerJonathan Cameron <jic23@kernel.org>2012-07-09 13:18:15 -0400
commit81636632057cc1bece2531220dd5803036f95ea9 (patch)
tree6c1d73dbc88d32e49a2c5b44423a972a9b8da0c0 /drivers/iio
parent939546d1a9f47ed169554c711e1e05965b84ffe1 (diff)
iio: Introduce iio_validate_scan_mask_onehot
Add a helper function for validating a scan mask for devices where exactly one channel must be selected during sampling. This is a common case among devices which have scan mask restrictions so it makes sense to provide this function in the core. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio')
-rw-r--r--drivers/iio/industrialio-buffer.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c
index cc5db36fb75a..8c1dc9a683fb 100644
--- a/drivers/iio/industrialio-buffer.c
+++ b/drivers/iio/industrialio-buffer.c
@@ -570,6 +570,22 @@ int iio_sw_buffer_preenable(struct iio_dev *indio_dev)
570} 570}
571EXPORT_SYMBOL(iio_sw_buffer_preenable); 571EXPORT_SYMBOL(iio_sw_buffer_preenable);
572 572
573/**
574 * iio_validate_scan_mask_onehot() - Validates that exactly one channel is selected
575 * @indio_dev: the iio device
576 * @mask: scan mask to be checked
577 *
578 * Return true if exactly one bit is set in the scan mask, false otherwise. It
579 * can be used for devices where only one channel can be active for sampling at
580 * a time.
581 */
582bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev,
583 const unsigned long *mask)
584{
585 return bitmap_weight(mask, indio_dev->masklength) == 1;
586}
587EXPORT_SYMBOL_GPL(iio_validate_scan_mask_onehot);
588
573static bool iio_validate_scan_mask(struct iio_dev *indio_dev, 589static bool iio_validate_scan_mask(struct iio_dev *indio_dev,
574 const unsigned long *mask) 590 const unsigned long *mask)
575{ 591{