summaryrefslogtreecommitdiff
path: root/src/drivers/spi/adesto.c
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2020-01-11 23:18:51 -0700
committerAaron Durbin <adurbin@chromium.org>2020-01-17 05:48:52 +0000
commita6c73c898775bbc59b9d6e1fcb03e340db89ee67 (patch)
tree2d8970388b3871bd7428c2d703f769ebd0cefe49 /src/drivers/spi/adesto.c
parentae43f32458ad85a8b9cca4868ed47afda108652d (diff)
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 <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/38378 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
Diffstat (limited to 'src/drivers/spi/adesto.c')
-rw-r--r--src/drivers/spi/adesto.c99
1 files changed, 32 insertions, 67 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;