summaryrefslogtreecommitdiffstats
path: root/drivers/mtd/spi/spi_flash.c
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2011-01-10 02:20:12 -0500
committerWolfgang Denk <wd@denx.de>2011-04-11 21:00:53 +0200
commit6163045bcd276818d9ad6bdd1bf36ddcd60d014b (patch)
tree732ba3dd3b07977e38c773960dfb76c78ee4ab09 /drivers/mtd/spi/spi_flash.c
parent000044d8bfdc803a1a97e68ba95f289bfe5ad149 (diff)
downloadblackbird-obmc-uboot-6163045bcd276818d9ad6bdd1bf36ddcd60d014b.tar.gz
blackbird-obmc-uboot-6163045bcd276818d9ad6bdd1bf36ddcd60d014b.zip
sf: unify status polling for ready bit
All of the spi flash drivers implement the status register polling for detecting the device ready state, so unify them all in a new helper function -- spi_flash_wait_ready. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'drivers/mtd/spi/spi_flash.c')
-rw-r--r--drivers/mtd/spi/spi_flash.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index 2b7f22c599..e483ce4af3 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -69,6 +69,47 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
return ret;
}
+int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
+ u8 cmd, u8 poll_bit)
+{
+ struct spi_slave *spi = flash->spi;
+ unsigned long timebase;
+ int ret;
+ u8 status;
+
+ ret = spi_xfer(spi, 8, &cmd, NULL, SPI_XFER_BEGIN);
+ if (ret) {
+ debug("SF: Failed to send command %02x: %d\n", cmd, ret);
+ return ret;
+ }
+
+ timebase = get_timer(0);
+ do {
+ ret = spi_xfer(spi, 8, NULL, &status, 0);
+ if (ret)
+ return -1;
+
+ if ((status & poll_bit) == 0)
+ break;
+
+ } while (get_timer(timebase) < timeout);
+
+ spi_xfer(spi, 0, NULL, NULL, SPI_XFER_END);
+
+ if ((status & poll_bit) == 0)
+ return 0;
+
+ /* Timed out */
+ debug("SF: time out!\n");
+ return -1;
+}
+
+int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
+{
+ return spi_flash_cmd_poll_bit(flash, timeout,
+ CMD_READ_STATUS, STATUS_WIP);
+}
+
/*
* The following table holds all device probe functions
*
OpenPOWER on IntegriCloud