[PATCH] driver/mtd/spi-nor: Regression lock/unlock fail

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: shreyas <shreyasjoshi15@xxxxxxxxx>

      The n25q128 micron chips cannot be treated similar to STM SPI NOR
      when it comes to flash lock/unlock. The JDEC ID read here is just 1 byte
      and it is not sufficient to distinguish between different chips. Thus,
      memory type is used here in addition to JDEC ID to distinguish further.
      Once the unique manufacture id is detected, it will invoke the required
      lock/unlock function required for n25 micron chipsets.

Signed-off-by: shreyas <shreyasjoshi15@xxxxxxxxx>
---
 drivers/mtd/spi-nor/spi-nor.c | 20 +++++++++++---------
 include/linux/mtd/spi-nor.h   |  4 ++--
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index f3b2df2c52b4..6dfdd95a5961 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -1356,6 +1356,7 @@ static int n25q_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
 	int status_old, status_new;
 	uint32_t offset = ofs;
 	int ret = 0;
+
 	status_old = read_sr(nor);
 	if (status_old < 0)
 		return status_old;
@@ -1373,7 +1374,8 @@ static int n25q_lock(struct spi_nor *nor, loff_t ofs, uint64_t len)
 		status_new = (status_old & ~(SR_BP2|SR_BP0)) | SR_BP1;
 	else
 		status_new = (status_old & ~(SR_BP2|SR_BP1)) | SR_BP0;
-	if ((status_new & (SR_BP2|SR_BP1|SR_BP0)) > (status_old & (SR_BP2|SR_BP1|SR_BP0))) {
+	if ((status_new & (SR_BP2|SR_BP1|SR_BP0)) >
+			(status_old & (SR_BP2|SR_BP1|SR_BP0))) {
 		write_enable(nor);
 		if (write_sr(nor, status_new) < 0)
 			return -EINVAL;
@@ -1392,6 +1394,7 @@ static int n25q_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len)
 	int status_old, status_new;
 	uint32_t offset = ofs;
 	int ret = 0;
+
 	status_old = read_sr(nor);
 	if (status_old < 0)
 		return status_old;
@@ -4266,14 +4269,13 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 	if (JEDEC_MFR(info) == SNOR_MFR_ST ||
 	    JEDEC_MFR(info) == SNOR_MFR_MICRON ||
 	    info->flags & SPI_NOR_HAS_LOCK) {
-	if (JEDEC_MT(info) == SNOR_MT_MICRON) {
-		nor->flash_lock = n25q_lock;
-		nor->flash_unlock = n25q_unlock;
-	}
-	else {
-		nor->flash_lock = stm_lock;
-		nor->flash_unlock = stm_unlock;
-	}
+		if (JEDEC_MT(info) == SNOR_MT_MICRON) {
+			nor->flash_lock = n25q_lock;
+			nor->flash_unlock = n25q_unlock;
+		} else {
+			nor->flash_lock = stm_lock;
+			nor->flash_unlock = stm_unlock;
+		}
 	nor->flash_is_locked = stm_is_locked;
 	}
 	if (nor->flash_lock && nor->flash_unlock && nor->flash_is_locked) {
diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h
index aaa3c1065b3b..3939cd77d778 100644
--- a/include/linux/mtd/spi-nor.h
+++ b/include/linux/mtd/spi-nor.h
@@ -27,8 +27,8 @@
 #define SNOR_MFR_WINBOND	0xef /* Also used by some Spansion */
 
 /* Manufacturer Memory Type
-* The second byte returned from the flash after sending opcode SPINOR_OP_RDID.
-*/
+ * The second byte returned from the flash after sending opcode SPINOR_OP_RDID.
+ */
 #define SNOR_MT_MICRON	0xba
 #define SNOR_MT_ST      0x20
 
-- 
2.20.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux