From: David Lechner <dlechner@baylibre.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>,
Marcelo Schmitt <marcelo.schmitt@analog.com>
Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
jic23@kernel.org, lars@metafoo.de, Michael.Hennerich@analog.com,
nuno.sa@analog.com, andy@kernel.org, marcelo.schmitt1@gmail.com
Subject: Re: [PATCH] iio: adc: ad4000: Avoid potential double data word read
Date: Tue, 15 Apr 2025 16:22:34 -0500 [thread overview]
Message-ID: <22858e4f-db8e-4c97-8551-a1934a9f2fe7@baylibre.com> (raw)
In-Reply-To: <CAHp75VendQGLdpggySS3mX6M2YSeS70bvE8yg7sp_LNGDS-Scg@mail.gmail.com>
On 4/15/25 1:02 PM, Andy Shevchenko wrote:
> On Tue, Apr 15, 2025 at 3:21 PM Marcelo Schmitt
> <marcelo.schmitt@analog.com> wrote:
>>
>> Currently, SPI-Engine offload module always sends 32-bit data elements to
>> DMA engine. Appropriately, when set for SPI offloading, the IIO driver uses
>> 32 storagebits for IIO ADC channel buffer elements. However, setting SPI
>> transfer length according to storagebits (32-bits in case of offload) can
>> lead to unnecessarily long transfers for ADCs that are 16-bit or less
>> precision. Adjust AD4000 single-shot read to run transfers of 2 bytes when
>> that is enough to get all ADC data bits.
>
> ...
>
>> xfers[1].rx_buf = &st->scan.data;
>> - xfers[1].len = BITS_TO_BYTES(chan->scan_type.storagebits);
>> + xfers[1].len = chan->scan_type.realbits > 16 ? 4 : 2;
>
> But wouldn't be logical to have
>
> xfers[1].len = BITS_TO_BYTES(chan->scan_type.realbits);
>
> ?
>
No, SPI expects 1, 2 or 4 bytes, never 3. If realbits is 18, we
need len = 4.
It would have to be:
xfers[1].len = roundup_pow_of_two(BITS_TO_BYTES(chan->scan_type.realbits));
But that gets too long for 1 line, so I prefer what Marcelo wrote.
Maybe an idea for another day:
#define SPI_LEN_FOR_BITS(bits) roundup_pow_of_two(BITS_TO_BYTES(bits))
There are a couple of places in spi/ that could use this and several
iio drivers.
next prev parent reply other threads:[~2025-04-15 21:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-15 12:21 Marcelo Schmitt
2025-04-15 18:02 ` Andy Shevchenko
2025-04-15 21:22 ` David Lechner [this message]
2025-04-16 5:59 ` Andy Shevchenko
2025-04-16 6:01 ` Andy Shevchenko
2025-04-16 6:47 ` Andy Shevchenko
2025-05-05 16:14 ` Jonathan Cameron
2025-04-16 18:43 ` David Lechner
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=22858e4f-db8e-4c97-8551-a1934a9f2fe7@baylibre.com \
--to=dlechner@baylibre.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy.shevchenko@gmail.com \
--cc=andy@kernel.org \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.schmitt1@gmail.com \
--cc=marcelo.schmitt@analog.com \
--cc=nuno.sa@analog.com \
/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
all inboxes | Powered by JetHome®