* [PATCH 1/5] iio: dac: ad5758: Fix alignment for DMA safety
2026-09-18 12:20 [PATCH 0/5] iio: dac: ad5758: fix DMA alignment, raw range, offset and 4-20 mA Arka Mondal
@ 2026-09-18 12:20 ` Arka Mondal
2026-09-18 12:20 ` [PATCH 2/5] iio: dac: ad5758: Reject out-of-range raw values Arka Mondal
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Arka Mondal @ 2026-09-18 12:20 UTC (permalink / raw)
To: Jonathan Cameron, Nuno Sá, Michael Hennerich
Cc: David Lechner, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, linux, linux-iio, devicetree, linux-kernel,
arkamondalofficial, Arka Mondal
ad5758_spi_reg_read() reads into st->d32[2] with spi_sync_transfer(),
but d32 is not marked __aligned(IIO_DMA_MINALIGN), so it can share a
cacheline with the fields before it. When DMA is not cache coherent,
the cache invalidation after the read can discard CPU writes to those
fields.
Mark d32 __aligned(IIO_DMA_MINALIGN). It is the last member of the
struct, so nothing comes after it.
Fixes: 28d1a7ac2a0d ("iio: dac: Add AD5758 support")
Signed-off-by: Arka Mondal <arka@arkamondal.net>
---
Notes:
Compile tested only; no relevant hardware available.
drivers/iio/dac/ad5758.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/iio/dac/ad5758.c b/drivers/iio/dac/ad5758.c
index 44efa373cd80..ba381bd252d1 100644
--- a/drivers/iio/dac/ad5758.c
+++ b/drivers/iio/dac/ad5758.c
@@ -117,7 +117,7 @@ struct ad5758_state {
unsigned int dc_dc_ilim;
unsigned int slew_time;
bool pwr_down;
- __be32 d32[3];
+ __be32 d32[3] __aligned(IIO_DMA_MINALIGN);
};
/*
--
2.55.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 2/5] iio: dac: ad5758: Reject out-of-range raw values
2026-09-18 12:20 [PATCH 0/5] iio: dac: ad5758: fix DMA alignment, raw range, offset and 4-20 mA Arka Mondal
2026-09-18 12:20 ` [PATCH 1/5] iio: dac: ad5758: Fix alignment for DMA safety Arka Mondal
@ 2026-09-18 12:20 ` Arka Mondal
2026-09-18 12:20 ` [PATCH 3/5] iio: dac: ad5758: Fix the offset calculation Arka Mondal
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Arka Mondal @ 2026-09-18 12:20 UTC (permalink / raw)
To: Jonathan Cameron, Nuno Sá, Michael Hennerich
Cc: David Lechner, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, linux, linux-iio, devicetree, linux-kernel,
arkamondalofficial, Arka Mondal
ad5758_write_raw() passes the value from userspace straight to
ad5758_spi_reg_write(), which keeps only the low 16 bits. Writing -1
to the raw attribute gives full-scale output, and 65536 gives code 0.
Return -EINVAL for values outside 0 to U16_MAX, as ad5755 does.
Fixes: 28d1a7ac2a0d ("iio: dac: Add AD5758 support")
Signed-off-by: Arka Mondal <arka@arkamondal.net>
---
Notes:
Compile tested only; no relevant hardware available.
drivers/iio/dac/ad5758.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/iio/dac/ad5758.c b/drivers/iio/dac/ad5758.c
index ba381bd252d1..2a9e907b5eb8 100644
--- a/drivers/iio/dac/ad5758.c
+++ b/drivers/iio/dac/ad5758.c
@@ -556,6 +556,9 @@ static int ad5758_write_raw(struct iio_dev *indio_dev,
switch (info) {
case IIO_CHAN_INFO_RAW:
+ if (val < 0 || val > U16_MAX)
+ return -EINVAL;
+
mutex_lock(&st->lock);
ret = ad5758_spi_reg_write(st, AD5758_DAC_INPUT, val);
mutex_unlock(&st->lock);
--
2.55.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 3/5] iio: dac: ad5758: Fix the offset calculation
2026-09-18 12:20 [PATCH 0/5] iio: dac: ad5758: fix DMA alignment, raw range, offset and 4-20 mA Arka Mondal
2026-09-18 12:20 ` [PATCH 1/5] iio: dac: ad5758: Fix alignment for DMA safety Arka Mondal
2026-09-18 12:20 ` [PATCH 2/5] iio: dac: ad5758: Reject out-of-range raw values Arka Mondal
@ 2026-09-18 12:20 ` Arka Mondal
2026-09-18 12:20 ` [PATCH 4/5] dt-bindings: iio: dac: adi,ad5758: Fix the 4 mA to 20 mA current range Arka Mondal
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Arka Mondal @ 2026-09-18 12:20 UTC (permalink / raw)
To: Jonathan Cameron, Nuno Sá, Michael Hennerich
Cc: David Lechner, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, linux, linux-iio, devicetree, linux-kernel,
arkamondalofficial, Arka Mondal
The offset is a count of DAC codes, so the microamp or microvolt units
of min and max cancel out and the final division by 1000 is wrong. For
the +-20 mA range the driver reports -32 instead of -32768. For the
+-5 V and +-10 V ranges min * (1 << 16) also overflows int, and the
reported offset is 0.
Drop the division and do the multiplication in 64 bits.
Fixes: 28d1a7ac2a0d ("iio: dac: Add AD5758 support")
Signed-off-by: Arka Mondal <arka@arkamondal.net>
---
Notes:
Compile tested only; no relevant hardware available.
drivers/iio/dac/ad5758.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/dac/ad5758.c b/drivers/iio/dac/ad5758.c
index 2a9e907b5eb8..1e21ad2a050d 100644
--- a/drivers/iio/dac/ad5758.c
+++ b/drivers/iio/dac/ad5758.c
@@ -9,6 +9,7 @@
#include <linux/bsearch.h>
#include <linux/delay.h>
#include <linux/kernel.h>
+#include <linux/math64.h>
#include <linux/module.h>
#include <linux/property.h>
#include <linux/spi/spi.h>
@@ -540,7 +541,7 @@ static int ad5758_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_OFFSET:
min = st->out_range.min;
max = st->out_range.max;
- *val = ((min * (1 << 16)) / (max - min)) / 1000;
+ *val = div_s64((s64)min * (1 << 16), max - min);
return IIO_VAL_INT;
default:
return -EINVAL;
--
2.55.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 4/5] dt-bindings: iio: dac: adi,ad5758: Fix the 4 mA to 20 mA current range
2026-09-18 12:20 [PATCH 0/5] iio: dac: ad5758: fix DMA alignment, raw range, offset and 4-20 mA Arka Mondal
` (2 preceding siblings ...)
2026-09-18 12:20 ` [PATCH 3/5] iio: dac: ad5758: Fix the offset calculation Arka Mondal
@ 2026-09-18 12:20 ` Arka Mondal
2026-09-18 12:20 ` [PATCH 5/5] iio: dac: ad5758: " Arka Mondal
2026-09-18 15:22 ` [PATCH 0/5] iio: dac: ad5758: fix DMA alignment, raw range, offset and 4-20 mA Nuno Sá
5 siblings, 0 replies; 7+ messages in thread
From: Arka Mondal @ 2026-09-18 12:20 UTC (permalink / raw)
To: Jonathan Cameron, Nuno Sá, Michael Hennerich
Cc: David Lechner, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, linux, linux-iio, devicetree, linux-kernel,
arkamondalofficial, Arka Mondal
adi,range-microamp gives the 4 mA to 20 mA range as <4 24000>. The
values are in microamps, so this reads as 4 uA to 24 mA. The original
text binding described <4 24000> as the "4 mA to 20 mA current range",
and the data sheet (Rev. B, Table 32) confirms range code 1010 is
4 mA to 20 mA.
Add <4000 20000> and mark <4 24000> deprecated, so existing device
trees still validate.
Fixes: 777baca07ef1 ("dt-bindings: iio: dac: Add docs for AD5758 DAC")
Signed-off-by: Arka Mondal <arka@arkamondal.net>
---
Notes:
Checked with make dt_binding_check; no relevant hardware available.
Documentation/devicetree/bindings/iio/dac/adi,ad5758.yaml | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/Documentation/devicetree/bindings/iio/dac/adi,ad5758.yaml b/Documentation/devicetree/bindings/iio/dac/adi,ad5758.yaml
index 5121685337b5..ef0398170eb7 100644
--- a/Documentation/devicetree/bindings/iio/dac/adi,ad5758.yaml
+++ b/Documentation/devicetree/bindings/iio/dac/adi,ad5758.yaml
@@ -65,9 +65,13 @@ properties:
- items:
- const: 0
- enum: [20000, 24000]
+ - items:
+ - const: 4000
+ - const: 20000
- items:
- const: 4
- const: 24000
+ deprecated: true
- items:
- const: -20000
- const: 20000
--
2.55.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 5/5] iio: dac: ad5758: Fix the 4 mA to 20 mA current range
2026-09-18 12:20 [PATCH 0/5] iio: dac: ad5758: fix DMA alignment, raw range, offset and 4-20 mA Arka Mondal
` (3 preceding siblings ...)
2026-09-18 12:20 ` [PATCH 4/5] dt-bindings: iio: dac: adi,ad5758: Fix the 4 mA to 20 mA current range Arka Mondal
@ 2026-09-18 12:20 ` Arka Mondal
2026-09-18 15:22 ` [PATCH 0/5] iio: dac: ad5758: fix DMA alignment, raw range, offset and 4-20 mA Nuno Sá
5 siblings, 0 replies; 7+ messages in thread
From: Arka Mondal @ 2026-09-18 12:20 UTC (permalink / raw)
To: Jonathan Cameron, Nuno Sá, Michael Hennerich
Cc: David Lechner, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, linux, linux-iio, devicetree, linux-kernel,
arkamondalofficial, Arka Mondal
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@arkamondal.net>
---
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
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH 0/5] iio: dac: ad5758: fix DMA alignment, raw range, offset and 4-20 mA
2026-09-18 12:20 [PATCH 0/5] iio: dac: ad5758: fix DMA alignment, raw range, offset and 4-20 mA Arka Mondal
` (4 preceding siblings ...)
2026-09-18 12:20 ` [PATCH 5/5] iio: dac: ad5758: " Arka Mondal
@ 2026-09-18 15:22 ` Nuno Sá
5 siblings, 0 replies; 7+ messages in thread
From: Nuno Sá @ 2026-09-18 15:22 UTC (permalink / raw)
To: Arka Mondal, Jonathan Cameron, Nuno Sá, Michael Hennerich
Cc: David Lechner, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, linux, linux-iio, devicetree, linux-kernel,
arkamondalofficial
On Fri, 2026-09-18 at 21:20 +0900, Arka Mondal wrote:
> The first attempt to send this series on 2026-09-18 was rejected by
> the kernel.org mail servers, so it did not reach the lists. The patches
> are unchanged.
>
> This series fixes four bugs in the AD5758 driver, all present since
> commit 28d1a7ac2a0d ("iio: dac: Add AD5758 support"). The last bug
> takes two patches, one for the binding and one for the driver.
>
> Patch 1 marks the SPI receive buffer __aligned(IIO_DMA_MINALIGN), so
> it no longer shares a cacheline with other driver state. The 2022
> conversion of IIO drivers to IIO_DMA_MINALIGN only changed existing
> ____cacheline_aligned markings, and this driver had none.
>
> Patch 2 rejects raw values outside 0 to U16_MAX. Writing -1 currently
> gives full-scale output.
>
> Patch 3 fixes the offset for every range that does not start at 0.
> The +-20 mA range reports -32 instead of -32768.
>
> Patches 4 and 5 fix the 4 mA to 20 mA range. The binding and the
> driver give it as <4 24000>, which is 4 uA to 24 mA. The data sheet
> (Rev. B, Table 32) and the original text binding say range code 1010
> is 4 mA to 20 mA. The old value is still accepted: the binding marks
> it deprecated and the driver maps it to the corrected range, so
> existing device trees keep working.
>
> Compile tested only; no relevant hardware available. The binding was
> checked with make dt_binding_check and with test device trees:
> <4000 20000> and <4 24000> are accepted; <4 20000> is rejected.
>
> Arka Mondal (5):
> iio: dac: ad5758: Fix alignment for DMA safety
> iio: dac: ad5758: Reject out-of-range raw values
> iio: dac: ad5758: Fix the offset calculation
> dt-bindings: iio: dac: adi,ad5758: Fix the 4 mA to 20 mA current range
> iio: dac: ad5758: Fix the 4 mA to 20 mA current range
>
> .../bindings/iio/dac/adi,ad5758.yaml | 4 ++++
> drivers/iio/dac/ad5758.c | 18 ++++++++++++++----
> 2 files changed, 18 insertions(+), 4 deletions(-)
>
>
> base-commit: 08df884136f1c1197bab2a27814404fd329d9aac
LGTM,
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
^ permalink raw reply [flat|nested] 7+ messages in thread