summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2014-11-11 07:17:24 -0800
committerPatrick Georgi <pgeorgi@google.com>2015-03-20 16:02:11 +0100
commit032d4d258030c0b25325d2906c2a97b59f82bf40 (patch)
treeb7aa96c0e9b9a96ad7d0fa7e9b498ebdc3774883
parent93b9cb7f69381734da5ad9bdabf1c8b746a87a7f (diff)
downloadcoreboot-032d4d258030c0b25325d2906c2a97b59f82bf40.tar.xz
spi: do not use malloc in Winbond driver
When the driver is included in bootblock, malloc() is not available. Come to think of it, it is perfectly fine to use a statically allocated structure for the SPI device descriptor - coreboot is unlikely to require concurrent support of multiple SPI devices of the same kind. BRANCH=none BUG=chrome-os-partner:31438 TEST=bootblock on the FPGA board recognizes the installed Winbond device: coreboot-4.0 bootblock Tue Nov 11 07:27:24 PST 2014 starting... SF: Detected W25Q16 with page size 1000, total 200000 Change-Id: Iea1936a219d38848580a10f75eb8bbcab17e6507 Signed-off-by: Patrick Georgi <pgeorgi@chromium.org> Original-Commit-Id: 0b4082442aa526d387a80cb5872d78670e6b468b Original-Change-Id: Iaa69d610ef18e69b1ae5ade2d958f9fe1595a723 Original-Signed-off-by: Vadim Bendebury <vbendeb@chromium.org> Original-Reviewed-on: https://chromium-review.googlesource.com/228959 Original-Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: http://review.coreboot.org/8771 Tested-by: build bot (Jenkins) Reviewed-by: David Hendricks <dhendrix@chromium.org>
-rw-r--r--src/drivers/spi/winbond.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/src/drivers/spi/winbond.c b/src/drivers/spi/winbond.c
index 4c4150f40d..5fc7b4274a 100644
--- a/src/drivers/spi/winbond.c
+++ b/src/drivers/spi/winbond.c
@@ -194,11 +194,12 @@ static int winbond_erase(struct spi_flash *flash, u32 offset, size_t len)
return spi_flash_cmd_erase(flash, CMD_W25_SE, offset, len);
}
+static struct winbond_spi_flash stm;
+
struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
{
const struct winbond_spi_flash_params *params;
unsigned page_size;
- struct winbond_spi_flash *stm;
unsigned int i;
for (i = 0; i < ARRAY_SIZE(winbond_spi_flash_table); i++) {
@@ -213,31 +214,25 @@ struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
return NULL;
}
- stm = malloc(sizeof(struct winbond_spi_flash));
- if (!stm) {
- printk(BIOS_WARNING, "SF: Failed to allocate memory\n");
- return NULL;
- }
-
- stm->params = params;
- stm->flash.spi = spi;
- stm->flash.name = params->name;
+ stm.params = params;
+ stm.flash.spi = spi;
+ stm.flash.name = params->name;
/* Assuming power-of-two page size initially. */
page_size = 1 << params->l2_page_size;
- stm->flash.write = winbond_write;
- stm->flash.erase = winbond_erase;
+ stm.flash.write = winbond_write;
+ stm.flash.erase = winbond_erase;
#if CONFIG_SPI_FLASH_NO_FAST_READ
- stm->flash.read = spi_flash_cmd_read_slow;
+ stm.flash.read = spi_flash_cmd_read_slow;
#else
- stm->flash.read = spi_flash_cmd_read_fast;
+ stm.flash.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
+ 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;
- return &stm->flash;
+ return &stm.flash;
}