* [PATCH v3 1/5] dt-bindings: iio: dac: ad5504: add output-range and missing gpios
2026-05-09 14:20 [PATCH v3 0/5] iio: dac: ad5504: bindings, cleanups, and scale fixes Taha Ed-Dafili
@ 2026-05-09 14:20 ` Taha Ed-Dafili
2026-05-11 16:22 ` Conor Dooley
2026-05-09 14:20 ` [PATCH v3 2/5] iio: dac: ad5504: sort headers alphabetically Taha Ed-Dafili
` (4 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Taha Ed-Dafili @ 2026-05-09 14:20 UTC (permalink / raw)
To: lars, Michael.Hennerich, jic23, robh, krzk+dt, conor+dt
Cc: dlechner, nuno.sa, andy, skhan, linux-iio, devicetree,
linux-kernel, Taha Ed-Dafili
The AD5504 output range (0-30V or 0-60V) is determined by the R_SEL pin.
Use standard output-range-microvolt and range-sel-gpios properties to
describe the hardware configuration of the R_SEL pin. Ensure mutual
exclusivity using the not/required logic. Additionally, add missing
vlogic-supply, clr-gpios, ldac-gpios and datasheet links, and provide
a complete usage example.
Signed-off-by: Taha Ed-Dafili <0rayn.dev@gmail.com>
---
.../bindings/iio/dac/adi,ad5504.yaml | 39 ++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/iio/dac/adi,ad5504.yaml b/Documentation/devicetree/bindings/iio/dac/adi,ad5504.yaml
index 9c2c038683b4..e0123dceaa33 100644
--- a/Documentation/devicetree/bindings/iio/dac/adi,ad5504.yaml
+++ b/Documentation/devicetree/bindings/iio/dac/adi,ad5504.yaml
@@ -10,8 +10,10 @@ maintainers:
- Lars-Peter Clausen <lars@metafoo.de>
- Jonathan Cameron <jic23@kernel.org>
-description:
+description: |
High voltage (up to 60V) DACs with temperature sensor alarm function
+ https://www.analog.com/media/en/technical-documentation/data-sheets/ad5504.pdf
+ https://www.analog.com/media/en/technical-documentation/data-sheets/ad5501.pdf
properties:
compatible:
@@ -27,6 +29,29 @@ properties:
maxItems: 1
vcc-supply: true
+ vlogic-supply: true
+
+ output-range-microvolt:
+ description: |
+ Specify the channel output full scale range. The R_SEL pin
+ determines if the range is 0-30V or 0-60V.
+ items:
+ - const: 0
+ - enum: [30000000, 60000000]
+ default: [0, 60000000]
+
+ range-sel-gpios:
+ description:
+ GPIO connected to the R_SEL pin to select the output voltage range.
+ maxItems: 1
+
+ clr-gpios:
+ description: GPIO that controls the /CLR pin (active low).
+ maxItems: 1
+
+ ldac-gpios:
+ description: GPIO that controls the /LDAC pin (active low).
+ maxItems: 1
additionalProperties: false
@@ -34,9 +59,17 @@ required:
- compatible
- reg
+allOf:
+ - not:
+ required:
+ - range-sel-gpios
+ - output-range-microvolt
+
examples:
- |
#include <dt-bindings/interrupt-controller/irq.h>
+ #include <dt-bindings/gpio/gpio.h>
+
spi {
#address-cells = <1>;
#size-cells = <0>;
@@ -45,6 +78,10 @@ examples:
compatible = "adi,ad5504";
vcc-supply = <&dac_vcc>;
interrupts = <55 IRQ_TYPE_EDGE_FALLING>;
+
+ output-range-microvolt = <0 60000000>;
+ clr-gpios = <&gpio 4 GPIO_ACTIVE_LOW>;
+ ldac-gpios = <&gpio 5 GPIO_ACTIVE_LOW>;
};
};
...
--
2.47.3
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v3 1/5] dt-bindings: iio: dac: ad5504: add output-range and missing gpios
2026-05-09 14:20 ` [PATCH v3 1/5] dt-bindings: iio: dac: ad5504: add output-range and missing gpios Taha Ed-Dafili
@ 2026-05-11 16:22 ` Conor Dooley
0 siblings, 0 replies; 10+ messages in thread
From: Conor Dooley @ 2026-05-11 16:22 UTC (permalink / raw)
To: Taha Ed-Dafili
Cc: lars, Michael.Hennerich, jic23, robh, krzk+dt, conor+dt, dlechner,
nuno.sa, andy, skhan, linux-iio, devicetree, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 600 bytes --]
On Sat, May 09, 2026 at 03:20:39PM +0100, Taha Ed-Dafili wrote:
> The AD5504 output range (0-30V or 0-60V) is determined by the R_SEL pin.
>
> Use standard output-range-microvolt and range-sel-gpios properties to
> describe the hardware configuration of the R_SEL pin. Ensure mutual
> exclusivity using the not/required logic. Additionally, add missing
> vlogic-supply, clr-gpios, ldac-gpios and datasheet links, and provide
> a complete usage example.
>
> Signed-off-by: Taha Ed-Dafili <0rayn.dev@gmail.com>
Acked-by: Conor Dooley <conor.dooley@microchip.com>
pw-bot: not-applicable
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH v3 2/5] iio: dac: ad5504: sort headers alphabetically
2026-05-09 14:20 [PATCH v3 0/5] iio: dac: ad5504: bindings, cleanups, and scale fixes Taha Ed-Dafili
2026-05-09 14:20 ` [PATCH v3 1/5] dt-bindings: iio: dac: ad5504: add output-range and missing gpios Taha Ed-Dafili
@ 2026-05-09 14:20 ` Taha Ed-Dafili
2026-05-09 14:20 ` [PATCH v3 3/5] iio: dac: ad5504: Align headers with IWYU principle Taha Ed-Dafili
` (3 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Taha Ed-Dafili @ 2026-05-09 14:20 UTC (permalink / raw)
To: lars, Michael.Hennerich, jic23, robh, krzk+dt, conor+dt
Cc: dlechner, nuno.sa, andy, skhan, linux-iio, devicetree,
linux-kernel, Taha Ed-Dafili
Rearrange the include headers in alphabetical order to follow the
standard kernel coding style. This is a preparatory cleanup with
no functional changes.
Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Taha Ed-Dafili <0rayn.dev@gmail.com>
---
drivers/iio/dac/ad5504.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/dac/ad5504.c b/drivers/iio/dac/ad5504.c
index 355bcb6a8ba0..03ce37e2c616 100644
--- a/drivers/iio/dac/ad5504.c
+++ b/drivers/iio/dac/ad5504.c
@@ -5,21 +5,21 @@
* Copyright 2011 Analog Devices Inc.
*/
-#include <linux/interrupt.h>
-#include <linux/fs.h>
+#include <linux/bitops.h>
#include <linux/device.h>
+#include <linux/fs.h>
+#include <linux/interrupt.h>
#include <linux/kernel.h>
-#include <linux/spi/spi.h>
+#include <linux/module.h>
+#include <linux/regulator/consumer.h>
#include <linux/slab.h>
+#include <linux/spi/spi.h>
#include <linux/sysfs.h>
-#include <linux/regulator/consumer.h>
-#include <linux/module.h>
-#include <linux/bitops.h>
+#include <linux/iio/dac/ad5504.h>
+#include <linux/iio/events.h>
#include <linux/iio/iio.h>
#include <linux/iio/sysfs.h>
-#include <linux/iio/events.h>
-#include <linux/iio/dac/ad5504.h>
#define AD5504_RES_MASK GENMASK(11, 0)
#define AD5504_CMD_READ BIT(15)
--
2.47.3
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v3 3/5] iio: dac: ad5504: Align headers with IWYU principle
2026-05-09 14:20 [PATCH v3 0/5] iio: dac: ad5504: bindings, cleanups, and scale fixes Taha Ed-Dafili
2026-05-09 14:20 ` [PATCH v3 1/5] dt-bindings: iio: dac: ad5504: add output-range and missing gpios Taha Ed-Dafili
2026-05-09 14:20 ` [PATCH v3 2/5] iio: dac: ad5504: sort headers alphabetically Taha Ed-Dafili
@ 2026-05-09 14:20 ` Taha Ed-Dafili
2026-05-09 14:20 ` [PATCH v3 4/5] iio: dac: ad5504: introduce local dev pointer Taha Ed-Dafili
` (2 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Taha Ed-Dafili @ 2026-05-09 14:20 UTC (permalink / raw)
To: lars, Michael.Hennerich, jic23, robh, krzk+dt, conor+dt
Cc: dlechner, nuno.sa, andy, skhan, linux-iio, devicetree,
linux-kernel, Taha Ed-Dafili
Update the header inclusions to follow the IWYU principle and ensure
they are sorted alphabetically:
- Remove <linux/fs.h>, <linux/slab.h>, and <linux/kernel.h> as they
are unused. The driver relies on devm_ managed allocations, so slab
is not required.
- Replace <linux/bitops.h> with <linux/bits.h> as only the BIT() and
GENMASK() macros are used.
- Add <linux/mod_devicetable.h> for struct spi_device_id.
- Add <linux/errno.h> and <linux/types.h> for error codes and data types.
- Add <asm/byteorder.h> for cpu_to_be16().
- Add <linux/array_size.h> for ARRAY_SIZE().
- Add <linux/kstrtox.h> for string to integer conversions.
Signed-off-by: Taha Ed-Dafili <0rayn.dev@gmail.com>
---
drivers/iio/dac/ad5504.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/iio/dac/ad5504.c b/drivers/iio/dac/ad5504.c
index 03ce37e2c616..57e6eeed26ef 100644
--- a/drivers/iio/dac/ad5504.c
+++ b/drivers/iio/dac/ad5504.c
@@ -5,16 +5,19 @@
* Copyright 2011 Analog Devices Inc.
*/
-#include <linux/bitops.h>
+#include <asm/byteorder.h>
+#include <linux/array_size.h>
+#include <linux/bits.h>
#include <linux/device.h>
-#include <linux/fs.h>
+#include <linux/errno.h>
#include <linux/interrupt.h>
-#include <linux/kernel.h>
+#include <linux/kstrtox.h>
+#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/regulator/consumer.h>
-#include <linux/slab.h>
#include <linux/spi/spi.h>
#include <linux/sysfs.h>
+#include <linux/types.h>
#include <linux/iio/dac/ad5504.h>
#include <linux/iio/events.h>
--
2.47.3
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v3 4/5] iio: dac: ad5504: introduce local dev pointer
2026-05-09 14:20 [PATCH v3 0/5] iio: dac: ad5504: bindings, cleanups, and scale fixes Taha Ed-Dafili
` (2 preceding siblings ...)
2026-05-09 14:20 ` [PATCH v3 3/5] iio: dac: ad5504: Align headers with IWYU principle Taha Ed-Dafili
@ 2026-05-09 14:20 ` Taha Ed-Dafili
2026-05-09 14:20 ` [PATCH v3 5/5] iio: dac: ad5504: fix scale via output-range-microvolt Taha Ed-Dafili
2026-05-09 20:46 ` [PATCH v3 0/5] iio: dac: ad5504: bindings, cleanups, and scale fixes David Lechner
5 siblings, 0 replies; 10+ messages in thread
From: Taha Ed-Dafili @ 2026-05-09 14:20 UTC (permalink / raw)
To: lars, Michael.Hennerich, jic23, robh, krzk+dt, conor+dt
Cc: dlechner, nuno.sa, andy, skhan, linux-iio, devicetree,
linux-kernel, Taha Ed-Dafili
Replace &spi->dev with a local dev pointer to shorten lines, fix
alignment, and improve overall readability in the probe function.
Signed-off-by: Taha Ed-Dafili <0rayn.dev@gmail.com>
---
drivers/iio/dac/ad5504.c | 23 ++++++++++++-----------
1 file changed, 12 insertions(+), 11 deletions(-)
diff --git a/drivers/iio/dac/ad5504.c b/drivers/iio/dac/ad5504.c
index 57e6eeed26ef..9e95da6e49d6 100644
--- a/drivers/iio/dac/ad5504.c
+++ b/drivers/iio/dac/ad5504.c
@@ -273,25 +273,26 @@ static const struct iio_chan_spec ad5504_channels[] = {
static int ad5504_probe(struct spi_device *spi)
{
- const struct ad5504_platform_data *pdata = dev_get_platdata(&spi->dev);
+ struct device *dev = &spi->dev;
+ const struct ad5504_platform_data *pdata = dev_get_platdata(dev);
struct iio_dev *indio_dev;
struct ad5504_state *st;
int ret;
- indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
if (!indio_dev)
return -ENOMEM;
st = iio_priv(indio_dev);
- ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vcc");
+ ret = devm_regulator_get_enable_read_voltage(dev, "vcc");
if (ret < 0 && ret != -ENODEV)
return ret;
if (ret == -ENODEV) {
if (pdata->vref_mv)
st->vref_mv = pdata->vref_mv;
else
- dev_warn(&spi->dev, "reference voltage unspecified\n");
+ dev_warn(dev, "reference voltage unspecified\n");
} else {
st->vref_mv = ret / 1000;
}
@@ -307,17 +308,17 @@ static int ad5504_probe(struct spi_device *spi)
indio_dev->modes = INDIO_DIRECT_MODE;
if (spi->irq) {
- ret = devm_request_threaded_irq(&spi->dev, spi->irq,
- NULL,
- &ad5504_event_handler,
- IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
- spi_get_device_id(st->spi)->name,
- indio_dev);
+ ret = devm_request_threaded_irq(dev, spi->irq,
+ NULL,
+ &ad5504_event_handler,
+ IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
+ spi_get_device_id(st->spi)->name,
+ indio_dev);
if (ret)
return ret;
}
- return devm_iio_device_register(&spi->dev, indio_dev);
+ return devm_iio_device_register(dev, indio_dev);
}
static const struct spi_device_id ad5504_id[] = {
--
2.47.3
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH v3 5/5] iio: dac: ad5504: fix scale via output-range-microvolt
2026-05-09 14:20 [PATCH v3 0/5] iio: dac: ad5504: bindings, cleanups, and scale fixes Taha Ed-Dafili
` (3 preceding siblings ...)
2026-05-09 14:20 ` [PATCH v3 4/5] iio: dac: ad5504: introduce local dev pointer Taha Ed-Dafili
@ 2026-05-09 14:20 ` Taha Ed-Dafili
2026-05-09 14:57 ` Jonathan Cameron
2026-05-09 20:59 ` David Lechner
2026-05-09 20:46 ` [PATCH v3 0/5] iio: dac: ad5504: bindings, cleanups, and scale fixes David Lechner
5 siblings, 2 replies; 10+ messages in thread
From: Taha Ed-Dafili @ 2026-05-09 14:20 UTC (permalink / raw)
To: lars, Michael.Hennerich, jic23, robh, krzk+dt, conor+dt
Cc: dlechner, nuno.sa, andy, skhan, linux-iio, devicetree,
linux-kernel, Taha Ed-Dafili
The AD5504 full-scale range is hardware-determined by the R_SEL pin,
not the VCC supply voltage.
Fix the scaling logic by reading the standard 'output-range-microvolt'
property from the device tree instead of querying the VCC regulator or
relying on legacy platform data (pdata).
As a result of this transition:
- The 'vcc' regulator is now only enabled, not read.
- Legacy pdata support is removed, as it is no longer required for
fallback voltage calculations.
- Strict array bounds checking is added for the DT property.
Signed-off-by: Taha Ed-Dafili <0rayn.dev@gmail.com>
---
drivers/iio/dac/ad5504.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/drivers/iio/dac/ad5504.c b/drivers/iio/dac/ad5504.c
index 9e95da6e49d6..040f580b8282 100644
--- a/drivers/iio/dac/ad5504.c
+++ b/drivers/iio/dac/ad5504.c
@@ -14,10 +14,12 @@
#include <linux/kstrtox.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
+#include <linux/property.h>
#include <linux/regulator/consumer.h>
#include <linux/spi/spi.h>
#include <linux/sysfs.h>
#include <linux/types.h>
+#include <linux/units.h>
#include <linux/iio/dac/ad5504.h>
#include <linux/iio/events.h>
@@ -274,9 +276,9 @@ static const struct iio_chan_spec ad5504_channels[] = {
static int ad5504_probe(struct spi_device *spi)
{
struct device *dev = &spi->dev;
- const struct ad5504_platform_data *pdata = dev_get_platdata(dev);
struct iio_dev *indio_dev;
struct ad5504_state *st;
+ u32 range[2];
int ret;
indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
@@ -285,16 +287,19 @@ static int ad5504_probe(struct spi_device *spi)
st = iio_priv(indio_dev);
- ret = devm_regulator_get_enable_read_voltage(dev, "vcc");
- if (ret < 0 && ret != -ENODEV)
+ ret = devm_regulator_get_enable(dev, "vcc");
+ if (ret && ret != -ENODEV)
return ret;
- if (ret == -ENODEV) {
- if (pdata->vref_mv)
- st->vref_mv = pdata->vref_mv;
- else
- dev_warn(dev, "reference voltage unspecified\n");
- } else {
- st->vref_mv = ret / 1000;
+
+ st->vref_mv = 60 * MILLI;
+ ret = device_property_read_u32_array(dev, "output-range-microvolt",
+ range, ARRAY_SIZE(range));
+ if (!ret) {
+ if (range[0] != 0 || (range[1] != 30 * MICRO && range[1] != 60 * MICRO))
+ return -EINVAL;
+
+ if (range[1] == 30 * MICRO)
+ st->vref_mv = 30 * MILLI;
}
st->spi = spi;
--
2.47.3
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH v3 5/5] iio: dac: ad5504: fix scale via output-range-microvolt
2026-05-09 14:20 ` [PATCH v3 5/5] iio: dac: ad5504: fix scale via output-range-microvolt Taha Ed-Dafili
@ 2026-05-09 14:57 ` Jonathan Cameron
2026-05-09 20:59 ` David Lechner
1 sibling, 0 replies; 10+ messages in thread
From: Jonathan Cameron @ 2026-05-09 14:57 UTC (permalink / raw)
To: Taha Ed-Dafili
Cc: lars, Michael.Hennerich, robh, krzk+dt, conor+dt, dlechner,
nuno.sa, andy, skhan, linux-iio, devicetree, linux-kernel
On Sat, 9 May 2026 15:20:43 +0100
Taha Ed-Dafili <0rayn.dev@gmail.com> wrote:
> The AD5504 full-scale range is hardware-determined by the R_SEL pin,
> not the VCC supply voltage.
>
> Fix the scaling logic by reading the standard 'output-range-microvolt'
> property from the device tree instead of querying the VCC regulator or
> relying on legacy platform data (pdata).
>
> As a result of this transition:
> - The 'vcc' regulator is now only enabled, not read.
> - Legacy pdata support is removed, as it is no longer required for
> fallback voltage calculations.
> - Strict array bounds checking is added for the DT property.
Hi Taha
These could have been broken up more. Given this patch isn't suitable
for backporting anyway, you could have done a precursor ripping out
the pdata.
>
> Signed-off-by: Taha Ed-Dafili <0rayn.dev@gmail.com>
The datasheet is less clear than it might be but I'm far from
sure that the range is as simple as 0-30 vs 0-60.
See for example the output characteristics in table 2.
That lists Output Voltage Range as AGND + 0.5 to VDD - 0.5V
which is not surprising as VDD can be too low to support the fully
0-60V without any nasty things like step up convertors which
aren't present here.
Now there is a footnote:
"The DAC architecture gives a fixed linear voltage output range
of 0 V to 30 V if R_SEL is held high and 0 V to 60 V if R_SEL is
held low. As the output voltage range is limited by output
amplifier compliance, VDD should be set to at least 0.5 V higher
than the maximum output voltage to ensure compliance."
So I guess we can 'assume' that footnote is obeyed and indeed
do things as you have here.
One other thing inline.
> ---
> drivers/iio/dac/ad5504.c | 25 +++++++++++++++----------
> 1 file changed, 15 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/iio/dac/ad5504.c b/drivers/iio/dac/ad5504.c
> index 9e95da6e49d6..040f580b8282 100644
> --- a/drivers/iio/dac/ad5504.c
> +++ b/drivers/iio/dac/ad5504.c
> @@ -14,10 +14,12 @@
> #include <linux/kstrtox.h>
> #include <linux/mod_devicetable.h>
> #include <linux/module.h>
> +#include <linux/property.h>
> #include <linux/regulator/consumer.h>
> #include <linux/spi/spi.h>
> #include <linux/sysfs.h>
> #include <linux/types.h>
> +#include <linux/units.h>
>
> #include <linux/iio/dac/ad5504.h>
> #include <linux/iio/events.h>
> @@ -274,9 +276,9 @@ static const struct iio_chan_spec ad5504_channels[] = {
> static int ad5504_probe(struct spi_device *spi)
> {
> struct device *dev = &spi->dev;
> - const struct ad5504_platform_data *pdata = dev_get_platdata(dev);
Last use of this - remove the header as well.
> struct iio_dev *indio_dev;
> struct ad5504_state *st;
> + u32 range[2];
> int ret;
>
> indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
> @@ -285,16 +287,19 @@ static int ad5504_probe(struct spi_device *spi)
>
> st = iio_priv(indio_dev);
>
> - ret = devm_regulator_get_enable_read_voltage(dev, "vcc");
> - if (ret < 0 && ret != -ENODEV)
> + ret = devm_regulator_get_enable(dev, "vcc");
> + if (ret && ret != -ENODEV)
> return ret;
> - if (ret == -ENODEV) {
> - if (pdata->vref_mv)
> - st->vref_mv = pdata->vref_mv;
> - else
> - dev_warn(dev, "reference voltage unspecified\n");
> - } else {
> - st->vref_mv = ret / 1000;
> +
> + st->vref_mv = 60 * MILLI;
> + ret = device_property_read_u32_array(dev, "output-range-microvolt",
> + range, ARRAY_SIZE(range));
> + if (!ret) {
> + if (range[0] != 0 || (range[1] != 30 * MICRO && range[1] != 60 * MICRO))
> + return -EINVAL;
> +
> + if (range[1] == 30 * MICRO)
> + st->vref_mv = 30 * MILLI;
> }
>
> st->spi = spi;
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH v3 5/5] iio: dac: ad5504: fix scale via output-range-microvolt
2026-05-09 14:20 ` [PATCH v3 5/5] iio: dac: ad5504: fix scale via output-range-microvolt Taha Ed-Dafili
2026-05-09 14:57 ` Jonathan Cameron
@ 2026-05-09 20:59 ` David Lechner
1 sibling, 0 replies; 10+ messages in thread
From: David Lechner @ 2026-05-09 20:59 UTC (permalink / raw)
To: Taha Ed-Dafili, lars, Michael.Hennerich, jic23, robh, krzk+dt,
conor+dt
Cc: nuno.sa, andy, skhan, linux-iio, devicetree, linux-kernel
On 5/9/26 9:20 AM, Taha Ed-Dafili wrote:
> The AD5504 full-scale range is hardware-determined by the R_SEL pin,
> not the VCC supply voltage.
>
> Fix the scaling logic by reading the standard 'output-range-microvolt'
> property from the device tree instead of querying the VCC regulator or
> relying on legacy platform data (pdata).
>
> As a result of this transition:
> - The 'vcc' regulator is now only enabled, not read.
> - Legacy pdata support is removed, as it is no longer required for
> fallback voltage calculations.
> - Strict array bounds checking is added for the DT property.
>
> Signed-off-by: Taha Ed-Dafili <0rayn.dev@gmail.com>
> ---
> drivers/iio/dac/ad5504.c | 25 +++++++++++++++----------
> 1 file changed, 15 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/iio/dac/ad5504.c b/drivers/iio/dac/ad5504.c
> index 9e95da6e49d6..040f580b8282 100644
> --- a/drivers/iio/dac/ad5504.c
> +++ b/drivers/iio/dac/ad5504.c
> @@ -14,10 +14,12 @@
> #include <linux/kstrtox.h>
> #include <linux/mod_devicetable.h>
> #include <linux/module.h>
> +#include <linux/property.h>
> #include <linux/regulator/consumer.h>
> #include <linux/spi/spi.h>
> #include <linux/sysfs.h>
> #include <linux/types.h>
> +#include <linux/units.h>
>
> #include <linux/iio/dac/ad5504.h>
> #include <linux/iio/events.h>
> @@ -274,9 +276,9 @@ static const struct iio_chan_spec ad5504_channels[] = {
> static int ad5504_probe(struct spi_device *spi)
> {
> struct device *dev = &spi->dev;
> - const struct ad5504_platform_data *pdata = dev_get_platdata(dev);
> struct iio_dev *indio_dev;
> struct ad5504_state *st;
> + u32 range[2];
> int ret;
>
> indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
> @@ -285,16 +287,19 @@ static int ad5504_probe(struct spi_device *spi)
>
> st = iio_priv(indio_dev);
>
> - ret = devm_regulator_get_enable_read_voltage(dev, "vcc");
> - if (ret < 0 && ret != -ENODEV)
I don't think this would ever return -ENODEV, even on ACPI. It will
just get a dummy regulator now.
> + ret = devm_regulator_get_enable(dev, "vcc");
> + if (ret && ret != -ENODEV)
> return ret;
> - if (ret == -ENODEV) {
> - if (pdata->vref_mv)
> - st->vref_mv = pdata->vref_mv;
> - else
> - dev_warn(dev, "reference voltage unspecified\n");
> - } else {
> - st->vref_mv = ret / 1000;
> +
> + st->vref_mv = 60 * MILLI;
> + ret = device_property_read_u32_array(dev, "output-range-microvolt",
> + range, ARRAY_SIZE(range));
> + if (!ret) {
> + if (range[0] != 0 || (range[1] != 30 * MICRO && range[1] != 60 * MICRO))
> + return -EINVAL;
> +
> + if (range[1] == 30 * MICRO)
> + st->vref_mv = 30 * MILLI;
> }
>
> st->spi = spi;
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH v3 0/5] iio: dac: ad5504: bindings, cleanups, and scale fixes
2026-05-09 14:20 [PATCH v3 0/5] iio: dac: ad5504: bindings, cleanups, and scale fixes Taha Ed-Dafili
` (4 preceding siblings ...)
2026-05-09 14:20 ` [PATCH v3 5/5] iio: dac: ad5504: fix scale via output-range-microvolt Taha Ed-Dafili
@ 2026-05-09 20:46 ` David Lechner
5 siblings, 0 replies; 10+ messages in thread
From: David Lechner @ 2026-05-09 20:46 UTC (permalink / raw)
To: Taha Ed-Dafili, lars, Michael.Hennerich, jic23, robh, krzk+dt,
conor+dt
Cc: nuno.sa, andy, skhan, linux-iio, devicetree, linux-kernel
On 5/9/26 9:20 AM, Taha Ed-Dafili wrote:
> Hi everyone,
>
> First, I want to sincerely apologize for the long delay between v2 and v3.
> I had to step away to focus on finishing my last year studies, but I am
> back now to get this series over the finish line!
>
> This v3 series addresses the feedbacks from the v2 review,
> specifically focusing on strict DT validation, dropping unnecessary
> driver code, and making sure the driver works perfectly at every
> individual commit.
>
> Testing & Hardware Proof:
> The series has been physically verified on an ARM64 Raspberry Pi 5 using
> a custom Device Tree overlay.
>
> The AD5504 is a 12-bit DAC. The hardware scale outputs
> now perfectly match the DT inputs:
>
> Testing the 60V path (output-range-microvolt = <0 60000000>):
> $ cat /sys/bus/iio/devices/iio:device0/out_voltage_scale
> 14.648437500 (60000mV / 4096)
>
> Testing the 30V path (output-range-microvolt = <0 30000000>):
> $ cat /sys/bus/iio/devices/iio:device0/out_voltage_scale
> 7.324218750 (30000mV / 4096)
>
> Additionally, providing invalid DT configurations (e.g., 70V) successfully
> triggers the strict bounds checking and cleanly aborts the probe with
> -EINVAL.
>
> Changes in v3:
>
> * Dropped the patch adding GPIO control for /CLR and /LDAC. As pointed out
> by Nuno Sá, since the driver does not actively handle or toggle these
> pins, requesting them in the driver is dead code. They remain documented
> in the bindings.
> * Combined the pdata removal, regulator _enable swap, and DT parsing into
> a single atomic commit (Patch 5) so the driver compiles and runs cleanly
> at every step of the git history.
It should be possible to do this while still having separate commits.
> * Restored the -ENODEV check for the regulator to maintain ACPI
> compatibility.
While you were studying we discussed this some more in similar cases
and decided that we would like to handle this differently going forward.
For example, see recent changes in adc/ti-ads7950.c which also has
an ACPI case.
> * Implemented strict min/max array bounds validation for the
> 'output-range-microvolt' property.
> * Included missing <linux/array_size.h>, <asm/byteorder.h>, and
> <linux/kstrtox.h> headers for full IWYU compliance.
> * Reordered commits to group cleanups before functional changes.
> * Dropped Suggested-by tags for standard review feedback.
>
^ permalink raw reply [flat|nested] 10+ messages in thread