Devicetree
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: "Sabau, Radu bogdan" <Radu.Sabau@analog.com>
Cc: "Lars-Peter Clausen" <lars@metafoo.de>,
	"Hennerich, Michael" <Michael.Hennerich@analog.com>,
	"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>,
	"Uwe Kleine-König" <ukleinek@kernel.org>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Linus Walleij" <linusw@kernel.org>,
	"Bartosz Golaszewski" <brgl@kernel.org>,
	"Philipp Zabel" <p.zabel@pengutronix.de>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Shuah Khan" <skhan@linuxfoundation.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>,
	"linux-pwm@vger.kernel.org" <linux-pwm@vger.kernel.org>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
	"linux-doc@vger.kernel.org" <linux-doc@vger.kernel.org>
Subject: Re: [PATCH v9 4/6] iio: adc: ad4691: add SPI offload support
Date: Thu, 7 May 2026 16:11:11 +0100	[thread overview]
Message-ID: <20260507161111.555bba75@jic23-huawei> (raw)
In-Reply-To: <LV9PR03MB8414E7E034F79900A6595750F73C2@LV9PR03MB8414.namprd03.prod.outlook.com>


> > +		/* TX: address phase, CS stays asserted into data phase */
> > +		st->scan_xfers[2 * k].tx_buf = offload->tx_cmd[k];
> > +		st->scan_xfers[2 * k].len = sizeof(offload->tx_cmd[k]);
> > +		st->scan_xfers[2 * k].bits_per_word = bpw;  
> 
> "When bits_per_word is greater than 8 (like bpw = 16 here), the SPI framework
> treats tx_buf as an array of native 16-bit words.
> On little-endian architectures, the controller will byte-swap the data before
> transmitting it. Will using a u8 array and put_unaligned_be16() result in the
> command bytes being reversed on the wire?"
> 
> Switched to cpu_to_be16() assigned directly into __be16 scan_tx[],
> matching the non-offload path. This makes the intended wire format
> self-evident and sidesteps the byte-ordering question entirely.

This confuses me a bit because the SPI controller should work with
native endian and from that generate the expected big endian on the wire.

So on a little endian host byte order in address space is LH but it will
write top bit of H first thus the ADC channel address needs to be in the
second byte.
On a big endian host despite the ordering in memory being HL, the top
bit of H is still written first thus in needs to be in the first byte.


If you using cpu_to_be16() to assign a 16 bit value swapping only on little endian
and start with the cmd in L on little endian you'll end up with LH swapped to
HL and on big endian HL but the little endian SPI controller should then swap
it again sending what it thinks is the high byte first (L) whereas the big endian
system will send H.

Upshot. I think the field should be native endian. If a byte swap is needed
it should be unconditional and not rely on endianness of the host.

> 
> > +
> > +		/* RX: data phase, CS toggles after to delimit the next register
> > op */
> > +		st->scan_xfers[2 * k + 1].len = sizeof(offload->tx_cmd[k]);
> > +		st->scan_xfers[2 * k + 1].bits_per_word = bpw;
> > +		st->scan_xfers[2 * k + 1].offload_flags =
> > SPI_OFFLOAD_XFER_RX_STREAM;
> > +		st->scan_xfers[2 * k + 1].cs_change = 1;
> > +		k++;
> > +	}
> > +
> > +	/* State reset to re-arm DATA_READY for the next scan. */
> > +	put_unaligned_be16(AD4691_STATE_RESET_REG, offload->tx_reset);
> > +	offload->tx_reset[2] = AD4691_STATE_RESET_ALL;
> > +
> > +	st->scan_xfers[2 * k].tx_buf = offload->tx_reset;
> > +	st->scan_xfers[2 * k].len = sizeof(offload->tx_cmd[k]);
> > +	st->scan_xfers[2 * k].bits_per_word = bpw;
> > +
> > +	st->scan_xfers[2 * k + 1].tx_buf = &offload->tx_reset[2];
> > +	st->scan_xfers[2 * k + 1].len = sizeof(offload->tx_cmd[k]);  
> 
> "Will passing &offload->tx_reset[2] directly as tx_buf cause DMA mapping
> issues, since it is only 2-byte aligned?"
> 
> Addressed by the second concern's fix: no sub-aligned pointer into the middle
> of a DMA buffer — the full 4-byte scan_tx_reset[] is passed as tx_buf
> from its own cache-line-aligned start address.
> 

  reply	other threads:[~2026-05-07 15:11 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-30 10:16 [PATCH v9 0/6] iio: adc: ad4691: add driver for AD4691 multichannel SAR ADC family Radu Sabau via B4 Relay
2026-04-30 10:16 ` [PATCH v9 1/6] dt-bindings: iio: adc: add AD4691 family Radu Sabau via B4 Relay
2026-04-30 10:16 ` [PATCH v9 2/6] iio: adc: ad4691: add initial driver for " Radu Sabau via B4 Relay
2026-05-05 13:23   ` Jonathan Cameron
2026-05-07  9:26   ` Sabau, Radu bogdan
2026-05-07 14:15     ` Jonathan Cameron
2026-05-08  4:44       ` Andy Shevchenko
2026-05-08  9:53         ` Andy Shevchenko
2026-04-30 10:16 ` [PATCH v9 3/6] iio: adc: ad4691: add triggered buffer support Radu Sabau via B4 Relay
2026-05-04  7:57   ` Andy Shevchenko
2026-05-04 12:05     ` Sabau, Radu bogdan
2026-05-05 13:26       ` Jonathan Cameron
2026-05-05 14:58         ` Andy Shevchenko
2026-05-05 16:17           ` Jonathan Cameron
2026-05-06  7:25             ` Andy Shevchenko
2026-05-06  9:01               ` Sabau, Radu bogdan
2026-05-05 14:04   ` Jonathan Cameron
2026-05-05 14:07   ` Jonathan Cameron
2026-05-07 11:37   ` Sabau, Radu bogdan
2026-05-07 14:25     ` Jonathan Cameron
2026-05-08 11:08       ` Sabau, Radu bogdan
2026-04-30 10:16 ` [PATCH v9 4/6] iio: adc: ad4691: add SPI offload support Radu Sabau via B4 Relay
2026-05-04  8:10   ` Andy Shevchenko
2026-05-05 14:12   ` Jonathan Cameron
2026-05-05 14:28   ` Jonathan Cameron
2026-05-06  9:17     ` Sabau, Radu bogdan
2026-05-07 11:49   ` Sabau, Radu bogdan
2026-05-07 15:11     ` Jonathan Cameron [this message]
2026-05-08 11:11       ` Sabau, Radu bogdan
2026-04-30 10:16 ` [PATCH v9 5/6] iio: adc: ad4691: add oversampling support Radu Sabau via B4 Relay
2026-05-04  8:14   ` Andy Shevchenko
2026-05-05 14:32   ` Jonathan Cameron
2026-05-07 11:56   ` Sabau, Radu bogdan
2026-05-07 15:26     ` Jonathan Cameron
2026-04-30 10:16 ` [PATCH v9 6/6] docs: iio: adc: ad4691: add driver documentation Radu Sabau via B4 Relay
2026-05-05 14:35   ` 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=20260507161111.555bba75@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=Nuno.Sa@analog.com \
    --cc=Radu.Sabau@analog.com \
    --cc=andy@kernel.org \
    --cc=brgl@kernel.org \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=corbet@lwn.net \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=lgirdwood@gmail.com \
    --cc=linusw@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=robh@kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=ukleinek@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