diff mbox

[U-Boot,1/2] SPI: Add struct spi_flash.sector_size parameter

Message ID 1297892242-8595-1-git-send-email-RichardRetanubun@RuggedCom.com
State Superseded
Headers show

Commit Message

Richard Retanubun Feb. 16, 2011, 9:37 p.m. UTC
This patch adds a new member to struct spi_flash (u16 sector_size)
and updates the spi flash drivers to start populating it.

This parameter can be used by spi flash commands that need to round
up units of operation to the flash's sector_size.

Signed-off-by: Richard Retanubun <RichardRetanubun@RuggedCom.com>
---
v2: scrubbed via checkpatch, thanks WD!

 drivers/mtd/spi/atmel.c    |    1 +
 drivers/mtd/spi/macronix.c |    1 +
 drivers/mtd/spi/spansion.c |    4 ++--
 drivers/mtd/spi/sst.c      |    3 ++-
 drivers/mtd/spi/stmicro.c  |    4 ++--
 drivers/mtd/spi/winbond.c  |    5 +++--
 include/spi_flash.h        |    2 ++
 7 files changed, 13 insertions(+), 7 deletions(-)

Comments

Mike Frysinger April 12, 2011, 6:34 a.m. UTC | #1
these patches have been integrated/superseded by my recent sf patchset
-mike
diff mbox

Patch

diff --git a/drivers/mtd/spi/atmel.c b/drivers/mtd/spi/atmel.c
index a9910b1..180a52b 100644
--- a/drivers/mtd/spi/atmel.c
+++ b/drivers/mtd/spi/atmel.c
@@ -498,6 +498,7 @@  struct spi_flash *spi_flash_probe_atmel(struct spi_slave *spi, u8 *idcode)
 	asf->flash.size = page_size * params->pages_per_block
 				* params->blocks_per_sector
 				* params->nr_sectors;
+	asf->flash.sector_size = page_size;
 
 	printf("SF: Detected %s with page size %u, total ",
 	       params->name, page_size);
diff --git a/drivers/mtd/spi/macronix.c b/drivers/mtd/spi/macronix.c
index 4155d4d..4a8e17f 100644
--- a/drivers/mtd/spi/macronix.c
+++ b/drivers/mtd/spi/macronix.c
@@ -217,6 +217,7 @@  struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode)
 	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;
+	mcx->flash.sector_size = mcx->flash.size/params->nr_blocks;
 
 	printf("SF: Detected %s with page size %u, total ",
 	       params->name, params->page_size);
diff --git a/drivers/mtd/spi/spansion.c b/drivers/mtd/spi/spansion.c
index d54a5fa..c88457b 100644
--- a/drivers/mtd/spi/spansion.c
+++ b/drivers/mtd/spi/spansion.c
@@ -199,8 +199,7 @@  static int spansion_write(struct spi_flash *flash,
 int spansion_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
 	struct spansion_spi_flash *spsn = to_spansion_spi_flash(flash);
-	return spi_flash_cmd_erase(flash, CMD_S25FLXX_SE,
-		spsn->params->page_size * spsn->params->pages_per_sector,
+	return spi_flash_cmd_erase(flash, CMD_S25FLXX_SE, flash->sector_size,
 		offset, len);
 }
 
@@ -242,6 +241,7 @@  struct spi_flash *spi_flash_probe_spansion(struct spi_slave *spi, u8 *idcode)
 	spsn->flash.read = spi_flash_cmd_read_fast;
 	spsn->flash.size = params->page_size * params->pages_per_sector
 	    * params->nr_sectors;
+	spsn->flash.sector_size = spsn->flash.size/params->nr_sectors;
 
 	printf("SF: Detected %s with page size %u, total ",
 	       params->name, params->page_size);
diff --git a/drivers/mtd/spi/sst.c b/drivers/mtd/spi/sst.c
index 792d04d..15de12b 100644
--- a/drivers/mtd/spi/sst.c
+++ b/drivers/mtd/spi/sst.c
@@ -201,7 +201,7 @@  sst_write(struct spi_flash *flash, u32 offset, size_t len, const void *buf)
 
 int sst_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
-	return spi_flash_cmd_erase(flash, CMD_SST_SE, SST_SECTOR_SIZE,
+	return spi_flash_cmd_erase(flash, CMD_SST_SE, flash->sector_size,
 		offset, len);
 }
 
@@ -257,6 +257,7 @@  spi_flash_probe_sst(struct spi_slave *spi, u8 *idcode)
 	stm->flash.write = sst_write;
 	stm->flash.erase = sst_erase;
 	stm->flash.size = SST_SECTOR_SIZE * params->nr_sectors;
+	stm->flash.sector_size = SST_SECTOR_SIZE;
 
 	printf("SF: Detected %s with page size %u, total ",
 	       params->name, SST_SECTOR_SIZE);
diff --git a/drivers/mtd/spi/stmicro.c b/drivers/mtd/spi/stmicro.c
index 7ef690d..80d838e 100644
--- a/drivers/mtd/spi/stmicro.c
+++ b/drivers/mtd/spi/stmicro.c
@@ -200,8 +200,7 @@  static int stmicro_write(struct spi_flash *flash,
 int stmicro_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
 	struct stmicro_spi_flash *stm = to_stmicro_spi_flash(flash);
-	return spi_flash_cmd_erase(flash, CMD_M25PXX_SE,
-		stm->params->page_size * stm->params->pages_per_sector,
+	return spi_flash_cmd_erase(flash, CMD_M25PXX_SE, flash->sector_size,
 		offset, len);
 }
 
@@ -251,6 +250,7 @@  struct spi_flash *spi_flash_probe_stmicro(struct spi_slave *spi, u8 * idcode)
 	stm->flash.read = spi_flash_cmd_read_fast;
 	stm->flash.size = params->page_size * params->pages_per_sector
 	    * params->nr_sectors;
+	stm->flash.sector_size = stm->flash.size/params->nr_sectors;
 
 	printf("SF: Detected %s with page size %u, total ",
 	       params->name, params->page_size);
diff --git a/drivers/mtd/spi/winbond.c b/drivers/mtd/spi/winbond.c
index e88802f..ec6fb79 100644
--- a/drivers/mtd/spi/winbond.c
+++ b/drivers/mtd/spi/winbond.c
@@ -173,8 +173,7 @@  out:
 int winbond_erase(struct spi_flash *flash, u32 offset, size_t len)
 {
 	struct winbond_spi_flash *stm = to_winbond_spi_flash(flash);
-	return spi_flash_cmd_erase(flash, CMD_W25_SE,
-		(1 << stm->params->l2_page_size) * stm->params->pages_per_sector,
+	return spi_flash_cmd_erase(flash, CMD_W25_SE, flash->sector_size,
 		offset, len);
 }
 
@@ -216,6 +215,8 @@  struct spi_flash *spi_flash_probe_winbond(struct spi_slave *spi, u8 *idcode)
 	stm->flash.size = page_size * params->pages_per_sector
 				* params->sectors_per_block
 				* params->nr_blocks;
+	stm->flash.sector_size = (1 << stm->params->l2_page_size) *
+		stm->params->pages_per_sector;
 
 	printf("SF: Detected %s with page size %u, total ",
 	       params->name, page_size);
diff --git a/include/spi_flash.h b/include/spi_flash.h
index 1f8ba29..039b94e 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -38,6 +38,8 @@  struct spi_flash {
 
 	u32		size;
 
+	u16		sector_size;
+
 	int		(*read)(struct spi_flash *flash, u32 offset,
 				size_t len, void *buf);
 	int		(*write)(struct spi_flash *flash, u32 offset,