From 0f8bf022fca97659efef400794d38ec0d1f48d2b Mon Sep 17 00:00:00 2001 From: Patrick Rudolph Date: Fri, 9 Mar 2018 14:20:25 +0100 Subject: drivers/spi: Read Winbond's flash protection bits Extend the generic flash interface to probe for write protected regions. Add Winbond custom code to return flash protection. Tested on Cavium EVB CN81xx using W25Q128. Change-Id: I933a8abdc28174ec32acf323c102d606b58c1ea5 Signed-off-by: Patrick Rudolph Reviewed-on: https://review.coreboot.org/25082 Reviewed-by: Julius Werner Tested-by: build bot (Jenkins) --- src/drivers/spi/spi_flash.c | 22 ++++++++++++++++++++++ 1 file changed, 22 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 f2714791db..c4840886bb 100644 --- a/src/drivers/spi/spi_flash.c +++ b/src/drivers/spi/spi_flash.c @@ -432,6 +432,28 @@ int spi_flash_status(const struct spi_flash *flash, u8 *reg) return -1; } +int spi_flash_is_write_protected(const struct spi_flash *flash, + const struct region *region) +{ + struct region flash_region = { 0 }; + + if (!flash || !region) + return -1; + + flash_region.size = flash->size; + + if (!region_is_subregion(&flash_region, region)) + return -1; + + if (!flash->ops->get_write_protection) { + printk(BIOS_WARNING, "SPI: Write-protection gathering not " + "implemented for this vendor.\n"); + return 0; + } + + return flash->ops->get_write_protection(flash, region); +} + static uint32_t volatile_group_count CAR_GLOBAL; int spi_flash_volatile_group_begin(const struct spi_flash *flash) -- cgit v1.2.3