mtd: spi-nor: wait until lock/unlock operations are ready
authorEzequiel García <ezequiel@vanguardiasur.com.ar>
Mon, 28 Dec 2015 20:54:51 +0000 (17:54 -0300)
committerBrian Norris <computersforpeace@gmail.com>
Thu, 7 Jan 2016 01:18:34 +0000 (17:18 -0800)
On Micron and Numonyx devices, the status register write command
(WRSR), raises a work-in-progress bit (WIP) on the status register.
The datasheets for these devices specify that while the status
register write is in progress, the status register WIP bit can still
be read to check the end of the operation.

This commit adds a wait_till_ready call on lock/unlock operations,
which is required for Micron and Numonyx but should be harmless for
others. This is needed to prevent applications from issuing erase or
program operations before the unlock operation is completed.

Reported-by: Stas Sergeev <stsp@list.ru>
Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
drivers/mtd/spi-nor/spi-nor.c

index f8f36d47575f138d751b38935921a95aa30ab686..ed0c19c558b5e73be3846ebbbcb0f455de60239b 100644 (file)
@@ -481,6 +481,7 @@ static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
        int status_old, status_new;
        u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
        u8 shift = ffs(mask) - 1, pow, val;
+       int ret;
 
        status_old = read_sr(nor);
        if (status_old < 0)
@@ -519,7 +520,10 @@ static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
                return -EINVAL;
 
        write_enable(nor);
-       return write_sr(nor, status_new);
+       ret = write_sr(nor, status_new);
+       if (ret)
+               return ret;
+       return spi_nor_wait_till_ready(nor);
 }
 
 /*
@@ -533,6 +537,7 @@ static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
        int status_old, status_new;
        u8 mask = SR_BP2 | SR_BP1 | SR_BP0;
        u8 shift = ffs(mask) - 1, pow, val;
+       int ret;
 
        status_old = read_sr(nor);
        if (status_old < 0)
@@ -569,7 +574,10 @@ static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
                return -EINVAL;
 
        write_enable(nor);
-       return write_sr(nor, status_new);
+       ret = write_sr(nor, status_new);
+       if (ret)
+               return ret;
+       return spi_nor_wait_till_ready(nor);
 }
 
 /*
This page took 0.026061 seconds and 5 git commands to generate.