[U-Boot] [PATCH 3/4] sf: kill off now-unused local state

Mike Frysinger vapier at gentoo.org
Sun Apr 24 11:05:57 CEST 2011


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 <vapier at gentoo.org>
---
 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(-)

diff --git a/drivers/mtd/spi/eon.c b/drivers/mtd/spi/eon.c
index 457265b..863a4cf 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,
@@ -71,7 +60,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) {
@@ -85,24 +74,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 = eon_write;
-	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 = eon_write;
+	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 8e58e75..8f6eb3f 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 = 0x2013,
@@ -143,7 +132,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;
 
@@ -158,23 +147,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 = macronix_write;
-	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 = macronix_write;
+	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 29fd63c..4116ba9 100644
--- a/drivers/mtd/spi/spansion.c
+++ b/drivers/mtd/spi/spansion.c
@@ -64,17 +64,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,
@@ -157,7 +146,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;
 
@@ -177,22 +166,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 = spansion_write;
-	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 = spansion_write;
+	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 ef95e56..63dd036 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,
@@ -149,7 +137,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) {
@@ -177,22 +165,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 = stmicro_write;
-	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 = stmicro_write;
+	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 cdfbd0a..99d6df1 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,
@@ -120,9 +108,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];
@@ -136,27 +124,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 = winbond_write;
-	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 = winbond_write;
+	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;
 }
-- 
1.7.5.rc1



More information about the U-Boot mailing list