iio: inkern: add iio_read_channel_average_raw
authorSebastian Reichel <sre@debian.org>
Fri, 3 Oct 2014 16:25:00 +0000 (17:25 +0100)
committerJonathan Cameron <jic23@kernel.org>
Sun, 16 Mar 2014 18:00:33 +0000 (18:00 +0000)
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>
drivers/iio/inkern.c
include/linux/iio/consumer.h

index 0cf5f8e06cfcc6b6bc8c059871e153a391cbd122..adeba5a0ecf70ff79ed4e3ed653ee6e4bf27b0ca 100644 (file)
@@ -443,6 +443,24 @@ err_unlock:
 }
 EXPORT_SYMBOL_GPL(iio_read_channel_raw);
 
+int iio_read_channel_average_raw(struct iio_channel *chan, int *val)
+{
+       int ret;
+
+       mutex_lock(&chan->indio_dev->info_exist_lock);
+       if (chan->indio_dev->info == NULL) {
+               ret = -ENODEV;
+               goto err_unlock;
+       }
+
+       ret = iio_channel_read(chan, val, NULL, IIO_CHAN_INFO_AVERAGE_RAW);
+err_unlock:
+       mutex_unlock(&chan->indio_dev->info_exist_lock);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(iio_read_channel_average_raw);
+
 static int iio_convert_raw_to_processed_unlocked(struct iio_channel *chan,
        int raw, int *processed, unsigned int scale)
 {
index 2752b1fd12be3ea8b41c58f64b408d88f1afddaa..651f9a0e2765fa17a4896321478c15b9997f416e 100644 (file)
@@ -122,6 +122,19 @@ struct iio_channel
 int iio_read_channel_raw(struct iio_channel *chan,
                         int *val);
 
+/**
+ * iio_read_channel_average_raw() - read from a given channel
+ * @chan:              The channel being queried.
+ * @val:               Value read back.
+ *
+ * Note raw reads from iio channels are in adc counts and hence
+ * scale will need to be applied if standard units required.
+ *
+ * In opposit to the normal iio_read_channel_raw this function
+ * returns the average of multiple reads.
+ */
+int iio_read_channel_average_raw(struct iio_channel *chan, int *val);
+
 /**
  * iio_read_channel_processed() - read processed value from a given channel
  * @chan:              The channel being queried.