From 9c61ac52c5b51e85b51cd162fb5e338c0a2428de Mon Sep 17 00:00:00 2001 From: Vipul Kumar Date: Fri, 20 Apr 2018 10:36:23 +0530 Subject: [PATCH] mtd: spi: Set the current bank of flash to zero after doing clear bar clean_bar() function selecting bank zero but not setting the flash current bank to zero. After erase operation, bank zero is selected but the flash current bank is pointing to bank one. So, during write operation, while trying to write bank one, it actually writes in bank zero. This patch fixed this issue by setting the current bank of flash to zero after doing clear_bar() after erase, write and read operations. Signed-off-by: Vipul Kumar Signed-off-by: Siva Durga Prasad Paladugu Signed-off-by: Michal Simek --- drivers/mtd/spi/spi_flash.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index 8e79a4a125a..cba61da744a 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -165,12 +165,21 @@ static int write_cr(struct spi_flash *flash, u8 wc) static int clean_bar(struct spi_flash *flash) { u8 cmd, bank_sel = 0; + int ret; if (flash->bank_curr == 0) return 0; cmd = flash->bank_write_cmd; - return spi_flash_write_common(flash, &cmd, 1, &bank_sel, 1); + ret = spi_flash_write_common(flash, &cmd, 1, &bank_sel, 1); + if (ret) { + debug("SF: fail to write bank register\n"); + return ret; + } + + flash->bank_curr = bank_sel; + + return ret; } static int write_bar(struct spi_flash *flash, u32 offset) -- 2.47.3