From: Jonathan Cameron <jic23@kernel.org>
To: Radu Sabau via B4 Relay <devnull+radu.sabau.analog.com@kernel.org>
Cc: radu.sabau@analog.com, "Lars-Peter Clausen" <lars@metafoo.de>,
"Michael Hennerich" <Michael.Hennerich@analog.com>,
"David Lechner" <dlechner@baylibre.com>,
"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>,
"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>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org,
linux-gpio@vger.kernel.org
Subject: Re: [PATCH 4/4] iio: adc: ad4691: add SPI offload support
Date: Thu, 5 Mar 2026 19:26:41 +0000 [thread overview]
Message-ID: <20260305192641.3c7c653f@jic23-huawei> (raw)
In-Reply-To: <20260305-ad4692-multichannel-sar-adc-driver-v1-4-336229a8dcc7@analog.com>
On Thu, 05 Mar 2026 14:23:30 +0200
Radu Sabau via B4 Relay <devnull+radu.sabau.analog.com@kernel.org> wrote:
> From: Radu Sabau <radu.sabau@analog.com>
>
> Add SPI offload support to the AD4691 family driver to enable
> DMA-based RX stream acquisition. When an SPI offload is available,
> the driver switches to a pre-built SPI message with 32-bit transfers
> (4-byte frames aligned to DMA width) and registers a periodic
> offload trigger for autonomous, CPU-independent sampling.
>
> The offload path implements its own buffer setup ops
> (ad4691_offload_buffer_postenable/predisable) that enable the
> offload trigger and wire the DMAengine buffer, while the existing
> software triggered buffer path is retained as a fallback for
> non-offload configurations.
>
> Offload channel specs use a 32-bit storage/repeat with a 16-bit
> shift to extract ADC data from the MSBytes of each DMA word,
> matching the wire format in Manual Mode where SDO outputs ADC data
> directly without a command echo.
>
> Kconfig gains a dependency on IIO_BUFFER_DMAENGINE.
>
> Signed-off-by: Radu Sabau <radu.sabau@analog.com>
Just a few really quick comments as I'm out of time for today.
J
> diff --git a/drivers/iio/adc/ad4691.c b/drivers/iio/adc/ad4691.c
> index ab48f336e46c..7ec0a2555a4b 100644
> --- a/drivers/iio/adc/ad4691.c
> +++ b/drivers/iio/adc/ad4691.c
> @@ -8,6 +8,7 @@
> #include <linux/clk.h>
> #include <linux/delay.h>
> #include <linux/device.h>
> +#include <linux/dmaengine.h>
> #include <linux/err.h>
> #include <linux/gpio/consumer.h>
> #include <linux/hrtimer.h>
> @@ -21,11 +22,15 @@
> #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>
This is a provider and a consumer?
> #include <linux/util_macros.h>
> #include <linux/units.h>
> #include <linux/unaligned.h>
> @@ -719,7 +871,9 @@ static int ad4691_set_sampling_freq(struct iio_dev *indio_dev, unsigned int freq
> * count. The exact period is refined at buffer enable time when
> * the active channel count is known.
> */
> - period_ns = ad4691_cnv_burst_period_ns(st, st->chip->num_channels);
> + period_ns = ad4691_cnv_burst_period_ns(st,
> + st->chip->num_channels,
Check for reformatting like occurred for 1st two lines here and try and
tweak earlier patches to reduce the churn.
> + false);
> +
> +static int ad4691_offload_buffer_predisable(struct iio_dev *indio_dev)
> +{
> + struct ad4691_state *st = iio_priv(indio_dev);
> + struct spi_offload_trigger *trigger;
> + int ret = 0, tmp;
> +
> + trigger = (st->adc_mode == AD4691_MANUAL_MODE) ?
> + st->offload_trigger_periodic : st->offload_trigger;
> +
> + spi_offload_trigger_disable(st->offload, trigger);
> + spi_unoptimize_message(&st->offload_msg);
> +
> + /* Stop conversions and reset sequencer state (not needed for MANUAL_MODE) */
> + if (st->adc_mode != AD4691_MANUAL_MODE) {
> + tmp = ad4691_sampling_enable(st, false);
> + if (!ret)
> + ret = tmp;
> +
> + tmp = regmap_write(st->regmap, AD4691_STD_SEQ_CONFIG,
> + AD4691_SEQ_ALL_CHANNELS_OFF);
> + if (!ret)
If that failed, all bets are off. May be better to just return the error.
> + ret = tmp;
> +
> + tmp = regmap_write(st->regmap, AD4691_STATE_RESET_REG,
> + AD4691_STATE_RESET_ALL);
> + if (!ret)
> + ret = tmp;
> + }
> +
> + return ret;
> +}
> static irqreturn_t ad4691_irq(int irq, void *private)
> {
> struct iio_dev *indio_dev = private;
> @@ -1353,10 +1802,17 @@ static void ad4691_setup_channels(struct iio_dev *indio_dev,
> struct ad4691_state *st)
> {
> if (st->adc_mode == AD4691_MANUAL_MODE) {
> - if (st->chip->num_channels == 8)
> - indio_dev->channels = ad4693_manual_channels;
> - else
> - indio_dev->channels = ad4691_manual_channels;
> + if (st->offload) {
Add more pointers to channel arrays to the chip_info structures and just look them
up from there.
> + if (st->chip->num_channels == 8)
> + indio_dev->channels = ad4693_manual_offload_channels;
> + else
> + indio_dev->channels = ad4691_manual_offload_channels;
> + } else {
> + if (st->chip->num_channels == 8)
> + indio_dev->channels = ad4693_manual_channels;
> + else
> + indio_dev->channels = ad4691_manual_channels;
> + }
next prev parent reply other threads:[~2026-03-05 19:26 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-05 12:23 [PATCH 0/4] iio: adc: ad4691: add driver for AD4691 multichannel SAR ADC family Radu Sabau via B4 Relay
2026-03-05 12:23 ` [PATCH 1/4] dt-bindings: iio: adc: add bindings for AD4691 family Radu Sabau via B4 Relay
2026-03-05 12:44 ` Krzysztof Kozlowski
2026-03-05 17:45 ` Jonathan Cameron
2026-03-06 11:55 ` Sabau, Radu bogdan
2026-03-07 18:48 ` David Lechner
2026-03-08 18:28 ` Jonathan Cameron
2026-03-09 8:57 ` Sabau, Radu bogdan
2026-03-09 14:34 ` David Lechner
2026-03-05 12:23 ` [PATCH 2/4] iio: adc: ad4691: add initial driver " Radu Sabau via B4 Relay
2026-03-05 19:12 ` Jonathan Cameron
2026-03-06 17:30 ` Markus Elfring
2026-03-05 12:23 ` [PATCH 3/4] iio: adc: ad4691: add triggered buffer support Radu Sabau via B4 Relay
2026-03-05 19:21 ` Jonathan Cameron
2026-03-05 12:23 ` [PATCH 4/4] iio: adc: ad4691: add SPI offload support Radu Sabau via B4 Relay
2026-03-05 19:26 ` Jonathan Cameron [this message]
2026-03-06 12:05 ` [PATCH 0/4] iio: adc: ad4691: add driver for AD4691 multichannel SAR ADC family Andy Shevchenko
2026-03-06 12:39 ` Sabau, Radu bogdan
2026-03-06 14:33 ` Andy Shevchenko
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=20260305192641.3c7c653f@jic23-huawei \
--to=jic23@kernel.org \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=brgl@kernel.org \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=devnull+radu.sabau.analog.com@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-gpio@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=radu.sabau@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