]> git.sur5r.net Git - u-boot/commitdiff
sf: Add flag status register polling support
authorJagannadha Sutradharudu Teki <jaganna@xilinx.com>
Fri, 21 Jun 2013 10:26:30 +0000 (15:56 +0530)
committerJagannadha Sutradharudu Teki <jaganna@xilinx.com>
Sun, 23 Jun 2013 16:32:51 +0000 (22:02 +0530)
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 in 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>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/mtd/spi/spi_flash.c
drivers/mtd/spi/spi_flash_internal.h
drivers/mtd/spi/stmicro.c
include/spi_flash.h

index cca02d13bc1def49f83693b192f118a25a8d5eb2..6ce82c1cbe09813af5e71a23bb5c3aff4d72e502 100644 (file)
@@ -200,12 +200,19 @@ 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;
+       u8 cmd = flash->poll_cmd;
+
+       if (cmd == CMD_FLAG_STATUS) {
+               poll_bit = STATUS_PEC;
+               check_status = poll_bit;
+       }
 
        ret = spi_xfer(spi, 8, &cmd, NULL, SPI_XFER_BEGIN);
        if (ret) {
-               debug("SF: Failed to send command %02x: %d\n", cmd, ret);
+               debug("SF: fail to read %s status register\n",
+                       cmd == CMD_READ_STATUS ? "read" : "flag");
                return ret;
        }
 
@@ -217,14 +224,14 @@ int spi_flash_cmd_wait_ready(struct spi_flash *flash, unsigned long timeout)
                if (ret)
                        return -1;
 
-               if ((status & poll_bit) == 0)
+               if ((status & poll_bit) == check_status)
                        break;
 
        } while (get_timer(timebase) < timeout);
 
        spi_xfer(spi, 0, NULL, NULL, SPI_XFER_END);
 
-       if ((status & poll_bit) == 0)
+       if ((status & poll_bit) == check_status)
                return 0;
 
        /* Timed out */
@@ -584,6 +591,7 @@ void *spi_flash_do_alloc(int offset, int size, struct spi_slave *spi,
        /* Set up some basic fields - caller will sort out sizes */
        flash->spi = spi;
        flash->name = name;
+       flash->poll_cmd = CMD_READ_STATUS;
 
        flash->read = spi_flash_cmd_read_fast;
        flash->write = spi_flash_cmd_write_multi;
index e9b85bfef7d96cb0c2a157880914161b4531fc7b..8147f27c1e4b5c855428c25a07b27440cd0c119b 100644 (file)
@@ -22,6 +22,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
@@ -45,6 +46,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);
index ef4b911da512467a96961d5d1c23363db565d7bf..7e41ee13219ba466cdad0f0d5934685cb7b34a29 100644 (file)
@@ -210,5 +210,9 @@ struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
        flash->sector_size = 256 * params->pages_per_sector;
        flash->size = flash->sector_size * params->nr_sectors;
 
+       /* for >= 512MiB flashes, use flag status instead of read_status */
+       if (flash->size >= 0x4000000)
+               flash->poll_cmd = CMD_FLAG_STATUS;
+
        return flash;
 }
index e22d698af425bd0ef6e06a73faee4a94bb2deecd..e80785f55ef578ac989ceef262391bb602abdcec 100644 (file)
@@ -46,6 +46,9 @@ struct spi_flash {
        /* Current flash bank */
        u8              bank_curr;
 #endif
+       /* Poll cmd - for flash erase/program */
+       u8              poll_cmd;
+
        void *memory_map;       /* Address of read-only SPI flash access */
        int             (*read)(struct spi_flash *flash, u32 offset,
                                size_t len, void *buf);