[U-Boot] [PATCH 4/4] sf: unify read functions

Mike Frysinger vapier at gentoo.org
Mon Jan 10 08:20:14 CET 2011


Signed-off-by: Mike Frysinger <vapier at gentoo.org>
---
 drivers/mtd/spi/atmel.c              |   18 +-------------
 drivers/mtd/spi/eon.c                |   22 +-----------------
 drivers/mtd/spi/macronix.c           |   22 +-----------------
 drivers/mtd/spi/spansion.c           |   26 +---------------------
 drivers/mtd/spi/spi_flash.c          |   12 ++++++++++
 drivers/mtd/spi/spi_flash_internal.h |    3 ++
 drivers/mtd/spi/sst.c                |   14 ------------
 drivers/mtd/spi/stmicro.c            |   22 +-----------------
 drivers/mtd/spi/winbond.c            |   40 +---------------------------------
 9 files changed, 22 insertions(+), 157 deletions(-)

diff --git a/drivers/mtd/spi/atmel.c b/drivers/mtd/spi/atmel.c
index 7827b75..a9910b1 100644
--- a/drivers/mtd/spi/atmel.c
+++ b/drivers/mtd/spi/atmel.c
@@ -143,20 +143,6 @@ static void at45_build_address(struct atmel_spi_flash *asf, u8 *cmd, u32 offset)
 	cmd[2] = byte_addr;
 }
 
-static int dataflash_read_fast_p2(struct spi_flash *flash,
-		u32 offset, size_t len, void *buf)
-{
-	u8 cmd[5];
-
-	cmd[0] = CMD_READ_ARRAY_FAST;
-	cmd[1] = offset >> 16;
-	cmd[2] = offset >> 8;
-	cmd[3] = offset;
-	cmd[4] = 0x00;
-
-	return spi_flash_read_common(flash, cmd, sizeof(cmd), buf, len);
-}
-
 static int dataflash_read_fast_at45(struct spi_flash *flash,
 		u32 offset, size_t len, void *buf)
 {
@@ -492,7 +478,7 @@ struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
 			asf->flash.erase = dataflash_erase_at45;
 			page_size += 1 << (params->l2_page_size - 5);
 		} else {
-			asf->flash.read = dataflash_read_fast_p2;
+			asf->flash.read = spi_flash_cmd_read_fast;
 			asf->flash.write = dataflash_write_p2;
 			asf->flash.erase = dataflash_erase_p2;
 		}
@@ -501,7 +487,7 @@ struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
 
 	case DF_FAMILY_AT26F:
 	case DF_FAMILY_AT26DF:
-		asf->flash.read = dataflash_read_fast_p2;
+		asf->flash.read = spi_flash_cmd_read_fast;
 		break;
 
 	default:
diff --git a/drivers/mtd/spi/eon.c b/drivers/mtd/spi/eon.c
index 0c0b05f..01caed5 100644
--- a/drivers/mtd/spi/eon.c
+++ b/drivers/mtd/spi/eon.c
@@ -56,26 +56,6 @@ static const struct eon_spi_flash_params eon_spi_flash_table[] = {
 	},
 };
 
-static int eon_read_fast(struct spi_flash *flash,
-			 u32 offset, size_t len, void *buf)
-{
-	struct eon_spi_flash *eon = to_eon_spi_flash(flash);
-	unsigned long page_addr;
-	unsigned long page_size;
-	u8 cmd[5];
-
-	page_size = eon->params->page_size;
-	page_addr = offset / page_size;
-
-	cmd[0] = CMD_READ_ARRAY_FAST;
-	cmd[1] = page_addr >> 8;
-	cmd[2] = page_addr;
-	cmd[3] = offset % page_size;
-	cmd[4] = 0x00;
-
-	return spi_flash_read_common(flash, cmd, sizeof(cmd), buf, len);
-}
-
 static int eon_write(struct spi_flash *flash,
 		     u32 offset, size_t len, const void *buf)
 {
@@ -177,7 +157,7 @@ struct spi_flash *spi_flash_probe_eon(struct spi_slave *spi, u8 *idcode)
 
 	eon->flash.write = eon_write;
 	eon->flash.erase = eon_erase;
-	eon->flash.read = eon_read_fast;
+	eon->flash.read = spi_flash_cmd_read_fast;
 	eon->flash.size = params->page_size * params->pages_per_sector
 	    * params->nr_sectors;
 
diff --git a/drivers/mtd/spi/macronix.c b/drivers/mtd/spi/macronix.c
index 573e1db..4155d4d 100644
--- a/drivers/mtd/spi/macronix.c
+++ b/drivers/mtd/spi/macronix.c
@@ -112,26 +112,6 @@ static const struct macronix_spi_flash_params macronix_spi_flash_table[] = {
 	},
 };
 
