[PATCH RFC] iio: adc: ad4030: fix calibscale read/write unit mismatch
From: Giorgi Tchankvetadze
Date: Wed Feb 25 2026 - 06:34:57 EST
The read path returns calibscale in IIO_VAL_INT_PLUS_NANO but the write
path treats it as MICRO. Since no write_raw_get_fmt is provided, the
IIO core defaults to MICRO when parsing userspace input.
This means reading calibscale and writing it back results in a ~1000x
gain error.
Change the read path and available range to use MICRO to match the
write path.
Fixes: 0cb8b324852f ("iio: adc: ad4030: add driver for ad4030-24")
Signed-off-by: Giorgi Tchankvetadze <giorgitchankvetadze1997@xxxxxxxxx>
---
drivers/iio/adc/ad4030.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/adc/ad4030.c b/drivers/iio/adc/ad4030.c
index def3e1d01ceb..3d823648371d 100644
--- a/drivers/iio/adc/ad4030.c
+++ b/drivers/iio/adc/ad4030.c
@@ -423,10 +423,10 @@ static int ad4030_get_chan_calibscale(struct iio_dev *indio_dev,
/* From datasheet: multiplied output = input × gain word/0x8000 */
*val = gain / AD4030_GAIN_MIDLE_POINT;
- *val2 = mul_u64_u32_div(gain % AD4030_GAIN_MIDLE_POINT, NANO,
+ *val2 = mul_u64_u32_div(gain % AD4030_GAIN_MIDLE_POINT, MICRO,
AD4030_GAIN_MIDLE_POINT);
- return IIO_VAL_INT_PLUS_NANO;
+ return IIO_VAL_INT_PLUS_MICRO;
}
/* Returns the offset where 1 LSB = (VREF/2^precision_bits - 1)/gain */
@@ -720,8 +720,8 @@ static irqreturn_t ad4030_trigger_handler(int irq, void *p)
static const int ad4030_gain_avail[3][2] = {
{ 0, 0 },
- { 0, 30518 },
- { 1, 999969482 },
+ { 0, 30 },
+ { 1, 999969 },
};
static int ad4030_read_avail(struct iio_dev *indio_dev,
@@ -739,7 +739,7 @@ static int ad4030_read_avail(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_CALIBSCALE:
*vals = (void *)ad4030_gain_avail;
- *type = IIO_VAL_INT_PLUS_NANO;
+ *type = IIO_VAL_INT_PLUS_MICRO;
return IIO_AVAIL_RANGE;
case IIO_CHAN_INFO_OVERSAMPLING_RATIO:
--
2.52.0