Re: [PATCH 3/3] iio: adc: ad7606: add SPI offload support

Jonathan Cameron
2025-04-05T15:40:51Z

On Thu, 03 Apr 2025 18:19:06 +0200
Angelo Dureghello <adureghello@baylibre.com> wrote:

> From: Angelo Dureghello <adureghello@baylibre.com>
>
> Add SPI offload support for this family.
>
> Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
Hi Angelo,

Code looks fine, but there is a TODO I'd like to know more about
as it sounds 'ominous'.

Otherwise this needs a dt review for patch 1 before I queue it up.

Jonathan
> diff --git a/drivers/iio/adc/ad7606_spi.c b/drivers/iio/adc/ad7606_spi.c
> index b2b975fb7fea4d1af6caef59e75ca495501bc140..b086122497eb22042171580878160334f56baa23 100644
> --- a/drivers/iio/adc/ad7606_spi.c
> +++ b/drivers/iio/adc/ad7606_spi.c

> +static int ad7606_spi_offload_probe(struct device *dev,
> + struct iio_dev *indio_dev)
> +{
> + struct ad7606_state *st = iio_priv(indio_dev);
> + struct spi_device *spi = to_spi_device(dev);
> + struct spi_bus_data *bus_data;
> + struct dma_chan *rx_dma;
> + struct spi_offload_trigger_info trigger_info = {
> + .fwnode = dev_fwnode(dev),
> + .ops = &ad7606_offload_trigger_ops,
> + .priv = st,
> + };
> + int ret;
> +
> + bus_data = devm_kzalloc(dev, sizeof(*bus_data), GFP_KERNEL);
> + if (!bus_data)
> + return -ENOMEM;
> + st->bus_data = bus_data;
> +
> + bus_data->offload = devm_spi_offload_get(dev, spi,
> + &ad7606_spi_offload_config);
> + ret = PTR_ERR_OR_ZERO(bus_data->offload);
> + if (ret && ret != -ENODEV)
> + return dev_err_probe(dev, ret, "failed to get SPI offload\n");
> + /* Allow main ad7606_probe function to continue. */
> + if (ret == -ENODEV)
> + return 0;
> +
> + ret = devm_spi_offload_trigger_register(dev, &trigger_info);
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "failed to register offload trigger\n");
> +
> + bus_data->offload_trigger = devm_spi_offload_trigger_get(dev,
> + bus_data->offload, SPI_OFFLOAD_TRIGGER_DATA_READY);
> + if (IS_ERR(bus_data->offload_trigger))
> + return dev_err_probe(dev, PTR_ERR(bus_data->offload_trigger),
> + "failed to get offload trigger\n");
> +
> + /* TODO: PWM setup should be ok, done for the backend. PWM mutex ? */

I don't understand this todo. Perhaps some more details?

> + rx_dma = devm_spi_offload_rx_stream_request_dma_chan(dev,
> + bus_data->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, PTR_ERR(rx_dma),
> + "failed to setup offload RX DMA\n");
> +
> + /* Use offload ops. */
> + indio_dev->setup_ops = &ad7606_offload_buffer_setup_ops;
> +
> + st->offload_en = true;
> +
> + return 0;
> +}