spi: sh_qspi: Replace ad hoc waiting with wait_for_bit
authorMarek Vasut <marek.vasut+renesas@gmail.com>
Tue, 10 Apr 2018 14:58:46 +0000 (16:58 +0200)
committerMarek Vasut <marex@denx.de>
Wed, 11 Apr 2018 21:19:51 +0000 (23:19 +0200)
Replace the ad-hoc endless loops with wait_for_bit() with
reasonable timeout. Note that the loops had internal 10uS
delays, although there is no reason for those on this HW,
so they are dropped.

Signed-off-by: Marek Vasut <marek.vasut+renesas@gmail.com>
Cc: Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
drivers/spi/sh_qspi.c

index 8eaa6744ccf3cb9be57370a49c372ace57520f32..d7f558a54126291799c7e2f89ac9e6104a0c5dee 100644 (file)
@@ -11,6 +11,7 @@
 #include <console.h>
 #include <malloc.h>
 #include <spi.h>
+#include <wait_bit.h>
 #include <asm/arch/rmobile.h>
 #include <asm/io.h>
 
@@ -236,23 +237,17 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
                rdata = din;
 
        while (nbyte > 0) {
-               while (!(readb(&ss->regs->spsr) & SPSR_SPTEF)) {
-                       if (ctrlc()) {
-                               puts("abort\n");
-                               return 1;
-                       }
-                       udelay(10);
-               }
+               ret = wait_for_bit_8(&ss->regs->spsr, SPSR_SPTEF,
+                                    true, 1000, true);
+               if (ret)
+                       return ret;
 
                writeb(*tdata, (u8 *)(&ss->regs->spdr));
 
-               while (!(readb(&ss->regs->spsr) & SPSR_SPRFF)) {
-                       if (ctrlc()) {
-                               puts("abort\n");
-                               return 1;
-                       }
-                       udelay(10);
-               }
+               ret = wait_for_bit_8(&ss->regs->spsr, SPSR_SPRFF,
+                                    true, 1000, true);
+               if (ret)
+                       return ret;
 
                *rdata = readb((u8 *)(&ss->regs->spdr));