diff mbox series

[U-Boot,1/2] drivers/spi: fsl_qspi: fix read timeout

Message ID 20190701153735.170-2-thomas.schaefer@kontron.com
State Accepted
Commit c6d0c5eb30b5d677a6eeca5079a4e9a27630b530
Delegated to: Jagannadha Sutradharudu Teki
Headers show
Series [U-Boot,1/2] drivers/spi: fsl_qspi: fix read timeout | expand

Commit Message

Thomas Schaefer July 1, 2019, 3:37 p.m. UTC
During QSPI reads, current is_controller_busy function sporadically
fails with -ETIMEDOUT due to fixed number of 5 test loops. Using
timer functions to wait 1000 us instead will fix this.

Signed-off-by: Thomas Schaefer <thomas.schaefer@kontron.com>
---
 drivers/spi/fsl_qspi.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

Comments

Fabio Estevam July 1, 2019, 3:40 p.m. UTC | #1
On Mon, Jul 1, 2019 at 12:38 PM Thomas Schaefer
<thomas.schaefer@kontron.com> wrote:
>
> During QSPI reads, current is_controller_busy function sporadically
> fails with -ETIMEDOUT due to fixed number of 5 test loops. Using
> timer functions to wait 1000 us instead will fix this.
>
> Signed-off-by: Thomas Schaefer <thomas.schaefer@kontron.com>

Thanks for the fix:

Reviewed-by: Fabio Estevam <festevam@gmail.com>
Jagan Teki July 2, 2019, 11:01 a.m. UTC | #2
On Mon, Jul 1, 2019 at 9:08 PM Thomas Schaefer
<thomas.schaefer@kontron.com> wrote:
>
> During QSPI reads, current is_controller_busy function sporadically
> fails with -ETIMEDOUT due to fixed number of 5 test loops. Using
> timer functions to wait 1000 us instead will fix this.
>
> Signed-off-by: Thomas Schaefer <thomas.schaefer@kontron.com>
> ---

Applied to u-boot-spi/master
diff mbox series

Patch

diff --git a/drivers/spi/fsl_qspi.c b/drivers/spi/fsl_qspi.c
index 1598c4f698..2c5937509f 100644
--- a/drivers/spi/fsl_qspi.c
+++ b/drivers/spi/fsl_qspi.c
@@ -152,7 +152,7 @@  static inline int is_controller_busy(const struct fsl_qspi_priv *priv)
 	u32 val;
 	const u32 mask = QSPI_SR_BUSY_MASK | QSPI_SR_AHB_ACC_MASK |
 			 QSPI_SR_IP_ACC_MASK;
-	unsigned int retry = 5;
+	unsigned long timeout = timer_get_us() + 1000;
 
 	do {
 		val = qspi_read32(priv->flags, &priv->regs->sr);
@@ -160,10 +160,9 @@  static inline int is_controller_busy(const struct fsl_qspi_priv *priv)
 		if ((~val & mask) == mask)
 			return 0;
 
-		udelay(1);
-	} while (--retry);
-
-	return -ETIMEDOUT;
+		if (timer_get_us() > timeout )
+			return -ETIMEDOUT;
+	} while (1);
 }
 
 /* QSPI support swapping the flash read/write data