-static int macronix_read_fast(struct spi_flash *flash,
-			      u32 offset, size_t len, void *buf)
-{
-	struct macronix_spi_flash *mcx = to_macronix_spi_flash(flash);
-	unsigned long page_addr;
-	unsigned long page_size;
-	u8 cmd[5];
-
-	page_size = mcx->params->page_size;
-	page_addr = offset / page_size;
-
-	cmd[0] = CMD_READ_ARRAY_FAST;
-	cmd[1] = page_addr >> 8;
-	cmd[2] = page_addr;
-	cmd[3] = offset % page_size;
-	cmd[4] = 0x00;
-
-	return spi_flash_read_common(flash, cmd, sizeof(cmd), buf, len);
-}
-
 static int macronix_write(struct spi_flash *flash,
 			  u32 offset, size_t len, const void *buf)
 {
@@ -234,7 +214,7 @@ struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
 
 	mcx->flash.write = macronix_write;
 	mcx->flash.erase = macronix_erase;
-	mcx->flash.read = macronix_read_fast;
+	mcx->flash.read = spi_flash_cmd_read_fast;
 	mcx->flash.size = params->page_size * params->pages_per_sector
 	    * params->sectors_per_block * params->nr_blocks;
 
diff --git a/drivers/mtd/spi/spansion.c b/drivers/mtd/spi/spansion.c
index be4fc67..d54a5fa 100644
--- a/drivers/mtd/spi/spansion.c
+++ b/drivers/mtd/spi/spansion.c
@@ -133,30 +133,6 @@ static const struct spansion_spi_flash_params spansion_spi_flash_table[] = {
 	},
 };
 
-static int spansion_read_fast(struct spi_flash *flash,
-			     u32 offset, size_t len, void *buf)
-{
-	struct spansion_spi_flash *spsn = to_spansion_spi_flash(flash);
-	unsigned long page_addr;
-	unsigned long page_size;
-	u8 cmd[5];
-
-	page_size = spsn->params->page_size;
-	page_addr = offset / page_size;
-
-	cmd[0] = CMD_READ_ARRAY_FAST;
-	cmd[1] = page_addr >> 8;
-	cmd[2] = page_addr;
-	cmd[3] = offset % page_size;
-	cmd[4] = 0x00;
-
-	debug
-		("READ: 0x%x => cmd = { 0x%02x 0x%02x%02x%02x%02x } len = 0x%x\n",
-		 offset, cmd[0], cmd[1], cmd[2], cmd[3], cmd[4], len);
-
-	return spi_flash_read_common(flash, cmd, sizeof(cmd), buf, len);
-}
-
 static int spansion_write(struct spi_flash *flash,
 			 u32 offset, size_t len, const void *buf)
 {
@@ -263,7 +239,7 @@ struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
 
 	spsn->flash.write = spansion_write;
 	spsn->flash.erase = spansion_erase;
-	spsn->flash.read = spansion_read_fast;
+	spsn->flash.read = spi_flash_cmd_read_fast;
 	spsn->flash.size = params->page_size * params->pages_per_sector
 	    * params->nr_sectors;
 
diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index ca4bbb2..5c261f1 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -77,6 +77,18 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
 	return ret;
 }
 
