[PATCH v5 6/6] iio: dac: ad5504: support scale via output-range-microvolt property
From: Taha Ed-Dafili
Date: Fri Aug 21 2026 - 06:56:34 EST
The AD5504 output range is set by the R_SEL pin, not the VCC supply.
Add support for 'output-range-microvolt' to set vref_mv directly from
firmware. Use device_property_present() to distinguish absent from
malformed property rather than relying on the ambiguous -EINVAL from
device_property_read_u32_array(). Fall back to the vcc regulator
voltage for old DTs that predate this property.
Signed-off-by: Taha Ed-Dafili <0rayn.dev@xxxxxxxxx>
---
drivers/iio/dac/ad5504.c | 31 +++++++++++++++++++++++++------
1 file changed, 25 insertions(+), 6 deletions(-)
diff --git a/drivers/iio/dac/ad5504.c b/drivers/iio/dac/ad5504.c
index 489d2e03e9f6..19ece5a2af58 100644
--- a/drivers/iio/dac/ad5504.c
+++ b/drivers/iio/dac/ad5504.c
@@ -300,6 +300,7 @@ static int ad5504_probe(struct spi_device *spi)
struct device *dev = &spi->dev;
struct iio_dev *indio_dev;
struct ad5504_state *st;
+ u32 range[2];
int ret;
indio_dev = devm_iio_device_alloc(dev, sizeof(*st));
@@ -315,12 +316,30 @@ static int ad5504_probe(struct spi_device *spi)
if (is_acpi_device_node(dev_fwnode(dev))) {
st->vref_mv = AD5504_VREF_ACPI_DEFAULT_mV;
} else {
- ret = devm_regulator_get_enable_read_voltage(dev, "vcc");
- if (ret < 0)
- return dev_err_probe(dev, ret,
- "Failed to get vcc regulator\n");
-
- st->vref_mv = ret / 1000;
+ if (device_property_present(dev, "output-range-microvolt")) {
+ ret = device_property_read_u32_array(dev, "output-range-microvolt",
+ range, ARRAY_SIZE(range));
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "Error parsing output-range-microvolt\n");
+
+ if (range[0] != 0 || (range[1] != 30 * MICRO && range[1] != 60 * MICRO))
+ return dev_err_probe(dev, -EINVAL,
+ "Invalid output-range-microvolt\n");
+
+ st->vref_mv = range[1] / (MICRO / MILLI);
+
+ ret = devm_regulator_get_enable(dev, "vcc");
+ if (ret < 0)
+ return dev_err_probe(dev, ret, "Failed to enable vcc regulator\n");
+ } else {
+ /* Backward compat: old DTs without output-range-microvolt */
+ ret = devm_regulator_get_enable_read_voltage(dev, "vcc");
+ if (ret < 0)
+ return dev_err_probe(dev, ret, "Failed to get vcc regulator\n");
+
+ st->vref_mv = ret / (MICRO / MILLI);
+ }
}
st->spi = spi;
--
2.55.0