aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/spi/sst.c
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2019-12-27 15:16:17 -0700
committerAaron Durbin <adurbin@chromium.org>2020-01-06 15:00:50 +0000
commitd701ef7475fe6d015a61cd91410391c3e0902f53 (patch)
treea3b1aaaaa6490b62ef7c71e9a119a41bd32d825a /src/drivers/spi/sst.c
parent9e877ec60d177565776b20e3d61f723a9552ee34 (diff)
drives/spi_flash: add spi_flash_cmd_write_page_program()
The SPI flashes that support page programming mode had duplicated the logic for writing in every driver. Add spi_flash_cmd_write_page_program() and use the common implementation to reduce code size that comes from duplication. The savings is ~2.5KiB per stage where the spi flash drivers are utilized. Change-Id: Ie6db03fa8ad33789f1d07a718a769e4ca8bffe1d Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/37963 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net> Reviewed-by: Marshall Dawson <marshalldawson3rd@gmail.com>
Diffstat (limited to 'src/drivers/spi/sst.c')
-rw-r--r--src/drivers/spi/sst.c64
1 files changed, 7 insertions, 57 deletions
diff --git a/src/drivers/spi/sst.c b/src/drivers/spi/sst.c
index 499db3550b..bcc47700d9 100644
--- a/src/drivers/spi/sst.c
+++ b/src/drivers/spi/sst.c
@@ -53,8 +53,6 @@ struct sst_spi_flash_params {
static int sst_write_ai(const struct spi_flash *flash, u32 offset, size_t len,
const void *buf);
-static int sst_write_256(const struct spi_flash *flash, u32 offset, size_t len,
- const void *buf);
static const struct spi_flash_ops spi_flash_ops_write_ai = {
.write = sst_write_ai,
@@ -63,7 +61,7 @@ static const struct spi_flash_ops spi_flash_ops_write_ai = {
};
static const struct spi_flash_ops spi_flash_ops_write_256 = {
- .write = sst_write_256,
+ .write = spi_flash_cmd_write_page_program,
.erase = spi_flash_cmd_erase,
.status = spi_flash_cmd_status,
};
@@ -187,60 +185,6 @@ sst_byte_write(const struct spi_flash *flash, u32 offset, const void *buf)
return spi_flash_cmd_wait_ready(flash, SPI_FLASH_PROG_TIMEOUT_MS);
}
-static int sst_write_256(const struct spi_flash *flash, u32 offset, size_t len,
- const void *buf)
-{
- size_t actual, chunk_len;
- unsigned long byte_addr;
- unsigned long page_size;
- int ret = 0;
- u8 cmd[4];
-
- page_size = 256;
-
- for (actual = 0; actual < len; actual += chunk_len) {
- byte_addr = offset % page_size;
- chunk_len = MIN(len - actual, page_size - byte_addr);
- chunk_len = spi_crop_chunk(&flash->spi, sizeof(cmd), chunk_len);
-
- cmd[0] = CMD_SST_PP;
- cmd[1] = (offset >> 16) & 0xff;
- cmd[2] = (offset >> 8) & 0xff;
- cmd[3] = offset & 0xff;
-#if CONFIG(DEBUG_SPI_FLASH)
- printk(BIOS_SPEW, "PP: %p => cmd = { 0x%02x 0x%02x%02x%02x }"
- " chunk_len = %zu\n",
- buf + actual, cmd[0], cmd[1], cmd[2], cmd[3], chunk_len);
-#endif
-
- ret = spi_flash_cmd(&flash->spi, CMD_SST_WREN, NULL, 0);
- if (ret < 0) {
- printk(BIOS_WARNING, "SF: Enabling Write failed\n");
- break;
- }
-
- ret = spi_flash_cmd_write(&flash->spi, cmd, sizeof(cmd),
- buf + actual, chunk_len);
- if (ret < 0) {
- printk(BIOS_WARNING, "SF: SST Page Program failed\n");
- break;
- }
-
- ret = spi_flash_cmd_wait_ready(flash,
- SPI_FLASH_PROG_TIMEOUT_MS);
- if (ret)
- break;
-
- offset += chunk_len;
- }
-
-#if CONFIG(DEBUG_SPI_FLASH)
- printk(BIOS_SPEW, "SF: SST: program %s %zu bytes @ 0x%lx\n",
- ret ? "failure" : "success", len, (unsigned long)offset - actual);
-#endif
- return ret;
-}
-
static int sst_write_ai(const struct spi_flash *flash, u32 offset, size_t len,
const void *buf)
{
@@ -350,6 +294,12 @@ int spi_flash_probe_sst(const struct spi_slave *spi, u8 *idcode,
flash->size = flash->sector_size * params->nr_sectors;
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;