From a6c73c898775bbc59b9d6e1fcb03e340db89ee67 Mon Sep 17 00:00:00 2001 From: Aaron Durbin Date: Sat, 11 Jan 2020 23:18:51 -0700 Subject: drivers/spi/spi_flash: introduce common spi_flash_part_id object To further drive to a common approach for describing the spi flash parts in the drivers add spi_flash_part_id object. All the drivers are updated to utilize the new object. Additionally, the driver_private is also not needed in the spi_flash object. A Chrome OS build of Aleena provides 960 byte saving of text. A subsequent patch will save more memory. Change-Id: I9c0cc75f188ac004ab647805b9551bf06a0c646b Signed-off-by: Aaron Durbin Reviewed-on: https://review.coreboot.org/c/coreboot/+/38378 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner --- src/drivers/spi/adesto.c | 99 +++++-------- src/drivers/spi/amic.c | 81 ++++------- src/drivers/spi/atmel.c | 69 +++------ src/drivers/spi/eon.c | 151 +++++++------------- src/drivers/spi/gigadevice.c | 132 ++++++----------- src/drivers/spi/macronix.c | 180 +++++++++-------------- src/drivers/spi/spansion.c | 218 ++++++++++------------------ src/drivers/spi/spi_flash_internal.h | 14 ++ src/drivers/spi/sst.c | 137 +++++++++--------- src/drivers/spi/stmicro.c | 269 +++++++++++++++-------------------- src/drivers/spi/winbond.c | 221 ++++++++++++---------------- src/include/spi_flash.h | 1 - 12 files changed, 608 insertions(+), 964 deletions(-) diff --git a/src/drivers/spi/adesto.c b/src/drivers/spi/adesto.c index fd3c0a2422..cfcde34a95 100644 --- a/src/drivers/spi/adesto.c +++ b/src/drivers/spi/adesto.c @@ -39,112 +39,78 @@ #define CMD_AT25DF_DP 0xb9 /* Deep Power-down */ #define CMD_AT25DF_RES 0xab /* Release from DP, and Read Signature */ -struct adesto_spi_flash_params { - uint16_t id; - /* Log2 of page size in power-of-two mode */ - uint8_t l2_page_size; - uint16_t pages_per_sector; - uint16_t sectors_per_block; - uint16_t nr_blocks; - const char *name; -}; - -static const struct adesto_spi_flash_params adesto_spi_flash_table[] = { +static const struct spi_flash_part_id flash_table[] = { { .id = 0x4218, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 256, .name = "AT25SL128A", + .nr_sectors_shift = 12, + .sector_size_kib_shift = 2, }, { .id = 0x4501, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 16, .name = "AT25DF081A", /* Yes, 81A id < 81 */ + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, }, { .id = 0x4502, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 16, .name = "AT25DF081", + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, }, { .id = 0x4602, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 32, .name = "AT25DF161", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { .id = 0x4603, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 32, .name = "AT25DL161", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { .id = 0x4700, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 64, .name = "AT25DF321", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, { .id = 0x4701, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 64, .name = "AT25DF321A", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, { .id = 0x4800, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 128, .name = "AT25DF641", + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, }, { .id = 0x8501, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 16, .name = "AT25SF081", + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, }, { .id = 0x8600, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 32, .name = "AT25DQ161", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { .id = 0x8601, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 32, .name = "AT25SF161", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { .id = 0x8700, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 64, .name = "AT25DQ321", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, }; @@ -158,16 +124,16 @@ static const struct spi_flash_ops spi_flash_ops = { int spi_flash_probe_adesto(const struct spi_slave *spi, u8 *idcode, struct spi_flash *flash) { - const struct adesto_spi_flash_params *params; + const struct spi_flash_part_id *params; unsigned int i; - for (i = 0; i < ARRAY_SIZE(adesto_spi_flash_table); i++) { - params = &adesto_spi_flash_table[i]; + for (i = 0; i < ARRAY_SIZE(flash_table); i++) { + params = &flash_table[i]; if (params->id == ((idcode[1] << 8) | idcode[2])) break; } - if (i == ARRAY_SIZE(adesto_spi_flash_table)) { + if (i == ARRAY_SIZE(flash_table)) { printk(BIOS_WARNING, "SF: Unsupported adesto ID %02x%02x\n", idcode[1], idcode[2]); return -1; @@ -176,10 +142,9 @@ int spi_flash_probe_adesto(const struct spi_slave *spi, u8 *idcode, memcpy(&flash->spi, spi, sizeof(*spi)); flash->name = params->name; /* Assuming power-of-two page size initially. */ - flash->page_size = 1 << params->l2_page_size; - flash->sector_size = flash->page_size * params->pages_per_sector; - flash->size = flash->sector_size *params->sectors_per_block * - params->nr_blocks; + flash->page_size = 256; + flash->sector_size = (1U << params->sector_size_kib_shift) * KiB; + flash->size = flash->sector_size * (1U << params->nr_sectors_shift); flash->erase_cmd = CMD_AT25DF_SE; flash->status_cmd = CMD_AT25DF_RDSR; flash->pp_cmd = CMD_AT25DF_PP; diff --git a/src/drivers/spi/amic.c b/src/drivers/spi/amic.c index e30ed4894d..fb5bdea27e 100644 --- a/src/drivers/spi/amic.c +++ b/src/drivers/spi/amic.c @@ -34,88 +34,60 @@ #define CMD_A25_DP 0xb9 /* Deep Power-down */ #define CMD_A25_RES 0xab /* Release from DP, and Read Signature */ -struct amic_spi_flash_params { - uint16_t id; - /* Log2 of page size in power-of-two mode */ - uint8_t l2_page_size; - uint16_t pages_per_sector; - uint16_t sectors_per_block; - uint16_t nr_blocks; - const char *name; -}; - -static const struct amic_spi_flash_params amic_spi_flash_table[] = { +static const struct spi_flash_part_id flash_table[] = { { .id = 0x2015, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 32, .name = "A25L16PU", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { .id = 0x2025, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 32, .name = "A25L16PT", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { .id = 0x3014, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 16, .name = "A25L080", + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, }, { .id = 0x3015, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 32, .name = "A25L016", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { .id = 0x3016, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 64, .name = "A25L032", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, { .id = 0x4014, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 16, .name = "A25LQ080", + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, }, { .id = 0x4015, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 32, .name = "A25LQ16", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { .id = 0x4016, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 64, .name = "A25LQ032", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, { .id = 0x4017, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 128, .name = "A25LQ64", + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, }, }; @@ -129,16 +101,16 @@ static const struct spi_flash_ops spi_flash_ops = { int spi_flash_probe_amic(const struct spi_slave *spi, u8 *idcode, struct spi_flash *flash) { - const struct amic_spi_flash_params *params; + const struct spi_flash_part_id *params; unsigned int i; - for (i = 0; i < ARRAY_SIZE(amic_spi_flash_table); i++) { - params = &amic_spi_flash_table[i]; + for (i = 0; i < ARRAY_SIZE(flash_table); i++) { + params = &flash_table[i]; if (params->id == ((idcode[1] << 8) | idcode[2])) break; } - if (i == ARRAY_SIZE(amic_spi_flash_table)) { + if (i == ARRAY_SIZE(flash_table)) { printk(BIOS_WARNING, "SF: Unsupported AMIC ID %02x%02x\n", idcode[1], idcode[2]); return -1; @@ -148,10 +120,9 @@ int spi_flash_probe_amic(const struct spi_slave *spi, u8 *idcode, flash->name = params->name; /* Assuming power-of-two page size initially. */ - flash->page_size = 1 << params->l2_page_size; - flash->sector_size = flash->page_size * params->pages_per_sector; - flash->size = flash->sector_size * params->sectors_per_block * - params->nr_blocks; + flash->page_size = 256; + flash->sector_size = (1U << params->sector_size_kib_shift) * KiB; + flash->size = flash->sector_size * (1U << params->nr_sectors_shift); flash->erase_cmd = CMD_A25_SE; flash->status_cmd = CMD_A25_RDSR; flash->pp_cmd = CMD_A25_PP; diff --git a/src/drivers/spi/atmel.c b/src/drivers/spi/atmel.c index ad9e75b4f3..a49484464e 100644 --- a/src/drivers/spi/atmel.c +++ b/src/drivers/spi/atmel.c @@ -34,72 +34,48 @@ #define CMD_AT25_DP 0xb9 /* Deep Power-down */ #define CMD_AT25_RES 0xab /* Release from DP, and Read Signature */ -struct atmel_spi_flash_params { - uint16_t id; - /* Log2 of page size in power-of-two mode */ - uint8_t l2_page_size; - uint16_t pages_per_sector; - uint16_t sectors_per_block; - uint16_t nr_blocks; - const char *name; -}; - -static const struct atmel_spi_flash_params atmel_spi_flash_table[] = { +static const struct spi_flash_part_id flash_table[] = { { .id = 0x3015, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 32, .name = "AT25X16", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { .id = 0x47, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 64, .name = "AT25DF32", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, { .id = 0x3017, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 128, .name = "AT25X64", + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, }, { .id = 0x4015, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 32, .name = "AT25Q16", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { .id = 0x4016, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 64, .name = "AT25Q32", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, { .id = 0x4017, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 128, .name = "AT25Q64", + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, }, { .id = 0x4018, - .l2_page_size = 8, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 256, .name = "AT25Q128", + .nr_sectors_shift = 12, + .sector_size_kib_shift = 2, }, }; @@ -113,16 +89,16 @@ static const struct spi_flash_ops spi_flash_ops = { int spi_flash_probe_atmel(const struct spi_slave *spi, u8 *idcode, struct spi_flash *flash) { - const struct atmel_spi_flash_params *params; + const struct spi_flash_part_id *params; unsigned int i; - for (i = 0; i < ARRAY_SIZE(atmel_spi_flash_table); i++) { - params = &atmel_spi_flash_table[i]; + for (i = 0; i < ARRAY_SIZE(flash_table); i++) { + params = &flash_table[i]; if (params->id == ((idcode[1] << 8) | idcode[2])) break; } - if (i == ARRAY_SIZE(atmel_spi_flash_table)) { + if (i == ARRAY_SIZE(flash_table)) { printk(BIOS_WARNING, "SF: Unsupported Atmel ID %02x%02x\n", idcode[1], idcode[2]); return -1; @@ -132,10 +108,9 @@ int spi_flash_probe_atmel(const struct spi_slave *spi, u8 *idcode, flash->name = params->name; /* Assuming power-of-two page size initially. */ - flash->page_size = 1 << params->l2_page_size; - flash->sector_size = flash->page_size * params->pages_per_sector; - flash->size = flash->sector_size * params->sectors_per_block * - params->nr_blocks; + flash->page_size = 256; + flash->sector_size = (1U << params->sector_size_kib_shift) * KiB; + flash->size = flash->sector_size * (1U << params->nr_sectors_shift); flash->erase_cmd = CMD_AT25_SE; flash->status_cmd = CMD_AT25_RDSR; flash->pp_cmd = CMD_AT25_PP; diff --git a/src/drivers/spi/eon.c b/src/drivers/spi/eon.c index b2c7ddcff1..3270c39ab5 100644 --- a/src/drivers/spi/eon.c +++ b/src/drivers/spi/eon.c @@ -55,183 +55,132 @@ #define EON_ID_EN25S32 0x3816 #define EON_ID_EN25S64 0x3817 -struct eon_spi_flash_params { - u16 id; - u16 page_size; - u16 pages_per_sector; - u16 sectors_per_block; - u16 nr_sectors; - const char *name; -}; - -static const struct eon_spi_flash_params eon_spi_flash_table[] = { +static const struct spi_flash_part_id flash_table[] = { { .id = EON_ID_EN25B80, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 256, .name = "EN25B80", + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25B16, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 512, .name = "EN25B16", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25B32, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 1024, .name = "EN25B32", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25B64, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 2048, .name = "EN25B64", + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25F80, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 256, .name = "EN25F80", + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25F16, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 512, .name = "EN25F16", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25F32, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 1024, .name = "EN25F32", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25F64, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 2048, .name = "EN25F64", + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25Q80, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 256, .name = "EN25Q80(A)", + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25Q16, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 512, .name = "EN25Q16(D16)", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25Q32, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 1024, .name = "EN25Q32(A/B)", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25Q64, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 2048, .name = "EN25Q64", + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25Q128, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 4096, .name = "EN25Q128", + .nr_sectors_shift = 12, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25QH16, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 512, .name = "EN25QH16", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25QH32, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 1024, .name = "EN25QH32", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25QH64, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 2048, .name = "EN25QH64", + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25QH128, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 4096, .name = "EN25QH128", + .nr_sectors_shift = 12, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25S80, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 256, .name = "EN25S80", + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25S16, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 512, .name = "EN25S16", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25S32, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 1024, .name = "EN25S32", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, { .id = EON_ID_EN25S64, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_sectors = 2048, .name = "EN25S64", + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, }, }; @@ -245,16 +194,16 @@ static const struct spi_flash_ops spi_flash_ops = { int spi_flash_probe_eon(const struct spi_slave *spi, u8 *idcode, struct spi_flash *flash) { - const struct eon_spi_flash_params *params; + const struct spi_flash_part_id *params; unsigned int i; - for (i = 0; i < ARRAY_SIZE(eon_spi_flash_table); ++i) { - params = &eon_spi_flash_table[i]; + for (i = 0; i < ARRAY_SIZE(flash_table); ++i) { + params = &flash_table[i]; if (params->id == ((idcode[1] << 8) | idcode[2])) break; } - if (i == ARRAY_SIZE(eon_spi_flash_table)) { + if (i == ARRAY_SIZE(flash_table)) { printk(BIOS_WARNING, "SF: Unsupported EON ID %#02x%02x\n", idcode[1], idcode[2]); return -1; @@ -263,9 +212,9 @@ int spi_flash_probe_eon(const struct spi_slave *spi, u8 *idcode, memcpy(&flash->spi, spi, sizeof(*spi)); flash->name = params->name; - flash->page_size = params->page_size; - flash->sector_size = params->page_size * params->pages_per_sector; - flash->size = flash->sector_size * params->nr_sectors; + flash->page_size = 256; + flash->sector_size = (1U << params->sector_size_kib_shift) * KiB; + flash->size = flash->sector_size * (1U << params->nr_sectors_shift); flash->erase_cmd = CMD_EN25_SE; flash->status_cmd = CMD_EN25_RDSR; flash->pp_cmd = CMD_EN25_PP; diff --git a/src/drivers/spi/gigadevice.c b/src/drivers/spi/gigadevice.c index b78b83048e..010fb45e4a 100644 --- a/src/drivers/spi/gigadevice.c +++ b/src/drivers/spi/gigadevice.c @@ -34,133 +34,96 @@ #define CMD_GD25_DP 0xb9 /* Deep Power-down */ #define CMD_GD25_RES 0xab /* Release from DP, and Read Signature */ -struct gigadevice_spi_flash_params { - uint16_t id; - uint8_t dual_spi : 1; - uint8_t _reserved_for_flags : 3; - uint8_t l2_page_size_shift : 4; - uint8_t pages_per_sector_shift : 4; - uint8_t sectors_per_block_shift : 4; - uint8_t nr_blocks_shift; - const char name[10]; -}; - -static const struct gigadevice_spi_flash_params gigadevice_spi_flash_table[] = { +static const struct spi_flash_part_id flash_table[] = { { .id = 0x3114, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 4, .name = "GD25T80", + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, }, { .id = 0x4014, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 4, - .dual_spi = 1, .name = "GD25Q80", + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, }, /* also GD25Q80B */ { .id = 0x4015, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 5, - .dual_spi = 1, .name = "GD25Q16", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, }, /* also GD25Q16B */ { .id = 0x4016, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 6, - .dual_spi = 1, .name = "GD25Q32B", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, }, /* also GD25Q32B */ { .id = 0x4017, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 7, - .dual_spi = 1, .name = "GD25Q64", + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, }, /* also GD25Q64B, GD25B64C */ { .id = 0x4018, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 8, - .dual_spi = 1, .name = "GD25Q128", + .nr_sectors_shift = 12, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, }, /* also GD25Q128B */ { .id = 0x4214, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 4, - .dual_spi = 1, .name = "GD25VQ80C", + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, }, { .id = 0x4215, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 5, - .dual_spi = 1, .name = "GD25VQ16C", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, }, { .id = 0x6014, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 4, - .dual_spi = 1, .name = "GD25LQ80", + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, }, { .id = 0x6015, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 5, - .dual_spi = 1, .name = "GD25LQ16", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, }, { .id = 0x6016, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 6, - .dual_spi = 1, .name = "GD25LQ32", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, }, { .id = 0x6017, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 7, - .dual_spi = 1, .name = "GD25LQ64C", + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, }, /* also GD25LB64C */ { .id = 0x6018, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 8, - .dual_spi = 1, .name = "GD25LQ128", + .nr_sectors_shift = 12, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, }, }; @@ -174,16 +137,16 @@ static const struct spi_flash_ops spi_flash_ops = { int spi_flash_probe_gigadevice(const struct spi_slave *spi, u8 *idcode, struct spi_flash *flash) { - const struct gigadevice_spi_flash_params *params; + const struct spi_flash_part_id *params; unsigned int i; - for (i = 0; i < ARRAY_SIZE(gigadevice_spi_flash_table); i++) { - params = &gigadevice_spi_flash_table[i]; + for (i = 0; i < ARRAY_SIZE(flash_table); i++) { + params = &flash_table[i]; if (params->id == ((idcode[1] << 8) | idcode[2])) break; } - if (i == ARRAY_SIZE(gigadevice_spi_flash_table)) { + if (i == ARRAY_SIZE(flash_table)) { printk(BIOS_WARNING, "SF gigadevice.c: Unsupported ID %#02x%02x\n", idcode[1], idcode[2]); @@ -194,12 +157,9 @@ int spi_flash_probe_gigadevice(const struct spi_slave *spi, u8 *idcode, flash->name = params->name; /* Assuming power-of-two page size initially. */ - flash->page_size = 1 << params->l2_page_size_shift; - flash->sector_size = flash->page_size * - (1 << params->pages_per_sector_shift); - flash->size = flash->sector_size * - (1 << params->sectors_per_block_shift) * - (1 << params->nr_blocks_shift); + flash->page_size = 256; + flash->sector_size = (1U << params->sector_size_kib_shift) * KiB; + flash->size = flash->sector_size * (1U << params->nr_sectors_shift); flash->erase_cmd = CMD_GD25_SE; flash->status_cmd = CMD_GD25_RDSR; flash->pp_cmd = CMD_GD25_PP; diff --git a/src/drivers/spi/macronix.c b/src/drivers/spi/macronix.c index 334404dee9..c7a4ce06aa 100644 --- a/src/drivers/spi/macronix.c +++ b/src/drivers/spi/macronix.c @@ -36,167 +36,120 @@ #define MACRONIX_SR_WIP (1 << 0) /* Write-in-Progress */ -struct macronix_spi_flash_params { - u16 idcode; - u16 page_size; - u16 pages_per_sector; - u16 sectors_per_block; - u16 nr_blocks; - const char *name; -}; - -static const struct macronix_spi_flash_params macronix_spi_flash_table[] = { +static const struct spi_flash_part_id flash_table[] = { { - .idcode = 0x2014, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 16, + .id = 0x2014, .name = "MX25L8005", + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, }, { - .idcode = 0x2015, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 32, + .id = 0x2015, .name = "MX25L1605D", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { - .idcode = 0x2016, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 64, + .id = 0x2016, .name = "MX25L3205D", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, { - .idcode = 0x2017, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 128, + .id = 0x2017, .name = "MX25L6405D", + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, }, { - .idcode = 0x2018, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 256, + .id = 0x2018, .name = "MX25L12805D", + .nr_sectors_shift = 12, + .sector_size_kib_shift = 2, }, { - .idcode = 0x2019, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 512, + .id = 0x2019, .name = "MX25L25635F", + .nr_sectors_shift = 13, + .sector_size_kib_shift = 2, }, { - .idcode = 0x201a, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 1024, + .id = 0x201a, .name = "MX66L51235F", + .nr_sectors_shift = 14, + .sector_size_kib_shift = 2, }, { - .idcode = 0x2415, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 32, + .id = 0x2415, .name = "MX25L1635D", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { - .idcode = 0x2515, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 32, + .id = 0x2515, .name = "MX25L1635E", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { - .idcode = 0x2534, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 16, + .id = 0x2534, .name = "MX25U8032E", + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, }, { - .idcode = 0x2535, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 32, + .id = 0x2535, .name = "MX25U1635E", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { - .idcode = 0x2536, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 64, + .id = 0x2536, .name = "MX25U3235E", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, { - .idcode = 0x2537, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 128, + .id = 0x2537, .name = "MX25U6435F", + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, }, { - .idcode = 0x2538, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 256, + .id = 0x2538, .name = "MX25U12835F", + .nr_sectors_shift = 12, + .sector_size_kib_shift = 2, }, { - .idcode = 0x2539, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 512, + .id = 0x2539, .name = "MX25U25635F", + .nr_sectors_shift = 13, + .sector_size_kib_shift = 2, }, { - .idcode = 0x253a, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 1024, + .id = 0x253a, .name = "MX25U51245G", + .nr_sectors_shift = 14, + .sector_size_kib_shift = 2, }, { - .idcode = 0x2618, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 256, + .id = 0x2618, .name = "MX25L12855E", + .nr_sectors_shift = 12, + .sector_size_kib_shift = 2, }, { - .idcode = 0x5e16, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 64, + .id = 0x5e16, .name = "MX25L3235D", /* MX25L3225D/MX25L3236D/MX25L3237D */ + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, { - .idcode = 0x9517, - .page_size = 256, - .pages_per_sector = 16, - .sectors_per_block = 16, - .nr_blocks = 128, + .id = 0x9517, .name = "MX25L6495F", + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, }, }; @@ -210,27 +163,26 @@ static const struct spi_flash_ops spi_flash_ops = { int spi_flash_probe_macronix(const struct spi_slave *spi, u8 *idcode, struct spi_flash *flash) { - const struct macronix_spi_flash_params *params; + const struct spi_flash_part_id *params; unsigned int i; u16 id = idcode[2] | idcode[1] << 8; - for (i = 0; i < ARRAY_SIZE(macronix_spi_flash_table); i++) { - params = ¯onix_spi_flash_table[i]; - if (params->idcode == id) + for (i = 0; i < ARRAY_SIZE(flash_table); i++) { + params = &flash_table[i]; + if (params->id == id) break; } - if (i == ARRAY_SIZE(macronix_spi_flash_table)) { + if (i == ARRAY_SIZE(flash_table)) { printk(BIOS_WARNING, "SF: Unsupported Macronix ID %04x\n", id); return -1; } memcpy(&flash->spi, spi, sizeof(*spi)); flash->name = params->name; - flash->page_size = params->page_size; - flash->sector_size = params->page_size * params->pages_per_sector; - flash->size = flash->sector_size * params->sectors_per_block * - params->nr_blocks; + flash->page_size = 256; + flash->sector_size = (1U << params->sector_size_kib_shift) * KiB; + flash->size = flash->sector_size * params->nr_sectors_shift; flash->erase_cmd = CMD_MX25XX_SE; flash->status_cmd = CMD_MX25XX_RDSR; flash->pp_cmd = CMD_MX25XX_PP; diff --git a/src/drivers/spi/spansion.c b/src/drivers/spi/spansion.c index 3d2f39d6df..b4fca4f8b3 100644 --- a/src/drivers/spi/spansion.c +++ b/src/drivers/spi/spansion.c @@ -34,7 +34,6 @@ #define CMD_S25FLXX_DP 0xb9 /* Deep Power-down */ #define CMD_S25FLXX_RES 0xab /* Release from DP, and Read Signature */ -#define SPSN_MANUFACTURER_ID_S25FL_K 0x01 #define SPSN_ID_S25FL008A 0x0213 #define SPSN_ID_S25FL016A 0x0214 #define SPSN_ID_S25FL032A 0x0215 @@ -50,171 +49,87 @@ #define SPSN_EXT_ID_S25FL032P 0x4d00 #define SPSN_EXT_ID_S25FLXXS_64KB 0x4d01 -struct spansion_spi_flash_params { - u8 idcode0; - u16 idcode1; - u16 idcode2; - int (*identify) (const struct spansion_spi_flash_params *params, - u8 *idcode); - u16 page_size; - u16 pages_per_sector; - u16 nr_sectors; - const char *name; -}; - -/* - * returns non-zero if the given idcode matches the ID of the chip. this is for - * chips which use 2nd, 3rd, 4th, and 5th byte. - */ -static int identify_2345(const struct spansion_spi_flash_params *params, - u8 *idcode) -{ - u16 jedec = idcode[1] << 8 | idcode[2]; - u16 ext_jedec = idcode[3] << 8 | idcode[4]; - return (params->idcode1 == jedec) && (params->idcode2 == ext_jedec); -} - -/* - * returns non-zero if the given idcode matches the ID of the chip. this is for - * chips which use 1st, 2nd, and 3rd byte. - */ -static int identify_123(const struct spansion_spi_flash_params *params, - u8 *idcode) -{ - u16 jedec = idcode[1] << 8 | idcode[2]; - return (params->idcode0 == idcode[0]) && (params->idcode1 == jedec); -} - -static const struct spansion_spi_flash_params spansion_spi_flash_table[] = { +static const struct spi_flash_part_id flash_table_ext[] = { { - .idcode0 = 0, - .idcode1 = SPSN_ID_S25FL008A, - .idcode2 = 0, - .identify = identify_2345, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 16, + .id = SPSN_ID_S25FL008A, .name = "S25FL008A", + .nr_sectors_shift = 4, + .sector_size_kib_shift = 6, }, { - .idcode0 = 0, - .idcode1 = SPSN_ID_S25FL016A, - .idcode2 = 0, - .identify = identify_2345, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 32, + .id = SPSN_ID_S25FL016A, .name = "S25FL016A", + .nr_sectors_shift = 5, + .sector_size_kib_shift = 6, }, { - .idcode0 = 0, - .idcode1 = SPSN_ID_S25FL032A, - .idcode2 = 0, - .identify = identify_2345, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 64, + .id = SPSN_ID_S25FL032A, .name = "S25FL032A", + .nr_sectors_shift = 6, + .sector_size_kib_shift = 6, }, { - .idcode0 = 0, - .idcode1 = SPSN_ID_S25FL064A, - .idcode2 = 0, - .identify = identify_2345, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 128, + .id = SPSN_ID_S25FL064A, .name = "S25FL064A", + .nr_sectors_shift = 7, + .sector_size_kib_shift = 6, }, { - .idcode0 = 0, - .idcode1 = SPSN_ID_S25FL128P, - .idcode2 = SPSN_EXT_ID_S25FL128P_64KB, - .identify = identify_2345, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 256, + .id = (SPSN_EXT_ID_S25FL128P_64KB << 16) | SPSN_ID_S25FL128P, .name = "S25FL128P_64K", + .nr_sectors_shift = 8, + .sector_size_kib_shift = 6, }, { - .idcode0 = 0, - .idcode1 = SPSN_ID_S25FL128P, - .idcode2 = SPSN_EXT_ID_S25FL128P_256KB, - .identify = identify_2345, - .page_size = 256, - .pages_per_sector = 1024, - .nr_sectors = 64, + .id = (SPSN_EXT_ID_S25FL128P_256KB << 16) | SPSN_ID_S25FL128P, .name = "S25FL128P_256K", + .nr_sectors_shift = 6, + .sector_size_kib_shift = 8, }, { - .idcode0 = 0, - .idcode1 = SPSN_ID_S25FL128S, - .idcode2 = SPSN_EXT_ID_S25FLXXS_64KB, - .identify = identify_2345, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 512, + .id = (SPSN_EXT_ID_S25FLXXS_64KB << 16) | SPSN_ID_S25FL128S, .name = "S25FL128S_256K", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 6, }, { - .idcode0 = 0, - .idcode1 = SPSN_ID_S25FL032A, - .idcode2 = SPSN_EXT_ID_S25FL032P, - .identify = identify_2345, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 64, + .id = (SPSN_EXT_ID_S25FL032P << 16) | SPSN_ID_S25FL032A, .name = "S25FL032P", + .nr_sectors_shift = 6, + .sector_size_kib_shift = 6, }, { - .idcode0 = 0, - .idcode1 = SPSN_ID_S25FL128P, - .idcode2 = SPSN_EXT_ID_S25FLXXS_64KB, - .identify = identify_2345, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 256, + .id = (SPSN_EXT_ID_S25FLXXS_64KB << 16) | SPSN_ID_S25FL128P, .name = "S25FS128S", + .nr_sectors_shift = 8, + .sector_size_kib_shift = 6, }, +}; + +static const struct spi_flash_part_id flash_table[] = { { - .idcode0 = SPSN_MANUFACTURER_ID_S25FL_K, - .idcode1 = SPSN_ID_S25FL208K, - .idcode2 = 0, - .identify = identify_123, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 16, + .id = SPSN_ID_S25FL208K, .name = "S25FL208K", + .nr_sectors_shift = 4, + .sector_size_kib_shift = 6, }, { - .idcode0 = SPSN_MANUFACTURER_ID_S25FL_K, - .idcode1 = SPSN_ID_S25FL116K, - .idcode2 = 0, - .identify = identify_123, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 32, + .id = SPSN_ID_S25FL116K, .name = "S25FL116K_16M", + .nr_sectors_shift = 5, + .sector_size_kib_shift = 6, }, { - .idcode0 = SPSN_MANUFACTURER_ID_S25FL_K, - .idcode1 = SPSN_ID_S25FL132K, - .idcode2 = 0, - .identify = identify_123, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 64, + .id = SPSN_ID_S25FL132K, .name = "S25FL132K", + .nr_sectors_shift = 6, + .sector_size_kib_shift = 6, }, { - .idcode0 = SPSN_MANUFACTURER_ID_S25FL_K, - .idcode1 = SPSN_ID_S25FL164K, - .idcode2 = 0, - .identify = identify_123, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 128, + .id = SPSN_ID_S25FL164K, .name = "S25FL164K", + .nr_sectors_shift = 7, + .sector_size_kib_shift = 6, }, }; @@ -225,30 +140,28 @@ static const struct spi_flash_ops spi_flash_ops = { .status = spi_flash_cmd_status, }; -int spi_flash_probe_spansion(const struct spi_slave *spi, u8 *idcode, - struct spi_flash *flash) + +static int match_table(const struct spi_slave *spi, struct spi_flash *flash, u32 id, + const struct spi_flash_part_id *parts, size_t num_parts) { - const struct spansion_spi_flash_params *params; + const struct spi_flash_part_id *params = NULL; unsigned int i; - for (i = 0; i < ARRAY_SIZE(spansion_spi_flash_table); i++) { - params = &spansion_spi_flash_table[i]; - if (params->identify(params, idcode)) - break; + for (i = 0; i < num_parts; i++) { + if (parts[i].id != id) + continue; + params = &parts[i]; + break; } - if (i == ARRAY_SIZE(spansion_spi_flash_table)) { - printk(BIOS_WARNING, - "SF: Unsupported SPANSION ID %02x %02x %02x %02x %02x\n", - idcode[0], idcode[1], idcode[2], idcode[3], idcode[4]); + if (params == NULL) return -1; - } memcpy(&flash->spi, spi, sizeof(*spi)); flash->name = params->name; - flash->page_size = params->page_size; - flash->sector_size = params->page_size * params->pages_per_sector; - flash->size = flash->sector_size * params->nr_sectors; + flash->page_size = 256; + flash->sector_size = (1U << params->sector_size_kib_shift) * KiB; + flash->size = flash->sector_size * (1U << params->nr_sectors_shift); flash->erase_cmd = CMD_S25FLXX_SE; flash->status_cmd = CMD_S25FLXX_RDSR; flash->pp_cmd = CMD_S25FLXX_PP; @@ -258,3 +171,22 @@ int spi_flash_probe_spansion(const struct spi_slave *spi, u8 *idcode, return 0; } + +int spi_flash_probe_spansion(const struct spi_slave *spi, u8 *idcode, + struct spi_flash *flash) +{ + u32 id; + + id = ((idcode[3] << 8) | idcode[4]) << 16; + id |= (idcode[1] << 8) | idcode[2]; + + if (!match_table(spi, flash, id, flash_table_ext, ARRAY_SIZE(flash_table_ext))) + return 0; + + if (!match_table(spi, flash, id & 0xffff, flash_table, ARRAY_SIZE(flash_table))) + return 0; + + printk(BIOS_WARNING, "SF: Unsupported SPANSION ID %08x\n", id); + + return -1; +} diff --git a/src/drivers/spi/spi_flash_internal.h b/src/drivers/spi/spi_flash_internal.h index ef756c78d7..cc258ded20 100644 --- a/src/drivers/spi/spi_flash_internal.h +++ b/src/drivers/spi/spi_flash_internal.h @@ -93,4 +93,18 @@ int spi_flash_probe_gigadevice(const struct spi_slave *spi, u8 *idcode, int spi_flash_probe_adesto(const struct spi_slave *spi, u8 *idcode, struct spi_flash *flash); +struct spi_flash_part_id { + uint32_t id; + const char *name; + /* Log based 2 total number of sectors. */ + uint16_t nr_sectors_shift: 4; + /* Log based 2 sector size */ + uint16_t sector_size_kib_shift: 4; + uint16_t fast_read_dual_output_support : 1; + uint16_t _reserved_for_flags: 7; + /* Block protection. Currently used by Winbond. */ + uint16_t protection_granularity_shift : 5; + uint16_t bp_bits : 3; +}; + #endif /* SPI_FLASH_INTERNAL_H */ diff --git a/src/drivers/spi/sst.c b/src/drivers/spi/sst.c index 1fb64467a0..1b4ba57f1e 100644 --- a/src/drivers/spi/sst.c +++ b/src/drivers/spi/sst.c @@ -44,13 +44,6 @@ #define SST_SR_AAI (1 << 6) /* Addressing mode */ #define SST_SR_BPL (1 << 7) /* BP bits lock */ -struct sst_spi_flash_params { - u8 idcode1; - u16 nr_sectors; - const char *name; - const struct spi_flash_ops *ops; -}; - static int sst_write_ai(const struct spi_flash *flash, u32 offset, size_t len, const void *buf); @@ -68,68 +61,71 @@ static const struct spi_flash_ops spi_flash_ops_write_256 = { .status = spi_flash_cmd_status, }; -#define SST_SECTOR_SIZE (4 * 1024) -static const struct sst_spi_flash_params sst_spi_flash_table[] = { +static const struct spi_flash_part_id flash_table_ai[] = { { - .idcode1 = 0x8d, - .nr_sectors = 128, + .id = 0x8d, .name = "SST25VF040B", - .ops = &spi_flash_ops_write_ai, + .nr_sectors_shift = 7, + .sector_size_kib_shift = 2, },{ - .idcode1 = 0x8e, - .nr_sectors = 256, + .id = 0x8e, .name = "SST25VF080B", - .ops = &spi_flash_ops_write_ai, + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, },{ - .idcode1 = 0x80, - .nr_sectors = 256, + .id = 0x80, .name = "SST25VF080", - .ops = &spi_flash_ops_write_ai, + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, },{ - .idcode1 = 0x41, - .nr_sectors = 512, + .id = 0x41, .name = "SST25VF016B", - .ops = &spi_flash_ops_write_ai, + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, },{ - .idcode1 = 0x4a, - .nr_sectors = 1024, + .id = 0x4a, .name = "SST25VF032B", - .ops = &spi_flash_ops_write_ai, - },{ - .idcode1 = 0x4b, - .nr_sectors = 2048, - .name = "SST25VF064C", - .ops = &spi_flash_ops_write_256, + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, },{ - .idcode1 = 0x01, - .nr_sectors = 16, + .id = 0x01, .name = "SST25WF512", - .ops = &spi_flash_ops_write_ai, + .nr_sectors_shift = 4, + .sector_size_kib_shift = 2, },{ - .idcode1 = 0x02, - .nr_sectors = 32, + .id = 0x02, .name = "SST25WF010", - .ops = &spi_flash_ops_write_ai, + .nr_sectors_shift = 5, + .sector_size_kib_shift = 2, },{ - .idcode1 = 0x03, - .nr_sectors = 64, + .id = 0x03, .name = "SST25WF020", - .ops = &spi_flash_ops_write_ai, + .nr_sectors_shift = 6, + .sector_size_kib_shift = 2, },{ - .idcode1 = 0x04, - .nr_sectors = 128, + .id = 0x04, .name = "SST25WF040", - .ops = &spi_flash_ops_write_ai, + .nr_sectors_shift = 7, + .sector_size_kib_shift = 2, },{ - .idcode1 = 0x05, - .nr_sectors = 256, + .id = 0x05, .name = "SST25WF080", - .ops = &spi_flash_ops_write_ai, + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, },{ - .idcode1 = 0x14, - .nr_sectors = 256, + .id = 0x14, .name = "SST25WF080B", - .ops = &spi_flash_ops_write_ai, + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, + }, +}; + +static const struct spi_flash_part_id flash_table_pp256[] = { + { + .id = 0x4b, + .name = "SST25VF064C", + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, }, }; @@ -273,40 +269,53 @@ sst_unlock(const struct spi_flash *flash) return ret; } -int spi_flash_probe_sst(const struct spi_slave *spi, u8 *idcode, - struct spi_flash *flash) +static int match_table(const struct spi_slave *spi, struct spi_flash *flash, u8 id, + const struct spi_flash_part_id *parts, size_t num_parts, + const struct spi_flash_ops *ops) { - const struct sst_spi_flash_params *params; + const struct spi_flash_part_id *params; size_t i; - for (i = 0; i < ARRAY_SIZE(sst_spi_flash_table); ++i) { - params = &sst_spi_flash_table[i]; - if (params->idcode1 == idcode[2]) + for (i = 0; i < num_parts; i++) { + params = &parts[i]; + if (params->id == id) break; } - if (i == ARRAY_SIZE(sst_spi_flash_table)) { - printk(BIOS_WARNING, "SF: Unsupported SST ID %02x\n", idcode[1]); + if (i == num_parts) return -1; - } memcpy(&flash->spi, spi, sizeof(*spi)); flash->name = params->name; - flash->sector_size = SST_SECTOR_SIZE; - flash->size = flash->sector_size * params->nr_sectors; + flash->sector_size = (1U << params->sector_size_kib_shift) * KiB; + flash->size = flash->sector_size * (1U << params->nr_sectors_shift); flash->erase_cmd = CMD_SST_SE; flash->status_cmd = CMD_SST_RDSR; flash->wren_cmd = CMD_SST_WREN; - if (params->ops == &spi_flash_ops_write_256) { - flash->page_size = 256; - flash->pp_cmd = CMD_SST_PP; - } - - flash->ops = params->ops; + flash->ops = ops; /* Flash powers up read-only, so clear BP# bits */ sst_unlock(flash); return 0; } + +int spi_flash_probe_sst(const struct spi_slave *spi, u8 *idcode, + struct spi_flash *flash) +{ + if (!match_table(spi, flash, idcode[2], flash_table_ai, + ARRAY_SIZE(flash_table_ai), &spi_flash_ops_write_ai)) + return 0; + + if (!match_table(spi, flash, idcode[2], flash_table_pp256, + ARRAY_SIZE(flash_table_pp256), &spi_flash_ops_write_256)) { + flash->page_size = 256; + flash->pp_cmd = CMD_SST_PP; + return 0; + } + + printk(BIOS_WARNING, "SF: Unsupported SST ID %02x\n", idcode[2]); + + return -1; +} diff --git a/src/drivers/spi/stmicro.c b/src/drivers/spi/stmicro.c index 7aa06bd498..2f4e42a630 100644 --- a/src/drivers/spi/stmicro.c +++ b/src/drivers/spi/stmicro.c @@ -64,223 +64,165 @@ #define STM_ID_N25Q128__1E 0xbb18 #define STM_ID_N25Q256__1E 0xbb19 -struct stmicro_spi_flash_params { - u16 device_id; - u8 op_erase; - u16 page_size; - u16 pages_per_sector; - u16 nr_sectors; - const char *name; -}; - -static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = { +static const struct spi_flash_part_id flash_table_se[] = { { - .device_id = STM_ID_M25P10, - .op_erase = CMD_M25PXX_SE, - .page_size = 256, - .pages_per_sector = 128, - .nr_sectors = 4, + .id = STM_ID_M25P10, .name = "M25P10", + .nr_sectors_shift = 2, + .sector_size_kib_shift = 5, }, { - .device_id = STM_ID_M25P16, - .op_erase = CMD_M25PXX_SE, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 32, + .id = STM_ID_M25P16, .name = "M25P16", + .nr_sectors_shift = 5, + .sector_size_kib_shift = 6, }, { - .device_id = STM_ID_M25P20, - .op_erase = CMD_M25PXX_SE, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 4, + .id = STM_ID_M25P20, .name = "M25P20", + .nr_sectors_shift = 2, + .sector_size_kib_shift = 6, }, { - .device_id = STM_ID_M25P32, - .op_erase = CMD_M25PXX_SE, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 64, + .id = STM_ID_M25P32, .name = "M25P32", + .nr_sectors_shift = 6, + .sector_size_kib_shift = 6, }, { - .device_id = STM_ID_M25P40, - .op_erase = CMD_M25PXX_SE, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 8, + .id = STM_ID_M25P40, .name = "M25P40", + .nr_sectors_shift = 3, + .sector_size_kib_shift = 6, }, { - .device_id = STM_ID_M25P64, - .op_erase = CMD_M25PXX_SE, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 128, + .id = STM_ID_M25P64, .name = "M25P64", + .nr_sectors_shift = 7, + .sector_size_kib_shift = 6, }, { - .device_id = STM_ID_M25P80, - .op_erase = CMD_M25PXX_SE, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 16, + .id = STM_ID_M25P80, .name = "M25P80", + .nr_sectors_shift = 4, + .sector_size_kib_shift = 6, }, { - .device_id = STM_ID_M25P128, - .op_erase = CMD_M25PXX_SE, - .page_size = 256, - .pages_per_sector = 1024, - .nr_sectors = 64, + .id = STM_ID_M25P128, .name = "M25P128", + .nr_sectors_shift = 6, + .sector_size_kib_shift = 8, }, { - .device_id = STM_ID_M25PX80, - .op_erase = CMD_M25PXX_SE, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 16, + .id = STM_ID_M25PX80, .name = "M25PX80", + .nr_sectors_shift = 4, + .sector_size_kib_shift = 6, }, { - .device_id = STM_ID_M25PX16, - .op_erase = CMD_M25PXX_SE, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 32, + .id = STM_ID_M25PX16, .name = "M25PX16", + .nr_sectors_shift = 5, + .sector_size_kib_shift = 6, }, { - .device_id = STM_ID_M25PX32, - .op_erase = CMD_M25PXX_SE, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 64, + .id = STM_ID_M25PX32, .name = "M25PX32", + .nr_sectors_shift = 6, + .sector_size_kib_shift = 6, }, { - .device_id = STM_ID_M25PX64, - .op_erase = CMD_M25PXX_SE, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 128, + .id = STM_ID_M25PX64, .name = "M25PX64", + .nr_sectors_shift = 7, + .sector_size_kib_shift = 6, }, { - .device_id = STM_ID_M25PE80, - .op_erase = CMD_M25PXX_SE, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 16, + .id = STM_ID_M25PE80, .name = "M25PE80", + .nr_sectors_shift = 4, + .sector_size_kib_shift = 6, }, { - .device_id = STM_ID_M25PE16, - .op_erase = CMD_M25PXX_SE, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 32, + .id = STM_ID_M25PE16, .name = "M25PE16", + .nr_sectors_shift = 5, + .sector_size_kib_shift = 6, }, { - .device_id = STM_ID_M25PE32, - .op_erase = CMD_M25PXX_SE, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 64, + .id = STM_ID_M25PE32, .name = "M25PE32", + .nr_sectors_shift = 6, + .sector_size_kib_shift = 6, }, { - .device_id = STM_ID_M25PE64, - .op_erase = CMD_M25PXX_SE, - .page_size = 256, - .pages_per_sector = 256, - .nr_sectors = 128, + .id = STM_ID_M25PE64, .name = "M25PE64", + .nr_sectors_shift = 7, + .sector_size_kib_shift = 6, }, +}; + +static const struct spi_flash_part_id flash_table_sse[] = { { - .device_id = STM_ID_N25Q016__3E, - .op_erase = CMD_M25PXX_SSE, - .page_size = 256, - .pages_per_sector = 16, - .nr_sectors = 512, + .id = STM_ID_N25Q016__3E, .name = "N25Q016..3E", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { - .device_id = STM_ID_N25Q032__3E, - .op_erase = CMD_M25PXX_SSE, - .page_size = 256, - .pages_per_sector = 16, - .nr_sectors = 1024, + .id = STM_ID_N25Q032__3E, .name = "N25Q032..3E", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, { - .device_id = STM_ID_N25Q064__3E, - .op_erase = CMD_M25PXX_SSE, - .page_size = 256, - .pages_per_sector = 16, - .nr_sectors = 2048, + .id = STM_ID_N25Q064__3E, .name = "N25Q064..3E", + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, }, { - .device_id = STM_ID_N25Q128__3E, - .op_erase = CMD_M25PXX_SSE, - .page_size = 256, - .pages_per_sector = 16, - .nr_sectors = 4096, + .id = STM_ID_N25Q128__3E, .name = "N25Q128..3E", + .nr_sectors_shift = 12, + .sector_size_kib_shift = 2, }, { - .device_id = STM_ID_N25Q256__3E, - .op_erase = CMD_M25PXX_SSE, - .page_size = 256, - .pages_per_sector = 16, - .nr_sectors = 8192, + .id = STM_ID_N25Q256__3E, .name = "N25Q256..3E", + .nr_sectors_shift = 13, + .sector_size_kib_shift = 2, }, { - .device_id = STM_ID_N25Q016__1E, - .op_erase = CMD_M25PXX_SSE, - .page_size = 256, - .pages_per_sector = 16, - .nr_sectors = 512, + .id = STM_ID_N25Q016__1E, .name = "N25Q016..1E", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { - .device_id = STM_ID_N25Q032__1E, - .op_erase = CMD_M25PXX_SSE, - .page_size = 256, - .pages_per_sector = 16, - .nr_sectors = 1024, + .id = STM_ID_N25Q032__1E, .name = "N25Q032..1E", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, { - .device_id = STM_ID_N25Q064__1E, - .op_erase = CMD_M25PXX_SSE, - .page_size = 256, - .pages_per_sector = 16, - .nr_sectors = 2048, + .id = STM_ID_N25Q064__1E, .name = "N25Q064..1E", + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, }, { - .device_id = STM_ID_N25Q128__1E, - .op_erase = CMD_M25PXX_SSE, - .page_size = 256, - .pages_per_sector = 16, - .nr_sectors = 4096, + .id = STM_ID_N25Q128__1E, .name = "N25Q128..1E", + .nr_sectors_shift = 12, + .sector_size_kib_shift = 2, }, { - .device_id = STM_ID_N25Q256__1E, - .op_erase = CMD_M25PXX_SSE, - .page_size = 256, - .pages_per_sector = 16, - .nr_sectors = 8192, + .id = STM_ID_N25Q256__1E, .name = "N25Q256..1E", + .nr_sectors_shift = 13, + .sector_size_kib_shift = 2, }, }; @@ -309,31 +251,30 @@ int stmicro_release_deep_sleep_identify(const struct spi_slave *spi, u8 *idcode) return 0; } -int spi_flash_probe_stmicro(const struct spi_slave *spi, u8 *idcode, - struct spi_flash *flash) +static int match_table(const struct spi_slave *spi, struct spi_flash *flash, u16 id, + const struct spi_flash_part_id *parts, size_t num_parts, + u8 erase_cmd) { - const struct stmicro_spi_flash_params *params; - unsigned int i; + const struct spi_flash_part_id *params; + size_t i; - for (i = 0; i < ARRAY_SIZE(stmicro_spi_flash_table); i++) { - params = &stmicro_spi_flash_table[i]; - if (params->device_id == (idcode[1] << 8 | idcode[2])) { + for (i = 0; i < num_parts; i++) { + params = &parts[i]; + if (params->id == id) break; - } } - if (i == ARRAY_SIZE(stmicro_spi_flash_table)) { - printk(BIOS_WARNING, "SF: Unsupported STMicro ID %02x%02x\n", - idcode[1], idcode[2]); + if (i == num_parts) { + printk(BIOS_WARNING, "SF: Unsupported STMicro ID %04x\n", id); return -1; } memcpy(&flash->spi, spi, sizeof(*spi)); flash->name = params->name; - flash->page_size = params->page_size; - flash->sector_size = params->page_size * params->pages_per_sector; - flash->size = flash->sector_size * params->nr_sectors; - flash->erase_cmd = params->op_erase; + flash->page_size = 256; + flash->sector_size = (1U << params->sector_size_kib_shift) * KiB; + flash->size = flash->sector_size * (1U << params->nr_sectors_shift); + flash->erase_cmd = erase_cmd; flash->status_cmd = CMD_M25PXX_RDSR; flash->pp_cmd = CMD_M25PXX_PP; flash->wren_cmd = CMD_M25PXX_WREN; @@ -342,3 +283,21 @@ int spi_flash_probe_stmicro(const struct spi_slave *spi, u8 *idcode, return 0; } + +int spi_flash_probe_stmicro(const struct spi_slave *spi, u8 *idcode, + struct spi_flash *flash) +{ + u16 id = (idcode[1] << 8) | idcode[2]; + + if (!match_table(spi, flash, id, flash_table_se, ARRAY_SIZE(flash_table_se), + CMD_M25PXX_SE)) { + return 0; + } + + if (!match_table(spi, flash, id, flash_table_sse, ARRAY_SIZE(flash_table_sse), + CMD_M25PXX_SSE)) { + return 0; + } + + return -1; +} diff --git a/src/drivers/spi/winbond.c b/src/drivers/spi/winbond.c index 27aaae8440..6766bb6e44 100644 --- a/src/drivers/spi/winbond.c +++ b/src/drivers/spi/winbond.c @@ -23,19 +23,6 @@ #include "spi_flash_internal.h" #include "spi_winbond.h" -struct winbond_spi_flash_params { - uint16_t id; - uint8_t dual_spi : 1; - uint8_t _reserved_for_flags : 3; - uint8_t l2_page_size_shift : 4; - uint8_t pages_per_sector_shift : 4; - uint8_t sectors_per_block_shift : 4; - uint8_t nr_blocks_shift; - uint8_t bp_bits : 3; - uint8_t protection_granularity_shift : 5; - char name[10]; -}; - union status_reg1_bp3 { uint8_t u; struct { @@ -92,205 +79,165 @@ struct status_regs { }; }; -static const struct winbond_spi_flash_params winbond_spi_flash_table[] = { +static const struct spi_flash_part_id flash_table[] = { { .id = 0x2014, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 4, .name = "W25P80", + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, }, { .id = 0x2015, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 5, .name = "W25P16", + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, }, { .id = 0x2016, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 6, .name = "W25P32", + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, }, { .id = 0x3014, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 4, .name = "W25X80", - .dual_spi = 1, + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, }, { .id = 0x3015, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 5, .name = "W25X16", - .dual_spi = 1, + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, }, { .id = 0x3016, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 6, .name = "W25X32", - .dual_spi = 1, + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, }, { .id = 0x3017, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 7, .name = "W25X64", - .dual_spi = 1, + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, }, { .id = 0x4014, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 4, .name = "W25Q80_V", - .dual_spi = 1, + .nr_sectors_shift = 8, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, }, { .id = 0x4015, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 5, .name = "W25Q16_V", - .dual_spi = 1, + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, .protection_granularity_shift = 16, .bp_bits = 3, }, { .id = 0x6015, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 5, .name = "W25Q16DW", - .dual_spi = 1, + .nr_sectors_shift = 9, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, .protection_granularity_shift = 16, .bp_bits = 3, }, { .id = 0x4016, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 6, .name = "W25Q32_V", - .dual_spi = 1, + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, .protection_granularity_shift = 16, .bp_bits = 3, }, { .id = 0x6016, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 6, .name = "W25Q32DW", - .dual_spi = 1, + .nr_sectors_shift = 10, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, .protection_granularity_shift = 16, .bp_bits = 3, }, { .id = 0x4017, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 7, .name = "W25Q64_V", - .dual_spi = 1, + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, .protection_granularity_shift = 17, .bp_bits = 3, }, { .id = 0x6017, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 7, .name = "W25Q64DW", - .dual_spi = 1, + .nr_sectors_shift = 11, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, .protection_granularity_shift = 17, .bp_bits = 3, }, { .id = 0x4018, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 8, .name = "W25Q128_V", - .dual_spi = 1, + .nr_sectors_shift = 12, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, .protection_granularity_shift = 18, .bp_bits = 3, }, { .id = 0x6018, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 8, .name = "W25Q128FW", - .dual_spi = 1, + .nr_sectors_shift = 12, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, .protection_granularity_shift = 18, .bp_bits = 3, }, { .id = 0x7018, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 8, .name = "W25Q128J", - .dual_spi = 1, + .nr_sectors_shift = 12, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, .protection_granularity_shift = 18, .bp_bits = 3, }, { - .id = 0x8018, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 8, - .name = "W25Q128JW", - .dual_spi = 1, - .protection_granularity_shift = 18, - .bp_bits = 3, + .id = 0x8018, + .name = "W25Q128JW", + .nr_sectors_shift = 12, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, + .protection_granularity_shift = 18, + .bp_bits = 3, }, { .id = 0x4019, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 9, .name = "W25Q256_V", - .dual_spi = 1, + .nr_sectors_shift = 13, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, .protection_granularity_shift = 16, .bp_bits = 4, }, { .id = 0x7019, - .l2_page_size_shift = 8, - .pages_per_sector_shift = 4, - .sectors_per_block_shift = 4, - .nr_blocks_shift = 9, .name = "W25Q256J", - .dual_spi = 1, + .nr_sectors_shift = 13, + .sector_size_kib_shift = 2, + .fast_read_dual_output_support = 1, .protection_granularity_shift = 16, .bp_bits = 4, }, @@ -319,6 +266,17 @@ static void winbond_bpbits_to_region(const size_t granularity, out->size = protected_size; } +static const struct spi_flash_part_id *lookup_part(u16 id) +{ + size_t i; + + for (i = 0; i < ARRAY_SIZE(flash_table); i++) { + if (flash_table[i].id == id) + return &flash_table[i]; + } + + return NULL; +} /* * Available on all devices. * Read block protect bits from Status/Status2 Reg. @@ -332,13 +290,17 @@ static void winbond_bpbits_to_region(const size_t granularity, static int winbond_get_write_protection(const struct spi_flash *flash, const struct region *region) { - const struct winbond_spi_flash_params *params; + const struct spi_flash_part_id *params; struct region wp_region; union status_reg2 reg2; u8 bp, tb; int ret; - params = (const struct winbond_spi_flash_params *)flash->driver_private; + params = lookup_part(flash->model); + + if (!params) + return -1; + const size_t granularity = (1 << params->protection_granularity_shift); if (params->bp_bits == 3) { @@ -507,7 +469,7 @@ winbond_set_write_protection(const struct spi_flash *flash, const bool non_volatile, const enum spi_flash_status_reg_lockdown mode) { - const struct winbond_spi_flash_params *params; + const struct spi_flash_part_id *params; struct status_regs mask, val; struct region wp_region; u8 cmp, bp, tb; @@ -517,7 +479,8 @@ winbond_set_write_protection(const struct spi_flash *flash, if (region_offset(region) != 0 && region_end(region) != flash->size) return -1; - params = (const struct winbond_spi_flash_params *)flash->driver_private; + params = lookup_part(flash->model); + if (!params) return -1; @@ -625,16 +588,16 @@ static const struct spi_flash_protection_ops spi_flash_protection_ops = { int spi_flash_probe_winbond(const struct spi_slave *spi, u8 *idcode, struct spi_flash *flash) { - const struct winbond_spi_flash_params *params; + const struct spi_flash_part_id *params; unsigned int i; - for (i = 0; i < ARRAY_SIZE(winbond_spi_flash_table); i++) { - params = &winbond_spi_flash_table[i]; + for (i = 0; i < ARRAY_SIZE(flash_table); i++) { + params = &flash_table[i]; if (params->id == ((idcode[1] << 8) | idcode[2])) break; } - if (i == ARRAY_SIZE(winbond_spi_flash_table)) { + if (i == ARRAY_SIZE(flash_table)) { printk(BIOS_WARNING, "SF: Unsupported Winbond ID %02x%02x\n", idcode[1], idcode[2]); return -1; @@ -644,22 +607,18 @@ int spi_flash_probe_winbond(const struct spi_slave *spi, u8 *idcode, flash->name = params->name; /* Params are in power-of-two. */ - flash->page_size = 1 << params->l2_page_size_shift; - flash->sector_size = flash->page_size * - (1 << params->pages_per_sector_shift); - flash->size = flash->sector_size * - (1 << params->sectors_per_block_shift) * - (1 << params->nr_blocks_shift); + flash->page_size = 256; + flash->sector_size = (1U << params->sector_size_kib_shift) * KiB; + flash->size = flash->sector_size * (1U << params->nr_sectors_shift); flash->erase_cmd = CMD_W25_SE; flash->status_cmd = CMD_W25_RDSR; flash->pp_cmd = CMD_W25_PP; flash->wren_cmd = CMD_W25_WREN; - flash->flags.dual_spi = params->dual_spi; + flash->flags.dual_spi = params->fast_read_dual_output_support; 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 9c11433ff0..ffa66db561 100644 --- a/src/include/spi_flash.h +++ b/src/include/spi_flash.h @@ -113,7 +113,6 @@ struct spi_flash { const struct spi_flash_ops *ops; /* If !NULL all protection callbacks exist. */ const struct spi_flash_protection_ops *prot_ops; - const void *driver_private; }; void lb_spi_flash(struct lb_header *header); -- cgit v1.2.3