Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Angelo Dureghello <adureghello@baylibre.com>
Cc: "Lars-Peter Clausen" <lars@metafoo.de>,
	"Michael Hennerich" <Michael.Hennerich@analog.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"David Lechner" <dlechner@baylibre.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: ad7380: add support for SPI offload
Date: Sat, 22 Feb 2025 16:31:02 +0000	[thread overview]
Message-ID: <20250222163102.20510e8d@jic23-huawei> (raw)
In-Reply-To: <20250220-wip-bl-spi-offload-ad7380-v1-1-838aa873e62a@baylibre.com>

On Thu, 20 Feb 2025 19:03:30 +0100
Angelo Dureghello <adureghello@baylibre.com> wrote:

> From: Angelo Dureghello <adureghello@baylibre.com>
> 
> Add support for SPI offload to the ad7380 driver. SPI offload allows
> sampling data at the max sample rate (2MSPS with one SDO line).
> 
> This is developed and tested against the ADI example FPGA design for
> this family of ADCs [1].
> 
> [1]: http://analogdevicesinc.github.io/hdl/projects/ad738x_fmc/index.html
> 
> Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
Just one trivial comment from me that I can tidy up when applying if nothing else
comes up.  However, I'd like David to take a look at this before I apply
(+ anyone else who has time!)

Jonathan

> diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c
> index a18dcd664c1b5e5032cc55c063e5681d11c23352..492356eed9a9f86c27a00cf1e280bd6432ed30b2 100644
> --- a/drivers/iio/adc/ad7380.c
> +++ b/drivers/iio/adc/ad7380.c
> @@ -15,6 +15,9 @@


> +static int ad7380_probe_spi_offload(struct iio_dev *indio_dev,
> +				    struct ad7380_state *st)
> +{
> +	struct spi_device *spi = st->spi;
> +	struct device *dev = &spi->dev;
> +	struct dma_chan *rx_dma;
> +	int sample_rate, ret;
> +
> +	indio_dev->setup_ops = &ad7380_offload_buffer_setup_ops;
> +	indio_dev->channels = st->chip_info->offload_channels;
> +	/* Just removing the timestamp channel. */
> +	indio_dev->num_channels--;
> +
> +	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");
> +
> +	sample_rate = st->chip_info->max_conversion_rate_hz *
> +		      AD7380_NUM_SDO_LINES / st->chip_info->num_simult_channels;
> +
> +	st->sample_freq_range[0] = 1; /* min */
> +	st->sample_freq_range[1] = 1; /* step */
> +	st->sample_freq_range[2] = sample_rate; /* max */
> +
> +	/*
> +	 * Starting with a quite low frequency, to allow oversampling x32,
> +	 * user is then reponsible to adjust the frequency for the specific case.
> +	 */
> +	ret = ad7380_set_sample_freq(st, sample_rate / 32);
> +	if (ret)
> +		return ret;
> +
> +	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");
> +
> +	ret = devm_iio_dmaengine_buffer_setup_with_handle(dev, indio_dev,
> +		rx_dma, IIO_BUFFER_DIRECTION_IN);
> +	if (ret)
> +		return dev_err_probe(dev, ret, "cannot setup dma buffer\n");
> +
> +	return ret;
return 0; as it can't be anything else.

> +}

  reply	other threads:[~2025-02-22 16:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-20 18:03 [PATCH] iio: ad7380: add support for SPI offload Angelo Dureghello
2025-02-22 16:31 ` Jonathan Cameron [this message]
2025-02-22 17:31 ` David Lechner
2025-02-25  9:48   ` Angelo Dureghello
2025-03-14 20:03   ` David Lechner
2025-03-15 18:15     ` 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=20250222163102.20510e8d@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Michael.Hennerich@analog.com \
    --cc=adureghello@baylibre.com \
    --cc=dlechner@baylibre.com \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --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