diff options
author | Furquan Shaikh <furquan@chromium.org> | 2016-11-20 21:04:00 -0800 |
---|---|---|
committer | Furquan Shaikh <furquan@google.com> | 2016-11-22 17:32:09 +0100 |
commit | c28984d9ea08e7d995ef9fc8064c10ec0c0d9d77 (patch) | |
tree | c113582c3d2d8fb8d54a4c9a53375340fcc302d5 /src/drivers/spi/sst.c | |
parent | 282c8322791800ee0d732fdaa5eb2cd8f7effd58 (diff) | |
download | coreboot-c28984d9ea08e7d995ef9fc8064c10ec0c0d9d77.tar.xz |
spi: Clean up SPI flash driver interface
RW flag was added to spi_slave structure to get around a requirement on
some AMD flash controllers that need to group together all spi volatile
operations (write/erase). This rw flag is not a property or attribute of
the SPI slave or controller. Thus, instead of saving it in spi_slave
structure, clean up the SPI flash driver interface. This allows
chipsets/mainboards (that require volatile operations to be grouped) to
indicate beginning and end of such grouped operations.
New user APIs are added to allow users to perform probe, read, write,
erase, volatile group begin and end operations. Callbacks defined in
spi_flash structure are expected to be used only by the SPI flash
driver. Any chipset that requires grouping of volatile operations can
select the newly added Kconfig option SPI_FLASH_HAS_VOLATILE_GROUP and
define callbacks for chipset_volatile_group_{begin,end}.
spi_claim_bus/spi_release_bus calls have been removed from the SPI flash
chip drivers which end up calling do_spi_flash_cmd since it already has
required calls for claiming and releasing SPI bus before performing a
read/write operation.
BUG=None
BRANCH=None
TEST=Compiles successfully.
Change-Id: Idfc052e82ec15b6c9fa874cee7a61bd06e923fbf
Signed-off-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-on: https://review.coreboot.org/17462
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'src/drivers/spi/sst.c')
-rw-r--r-- | src/drivers/spi/sst.c | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/src/drivers/spi/sst.c b/src/drivers/spi/sst.c index 87c1c5b38a..940d894396 100644 --- a/src/drivers/spi/sst.c +++ b/src/drivers/spi/sst.c @@ -12,8 +12,10 @@ * Licensed under the GPL-2 or later. */ +#include <console/console.h> #include <stdlib.h> #include <spi_flash.h> +#include <spi-generic.h> #include "spi_flash_internal.h" @@ -40,7 +42,7 @@ struct sst_spi_flash_params { u8 idcode1; u16 nr_sectors; const char *name; - int (*write)(struct spi_flash *flash, u32 offset, + int (*write)(const struct spi_flash *flash, u32 offset, size_t len, const void *buf); }; @@ -49,10 +51,10 @@ struct sst_spi_flash { const struct sst_spi_flash_params *params; }; -static int -sst_write_ai(struct spi_flash *flash, u32 offset, size_t len, const void *buf); -static int -sst_write_256(struct spi_flash *flash, u32 offset, size_t len, const void *buf); +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); #define SST_SECTOR_SIZE (4 * 1024) static const struct sst_spi_flash_params sst_spi_flash_table[] = { @@ -105,7 +107,7 @@ static const struct sst_spi_flash_params sst_spi_flash_table[] = { }; static int -sst_enable_writing(struct spi_flash *flash) +sst_enable_writing(const struct spi_flash *flash) { int ret = spi_flash_cmd(flash->spi, CMD_SST_WREN, NULL, 0); if (ret) @@ -114,7 +116,7 @@ sst_enable_writing(struct spi_flash *flash) } static int -sst_enable_writing_status(struct spi_flash *flash) +sst_enable_writing_status(const struct spi_flash *flash) { int ret = spi_flash_cmd(flash->spi, CMD_SST_EWSR, NULL, 0); if (ret) @@ -123,7 +125,7 @@ sst_enable_writing_status(struct spi_flash *flash) } static int -sst_disable_writing(struct spi_flash *flash) +sst_disable_writing(const struct spi_flash *flash) { int ret = spi_flash_cmd(flash->spi, CMD_SST_WRDI, NULL, 0); if (ret) @@ -132,7 +134,7 @@ sst_disable_writing(struct spi_flash *flash) } static int -sst_byte_write(struct spi_flash *flash, u32 offset, const void *buf) +sst_byte_write(const struct spi_flash *flash, u32 offset, const void *buf) { int ret; u8 cmd[4] = { @@ -158,8 +160,8 @@ sst_byte_write(struct spi_flash *flash, u32 offset, const void *buf) return spi_flash_cmd_wait_ready(flash, SPI_FLASH_PROG_TIMEOUT); } -static int -sst_write_256(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) { size_t actual, chunk_len, cmd_len; unsigned long byte_addr; @@ -170,8 +172,6 @@ sst_write_256(struct spi_flash *flash, u32 offset, size_t len, const void *buf) page_size = 256; byte_addr = offset % page_size; - flash->spi->rw = SPI_WRITE_FLAG; - /* If the data is not word aligned, write out leading single byte */ actual = offset % 2; if (actual) { @@ -234,15 +234,13 @@ done: return ret; } -static int -sst_write_ai(struct spi_flash *flash, u32 offset, size_t len, const void *buf) +static int sst_write_ai(const struct spi_flash *flash, u32 offset, size_t len, + const void *buf) { size_t actual, cmd_len; int ret = 0; u8 cmd[4]; - flash->spi->rw = SPI_WRITE_FLAG; - /* If the data is not word aligned, write out leading single byte */ actual = offset % 2; if (actual) { @@ -301,7 +299,7 @@ done: static int -sst_unlock(struct spi_flash *flash) +sst_unlock(const struct spi_flash *flash) { int ret; u8 cmd, status; @@ -349,10 +347,10 @@ spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode) stm->flash.spi = spi; stm->flash.name = params->name; - stm->flash.write = params->write; - stm->flash.erase = spi_flash_cmd_erase; - stm->flash.status = spi_flash_cmd_status; - stm->flash.read = spi_flash_cmd_read_fast; + stm->flash.internal_write = params->write; + stm->flash.internal_erase = spi_flash_cmd_erase; + stm->flash.internal_status = spi_flash_cmd_status; + stm->flash.internal_read = spi_flash_cmd_read_fast; stm->flash.sector_size = SST_SECTOR_SIZE; stm->flash.size = stm->flash.sector_size * params->nr_sectors; stm->flash.erase_cmd = CMD_SST_SE; |