From mboxrd@z Thu Jan 1 00:00:00 1970 From: George McCollister Date: Mon, 10 Oct 2016 13:57:57 -0500 Subject: [U-Boot] [PATCH 1/5] sf: Add status register protection mechanism In-Reply-To: <20161010185801.27991-1-george.mccollister@gmail.com> References: <20161010185801.27991-1-george.mccollister@gmail.com> Message-ID: <20161010185801.27991-2-george.mccollister@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 --- include/spi_flash.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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_ */ -- 2.9.3