Skip to contentSkip to conversation

mtd: spi-nor: Make sure SFDP-based 4B_OPCODE support detection works correctly

PATCH Superseded Boris Brezillon 3 participants 5 messages Oct 18, 2018 – Oct 19, 2018

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 mtd: spi-nor: Make sure SFDP-based 4B_OPCODE support detection works correctly

Some flash_info entries have the SPI_NOR_4B_OPCODES flag set to let the core know that the flash supports 4B opcode. While this solution works fine for id-based caps detection, it doesn't work that well when relying on SFDP-based caps detection. Let's add an SNOR_F_4B_OPCODES flag so that spi_nor_parse_bfpt() can add it when the BFPT_DWORD1_ADDRESS_BYTES field is set to BFPT_DWORD1_ADDRESS_BYTES_4_ONLY.

---
Changes in v2:
- Fix the commit message
- Fix the ->addr_width check
- Add a comma at the end of the SNOR_F_4B_OPCODES definition

---
 drivers/mtd/spi-nor/spi-nor.c | 11 ++++++++---
 include/linux/mtd/spi-nor.h   |  1 +
 2 files changed, 9 insertions(+), 3 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +8 -3
index 9407ca5f9443..9155d3b9c37b 100644
@@ -2643,6 +2643,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
 		break;
 
 	case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY:
+		nor->flags |= SNOR_F_4B_OPCODES;
 		nor->addr_width = 4;
 		break;
 
@@ -3552,7 +3553,7 @@ static int spi_nor_init(struct spi_nor *nor)
 
 	if ((nor->addr_width == 4) &&
 	    (JEDEC_MFR(nor->info) != SNOR_MFR_SPANSION) &&
-	    !(nor->info->flags & SPI_NOR_4B_OPCODES)) {
+	    !(nor->flags & SNOR_F_4B_OPCODES)) {
 		/*
 		 * If the RESET# pin isn't hooked up properly, or the system
 		 * otherwise doesn't perform a reset command in the boot
@@ -3586,7 +3587,7 @@ void spi_nor_restore(struct spi_nor *nor)
 	/* restore the addressing mode */
 	if ((nor->addr_width == 4) &&
 	    (JEDEC_MFR(nor->info) != SNOR_MFR_SPANSION) &&
-	    !(nor->info->flags & SPI_NOR_4B_OPCODES) &&
+	    !(nor->flags & SNOR_F_4B_OPCODES) &&
 	    (nor->flags & SNOR_F_BROKEN_RESET))
 		set_4byte(nor, nor->info, 0);
 }
@@ -3744,11 +3745,15 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 		nor->addr_width = 4;
 		if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
 		    info->flags & SPI_NOR_4B_OPCODES)
-			spi_nor_set_4byte_opcodes(nor, info);
+			nor->flags |= SNOR_F_4B_OPCODES;
 	} else {
 		nor->addr_width = 3;
 	}
 
