From e63a5f1e7f6e70cf3417332411fcce024afa390f Mon Sep 17 00:00:00 2001 From: Patrick Rudolph Date: Mon, 12 Mar 2018 11:34:53 +0100 Subject: 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 Reviewed-on: https://review.coreboot.org/25105 Tested-by: build bot (Jenkins) Reviewed-by: Philipp Deppenwiese --- src/drivers/spi/spi_flash.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'src/drivers/spi/spi_flash.c') 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) -- cgit v1.2.3