]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
sf: Add Flag status reg polling support
authorJagannadha Sutradharudu Teki <jaganna@xilinx.com>
Wed, 15 May 2013 18:06:06 +0000 (23:36 +0530)
committerMichal Simek <michal.simek@xilinx.com>
Mon, 27 May 2013 11:21:19 +0000 (13:21 +0200)
Flag status register polling is required for micron 512Mb flash
devices onwards, for performing erase/program operations.

Like polling for WIP(Write-In-Progress) bit n read status register,
spi_flash_cmd_wait_ready will poll for PEC(Program-Erase-Control)
bit in flag status register.

Signed-off-by: Jagannadha Sutradharudu Teki <jaganna@xilinx.com>
drivers/mtd/spi/spi_flash.c
drivers/mtd/spi/spi_flash_internal.h

index 99e9f8e3cd251bab5d3f01b1325d41dfd6b6a02a..763c22a7e2b746fc4cff546b442b969f276aa531 100644 (file)
@@ -237,25 +237,34 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
        unsigned long timebase;
        int ret;
        u8 status;
+       u8 check_status = 0x0;
        u8 poll_bit = STATUS_WIP;
        u8 cmd = CMD_READ_STATUS;
 
+       if ((flash->idcode0 == 0x20) &&
+                       (flash->size >= SPI_FLASH_512MB_MIC)) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+               cmd = CMD_FLAG_STATUS;
+       }
+
        timebase = get_timer(0);
        do {
                WATCHDOG_RESET();
 
                ret = spi_flash_read_common(flash, &cmd, 1, &status, 1);
                if (ret < 0) {
-                       debug("SF: fail to read read status register\n");
+                       debug("SF: fail to read %s status register\n",
+                               cmd == CMD_READ_STATUS ? "read" : "flag");
                        return ret;
                }
 
-               if ((status & poll_bit) == 0)
+               if ((status & poll_bit) == check_status)
                        break;
 
        } while (get_timer(timebase) < timeout);
 
-       if ((status & poll_bit) == 0)
+       if ((status & poll_bit) == check_status)
                return 0;
 
        /* Timed out */
index 021d00976a7c51c66cc3bf443047c46b15e5df2a..b669e61a96dd7a671c43d3bd910deb308b20f973 100644 (file)
@@ -14,6 +14,7 @@
 
 #define SPI_FLASH_16MB_BOUN            0x1000000
 #define SPI_FLASH_16MB_MASK            0xFFFFFF
+#define SPI_FLASH_512MB_MIC            0x4000000
 
 /* Common commands */
 #define CMD_READ_ID                    0x9f
@@ -25,6 +26,7 @@
 #define CMD_PAGE_PROGRAM               0x02
 #define CMD_WRITE_DISABLE              0x04
 #define CMD_READ_STATUS                        0x05
+#define CMD_FLAG_STATUS                        0x70
 #define CMD_WRITE_ENABLE               0x06
 #define CMD_ERASE_4K                   0x20
 #define CMD_ERASE_32K                  0x52
@@ -39,6 +41,7 @@
 
 /* Common status */
 #define STATUS_WIP                     0x01
+#define STATUS_PEC                     0x80
 
 /* Send a single-byte command to the device and read the response */
 int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, size_t len);