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>
This commit is contained in:
parent
93b9cb7f69
commit
032d4d2580
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue