From: Peter Rosin <peda@axentia.se>
To: Liam Beguin <liambeguin@gmail.com>,
jic23@kernel.org, andy.shevchenko@gmail.com, lars@metafoo.de
Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
devicetree@vger.kernel.org, robh+dt@kernel.org
Subject: Re: [PATCH v14 03/11] iio: afe: rescale: add offset support
Date: Thu, 10 Feb 2022 17:47:26 +0100 [thread overview]
Message-ID: <adb275f6-07bf-1468-b548-df944a25dbd0@axentia.se> (raw)
In-Reply-To: <20220208020441.3081162-4-liambeguin@gmail.com>
Hi!
On 2022-02-08 03:04, Liam Beguin wrote:
> This is a preparatory change required for the addition of temperature
> sensing front ends.
>
> Signed-off-by: Liam Beguin <liambeguin@gmail.com>
> Reviewed-by: Peter Rosin <peda@axentia.se>
> ---
> drivers/iio/afe/iio-rescale.c | 81 +++++++++++++++++++++++++++++++++
> include/linux/iio/afe/rescale.h | 4 ++
> 2 files changed, 85 insertions(+)
>
> diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c
> index f833eb38f8bb..63035b4bce5e 100644
> --- a/drivers/iio/afe/iio-rescale.c
> +++ b/drivers/iio/afe/iio-rescale.c
> @@ -3,6 +3,7 @@
> * IIO rescale driver
> *
> * Copyright (C) 2018 Axentia Technologies AB
> + * Copyright (C) 2022 Liam Beguin <liambeguin@gmail.com>
> *
> * Author: Peter Rosin <peda@axentia.se>
> */
> @@ -82,11 +83,46 @@ int rescale_process_scale(struct rescale *rescale, int scale_type,
> }
> }
>
> +int rescale_process_offset(struct rescale *rescale, int scale_type,
> + int scale, int scale2, int schan_off,
> + int *val, int *val2)
> +{
> + s64 tmp, tmp2;
> +
> + switch (scale_type) {
> + case IIO_VAL_FRACTIONAL:
> + tmp = (s64)rescale->offset * scale2;
> + *val = div_s64(tmp, scale) + schan_off;
> + return IIO_VAL_INT;
> + case IIO_VAL_INT:
> + *val = div_s64(rescale->offset, scale) + schan_off;
> + return IIO_VAL_INT;
> + case IIO_VAL_FRACTIONAL_LOG2:
> + tmp = (s64)rescale->offset * (1 << scale2);
> + *val = div_s64(tmp, scale) + schan_off;
> + return IIO_VAL_INT;
> + case IIO_VAL_INT_PLUS_NANO:
> + tmp = (s64)rescale->offset * GIGA;
> + tmp2 = ((s64)scale * GIGA) + scale2;
Same thing here as in patch 2/11, use NANO or the raw number. GIGA
has no connection to the usage.
> + *val = div64_s64(tmp, tmp2) + schan_off;
> + return IIO_VAL_INT;
> + case IIO_VAL_INT_PLUS_MICRO:
> + tmp = (s64)rescale->offset * MEGA;
> + tmp2 = ((s64)scale * MEGA) + scale2;
And MICRO here of course.
Cheers,
Peter
*snip*
next prev parent reply other threads:[~2022-02-10 16:48 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-08 2:04 [PATCH v14 00/11] iio: afe: add temperature rescaling support Liam Beguin
2022-02-08 2:04 ` [PATCH v14 01/11] iio: afe: rescale: expose scale processing function Liam Beguin
2022-02-08 2:04 ` [PATCH v14 02/11] iio: afe: rescale: add INT_PLUS_{MICRO,NANO} support Liam Beguin
2022-02-10 16:42 ` Peter Rosin
2022-02-10 17:36 ` Liam Beguin
2022-02-11 14:20 ` Peter Rosin
2022-02-08 2:04 ` [PATCH v14 03/11] iio: afe: rescale: add offset support Liam Beguin
2022-02-08 13:42 ` Andy Shevchenko
2022-02-09 16:35 ` Liam Beguin
2022-02-10 16:47 ` Peter Rosin [this message]
2022-02-08 2:04 ` [PATCH v14 04/11] iio: afe: rescale: fix accuracy for small fractional scales Liam Beguin
2022-02-08 2:04 ` [PATCH v14 05/11] iio: afe: rescale: reduce risk of integer overflow Liam Beguin
2022-02-08 2:04 ` [PATCH v14 06/11] iio: afe: rescale: make use of units.h Liam Beguin
2022-02-10 17:41 ` Peter Rosin
2022-02-08 2:04 ` [PATCH v14 07/11] iio: test: add basic tests for the iio-rescale driver Liam Beguin
2022-02-08 2:04 ` [PATCH v14 08/11] iio: afe: rescale: add RTD temperature sensor support Liam Beguin
2022-02-08 2:04 ` [PATCH v14 09/11] iio: afe: rescale: add temperature transducers Liam Beguin
2022-02-08 13:46 ` Andy Shevchenko
2022-02-09 16:38 ` Liam Beguin
2022-02-08 2:04 ` [PATCH v14 10/11] dt-bindings: iio: afe: add bindings for temperature-sense-rtd Liam Beguin
2022-02-08 2:04 ` [PATCH v14 11/11] dt-bindings: iio: afe: add bindings for temperature transducers Liam Beguin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=adb275f6-07bf-1468-b548-df944a25dbd0@axentia.se \
--to=peda@axentia.se \
--cc=andy.shevchenko@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=liambeguin@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).