From: Marek Vasut Date: Tue, 10 Apr 2018 17:15:39 +0200 Subject: [U-Boot] [PATCH 3/4] spi: sh_qspi: Replace ad hoc waiting with wait_for_bit In-Reply-To: <20180410151540.12103-1-marek.vasut+renesas@gmail.com> References: <20180410151540.12103-1-marek.vasut+renesas@gmail.com> Message-ID: <20180410151540.12103-3-marek.vasut+renesas@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 Cc: Nobuhiro Iwamatsu --- drivers/spi/sh_qspi.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/drivers/spi/sh_qspi.c b/drivers/spi/sh_qspi.c index 8eaa6744cc..d7f558a541 100644 --- a/drivers/spi/sh_qspi.c +++ b/drivers/spi/sh_qspi.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -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)); -- 2.16.2