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

Angelo Dureghello
2025-04-14T20:00:45Z

On 14.04.2025 19:24, Jonathan Cameron wrote:
>
> > +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 ? */
> > + 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)
>
> should be ret; Thanks to 0-day for the report and fixed up.
>

thanks for fixing it.

Regards,
angelo

> > + 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;
> > +}