diff options
-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 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 | } |
571 | EXPORT_SYMBOL(iio_sw_buffer_preenable); | 571 | EXPORT_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 | */ | ||
582 | bool 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 | } | ||
587 | EXPORT_SYMBOL_GPL(iio_validate_scan_mask_onehot); | ||
588 | |||
573 | static bool iio_validate_scan_mask(struct iio_dev *indio_dev, | 589 | static bool iio_validate_scan_mask(struct iio_dev *indio_dev, |
574 | const unsigned long *mask) | 590 | const unsigned long *mask) |
575 | { | 591 | { |
diff --git a/include/linux/iio/buffer.h b/include/linux/iio/buffer.h index 2a2b6b4d8d05..8ba516fc2ec6 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, | |||
177 | 177 | ||
178 | int iio_sw_buffer_preenable(struct iio_dev *indio_dev); | 178 | int iio_sw_buffer_preenable(struct iio_dev *indio_dev); |
179 | 179 | ||
180 | bool iio_validate_scan_mask_onehot(struct iio_dev *indio_dev, | ||
181 | const unsigned long *mask); | ||
182 | |||
180 | #else /* CONFIG_IIO_BUFFER */ | 183 | #else /* CONFIG_IIO_BUFFER */ |
181 | 184 | ||
182 | static inline int iio_buffer_register(struct iio_dev *indio_dev, | 185 | static inline int iio_buffer_register(struct iio_dev *indio_dev, |