From: Jonathan Cameron <jic23@kernel.org>
To: Romain Gantois <romain.gantois@bootlin.com>
Cc: "Liam Girdwood" <lgirdwood@gmail.com>,
"Mark Brown" <broonie@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Hans de Goede" <hansg@kernel.org>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
linux-iio@vger.kernel.org
Subject: Re: [PATCH v2 2/5] iio: add processed write API
Date: Sun, 28 Sep 2025 10:07:57 +0100 [thread overview]
Message-ID: <20250928100757.0fa73692@jic23-huawei> (raw)
In-Reply-To: <20250925-ltm8054-driver-v2-2-bb61a401a0dc@bootlin.com>
On Thu, 25 Sep 2025 14:37:34 +0200
Romain Gantois <romain.gantois@bootlin.com> wrote:
> Add a function to allow IIO consumers to write a processed value to a
> channel.
>
> Signed-off-by: Romain Gantois <romain.gantois@bootlin.com>
Just one trivial thing I noticed.
Thanks for adding the unit tests btw. Makes me much more confident we don't have
the corner case sign errors that plagued the similar functions before unit tests and fixes
were applied.
J
> ---
> drivers/iio/inkern.c | 120 +++++++++++++++++++++++++++++++++++++++++++
> include/linux/iio/consumer.h | 36 +++++++++++++
> 2 files changed, 156 insertions(+)
>
> diff --git a/drivers/iio/inkern.c b/drivers/iio/inkern.c
> index 2a1ecef2b82007f5ee8e8d0f8b35846bc4d2f94a..a6ec724b7c1fb197e6261c1162f8315deda20fd7 100644
> --- a/drivers/iio/inkern.c
> +++ b/drivers/iio/inkern.c
> @@ -631,6 +631,57 @@ int iio_multiply_value(int *result, s64 multiplier,
> }
> EXPORT_SYMBOL_GPL(iio_multiply_value);
>
> +int iio_divide_by_value(int *result, s64 numerator,
> + unsigned int type, int val, int val2)
> +{
> + s64 tmp_num, tmp_den;
> +
> + switch (type) {
> + case IIO_VAL_INT:
> + tmp_num = numerator;
> + tmp_den = val;
> + break;
> + case IIO_VAL_INT_PLUS_MICRO:
> + case IIO_VAL_INT_PLUS_NANO:
> + switch (type) {
> + case IIO_VAL_INT_PLUS_MICRO:
> + tmp_num = MICRO;
> + tmp_den = MICRO;
> + break;
> +
> + case IIO_VAL_INT_PLUS_NANO:
> + tmp_num = NANO;
> + tmp_den = NANO;
> + break;
> + }
> +
> + tmp_num *= (s64)numerator;
Seems to be casting an s64 to an s64.
> + tmp_den = (s64)abs(val) * tmp_den + (s64)abs(val2);
> +
> + if (val < 0 || val2 < 0)
> + tmp_num *= -1;
> +
> + break;
> + case IIO_VAL_FRACTIONAL:
> + tmp_num = (s64)numerator * (s64)val2;
> + tmp_den = val;
> + break;
> + case IIO_VAL_FRACTIONAL_LOG2:
> + tmp_num = (s64)numerator << val2;
> + tmp_den = val;
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + if (!tmp_den)
> + return -ERANGE;
> +
> + *result = div64_s64(tmp_num, tmp_den);
> +
> + return IIO_VAL_INT;
> +}
next prev parent reply other threads:[~2025-09-28 9:08 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-25 12:37 [PATCH v2 0/5] Add support for the LTM8054 voltage regulator Romain Gantois
2025-09-25 12:37 ` [PATCH v2 1/5] regulator: dt-bindings: Add Linear Technology LTM8054 regulator Romain Gantois
2025-09-25 19:27 ` Conor Dooley
2025-09-26 15:59 ` Romain Gantois
2025-09-27 22:31 ` Conor Dooley
2025-10-01 7:11 ` Romain Gantois
2025-10-01 11:18 ` David Lechner
2025-10-01 18:40 ` Conor Dooley
2025-10-02 7:11 ` David Lechner
2025-09-25 12:37 ` [PATCH v2 2/5] iio: add processed write API Romain Gantois
2025-09-25 21:10 ` David Lechner
2025-10-01 7:19 ` Romain Gantois
2025-10-01 10:43 ` David Lechner
[not found] ` <CAMknhBG_o=jTKtHHDyK=bq7wcHMnDM1ZHaYAfX0K2hjHfkX3Bg@mail.gmail.com>
2025-10-03 14:35 ` Romain Gantois
2025-09-28 9:07 ` Jonathan Cameron [this message]
2025-09-25 12:37 ` [PATCH v2 3/5] Add kunit tests for iio_divide_by_value() Romain Gantois
2025-09-25 20:26 ` David Lechner
2025-09-25 12:37 ` [PATCH v2 4/5] regulator: Support the LTM8054 voltage regulator Romain Gantois
2025-10-22 14:44 ` Andy Shevchenko
2025-09-25 12:37 ` [PATCH v2 5/5] regulator: ltm8054: Support output current limit control Romain Gantois
2025-10-22 8:05 ` Romain Gantois
2025-10-22 16:37 ` Andy Shevchenko
2025-10-24 7:55 ` Romain Gantois
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=20250928100757.0fa73692@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=hansg@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
--cc=romain.gantois@bootlin.com \
--cc=thomas.petazzoni@bootlin.com \
/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).