[PATCH 5/5] iio: dac: ad5758: Fix the 4 mA to 20 mA current range
From: Arka Mondal
Date: Fri Sep 18 2026 - 08:50:40 EST
Range code 1010 selects 4 mA to 20 mA (data sheet Rev. B, Table 32),
but the driver describes it as 4 uA to 24 mA. With the reported scale
and offset, userspace converts raw code 0 to about 0 mA instead of
4 mA, and full scale to about 23 mA instead of 20 mA.
Describe the range as 4000 to 20000 uA and rename the enum entry to
match. Map the deprecated <4 24000> device tree value to the corrected
range, so existing device trees keep working.
Fixes: 28d1a7ac2a0d ("iio: dac: Add AD5758 support")
Signed-off-by: Arka Mondal <arka@xxxxxxxxxxxxxx>
---
Notes:
Compile tested only; no relevant hardware available.
drivers/iio/dac/ad5758.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/iio/dac/ad5758.c b/drivers/iio/dac/ad5758.c
index 1e21ad2a050d..b152001f38d4 100644
--- a/drivers/iio/dac/ad5758.c
+++ b/drivers/iio/dac/ad5758.c
@@ -141,7 +141,7 @@ enum ad5758_output_range {
AD5758_RANGE_PLUSMINUS_10V,
AD5758_RANGE_0mA_20mA = 8,
AD5758_RANGE_0mA_24mA,
- AD5758_RANGE_4mA_24mA,
+ AD5758_RANGE_4mA_20mA,
AD5758_RANGE_PLUSMINUS_20mA,
AD5758_RANGE_PLUSMINUS_24mA,
AD5758_RANGE_MINUS_1mA_PLUS_22mA,
@@ -164,7 +164,7 @@ static const struct ad5758_range ad5758_voltage_range[] = {
static const struct ad5758_range ad5758_current_range[] = {
{ AD5758_RANGE_0mA_20mA, 0, 20000},
{ AD5758_RANGE_0mA_24mA, 0, 24000 },
- { AD5758_RANGE_4mA_24mA, 4, 24000 },
+ { AD5758_RANGE_4mA_20mA, 4000, 20000 },
{ AD5758_RANGE_PLUSMINUS_20mA, -20000, 20000 },
{ AD5758_RANGE_PLUSMINUS_24mA, -24000, 24000 },
{ AD5758_RANGE_MINUS_1mA_PLUS_22mA, -1000, 22000 },
@@ -747,6 +747,12 @@ static int ad5758_parse_dt(struct ad5758_state *st)
"Missing \"range-microamp\" property\n");
return ret;
}
+
+ if (tmparray[0] == 4 && tmparray[1] == 24000) {
+ tmparray[0] = 4000;
+ tmparray[1] = 20000;
+ }
+
range = ad5758_current_range;
size = ARRAY_SIZE(ad5758_current_range);
}
--
2.55.0