summaryrefslogtreecommitdiff
path: root/src/drivers/spi/stmicro.c
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2020-01-12 15:12:18 -0700
committerAaron Durbin <adurbin@chromium.org>2020-01-17 05:49:09 +0000
commit5abeb06a73c6f3073f2796a726ea6dc7fb584371 (patch)
tree82c6a3b967edcf0ccf0aabcbd06894b8847009af /src/drivers/spi/stmicro.c
parenta6c73c898775bbc59b9d6e1fcb03e340db89ee67 (diff)
downloadcoreboot-5abeb06a73c6f3073f2796a726ea6dc7fb584371.tar.xz
drivers/spi/spi_flash: organize spi flash by sector topology
By grouping the spi flash parts by their {vendor, sector topology} tuple one can use a common probe function for looking up the part instead of having per-vendor probe functions. Additionally, by grouping by the command set one can save more space as well. SST is the exception that requires after_probe() function to unlock the parts. 2KiB of savings in each of verstage, romstage, and ramstage on Aleena Chrome OS Build. Change-Id: I9cc20ca0f3d0a1b97154b000c95ff2e7e87f3375 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/38379 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'src/drivers/spi/stmicro.c')
-rw-r--r--src/drivers/spi/stmicro.c134
1 files changed, 48 insertions, 86 deletions
diff --git a/src/drivers/spi/stmicro.c b/src/drivers/spi/stmicro.c
index 2f4e42a630..62755f4a01 100644
--- a/src/drivers/spi/stmicro.c
+++ b/src/drivers/spi/stmicro.c
@@ -64,102 +64,92 @@
#define STM_ID_N25Q128__1E 0xbb18
#define STM_ID_N25Q256__1E 0xbb19
-static const struct spi_flash_part_id flash_table_se[] = {
+static const struct spi_flash_part_id flash_table_se32k[] = {
{
.id = STM_ID_M25P10,
.name = "M25P10",
.nr_sectors_shift = 2,
- .sector_size_kib_shift = 5,
},
+};
+
+static const struct spi_flash_part_id flash_table_se64k[] = {
{
.id = STM_ID_M25P16,
.name = "M25P16",
.nr_sectors_shift = 5,
- .sector_size_kib_shift = 6,
},
{
.id = STM_ID_M25P20,
.name = "M25P20",
.nr_sectors_shift = 2,
- .sector_size_kib_shift = 6,
},
{
.id = STM_ID_M25P32,
.name = "M25P32",
.nr_sectors_shift = 6,
- .sector_size_kib_shift = 6,
},
{
.id = STM_ID_M25P40,
.name = "M25P40",
.nr_sectors_shift = 3,
- .sector_size_kib_shift = 6,
},
{
.id = STM_ID_M25P64,
.name = "M25P64",
.nr_sectors_shift = 7,
- .sector_size_kib_shift = 6,
},
{
.id = STM_ID_M25P80,
.name = "M25P80",
.nr_sectors_shift = 4,
- .sector_size_kib_shift = 6,
- },
- {
- .id = STM_ID_M25P128,
- .name = "M25P128",
- .nr_sectors_shift = 6,
- .sector_size_kib_shift = 8,
},
{
.id = STM_ID_M25PX80,
.name = "M25PX80",
.nr_sectors_shift = 4,
- .sector_size_kib_shift = 6,
},
{
.id = STM_ID_M25PX16,
.name = "M25PX16",
.nr_sectors_shift = 5,
- .sector_size_kib_shift = 6,
},
{
.id = STM_ID_M25PX32,
.name = "M25PX32",
.nr_sectors_shift = 6,
- .sector_size_kib_shift = 6,
},
{
.id = STM_ID_M25PX64,
.name = "M25PX64",
.nr_sectors_shift = 7,
- .sector_size_kib_shift = 6,
},
{
.id = STM_ID_M25PE80,
.name = "M25PE80",
.nr_sectors_shift = 4,
- .sector_size_kib_shift = 6,
},
{
.id = STM_ID_M25PE16,
.name = "M25PE16",
.nr_sectors_shift = 5,
- .sector_size_kib_shift = 6,
},
{
.id = STM_ID_M25PE32,
.name = "M25PE32",
.nr_sectors_shift = 6,
- .sector_size_kib_shift = 6,
},
{
.id = STM_ID_M25PE64,
.name = "M25PE64",
.nr_sectors_shift = 7,
- .sector_size_kib_shift = 6,
+ },
+};
+
+static const struct spi_flash_part_id flash_table_se256k[] = {
+ {
+ .id = STM_ID_M25P128,
+ .name = "M25P128",
+ .nr_sectors_shift = 6,
},
};
@@ -168,71 +158,54 @@ static const struct spi_flash_part_id flash_table_sse[] = {
.id = STM_ID_N25Q016__3E,
.name = "N25Q016..3E",
.nr_sectors_shift = 9,
- .sector_size_kib_shift = 2,
},
{
.id = STM_ID_N25Q032__3E,
.name = "N25Q032..3E",
.nr_sectors_shift = 10,
- .sector_size_kib_shift = 2,
},
{
.id = STM_ID_N25Q064__3E,
.name = "N25Q064..3E",
.nr_sectors_shift = 11,
- .sector_size_kib_shift = 2,
},
{
.id = STM_ID_N25Q128__3E,
.name = "N25Q128..3E",
.nr_sectors_shift = 12,
- .sector_size_kib_shift = 2,
},
{
.id = STM_ID_N25Q256__3E,
.name = "N25Q256..3E",
.nr_sectors_shift = 13,
- .sector_size_kib_shift = 2,
},
{
.id = STM_ID_N25Q016__1E,
.name = "N25Q016..1E",
.nr_sectors_shift = 9,
- .sector_size_kib_shift = 2,
},
{
.id = STM_ID_N25Q032__1E,
.name = "N25Q032..1E",
.nr_sectors_shift = 10,
- .sector_size_kib_shift = 2,
},
{
.id = STM_ID_N25Q064__1E,
.name = "N25Q064..1E",
.nr_sectors_shift = 11,
- .sector_size_kib_shift = 2,
},
{
.id = STM_ID_N25Q128__1E,
.name = "N25Q128..1E",
.nr_sectors_shift = 12,
- .sector_size_kib_shift = 2,
},
{
.id = STM_ID_N25Q256__1E,
.name = "N25Q256..1E",
.nr_sectors_shift = 13,
- .sector_size_kib_shift = 2,
},
};
-static const struct spi_flash_ops spi_flash_ops = {
- .read = spi_flash_cmd_read,
- .write = spi_flash_cmd_write_page_program,
- .erase = spi_flash_cmd_erase,
- .status = spi_flash_cmd_status,
-};
-
int stmicro_release_deep_sleep_identify(const struct spi_slave *spi, u8 *idcode)
{
if (spi_flash_cmd(spi, CMD_M25PXX_RES, idcode, 4))
@@ -251,53 +224,42 @@ int stmicro_release_deep_sleep_identify(const struct spi_slave *spi, u8 *idcode)
return 0;
}
-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 spi_flash_part_id *params;
- size_t i;
-
- for (i = 0; i < num_parts; i++) {
- params = &parts[i];
- if (params->id == id)
- break;
- }
-
- 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 = 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;
-
- flash->ops = &spi_flash_ops;
-
- 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];
+const struct spi_flash_vendor_info spi_flash_stmicro1_vi = {
+ .id = VENDOR_ID_STMICRO,
+ .page_size_shift = 8,
+ .sector_size_kib_shift = 5,
+ .match_id_mask = 0xffff,
+ .ids = flash_table_se32k,
+ .nr_part_ids = ARRAY_SIZE(flash_table_se32k),
+ .desc = &spi_flash_pp_0xd8_sector_desc,
+};
- if (!match_table(spi, flash, id, flash_table_se, ARRAY_SIZE(flash_table_se),
- CMD_M25PXX_SE)) {
- return 0;
- }
+const struct spi_flash_vendor_info spi_flash_stmicro2_vi = {
+ .id = VENDOR_ID_STMICRO,
+ .page_size_shift = 8,
+ .sector_size_kib_shift = 6,
+ .match_id_mask = 0xffff,
+ .ids = flash_table_se64k,
+ .nr_part_ids = ARRAY_SIZE(flash_table_se64k),
+ .desc = &spi_flash_pp_0xd8_sector_desc,
+};
- if (!match_table(spi, flash, id, flash_table_sse, ARRAY_SIZE(flash_table_sse),
- CMD_M25PXX_SSE)) {
- return 0;
- }
+const struct spi_flash_vendor_info spi_flash_stmicro3_vi = {
+ .id = VENDOR_ID_STMICRO,
+ .page_size_shift = 8,
+ .sector_size_kib_shift = 8,
+ .match_id_mask = 0xffff,
+ .ids = flash_table_se256k,
+ .nr_part_ids = ARRAY_SIZE(flash_table_se256k),
+ .desc = &spi_flash_pp_0xd8_sector_desc,
+};
- return -1;
-}
+const struct spi_flash_vendor_info spi_flash_stmicro4_vi = {
+ .id = VENDOR_ID_STMICRO,
+ .page_size_shift = 8,
+ .sector_size_kib_shift = 2,
+ .match_id_mask = 0xffff,
+ .ids = flash_table_sse,
+ .nr_part_ids = ARRAY_SIZE(flash_table_sse),
+ .desc = &spi_flash_pp_0x20_sector_desc,
+};