STMICRO parts such as M25PX64 and SST parts such as SST26VF032B support
a single status register protect bit. When set this bit cause writes to
the status register to be blocked when the write protect signal is low.

Implement sr_protect for these devices.

Signed-off-by: George McCollister <george.mccollis...@gmail.com>
---
 drivers/mtd/spi/sf_internal.h |  1 +
 drivers/mtd/spi/spi_flash.c   | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h
index cde4cfb..1b576e8 100644
--- a/drivers/mtd/spi/sf_internal.h
+++ b/drivers/mtd/spi/sf_internal.h
@@ -81,6 +81,7 @@ enum spi_nor_option_flags {
 #define SR_BP0                         BIT(2)  /* Block protect 0 */
 #define SR_BP1                         BIT(3)  /* Block protect 1 */
 #define SR_BP2                         BIT(4)  /* Block protect 2 */
+#define SR_SRP0                                BIT(7)  /* Status register 
protect 0 */
 
 /* Flash timeout values */
 #define SPI_FLASH_PROG_TIMEOUT         (2 * CONFIG_SYS_HZ)
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index 7f6e9ae..0e33901 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -837,6 +837,40 @@ int stm_unlock(struct spi_flash *flash, u32 ofs, size_t 
len)
 
        return 0;
 }
+
+/*
+ * Set status register protection method for parts with one protection bit
+ *
+ * Returns negative on errors, 0 on success.
+ */
+int stm_sr_protect(struct spi_flash *flash, enum srp_method method)
+{
+       uint8_t status_old, status_new;
+       u8 mask = SR_SRP0;
+       u8 val;
+       int ret;
+
+       ret = read_sr(flash, &status_old);
+       if (ret < 0)
+               return ret;
+
+       switch (method) {
+       case SRP_SOFTWARE:
+               val = 0;
+               break;
+       case SRP_HARDWARE:
+               val = SR_SRP0;
+               break;
+       default:
+               return -EOPNOTSUPP;
+       }
+
+       status_new = (status_old & ~mask) | val;
+
+       write_sr(flash, status_new);
+
+       return 0;
+}
 #endif
 
 
@@ -1125,6 +1159,7 @@ int spi_flash_scan(struct spi_flash *flash)
                flash->flash_lock = stm_lock;
                flash->flash_unlock = stm_unlock;
                flash->flash_is_locked = stm_is_locked;
+               flash->sr_protect = stm_sr_protect;
 #endif
                break;
        default:
-- 
2.9.3

_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to