diff options
author | Jun Lin <CHLin56@nuvoton.com> | 2021-11-09 11:33:51 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-11-12 23:40:38 +0000 |
commit | 08f4749d6a5c154b4e0870cf0be45652d0040495 (patch) | |
tree | 0e075332c32453292f09e9d01d0e46c1cdf0b713 | |
parent | d214c6b3dc06e1ff4c11438f2420a1d29bc35ee8 (diff) | |
download | chrome-ec-08f4749d6a5c154b4e0870cf0be45652d0040495.tar.gz |
zephyr: flash: npcx: Refactor flash_get_status()
NPCX internal flash status register 1/2 are always read at the same
time. This CL merges flash_get_status1() and flash_get_status2() into
one function. This improves the performance by eliminating duplicate
mutex function call operations.
This change aligns with the change in the CL:3247742 of ECOS.
BUG=none
BRANCH=none
TEST=write status1/2 registers with different values, read them back
with console command "flashchip"
Signed-off-by: Jun Lin <CHLin56@nuvoton.com>
Change-Id: I414424401df22eaa577d3e5238cdeae06eb5e61d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3268036
Tested-by: CH Lin <chlin56@nuvoton.com>
Reviewed-by: Keith Short <keithshort@chromium.org>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Commit-Queue: Keith Short <keithshort@chromium.org>
-rw-r--r-- | zephyr/drivers/cros_flash/cros_flash_npcx.c | 51 |
1 files changed, 16 insertions, 35 deletions
diff --git a/zephyr/drivers/cros_flash/cros_flash_npcx.c b/zephyr/drivers/cros_flash/cros_flash_npcx.c index 902117d4c1..45bc7f1b90 100644 --- a/zephyr/drivers/cros_flash/cros_flash_npcx.c +++ b/zephyr/drivers/cros_flash/cros_flash_npcx.c @@ -222,40 +222,25 @@ static int cros_flash_npcx_uma_lock(const struct device *dev, bool enable) return spi_transceive(data->spi_ctrl_dev, &spi_cfg, NULL, NULL); } -static int flash_get_status1(const struct device *dev) +static void flash_get_status(const struct device *dev, uint8_t *sr1, + uint8_t *sr2) { - uint8_t reg; - - if (all_protected) - return saved_sr1; - - /* Lock physical flash operations */ - crec_flash_lock_mapped_storage(1); - - cros_flash_npcx_get_status_reg(dev, SPI_NOR_CMD_RDSR, ®); - - /* Unlock physical flash operations */ - crec_flash_lock_mapped_storage(0); - - return reg; -} - -static int flash_get_status2(const struct device *dev) -{ - uint8_t reg; - - if (all_protected) - return saved_sr1; + if (all_protected) { + *sr1 = saved_sr1; + *sr2 = saved_sr2; + return; + } /* Lock physical flash operations */ crec_flash_lock_mapped_storage(1); - cros_flash_npcx_get_status_reg(dev, SPI_NOR_CMD_RDSR2, ®); + /* Read status register1 */ + cros_flash_npcx_get_status_reg(dev, SPI_NOR_CMD_RDSR, sr1); + /* Read status register2 */ + cros_flash_npcx_get_status_reg(dev, SPI_NOR_CMD_RDSR2, sr2); /* Unlock physical flash operations */ crec_flash_lock_mapped_storage(0); - - return reg; } static int flash_write_status_reg(const struct device *dev, uint8_t *data) @@ -285,8 +270,7 @@ static void flash_uma_lock(const struct device *dev, int enable) * Store SR1 / SR2 for later use since we're about to lock * out all access (including read access) to these regs. */ - saved_sr1 = flash_get_status1(dev); - saved_sr2 = flash_get_status2(dev); + flash_get_status(dev, &saved_sr1, &saved_sr2); } cros_flash_npcx_uma_lock(dev, enable); @@ -355,14 +339,12 @@ static int flash_check_prot_reg(const struct device *dev, unsigned int offset, flash_protect_int_flash(dev, !gpio_get_level(GPIO_WP_L)); #endif /* CONFIG_WP_ACTIVE_HIGH */ - sr1 = flash_get_status1(dev); - sr2 = flash_get_status2(dev); - /* Invalid value */ if (offset + bytes > CONFIG_FLASH_SIZE_BYTES) return EC_ERROR_INVAL; /* Compute current protect range */ + flash_get_status(dev, &sr1, &sr2); rv = spi_flash_reg_to_protect(sr1, sr2, &start, &len); if (rv) return rv; @@ -378,14 +360,14 @@ static int flash_write_prot_reg(const struct device *dev, unsigned int offset, unsigned int bytes, int hw_protect) { int rv; - uint8_t sr1 = flash_get_status1(dev); - uint8_t sr2 = flash_get_status2(dev); + uint8_t sr1, sr2; /* Invalid values */ if (offset + bytes > CONFIG_FLASH_SIZE_BYTES) return EC_ERROR_INVAL; /* Compute desired protect range */ + flash_get_status(dev, &sr1, &sr2); rv = spi_flash_protect_to_reg(offset, bytes, &sr1, &sr2); if (rv) return rv; @@ -585,8 +567,7 @@ static int cros_flash_npcx_get_jedec_id(const struct device *dev, static int cros_flash_npcx_get_status(const struct device *dev, uint8_t *sr1, uint8_t *sr2) { - *sr1 = flash_get_status1(dev); - *sr2 = flash_get_status2(dev); + flash_get_status(dev, sr1, sr2); return EC_SUCCESS; } |