Skip to contentSkip to conversation

iio: adc: stm32-adc: Use dma_request_chan() instead dma_request_slave_channel()

PATCH In review Peter Ujfalusi 3 participants 3 messages Dec 17, 2019 – Jan 6, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: adc: stm32-adc: Use dma_request_chan() instead dma_request_slave_channel()

dma_request_slave_channel() is a wrapper on top of dma_request_chan() eating up the error code.

By using dma_request_chan() directly the driver can support deferred probing against DMA.

---
 drivers/iio/adc/stm32-adc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/iio/adc/stm32-adc.c +8 -2
index 3b291d72701c..5dab23f1fdee 100644
@@ -1746,9 +1746,15 @@ static int stm32_adc_dma_request(struct iio_dev *indio_dev)
 	struct dma_slave_config config;
 	int ret;
 
-	adc->dma_chan = dma_request_slave_channel(&indio_dev->dev, "rx");
-	if (!adc->dma_chan)
+	adc->dma_chan = dma_request_chan(&indio_dev->dev, "rx");
+	if (IS_ERR(adc->dma_chan)) {
+		if (PTR_ERR(adc->dma_chan) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+
+		/* Ignore errors to fall back to IRQ mode */
+		adc->dma_chan = NULL;
 		return 0;
+	}
 
 	adc->rx_buf = dma_alloc_coherent(adc->dma_chan->device->dev,
 					 STM32_DMA_BUFFER_SIZE,
Signature · 4 lines
Peter

Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki.
Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki
maintainer
#1 lore raw
Quoted 7 lines · On Tue, 17 Dec 2019 09:51:53 +0200 Peter Ujfalusi <[email protected]> wrote:

dma_request_slave_channel() is a wrapper on top of dma_request_chan() eating up the error code.

By using dma_request_chan() directly the driver can support deferred probing against DMA.

Hi Peter,

Change looks sensible to me, but I'd like to leave a little longer for others to look at this.

Give me a poke if I seem to have lost it by the end of the first week in Jan.

Thanks,

Jonathan

Quoted 26 lines
---
 drivers/iio/adc/stm32-adc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/iio/adc/stm32-adc.c +8 -2
index 3b291d72701c..5dab23f1fdee 100644
@@ -1746,9 +1746,15 @@ static int stm32_adc_dma_request(struct iio_dev *indio_dev)
 	struct dma_slave_config config;
 	int ret;
 
-	adc->dma_chan = dma_request_slave_channel(&indio_dev->dev, "rx");
-	if (!adc->dma_chan)
+	adc->dma_chan = dma_request_chan(&indio_dev->dev, "rx");
+	if (IS_ERR(adc->dma_chan)) {
+		if (PTR_ERR(adc->dma_chan) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+
+		/* Ignore errors to fall back to IRQ mode */
+		adc->dma_chan = NULL;
 		return 0;
+	}
 
 	adc->rx_buf = dma_alloc_coherent(adc->dma_chan->device->dev,
 					 STM32_DMA_BUFFER_SIZE,
#2 lore raw
Quoted 34 lines · Jonathan Cameron
Quoted 7 lines · On Tue, 17 Dec 2019 09:51:53 +0200 Peter Ujfalusi <[email protected]> wrote:

dma_request_slave_channel() is a wrapper on top of dma_request_chan() eating up the error code.

By using dma_request_chan() directly the driver can support deferred probing against DMA.

Hi Peter,

Change looks sensible to me, but I'd like to leave a little longer for others to look at this.

Give me a poke if I seem to have lost it by the end of the first week in Jan.

Thanks,

Jonathan

Quoted 12 lines
---
 drivers/iio/adc/stm32-adc.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/iio/adc/stm32-adc.c +0 -0
index 3b291d72701c..5dab23f1fdee 100644
@@ -1746,9 +1746,15 @@ static int stm32_adc_dma_request(struct iio_dev *indio_dev)
 	struct dma_slave_config config;
 	int ret;
 
Quoted 6 lines

drivers/iio/adc/stm32-adc.c static int stm32_adc_dma_request(struct iio_dev *indio_dev) · line 1752

Quoted 6 lines
drivers/iio/adc/stm32-adc.c +4 -2
-	adc->dma_chan = dma_request_slave_channel(&indio_dev->dev, "rx");
-	if (!adc->dma_chan)
+	adc->dma_chan = dma_request_chan(&indio_dev->dev, "rx");
+	if (IS_ERR(adc->dma_chan)) {
+		if (PTR_ERR(adc->dma_chan) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;

Hi Peter,

Thanks for the patch and sorry for the late reply.

I'd rather prefer to check explicitly for -ENODEV (as the DMA is optional) to use the IRQ mode and treat all other codes (including EPROBE_DEFER) as errors.

Rationale is: This can hide other errors e.g. like all DMA channels are busy/reserved for other usage. So the user may wrongly think it's probing the driver, with DMA. This may be a corner case, but still... DMA channels are assigned via device tree. I'd rather prefer to avoid depending of runtime (probe ordering) in such a case.

Can you update the patch considering this ?

Please find here an alternate proposal:

	adc->dma_chan = dma_request_chan(&indio_dev->dev, "rx");
	if (IS_ERR(adc->dma_chan)) {
		if (PTR_ERR(adc->dma_chan) != -ENODEV)
			return PTR_ERR(adc->dma_chan);

		/* DMA is optional: fall back to IRQ mode */
		adc->dma_chan = NULL;
		return 0;
	}

Best regards,
Fabrice

Quoted 9 lines

drivers/iio/adc/stm32-adc.c static int stm32_adc_dma_request(struct iio_dev *indio_dev) · line 1760

Quoted 8 lines
drivers/iio/adc/stm32-adc.c +4 -0
+
+		/* Ignore errors to fall back to IRQ mode */
+		adc->dma_chan = NULL;
 		return 0;
+	}
 
 	adc->rx_buf = dma_alloc_coherent(adc->dma_chan->device->dev,
 					 STM32_DMA_BUFFER_SIZE,

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel