diff mbox

[U-Boot,1/5] sf: Add status register protection mechanism

Message ID 20161010185801.27991-2-george.mccollister@gmail.com
State Deferred
Delegated to: Jagannadha Sutradharudu Teki
Headers show

Commit Message

George McCollister Oct. 10, 2016, 6:57 p.m. UTC
Many SPI NOR flash devices support status register protection through
one or two status register protection bits. Status register protection
enables protection of block protect and other bits from manipulation.

So far, four different status register protection methods have been
observed:

 Software         - Writes to the status register are blocked until
                    a write enable bit is set by software.
 Hardware         - Writes to the status register are blocked while
                    a pin is in a certain state.
 Power            - Writes to the status register are blocked until
                    the next power-down.
 One Time Program - Writes to the status register are permanently
                    blocked.

Signed-off-by: George McCollister <george.mccollister@gmail.com>
---
 include/spi_flash.h | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

Comments

Bin Meng Oct. 11, 2016, 2:05 a.m. UTC | #1
On Tue, Oct 11, 2016 at 2:57 AM, George McCollister
<george.mccollister@gmail.com> wrote:
> Many SPI NOR flash devices support status register protection through
> one or two status register protection bits. Status register protection
> enables protection of block protect and other bits from manipulation.
>
> So far, four different status register protection methods have been
> observed:
>
>  Software         - Writes to the status register are blocked until
>                     a write enable bit is set by software.
>  Hardware         - Writes to the status register are blocked while
>                     a pin is in a certain state.
>  Power            - Writes to the status register are blocked until
>                     the next power-down.
>  One Time Program - Writes to the status register are permanently
>                     blocked.
>
> Signed-off-by: George McCollister <george.mccollister@gmail.com>
> ---
>  include/spi_flash.h | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
diff mbox

Patch

diff --git a/include/spi_flash.h b/include/spi_flash.h
index be2fe3f..d1f63c7 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -26,6 +26,13 @@ 
 # define CONFIG_SF_DEFAULT_BUS		0
 #endif
 
+enum srp_method {
+	SRP_SOFTWARE,
+	SRP_HARDWARE,
+	SRP_POWER,
+	SRP_OTP,
+};
+
 struct spi_slave;
 
 /**
@@ -89,6 +96,7 @@  struct spi_flash {
 	int (*flash_lock)(struct spi_flash *flash, u32 ofs, size_t len);
 	int (*flash_unlock)(struct spi_flash *flash, u32 ofs, size_t len);
 	int (*flash_is_locked)(struct spi_flash *flash, u32 ofs, size_t len);
+	int (*sr_protect)(struct spi_flash *flash, enum srp_method method);
 #ifndef CONFIG_DM_SPI_FLASH
 	/*
 	 * These are not strictly needed for driver model, but keep them here
@@ -239,4 +247,13 @@  static inline int spi_flash_protect(struct spi_flash *flash, u32 ofs, u32 len,
 		return flash->flash_unlock(flash, ofs, len);
 }
 
+static inline int spi_flash_sr_protect(struct spi_flash *flash,
+		enum srp_method method)
+{
+	if (!flash->sr_protect)
+		return -EOPNOTSUPP;
+
+	return flash->sr_protect(flash, method);
+}
+
 #endif /* _SPI_FLASH_H_ */