summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/intel/fsp1_0/fastboot_cache.c9
-rw-r--r--src/drivers/spi/adesto.c14
-rw-r--r--src/drivers/spi/amic.c14
-rw-r--r--src/drivers/spi/atmel.c14
-rw-r--r--src/drivers/spi/boot_device_rw_nommap.c23
-rw-r--r--src/drivers/spi/cbfs_spi.c25
-rw-r--r--src/drivers/spi/eon.c14
-rw-r--r--src/drivers/spi/gigadevice.c33
-rw-r--r--src/drivers/spi/macronix.c33
-rw-r--r--src/drivers/spi/spansion.c31
-rw-r--r--src/drivers/spi/spi_flash.c48
-rw-r--r--src/drivers/spi/spi_flash_internal.h34
-rw-r--r--src/drivers/spi/sst.c15
-rw-r--r--src/drivers/spi/stmicro.c31
-rw-r--r--src/drivers/spi/winbond.c33
15 files changed, 181 insertions, 190 deletions
diff --git a/src/drivers/intel/fsp1_0/fastboot_cache.c b/src/drivers/intel/fsp1_0/fastboot_cache.c
index b57f382b27..906b356b90 100644
--- a/src/drivers/intel/fsp1_0/fastboot_cache.c
+++ b/src/drivers/intel/fsp1_0/fastboot_cache.c
@@ -157,6 +157,7 @@ void update_mrc_cache(void *unused)
struct mrc_data_container *current = cbmem_find(CBMEM_ID_MRCDATA);
struct mrc_data_container *cache, *cache_base;
u32 cache_size;
+ struct spi_flash flash;
if (!current) {
printk(BIOS_ERR, "No fast boot cache in cbmem. Can't update flash.\n");
@@ -189,8 +190,7 @@ void update_mrc_cache(void *unused)
/* 1. use spi_flash_probe() to find the flash, then... */
spi_init();
- struct spi_flash *flash = spi_flash_probe(0, 0);
- if (!flash) {
+ if (spi_flash_probe(0, 0, &flash)) {
printk(BIOS_DEBUG, "Could not find SPI device\n");
return;
}
@@ -209,7 +209,8 @@ void update_mrc_cache(void *unused)
"Need to erase the MRC cache region of %d bytes at %p\n",
cache_size, cache_base);
- spi_flash_erase(flash, to_flash_offset(cache_base), cache_size);
+ spi_flash_erase(&flash, to_flash_offset(cache_base),
+ cache_size);
/* we will start at the beginning again */
cache = cache_base;
@@ -217,7 +218,7 @@ void update_mrc_cache(void *unused)
/* 4. write mrc data with spi_flash_write() */
printk(BIOS_DEBUG, "Write MRC cache update to flash at %p\n",
cache);
- spi_flash_write(flash, to_flash_offset(cache),
+ spi_flash_write(&flash, to_flash_offset(cache),
current->mrc_data_size + sizeof(*current), current);
}
diff --git a/src/drivers/spi/adesto.c b/src/drivers/spi/adesto.c
index c5c68b546b..d062c36594 100644
--- a/src/drivers/spi/adesto.c
+++ b/src/drivers/spi/adesto.c
@@ -126,10 +126,10 @@ out:
return ret;
}
-struct spi_flash *spi_flash_probe_adesto(struct spi_slave *spi, u8 *idcode)
+int spi_flash_probe_adesto(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash)
{
const struct adesto_spi_flash_params *params;
- struct spi_flash *flash;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(adesto_spi_flash_table); i++) {
@@ -141,13 +141,7 @@ struct spi_flash *spi_flash_probe_adesto(struct spi_slave *spi, u8 *idcode)
if (i == ARRAY_SIZE(adesto_spi_flash_table)) {
printk(BIOS_WARNING, "SF: Unsupported adesto ID %02x%02x\n",
idcode[1], idcode[2]);
- return NULL;
- }
-
- flash = malloc(sizeof(*flash));
- if (!flash) {
- printk(BIOS_WARNING, "SF: Failed to allocate memory\n");
- return NULL;
+ return -1;
}
memcpy(&flash->spi, spi, sizeof(*spi));
@@ -167,5 +161,5 @@ struct spi_flash *spi_flash_probe_adesto(struct spi_slave *spi, u8 *idcode)
flash->internal_read = spi_flash_cmd_read_fast;
#endif
- return flash;
+ return 0;
}
diff --git a/src/drivers/spi/amic.c b/src/drivers/spi/amic.c
index 60843608f5..cf5a29601d 100644
--- a/src/drivers/spi/amic.c
+++ b/src/drivers/spi/amic.c
@@ -109,11 +109,11 @@ out:
return ret;
}
-struct spi_flash *spi_flash_probe_amic(struct spi_slave *spi, u8 *idcode)
+int spi_flash_probe_amic(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash)
{
const struct amic_spi_flash_params *params;
unsigned int i;
- struct spi_flash *flash;
for (i = 0; i < ARRAY_SIZE(amic_spi_flash_table); i++) {
params = &amic_spi_flash_table[i];
@@ -124,13 +124,7 @@ struct spi_flash *spi_flash_probe_amic(struct spi_slave *spi, u8 *idcode)
if (i == ARRAY_SIZE(amic_spi_flash_table)) {
printk(BIOS_WARNING, "SF: Unsupported AMIC ID %02x%02x\n",
idcode[1], idcode[2]);
- return NULL;
- }
-
- flash = malloc(sizeof(*flash));
- if (!flash) {
- printk(BIOS_WARNING, "SF: Failed to allocate memory\n");
- return NULL;
+ return -1;
}
memcpy(&flash->spi, spi, sizeof(*spi));
@@ -151,5 +145,5 @@ struct spi_flash *spi_flash_probe_amic(struct spi_slave *spi, u8 *idcode)
flash->internal_read = spi_flash_cmd_read_fast;
#endif
- return flash;
+ return 0;
}
diff --git a/src/drivers/spi/atmel.c b/src/drivers/spi/atmel.c
index 4f614ff283..edc172e65f 100644
--- a/src/drivers/spi/atmel.c
+++ b/src/drivers/spi/atmel.c
@@ -154,11 +154,11 @@ out:
return ret;
}
-struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
+int spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash)
{
const struct atmel_spi_flash_params *params;
unsigned int i;
- struct spi_flash *flash;
for (i = 0; i < ARRAY_SIZE(atmel_spi_flash_table); i++) {
params = &atmel_spi_flash_table[i];
@@ -169,13 +169,7 @@ struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
if (i == ARRAY_SIZE(atmel_spi_flash_table)) {
printk(BIOS_WARNING, "SF: Unsupported Atmel ID %02x%02x\n",
idcode[1], idcode[2]);
- return NULL;
- }
-
- flash = malloc(sizeof(*flash));
- if (!flash) {
- printk(BIOS_WARNING, "SF: Failed to allocate memory\n");
- return NULL;
+ return -1;
}
memcpy(&flash->spi, spi, sizeof(*spi));
@@ -196,5 +190,5 @@ struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
flash->internal_read = spi_flash_cmd_read_fast;
#endif
- return flash;
+ return 0;
}
diff --git a/src/drivers/spi/boot_device_rw_nommap.c b/src/drivers/spi/boot_device_rw_nommap.c
index e7d9b9a944..64d81c5b00 100644
--- a/src/drivers/spi/boot_device_rw_nommap.c
+++ b/src/drivers/spi/boot_device_rw_nommap.c
@@ -17,13 +17,15 @@
#include <boot_device.h>
#include <spi_flash.h>
#include <spi-generic.h>
+#include <stdint.h>
-static struct spi_flash *sfg CAR_GLOBAL;
+static struct spi_flash sfg CAR_GLOBAL;
+static bool sfg_init_done CAR_GLOBAL;
static ssize_t spi_readat(const struct region_device *rd, void *b,
size_t offset, size_t size)
{
- struct spi_flash *sf = car_get_var(sfg);
+ struct spi_flash *sf = car_get_var_ptr(&sfg);
if (sf == NULL)
return -1;
@@ -37,7 +39,7 @@ static ssize_t spi_readat(const struct region_device *rd, void *b,
static ssize_t spi_writeat(const struct region_device *rd, const void *b,
size_t offset, size_t size)
{
- struct spi_flash *sf = car_get_var(sfg);
+ struct spi_flash *sf = car_get_var_ptr(&sfg);
if (sf == NULL)
return -1;
@@ -51,7 +53,7 @@ static ssize_t spi_writeat(const struct region_device *rd, const void *b,
static ssize_t spi_eraseat(const struct region_device *rd,
size_t offset, size_t size)
{
- struct spi_flash *sf = car_get_var(sfg);
+ struct spi_flash *sf = car_get_var_ptr(&sfg);
if (sf == NULL)
return -1;
@@ -76,13 +78,14 @@ static void boot_device_rw_init(void)
const int bus = CONFIG_BOOT_DEVICE_SPI_FLASH_BUS;
const int cs = 0;
- if (car_get_var(sfg) != NULL)
+ if (car_get_var(sfg_init_done) == true)
return;
/* Ensure any necessary setup is performed by the drivers. */
spi_init();
- car_set_var(sfg, spi_flash_probe(bus, cs));
+ if (!spi_flash_probe(bus, cs, car_get_var_ptr(&sfg)))
+ car_set_var(sfg_init_done, true);
}
const struct region_device *boot_device_rw(void)
@@ -90,7 +93,7 @@ const struct region_device *boot_device_rw(void)
/* Probe for the SPI flash device if not already done. */
boot_device_rw_init();
- if (car_get_var(sfg) == NULL)
+ if (car_get_var(sfg_init_done) != true)
return NULL;
return &spi_rw;
@@ -99,5 +102,9 @@ const struct region_device *boot_device_rw(void)
const struct spi_flash *boot_device_spi_flash(void)
{
boot_device_rw_init();
- return car_get_var(sfg);
+
+ if (car_get_var(sfg_init_done) != true)
+ return NULL;
+
+ return car_get_var_ptr(&sfg);
}
diff --git a/src/drivers/spi/cbfs_spi.c b/src/drivers/spi/cbfs_spi.c
index ae2994c257..3e5f2af889 100644
--- a/src/drivers/spi/cbfs_spi.c
+++ b/src/drivers/spi/cbfs_spi.c
@@ -24,9 +24,11 @@
#include <spi_flash.h>
#include <symbols.h>
#include <cbmem.h>
+#include <stdint.h>
#include <timer.h>
-static struct spi_flash *spi_flash_info;
+static struct spi_flash spi_flash_info;
+static bool spi_flash_init_done;
/*
* Set this to 1 to debug SPI speed, 0 to disable it
@@ -47,7 +49,7 @@ static ssize_t spi_readat(const struct region_device *rd, void *b,
if (show)
stopwatch_init(&sw);
- if (spi_flash_read(spi_flash_info, offset, size, b))
+ if (spi_flash_read(&spi_flash_info, offset, size, b))
return -1;
if (show) {
long usecs;
@@ -68,7 +70,7 @@ static ssize_t spi_readat(const struct region_device *rd, void *b,
static ssize_t spi_writeat(const struct region_device *rd, const void *b,
size_t offset, size_t size)
{
- if (spi_flash_write(spi_flash_info, offset, size, b))
+ if (spi_flash_write(&spi_flash_info, offset, size, b))
return -1;
return size;
}
@@ -76,7 +78,7 @@ static ssize_t spi_writeat(const struct region_device *rd, const void *b,
static ssize_t spi_eraseat(const struct region_device *rd,
size_t offset, size_t size)
{
- if (spi_flash_erase(spi_flash_info, offset, size))
+ if (spi_flash_erase(&spi_flash_info, offset, size))
return -1;
return size;
}
@@ -112,10 +114,13 @@ void boot_device_init(void)
int bus = CONFIG_BOOT_DEVICE_SPI_FLASH_BUS;
int cs = 0;
- if (spi_flash_info != NULL)
+ if (spi_flash_init_done == true)
return;
- spi_flash_info = spi_flash_probe(bus, cs);
+ if (spi_flash_probe(bus, cs, &spi_flash_info))
+ return;
+
+ spi_flash_init_done = true;
mmap_helper_device_init(&mdev, _cbfs_cache, _cbfs_cache_size);
}
@@ -123,7 +128,7 @@ void boot_device_init(void)
/* Return the CBFS boot device. */
const struct region_device *boot_device_ro(void)
{
- if (spi_flash_info == NULL)
+ if (spi_flash_init_done != true)
return NULL;
return &mdev.rdev;
@@ -138,5 +143,9 @@ const struct region_device *boot_device_rw(void)
const struct spi_flash *boot_device_spi_flash(void)
{
boot_device_init();
- return spi_flash_info;
+
+ if (spi_flash_init_done != true)
+ return NULL;
+
+ return &spi_flash_info;
}
diff --git a/src/drivers/spi/eon.c b/src/drivers/spi/eon.c
index 8ad5f84bc8..f5a3af6892 100644
--- a/src/drivers/spi/eon.c
+++ b/src/drivers/spi/eon.c
@@ -126,10 +126,10 @@ out:
return ret;
}
-struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode)
+int spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash)
{
const struct eon_spi_flash_params *params;
- struct spi_flash *flash;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(eon_spi_flash_table); ++i) {
@@ -141,13 +141,7 @@ struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode)
if (i == ARRAY_SIZE(eon_spi_flash_table)) {
printk(BIOS_WARNING, "SF: Unsupported EON ID %#02x%02x\n",
idcode[1], idcode[2]);
- return NULL;
- }
-
- flash = malloc(sizeof(*flash));
- if (!flash) {
- printk(BIOS_WARNING, "SF: Failed to allocate memory\n");
- return NULL;
+ return -1;
}
memcpy(&flash->spi, spi, sizeof(*spi));
@@ -164,5 +158,5 @@ struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode)
flash->internal_status = spi_flash_cmd_status;
flash->internal_read = spi_flash_cmd_read_fast;
- return flash;
+ return 0;
}
diff --git a/src/drivers/spi/gigadevice.c b/src/drivers/spi/gigadevice.c
index bd6d6edb28..0b7173d608 100644
--- a/src/drivers/spi/gigadevice.c
+++ b/src/drivers/spi/gigadevice.c
@@ -170,9 +170,8 @@ out:
return ret;
}
-static struct spi_flash flash;
-
-struct spi_flash *spi_flash_probe_gigadevice(struct spi_slave *spi, u8 *idcode)
+int spi_flash_probe_gigadevice(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash)
{
const struct gigadevice_spi_flash_params *params;
unsigned int i;
@@ -187,28 +186,28 @@ struct spi_flash *spi_flash_probe_gigadevice(struct spi_slave *spi, u8 *idcode)
printk(BIOS_WARNING,
"SF gigadevice.c: Unsupported ID %#02x%02x\n",
idcode[1], idcode[2]);
- return NULL;
+ return -1;
}
- memcpy(&flash.spi, spi, sizeof(*spi));
- flash.name = params->name;
+ memcpy(&flash->spi, spi, sizeof(*spi));
+ 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 *
+ 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->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;
+ 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
- flash.internal_read = spi_flash_cmd_read_slow;
+ flash->internal_read = spi_flash_cmd_read_slow;
#else
- flash.internal_read = spi_flash_cmd_read_fast;
+ flash->internal_read = spi_flash_cmd_read_fast;
#endif
- return &flash;
+ return 0;
}
diff --git a/src/drivers/spi/macronix.c b/src/drivers/spi/macronix.c
index 6e17719fa8..87b6fd7c42 100644
--- a/src/drivers/spi/macronix.c
+++ b/src/drivers/spi/macronix.c
@@ -192,9 +192,8 @@ static int macronix_write(const struct spi_flash *flash, u32 offset, size_t len,
return ret;
}
-static struct spi_flash flash;
-
-struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
+int spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash)
{
const struct macronix_spi_flash_params *params;
unsigned int i;
@@ -208,26 +207,26 @@ struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
if (i == ARRAY_SIZE(macronix_spi_flash_table)) {
printk(BIOS_WARNING, "SF: Unsupported Macronix ID %04x\n", id);
- return NULL;
+ return -1;
}
- 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 *
+ 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->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;
+ 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
- flash.internal_read = spi_flash_cmd_read_slow;
+ flash->internal_read = spi_flash_cmd_read_slow;
#else
- flash.internal_read = spi_flash_cmd_read_fast;
+ flash->internal_read = spi_flash_cmd_read_fast;
#endif
- return &flash;
+ return 0;
}
diff --git a/src/drivers/spi/spansion.c b/src/drivers/spi/spansion.c
index 8f9e96687d..a376b6e0a4 100644
--- a/src/drivers/spi/spansion.c
+++ b/src/drivers/spi/spansion.c
@@ -246,9 +246,8 @@ static int spansion_write(const struct spi_flash *flash, u32 offset, size_t len,
return ret;
}
-static struct spi_flash flash;
-
-struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
+int spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash)
{
const struct spansion_spi_flash_params *params;
unsigned int i;
@@ -263,21 +262,21 @@ struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
printk(BIOS_WARNING,
"SF: Unsupported SPANSION ID %02x %02x %02x %02x %02x\n",
idcode[0], idcode[1], idcode[2], idcode[3], idcode[4]);
- return NULL;
+ return -1;
}
- 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;
+ 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;
- 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;
+ 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 &flash;
+ return 0;
}
diff --git a/src/drivers/spi/spi_flash.c b/src/drivers/spi/spi_flash.c
index e84df73c29..701033aaf3 100644
--- a/src/drivers/spi/spi_flash.c
+++ b/src/drivers/spi/spi_flash.c
@@ -240,7 +240,8 @@ int spi_flash_cmd_status(const struct spi_flash *flash, u8 *reg)
static struct {
const u8 shift;
const u8 idcode;
- struct spi_flash *(*probe) (struct spi_slave *spi, u8 *idcode);
+ int (*probe) (struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash);
} flashes[] = {
/* Keep it sorted by define name */
#if CONFIG_SPI_FLASH_AMIC
@@ -280,24 +281,24 @@ static struct {
};
#define IDCODE_LEN (IDCODE_CONT_LEN + IDCODE_PART_LEN)
-struct spi_flash *
+int
__attribute__((weak)) spi_flash_programmer_probe(struct spi_slave *spi,
- int force)
+ int force,
+ struct spi_flash *flash)
{
/* Default weak implementation. Do nothing. */
- return NULL;
+ return -1;
}
-static struct spi_flash *__spi_flash_probe(struct spi_slave *spi)
+static int __spi_flash_probe(struct spi_slave *spi, struct spi_flash *flash)
{
int ret, i, shift;
u8 idcode[IDCODE_LEN], *idp;
- struct spi_flash *flash = NULL;
/* Read the ID codes */
ret = spi_flash_cmd(spi, CMD_READ_ID, idcode, sizeof(idcode));
if (ret)
- return NULL;
+ return -1;
if (IS_ENABLED(CONFIG_DEBUG_SPI_FLASH)) {
printk(BIOS_SPEW, "SF: Got idcode: ");
@@ -317,45 +318,44 @@ static struct spi_flash *__spi_flash_probe(struct spi_slave *spi)
for (i = 0; i < ARRAY_SIZE(flashes); ++i)
if (flashes[i].shift == shift && flashes[i].idcode == *idp) {
/* we have a match, call probe */
- flash = flashes[i].probe(spi, idp);
- if (flash)
- break;
+ if (flashes[i].probe(spi, idp, flash) == 0)
+ return 0;
}
- return flash;
+ /* No match, return error. */
+ return -1;
}
-struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs)
+int spi_flash_probe(unsigned int bus, unsigned int cs, struct spi_flash *flash)
{
struct spi_slave spi;
- struct spi_flash *flash;
if (spi_setup_slave(bus, cs, &spi)) {
printk(BIOS_WARNING, "SF: Failed to set up slave\n");
- return NULL;
+ return -1;
}
/* Try special programmer probe if any (without force). */
- flash = spi_flash_programmer_probe(&spi, 0);
+ if (spi_flash_programmer_probe(&spi, 0, flash) == 0)
+ goto flash_found;
/* If flash is not found, try generic spi flash probe. */
- if (!flash)
- flash = __spi_flash_probe(&spi);
+ if (__spi_flash_probe(&spi, flash) == 0)
+ goto flash_found;
/* If flash is not yet found, force special programmer probe if any. */
- if (!flash)
- flash = spi_flash_programmer_probe(&spi, 1);
+ if (spi_flash_programmer_probe(&spi, 1, flash) == 0)
+ goto flash_found;
/* Give up -- nothing more to try if flash is not found. */
- if (!flash) {
- printk(BIOS_WARNING, "SF: Unsupported manufacturer!\n");
- return NULL;
- }
+ printk(BIOS_WARNING, "SF: Unsupported manufacturer!\n");
+ return -1;
+flash_found:
printk(BIOS_INFO, "SF: Detected %s with sector size 0x%x, total 0x%x\n",
flash->name, flash->sector_size, flash->size);
- return flash;
+ return 0;
}
int spi_flash_read(const struct spi_flash *flash, u32 offset, size_t len,
diff --git a/src/drivers/spi/spi_flash_internal.h b/src/drivers/spi/spi_flash_internal.h
index 9b517238b2..4ad0b09ca3 100644
--- a/src/drivers/spi/spi_flash_internal.h
+++ b/src/drivers/spi/spi_flash_internal.h
@@ -64,17 +64,27 @@ int spi_flash_cmd_erase(const struct spi_flash *flash, u32 offset, size_t len);
int spi_flash_cmd_status(const struct spi_flash *flash, u8 *reg);
/* Manufacturer-specific probe functions */
-struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode);
-struct spi_flash *spi_flash_probe_amic(struct spi_slave *spi, u8 *idcode);
-struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode);
-struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode);
-struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode);
-struct spi_flash *spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode);
-struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 *idcode);
-struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode);
-struct spi_flash *spi_flash_probe_gigadevice(struct spi_slave *spi,
- u8 *idcode);
-struct spi_flash *spi_flash_probe_adesto(struct spi_slave *spi, u8 *idcode);
-struct spi_flash *spi_fram_probe_ramtron(struct spi_slave *spi, u8 *idcode);
+int spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash);
+int spi_flash_probe_amic(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash);
+int spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash);
+int spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash);
+int spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash);
+int spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash);
+int spi_flash_probe_stmicro(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash);
+int spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash);
+int spi_flash_probe_gigadevice(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash);
+int spi_flash_probe_adesto(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash);
+int spi_fram_probe_ramtron(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash);
#endif /* SPI_FLASH_INTERNAL_H */
diff --git a/src/drivers/spi/sst.c b/src/drivers/spi/sst.c
index 0683846ce9..bf211571e1 100644
--- a/src/drivers/spi/sst.c
+++ b/src/drivers/spi/sst.c
@@ -314,11 +314,10 @@ sst_unlock(const struct spi_flash *flash)
return ret;
}
-struct spi_flash *
-spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode)
+int spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash)
{
const struct sst_spi_flash_params *params;
- struct spi_flash *flash;
size_t i;
for (i = 0; i < ARRAY_SIZE(sst_spi_flash_table); ++i) {
@@ -329,13 +328,7 @@ spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode)
if (i == ARRAY_SIZE(sst_spi_flash_table)) {
printk(BIOS_WARNING, "SF: Unsupported SST ID %02x\n", idcode[1]);
- return NULL;
- }
-
- flash = malloc(sizeof(*flash));
- if (!flash) {
- printk(BIOS_WARNING, "SF: Failed to allocate memory\n");
- return NULL;
+ return -1;
}
memcpy(&flash->spi, spi, sizeof(*spi));
@@ -353,5 +346,5 @@ spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode)
/* Flash powers up read-only, so clear BP# bits */
sst_unlock(flash);
- return flash;
+ return 0;
}
diff --git a/src/drivers/spi/stmicro.c b/src/drivers/spi/stmicro.c
index 2ec9f18376..b7ceba21a8 100644
--- a/src/drivers/spi/stmicro.c
+++ b/src/drivers/spi/stmicro.c
@@ -222,9 +222,8 @@ out:
return ret;
}
-static struct spi_flash flash;
-
-struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
+int spi_flash_probe_stmicro(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash)
{
const struct stmicro_spi_flash_params *params;
unsigned int i;
@@ -232,13 +231,13 @@ struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
if (idcode[0] == 0xff) {
i = spi_flash_cmd(spi, CMD_M25PXX_RES, idcode, 4);
if (i)
- return NULL;
+ return -1;
if ((idcode[3] & 0xf0) == 0x10) {
idcode[0] = 0x20;
idcode[1] = 0x20;
idcode[2] = idcode[3] + 1;
} else
- return NULL;
+ return -1;
}
for (i = 0; i < ARRAY_SIZE(stmicro_spi_flash_table); i++) {
@@ -251,19 +250,19 @@ struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
if (i == ARRAY_SIZE(stmicro_spi_flash_table)) {
printk(BIOS_WARNING, "SF: Unsupported STMicro ID %02x%02x\n",
idcode[1], idcode[2]);
- return NULL;
+ return -1;
}
- 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;
+ 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;
- flash.internal_write = stmicro_write;
- flash.internal_erase = spi_flash_cmd_erase;
- flash.internal_read = spi_flash_cmd_read_fast;
+ flash->internal_write = stmicro_write;
+ flash->internal_erase = spi_flash_cmd_erase;
+ flash->internal_read = spi_flash_cmd_read_fast;
- return &flash;
+ return 0;
}
diff --git a/src/drivers/spi/winbond.c b/src/drivers/spi/winbond.c
index 3f167c0d06..c9d4aad4d6 100644
--- a/src/drivers/spi/winbond.c
+++ b/src/drivers/spi/winbond.c
@@ -184,9 +184,8 @@ out:
return ret;
}
-static struct spi_flash flash;
-
-struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
+int spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode,
+ struct spi_flash *flash)
{
const struct winbond_spi_flash_params *params;
unsigned int i;
@@ -200,27 +199,27 @@ struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
if (i == ARRAY_SIZE(winbond_spi_flash_table)) {
printk(BIOS_WARNING, "SF: Unsupported Winbond ID %02x%02x\n",
idcode[1], idcode[2]);
- return NULL;
+ return -1;
}
- memcpy(&flash.spi, spi, sizeof(*spi));
- flash.name = params->name;
+ memcpy(&flash->spi, spi, sizeof(*spi));
+ 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 *
+ 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->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;
+ 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
- flash.internal_read = spi_flash_cmd_read_slow;
+ flash->internal_read = spi_flash_cmd_read_slow;
#else
- flash.internal_read = spi_flash_cmd_read_fast;
+ flash->internal_read = spi_flash_cmd_read_fast;
#endif
- return &flash;
+ return 0;
}