* [PATCH v1 0/3] iio: adc: Provide mult_fract() and make use of it
@ 2026-11-17 9:14 Andy Shevchenko
2026-11-17 9:14 ` [PATCH v1 1/3] math.h: Add mult_fract() that takes struct __Txx_fract as argument Andy Shevchenko
` (3 more replies)
0 siblings, 4 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-11-17 9:14 UTC (permalink / raw)
To: Jonathan Cameron, Marcelo Schmitt, Andy Shevchenko,
Cristian Ciocaltea, linux, linux-iio, linux-kernel
Cc: Michael Hennerich, Nuno Sá, Esteban Blanc, Jonathan Cameron,
David Lechner, Andy Shevchenko
In a couple of IIO ADC driver the suggested new helper mult_fract()
may be used. So, provide it and update the straightforward users.
The helper has potential treewide, hence it's provided directly in math.h.
Andy Shevchenko (3):
math.h: Add mult_fract() that takes struct __Txx_fract as argument
iio: adc: ad4030: Switch to use mult_fract() helper
iio: adc: ltc2378: Switch to use mult_fract() helper
drivers/iio/adc/ad4030.c | 13 ++++++-------
drivers/iio/adc/ltc2378.c | 4 +++-
include/linux/math.h | 4 ++++
3 files changed, 13 insertions(+), 8 deletions(-)
--
2.50.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v1 1/3] math.h: Add mult_fract() that takes struct __Txx_fract as argument
2026-11-17 9:14 [PATCH v1 0/3] iio: adc: Provide mult_fract() and make use of it Andy Shevchenko
@ 2026-11-17 9:14 ` Andy Shevchenko
2026-11-18 8:22 ` Joshua Crofts
2026-11-17 9:14 ` [PATCH v1 2/3] iio: adc: ad4030: Switch to use mult_fract() helper Andy Shevchenko
` (2 subsequent siblings)
3 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2026-11-17 9:14 UTC (permalink / raw)
To: Jonathan Cameron, Marcelo Schmitt, Andy Shevchenko,
Cristian Ciocaltea, linux, linux-iio, linux-kernel
Cc: Michael Hennerich, Nuno Sá, Esteban Blanc, Jonathan Cameron,
David Lechner, Andy Shevchenko
Add mult_fract() that takes struct __Txx_fract as argument and
calls do_div() instead of plain divisions.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/math.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/include/linux/math.h b/include/linux/math.h
index 1e8fb3efbc8c..ded258df50df 100644
--- a/include/linux/math.h
+++ b/include/linux/math.h
@@ -128,6 +128,10 @@ __STRUCT_FRACT(u32)
q * n_ + r * n_ / d_; \
})
+/* Same as above but for a struct __Txx_fract fraction */
+#define mult_fract(x, f) \
+ mult_frac(x, (f)->numerator, (f)->denominator)
+
#define sector_div(a, b) do_div(a, b)
/**
--
2.50.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v1 2/3] iio: adc: ad4030: Switch to use mult_fract() helper
2026-11-17 9:14 [PATCH v1 0/3] iio: adc: Provide mult_fract() and make use of it Andy Shevchenko
2026-11-17 9:14 ` [PATCH v1 1/3] math.h: Add mult_fract() that takes struct __Txx_fract as argument Andy Shevchenko
@ 2026-11-17 9:14 ` Andy Shevchenko
2026-11-17 9:14 ` [PATCH v1 3/3] iio: adc: ltc2378: " Andy Shevchenko
2026-11-18 2:18 ` [PATCH v1 0/3] iio: adc: Provide mult_fract() and make use of it Marcelo Schmitt
3 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-11-17 9:14 UTC (permalink / raw)
To: Jonathan Cameron, Marcelo Schmitt, Andy Shevchenko,
Cristian Ciocaltea, linux, linux-iio, linux-kernel
Cc: Michael Hennerich, Nuno Sá, Esteban Blanc, Jonathan Cameron,
David Lechner, Andy Shevchenko
Switch the driver to use mult_fract() helper.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/iio/adc/ad4030.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/iio/adc/ad4030.c b/drivers/iio/adc/ad4030.c
index 877b06007396..d61950129083 100644
--- a/drivers/iio/adc/ad4030.c
+++ b/drivers/iio/adc/ad4030.c
@@ -161,11 +161,11 @@ static const int adaq4216_hw_gains_vpv[] = {
20 * MILLI / 3, /* 0.6666 */
};
-static const int adaq4216_hw_gains_frac[][2] = {
- { 1, 3 }, /* 1/3 V/V gain */
- { 5, 9 }, /* 5/9 V/V gain */
- { 20, 9 }, /* 20/9 V/V gain */
- { 20, 3 }, /* 20/3 V/V gain */
+static const struct s32_fract adaq4216_hw_gains_frac[] = {
+ { .numerator = 3, .denominator = 1 }, /* 1/3 V/V gain */
+ { .numerator = 9, .denominator = 5 }, /* 5/9 V/V gain */
+ { .numerator = 9, .denominator = 20 }, /* 20/9 V/V gain */
+ { .numerator = 3, .denominator = 20 }, /* 20/3 V/V gain */
};
struct ad4030_chip_info {
@@ -467,8 +467,7 @@ static void ad4030_fill_scale_avail(struct ad4030_state *st)
mag_bits = st->chip->precision_bits - 1;
for (unsigned int i = 0; i < ARRAY_SIZE(adaq4216_hw_gains_frac); i++) {
- range = mult_frac(st->vref_uv, adaq4216_hw_gains_frac[i][1],
- adaq4216_hw_gains_frac[i][0]);
+ range = mult_fract(st->vref_uv, &adaq4216_hw_gains_frac[i]);
/*
* If range were in mV, we would multiply it by NANO below.
* Though, range is in µV so multiply it by MICRO only so the
--
2.50.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH v1 3/3] iio: adc: ltc2378: Switch to use mult_fract() helper
2026-11-17 9:14 [PATCH v1 0/3] iio: adc: Provide mult_fract() and make use of it Andy Shevchenko
2026-11-17 9:14 ` [PATCH v1 1/3] math.h: Add mult_fract() that takes struct __Txx_fract as argument Andy Shevchenko
2026-11-17 9:14 ` [PATCH v1 2/3] iio: adc: ad4030: Switch to use mult_fract() helper Andy Shevchenko
@ 2026-11-17 9:14 ` Andy Shevchenko
2026-11-18 2:18 ` [PATCH v1 0/3] iio: adc: Provide mult_fract() and make use of it Marcelo Schmitt
3 siblings, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2026-11-17 9:14 UTC (permalink / raw)
To: Jonathan Cameron, Marcelo Schmitt, Andy Shevchenko,
Cristian Ciocaltea, linux, linux-iio, linux-kernel
Cc: Michael Hennerich, Nuno Sá, Esteban Blanc, Jonathan Cameron,
David Lechner, Andy Shevchenko
Switch the driver to use mult_fract() helper.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
drivers/iio/adc/ltc2378.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/adc/ltc2378.c b/drivers/iio/adc/ltc2378.c
index b0ff2be1aee0..a0c5fdd5e761 100644
--- a/drivers/iio/adc/ltc2378.c
+++ b/drivers/iio/adc/ltc2378.c
@@ -396,9 +396,11 @@ static int ltc2378_read_raw(struct iio_dev *indio_dev,
}
case IIO_CHAN_INFO_SCALE: {
struct u32_fract fract = st->info->internal_div;
+
*val = st->ref_uV / MILLI;
if (fract.numerator && fract.denominator)
- *val = mult_frac(*val, fract.numerator, fract.denominator);
+ *val = mult_fract(*val, &fract);
+
/*
* For all LTC2378-like devices, the amount of bits that express
* voltage magnitude depend on the polarity / output code format:
--
2.50.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v1 0/3] iio: adc: Provide mult_fract() and make use of it
2026-11-17 9:14 [PATCH v1 0/3] iio: adc: Provide mult_fract() and make use of it Andy Shevchenko
` (2 preceding siblings ...)
2026-11-17 9:14 ` [PATCH v1 3/3] iio: adc: ltc2378: " Andy Shevchenko
@ 2026-11-18 2:18 ` Marcelo Schmitt
3 siblings, 0 replies; 6+ messages in thread
From: Marcelo Schmitt @ 2026-11-18 2:18 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jonathan Cameron, Marcelo Schmitt, Cristian Ciocaltea, linux,
linux-iio, linux-kernel, Michael Hennerich, Nuno Sá,
Esteban Blanc, Jonathan Cameron, David Lechner, Andy Shevchenko
On 11/17, Andy Shevchenko wrote:
> In a couple of IIO ADC driver the suggested new helper mult_fract()
> may be used. So, provide it and update the straightforward users.
>
> The helper has potential treewide, hence it's provided directly in math.h.
>
> Andy Shevchenko (3):
> math.h: Add mult_fract() that takes struct __Txx_fract as argument
> iio: adc: ad4030: Switch to use mult_fract() helper
> iio: adc: ltc2378: Switch to use mult_fract() helper
For the whole series
Reviewed-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
Thanks,
Marcelo
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v1 1/3] math.h: Add mult_fract() that takes struct __Txx_fract as argument
2026-11-17 9:14 ` [PATCH v1 1/3] math.h: Add mult_fract() that takes struct __Txx_fract as argument Andy Shevchenko
@ 2026-11-18 8:22 ` Joshua Crofts
0 siblings, 0 replies; 6+ messages in thread
From: Joshua Crofts @ 2026-11-18 8:22 UTC (permalink / raw)
To: Andy Shevchenko
Cc: Jonathan Cameron, Marcelo Schmitt, Cristian Ciocaltea, linux,
linux-iio, linux-kernel, Michael Hennerich, Nuno Sá,
Esteban Blanc, Jonathan Cameron, David Lechner, Andy Shevchenko
On Tue, 17 Nov 2026 10:14:40 +0100
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:
> Add mult_fract() that takes struct __Txx_fract as argument and
> calls do_div() instead of plain divisions.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> include/linux/math.h | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/include/linux/math.h b/include/linux/math.h
> index 1e8fb3efbc8c..ded258df50df 100644
> --- a/include/linux/math.h
> +++ b/include/linux/math.h
> @@ -128,6 +128,10 @@ __STRUCT_FRACT(u32)
> q * n_ + r * n_ / d_; \
> })
>
> +/* Same as above but for a struct __Txx_fract fraction */
> +#define mult_fract(x, f) \
> + mult_frac(x, (f)->numerator, (f)->denominator)
> +
> #define sector_div(a, b) do_div(a, b)
Sashiko has some remarks.
https://sashiko.dev/#/patchset/20261117091638.1463621-1-andriy.shevchenko%40linux.intel.com
--
Kind regards,
Joshua Crofts
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-18 8:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 9:14 [PATCH v1 0/3] iio: adc: Provide mult_fract() and make use of it Andy Shevchenko
2026-11-17 9:14 ` [PATCH v1 1/3] math.h: Add mult_fract() that takes struct __Txx_fract as argument Andy Shevchenko
2026-11-18 8:22 ` Joshua Crofts
2026-11-17 9:14 ` [PATCH v1 2/3] iio: adc: ad4030: Switch to use mult_fract() helper Andy Shevchenko
2026-11-17 9:14 ` [PATCH v1 3/3] iio: adc: ltc2378: " Andy Shevchenko
2026-11-18 2:18 ` [PATCH v1 0/3] iio: adc: Provide mult_fract() and make use of it Marcelo Schmitt
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.