summaryrefslogtreecommitdiff
path: root/src/drivers
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
parentf422fd2c78b8a7ab58e75ba7bd13b0c354a207b8 (diff)
downloadcoreboot-fc1a123aa7392fe7900b466e6a6f089733fec1ee.tar.xz
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')
-rw-r--r--src/drivers/spi/adesto.c54
-rw-r--r--src/drivers/spi/amic.c53
-rw-r--r--src/drivers/spi/atmel.c53
-rw-r--r--src/drivers/spi/eon.c51
-rw-r--r--src/drivers/spi/gigadevice.c53
-rw-r--r--src/drivers/spi/macronix.c46
-rw-r--r--src/drivers/spi/spansion.c43
-rw-r--r--src/drivers/spi/sst.c36
-rw-r--r--src/drivers/spi/stmicro.c37
-rw-r--r--src/drivers/spi/winbond.c54
10 files changed, 167 insertions, 313 deletions
diff --git a/src/drivers/spi/adesto.c b/src/drivers/spi/adesto.c
index 1091d9a4b1..c5c68b546b 100644
--- a/src/drivers/spi/adesto.c
+++ b/src/drivers/spi/adesto.c
@@ -42,18 +42,6 @@ struct adesto_spi_flash_params {
const char *name;
};
-/* spi_flash needs to be first so upper layers can free() it */
-struct adesto_spi_flash {
- struct spi_flash flash;
- const struct adesto_spi_flash_params *params;
-};
-
-static inline struct adesto_spi_flash *
-to_adesto_spi_flash(const struct spi_flash *flash)
-{
- return container_of(flash, struct adesto_spi_flash, flash);
-}
-
static const struct adesto_spi_flash_params adesto_spi_flash_table[] = {
{
.id = 0x4501,
@@ -84,7 +72,6 @@ static const struct adesto_spi_flash_params adesto_spi_flash_table[] = {
static int adesto_write(const struct spi_flash *flash, u32 offset, size_t len,
const void *buf)
{
- struct adesto_spi_flash *stm = to_adesto_spi_flash(flash);
unsigned long byte_addr;
unsigned long page_size;
size_t chunk_len;
@@ -92,7 +79,7 @@ static int adesto_write(const struct spi_flash *flash, u32 offset, size_t len,
int ret;
u8 cmd[4];
- page_size = 1 << stm->params->l2_page_size;
+ page_size = flash->page_size;
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
@@ -142,8 +129,7 @@ out:
struct spi_flash *spi_flash_probe_adesto(struct spi_slave *spi, u8 *idcode)
{
const struct adesto_spi_flash_params *params;
- unsigned page_size;
- struct adesto_spi_flash *stm;
+ struct spi_flash *flash;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(adesto_spi_flash_table); i++) {
@@ -158,32 +144,28 @@ struct spi_flash *spi_flash_probe_adesto(struct spi_slave *spi, u8 *idcode)
return NULL;
}
- stm = malloc(sizeof(struct adesto_spi_flash));
- if (!stm) {
+ flash = malloc(sizeof(*flash));
+ if (!flash) {
printk(BIOS_WARNING, "SF: Failed to allocate memory\n");
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;
/* Assuming power-of-two page size initially. */
- page_size = 1 << params->l2_page_size;
-
- stm->flash.internal_write = adesto_write;
- stm->flash.internal_erase = spi_flash_cmd_erase;
+ 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->erase_cmd = CMD_AT25DF_SE;
+
+ flash->internal_write = adesto_write;
+ flash->internal_erase = spi_flash_cmd_erase;
#if CONFIG_SPI_FLASH_NO_FAST_READ
- stm->flash.internal_read = spi_flash_cmd_read_slow;
+ flash->internal_read = spi_flash_cmd_read_slow;
#else
- stm->flash.internal_read = spi_flash_cmd_read_fast;
+ flash->internal_read = spi_flash_cmd_read_fast;
#endif
- stm->flash.sector_size = (1 << stm->params->l2_page_size) *
- stm->params->pages_per_sector;
- stm->flash.size = page_size * params->pages_per_sector
- * params->sectors_per_block
- * params->nr_blocks;
- stm->flash.erase_cmd = CMD_AT25DF_SE;
-
- return &stm->flash;
+
+ return flash;
}
diff --git a/src/drivers/spi/amic.c b/src/drivers/spi/amic.c
index 2ee5d69790..60843608f5 100644
--- a/src/drivers/spi/amic.c
+++ b/src/drivers/spi/amic.c
@@ -40,18 +40,6 @@ struct amic_spi_flash_params {
const char *name;
};
-/* spi_flash needs to be first so upper layers can free() it */
-struct amic_spi_flash {
- struct spi_flash flash;
- const struct amic_spi_flash_params *params;
-};
-
-static inline struct amic_spi_flash *
-to_amic_spi_flash(const struct spi_flash *flash)
-{
- return container_of(flash, struct amic_spi_flash, flash);
-}
-
static const struct amic_spi_flash_params amic_spi_flash_table[] = {
{
.id = 0x3016,
@@ -66,7 +54,6 @@ static const struct amic_spi_flash_params amic_spi_flash_table[] = {
static int amic_write(const struct spi_flash *flash, u32 offset, size_t len,
const void *buf)
{
- struct amic_spi_flash *amic = to_amic_spi_flash(flash);
unsigned long byte_addr;
unsigned long page_size;
size_t chunk_len;
@@ -74,7 +61,7 @@ static int amic_write(const struct spi_flash *flash, u32 offset, size_t len,
int ret;
u8 cmd[4];
- page_size = 1 << amic->params->l2_page_size;
+ page_size = flash->page_size;
byte_addr = offset % page_size;
for (actual = 0; actual < len; actual += chunk_len) {
@@ -125,9 +112,8 @@ out:
struct spi_flash *spi_flash_probe_amic(struct spi_slave *spi, u8 *idcode)
{
const struct amic_spi_flash_params *params;
- unsigned page_size;
- struct amic_spi_flash *amic;
unsigned int i;
+ struct spi_flash *flash;
for (i = 0; i < ARRAY_SIZE(amic_spi_flash_table); i++) {
params = &amic_spi_flash_table[i];
@@ -141,32 +127,29 @@ struct spi_flash *spi_flash_probe_amic(struct spi_slave *spi, u8 *idcode)
return NULL;
}
- amic = malloc(sizeof(struct amic_spi_flash));
- if (!amic) {
+ flash = malloc(sizeof(*flash));
+ if (!flash) {
printk(BIOS_WARNING, "SF: Failed to allocate memory\n");
return NULL;
}
- amic->params = params;
- memcpy(&amic->flash.spi, spi, sizeof(*spi));
- amic->flash.name = params->name;
+ memcpy(&flash->spi, spi, sizeof(*spi));
+ flash->name = params->name;
/* Assuming power-of-two page size initially. */
- page_size = 1 << params->l2_page_size;
-
- amic->flash.internal_write = amic_write;
- amic->flash.internal_erase = spi_flash_cmd_erase;
+ 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->erase_cmd = CMD_A25_SE;
+
+ flash->internal_write = amic_write;
+ flash->internal_erase = spi_flash_cmd_erase;
#if CONFIG_SPI_FLASH_NO_FAST_READ
- amic->flash.internal_read = spi_flash_cmd_read_slow;
+ flash->internal_read = spi_flash_cmd_read_slow;
#else
- amic->flash.internal_read = spi_flash_cmd_read_fast;
+ flash->internal_read = spi_flash_cmd_read_fast;
#endif
- amic->flash.sector_size = (1 << amic->params->l2_page_size) *
- amic->params->pages_per_sector;
- amic->flash.size = page_size * params->pages_per_sector
- * params->sectors_per_block
- * params->nr_blocks;
- amic->flash.erase_cmd = CMD_A25_SE;
-
- return &amic->flash;
+
+ return flash;
}
diff --git a/src/drivers/spi/atmel.c b/src/drivers/spi/atmel.c
index 4fe679d036..4f614ff283 100644
--- a/src/drivers/spi/atmel.c
+++ b/src/drivers/spi/atmel.c
@@ -38,18 +38,6 @@ struct atmel_spi_flash_params {
const char *name;
};
-/* spi_flash needs to be first so upper layers can free() it */
-struct atmel_spi_flash {
- struct spi_flash flash;
- const struct atmel_spi_flash_params *params;
-};
-
-static inline struct atmel_spi_flash *
-to_atmel_spi_flash(const struct spi_flash *flash)
-{
- return container_of(flash, struct atmel_spi_flash, flash);
-}
-
static const struct atmel_spi_flash_params atmel_spi_flash_table[] = {
{
.id = 0x3015,
@@ -112,7 +100,6 @@ static const struct atmel_spi_flash_params atmel_spi_flash_table[] = {
static int atmel_write(const struct spi_flash *flash, u32 offset, size_t len,
const void *buf)
{
- struct atmel_spi_flash *stm = to_atmel_spi_flash(flash);
unsigned long byte_addr;
unsigned long page_size;
size_t chunk_len;
@@ -120,7 +107,7 @@ static int atmel_write(const struct spi_flash *flash, u32 offset, size_t len,
int ret;
u8 cmd[4];
- page_size = 1 << stm->params->l2_page_size;
+ page_size = flash->page_size;
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
@@ -170,9 +157,8 @@ out:
struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
{
const struct atmel_spi_flash_params *params;
- unsigned page_size;
- struct atmel_spi_flash *stm;
unsigned int i;
+ struct spi_flash *flash;
for (i = 0; i < ARRAY_SIZE(atmel_spi_flash_table); i++) {
params = &atmel_spi_flash_table[i];
@@ -186,32 +172,29 @@ struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
return NULL;
}
- stm = malloc(sizeof(struct atmel_spi_flash));
- if (!stm) {
+ flash = malloc(sizeof(*flash));
+ if (!flash) {
printk(BIOS_WARNING, "SF: Failed to allocate memory\n");
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;
/* Assuming power-of-two page size initially. */
- page_size = 1 << params->l2_page_size;
-
- stm->flash.internal_write = atmel_write;
- stm->flash.internal_erase = spi_flash_cmd_erase;
+ 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->erase_cmd = CMD_AT25_SE;
+
+ flash->internal_write = atmel_write;
+ flash->internal_erase = spi_flash_cmd_erase;
#if CONFIG_SPI_FLASH_NO_FAST_READ
- stm->flash.internal_read = spi_flash_cmd_read_slow;
+ flash->internal_read = spi_flash_cmd_read_slow;
#else
- stm->flash.internal_read = spi_flash_cmd_read_fast;
+ flash->internal_read = spi_flash_cmd_read_fast;
#endif
- stm->flash.sector_size = (1 << stm->params->l2_page_size) *
- stm->params->pages_per_sector;
- stm->flash.size = page_size * params->pages_per_sector
- * params->sectors_per_block
- * params->nr_blocks;
- stm->flash.erase_cmd = CMD_AT25_SE;
-
- return &stm->flash;
+
+ return flash;
}
diff --git a/src/drivers/spi/eon.c b/src/drivers/spi/eon.c
index 9c1665d480..8ad5f84bc8 100644
--- a/src/drivers/spi/eon.c
+++ b/src/drivers/spi/eon.c
@@ -40,18 +40,6 @@ struct eon_spi_flash_params {
const char *name;
};
-/* spi_flash needs to be first so upper layers can free() it */
-struct eon_spi_flash {
- struct spi_flash flash;
- const struct eon_spi_flash_params *params;
-};
-
-static inline
-struct eon_spi_flash *to_eon_spi_flash(const struct spi_flash *flash)
-{
- return container_of(flash, struct eon_spi_flash, flash);
-}
-
static const struct eon_spi_flash_params eon_spi_flash_table[] = {
{
.id = EON_ID_EN25Q128,
@@ -82,7 +70,6 @@ static const struct eon_spi_flash_params eon_spi_flash_table[] = {
static int eon_write(const struct spi_flash *flash,
u32 offset, size_t len, const void *buf)
{
- struct eon_spi_flash *eon = to_eon_spi_flash(flash);
unsigned long byte_addr;
unsigned long page_size;
size_t chunk_len;
@@ -90,7 +77,7 @@ static int eon_write(const struct spi_flash *flash,
int ret = 0;
u8 cmd[4];
- page_size = 1 << eon->params->page_size;
+ page_size = flash->page_size;
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
@@ -142,7 +129,7 @@ out:
struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode)
{
const struct eon_spi_flash_params *params;
- struct eon_spi_flash *eon;
+ struct spi_flash *flash;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(eon_spi_flash_table); ++i) {
@@ -157,25 +144,25 @@ struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode)
return NULL;
}
- eon = malloc(sizeof(*eon));
- if (!eon) {
+ flash = malloc(sizeof(*flash));
+ if (!flash) {
printk(BIOS_WARNING, "SF: Failed to allocate memory\n");
return NULL;
}
- eon->params = params;
- memcpy(&eon->flash.spi, spi, sizeof(*spi));
- eon->flash.name = params->name;
-
- eon->flash.internal_write = eon_write;
- eon->flash.internal_erase = spi_flash_cmd_erase;
- eon->flash.internal_status = spi_flash_cmd_status;
- eon->flash.internal_read = spi_flash_cmd_read_fast;
- eon->flash.sector_size = params->page_size * params->pages_per_sector;
- eon->flash.size = params->page_size * params->pages_per_sector
- * params->nr_sectors;
- eon->flash.erase_cmd = CMD_EN25_SE;
- eon->flash.status_cmd = CMD_EN25_RDSR;
-
- return &eon->flash;
+ 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 = CMD_EN25_SE;
+ flash->status_cmd = CMD_EN25_RDSR;
+
+ flash->internal_write = eon_write;
+ flash->internal_erase = spi_flash_cmd_erase;
+ flash->internal_status = spi_flash_cmd_status;
+ flash->internal_read = spi_flash_cmd_read_fast;
+
+ return flash;
}
diff --git a/src/drivers/spi/gigadevice.c b/src/drivers/spi/gigadevice.c
index cbc9744614..bd6d6edb28 100644
--- a/src/drivers/spi/gigadevice.c
+++ b/src/drivers/spi/gigadevice.c
@@ -49,18 +49,6 @@ struct gigadevice_spi_flash_params {
const char *name;
};
-/* spi_flash needs to be first so upper layers can free() it */
-struct gigadevice_spi_flash {
- struct spi_flash flash;
- const struct gigadevice_spi_flash_params *params;
-};
-
-static inline struct gigadevice_spi_flash *
-to_gigadevice_spi_flash(const struct spi_flash *flash)
-{
- return container_of(flash, struct gigadevice_spi_flash, flash);
-}
-
static const struct gigadevice_spi_flash_params gigadevice_spi_flash_table[] = {
{
.id = 0x4014,
@@ -123,7 +111,6 @@ static const struct gigadevice_spi_flash_params gigadevice_spi_flash_table[] = {
static int gigadevice_write(const struct spi_flash *flash, u32 offset,
size_t len, const void *buf)
{
- struct gigadevice_spi_flash *stm = to_gigadevice_spi_flash(flash);
unsigned long byte_addr;
unsigned long page_size;
size_t chunk_len;
@@ -131,7 +118,7 @@ static int gigadevice_write(const struct spi_flash *flash, u32 offset,
int ret = 0;
u8 cmd[4];
- page_size = 1 << stm->params->l2_page_size;
+ page_size = flash->page_size;
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
@@ -183,12 +170,11 @@ out:
return ret;
}
-static struct gigadevice_spi_flash stm;
+static struct spi_flash flash;
struct spi_flash *spi_flash_probe_gigadevice(struct spi_slave *spi, u8 *idcode)
{
const struct gigadevice_spi_flash_params *params;
- unsigned page_size;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(gigadevice_spi_flash_table); i++) {
@@ -204,28 +190,25 @@ struct spi_flash *spi_flash_probe_gigadevice(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;
/* Assuming power-of-two page size initially. */
- page_size = 1 << params->l2_page_size;
-
- stm.flash.internal_write = gigadevice_write;
- stm.flash.internal_erase = spi_flash_cmd_erase;
- stm.flash.internal_status = spi_flash_cmd_status;
+ 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.erase_cmd = CMD_GD25_SE;
+ flash.status_cmd = CMD_GD25_RDSR;
+
+ flash.internal_write = gigadevice_write;
+ flash.internal_erase = spi_flash_cmd_erase;
+ flash.internal_status = spi_flash_cmd_status;
#if CONFIG_SPI_FLASH_NO_FAST_READ
- stm.flash.internal_read = spi_flash_cmd_read_slow;
+ flash.internal_read = spi_flash_cmd_read_slow;
#else
- stm.flash.internal_read = spi_flash_cmd_read_fast;
+ flash.internal_read = spi_flash_cmd_read_fast;
#endif
- stm.flash.sector_size = (1 << stm.params->l2_page_size) *
- stm.params->pages_per_sector;
- stm.flash.size = page_size * params->pages_per_sector
- * params->sectors_per_block
- * params->nr_blocks;
- stm.flash.erase_cmd = CMD_GD25_SE;
- stm.flash.status_cmd = CMD_GD25_RDSR;
-
- return &stm.flash;
+
+ return &flash;
}
diff --git a/src/drivers/spi/macronix.c b/src/drivers/spi/macronix.c
index 07d1e5624d..6e17719fa8 100644
--- a/src/drivers/spi/macronix.c
+++ b/src/drivers/spi/macronix.c
@@ -54,17 +54,6 @@ struct macronix_spi_flash_params {
const char *name;
};
-struct macronix_spi_flash {
- struct spi_flash flash;
- const struct macronix_spi_flash_params *params;
-};
-
-static inline
-struct macronix_spi_flash *to_macronix_spi_flash(const struct spi_flash *flash)
-{
- return container_of(flash, struct macronix_spi_flash, flash);
-}
-
static const struct macronix_spi_flash_params macronix_spi_flash_table[] = {
{
.idcode = 0x2015,
@@ -151,7 +140,6 @@ static const struct macronix_spi_flash_params macronix_spi_flash_table[] = {
static int macronix_write(const struct spi_flash *flash, u32 offset, size_t len,
const void *buf)
{
- struct macronix_spi_flash *mcx = to_macronix_spi_flash(flash);
unsigned long byte_addr;
unsigned long page_size;
size_t chunk_len;
@@ -159,7 +147,7 @@ static int macronix_write(const struct spi_flash *flash, u32 offset, size_t len,
int ret = 0;
u8 cmd[4];
- page_size = mcx->params->page_size;
+ page_size = flash->page_size;
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
@@ -204,7 +192,7 @@ static int macronix_write(const struct spi_flash *flash, u32 offset, size_t len,
return ret;
}
-static struct macronix_spi_flash mcx;
+static struct spi_flash flash;
struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
{
@@ -223,23 +211,23 @@ struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
return NULL;
}
- mcx.params = params;
- memcpy(&mcx.flash.spi, spi, sizeof(*spi));
- mcx.flash.name = params->name;
-
- mcx.flash.internal_write = macronix_write;
- mcx.flash.internal_erase = spi_flash_cmd_erase;
- mcx.flash.internal_status = spi_flash_cmd_status;
+ 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->sectors_per_block *
+ params->nr_blocks;
+ flash.erase_cmd = CMD_MX25XX_SE;
+ flash.status_cmd = CMD_MX25XX_RDSR;
+
+ flash.internal_write = macronix_write;
+ flash.internal_erase = spi_flash_cmd_erase;
+ flash.internal_status = spi_flash_cmd_status;
#if CONFIG_SPI_FLASH_NO_FAST_READ
- mcx.flash.internal_read = spi_flash_cmd_read_slow;
+ flash.internal_read = spi_flash_cmd_read_slow;
#else
- mcx.flash.internal_read = spi_flash_cmd_read_fast;
+ flash.internal_read = spi_flash_cmd_read_fast;
#endif
- mcx.flash.sector_size = params->page_size * params->pages_per_sector;
- mcx.flash.size = mcx.flash.sector_size * params->sectors_per_block *
- params->nr_blocks;
- mcx.flash.erase_cmd = CMD_MX25XX_SE;
- mcx.flash.status_cmd = CMD_MX25XX_RDSR;
- return &mcx.flash;
+ return &flash;
}
diff --git a/src/drivers/spi/spansion.c b/src/drivers/spi/spansion.c
index 139e8239a0..8f9e96687d 100644
--- a/src/drivers/spi/spansion.c
+++ b/src/drivers/spi/spansion.c
@@ -64,17 +64,6 @@ struct spansion_spi_flash_params {
const char *name;
};
-struct spansion_spi_flash {
- struct spi_flash flash;
- const struct spansion_spi_flash_params *params;
-};
-
-static inline
-struct spansion_spi_flash *to_spansion_spi_flash(const struct spi_flash *flash)
-{
- return container_of(flash, struct spansion_spi_flash, flash);
-}
-
/*
* returns non-zero if the given idcode matches the ID of the chip. this is for
* chips which use 2nd, 3rd, 4th, and 5th byte.
@@ -204,7 +193,6 @@ static const struct spansion_spi_flash_params spansion_spi_flash_table[] = {
static int spansion_write(const struct spi_flash *flash, u32 offset, size_t len,
const void *buf)
{
- struct spansion_spi_flash *spsn = to_spansion_spi_flash(flash);
unsigned long byte_addr;
unsigned long page_size;
size_t chunk_len;
@@ -212,7 +200,7 @@ static int spansion_write(const struct spi_flash *flash, u32 offset, size_t len,
int ret = 0;
u8 cmd[4];
- page_size = spsn->params->page_size;
+ page_size = flash->page_size;
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
@@ -258,12 +246,11 @@ static int spansion_write(const struct spi_flash *flash, u32 offset, size_t len,
return ret;
}
-static struct spansion_spi_flash spsn_flash;
+static struct spi_flash flash;
struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
{
const struct spansion_spi_flash_params *params;
- struct spansion_spi_flash *spsn;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(spansion_spi_flash_table); i++) {
@@ -279,20 +266,18 @@ struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
return NULL;
}
- spsn = &spsn_flash;
-
- spsn->params = params;
- memcpy(&spsn->flash.spi, spi, sizeof(*spi));
- spsn->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 = CMD_S25FLXX_SE;
+ flash.status_cmd = CMD_S25FLXX_RDSR;
- spsn->flash.internal_write = spansion_write;
- spsn->flash.internal_erase = spi_flash_cmd_erase;
- spsn->flash.internal_read = spi_flash_cmd_read_slow;
- spsn->flash.internal_status = spi_flash_cmd_status;
- spsn->flash.sector_size = params->page_size * params->pages_per_sector;
- spsn->flash.size = spsn->flash.sector_size * params->nr_sectors;
- spsn->flash.erase_cmd = CMD_S25FLXX_SE;
- spsn->flash.status_cmd = CMD_S25FLXX_RDSR;
+ flash.internal_write = spansion_write;
+ flash.internal_erase = spi_flash_cmd_erase;
+ flash.internal_read = spi_flash_cmd_read_slow;
+ flash.internal_status = spi_flash_cmd_status;
- return &spsn->flash;
+ return &flash;
}
diff --git a/src/drivers/spi/sst.c b/src/drivers/spi/sst.c
index c9762accf5..0683846ce9 100644
--- a/src/drivers/spi/sst.c
+++ b/src/drivers/spi/sst.c
@@ -47,11 +47,6 @@ struct sst_spi_flash_params {
size_t len, const void *buf);
};
-struct sst_spi_flash {
- struct spi_flash flash;
- const struct sst_spi_flash_params *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,
@@ -323,7 +318,7 @@ struct spi_flash *
spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode)
{
const struct sst_spi_flash_params *params;
- struct sst_spi_flash *stm;
+ struct spi_flash *flash;
size_t i;
for (i = 0; i < ARRAY_SIZE(sst_spi_flash_table); ++i) {
@@ -337,27 +332,26 @@ spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode)
return NULL;
}
- stm = malloc(sizeof(*stm));
- if (!stm) {
+ flash = malloc(sizeof(*flash));
+ if (!flash) {
printk(BIOS_WARNING, "SF: Failed to allocate memory\n");
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->sector_size = SST_SECTOR_SIZE;
+ flash->size = flash->sector_size * params->nr_sectors;
+ flash->erase_cmd = CMD_SST_SE;
+ flash->status_cmd = CMD_SST_RDSR;
- 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;
- stm->flash.status_cmd = CMD_SST_RDSR;
+ flash->internal_write = params->write;
+ flash->internal_erase = spi_flash_cmd_erase;
+ flash->internal_status = spi_flash_cmd_status;
+ flash->internal_read = spi_flash_cmd_read_fast;
/* Flash powers up read-only, so clear BP# bits */
- sst_unlock(&stm->flash);
+ sst_unlock(flash);
- return &stm->flash;
+ return flash;
}
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;
}
diff --git a/src/drivers/spi/winbond.c b/src/drivers/spi/winbond.c
index 25a7b5bd32..3f167c0d06 100644
--- a/src/drivers/spi/winbond.c
+++ b/src/drivers/spi/winbond.c
@@ -36,18 +36,6 @@ struct winbond_spi_flash_params {
const char *name;
};
-/* spi_flash needs to be first so upper layers can free() it */
-struct winbond_spi_flash {
- struct spi_flash flash;
- const struct winbond_spi_flash_params *params;
-};
-
-static inline struct winbond_spi_flash *
-to_winbond_spi_flash(const struct spi_flash *flash)
-{
- return container_of(flash, struct winbond_spi_flash, flash);
-}
-
static const struct winbond_spi_flash_params winbond_spi_flash_table[] = {
{
.id = 0x3015,
@@ -142,7 +130,6 @@ static const struct winbond_spi_flash_params winbond_spi_flash_table[] = {
static int winbond_write(const struct spi_flash *flash, u32 offset, size_t len,
const void *buf)
{
- struct winbond_spi_flash *stm = to_winbond_spi_flash(flash);
unsigned long byte_addr;
unsigned long page_size;
size_t chunk_len;
@@ -150,7 +137,7 @@ static int winbond_write(const struct spi_flash *flash, u32 offset, size_t len,
int ret = 0;
u8 cmd[4];
- page_size = 1 << stm->params->l2_page_size;
+ page_size = flash->page_size;
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
@@ -197,12 +184,11 @@ out:
return ret;
}
-static struct winbond_spi_flash stm;
+static struct spi_flash flash;
struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
{
const struct winbond_spi_flash_params *params;
- unsigned page_size;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(winbond_spi_flash_table); i++) {
@@ -217,28 +203,24 @@ struct spi_flash *spi_flash_probe_winbond(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;
/* Assuming power-of-two page size initially. */
- page_size = 1 << params->l2_page_size;
-
- stm.flash.internal_write = winbond_write;
- stm.flash.internal_erase = spi_flash_cmd_erase;
- stm.flash.internal_status = spi_flash_cmd_status;
+ 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.erase_cmd = CMD_W25_SE;
+ flash.status_cmd = CMD_W25_RDSR;
+
+ flash.internal_write = winbond_write;
+ flash.internal_erase = spi_flash_cmd_erase;
+ flash.internal_status = spi_flash_cmd_status;
#if CONFIG_SPI_FLASH_NO_FAST_READ
- stm.flash.internal_read = spi_flash_cmd_read_slow;
+ flash.internal_read = spi_flash_cmd_read_slow;
#else
- stm.flash.internal_read = spi_flash_cmd_read_fast;
+ flash.internal_read = spi_flash_cmd_read_fast;
#endif
- stm.flash.sector_size = (1 << stm.params->l2_page_size) *
- stm.params->pages_per_sector;
- stm.flash.size = page_size * params->pages_per_sector
- * params->sectors_per_block
- * params->nr_blocks;
- stm.flash.erase_cmd = CMD_W25_SE;
- stm.flash.status_cmd = CMD_W25_RDSR;
-
- return &stm.flash;
+
+ return &flash;
}