From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from saturn.retrosnub.co.uk ([178.18.118.26]:60331 "EHLO saturn.retrosnub.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754929AbaCOP30 (ORCPT ); Sat, 15 Mar 2014 11:29:26 -0400 Message-ID: <53247210.3070307@kernel.org> Date: Sat, 15 Mar 2014 15:30:24 +0000 From: Jonathan Cameron MIME-Version: 1.0 To: Sebastian Reichel , Sebastian Reichel , Marek Belisko CC: Lee Jones , Samuel Ortiz , Lars-Peter Clausen , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell , Kumar Gala , Grant Likely , linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, linux-iio@vger.kernel.org Subject: Re: [PATCHv2 9/9] iio: inkern: add iio_read_channel_average_raw References: <1393702365-26429-1-git-send-email-sre@debian.org> <1393970751-18157-1-git-send-email-sre@debian.org> <1393970751-18157-10-git-send-email-sre@debian.org> In-Reply-To: <1393970751-18157-10-git-send-email-sre@debian.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Sender: linux-iio-owner@vger.kernel.org List-Id: linux-iio@vger.kernel.org On 04/03/14 22:05, Sebastian Reichel wrote: > Add iio_read_channel_average_raw to support reading > averaged raw values in consumer drivers. > > Signed-off-by: Sebastian Reichel Acked-by: Jonathan Cameron Sometimes these wrappers seem a little bit silly. There might be a case for automating them somewhat via some macros, but for now this is fine. Docs should in theory probably be with the implementation, but that's wrong throughout consumer.h so this isn't the time to change it! Jonathan > --- > drivers/iio/inkern.c | 18 ++++++++++++++++++ > include/linux/iio/consumer.h | 13 +++++++++++++ > 2 files changed, 31 insertions(+) > > diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c > index 0cf5f8e..adeba5a 100644 > --- a/drivers/iio/inkern.c > +++ b/drivers/iio/inkern.c > @@ -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) > { > diff --git a/include/linux/iio/consumer.h b/include/linux/iio/consumer.h > index 2752b1f..651f9a0 100644 > --- a/include/linux/iio/consumer.h > +++ b/include/linux/iio/consumer.h > @@ -123,6 +123,19 @@ int iio_read_channel_raw(struct iio_channel *chan, > int *val); > Ah, my bad habits propogate onwards. The docs should be with the implementation. Oh well, at somepoint I'll clean all remaining cases of this up. > /** > + * 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. > * @val: Value read back. >