summaryrefslogtreecommitdiff
path: root/drivers/spi
diff options
context:
space:
mode:
authorMarek Vasut <marex@denx.de>2014-10-22 21:56:01 +0200
committerJagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>2014-10-27 22:37:03 +0530
commit80d73338080c83e17fbf3f844052ec71d03ecd13 (patch)
tree636e9c4eefe012c66d1072e1fc80f82e4115a978 /drivers/spi
parent37dcc130e0c804da6ad50bf273d0d737cfe9cf8f (diff)
downloadu-boot-imx-80d73338080c83e17fbf3f844052ec71d03ecd13.zip
u-boot-imx-80d73338080c83e17fbf3f844052ec71d03ecd13.tar.gz
u-boot-imx-80d73338080c83e17fbf3f844052ec71d03ecd13.tar.bz2
spi: altera: Zap endless loop
The driver contained an endless loop when waiting for TX completion, this is a bad idea since if the hardware fails, the loop might spin forever. Add timeout and handle it. Signed-off-by: Marek Vasut <marex@denx.de> Cc: Chin Liang See <clsee@altera.com> Cc: Dinh Nguyen <dinguyen@altera.com> Cc: Albert Aribaud <albert.u.boot@aribaud.net> Cc: Pavel Machek <pavel@denx.de> Cc: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com> Acked-by: Pavel Machek <pavel@denx.de> Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
Diffstat (limited to 'drivers/spi')
-rw-r--r--drivers/spi/altera_spi.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/drivers/spi/altera_spi.c b/drivers/spi/altera_spi.c
index 373ce30..8e898b9 100644
--- a/drivers/spi/altera_spi.c
+++ b/drivers/spi/altera_spi.c
@@ -129,6 +129,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
uint bytes = bitlen / 8;
const uchar *txp = dout;
uchar *rxp = din;
+ uint32_t reg, start;
debug("%s: bus:%i cs:%i bitlen:%i bytes:%i flags:%lx\n", __func__,
slave->bus, slave->cs, bitlen, bytes, flags);
@@ -154,8 +155,16 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
debug("%s: tx:%x ", __func__, d);
writel(d, &altspi->regs->txdata);
- while (!(readl(&altspi->regs->status) & ALTERA_SPI_STATUS_RRDY_MSK))
- ;
+ start = get_timer(0);
+ while (1) {
+ reg = readl(&altspi->regs->status);
+ if (reg & ALTERA_SPI_STATUS_RRDY_MSK)
+ break;
+ if (get_timer(start) > (CONFIG_SYS_HZ / 1000)) {
+ printf("%s: Transmission timed out!\n", __func__);
+ goto done;
+ }
+ }
d = readl(&altspi->regs->rxdata);
if (rxp)