From b06afa75faeea2498447c56df1abaa23dbedb689 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Tue, 28 Jun 2011 07:38:10 +0000 Subject: sf: kill off now-unused local state Now that the common spi_flash structure tracks all the info that these drivers need, kill off their local state indirection and use just what the common code provides. Signed-off-by: Mike Frysinger --- drivers/mtd/spi/eon.c | 36 ++++++++++++------------------------ drivers/mtd/spi/macronix.c | 36 ++++++++++++------------------------ drivers/mtd/spi/spansion.c | 36 ++++++++++++------------------------ drivers/mtd/spi/stmicro.c | 37 ++++++++++++------------------------- drivers/mtd/spi/winbond.c | 39 +++++++++++++-------------------------- 5 files changed, 61 insertions(+), 123 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/spi/eon.c b/drivers/mtd/spi/eon.c index 036855b197..5937b612c7 100644 --- a/drivers/mtd/spi/eon.c +++ b/drivers/mtd/spi/eon.c @@ -34,17 +34,6 @@ struct eon_spi_flash_params { const char *name; }; -/* spi_flash needs to be first so upper layers can free() it */ -struct eon_spi_flash { - struct spi_flash flash; - const struct eon_spi_flash_params *params; -}; - -static inline struct eon_spi_flash *to_eon_spi_flash(struct spi_flash *flash) -{ - return container_of(flash, struct eon_spi_flash, flash); -} - static const struct eon_spi_flash_params eon_spi_flash_table[] = { { .idcode1 = EON_ID_EN25Q128, @@ -64,7 +53,7 @@ static int eon_erase(struct spi_flash *flash, u32 offset, size_t len) struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode) { const struct eon_spi_flash_params *params; - struct eon_spi_flash *eon; + struct spi_flash *flash; unsigned int i; for (i = 0; i < ARRAY_SIZE(eon_spi_flash_table); ++i) { @@ -78,24 +67,23 @@ struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode) return NULL; } - eon = malloc(sizeof(*eon)); - if (!eon) { + flash = malloc(sizeof(*flash)); + if (!flash) { debug("SF: Failed to allocate memory\n"); return NULL; } - eon->params = params; - eon->flash.spi = spi; - eon->flash.name = params->name; + flash->spi = spi; + flash->name = params->name; - eon->flash.write = spi_flash_cmd_write_multi; - eon->flash.erase = eon_erase; - eon->flash.read = spi_flash_cmd_read_fast; - eon->flash.page_size = params->page_size; - eon->flash.sector_size = params->page_size * params->pages_per_sector + flash->write = spi_flash_cmd_write_multi; + flash->erase = eon_erase; + flash->read = spi_flash_cmd_read_fast; + flash->page_size = params->page_size; + flash->sector_size = params->page_size * params->pages_per_sector * params->sectors_per_block; - eon->flash.size = params->page_size * params->pages_per_sector + flash->size = params->page_size * params->pages_per_sector * params->nr_sectors; - return &eon->flash; + return flash; } diff --git a/drivers/mtd/spi/macronix.c b/drivers/mtd/spi/macronix.c index 0a56420300..e6895620a3 100644 --- a/drivers/mtd/spi/macronix.c +++ b/drivers/mtd/spi/macronix.c @@ -58,17 +58,6 @@ struct macronix_spi_flash_params { const char *name; }; -struct macronix_spi_flash { - struct spi_flash flash; - const struct macronix_spi_flash_params *params; -}; - -static inline struct macronix_spi_flash *to_macronix_spi_flash(struct spi_flash - *flash) -{ - return container_of(flash, struct macronix_spi_flash, flash); -} - static const struct macronix_spi_flash_params macronix_spi_flash_table[] = { { .idcode = 0x2015, @@ -120,7 +109,7 @@ static int macronix_erase(struct spi_flash *flash, u32 offset, size_t len) struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode) { const struct macronix_spi_flash_params *params; - struct macronix_spi_flash *mcx; + struct spi_flash *flash; unsigned int i; u16 id = idcode[2] | idcode[1] << 8; @@ -135,23 +124,22 @@ struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode) return NULL; } - mcx = malloc(sizeof(*mcx)); - if (!mcx) { + flash = malloc(sizeof(*flash)); + if (!flash) { debug("SF: Failed to allocate memory\n"); return NULL; } - mcx->params = params; - mcx->flash.spi = spi; - mcx->flash.name = params->name; + flash->spi = spi; + flash->name = params->name; - mcx->flash.write = spi_flash_cmd_write_multi; - mcx->flash.erase = macronix_erase; - mcx->flash.read = spi_flash_cmd_read_fast; - mcx->flash.page_size = params->page_size; - mcx->flash.sector_size = params->page_size * params->pages_per_sector + flash->write = spi_flash_cmd_write_multi; + flash->erase = macronix_erase; + flash->read = spi_flash_cmd_read_fast; + flash->page_size = params->page_size; + flash->sector_size = params->page_size * params->pages_per_sector * params->sectors_per_block; - mcx->flash.size = mcx->flash.sector_size * params->nr_blocks; + flash->size = flash->sector_size * params->nr_blocks; - return &mcx->flash; + return flash; } diff --git a/drivers/mtd/spi/spansion.c b/drivers/mtd/spi/spansion.c index b219b3cace..28bb51a461 100644 --- a/drivers/mtd/spi/spansion.c +++ b/drivers/mtd/spi/spansion.c @@ -63,17 +63,6 @@ struct spansion_spi_flash_params { const char *name; }; -struct spansion_spi_flash { - struct spi_flash flash; - const struct spansion_spi_flash_params *params; -}; - -static inline struct spansion_spi_flash *to_spansion_spi_flash(struct spi_flash - *flash) -{ - return container_of(flash, struct spansion_spi_flash, flash); -} - static const struct spansion_spi_flash_params spansion_spi_flash_table[] = { { .idcode1 = SPSN_ID_S25FL008A, @@ -141,7 +130,7 @@ static int spansion_erase(struct spi_flash *flash, u32 offset, size_t len) struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode) { const struct spansion_spi_flash_params *params; - struct spansion_spi_flash *spsn; + struct spi_flash *flash; unsigned int i; unsigned short jedec, ext_jedec; @@ -161,22 +150,21 @@ struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode) return NULL; } - spsn = malloc(sizeof(struct spansion_spi_flash)); - if (!spsn) { + flash = malloc(sizeof(*flash)); + if (!flash) { debug("SF: Failed to allocate memory\n"); return NULL; } - spsn->params = params; - spsn->flash.spi = spi; - spsn->flash.name = params->name; + flash->spi = spi; + flash->name = params->name; - spsn->flash.write = spi_flash_cmd_write_multi; - spsn->flash.erase = spansion_erase; - spsn->flash.read = spi_flash_cmd_read_fast; - spsn->flash.page_size = params->page_size; - spsn->flash.sector_size = params->page_size * params->pages_per_sector; - spsn->flash.size = spsn->flash.sector_size * params->nr_sectors; + flash->write = spi_flash_cmd_write_multi; + flash->erase = spansion_erase; + flash->read = spi_flash_cmd_read_fast; + flash->page_size = params->page_size; + flash->sector_size = params->page_size * params->pages_per_sector; + flash->size = flash->sector_size * params->nr_sectors; - return &spsn->flash; + return flash; } diff --git a/drivers/mtd/spi/stmicro.c b/drivers/mtd/spi/stmicro.c index 8106e7c9e8..9a9d3d4013 100644 --- a/drivers/mtd/spi/stmicro.c +++ b/drivers/mtd/spi/stmicro.c @@ -63,18 +63,6 @@ struct stmicro_spi_flash_params { const char *name; }; -/* spi_flash needs to be first so upper layers can free() it */ -struct stmicro_spi_flash { - struct spi_flash flash; - const struct stmicro_spi_flash_params *params; -}; - -static inline struct stmicro_spi_flash *to_stmicro_spi_flash(struct spi_flash - *flash) -{ - return container_of(flash, struct stmicro_spi_flash, flash); -} - static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = { { .idcode1 = STM_ID_M25P10, @@ -142,7 +130,7 @@ static int stmicro_erase(struct spi_flash *flash, u32 offset, size_t len) struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode) { const struct stmicro_spi_flash_params *params; - struct stmicro_spi_flash *stm; + struct spi_flash *flash; unsigned int i; if (idcode[0] == 0xff) { @@ -170,22 +158,21 @@ struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode) return NULL; } - stm = malloc(sizeof(struct stmicro_spi_flash)); - if (!stm) { + flash = malloc(sizeof(*flash)); + if (!flash) { debug("SF: Failed to allocate memory\n"); return NULL; } - stm->params = params; - stm->flash.spi = spi; - stm->flash.name = params->name; + flash->spi = spi; + flash->name = params->name; - stm->flash.write = spi_flash_cmd_write_multi; - stm->flash.erase = stmicro_erase; - stm->flash.read = spi_flash_cmd_read_fast; - stm->flash.page_size = params->page_size; - stm->flash.sector_size = params->page_size * params->pages_per_sector; - stm->flash.size = stm->flash.sector_size * params->nr_sectors; + flash->write = spi_flash_cmd_write_multi; + flash->erase = stmicro_erase; + flash->read = spi_flash_cmd_read_fast; + flash->page_size = params->page_size; + flash->sector_size = params->page_size * params->pages_per_sector; + flash->size = flash->sector_size * params->nr_sectors; - return &stm->flash; + return flash; } diff --git a/drivers/mtd/spi/winbond.c b/drivers/mtd/spi/winbond.c index 3db0cb0224..45bd1461eb 100644 --- a/drivers/mtd/spi/winbond.c +++ b/drivers/mtd/spi/winbond.c @@ -34,18 +34,6 @@ struct winbond_spi_flash_params { const char *name; }; -/* spi_flash needs to be first so upper layers can free() it */ -struct winbond_spi_flash { - struct spi_flash flash; - const struct winbond_spi_flash_params *params; -}; - -static inline struct winbond_spi_flash * -to_winbond_spi_flash(struct spi_flash *flash) -{ - return container_of(flash, struct winbond_spi_flash, flash); -} - static const struct winbond_spi_flash_params winbond_spi_flash_table[] = { { .id = 0x3015, @@ -113,9 +101,9 @@ static int winbond_erase(struct spi_flash *flash, u32 offset, size_t len) 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; + struct spi_flash *flash; unsigned int i; + unsigned page_size; for (i = 0; i < ARRAY_SIZE(winbond_spi_flash_table); i++) { params = &winbond_spi_flash_table[i]; @@ -129,27 +117,26 @@ struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode) return NULL; } - stm = malloc(sizeof(struct winbond_spi_flash)); - if (!stm) { + flash = malloc(sizeof(*flash)); + if (!flash) { debug("SF: Failed to allocate memory\n"); return NULL; } - stm->params = params; - stm->flash.spi = spi; - stm->flash.name = params->name; + flash->spi = spi; + flash->name = params->name; /* Assuming power-of-two page size initially. */ page_size = 1 << params->l2_page_size; - stm->flash.write = spi_flash_cmd_write_multi; - stm->flash.erase = winbond_erase; - stm->flash.read = spi_flash_cmd_read_fast; - stm->flash.page_size = page_size; - stm->flash.sector_size = page_size * stm->params->pages_per_sector; - stm->flash.size = page_size * params->pages_per_sector + flash->write = spi_flash_cmd_write_multi; + flash->erase = winbond_erase; + flash->read = spi_flash_cmd_read_fast; + flash->page_size = page_size; + flash->sector_size = page_size * params->pages_per_sector; + flash->size = page_size * params->pages_per_sector * params->sectors_per_block * params->nr_blocks; - return &stm->flash; + return flash; } -- cgit