spi: do not use malloc in Gigadevice driver
This allows us to use the driver before ramstage. BRANCH=none BUG=none TEST=built and booted on Pinky Change-Id: I0700388b0e4e0562e3c0a52863c8357097bfd8d6 Signed-off-by: Patrick Georgi <pgeorgi@chromium.org> Original-Commit-Id: cd57587dab74de509d5c50cfc1ad337d765af6c8 Original-Signed-off-by: David Hendricks <dhendrix@chromium.org> Original-Change-Id: I0ce901331e401274254b8889484ffb41359119fa Original-Reviewed-on: https://chromium-review.googlesource.com/235864 Original-Reviewed-by: Julius Werner <jwerner@chromium.org> Reviewed-on: http://review.coreboot.org/8774 Tested-by: build bot (Jenkins) Reviewed-by: David Hendricks <dhendrix@chromium.org> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
This commit is contained in:
parent
032d4d2580
commit
fccc7dea24
|
@ -189,11 +189,12 @@ static int gigadevice_erase(struct spi_flash *flash, u32 offset, size_t len)
|
||||||
return spi_flash_cmd_erase(flash, CMD_GD25_SE, offset, len);
|
return spi_flash_cmd_erase(flash, CMD_GD25_SE, offset, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct gigadevice_spi_flash stm;
|
||||||
|
|
||||||
struct spi_flash *spi_flash_probe_gigadevice(struct spi_slave *spi, u8 *idcode)
|
struct spi_flash *spi_flash_probe_gigadevice(struct spi_slave *spi, u8 *idcode)
|
||||||
{
|
{
|
||||||
const struct gigadevice_spi_flash_params *params;
|
const struct gigadevice_spi_flash_params *params;
|
||||||
unsigned page_size;
|
unsigned page_size;
|
||||||
struct gigadevice_spi_flash *stm;
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(gigadevice_spi_flash_table); i++) {
|
for (i = 0; i < ARRAY_SIZE(gigadevice_spi_flash_table); i++) {
|
||||||
|
@ -209,32 +210,25 @@ struct spi_flash *spi_flash_probe_gigadevice(struct spi_slave *spi, u8 *idcode)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
stm = malloc(sizeof(struct gigadevice_spi_flash));
|
stm.params = params;
|
||||||
if (!stm) {
|
stm.flash.spi = spi;
|
||||||
printk(BIOS_WARNING,
|
stm.flash.name = params->name;
|
||||||
"SF gigadevice.c: Failed to allocate memory\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
stm->params = params;
|
|
||||||
stm->flash.spi = spi;
|
|
||||||
stm->flash.name = params->name;
|
|
||||||
|
|
||||||
/* Assuming power-of-two page size initially. */
|
/* Assuming power-of-two page size initially. */
|
||||||
page_size = 1 << params->l2_page_size;
|
page_size = 1 << params->l2_page_size;
|
||||||
|
|
||||||
stm->flash.write = gigadevice_write;
|
stm.flash.write = gigadevice_write;
|
||||||
stm->flash.erase = gigadevice_erase;
|
stm.flash.erase = gigadevice_erase;
|
||||||
#if CONFIG_SPI_FLASH_NO_FAST_READ
|
#if CONFIG_SPI_FLASH_NO_FAST_READ
|
||||||
stm->flash.read = spi_flash_cmd_read_slow;
|
stm.flash.read = spi_flash_cmd_read_slow;
|
||||||
#else
|
#else
|
||||||
stm->flash.read = spi_flash_cmd_read_fast;
|
stm.flash.read = spi_flash_cmd_read_fast;
|
||||||
#endif
|
#endif
|
||||||
stm->flash.sector_size = (1 << stm->params->l2_page_size) *
|
stm.flash.sector_size = (1 << stm.params->l2_page_size) *
|
||||||
stm->params->pages_per_sector;
|
stm.params->pages_per_sector;
|
||||||
stm->flash.size = page_size * params->pages_per_sector
|
stm.flash.size = page_size * params->pages_per_sector
|
||||||
* params->sectors_per_block
|
* params->sectors_per_block
|
||||||
* params->nr_blocks;
|
* params->nr_blocks;
|
||||||
|
|
||||||
return &stm->flash;
|
return &stm.flash;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue