Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: inkern: add iio_read_channel_average_raw

Add iio_read_channel_average_raw to support reading
averaged raw values in consumer drivers.

Signed-off-by: Sebastian Reichel <sre@debian.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Sebastian Reichel and committed by
Jonathan Cameron
476d4af2 c0a6b7ee

+31
+18
drivers/iio/inkern.c
··· 443 443 } 444 444 EXPORT_SYMBOL_GPL(iio_read_channel_raw); 445 445 446 + int iio_read_channel_average_raw(struct iio_channel *chan, int *val) 447 + { 448 + int ret; 449 + 450 + mutex_lock(&chan->indio_dev->info_exist_lock); 451 + if (chan->indio_dev->info == NULL) { 452 + ret = -ENODEV; 453 + goto err_unlock; 454 + } 455 + 456 + ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_AVERAGE_RAW); 457 + err_unlock: 458 + mutex_unlock(&chan->indio_dev->info_exist_lock); 459 + 460 + return ret; 461 + } 462 + EXPORT_SYMBOL_GPL(iio_read_channel_average_raw); 463 + 446 464 static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan, 447 465 int raw, int *processed, unsigned int scale) 448 466 {
+13
include/linux/iio/consumer.h
··· 123 123 int *val); 124 124 125 125 /** 126 + * iio_read_channel_average_raw() - read from a given channel 127 + * @chan: The channel being queried. 128 + * @val: Value read back. 129 + * 130 + * Note raw reads from iio channels are in adc counts and hence 131 + * scale will need to be applied if standard units required. 132 + * 133 + * In opposit to the normal iio_read_channel_raw this function 134 + * returns the average of multiple reads. 135 + */ 136 + int iio_read_channel_average_raw(struct iio_channel *chan, int *val); 137 + 138 + /** 126 139 * iio_read_channel_processed() - read processed value from a given channel 127 140 * @chan: The channel being queried. 128 141 * @val: Value read back.