From: Jonathan Cameron <jic23@kernel.org>
To: Jorge Marques <gastmaier@gmail.com>
Cc: "Jorge Marques" <jorge.marques@analog.com>,
"Lars-Peter Clausen" <lars@metafoo.de>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Uwe Kleine-König" <ukleinek@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org, linux-doc@vger.kernel.org,
linux-pwm@vger.kernel.org
Subject: Re: [PATCH v3 6/8] iio: adc: Add offload support for ad4052
Date: Sat, 21 Jun 2025 17:16:48 +0100 [thread overview]
Message-ID: <20250621171648.6f40904f@jic23-huawei> (raw)
In-Reply-To: <hdwuh3ouw4gzpbj7u7dtzaphdjonecls2xuu7p4nmi7wwrcmye@jhhhqvdlbuv3>
On Fri, 20 Jun 2025 20:52:10 +0200
Jorge Marques <gastmaier@gmail.com> wrote:
> On Sat, Jun 14, 2025 at 11:20:22AM +0100, Jonathan Cameron wrote:
> > On Tue, 10 Jun 2025 09:34:39 +0200
> > Jorge Marques <jorge.marques@analog.com> wrote:
> >
> > > Support SPI offload with appropriate FPGA firmware. Since the SPI-Engine
> > > offload module always sends 32-bit data to the DMA engine, the
> > > scantype.storagebytes is set to 32-bit and the SPI transfer length is
> > > based on the scantype.realbits. This combination allows to optimize the
> > > SPI to transfer only 2 or 3 bytes (depending on the granularity and
> > > mode), while the number of samples are computed correctly by tools on
> > > top of the iio scantype.
> > >
> > > Signed-off-by: Jorge Marques <jorge.marques@analog.com>
> > Minor comments inline. I think they are all follow up from comments on
> > earlier patches that apply here as well.
> >
> > > ---
> > > drivers/iio/adc/ad4052.c | 244 ++++++++++++++++++++++++++++++++++++++++++++++-
> > > 1 file changed, 242 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/iio/adc/ad4052.c b/drivers/iio/adc/ad4052.c
> > > index 842f5972a1c58701addf5243e7b87da9c26c773f..7d32dc4701ddb0204b5505a650ce7caafc2cb5ed 100644
> > > --- a/drivers/iio/adc/ad4052.c
> > > +++ b/drivers/iio/adc/ad4052.c
> > > @@ -11,6 +11,8 @@
> > > #include <linux/delay.h>
> > > #include <linux/err.h>
> > > #include <linux/gpio/consumer.h>
> > > +#include <linux/iio/buffer.h>
> > > +#include <linux/iio/buffer-dmaengine.h>
> > > #include <linux/iio/iio.h>
> > > #include <linux/iio/sysfs.h>
> > > #include <linux/interrupt.h>
> > > @@ -23,6 +25,8 @@
> > > #include <linux/regmap.h>
> > > #include <linux/regulator/consumer.h>
> > > #include <linux/spi/spi.h>
> > > +#include <linux/spi/offload/consumer.h>
> > > +#include <linux/spi/offload/provider.h>
> > > #include <linux/string.h>
> > > #include <linux/types.h>
> > > #include <linux/units.h>
> > > @@ -111,6 +115,7 @@ enum ad4052_interrupt_en {
> > >
> > > struct ad4052_chip_info {
> > > const struct iio_chan_spec channels[1];
> > > + const struct iio_chan_spec offload_channels[1];
> >
> > If there is only ever one of these drop the array.
> >
> Hi Jonathan,
>
> It is hard to predict if no other similar device will have only two
> channels. But I would say most drivers end-up having more channels.
Ok. I don't mind that much, but it does feel like planning for a future
that might or might not come. Easy enough to refactor later.
> >
> > >
> > > +static int ad4052_update_xfer_offload(struct iio_dev *indio_dev,
> > > + struct iio_chan_spec const *chan)
> > > +{
> > > + struct ad4052_state *st = iio_priv(indio_dev);
> > > + const struct iio_scan_type *scan_type;
> > > + struct spi_transfer *xfer = &st->offload_xfer;
> > > +
> > > + scan_type = iio_get_current_scan_type(indio_dev, chan);
> > > + if (IS_ERR(scan_type))
> > > + return PTR_ERR(scan_type);
> > > +
> > > + xfer->bits_per_word = scan_type->realbits;
> > > + xfer->offload_flags = SPI_OFFLOAD_XFER_RX_STREAM;
> > > + xfer->len = scan_type->realbits == 24 ? 4 : 2;
> >
> > Same question on length vs bits_per_word applies here as in the earlier
> > patch.
> >
> To be able to optimize the SPI message, len must be a multiple of 16
> bits. To achieve maximum throughput, no extra bits (and therefore SCLK
> clock cycles) must be transferred during the SPI transfer. This is set
> by bits_per_word, 24-bits means 24 SCLK.
I got that intention, what I wasn't sure on was what the spi subsystem
would do with this case.
I checked the docs and this case is called out though only in the
spi_device docs for bits_per_word (not mentioned in the spi_transfer
docs) so fair enough. Just seemed strange!
>
> Finally, storagebits is the number of bits actually used to store the
> reading, and for the offload channel is the DMA width, always 32-bits.
> An abstraction to obtain the DMA width should be created, so the 32-bits
> value is not hard-coded into the driver, still, for this series, it is.
>
Thanks
Jonathan
next prev parent reply other threads:[~2025-06-21 16:16 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-10 7:34 [PATCH v3 0/8] Add support for AD4052 device family Jorge Marques
2025-06-10 7:34 ` [PATCH v3 1/8] Documentation: ABI: add oversampling frequency in sysfs-bus-iio Jorge Marques
2025-06-11 17:02 ` Jonathan Cameron
2025-06-12 10:10 ` Jorge Marques
2025-06-10 7:34 ` [PATCH v3 2/8] dt-bindings: iio: adc: Add adi,ad4052 Jorge Marques
2025-06-11 17:18 ` Jonathan Cameron
2025-06-12 10:11 ` Jorge Marques
2025-06-12 15:03 ` David Lechner
2025-06-12 19:42 ` Jorge Marques
2025-06-12 20:20 ` David Lechner
2025-06-13 11:17 ` Jorge Marques
2025-06-14 10:14 ` Jonathan Cameron
2025-06-10 7:34 ` [PATCH v3 3/8] docs: iio: New docs for ad4052 driver Jorge Marques
2025-06-10 7:34 ` [PATCH v3 4/8] iio: adc: Add support for ad4052 Jorge Marques
2025-06-14 10:08 ` Jonathan Cameron
2025-06-16 14:54 ` David Lechner
2025-06-21 16:08 ` Jonathan Cameron
2025-06-21 16:13 ` David Lechner
2025-06-22 14:28 ` Jonathan Cameron
2025-06-17 14:59 ` Uwe Kleine-König
2025-06-17 15:34 ` Jorge Marques
2025-06-18 17:55 ` Uwe Kleine-König
2025-06-10 7:34 ` [PATCH v3 5/8] docs: iio: ad4052: Add offload support documentation Jorge Marques
2025-06-10 7:34 ` [PATCH v3 6/8] iio: adc: Add offload support for ad4052 Jorge Marques
2025-06-14 10:20 ` Jonathan Cameron
2025-06-20 18:52 ` Jorge Marques
2025-06-21 16:16 ` Jonathan Cameron [this message]
2025-06-10 7:34 ` [PATCH v3 7/8] docs: iio: ad4052: Add event documentation Jorge Marques
2025-06-10 7:34 ` [PATCH v3 8/8] iio: adc: Add events support to ad4052 Jorge Marques
2025-06-12 19:38 ` David Lechner
2025-06-13 10:02 ` Jorge Marques
2025-06-13 16:03 ` David Lechner
2025-06-14 10:25 ` Jonathan Cameron
2025-06-14 10:40 ` Jonathan Cameron
2025-06-14 10:36 ` Jonathan Cameron
2025-06-16 13:54 ` Jorge Marques
2025-06-21 16:20 ` 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=20250621171648.6f40904f@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=gastmaier@gmail.com \
--cc=jorge.marques@analog.com \
--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-pwm@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.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