diff options
author | Lars-Peter Clausen <lars@metafoo.de> | 2012-07-09 10:00:00 +0100 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2012-07-09 18:18:15 +0100 |
commit | 81636632057cc1bece2531220dd5803036f95ea9 (patch) | |
tree | 6c1d73dbc88d32e49a2c5b44423a972a9b8da0c0 | |
parent | 939546d1a9f47ed169554c711e1e05965b84ffe1 (diff) | |
download | op-kernel-dev-81636632057cc1bece2531220dd5803036f95ea9.zip op-kernel-dev-81636632057cc1bece2531220dd5803036f95ea9.tar.gz |
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>
-rw-r--r-- | drivers/iio/industrialio-buffer.c | 16 | ||||
-rw-r--r-- | include/linux/iio/buffer.h | 3 |
2 files changed, 19 insertions, 0 deletions
diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c index cc5db36..8c1dc9a 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) } EXPORT_SYMBOL(iio_sw_buffer_preenable); +/** + * iio_validate_scan_mask_onehot() - Validates that exactly one channel is selected + * @indio_dev: the iio device + * @mask: scan mask to be checked + * + * Return true if exactly one bit is set in the scan mask, false otherwise. It + * can be used for devices where only one channel can be active for sampling at + * a time. + */ +bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev, + const unsigned long *mask) +{ + return bitmap_weight(mask, indio_dev->masklength) == 1; +} +EXPORT_SYMBOL_GPL(iio_validate_scan_mask_onehot); + static bool iio_validate_scan_mask(struct iio_dev *indio_dev, const unsigned long *mask) { diff --git a/include/linux/iio/buffer.h b/include/linux/iio/buffer.h index 2a2b6b4..8ba516f 100644 --- a/include/linux/iio/buffer.h +++ b/include/linux/iio/buffer.h @@ -177,6 +177,9 @@ ssize_t iio_buffer_show_enable(struct device *dev, int iio_sw_buffer_preenable(struct iio_dev *indio_dev); +bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev, + const unsigned long *mask); + #else /* CONFIG_IIO_BUFFER */ static inline int iio_buffer_register(struct iio_dev *indio_dev, |