lkml.org 
[lkml]   [2019]   [Jun]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH v1 1/3] iio: afe: rescale: Move scale conversion to new function
Date
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@bootlin.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;
> }
>

\
 
 \ /
  Last update: 2019-06-11 13:05    [W:0.091 / U:2.356 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site