* [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
` (2 more replies)
0 siblings, 3 replies; 4+ 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] 4+ 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-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
2 siblings, 0 replies; 4+ 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 [flat|nested] 4+ 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
2 siblings, 0 replies; 4+ 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 [flat|nested] 4+ 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
2 siblings, 0 replies; 4+ 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 [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-17 9:16 UTC | newest]
Thread overview: 4+ 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-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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®