Re: [PATCH] iio: ad7380: add support for SPI offload

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

> From: Angelo Dureghello <adureghello@xxxxxxxxxxxx>
> 
> 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@xxxxxxxxxxxx>
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.

> +}




[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux