drivers/spi/spi_flash: Add page_size to struct spi_flash

Add a new member page_size to spi_flash structure so that the various
spi flash drivers can store this info in spi_flash along with the
other sizes (sector size and total size) during flash probe. This
removes the need to have {driver}_spi_flash structure in every spi
flash driver.

This is part of patch series to clean up the SPI flash and SPI driver
interface.

BUG=b:38330715

Change-Id: I0f83e52cb1041432b0b575a8ee3bd173cc038d1f
Signed-off-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-on: https://review.coreboot.org/19704
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
This commit is contained in:
Furquan Shaikh
2017-05-12 00:19:56 -07:00
committed by Furquan Shaikh
parent f422fd2c78
commit fc1a123aa7
12 changed files with 162 additions and 305 deletions

View File

@@ -38,18 +38,6 @@ struct atmel_spi_flash_params {
const char *name;
};
/* spi_flash needs to be first so upper layers can free() it */
struct atmel_spi_flash {
struct spi_flash flash;
const struct atmel_spi_flash_params *params;
};
static inline struct atmel_spi_flash *
to_atmel_spi_flash(const struct spi_flash *flash)
{
return container_of(flash, struct atmel_spi_flash, flash);
}
static const struct atmel_spi_flash_params atmel_spi_flash_table[] = {
{
.id = 0x3015,
@@ -112,7 +100,6 @@ static const struct atmel_spi_flash_params atmel_spi_flash_table[] = {
static int atmel_write(const struct spi_flash *flash, u32 offset, size_t len,
const void *buf)
{
struct atmel_spi_flash *stm = to_atmel_spi_flash(flash);
unsigned long byte_addr;
unsigned long page_size;
size_t chunk_len;
@@ -120,7 +107,7 @@ static int atmel_write(const struct spi_flash *flash, u32 offset, size_t len,
int ret;
u8 cmd[4];
page_size = 1 << stm->params->l2_page_size;
page_size = flash->page_size;
for (actual = 0; actual < len; actual += chunk_len) {
byte_addr = offset % page_size;
@@ -170,9 +157,8 @@ out:
struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
{
const struct atmel_spi_flash_params *params;
unsigned page_size;
struct atmel_spi_flash *stm;
unsigned int i;
struct spi_flash *flash;
for (i = 0; i < ARRAY_SIZE(atmel_spi_flash_table); i++) {
params = &atmel_spi_flash_table[i];
@@ -186,32 +172,29 @@ struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
return NULL;
}
stm = malloc(sizeof(struct atmel_spi_flash));
if (!stm) {
flash = malloc(sizeof(*flash));
if (!flash) {
printk(BIOS_WARNING, "SF: Failed to allocate memory\n");
return NULL;
}
stm->params = params;
memcpy(&stm->flash.spi, spi, sizeof(*spi));
stm->flash.name = params->name;
memcpy(&flash->spi, spi, sizeof(*spi));
flash->name = params->name;
/* Assuming power-of-two page size initially. */
page_size = 1 << params->l2_page_size;
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_AT25_SE;
stm->flash.internal_write = atmel_write;
stm->flash.internal_erase = spi_flash_cmd_erase;
flash->internal_write = atmel_write;
flash->internal_erase = spi_flash_cmd_erase;
#if CONFIG_SPI_FLASH_NO_FAST_READ
stm->flash.internal_read = spi_flash_cmd_read_slow;
flash->internal_read = spi_flash_cmd_read_slow;
#else
stm->flash.internal_read = spi_flash_cmd_read_fast;
flash->internal_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
* params->sectors_per_block
* params->nr_blocks;
stm->flash.erase_cmd = CMD_AT25_SE;
return &stm->flash;
return flash;
}