Skip to contentSkip to conversation

sf: Fix quad bit set for micron devices

PATCH Superseded Jagan Teki 2 participants 7 messages Dec 16, 2015 – Dec 23, 2015 Memory technology devices (MTD)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jagan Teki

author
#0 lore raw

PATCH v2 1/4 sf: Fix quad bit set for micron devices

Setting up quad bit for micron devices need to do the same way as other flash devices like spansion, winbond etc does using enhanced volatile config register so this patch adds this support instead of printing "QEB is volatile"

Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>
Cc Peter Pan <[email protected]>
Cc Fabio Estevam <[email protected]>
Cc Michal Simek <[email protected]>
Cc Siva Durga Prasad Paladugu <[email protected]>

---
Changes for v2:
- none

 drivers/mtd/spi/sf_internal.h |  3 +++
 drivers/mtd/spi/spi_flash.c   | 62 +++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 63 insertions(+), 2 deletions(-)
drivers/mtd/spi/sf_internal.h +3 -0
index 561abc3..55ba81e 100644
@@ -77,6 +77,7 @@ enum spi_nor_option_flags {
 #define CMD_WRITE_DISABLE		0x04
 #define CMD_WRITE_ENABLE		0x06
 #define CMD_QUAD_PAGE_PROGRAM		0x32
+#define CMD_WRITE_EVCR			0x61
 
 /* Read commands */
 #define CMD_READ_ARRAY_SLOW		0x03
@@ -90,6 +91,7 @@ enum spi_nor_option_flags {
 #define CMD_READ_STATUS1		0x35
 #define CMD_READ_CONFIG			0x35
 #define CMD_FLAG_STATUS			0x70
+#define CMD_READ_EVCR			0x65
 
 /* Bank addr access commands */
 #ifdef CONFIG_SPI_FLASH_BAR
@@ -104,6 +106,7 @@ enum spi_nor_option_flags {
 #define STATUS_QEB_WINSPAN		BIT(1)
 #define STATUS_QEB_MXIC			BIT(6)
 #define STATUS_PEC			BIT(7)
+#define STATUS_QEB_MICRON		BIT(7)
 #define SR_BP0				BIT(2)  /* Block protect 0 */
 #define SR_BP1				BIT(3)  /* Block protect 1 */
 #define SR_BP2				BIT(4)  /* Block protect 2 */
drivers/mtd/spi/spi_flash.c +60 -2

80 lines not on this page · raw message

Signature · 1 line
1.9.1
author
#1 lore raw

PATCH v2 2/4 sf: Read back and check once spansion quad bit set

One spansion quad bit set using CR, it's good to read back and check the written bit and also if it's already been set check for the bit and return.

Cc Vignesh R <[email protected]>
Cc Mugunthan V N <[email protected]>
Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>
Cc Michal Simek <[email protected]>
Cc Siva Durga Prasad Paladugu <[email protected]>

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/mtd/spi/spi_flash.c +12 -6
index 8e8b89f..ba6651e 100644
@@ -862,12 +862,18 @@ static int spansion_quad_enable(struct spi_flash *flash)
 	if (ret < 0)
 		return ret;
 
-	if (qeb_status & STATUS_QEB_WINSPAN) {
-		debug("SF: winspan: QEB is already set\n");
-	} else {
-		ret = write_cr(flash, STATUS_QEB_WINSPAN);
-		if (ret < 0)
-			return ret;
+	if (qeb_status & STATUS_QEB_WINSPAN)
+		return 0;
+
+	ret = write_cr(flash, STATUS_QEB_WINSPAN);
+	if (ret < 0)
+		return ret;
+
+	/* read CR and check it */
+	ret = read_cr(flash, &qeb_status);
+	if (!(ret > 0 && (qeb_status & STATUS_QEB_WINSPAN))) {
+		printf("SF: Spansion CR Quad bit not clear\n");
+		return -EINVAL;
 	}
 
 	return ret;
Signature · 1 line
1.9.1
author
#2 lore raw

PATCH v2 3/4 sf: Read back and check once macronix quad bit set

In reply to Jagan Teki

One macronix quad bit set using SR, it's good to read back and check the written bit and also if it's already been set check for the bit and return.

Cc Vignesh R <[email protected]>
Cc Mugunthan V N <[email protected]>
Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/mtd/spi/spi_flash.c +12 -6
index ba6651e..c922322 100644
@@ -840,12 +840,18 @@ static int macronix_quad_enable(struct spi_flash *flash)
 	if (ret < 0)
 		return ret;
 
-	if (qeb_status & STATUS_QEB_MXIC) {
-		debug("SF: mxic: QEB is already set\n");
-	} else {
-		ret = write_sr(flash, STATUS_QEB_MXIC);
-		if (ret < 0)
-			return ret;
+	if (qeb_status & STATUS_QEB_MXIC)
+		return 0;
+
+	ret = write_sr(flash, STATUS_QEB_MXIC);
+	if (ret < 0)
+		return ret;
+
+	/* read SR and check it */
+	ret = read_sr(flash, &qeb_status);
+	if (!(ret > 0 && (qeb_status & STATUS_QEB_MXIC))) {
+		printf("SF: Macronix SR Quad bit not clear\n");
+		return -EINVAL;
 	}
 
 	return ret;
Signature · 1 line
1.9.1
#3 lore raw

PATCH v2 3/4 sf: Read back and check once macronix quad bit set

Quoted 30 lines · Jagan Teki

One macronix quad bit set using SR, it's good to read back and check the written bit and also if it's already been set check for the bit and return.

Cc Vignesh R <[email protected]>
Cc Mugunthan V N <[email protected]>
Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/mtd/spi/spi_flash.c +0 -6
index ba6651e..c922322 100644
@@ -840,12 +840,18 @@ static int macronix_quad_enable(struct spi_flash *flash)
 	if (ret < 0)
 		return ret;
 
-	if (qeb_status & STATUS_QEB_MXIC) {
-		debug("SF: mxic: QEB is already set\n");
-	} else {
-		ret = write_sr(flash, STATUS_QEB_MXIC);
-		if (ret < 0)
-			return ret;

drivers/mtd/spi/spi_flash.c static int macronix_quad_enable(struct spi_flash *flash) · line 852

Quoted 10 lines
drivers/mtd/spi/spi_flash.c +10 -0
+	if (qeb_status & STATUS_QEB_MXIC)
+		return 0;
+
+	ret = write_sr(flash, STATUS_QEB_MXIC);
+	if (ret < 0)
+		return ret;
+
+	/* read SR and check it */
+	ret = read_sr(flash, &qeb_status);
+	if (!(ret > 0 && (qeb_status & STATUS_QEB_MXIC))) {

This error check is wrong, it can be either one of the below

if (!(ret >= 0 && (qeb_status & STATUS_QEB_MXIC))) { or
if (ret < 0 || !(qeb_status & STATUS_QEB_MXIC)) {

Regards
Mugunthan V N

Quoted 6 lines
drivers/mtd/spi/spi_flash.c +2 -0
+		printf("SF: Macronix SR Quad bit not clear\n");
+		return -EINVAL;
 	}
 
 	return ret;
author
#4 lore raw

PATCH v2 3/4 sf: Read back and check once macronix quad bit set

Quoted 44 lines · Mugunthan V N
Quoted 30 lines · Jagan Teki

One macronix quad bit set using SR, it's good to read back and check the written bit and also if it's already been set check for the bit and return.

Cc Vignesh R <[email protected]>
Cc Mugunthan V N <[email protected]>
Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/mtd/spi/spi_flash.c +0 -6
index ba6651e..c922322 100644
@@ -840,12 +840,18 @@ static int macronix_quad_enable(struct spi_flash *flash)
      if (ret < 0)
              return ret;
 
-     if (qeb_status & STATUS_QEB_MXIC) {
-             debug("SF: mxic: QEB is already set\n");
-     } else {
-             ret = write_sr(flash, STATUS_QEB_MXIC);
-             if (ret < 0)
-                     return ret;

drivers/mtd/spi/spi_flash.c static int macronix_quad_enable(struct spi_flash *flash) · line 852

Quoted 10 lines
drivers/mtd/spi/spi_flash.c +10 -0
+     if (qeb_status & STATUS_QEB_MXIC)
+             return 0;
+
+     ret = write_sr(flash, STATUS_QEB_MXIC);
+     if (ret < 0)
+             return ret;
+
+     /* read SR and check it */
+     ret = read_sr(flash, &qeb_status);
+     if (!(ret > 0 && (qeb_status & STATUS_QEB_MXIC))) {

This error check is wrong, it can be either one of the below

Quoted 1 line

if (!(ret >= 0 && (qeb_status & STATUS_QEB_MXIC))) {

So =0 is a success case, this is what you pointing to correct? did you test this?

Quoted 11 lines

or
if (ret < 0 || !(qeb_status & STATUS_QEB_MXIC)) {

Regards
Mugunthan V N

Quoted 5 lines
drivers/mtd/spi/spi_flash.c +2 -0
+             printf("SF: Macronix SR Quad bit not clear\n");
+             return -EINVAL;
      }
 
      return ret;

thanks!

Signature · 1 line
Jagan.
#5 lore raw

PATCH v2 3/4 sf: Read back and check once macronix quad bit set

Quoted 45 lines · Jagan Teki
Quoted 44 lines · Mugunthan V N
Quoted 30 lines · Jagan Teki

One macronix quad bit set using SR, it's good to read back and check the written bit and also if it's already been set check for the bit and return.

Cc Vignesh R <[email protected]>
Cc Mugunthan V N <[email protected]>
Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>

---
Changes for v2:
- none

 drivers/mtd/spi/spi_flash.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/mtd/spi/spi_flash.c +0 -6
index ba6651e..c922322 100644
@@ -840,12 +840,18 @@ static int macronix_quad_enable(struct spi_flash *flash)
      if (ret < 0)
              return ret;
 
-     if (qeb_status & STATUS_QEB_MXIC) {
-             debug("SF: mxic: QEB is already set\n");
-     } else {
-             ret = write_sr(flash, STATUS_QEB_MXIC);
-             if (ret < 0)
-                     return ret;

drivers/mtd/spi/spi_flash.c static int macronix_quad_enable(struct spi_flash *flash) · line 852

Quoted 10 lines
drivers/mtd/spi/spi_flash.c +10 -0
+     if (qeb_status & STATUS_QEB_MXIC)
+             return 0;
+
+     ret = write_sr(flash, STATUS_QEB_MXIC);
+     if (ret < 0)
+             return ret;
+
+     /* read SR and check it */
+     ret = read_sr(flash, &qeb_status);
+     if (!(ret > 0 && (qeb_status & STATUS_QEB_MXIC))) {

This error check is wrong, it can be either one of the below

Quoted 4 lines
Quoted 1 line

if (!(ret >= 0 && (qeb_status & STATUS_QEB_MXIC))) {

So =0 is a success case, this is what you pointing to correct? did you test this?

Yeah, I have tested this on am437x-sk evm.

The same fix has to be done for spansion flash as well!

Regards
Mugunthan V N

author
#6 lore raw

PATCH v2 4/4 sf: Write quad bit along with read status

In reply to Jagan Teki

While setting quad bit on spansion, macronix code is writing only particular quad bit this may give wrong functionality with other register bits, So this patch fix the issue where it with write previous read reg status along particular quad bit.

Cc Vignesh R <[email protected]>
Cc Mugunthan V N <[email protected]>
Cc Simon Glass <[email protected]>
Cc Bin Meng <[email protected]>
Cc Michal Simek <[email protected]>
Cc Siva Durga Prasad Paladugu <[email protected]>

---
Changes for v2:
- newly added

 drivers/mtd/spi/spi_flash.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/spi/spi_flash.c +2 -2
index c922322..1ba6222 100644
@@ -843,7 +843,7 @@ static int macronix_quad_enable(struct spi_flash *flash)
 	if (qeb_status & STATUS_QEB_MXIC)
 		return 0;
 
-	ret = write_sr(flash, STATUS_QEB_MXIC);
+	ret = write_sr(flash, qeb_status | STATUS_QEB_MXIC);
 	if (ret < 0)
 		return ret;
 
@@ -871,7 +871,7 @@ static int spansion_quad_enable(struct spi_flash *flash)
 	if (qeb_status & STATUS_QEB_WINSPAN)
 		return 0;
 
-	ret = write_cr(flash, STATUS_QEB_WINSPAN);
+	ret = write_cr(flash, qeb_status | STATUS_QEB_WINSPAN);
 	if (ret < 0)
 		return ret;
 
Signature · 1 line
1.9.1