From: David Lechner <dlechner@baylibre.com>
To: Andy Shevchenko <andriy.shevchenko@intel.com>
Cc: "Marilene Andrade Garcia" <marilene.agarcia@gmail.com>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org,
"Kim Seer Paller" <kimseer.paller@analog.com>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Jonathan Cameron" <jic23@kernel.org>,
"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>,
"Marcelo Schmitt" <marcelo.schmitt1@gmail.com>,
"Marcelo Schmitt" <Marcelo.Schmitt@analog.com>,
"Ceclan Dumitru" <dumitru.ceclan@analog.com>,
"Jonathan Santos" <Jonathan.Santos@analog.com>,
"Dragos Bogdan" <dragos.bogdan@analog.com>
Subject: Re: [PATCH v11 2/3] iio: adc: max14001: New driver
Date: Wed, 17 Sep 2025 08:21:23 -0500 [thread overview]
Message-ID: <6ab0cee1-846f-4f90-bc61-141f74144a50@baylibre.com> (raw)
In-Reply-To: <aMptaOOmQ6SUoMLj@smile.fi.intel.com>
On 9/17/25 3:12 AM, Andy Shevchenko wrote:
> On Wed, Sep 17, 2025 at 11:10:42AM +0300, Andy Shevchenko wrote:
>> On Tue, Sep 16, 2025 at 01:04:41PM -0500, David Lechner wrote:
>>> On 9/15/25 5:16 PM, Marilene Andrade Garcia wrote:
>
> ...
>
>>>> Change I was not able to do:
>>>> - I could not remove bitrev16 because I am using an SPI controller that
>>>> does not support SPI_LSB_FIRST. So I suggest keeping bitrev16 and not using
>>>> the spi-lsb-first devicetree property for now, since this driver currently
>>>> works for both types of controllers: those that support it and those that
>>>> do not. I left a TODO comment to address this issue as soon as the SPI
>>>> kernel code starts handling the bit-reverse operation for controllers that
>>>> do not have this support. Once I finish my work on this driver, if the SPI
>>>> code still does not include this handling, I can submit patches to add it.
>>>
>>> I looked more at what it would take to implement this in the SPI core code
>>> and found that it would actually be quite difficult to do in a generic way
>>> because there are so many edge/corner/n-dim cases. We can't change tx_buf
>>> data in-place because it might be const data that is in some memory area
>>> that can't be modified. And things would get complicated if different
>>> transfers pointed to the same buffer memory addresses anyway. So we would
>>> basically have to allocate new memory for all buffers, copy all tx data to
>>> that new memory, reverse all of the tx bits, and update all the pointers in
>>> the transfer structs. Then when the message was finished, we would have to
>>> reverse all of the rx bits, copy all of the rx buffers back to the original
>>> buffers and put all the buffer pointers back the way they were. But this
>>> could write over some of the original tx data if tx_buf and rx_buf point to
>>> the same original buffer, which would break things if a peripheral driver
>>> expected the tx data to persist.
>>
>> And what's the problem here? We do the same with bounce-buffers in case
>> of DMA/IOMMU (okay, without actual data modification, but it's possible
>> on-the-fly).
OK, maybe not as much problem as I thought. Just rather inefficient.
I might have another look. We could perhaps allocate the buffers
during the spi_optimize phase and only swap bits on each transfer to
make it as efficient as possible.
>
> Actually, can this be done on a regmap level instead? We have a lot of custom
> regmap IO accessors, bulk accessor that does something to a data can be also
> implemented.
>
Currently, if you have a peripheral that has the SPI_LSB_FIRST flag connected
to a controller that does not have that flag, the SPI core code will refuse to
make a SPI device for the peripheral. So to make anything work at all, the
core SPI code is going to have to be made aware one way or another.
>>> And we can't do this during the SPI optimize
>>> step because that currently allows the tx_buf data values to be modified after
>>> optimization.
>>
>> This I don't know, so perhaps it's indeed a showstopper.
>>
>>> So perhaps it is best to just handle it in the peripheral driver. It will
>>> be much more efficent that way anyway.
>>>
>>> However, we still do want to handle SPI_LSB_FIRST now so that people with
>>> hardware support can be more efficient and we don't want things to break
>>> if someone puts spi-lsb-first in the devicetree.
>
>
next prev parent reply other threads:[~2025-09-17 13:21 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-15 22:14 [PATCH v11 0/3] Add MAX14001/MAX14002 support Marilene Andrade Garcia
2025-09-15 22:16 ` [PATCH v11 1/3] dt-bindings: iio: adc: add max14001 Marilene Andrade Garcia
2025-09-16 16:40 ` David Lechner
2025-09-16 19:20 ` Conor Dooley
2025-09-20 21:44 ` Marcelo Schmitt
2025-09-21 21:22 ` Conor Dooley
2025-09-21 21:49 ` Marilene Andrade Garcia
2025-09-15 22:16 ` [PATCH v11 2/3] iio: adc: max14001: New driver Marilene Andrade Garcia
2025-09-16 7:57 ` Andy Shevchenko
2025-09-16 18:04 ` David Lechner
2025-09-16 18:25 ` David Lechner
2025-09-17 8:10 ` Andy Shevchenko
2025-09-17 8:12 ` Andy Shevchenko
2025-09-17 13:21 ` David Lechner [this message]
2025-09-17 13:14 ` David Lechner
2025-09-23 0:56 ` Marilene Andrade Garcia
2025-09-23 14:27 ` David Lechner
2025-09-24 2:40 ` Marilene Andrade Garcia
2025-09-15 22:16 ` [PATCH v11 3/3] iio: ABI: Add voltage mean raw attribute Marilene Andrade Garcia
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=6ab0cee1-846f-4f90-bc61-141f74144a50@baylibre.com \
--to=dlechner@baylibre.com \
--cc=Jonathan.Santos@analog.com \
--cc=Marcelo.Schmitt@analog.com \
--cc=Michael.Hennerich@analog.com \
--cc=andriy.shevchenko@intel.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dragos.bogdan@analog.com \
--cc=dumitru.ceclan@analog.com \
--cc=jic23@kernel.org \
--cc=kimseer.paller@analog.com \
--cc=krzk+dt@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.schmitt1@gmail.com \
--cc=marilene.agarcia@gmail.com \
--cc=nuno.sa@analog.com \
--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