Skip to content

Commit b903e79

Browse files
committed
iio: adc: ad4630: Use filtered DMA Engine buffer for single-channel ADCs
Use the new filtered DMA buffer variant to avoid pushing noise to IIO buffers when single-channel ADCs are used. Signed-off-by: Marcelo Schmitt <[email protected]>
1 parent 8ff837c commit b903e79

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

drivers/iio/adc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ config AD4630
8383
select IIO_BUFFER
8484
select IIO_BUFFER_DMA
8585
select IIO_BUFFER_DMAENGINE
86+
select IIO_BUFFER_DMAENGINE_FILTERED
8687
help
8788
Say yes here to build support for Analog Devices AD4630 high speed
8889
SPI analog to digital converters (ADC).

drivers/iio/adc/ad4630.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1540,8 +1540,24 @@ static int ad4630_probe(struct spi_device *spi)
15401540
return dev_err_probe(dev, PTR_ERR(rx_dma),
15411541
"failed to get offload RX DMA\n");
15421542

1543-
ret = devm_iio_dmaengine_buffer_setup_with_handle(dev, indio_dev,
1544-
rx_dma, IIO_BUFFER_DIRECTION_IN);
1543+
/*
1544+
* The ad4630_fmc HDL project was designed for ADCs with two channels
1545+
* and always streams two data channels to DMA (even when the ADC has
1546+
* only one physical channel). Though, if the ADC has only one physical
1547+
* channel, the data that would come from the second ADC channel comes
1548+
* in as noise and has to be discarded. Because of that, when using
1549+
* single-channel ADCs, the ADC driver needs to use a special DMA buffer
1550+
* that filters out half of the data that reaches DMA memory. With that,
1551+
* the ADC sample data can be delivered to user space without any noise
1552+
* being added to the IIO buffer.
1553+
*/
1554+
if (indio_dev->num_channels == 1)
1555+
ret = devm_iio_dmaengine_filtered_buffer_setup_with_handle(dev,
1556+
indio_dev, rx_dma,
1557+
IIO_BUFFER_DIRECTION_IN);
1558+
else
1559+
ret = devm_iio_dmaengine_buffer_setup_with_handle(dev, indio_dev,
1560+
rx_dma, IIO_BUFFER_DIRECTION_IN);
15451561
if (ret)
15461562
return dev_err_probe(dev, ret,
15471563
"Failed to get DMA buffer\n");
@@ -1638,3 +1654,4 @@ MODULE_AUTHOR("Liviu Adace <[email protected]>");
16381654
MODULE_DESCRIPTION("Analog Devices AD4630 and ADAQ4224 ADC family driver");
16391655
MODULE_LICENSE("GPL v2");
16401656
MODULE_IMPORT_NS(IIO_DMAENGINE_BUFFER);
1657+
MODULE_IMPORT_NS(IIO_DMAENGINE_FILTERED_BUFFER);

0 commit comments

Comments
 (0)