Skip to contentSkip to conversation

mtd: spinand: Only touch the QE bit on chips that have one

PATCH In review Ahmed Naseef 2 participants 2 messages Sep 10 – Sep 20

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd: spinand: Only touch the QE bit on chips that have one

Since commit be0b86c648bf ("mtd: spinand: Gather all the bus interface steps in one single function") spinand_init_quad_enable() is called unconditionally and clears bit 0 of the configuration register even on chips without SPINAND_HAS_QE_BIT. On such chips that bit can have another
meaning: on the Winbond W25N02KV it is H-DIS (Hold Disable, default 1), and clearing it enables the /HOLD function, after which erase and program operations silently stop taking effect on MT7986 boards.

Only program the QE bit when the chip declares SPINAND_HAS_QE_BIT, as before.

Fixes be0b86c648bf ("mtd: spinand: Gather all the bus interface steps in one single function")
Assisted-by Claude Code:claude-opus-5
---
 drivers/mtd/nand/spi/core.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/mtd/nand/spi/core.c +10 -5
index 43bbe2629b85..9fc1512e4fe2 100644
@@ -1781,7 +1781,7 @@ static int spinand_detect(struct spinand_device *spinand)
 static int spinand_configure_chip(struct spinand_device *spinand)
 {
 	bool odtr = false, quad_enable = false;
-	int ret;
+	int ret = 0;
 
 	if (spinand->odtr_op_templates.read_cache &&
 	    spinand->odtr_op_templates.write_cache &&
@@ -1808,16 +1808,21 @@ static int spinand_configure_chip(struct spinand_device *spinand)
 	}
 
 try_ssdr:
+	/*
+	 * Only touch the QE bit on chips that actually have one. On other
+	 * chips bit 0 of the configuration register may have a different
+	 * meaning (e.g. H-DIS on the Winbond W25N02KV).
+	 */
 	if (spinand->flags & SPINAND_HAS_QE_BIT) {
 		if (spinand->ssdr_op_templates.read_cache->data.buswidth == 4 ||
 		    spinand->ssdr_op_templates.write_cache->data.buswidth == 4 ||
 		    spinand->ssdr_op_templates.update_cache->data.buswidth == 4)
 			quad_enable = true;
-	}
 
-	ret = spinand_init_quad_enable(spinand, quad_enable);
-	if (ret)
-		return ret;
+		ret = spinand_init_quad_enable(spinand, quad_enable);
+		if (ret)
+			return ret;
+	}
 
 	if (spinand->configure_chip) {
 		ret = spinand->configure_chip(spinand, SSDR);

base-commit: 21f027016b1290d13c30b198ae7a00e6b3d1d5a5

Signature · 1 line
2.34.1
maintainer
#1 lore raw

Hi Ahmed,

Quoted 10 lines · Ahmed Naseef

Since commit be0b86c648bf ("mtd: spinand: Gather all the bus interface steps in one single function") spinand_init_quad_enable() is called unconditionally and clears bit 0 of the configuration register even on chips without SPINAND_HAS_QE_BIT. On such chips that bit can have another
meaning: on the Winbond W25N02KV it is H-DIS (Hold Disable, default 1), and clearing it enables the /HOLD function, after which erase and program operations silently stop taking effect on MT7986 boards.

Only program the QE bit when the chip declares SPINAND_HAS_QE_BIT, as before.

Sorry for the breakage and thanks for the fix, unfortunately it arrived just after another commit -which I am about to apply now-, therefore I must take the first patch sent visible there:

https://lore.kernel.org/linux-mtd/010701a08d7e1638-79aaf1ea-cc8c-49e8-ba74-cba028aaa183-000000@eu-central-1.amazonses.com/

Is is very close to your proposal.

Thanks,
Miquèl