spi_flash: Make a deep copy of spi_slave structure

Commit 36b81af (spi: Pass pointer to spi_slave structure in
spi_setup_slave) changes the way spi_setup_slave handles the spi_slave
structure. Instead of expecting spi controller drivers to maintain
spi_slave structure in CAR_GLOBAL/data section, caller is expected to
manage the spi_slave structure. This requires that spi_flash drivers
maintain spi_slave structure and flash probe function needs to make a
copy of the passed in spi_slave structure.

This change fixes the regression on Lenovo X230 and other mainboards.

Change-Id: I0ad971eecaf3bfe301e9f95badc043193cc27cab
Signed-off-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-on: https://review.coreboot.org/17728
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Iru Cai <mytbk920423@gmail.com>
This commit is contained in:
Furquan Shaikh
2016-12-05 20:32:24 -08:00
committed by Furquan Shaikh
parent d3d1f13599
commit 810e2cde30
17 changed files with 77 additions and 62 deletions

View File

@@ -236,12 +236,13 @@ static int nor_erase(const struct spi_flash *flash, u32 offset, size_t len)
struct spi_flash *spi_flash_programmer_probe(struct spi_slave *spi, int force)
{
static struct spi_flash flash = {0};
static int done = 0;
if (flash.spi)
if (done)
return &flash;
write32(&mt8173_nor->wrprot, SFLASH_COMMAND_ENABLE);
flash.spi = spi;
memcpy(&flash.spi, spi, sizeof(*spi));
flash.name = "mt8173 flash controller";
flash.internal_write = nor_write;
flash.internal_erase = nor_erase;
@@ -250,5 +251,6 @@ struct spi_flash *spi_flash_programmer_probe(struct spi_slave *spi, int force)
flash.sector_size = 0x1000;
flash.erase_cmd = SECTOR_ERASE_CMD;
flash.size = CONFIG_ROM_SIZE;
done = 1;
return &flash;
}