+int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
+		size_t len, void *data)
+{
+	u8 cmd[5];
+
+	cmd[0] = CMD_READ_ARRAY_FAST;
+	spi_flash_addr(offset, cmd);
+	cmd[4] = 0x00;
+
+	return spi_flash_read_common(flash, cmd, sizeof(cmd), data, len);
+}
+
 int spi_flash_cmd_poll_bit(struct spi_flash *flash, unsigned long timeout,
 			   u8 cmd, u8 poll_bit)
 {
diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h
index 114b634..d7bcd6d 100644
--- a/drivers/mtd/spi/spi_flash_internal.h
+++ b/drivers/mtd/spi/spi_flash_internal.h
@@ -35,6 +35,9 @@ int spi_flash_cmd(struct spi_slave *spi, u8 cmd, void *response, size_t len);
 int spi_flash_cmd_read(struct spi_slave *spi, const u8 *cmd,
 		size_t cmd_len, void *data, size_t data_len);
 
+int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset,
+		size_t len, void *data);
+
 /*
  * Send a multi-byte command to the device followed by (optional)
  * data. Used for programming the flash array, etc.
diff --git a/drivers/mtd/spi/sst.c b/drivers/mtd/spi/sst.c
index d550550..792d04d 100644
--- a/drivers/mtd/spi/sst.c
+++ b/drivers/mtd/spi/sst.c
@@ -108,19 +108,6 @@ sst_disable_writing(struct spi_flash *flash)
 }
 
 static int
-sst_read_fast(struct spi_flash *flash, u32 offset, size_t len, void *buf)
-{
-	u8 cmd[5] = {
-		CMD_READ_ARRAY_FAST,
-		offset >> 16,
-		offset >> 8,
-		offset,
-		0x00,
-	};
-	return spi_flash_read_common(flash, cmd, sizeof(cmd), buf, len);
-}
-
-static int
 sst_byte_write(struct spi_flash *flash, u32 offset, const void *buf)
 {
 	int ret;
@@ -269,7 +256,6 @@ spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode)
 
 	stm->flash.write = sst_write;
 	stm->flash.erase = sst_erase;
-	stm->flash.read = sst_read_fast;
 	stm->flash.size = SST_SECTOR_SIZE * params->nr_sectors;
 
 	printf("SF: Detected %s with page size %u, total ",
diff --git a/drivers/mtd/spi/stmicro.c b/drivers/mtd/spi/stmicro.c
index 494005c..7ef690d 100644
--- a/drivers/mtd/spi/stmicro.c
+++ b/drivers/mtd/spi/stmicro.c
@@ -134,26 +134,6 @@ static const struct stmicro_spi_flash_params stmicro_spi_flash_table[] = {
 	},
 };
 
-static int stmicro_read_fast(struct spi_flash *flash,
-			     u32 offset, size_t len, void *buf)
-{
-	struct stmicro_spi_flash *stm = to_stmicro_spi_flash(flash);
-	unsigned long page_addr;
-	unsigned long page_size;
-	u8 cmd[5];
-
-	page_size = stm->params->page_size;
-	page_addr = offset / page_size;
-
-	cmd[0] = CMD_READ_ARRAY_FAST;
-	cmd[1] = page_addr >> 8;
-	cmd[2] = page_addr;
-	cmd[3] = offset % page_size;
-	cmd[4] = 0x00;
-
-	return spi_flash_read_common(flash, cmd, sizeof(cmd), buf, len);
-}
-
 static int stmicro_write(struct spi_flash *flash,
 			 u32 offset, size_t len, const void *buf)
 {
@@ -268,7 +248,7 @@ struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
 
 	stm->flash.write = stmicro_write;
 	stm->flash.erase = stmicro_erase;
-	stm->flash.read = stmicro_read_fast;
+	stm->flash.read = spi_flash_cmd_read_fast;
 	stm->flash.size = params->page_size * params->pages_per_sector
 	    * params->nr_sectors;
 
diff --git a/drivers/mtd/spi/winbond.c b/drivers/mtd/spi/winbond.c
index 8470a82..e88802f 100644
--- a/drivers/mtd/spi/winbond.c
+++ b/drivers/mtd/spi/winbond.c
@@ -105,44 +105,6 @@ static const struct winbond_spi_flash_params winbond_spi_flash_table[] = {
 	},
 };
 
-/*
- * Assemble the address part of a command for Winbond devices in
- * non-power-of-two page size mode.
- */
-static void winbond_build_address(struct winbond_spi_flash *stm, u8 *cmd, u32 offset)
-{
-	unsigned long page_addr;
-	unsigned long byte_addr;
-	unsigned long page_size;
-	unsigned int page_shift;
-
-	/*
-	 * The "extra" space per page is the power-of-two page size
-	 * divided by 32.
-	 */
-	page_shift = stm->params->l2_page_size;
-	page_size = (1 << page_shift);
-	page_addr = offset / page_size;
-	byte_addr = offset % page_size;
-
-	cmd[0] = page_addr >> (16 - page_shift);
-	cmd[1] = page_addr << (page_shift - 8) | (byte_addr >> 8);
-	cmd[2] = byte_addr;
-}
-
-static int winbond_read_fast(struct spi_flash *flash,
-		u32 offset, size_t len, void *buf)
-{
-	struct winbond_spi_flash *stm = to_winbond_spi_flash(flash);
-	u8 cmd[5];
-
-	cmd[0] = CMD_READ_ARRAY_FAST;
-	winbond_build_address(stm, cmd + 1, offset);
-	cmd[4] = 0x00;
-
-	return spi_flash_read_common(flash, cmd, sizeof(cmd), buf, len);
-}
-
 static int winbond_write(struct spi_flash *flash,
 		u32 offset, size_t len, const void *buf)
 {
@@ -250,7 +212,7 @@ struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
 
 	stm->flash.write = winbond_write;
 	stm->flash.erase = winbond_erase;
-	stm->flash.read = winbond_read_fast;
+	stm->flash.read = spi_flash_cmd_read_fast;
 	stm->flash.size = page_size * params->pages_per_sector
 				* params->sectors_per_block
 				* params->nr_blocks;
-- 
1.7.4.rc1



More information about the U-Boot mailing list