From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: "Janani Sunil" <janani.sunil@analog.com>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Philipp Zabel" <p.zabel@pengutronix.de>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Mark Brown" <broonie@kernel.org>,
"Marius Cristea" <marius.cristea@microchip.com>,
"Marcus Folkesson" <marcus.folkesson@gmail.com>,
"Kent Gustavsson" <kent@minoris.se>,
"Conor Dooley" <conor.dooley@microchip.com>,
"Daire McNamara" <daire.mcnamara@microchip.com>,
"Paul Walmsley" <pjw@kernel.org>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
"Alexandre Ghiti" <alex@ghiti.fr>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
"Janani Sunil" <jan.sun97@gmail.com>,
linux-spi@vger.kernel.org, "Kent Gustavsson" <nedo80@gmail.com>,
linux-riscv@lists.infradead.org
Subject: Re: [PATCH v11 3/3] iio: dac: Add AD5529R DAC driver support
Date: Sun, 6 Sep 2026 22:24:42 +0100 [thread overview]
Message-ID: <20260906222442.01ff098d@jic23-huawei> (raw)
In-Reply-To: <apgdEf3pi_soGr3T@ashevche-desk.local>
On Wed, 2 Sep 2026 15:56:49 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> On Wed, Sep 02, 2026 at 11:26:17AM +0200, Janani Sunil wrote:
> > Add support for AD5529R 16-channel, 12/16 bit Digital to Analog Converter
> > from Analog Devices.
> >
> > The device communicates over SPI and supports per-channel output range
> > configuration. An optional external 4.096V reference can be used in
> > place of the internal reference.
>
> Since there might be a v12 (depends on Jonathan), a few more nit-picks.
>
> ...
>
> > +static const s32 ad5529r_output_ranges_mV[8][2] = {
> > + [AD5529R_RANGE_0V_5V] = { 0, 5000 },
> > + [AD5529R_RANGE_0V_10V] = { 0, 10000 },
> > + [AD5529R_RANGE_0V_20V] = { 0, 20000 },
> > + [AD5529R_RANGE_0V_40V] = { 0, 40000 },
> > + [AD5529R_RANGE_M5V_5V] = { -5000, 5000 },
> > + [AD5529R_RANGE_M10V_10V] = { -10000, 10000 },
> > + [AD5529R_RANGE_M15V_15V] = { -15000, 15000 },
> > + [AD5529R_RANGE_M20V_20V] = { -20000, 20000 },
> > +};
>
> Perhaps use MILLI multiplier?
I tried this and it looks pretty ugly so didn't adopt this one.
If it were many more zeros I'd agree.
>
> ...
>
> > +static int ad5529r_read_raw(struct iio_dev *indio_dev,
> > + struct iio_chan_spec const *chan,
> > + int *val, int *val2, long mask)
> > +{
> > + struct ad5529r_state *st = iio_priv(indio_dev);
> > + unsigned int reg_addr, reg_val_h;
> > + int ret, range_idx, span_mV;
>
> Why is 'range_idx' signed?
Why isn't it the enum like where it is coming from?
I changed it to the enum.
diff --git a/drivers/iio/dac/ad5529r.c b/drivers/iio/dac/ad5529r.c
index bc11d7671a76..8154b87ff831 100644
--- a/drivers/iio/dac/ad5529r.c
+++ b/drivers/iio/dac/ad5529r.c
@@ -228,8 +228,9 @@ static int ad5529r_read_raw(struct iio_dev *indio_dev,
int *val, int *val2, long mask)
{
struct ad5529r_state *st = iio_priv(indio_dev);
+ enum ad5529r_output_range range_idx;
unsigned int reg_addr, reg_val_h;
- int ret, range_idx, span_mV;
+ int ret, span_mV;
switch (mask) {
case IIO_CHAN_INFO_RAW:
>
> > + switch (mask) {
> > + case IIO_CHAN_INFO_RAW:
> > + /*
> > + * Read from DAC_INPUT_A register rather than DAC_DATA_READBACK.
> > + * The DAC operates in transparent mode and directly reflects
> > + * whatever value is written to the INPUT_A register.
> > + */
> > + reg_addr = AD5529R_REG_DAC_INPUT_A(chan->channel);
> > + ret = regmap_read(st->regmap_16bit, reg_addr, ®_val_h);
> > + if (ret)
> > + return ret;
> > +
> > + *val = reg_val_h;
> > +
> > + return IIO_VAL_INT;
> > + case IIO_CHAN_INFO_SCALE:
> > + range_idx = st->output_range_idx[chan->channel];
> > +
> > + /*
> > + * The datasheet specifies a 4.096 V external reference,
> > + * matching the nominal output voltage of the internal
> > + * reference.
> > + */
> > + span_mV = ad5529r_output_ranges_mV[range_idx][1] -
> > + ad5529r_output_ranges_mV[range_idx][0];
> > + *val = span_mV;
> > + *val2 = st->model_data->resolution;
> > +
> > + return IIO_VAL_FRACTIONAL_LOG2;
> > + case IIO_CHAN_INFO_OFFSET:
> > + range_idx = st->output_range_idx[chan->channel];
> > +
> > + if (ad5529r_output_ranges_mV[range_idx][0] < 0)
> > + *val = -BIT(st->model_data->resolution - 1);
> > + else
> > + *val = 0;
> > +
> > + return IIO_VAL_INT;
> > + default:
> > + return -EINVAL;
> > + }
> > +}
>
WARNING: multiple messages have this Message-ID (diff)
From: Jonathan Cameron <jic23@kernel.org>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: "Janani Sunil" <janani.sunil@analog.com>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Philipp Zabel" <p.zabel@pengutronix.de>,
"Jonathan Corbet" <corbet@lwn.net>,
"Shuah Khan" <skhan@linuxfoundation.org>,
"Mark Brown" <broonie@kernel.org>,
"Marius Cristea" <marius.cristea@microchip.com>,
"Marcus Folkesson" <marcus.folkesson@gmail.com>,
"Kent Gustavsson" <kent@minoris.se>,
"Conor Dooley" <conor.dooley@microchip.com>,
"Daire McNamara" <daire.mcnamara@microchip.com>,
"Paul Walmsley" <pjw@kernel.org>,
"Palmer Dabbelt" <palmer@dabbelt.com>,
"Albert Ou" <aou@eecs.berkeley.edu>,
"Alexandre Ghiti" <alex@ghiti.fr>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org,
"Janani Sunil" <jan.sun97@gmail.com>,
linux-spi@vger.kernel.org, "Kent Gustavsson" <nedo80@gmail.com>,
linux-riscv@lists.infradead.org
Subject: Re: [PATCH v11 3/3] iio: dac: Add AD5529R DAC driver support
Date: Sun, 6 Sep 2026 22:24:42 +0100 [thread overview]
Message-ID: <20260906222442.01ff098d@jic23-huawei> (raw)
In-Reply-To: <apgdEf3pi_soGr3T@ashevche-desk.local>
On Wed, 2 Sep 2026 15:56:49 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> On Wed, Sep 02, 2026 at 11:26:17AM +0200, Janani Sunil wrote:
> > Add support for AD5529R 16-channel, 12/16 bit Digital to Analog Converter
> > from Analog Devices.
> >
> > The device communicates over SPI and supports per-channel output range
> > configuration. An optional external 4.096V reference can be used in
> > place of the internal reference.
>
> Since there might be a v12 (depends on Jonathan), a few more nit-picks.
>
> ...
>
> > +static const s32 ad5529r_output_ranges_mV[8][2] = {
> > + [AD5529R_RANGE_0V_5V] = { 0, 5000 },
> > + [AD5529R_RANGE_0V_10V] = { 0, 10000 },
> > + [AD5529R_RANGE_0V_20V] = { 0, 20000 },
> > + [AD5529R_RANGE_0V_40V] = { 0, 40000 },
> > + [AD5529R_RANGE_M5V_5V] = { -5000, 5000 },
> > + [AD5529R_RANGE_M10V_10V] = { -10000, 10000 },
> > + [AD5529R_RANGE_M15V_15V] = { -15000, 15000 },
> > + [AD5529R_RANGE_M20V_20V] = { -20000, 20000 },
> > +};
>
> Perhaps use MILLI multiplier?
I tried this and it looks pretty ugly so didn't adopt this one.
If it were many more zeros I'd agree.
>
> ...
>
> > +static int ad5529r_read_raw(struct iio_dev *indio_dev,
> > + struct iio_chan_spec const *chan,
> > + int *val, int *val2, long mask)
> > +{
> > + struct ad5529r_state *st = iio_priv(indio_dev);
> > + unsigned int reg_addr, reg_val_h;
> > + int ret, range_idx, span_mV;
>
> Why is 'range_idx' signed?
Why isn't it the enum like where it is coming from?
I changed it to the enum.
diff --git a/drivers/iio/dac/ad5529r.c b/drivers/iio/dac/ad5529r.c
index bc11d7671a76..8154b87ff831 100644
--- a/drivers/iio/dac/ad5529r.c
+++ b/drivers/iio/dac/ad5529r.c
@@ -228,8 +228,9 @@ static int ad5529r_read_raw(struct iio_dev *indio_dev,
int *val, int *val2, long mask)
{
struct ad5529r_state *st = iio_priv(indio_dev);
+ enum ad5529r_output_range range_idx;
unsigned int reg_addr, reg_val_h;
- int ret, range_idx, span_mV;
+ int ret, span_mV;
switch (mask) {
case IIO_CHAN_INFO_RAW:
>
> > + switch (mask) {
> > + case IIO_CHAN_INFO_RAW:
> > + /*
> > + * Read from DAC_INPUT_A register rather than DAC_DATA_READBACK.
> > + * The DAC operates in transparent mode and directly reflects
> > + * whatever value is written to the INPUT_A register.
> > + */
> > + reg_addr = AD5529R_REG_DAC_INPUT_A(chan->channel);
> > + ret = regmap_read(st->regmap_16bit, reg_addr, ®_val_h);
> > + if (ret)
> > + return ret;
> > +
> > + *val = reg_val_h;
> > +
> > + return IIO_VAL_INT;
> > + case IIO_CHAN_INFO_SCALE:
> > + range_idx = st->output_range_idx[chan->channel];
> > +
> > + /*
> > + * The datasheet specifies a 4.096 V external reference,
> > + * matching the nominal output voltage of the internal
> > + * reference.
> > + */
> > + span_mV = ad5529r_output_ranges_mV[range_idx][1] -
> > + ad5529r_output_ranges_mV[range_idx][0];
> > + *val = span_mV;
> > + *val2 = st->model_data->resolution;
> > +
> > + return IIO_VAL_FRACTIONAL_LOG2;
> > + case IIO_CHAN_INFO_OFFSET:
> > + range_idx = st->output_range_idx[chan->channel];
> > +
> > + if (ad5529r_output_ranges_mV[range_idx][0] < 0)
> > + *val = -BIT(st->model_data->resolution - 1);
> > + else
> > + *val = 0;
> > +
> > + return IIO_VAL_INT;
> > + default:
> > + return -EINVAL;
> > + }
> > +}
>
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2026-09-06 21:24 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 9:26 [PATCH v11 0/3] iio: dac: Add support for AD5529R DAC Janani Sunil
2026-09-02 9:26 ` Janani Sunil
2026-09-02 9:26 ` [PATCH v11 1/3] spi: dt-bindings: Add spi-device-addr peripheral property Janani Sunil
2026-09-02 9:26 ` Janani Sunil
2026-09-02 9:26 ` [PATCH v11 2/3] dt-bindings: iio: dac: Add AD5529R Janani Sunil
2026-09-02 9:26 ` Janani Sunil
2026-09-02 9:36 ` sashiko-bot
2026-09-02 9:26 ` [PATCH v11 3/3] iio: dac: Add AD5529R DAC driver support Janani Sunil
2026-09-02 9:26 ` Janani Sunil
2026-09-02 9:39 ` sashiko-bot
2026-09-02 11:04 ` Andy Shevchenko
2026-09-02 11:04 ` Andy Shevchenko
2026-09-02 12:56 ` Andy Shevchenko
2026-09-02 12:56 ` Andy Shevchenko
2026-09-06 21:24 ` Jonathan Cameron [this message]
2026-09-06 21:24 ` Jonathan Cameron
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260906222442.01ff098d@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=alex@ghiti.fr \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=aou@eecs.berkeley.edu \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=conor.dooley@microchip.com \
--cc=corbet@lwn.net \
--cc=daire.mcnamara@microchip.com \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jan.sun97@gmail.com \
--cc=janani.sunil@analog.com \
--cc=kent@minoris.se \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-doc@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=linux-spi@vger.kernel.org \
--cc=marcus.folkesson@gmail.com \
--cc=marius.cristea@microchip.com \
--cc=nedo80@gmail.com \
--cc=nuno.sa@analog.com \
--cc=p.zabel@pengutronix.de \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=robh@kernel.org \
--cc=skhan@linuxfoundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.