summaryrefslogtreecommitdiff
path: root/src/drivers/spi/amic.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/amic.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/amic.c')
-rw-r--r--src/drivers/spi/amic.c81
1 files changed, 26 insertions, 55 deletions
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;