+	if (nor->addr_width == 4 &&
+	    nor->flags & SNOR_F_4B_OPCODES)
+		spi_nor_set_4byte_opcodes(nor, info);
+
 	if (nor->addr_width > SPI_NOR_MAX_ADDR_WIDTH) {
 		dev_err(dev, "address width is too large: %u\n",
 			nor->addr_width);
include/linux/mtd/spi-nor.h +1 -0
index 7f0c7303575e..5bc75110d5ea 100644
@@ -236,6 +236,7 @@ enum spi_nor_option_flags {
 	SNOR_F_READY_XSR_RDY	= BIT(4),
 	SNOR_F_USE_CLSR		= BIT(5),
 	SNOR_F_BROKEN_RESET	= BIT(6),
+	SNOR_F_4B_OPCODES	= BIT(7),
 };
 
 /**
Signature · 1 line
2.14.1
#1 lore raw

PATCH v2 2/2 mtd: spi-nor: Use 4B opcodes when the NOR advertises both 3B and 4B

When the NOR supports 4 bytes opcodes we should use those instead of switching the flash in 4-bytes mode. This way, we don't have to restore the addressing mode when resetting the board.

---
Changes in v2:
- None

---
 drivers/mtd/spi-nor/spi-nor.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/spi-nor/spi-nor.c +1 -0
index 9155d3b9c37b..72536a5dfe05 100644
@@ -2643,6 +2643,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
 		break;
 
 	case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY:
+	case BFPT_DWORD1_ADDRESS_BYTES_3_OR_4:
 		nor->flags |= SNOR_F_4B_OPCODES;
 		nor->addr_width = 4;
 		break;
Signature · 1 line
2.14.1
Tested-by on v2 2/2
#2 lore raw

Re: [PATCH v2 2/2] mtd: spi-nor: Use 4B opcodes when the NOR advertises both 3B and 4B

Quoted 5 lines · Boris Brezillon

When the NOR supports 4 bytes opcodes we should use those instead of switching the flash in 4-bytes mode. This way, we don't have to restore the addressing mode when resetting the board.

Quoted 23 lines

---
Changes in v2:
- None

---
 drivers/mtd/spi-nor/spi-nor.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/spi-nor/spi-nor.c +1 -0
index 9155d3b9c37b..72536a5dfe05 100644
@@ -2643,6 +2643,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
 		break;
 
 	case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY:
+	case BFPT_DWORD1_ADDRESS_BYTES_3_OR_4:
 		nor->flags |= SNOR_F_4B_OPCODES;
 		nor->addr_width = 4;
 		break;
Signature · 1 line
2.14.1
Signature · 3 lines
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Reviewed-by on v2 2/2
#3 lore raw

Re: [PATCH v2 2/2] mtd: spi-nor: Use 4B opcodes when the NOR advertises both 3B and 4B

In reply to Boris Brezillon

Le 18/10/2018 à 13:55, Boris Brezillon a écrit :

Quoted 5 lines

When the NOR supports 4 bytes opcodes we should use those instead of switching the flash in 4-bytes mode. This way, we don't have to restore the addressing mode when resetting the board.

Quoted 21 lines

---
Changes in v2:
- None

---
 drivers/mtd/spi-nor/spi-nor.c | 1 +
 1 file changed, 1 insertion(+)
drivers/mtd/spi-nor/spi-nor.c +1 -0
index 9155d3b9c37b..72536a5dfe05 100644
@@ -2643,6 +2643,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
 		break;
 
 	case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY:
+	case BFPT_DWORD1_ADDRESS_BYTES_3_OR_4:
 		nor->flags |= SNOR_F_4B_OPCODES;
 		nor->addr_width = 4;
 		break;
Tested-by on v2 1/2
#4 lore raw
In reply to Boris Brezillon
Quoted 8 lines · Boris Brezillon

Some flash_info entries have the SPI_NOR_4B_OPCODES flag set to let the core know that the flash supports 4B opcode. While this solution works fine for id-based caps detection, it doesn't work that well when relying on SFDP-based caps detection. Let's add an SNOR_F_4B_OPCODES flag so that spi_nor_parse_bfpt() can add it when the BFPT_DWORD1_ADDRESS_BYTES field is set to BFPT_DWORD1_ADDRESS_BYTES_4_ONLY.

Quoted 73 lines

---
Changes in v2:
- Fix the commit message
- Fix the ->addr_width check
- Add a comma at the end of the SNOR_F_4B_OPCODES definition

---
 drivers/mtd/spi-nor/spi-nor.c | 11 ++++++++---
 include/linux/mtd/spi-nor.h   |  1 +
 2 files changed, 9 insertions(+), 3 deletions(-)
drivers/mtd/spi-nor/spi-nor.c +8 -3
index 9407ca5f9443..9155d3b9c37b 100644
@@ -2643,6 +2643,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
 		break;
 
 	case BFPT_DWORD1_ADDRESS_BYTES_4_ONLY:
+		nor->flags |= SNOR_F_4B_OPCODES;
 		nor->addr_width = 4;
 		break;
 
@@ -3552,7 +3553,7 @@ static int spi_nor_init(struct spi_nor *nor)
 
 	if ((nor->addr_width == 4) &&
 	    (JEDEC_MFR(nor->info) != SNOR_MFR_SPANSION) &&
-	    !(nor->info->flags & SPI_NOR_4B_OPCODES)) {
+	    !(nor->flags & SNOR_F_4B_OPCODES)) {
 		/*
 		 * If the RESET# pin isn't hooked up properly, or the system
 		 * otherwise doesn't perform a reset command in the boot
@@ -3586,7 +3587,7 @@ void spi_nor_restore(struct spi_nor *nor)
 	/* restore the addressing mode */
 	if ((nor->addr_width == 4) &&
 	    (JEDEC_MFR(nor->info) != SNOR_MFR_SPANSION) &&
-	    !(nor->info->flags & SPI_NOR_4B_OPCODES) &&
+	    !(nor->flags & SNOR_F_4B_OPCODES) &&
 	    (nor->flags & SNOR_F_BROKEN_RESET))
 		set_4byte(nor, nor->info, 0);
 }
@@ -3744,11 +3745,15 @@ int spi_nor_scan(struct spi_nor *nor, const char *name,
 		nor->addr_width = 4;
 		if (JEDEC_MFR(info) == SNOR_MFR_SPANSION ||
 		    info->flags & SPI_NOR_4B_OPCODES)
-			spi_nor_set_4byte_opcodes(nor, info);
+			nor->flags |= SNOR_F_4B_OPCODES;
 	} else {
 		nor->addr_width = 3;
 	}
 
+	if (nor->addr_width == 4 &&
+	    nor->flags & SNOR_F_4B_OPCODES)
+		spi_nor_set_4byte_opcodes(nor, info);
+
 	if (nor->addr_width > SPI_NOR_MAX_ADDR_WIDTH) {
 		dev_err(dev, "address width is too large: %u\n",
 			nor->addr_width);
include/linux/mtd/spi-nor.h +1 -0
index 7f0c7303575e..5bc75110d5ea 100644
@@ -236,6 +236,7 @@ enum spi_nor_option_flags {
 	SNOR_F_READY_XSR_RDY	= BIT(4),
 	SNOR_F_USE_CLSR		= BIT(5),
 	SNOR_F_BROKEN_RESET	= BIT(6),
+	SNOR_F_4B_OPCODES	= BIT(7),
 };
 
 /**
Signature · 1 line
2.14.1
Signature · 3 lines
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com