diff mbox

[5/8] spi: sh-msiof: Wait for Tx FIFO empty after DMA

Message ID 20170906070507.26223-6-dirk.behme@de.bosch.com (mailing list archive)
State Superseded
Delegated to: Geert Uytterhoeven
Headers show

Commit Message

Dirk Behme Sept. 6, 2017, 7:05 a.m. UTC
From: Hiromitsu Yamasaki <hiromitsu.yamasaki.ym@renesas.com>

When Tx DMA is only used, Tx FIFO is still not empty after DMA callback.
This patch waits for sweeping data out of the Tx FIFO.

Signed-off-by: Hiromitsu Yamasaki <hiromitsu.yamasaki.ym@renesas.com>
[adjust context]
Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
---
 drivers/spi/spi-sh-msiof.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

Comments

Sergei Shtylyov Sept. 6, 2017, 5:57 p.m. UTC | #1
Hello!

On 09/06/2017 10:05 AM, Dirk Behme wrote:

> From: Hiromitsu Yamasaki <hiromitsu.yamasaki.ym@renesas.com>
> 
> When Tx DMA is only used, Tx FIFO is still not empty after DMA callback.
> This patch waits for sweeping data out of the Tx FIFO.
> 
> Signed-off-by: Hiromitsu Yamasaki <hiromitsu.yamasaki.ym@renesas.com>
> [adjust context]
> Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
> ---
>   drivers/spi/spi-sh-msiof.c | 13 ++++++++++++-
>   1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
> index 660b03ed6770..a960e8da123d 100644
> --- a/drivers/spi/spi-sh-msiof.c
> +++ b/drivers/spi/spi-sh-msiof.c
> @@ -638,6 +638,17 @@ static int sh_msiof_wait_for_completion(struct sh_msiof_spi_priv *p,
>   				dev_err(&p->pdev->dev, "Tx DMA timeout\n");
>   				return -ETIMEDOUT;
>   			}
> +			if (!rx) {
> +				sh_msiof_write(p, IER, IER_TEOFE);
> +
> +				/* wait for tx fifo to be emptied */
> +				if (!wait_for_completion_timeout(&p->done,
> +								 HZ)) {
> +					dev_err(&p->pdev->dev,
> +					"Tx fifo to be emptied timeout\n");

    Please indent this line properly, messages can violate 80-column limit.

> +					return -ETIMEDOUT;
> +				}
> +			}
>   		}
>   		if (rx) {
>   			if (!wait_for_completion_timeout(&p->done_dma_rx,
[...]

MBR, Sergei
Geert Uytterhoeven Sept. 7, 2017, 8:34 a.m. UTC | #2
Hi Dirk,

On Wed, Sep 6, 2017 at 9:05 AM, Dirk Behme <dirk.behme@de.bosch.com> wrote:
> From: Hiromitsu Yamasaki <hiromitsu.yamasaki.ym@renesas.com>
>
> When Tx DMA is only used, Tx FIFO is still not empty after DMA callback.
> This patch waits for sweeping data out of the Tx FIFO.
>
> Signed-off-by: Hiromitsu Yamasaki <hiromitsu.yamasaki.ym@renesas.com>
> [adjust context]
> Signed-off-by: Dirk Behme <dirk.behme@de.bosch.com>
> ---
>  drivers/spi/spi-sh-msiof.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
> index 660b03ed6770..a960e8da123d 100644
> --- a/drivers/spi/spi-sh-msiof.c
> +++ b/drivers/spi/spi-sh-msiof.c
> @@ -638,6 +638,17 @@ static int sh_msiof_wait_for_completion(struct sh_msiof_spi_priv *p,
>                                 dev_err(&p->pdev->dev, "Tx DMA timeout\n");
>                                 return -ETIMEDOUT;
>                         }
> +                       if (!rx) {

May the issue also happen is TX and RX are used?
See also "[PATCH 4/8] spi: sh-msiof: Fix DMA completion".

> +                               sh_msiof_write(p, IER, IER_TEOFE);
> +
> +                               /* wait for tx fifo to be emptied */
> +                               if (!wait_for_completion_timeout(&p->done,
> +                                                                HZ)) {
> +                                       dev_err(&p->pdev->dev,
> +                                       "Tx fifo to be emptied timeout\n");
> +                                       return -ETIMEDOUT;
> +                               }
> +                       }
>                 }
>                 if (rx) {
>                         if (!wait_for_completion_timeout(&p->done_dma_rx,

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
diff mbox

Patch

diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c
index 660b03ed6770..a960e8da123d 100644
--- a/drivers/spi/spi-sh-msiof.c
+++ b/drivers/spi/spi-sh-msiof.c
@@ -638,6 +638,17 @@  static int sh_msiof_wait_for_completion(struct sh_msiof_spi_priv *p,
 				dev_err(&p->pdev->dev, "Tx DMA timeout\n");
 				return -ETIMEDOUT;
 			}
+			if (!rx) {
+				sh_msiof_write(p, IER, IER_TEOFE);
+
+				/* wait for tx fifo to be emptied */
+				if (!wait_for_completion_timeout(&p->done,
+								 HZ)) {
+					dev_err(&p->pdev->dev,
+					"Tx fifo to be emptied timeout\n");
+					return -ETIMEDOUT;
+				}
+			}
 		}
 		if (rx) {
 			if (!wait_for_completion_timeout(&p->done_dma_rx,
@@ -805,7 +816,7 @@  static int sh_msiof_dma_once(struct sh_msiof_spi_priv *p, const void *tx,
 		goto stop_dma;
 	}
 
-	/* wait for tx fifo to be emptied / rx fifo to be filled */
+	/* wait for Tx/Rx DMA completion */
 	ret = sh_msiof_wait_for_completion(p, tx, rx);
 	if (ret)
 		goto stop_reset;