[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <11999b2d-b99f-a34c-d1d8-fcf58a5de3fc@axentia.se>
Date: Tue, 11 Jun 2019 11:03:59 +0000
From: Peter Rosin <peda@...ntia.se>
To: Mylène Josserand <mylene.josserand@...tlin.com>,
"jic23@...nel.org" <jic23@...nel.org>,
"knaack.h@....de" <knaack.h@....de>,
"lars@...afoo.de" <lars@...afoo.de>,
"pmeerw@...erw.net" <pmeerw@...erw.net>,
"robh+dt@...nel.org" <robh+dt@...nel.org>,
"mark.rutland@....com" <mark.rutland@....com>
CC: "linux-iio@...r.kernel.org" <linux-iio@...r.kernel.org>,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"devicetree@...r.kernel.org" <devicetree@...r.kernel.org>,
"thomas.petazzoni@...tlin.com" <thomas.petazzoni@...tlin.com>
Subject: Re: [PATCH v1 1/3] iio: afe: rescale: Move scale conversion to new
function
On 2019-06-11 11:56, Mylène Josserand wrote:
> To prepare the support of processed value, create a function
> to convert the scale according to the voltage-divider node
> used in the device-tree.
>
> Signed-off-by: Mylène Josserand <mylene.josserand@...tlin.com>
> ---
> drivers/iio/afe/iio-rescale.c | 54 +++++++++++++++++++++++++------------------
> 1 file changed, 31 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c
> index e9ceee66d1e7..3e689d6eb501 100644
> --- a/drivers/iio/afe/iio-rescale.c
> +++ b/drivers/iio/afe/iio-rescale.c
> @@ -33,12 +33,41 @@ struct rescale {
> s32 denominator;
> };
>
> +static int rescale_convert_scale(struct rescale *rescale, int *val, int *val2)
> +{
> + unsigned long long tmp;
> + int ret;
> +
> + ret = iio_read_channel_scale(rescale->source, val, val2);
> + switch (ret) {
> + case IIO_VAL_FRACTIONAL:
> + *val *= rescale->numerator;
> + *val2 *= rescale->denominator;
> + return ret;
> + case IIO_VAL_INT:
> + *val *= rescale->numerator;
> + if (rescale->denominator == 1)
> + return ret;
> + *val2 = rescale->denominator;
> + return IIO_VAL_FRACTIONAL;
> + case IIO_VAL_FRACTIONAL_LOG2:
> + tmp = *val * 1000000000LL;
> + do_div(tmp, rescale->denominator);
> + tmp *= rescale->numerator;
> + do_div(tmp, 1000000000LL);
> + *val = tmp;
> +
This blank line is in conflict with the style of the surrounding code.
Cheers,
Peter
> + return ret;
> + default:
> + return -EOPNOTSUPP;
> + }
> +}
> +
> static int rescale_read_raw(struct iio_dev *indio_dev,
> struct iio_chan_spec const *chan,
> int *val, int *val2, long mask)
> {
> struct rescale *rescale = iio_priv(indio_dev);
> - unsigned long long tmp;
> int ret;
>
> switch (mask) {
> @@ -46,28 +75,7 @@ static int rescale_read_raw(struct iio_dev *indio_dev,
> return iio_read_channel_raw(rescale->source, val);
>
> case IIO_CHAN_INFO_SCALE:
> - ret = iio_read_channel_scale(rescale->source, val, val2);
> - switch (ret) {
> - case IIO_VAL_FRACTIONAL:
> - *val *= rescale->numerator;
> - *val2 *= rescale->denominator;
> - return ret;
> - case IIO_VAL_INT:
> - *val *= rescale->numerator;
> - if (rescale->denominator == 1)
> - return ret;
> - *val2 = rescale->denominator;
> - return IIO_VAL_FRACTIONAL;
> - case IIO_VAL_FRACTIONAL_LOG2:
> - tmp = *val * 1000000000LL;
> - do_div(tmp, rescale->denominator);
> - tmp *= rescale->numerator;
> - do_div(tmp, 1000000000LL);
> - *val = tmp;
> - return ret;
> - default:
> - return -EOPNOTSUPP;
> - }
> + return rescale_convert_scale(rescale, val, val2);
> default:
> return -EINVAL;
> }
>
Powered by blists - more mailing lists