From mboxrd@z Thu Jan 1 00:00:00 1970 From: George McCollister Date: Mon, 10 Oct 2016 13:57:58 -0500 Subject: [U-Boot] [PATCH 2/5] sf: Add status register protect for STMICRO, SST In-Reply-To: <20161010185801.27991-1-george.mccollister@gmail.com> References: <20161010185801.27991-1-george.mccollister@gmail.com> Message-ID: <20161010185801.27991-3-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 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 --- 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