[PATCH 3/3] iio: adc: mt6359-auxadc: fix scale calculation
From: Roman Vivchar via B4 Relay
Date: Tue Nov 03 2026 - 14:11:23 EST
From: Roman Vivchar <rva333@xxxxxxxxxxxxxx>
IIO_CHAN_INFO_SCALE currently returns value without dividing by
2^realbits, overflowing the integer to an invalid value.
Fix this by using IIO_VAL_FRACTIONAL and setting val2 to the ADC
resolution.
Fixes: 3587914bf61d ("iio: adc: Add support for MediaTek MT6357/8/9 Auxiliary ADC")
Signed-off-by: Roman Vivchar <rva333@xxxxxxxxxxxxxx>
---
drivers/iio/adc/mt6359-auxadc.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/adc/mt6359-auxadc.c b/drivers/iio/adc/mt6359-auxadc.c
index 09432d0974cf..3a969c30f633 100644
--- a/drivers/iio/adc/mt6359-auxadc.c
+++ b/drivers/iio/adc/mt6359-auxadc.c
@@ -770,13 +770,9 @@ static int mt6359_auxadc_read_raw(struct iio_dev *indio_dev,
if (mask == IIO_CHAN_INFO_SCALE) {
*val = desc->r_ratio.numerator * cinfo->vref_mV;
+ *val2 = desc->r_ratio.denominator << chan->scan_type.realbits;
- if (desc->r_ratio.denominator > 1) {
- *val2 = desc->r_ratio.denominator;
- return IIO_VAL_FRACTIONAL;
- }
-
- return IIO_VAL_INT;
+ return IIO_VAL_FRACTIONAL;
}
scoped_guard(mutex, &adc_dev->lock) {
--
2.56.0