From a01c368a8a55992600db34029b24d753d710b2a8 Mon Sep 17 00:00:00 2001 From: Subrata Banik Date: Thu, 26 Jun 2025 06:36:08 +0000 Subject: [PATCH] drivers/spi: Refactor 4-byte addressing mode handling in SPI flash This commit refactors the logic for entering and exiting 4-byte addressing mode in the SPI flash driver. Changes include: - Renaming SPI_FLASH_EXIT_4BYTE_STAGE to SPI_FIRST_STAGE to better reflect its broader applicability to initial boot stages. - Applying SPI_FIRST_STAGE to both the force 4-byte address mode and exit 4-byte address mode configurations, ensuring these operations are only attempted during the appropriate early boot phases. - Renaming CMD_FORCE_4BYTE_ADDR_MODE to CMD_ENTER_4BYTE_ADDR_MODE for consistency and clearer semantics, as 0xb7 is typically used to enter this mode. BUG=b:417900125 TEST=Able to build google/bluey. Change-Id: I79e2c7bbd222fd0d76072860bdf3feba7e7d587d Signed-off-by: Subrata Banik Reviewed-on: https://review.coreboot.org/c/coreboot/+/88203 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner --- src/drivers/spi/spi_flash.c | 10 +++++----- src/drivers/spi/spi_flash_internal.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/drivers/spi/spi_flash.c b/src/drivers/spi/spi_flash.c index 80e937a724..88ed2abda2 100644 --- a/src/drivers/spi/spi_flash.c +++ b/src/drivers/spi/spi_flash.c @@ -18,7 +18,7 @@ #define ADDR_MOD 0 #endif -#define SPI_FLASH_EXIT_4BYTE_STAGE \ +#define SPI_FIRST_STAGE \ (ENV_INITIAL_STAGE || CONFIG(BOOT_DEVICE_MEMORY_MAPPED)) static void spi_flash_addr(u32 addr, u8 *cmd) @@ -564,12 +564,12 @@ int spi_flash_probe(unsigned int bus, unsigned int cs, struct spi_flash *flash) CONFIG_ROM_SIZE); } - if (CONFIG(SPI_FLASH_FORCE_4_BYTE_ADDR_MODE)) { - printk(BIOS_DEBUG, "SF: Force 4-byte addressing mode\n"); - spi_flash_cmd(&flash->spi, CMD_FORCE_4BYTE_ADDR_MODE, NULL, 0); + if (CONFIG(SPI_FLASH_FORCE_4_BYTE_ADDR_MODE) && SPI_FIRST_STAGE) { + printk(BIOS_DEBUG, "SF: Entering 4-byte addressing mode\n"); + spi_flash_cmd(&flash->spi, CMD_ENTER_4BYTE_ADDR_MODE, NULL, 0); } - if (CONFIG(SPI_FLASH_EXIT_4_BYTE_ADDR_MODE) && SPI_FLASH_EXIT_4BYTE_STAGE) { + if (CONFIG(SPI_FLASH_EXIT_4_BYTE_ADDR_MODE) && SPI_FIRST_STAGE) { printk(BIOS_DEBUG, "SF: Exiting 4-byte addressing mode\n"); spi_flash_cmd(&flash->spi, CMD_EXIT_4BYTE_ADDR_MODE, NULL, 0); } diff --git a/src/drivers/spi/spi_flash_internal.h b/src/drivers/spi/spi_flash_internal.h index 163b6181b7..c20369cdf4 100644 --- a/src/drivers/spi/spi_flash_internal.h +++ b/src/drivers/spi/spi_flash_internal.h @@ -22,7 +22,7 @@ #define CMD_READ_STATUS 0x05 #define CMD_WRITE_ENABLE 0x06 -#define CMD_FORCE_4BYTE_ADDR_MODE 0xb7 +#define CMD_ENTER_4BYTE_ADDR_MODE 0xb7 #define CMD_BLOCK_ERASE 0xD8