[U-Boot] [PATCH v2 8/9] spi: spi_flash: Fix Bank selection calculation for Dual parallel

Siva Durga Prasad Paladugu siva.durga.paladugu at xilinx.com
Tue Jul 19 17:48:33 CEST 2016


In Dual parallel connection the bank selection calculation
should be performed using offset and not the calculated address

Signed-off-by: Siva Durga Prasad Paladugu <sivadur at xilinx.com>
---
 drivers/mtd/spi/spi_flash.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index 404533b..293b47b 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -340,7 +340,7 @@ int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd,
 
 int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
 {
-	u32 erase_size, erase_addr;
+	u32 erase_size, erase_addr, bank_addr;
 	u8 cmd[SPI_FLASH_CMD_LEN];
 	int ret = -1;
 
@@ -361,13 +361,16 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
 	cmd[0] = flash->erase_cmd;
 	while (len) {
 		erase_addr = offset;
+		bank_addr = offset;
 
 #ifdef CONFIG_SF_DUAL_FLASH
 		if (flash->dual_flash > SF_SINGLE_FLASH)
 			spi_flash_dual(flash, &erase_addr);
+		if (flash->dual_flash == SF_DUAL_STACKED_FLASH)
+			bank_addr = erase_addr;
 #endif
 #ifdef CONFIG_SPI_FLASH_BAR
-		ret = spi_flash_write_bar(flash, erase_addr);
+		ret = spi_flash_write_bar(flash, bank_addr);
 		if (ret < 0)
 			return ret;
 #endif
@@ -394,7 +397,7 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
 {
 	struct spi_slave *spi = flash->spi;
 	unsigned long byte_addr, page_size;
-	u32 write_addr;
+	u32 write_addr, bank_addr;
 	size_t chunk_len, actual;
 	u8 cmd[SPI_FLASH_CMD_LEN];
 	int ret = -1;
@@ -412,13 +415,16 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
 	cmd[0] = flash->write_cmd;
 	for (actual = 0; actual < len; actual += chunk_len) {
 		write_addr = offset;
+		bank_addr = offset;
 
 #ifdef CONFIG_SF_DUAL_FLASH
 		if (flash->dual_flash > SF_SINGLE_FLASH)
 			spi_flash_dual(flash, &write_addr);
+		if (flash->dual_flash == SF_DUAL_STACKED_FLASH)
+			bank_addr = write_addr;
 #endif
 #ifdef CONFIG_SPI_FLASH_BAR
-		ret = spi_flash_write_bar(flash, write_addr);
+		ret = spi_flash_write_bar(flash, bank_addr);
 		if (ret < 0)
 			return ret;
 #endif
@@ -488,7 +494,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
 {
 	struct spi_slave *spi = flash->spi;
 	u8 *cmd, cmdsz;
-	u32 remain_len, read_len, read_addr;
+	u32 remain_len, read_len, read_addr, bank_addr;
 	int bank_sel = 0;
 	int ret = -1;
 
@@ -516,13 +522,16 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
 	cmd[0] = flash->read_cmd;
 	while (len) {
 		read_addr = offset;
+		bank_addr = offset;
 
 #ifdef CONFIG_SF_DUAL_FLASH
 		if (flash->dual_flash > SF_SINGLE_FLASH)
 			spi_flash_dual(flash, &read_addr);
+		if (flash->dual_flash == SF_DUAL_STACKED_FLASH)
+			bank_addr = read_addr;
 #endif
 #ifdef CONFIG_SPI_FLASH_BAR
-		ret = spi_flash_write_bar(flash, read_addr);
+		ret = spi_flash_write_bar(flash, bank_addr);
 		if (ret < 0)
 			return ret;
 		bank_sel = flash->bank_curr;
-- 
2.7.4



More information about the U-Boot mailing list