From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: "Torreno, Alexis Czezar" <AlexisCzezar.Torreno@analog.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
"Hennerich, Michael" <Michael.Hennerich@analog.com>,
Jonathan Cameron <jic23@kernel.org>,
David Lechner <dlechner@baylibre.com>,
"Sa, Nuno" <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>,
"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 2/2] iio: dac: ad5706r: Add support for AD5706R DAC
Date: Mon, 6 Apr 2026 21:32:22 +0300 [thread overview]
Message-ID: <adP8NnvAjAxDOJ-x@ashevche-desk.local> (raw)
In-Reply-To: <PH0PR03MB63516A449873005315ACFF02F15DA@PH0PR03MB6351.namprd03.prod.outlook.com>
On Mon, Apr 06, 2026 at 07:04:44AM +0000, Torreno, Alexis Czezar wrote:
> > On Wed, Apr 01, 2026 at 06:20:04PM +0800, Alexis Czezar Torreno wrote:
...
> > > +static int ad5706r_regmap_write(void *context, const void *data,
> > > +size_t count) {
> > > + struct ad5706r_state *st = context;
> > > + unsigned int num_bytes;
> >
> > Currently only 1 and 2 bytes are supported, right? Any updates are planned on
> > this in the future?
>
> Yes only 1 and 2 bytes, no future extension. Should I make num_bytes a 'u8'?
>
> > > + u16 reg;
> > > + cmd = AD5706R_RD_MASK | (reg & AD5706R_ADDR_MASK);
> > > + put_unaligned_be16(cmd, st->tx_buf);
> >
> > > + memset(st->tx_buf + 2, 0, num_bytes);
> >
> > I would use &st->tx_buf[2] here and below for the sake of consistency with
> > put_unaligned_*().
>
> Will edit for consistnency.
>
> > > + ret = spi_sync_transfer(st->spi, &xfer, 1);
> > > + if (ret)
> > > + return ret;
> > > +
> > > + /* Ignore the first two bytes (echo during command) */
> > > + if (num_bytes == AD5706R_SINGLE_BYTE_LEN)
> > > + put_unaligned_be16(st->rx_buf[2], val_buf);
> >
> > The comment wants to explain why it's required to put 2 bytes anyway.
>
> Will add clearer comments for this
>
> > > + else
> > > + memcpy(val_buf, st->rx_buf + 2, num_bytes);
> >
> > However with the above question in mind, if it's all about 1 or 2 bytes, can't we
> > simply use the same approach everywhere, like put_unaligned_*()?
>
> For consistency, put_unaligned_*() can work.
>
> Although since rx_buf is u8, this line:
>
> memcpy(val_buf, &st->rx_buf[2], num_bytes);
>
> Will look like this for 2 bytes:
>
> x = get_unaligned_be16( &st->rx_buf[2] )
> put_unaligned_be16( x, val_buf )
>
> I suppose the mem* commands looks cleaner
We optimise it a bit, so what you are going to have is something like
if (num_bytes == 1)
x = &st->rx_buf[2];
else if (num_bytes == 2)
x = get_unaligned...(...);
else
return -EINVAL;
put_unaligned...(...);
--
With Best Regards,
Andy Shevchenko
prev parent reply other threads:[~2026-04-06 18:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-01 10:20 [PATCH v4 0/2] Add support for AD5706R DAC Alexis Czezar Torreno
2026-04-01 10:20 ` [PATCH v4 1/2] dt-bindings: iio: dac: Add ADI AD5706R Alexis Czezar Torreno
2026-04-02 7:00 ` Krzysztof Kozlowski
2026-04-06 7:04 ` Torreno, Alexis Czezar
2026-04-01 10:20 ` [PATCH v4 2/2] iio: dac: ad5706r: Add support for AD5706R DAC Alexis Czezar Torreno
2026-04-01 14:56 ` Andy Shevchenko
2026-04-06 7:04 ` Torreno, Alexis Czezar
2026-04-06 18:32 ` Andy Shevchenko [this message]
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=adP8NnvAjAxDOJ-x@ashevche-desk.local \
--to=andriy.shevchenko@intel.com \
--cc=AlexisCzezar.Torreno@analog.com \
--cc=Michael.Hennerich@analog.com \
--cc=Nuno.Sa@analog.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox