[U-Boot] [PATCH v2 7/9] spi: spi_flash: Correct bank select incase of dual stacked

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


Correct the bank selection issue incase of Dual stacked mode.
This fix corrects the wrong bank selection if banks are accessed
as below.
1. Access the bank2 in upper flash.
2. Access the bank1 in lower flash.
3. Now access the bank1 in upper flash.
But here in the step3, the present code was accessing the bank2 in
upper flash not bank1. This was because the code thinks the bank1
was already selected as part of step2 but it was not taking care of
upper or lower flash.

Signed-off-by: Siva Durga Prasad Paladugu <sivadur at xilinx.com>
---
 drivers/mtd/spi/spi_flash.c | 20 +++++++++++++++++---
 include/spi_flash.h         |  1 +
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
index ef9b877..404533b 100644
--- a/drivers/mtd/spi/spi_flash.c
+++ b/drivers/mtd/spi/spi_flash.c
@@ -146,12 +146,26 @@ static int write_evcr(struct spi_flash *flash, u8 evcr)
 #ifdef CONFIG_SPI_FLASH_BAR
 static int spi_flash_write_bar(struct spi_flash *flash, u32 offset)
 {
-	u8 cmd, bank_sel;
+	u8 cmd, bank_sel, upage_curr;
 	int ret;
 
 	bank_sel = offset / (SPI_FLASH_16MB_BOUN << flash->shift);
-	if (bank_sel == flash->bank_curr)
-		goto bar_end;
+
+	upage_curr = flash->spi->flags & SPI_XFER_U_PAGE;
+
+	if (flash->dual_flash != SF_DUAL_STACKED_FLASH) {
+		if (flash->bank_curr == bank_sel) {
+			debug("SF: not require to enable bank%d\n", bank_sel);
+			goto bar_end;
+		}
+	} else if (flash->upage_prev == upage_curr) {
+		if (flash->bank_curr == bank_sel) {
+			debug("SF: not require to enable bank%d\n", bank_sel);
+			goto bar_end;
+		}
+	} else {
+		flash->upage_prev = upage_curr;
+	}
 
 	cmd = flash->bank_write_cmd;
 	ret = spi_flash_write_common(flash, &cmd, 1, &bank_sel, 1);
diff --git a/include/spi_flash.h b/include/spi_flash.h
index d0ce9e7..83052e0 100644
--- a/include/spi_flash.h
+++ b/include/spi_flash.h
@@ -78,6 +78,7 @@ struct spi_flash {
 	u8 bank_read_cmd;
 	u8 bank_write_cmd;
 	u8 bank_curr;
+	u8 upage_prev;
 #endif
 	u8 erase_cmd;
 	u8 read_cmd;
-- 
2.7.4



More information about the U-Boot mailing list