aboutsummaryrefslogtreecommitdiff
path: root/src/drivers/spi/stmicro.c
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@chromium.org>2017-05-12 00:19:56 -0700
committerFurquan Shaikh <furquan@google.com>2017-05-19 21:21:30 +0200
commitfc1a123aa7392fe7900b466e6a6f089733fec1ee (patch)
tree9aeca66f20edb1d92aaa751d502134d401a15045 /src/drivers/spi/stmicro.c
parentf422fd2c78b8a7ab58e75ba7bd13b0c354a207b8 (diff)
drivers/spi/spi_flash: Add page_size to struct spi_flash
Add a new member page_size to spi_flash structure so that the various spi flash drivers can store this info in spi_flash along with the other sizes (sector size and total size) during flash probe. This removes the need to have {driver}_spi_flash structure in every spi flash driver. This is part of patch series to clean up the SPI flash and SPI driver interface. BUG=b:38330715 Change-Id: I0f83e52cb1041432b0b575a8ee3bd173cc038d1f Signed-off-by: Furquan Shaikh <furquan@chromium.org> Reviewed-on: https://review.coreboot.org/19704 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'src/drivers/spi/stmicro.c')
-rw-r--r--src/drivers/spi/stmicro.c37
1 files changed, 12 insertions, 25 deletions
diff --git a/src/drivers/spi/stmicro.c b/src/drivers/spi/stmicro.c
index 06004f19b2..2ec9f18376 100644
--- a/src/drivers/spi/stmicro.c
+++ b/src/drivers/spi/stmicro.c
@@ -66,18 +66,6 @@ struct stmicro_spi_flash_params {
const char *name;
};
-/* spi_flash needs to be first so upper layers can free() it */
-struct stmicro_spi_flash {
- struct spi_flash flash;
- const struct stmicro_spi_flash_params *params;
-};
-
-static inline
-struct stmicro_spi_flash *to_stmicro_spi_flash(const struct spi_flash *flash)
-{
- return container_of(flash, struct stmicro_spi_flash, flash);
-}
-
static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = {
{
.device_id = STM_ID_M25P10,
@@ -180,7 +168,6 @@ static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = {
static int stmicro_write(const struct spi_flash *flash,
u32 offset, size_t len, const void *buf)
{
- struct stmicro_spi_flash *stm = to_stmicro_spi_flash(flash);
unsigned long byte_addr;
unsigned long page_size;
size_t chunk_len;
@@ -188,7 +175,7 @@ static int stmicro_write(const struct spi_flash *flash,
int ret = 0;
u8 cmd[4];
- page_size = stm->params->page_size;
+ page_size = flash->page_size;
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
@@ -235,7 +222,7 @@ out:
return ret;
}
-static struct stmicro_spi_flash stm;
+static struct spi_flash flash;
struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
{
@@ -267,16 +254,16 @@ struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
return NULL;
}
- stm.params = params;
- memcpy(&stm.flash.spi, spi, sizeof(*spi));
- stm.flash.name = params->name;
+ memcpy(&flash.spi, spi, sizeof(*spi));
+ flash.name = params->name;
+ flash.page_size = params->page_size;
+ flash.sector_size = params->page_size * params->pages_per_sector;
+ flash.size = flash.sector_size * params->nr_sectors;
+ flash.erase_cmd = params->op_erase;
- stm.flash.internal_write = stmicro_write;
- stm.flash.internal_erase = spi_flash_cmd_erase;
- stm.flash.internal_read = spi_flash_cmd_read_fast;
- stm.flash.sector_size = params->page_size * params->pages_per_sector;
- stm.flash.size = stm.flash.sector_size * params->nr_sectors;
- stm.flash.erase_cmd = params->op_erase;
+ flash.internal_write = stmicro_write;
+ flash.internal_erase = spi_flash_cmd_erase;
+ flash.internal_read = spi_flash_cmd_read_fast;
- return &stm.flash;
+ return &flash;
}