summaryrefslogtreecommitdiff
path: root/src/drivers/spi/spi_flash.c
diff options
context:
space:
mode:
authorPatrick Rudolph <patrick.rudolph@9elements.com>2018-03-12 11:34:53 +0100
committerPhilipp Deppenwiese <zaolin.daisuki@gmail.com>2018-10-30 12:15:57 +0000
commite63a5f1e7f6e70cf3417332411fcce024afa390f (patch)
tree906b7e35c715a93a22aa7fddddd39d325be46994 /src/drivers/spi/spi_flash.c
parent61322d7ad24ffcbd5b016da82c3fe2b804b611f7 (diff)
drivers/spi: Winbond specific write-protection enable
Extend the SPI interface to enable write-protection. Tested on Cavium EVB CN81xx using W25Q128. Change-Id: Ie3765b013855538eca37bc7800d3f9d5d09b8402 Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com> Reviewed-on: https://review.coreboot.org/25105 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Philipp Deppenwiese <zaolin.daisuki@gmail.com>
Diffstat (limited to 'src/drivers/spi/spi_flash.c')
-rw-r--r--src/drivers/spi/spi_flash.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/drivers/spi/spi_flash.c b/src/drivers/spi/spi_flash.c
index c4840886bb..cc21ccb20e 100644
--- a/src/drivers/spi/spi_flash.c
+++ b/src/drivers/spi/spi_flash.c
@@ -454,6 +454,55 @@ int spi_flash_is_write_protected(const struct spi_flash *flash,
return flash->ops->get_write_protection(flash, region);
}
+int spi_flash_set_write_protected(const struct spi_flash *flash,
+ const struct region *region,
+ const bool non_volatile,
+ const enum spi_flash_status_reg_lockdown mode)
+{
+ struct region flash_region = { 0 };
+ int ret;
+
+ if (!flash)
+ return -1;
+
+ flash_region.size = flash->size;
+
+ if (!region_is_subregion(&flash_region, region))
+ return -1;
+
+ if (!flash->ops->set_write_protection) {
+ printk(BIOS_WARNING, "SPI: Setting write-protection is not "
+ "implemented for this vendor.\n");
+ return 0;
+ }
+
+ ret = flash->ops->set_write_protection(flash, region, non_volatile,
+ mode);
+
+ if (ret == 0 && mode != SPI_WRITE_PROTECTION_PRESERVE) {
+ printk(BIOS_INFO, "SPI: SREG lock-down was set to ");
+ switch (mode) {
+ case SPI_WRITE_PROTECTION_NONE:
+ printk(BIOS_INFO, "NEVER\n");
+ break;
+ case SPI_WRITE_PROTECTION_PIN:
+ printk(BIOS_INFO, "WP\n");
+ break;
+ case SPI_WRITE_PROTECTION_REBOOT:
+ printk(BIOS_INFO, "REBOOT\n");
+ break;
+ case SPI_WRITE_PROTECTION_PERMANENT:
+ printk(BIOS_INFO, "PERMANENT\n");
+ break;
+ default:
+ printk(BIOS_INFO, "UNKNOWN\n");
+ break;
+ }
+ }
+
+ return ret;
+}
+
static uint32_t volatile_group_count CAR_GLOBAL;
int spi_flash_volatile_group_begin(const struct spi_flash *flash)