diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/drivers/spi/spi_flash.c | 9 | ||||
-rw-r--r-- | src/drivers/spi/winbond.c | 8 | ||||
-rw-r--r-- | src/include/spi_flash.h | 10 |
3 files changed, 18 insertions, 9 deletions
diff --git a/src/drivers/spi/spi_flash.c b/src/drivers/spi/spi_flash.c index 8f3a829e15..312f2f0817 100644 --- a/src/drivers/spi/spi_flash.c +++ b/src/drivers/spi/spi_flash.c @@ -520,13 +520,13 @@ int spi_flash_is_write_protected(const struct spi_flash *flash, if (!region_is_subregion(&flash_region, region)) return -1; - if (!flash->ops->get_write_protection) { + if (!flash->prot_ops) { printk(BIOS_WARNING, "SPI: Write-protection gathering not " "implemented for this vendor.\n"); return -1; } - return flash->ops->get_write_protection(flash, region); + return flash->prot_ops->get_write(flash, region); } int spi_flash_set_write_protected(const struct spi_flash *flash, @@ -545,14 +545,13 @@ int spi_flash_set_write_protected(const struct spi_flash *flash, if (!region_is_subregion(&flash_region, region)) return -1; - if (!flash->ops->set_write_protection) { + if (!flash->prot_ops) { printk(BIOS_WARNING, "SPI: Setting write-protection is not " "implemented for this vendor.\n"); return -1; } - ret = flash->ops->set_write_protection(flash, region, non_volatile, - mode); + ret = flash->prot_ops->set_write(flash, region, non_volatile, mode); if (ret == 0 && mode != SPI_WRITE_PROTECTION_PRESERVE) { printk(BIOS_INFO, "SPI: SREG lock-down was set to "); diff --git a/src/drivers/spi/winbond.c b/src/drivers/spi/winbond.c index 68cf1a3860..27aaae8440 100644 --- a/src/drivers/spi/winbond.c +++ b/src/drivers/spi/winbond.c @@ -615,8 +615,11 @@ static const struct spi_flash_ops spi_flash_ops = { .write = spi_flash_cmd_write_page_program, .erase = spi_flash_cmd_erase, .status = spi_flash_cmd_status, - .get_write_protection = winbond_get_write_protection, - .set_write_protection = winbond_set_write_protection, +}; + +static const struct spi_flash_protection_ops spi_flash_protection_ops = { + .get_write = winbond_get_write_protection, + .set_write = winbond_set_write_protection, }; int spi_flash_probe_winbond(const struct spi_slave *spi, u8 *idcode, @@ -655,6 +658,7 @@ int spi_flash_probe_winbond(const struct spi_slave *spi, u8 *idcode, flash->flags.dual_spi = params->dual_spi; flash->ops = &spi_flash_ops; + flash->prot_ops = &spi_flash_protection_ops; flash->driver_private = params; return 0; diff --git a/src/include/spi_flash.h b/src/include/spi_flash.h index 1a5a82934e..9c11433ff0 100644 --- a/src/include/spi_flash.h +++ b/src/include/spi_flash.h @@ -59,6 +59,10 @@ struct spi_flash_ops { const void *buf); int (*erase)(const struct spi_flash *flash, u32 offset, size_t len); int (*status)(const struct spi_flash *flash, u8 *reg); +}; + +/* Current code assumes all callbacks are supplied in this object. */ +struct spi_flash_protection_ops { /* * Returns 1 if the whole region is software write protected. * Hardware write protection mechanism aren't accounted. @@ -66,7 +70,7 @@ struct spi_flash_ops { * register for example, 0 should be returned. * Returns 0 on success. */ - int (*get_write_protection)(const struct spi_flash *flash, + int (*get_write)(const struct spi_flash *flash, const struct region *region); /* * Enable the status register write protection, if supported on the @@ -80,7 +84,7 @@ struct spi_flash_ops { * @return 0 on success */ int - (*set_write_protection)(const struct spi_flash *flash, + (*set_write)(const struct spi_flash *flash, const struct region *region, const bool non_volatile, const enum spi_flash_status_reg_lockdown mode); @@ -107,6 +111,8 @@ struct spi_flash { u8 pp_cmd; /* Page program command. */ u8 wren_cmd; /* Write Enable command. */ const struct spi_flash_ops *ops; + /* If !NULL all protection callbacks exist. */ + const struct spi_flash_protection_ops *prot_ops; const void *driver_private; }; |