linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: adc: stm32: fix scan of multiple channels with DMA
@ 2018-01-05 14:34 Fabrice Gasnier
  2018-01-06 12:50 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Fabrice Gasnier @ 2018-01-05 14:34 UTC (permalink / raw)
  To: linux-arm-kernel

By default, watermark is set to '1'. Watermark is used to fine tune
cyclic dma buffer period. In case watermark is left untouched (e.g. 1)
and several channels are being scanned, buffer period is wrongly set
(e.g. to 1 sample). As a consequence, data is never pushed to upper layer.
Fix buffer period size, by taking scan channels number into account.

Fixes: 2763ea0585c9 ("iio: adc: stm32: add optional dma support")

Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
---
 drivers/iio/adc/stm32-adc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
index c9d96f9..cecf1e5 100644
--- a/drivers/iio/adc/stm32-adc.c
+++ b/drivers/iio/adc/stm32-adc.c
@@ -1315,6 +1315,7 @@ static int stm32_adc_set_watermark(struct iio_dev *indio_dev, unsigned int val)
 {
 	struct stm32_adc *adc = iio_priv(indio_dev);
 	unsigned int watermark = STM32_DMA_BUFFER_SIZE / 2;
+	unsigned int rx_buf_sz = STM32_DMA_BUFFER_SIZE;
 
 	/*
 	 * dma cyclic transfers are used, buffer is split into two periods.
@@ -1323,7 +1324,7 @@ static int stm32_adc_set_watermark(struct iio_dev *indio_dev, unsigned int val)
 	 * - one buffer (period) driver can push with iio_trigger_poll().
 	 */
 	watermark = min(watermark, val * (unsigned)(sizeof(u16)));
-	adc->rx_buf_sz = watermark * 2;
+	adc->rx_buf_sz = min(rx_buf_sz, watermark * 2 * adc->num_conv);
 
 	return 0;
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] iio: adc: stm32: fix scan of multiple channels with DMA
  2018-01-05 14:34 [PATCH] iio: adc: stm32: fix scan of multiple channels with DMA Fabrice Gasnier
@ 2018-01-06 12:50 ` Jonathan Cameron
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2018-01-06 12:50 UTC (permalink / raw)
  To: linux-arm-kernel

On Fri, 5 Jan 2018 15:34:54 +0100
Fabrice Gasnier <fabrice.gasnier@st.com> wrote:

> By default, watermark is set to '1'. Watermark is used to fine tune
> cyclic dma buffer period. In case watermark is left untouched (e.g. 1)
> and several channels are being scanned, buffer period is wrongly set
> (e.g. to 1 sample). As a consequence, data is never pushed to upper layer.
> Fix buffer period size, by taking scan channels number into account.
> 
> Fixes: 2763ea0585c9 ("iio: adc: stm32: add optional dma support")
> 
> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>

Given where we are in the cycle I've applied this to the togreg
branch for the next merge window and marked it for stable.

This is probably the quickest way to get it in at this stage.

Thanks,

Jonathan
> ---
>  drivers/iio/adc/stm32-adc.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
> index c9d96f9..cecf1e5 100644
> --- a/drivers/iio/adc/stm32-adc.c
> +++ b/drivers/iio/adc/stm32-adc.c
> @@ -1315,6 +1315,7 @@ static int stm32_adc_set_watermark(struct iio_dev *indio_dev, unsigned int val)
>  {
>  	struct stm32_adc *adc = iio_priv(indio_dev);
>  	unsigned int watermark = STM32_DMA_BUFFER_SIZE / 2;
> +	unsigned int rx_buf_sz = STM32_DMA_BUFFER_SIZE;
>  
>  	/*
>  	 * dma cyclic transfers are used, buffer is split into two periods.
> @@ -1323,7 +1324,7 @@ static int stm32_adc_set_watermark(struct iio_dev *indio_dev, unsigned int val)
>  	 * - one buffer (period) driver can push with iio_trigger_poll().
>  	 */
>  	watermark = min(watermark, val * (unsigned)(sizeof(u16)));
> -	adc->rx_buf_sz = watermark * 2;
> +	adc->rx_buf_sz = min(rx_buf_sz, watermark * 2 * adc->num_conv);
>  
>  	return 0;
>  }

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-01-06 12:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-05 14:34 [PATCH] iio: adc: stm32: fix scan of multiple channels with DMA Fabrice Gasnier
2018-01-06 12:50 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).