From: David Lechner <dlechner@baylibre.com>
To: Marcelo Schmitt <marcelo.schmitt@analog.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Cc: jic23@kernel.org, nuno.sa@analog.com,
Michael.Hennerich@analog.com, andy@kernel.org, robh@kernel.org,
krzk+dt@kernel.org, conor+dt@kernel.org, julianbraha@gmail.com,
marcelo.schmitt1@gmail.com
Subject: Re: [PATCH v6 3/4] iio: adc: ltc2378: Enable high-speed data capture
Date: Sat, 11 Jul 2026 10:44:35 -0500 [thread overview]
Message-ID: <ef47b780-e62f-4d30-8c23-97422bcbb332@baylibre.com> (raw)
In-Reply-To: <4d4b5cac52b6f4a341d97bd41562a451e8e757f7.1783629101.git.marcelo.schmitt@analog.com>
On 7/9/26 3:50 PM, Marcelo Schmitt wrote:
> Make use of SPI transfer offloading to speed up data capture, enabling data
> acquisition at faster sample rates (up to 2 MSPS).
>
...
> +static int ltc2378_prepare_offload_message(struct device *dev,
> + struct ltc2378_state *st)
> +{
> + unsigned int resolution = st->info->offload_chan.scan_type.realbits;
> +
> + st->offload_xfer.bits_per_word = resolution;
> + st->offload_xfer.len = spi_bpw_to_bytes(resolution);
> + st->offload_xfer.offload_flags = SPI_OFFLOAD_XFER_RX_STREAM;
> +
> + /* Initialize message with offload */
> + spi_message_init_with_transfers(&st->offload_msg, &st->offload_xfer, 1);
> + st->offload_msg.offload = st->offload;
> +
> + return devm_spi_optimize_message(dev, st->spi, &st->offload_msg);
> +}
Would be more logical to move this function after buffer stuff.
> +
> +static int ltc2378_offload_buffer_postenable(struct iio_dev *indio_dev)
> +{
> + struct ltc2378_state *st = iio_priv(indio_dev);
> + int ret;
> +
> + ret = pwm_set_waveform_might_sleep(st->cnv_trigger, &st->cnv_wf, true);
> + if (ret)
> + return ret;
> +
> + ret = spi_offload_trigger_enable(st->offload, st->offload_trigger,
> + &st->offload_trigger_config);
> + if (ret)
> + goto out_pwm_disable;
> +
> + return 0;
> +
> +out_pwm_disable:
> + pwm_disable(st->cnv_trigger);
> + return ret;
> +}
> +
> +static int ltc2378_offload_buffer_predisable(struct iio_dev *indio_dev)
> +{
> + struct ltc2378_state *st = iio_priv(indio_dev);
> +
> + spi_offload_trigger_disable(st->offload, st->offload_trigger);
> + pwm_disable(st->cnv_trigger);
> +
> + return 0;
> +}
> +
> +static const struct iio_buffer_setup_ops ltc2378_offload_buffer_ops = {
> + .postenable = <c2378_offload_buffer_postenable,
> + .predisable = <c2378_offload_buffer_predisable,
> +};
> +
... to here or even below somewhere.
> +static int ltc2378_spi_offload_setup(struct iio_dev *indio_dev,
> + struct ltc2378_state *st)
> +{
> + struct device *dev = &st->spi->dev;
> + struct dma_chan *rx_dma;
> +
> + indio_dev->setup_ops = <c2378_offload_buffer_ops;
> +
> + st->offload_trigger = devm_spi_offload_trigger_get(dev, st->offload,
> + SPI_OFFLOAD_TRIGGER_PERIODIC);
> + if (IS_ERR(st->offload_trigger))
> + return dev_err_probe(dev, PTR_ERR(st->offload_trigger),
> + "failed to get offload trigger\n");
> +
> + st->offload_trigger_config.type = SPI_OFFLOAD_TRIGGER_PERIODIC;
> +
> + rx_dma = devm_spi_offload_rx_stream_request_dma_chan(dev, st->offload);
> + if (IS_ERR(rx_dma))
> + return dev_err_probe(dev, PTR_ERR(rx_dma), "failed to get offload RX DMA\n");
> +
> + return devm_iio_dmaengine_buffer_setup_with_handle(dev, indio_dev, rx_dma,
> + IIO_BUFFER_DIRECTION_IN);
> +}
> +
...
> @@ -340,8 +672,53 @@ static int ltc2378_probe(struct spi_device *spi)
> return dev_err_probe(dev, PTR_ERR(st->cnv_gpio),
> "failed to get CNV GPIO");
>
> - indio_dev->channels = &st->info->chan;
> - indio_dev->num_channels = 1;
> + st->offload = devm_spi_offload_get(dev, spi, <c2378_offload_config);
> + ret = PTR_ERR_OR_ZERO(st->offload);
> + /* Fall back to low speed usage when no SPI offload is available. */
> + if (ret == -ENODEV) {
> + indio_dev->info = <c2378_iio_info;
> + indio_dev->channels = &st->info->chan;
> + indio_dev->num_channels = 1;
> + } else if (ret) {
> + return dev_err_probe(dev, ret, "failed to get offload\n");
> + } else {
> + indio_dev->info = <c2378_offload_iio_info;
> + indio_dev->channels = &st->info->offload_chan;
> + indio_dev->num_channels = 1;
> + ret = ltc2378_spi_offload_setup(indio_dev, st);
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "failed to setup SPI offload\n");
> +
> + ret = ltc2378_pwm_get(st);
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to get PWM\n");
> +
> + st->sample_freq_range[0] = 1; /* min */
> + st->sample_freq_range[1] = 1; /* step */
> + st->sample_freq_range[2] = st->info->max_sample_rate_Hz; /* max */
> +
> + /*
> + * Start with a slower sampling rate so there is some room for
> + * adjusting the sample averaging and the sampling frequency
> + * without hitting the maximum conversion rate.
> + */
> + ret = ltc2378_update_conversion_rate(st, st->info->max_sample_rate_Hz >> 4);
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "failed to set offload samp freq\n");
> +
> + ret = ltc2378_prepare_offload_message(&spi->dev, st);
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to optimize SPI message\n");
> +
> + /*
> + * Set single-read transfer bits_per_word so the SPI subsystem
> + * rearanges data to CPU endianness, enabling us to reuse
s/rearanges/rearranges/
> + * offload_chan specifications for single-shot reads.
> + */
> + st->xfer.bits_per_word = st->info->offload_chan.scan_type.realbits;
> + }
>
> st->xfer.rx_buf = &st->scan.data;
> st->xfer.len = spi_bpw_to_bytes(indio_dev->channels[0].scan_type.realbits);
> @@ -412,3 +789,4 @@ module_spi_driver(ltc2378_driver);
> MODULE_AUTHOR("Marcelo Schmitt <marcelo.schmitt@analog.com>");
> MODULE_DESCRIPTION("Analog Devices LTC2378 ADC series driver");
> MODULE_LICENSE("GPL");
> +MODULE_IMPORT_NS("IIO_DMAENGINE_BUFFER");
next prev parent reply other threads:[~2026-07-11 15:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-09 20:49 [PATCH v6 0/4] iio: adc: Add support for LTC2378 and similar ADCs Marcelo Schmitt
2026-07-09 20:49 ` [PATCH v6 1/4] dt-bindings: iio: adc: Add ltc2378 Marcelo Schmitt
2026-07-09 20:58 ` sashiko-bot
2026-07-10 21:06 ` Marcelo Schmitt
2026-07-09 20:49 ` [PATCH v6 2/4] iio: adc: ltc2378: Add support for LTC2378-20 and similar ADCs Marcelo Schmitt
2026-07-09 21:04 ` sashiko-bot
2026-07-10 2:22 ` Jonathan Cameron
2026-07-11 15:45 ` David Lechner
2026-07-12 1:53 ` Jonathan Cameron
2026-07-09 20:50 ` [PATCH v6 3/4] iio: adc: ltc2378: Enable high-speed data capture Marcelo Schmitt
2026-07-09 23:24 ` sashiko-bot
2026-07-10 21:15 ` Marcelo Schmitt
2026-07-11 15:44 ` David Lechner [this message]
2026-07-09 20:50 ` [PATCH v6 4/4] iio: adc: ltc2378: Enable triggered buffer " Marcelo Schmitt
2026-07-11 15:49 ` [PATCH v6 0/4] iio: adc: Add support for LTC2378 and similar ADCs 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=ef47b780-e62f-4d30-8c23-97422bcbb332@baylibre.com \
--to=dlechner@baylibre.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=julianbraha@gmail.com \
--cc=krzk+dt@kernel.org \
--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 \
--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