iio: adc: Provide mult_fract() and make use of it
Subsystems (4)
cover iio: adc: Provide mult_fract() and make use of it
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(-)
Signature · 1 line
2.50.1
PATCH 1/3 math.h: Add mult_fract() that takes struct __Txx_fract as argument
Add mult_fract() that takes struct __Txx_fract as argument and calls do_div() instead of plain divisions.
--- include/linux/math.h | 4 ++++ 1 file changed, 4 insertions(+)
include/linux/math.h +4 -0
@@ -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)/**
Signature · 1 line
2.50.1
Re: [PATCH v1 1/3] math.h: Add mult_fract() that takes struct __Txx_fract as argument
Quoted 13 lines · On Tue, 17 Nov 2026 10:14:40 +0100 Andy Shevchenko…
Add
mult_fract()that takes struct__Txx_fractas argument and callsdo_div()instead of plain divisions.Signed-off-by Andy Shevchenko <[email protected]>--- include/linux/math.h | 4 ++++ 1 file changed, 4 insertions(+)include/linux/math.h +0
-0
include/linux/math.h __STRUCT_FRACT(u32) · line 135
Quoted 8 lines
include/linux/math.h +4
-0@@ -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
Signature · 2 lines
Kind regards, Joshua Crofts
Re: [PATCH v1 1/3] math.h: Add mult_fract() that takes struct __Txx_fract as argument
Quoted 19 lines · Joshua Crofts
Quoted 16 lines · On Tue, 17 Nov 2026 10:14:40 +0100 Andy Shevchenko…
Add
mult_fract()that takes struct__Txx_fractas argument and callsdo_div()instead of plain divisions.Signed-off-by Andy Shevchenko <[email protected]>--- include/linux/math.h | 4 ++++ 1 file changed, 4 insertions(+)include/linux/math.h +0
-0@@ -128,6 +128,10 @@ __STRUCT_FRACT(u32) q * n_ + r * n_ / d_; \ })
Quoted 7 lines
include/linux/math.h __STRUCT_FRACT(u32) · line 135
Quoted 5 lines
include/linux/math.h +4
-0+/* 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.
Strange that I have got no email on that...
Quoted 1 line
https://sashiko.dev/#/patchset/20261117091638.1463621-1-andriy.shevchenko%40linux.intel.com
Ah, yes, the commit message is stale, I need to make it up to date.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v1 1/3] math.h: Add mult_fract() that takes struct __Txx_fract as argument
Quoted 28 lines · On Wed, 18 Nov 2026 11:45:18 +0200 Andy Shevchenko…
Quoted 19 lines · Joshua Crofts
Quoted 16 lines · On Tue, 17 Nov 2026 10:14:40 +0100 Andy Shevchenko…
Add
mult_fract()that takes struct__Txx_fractas argument and callsdo_div()instead of plain divisions.Signed-off-by Andy Shevchenko <[email protected]>--- include/linux/math.h | 4 ++++ 1 file changed, 4 insertions(+)include/linux/math.h +0
-0@@ -128,6 +128,10 @@ __STRUCT_FRACT(u32) q * n_ + r * n_ / d_; \ })Quoted 7 lines
include/linux/math.h __STRUCT_FRACT(u32) · line 135
Quoted 5 lines
include/linux/math.h +4
-0+/* 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.
Quoted 1 line
Strange that I have got no email on that...
Yeah, for IIO Sashiko doesn't send emails, only if a patch series touches any dt-bindings stuff (new drivers etc.).
Signature · 2 lines
Kind regards, Joshua Crofts
PATCH 2/3 iio: adc: ad4030: Switch to use mult_fract() helper
In reply to Andy ShevchenkoSwitch the driver to use mult_fract() helper.
--- drivers/iio/adc/ad4030.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/iio/adc/ad4030.c +6 -7
@@ -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
Signature · 1 line
2.50.1
PATCH 3/3 iio: adc: ltc2378: Switch to use mult_fract() helper
In reply to Andy ShevchenkoSwitch the driver to use mult_fract() helper.
--- drivers/iio/adc/ltc2378.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/ltc2378.c +3 -1
@@ -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:
Signature · 1 line
2.50.1
Quoted 9 lines · 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: Addmult_fract()that takes struct__Txx_fractas argument
iio: adc: ad4030: Switch to usemult_fract()helper
iio: adc: ltc2378: Switch to usemult_fract()helper
For the whole series
Thanks,
Marcelo