Skip to contentSkip to conversation

mtd: spinand: winbond: Misc fixes

PATCH In review Miquel Raynal 2 participants 7 messages Apr 3 – Apr 5

Subsystems (2)
lore
Share & tools
lore

Miquel Raynal

author maintainer
#0 lore raw

cover mtd: spinand: winbond: Misc fixes

Hello,

Here is a small series slightly improving mtd support after a significant round of testing on top of Mikhail's work. Overall everything worked well, I just wanted to port two more patches from Linux which have been contributed after the SPI NAND update, plus a small command behavior improvement.

With these small enhancements, I could successfully test Winbond W25NxxJW chips in single, dual and quand modes, as well as W35NxxJW chips in single mode.

Thanks,
Miquèl

---
Miquel Raynal (3):
cmd: mtd: Prevent out-of-bound check
mtd: spinand: winbond: Add missing QE bit on W25NxxJW devices
mtd: spinand: winbond: Clarify when to enable the HS bit

 cmd/mtd.c                      | 12 +++++++++++-
 drivers/mtd/nand/spi/winbond.c | 17 ++++++++++-------
 2 files changed, 21 insertions(+), 8 deletions(-)

---
base-commit: 1ed7f122452b0336a0142fcdfebc7fcde6be0606
change-id: 20260403-winbond-ma35d1-b0b51e99473e

Best regards,

Signature · 1 line
Miquel Raynal <[email protected]>
author maintainer
#1 lore raw

PATCH 1/3 cmd: mtd: Prevent out-of-bound check

The while() loops searching for the next "good" block is unbounded, which means in some cases when looking close to the end of the device (or during development purposes) this check may lead to unexpected behaviours.

For instance, I observed the SPI NAND core complaining because there was a single "target" (as in "die"), but the core was selecting the second one, which is simply impossible as it does not exist.

---
 cmd/mtd.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
cmd/mtd.c +11 -1
index 7f25144098bb..d3289ab5edbf 100644
@@ -559,8 +559,13 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
 
 	/* Search for the first good block after the given offset */
 	off = start_off;
-	while (mtd_block_isbad(mtd, off))
+	while (mtd_block_isbad(mtd, off)) {
 		off += mtd->erasesize;
+		if (off >= mtd->size) {
+			ret = CMD_RET_FAILURE;
+			goto out_put_mtd;
+		}
+	}
 
 	led_activity_blink();
 
@@ -573,6 +578,11 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
 		if (mtd_is_aligned_with_block_size(mtd, off) &&
 		    mtd_block_isbad(mtd, off)) {
 			off += mtd->erasesize;
+			if (off >= mtd->size) {
+				ret = CMD_RET_FAILURE;
+				goto out_put_mtd;
+			}
+
 			continue;
 		}
 
Signature · 1 line
2.53.0
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] cmd: mtd: Prevent out-of-bound check

Hi

Quoted 35 lines · Miquel Raynal

The while() loops searching for the next "good" block is unbounded, which means in some cases when looking close to the end of the device (or during development purposes) this check may lead to unexpected behaviours.

For instance, I observed the SPI NAND core complaining because there was a single "target" (as in "die"), but the core was selecting the second one, which is simply impossible as it does not exist.

---
 cmd/mtd.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
cmd/mtd.c +6 -1
index 7f25144098bb..d3289ab5edbf 100644
@@ -559,8 +559,13 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
 
        /* Search for the first good block after the given offset */
        off = start_off;
-       while (mtd_block_isbad(mtd, off))
+       while (mtd_block_isbad(mtd, off)) {
                off += mtd->erasesize;
+               if (off >= mtd->size) {
+                       ret = CMD_RET_FAILURE;
+                       goto out_put_mtd;
+               }
+       }
 
        led_activity_blink();
 

cmd/mtd.c static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc, · line 585

Quoted 8 lines
cmd/mtd.c +5 -0
@@ -573,6 +578,11 @@ static int do_mtd_io(struct cmd_tbl *cmdtp, int flag, int argc,
                if (mtd_is_aligned_with_block_size(mtd, off) &&
                    mtd_block_isbad(mtd, off)) {
                        off += mtd->erasesize;
+                       if (off >= mtd->size) {
+                               ret = CMD_RET_FAILURE;
+                               goto out_put_mtd;
+                       }
+
Quoted 7 lines
cmd/mtd.c +0 -1
                        continue;
                }
 
 
--

2.53.0

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
author maintainer
#3 lore raw

PATCH 2/3 mtd: spinand: winbond: Add missing QE bit on W25NxxJW devices

In reply to Miquel Raynal

These devices have a bit in their status register to enable the Quad capability, make sure it is set when using quad mode.

---
 drivers/mtd/nand/spi/winbond.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/nand/spi/winbond.c +2 -2
index a89aaec516b7..79c3354efb65 100644
@@ -398,7 +398,7 @@ static const struct spinand_info winbond_spinand_table[] = {
 		     SPINAND_INFO_OP_VARIANTS(&read_cache_dual_quad_dtr_variants,
 					      &write_cache_variants,
 					      &update_cache_variants),
-		     0,
+		     SPINAND_HAS_QE_BIT,
 		     SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL),
 		     SPINAND_CONFIGURE_CHIP(w25n0xjw_hs_cfg)),
 	SPINAND_INFO("W25N01KV", /* 3.3V */
@@ -458,7 +458,7 @@ static const struct spinand_info winbond_spinand_table[] = {
 		     SPINAND_INFO_OP_VARIANTS(&read_cache_dual_quad_dtr_variants,
 					      &write_cache_variants,
 					      &update_cache_variants),
-		     0,
+		     SPINAND_HAS_QE_BIT,
 		     SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL),
 		     SPINAND_CONFIGURE_CHIP(w25n0xjw_hs_cfg)),
 	SPINAND_INFO("W25N02KV", /* 3.3V */
Signature · 1 line
2.53.0
Reviewed-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] mtd: spinand: winbond: Add missing QE bit on W25NxxJW devices

Hi

Quoted 23 lines · Miquel Raynal

These devices have a bit in their status register to enable the Quad capability, make sure it is set when using quad mode.

---
 drivers/mtd/nand/spi/winbond.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/nand/spi/winbond.c +1 -1
index a89aaec516b7..79c3354efb65 100644
@@ -398,7 +398,7 @@ static const struct spinand_info winbond_spinand_table[] = {
                     SPINAND_INFO_OP_VARIANTS(&read_cache_dual_quad_dtr_variants,
                                              &write_cache_variants,
                                              &update_cache_variants),
-                    0,
+                    SPINAND_HAS_QE_BIT,
                     SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL),
                     SPINAND_CONFIGURE_CHIP(w25n0xjw_hs_cfg)),
        SPINAND_INFO("W25N01KV", /* 3.3V */

drivers/mtd/nand/spi/winbond.c static const struct spinand_info winbond_spinand_table[] = { · line 464

Quoted 8 lines
drivers/mtd/nand/spi/winbond.c +1 -1
@@ -458,7 +458,7 @@ static const struct spinand_info winbond_spinand_table[] = {
                     SPINAND_INFO_OP_VARIANTS(&read_cache_dual_quad_dtr_variants,
                                              &write_cache_variants,
                                              &update_cache_variants),
-                    0,
+                    SPINAND_HAS_QE_BIT,
                     SPINAND_ECCINFO(&w25m02gv_ooblayout, NULL),
                     SPINAND_CONFIGURE_CHIP(w25n0xjw_hs_cfg)),
        SPINAND_INFO("W25N02KV", /* 3.3V */
Quoted 4 lines

--
2.53.0

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com
author maintainer
#5 lore raw

PATCH 3/3 mtd: spinand: winbond: Clarify when to enable the HS bit

In reply to Miquel Raynal

Above 104MHz when in fast dual or quad I/O reads, the delay between address and data cycles is too short. It is possible to reach higher frequencies, up to 166MHz, by adding a few more dummy cycles through the setting of the HS bit. Improve the condition for enabling this bit, and also make sure we set it at soon as we go over 104MHz.

---
This is a port from Linux.

---
 drivers/mtd/nand/spi/winbond.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/mtd/nand/spi/winbond.c +8 -5
index 79c3354efb65..accb46dfeb03 100644
@@ -261,16 +261,19 @@ static int w25n0xjw_hs_cfg(struct spinand_device *spinand)
 	u8 sr4;
 	int ret;
 
+	/*
+	 * SDR dual and quad I/O operations over 104MHz require the HS bit to
+	 * enable a few more dummy cycles.
+	 */
 	op = spinand->op_templates.read_cache;
 	if (op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr)
 		hs = false;
-	else if (op->cmd.buswidth == 1 && op->addr.buswidth == 1 &&
-		 op->dummy.buswidth == 1 && op->data.buswidth == 1)
+	else if (op->cmd.buswidth != 1 || op->addr.buswidth != 1)
+		hs = false;
+	else if (op->max_freq && op->max_freq <= 104 * HZ_PER_MHZ)
 		hs = false;
-	else if (!op->max_freq)
-		hs = true;
 	else
-		hs = false;
+		hs = true;
 
 	ret = spinand_read_reg_op(spinand, W25N0XJW_SR4, &sr4);
 	if (ret)
Signature · 1 line
2.53.0
Reviewed-by on v1 3/3
#6 lore raw

Re: [PATCH 3/3] mtd: spinand: winbond: Clarify when to enable the HS bit

Hi

Quoted 31 lines · Miquel Raynal

Above 104MHz when in fast dual or quad I/O reads, the delay between address and data cycles is too short. It is possible to reach higher frequencies, up to 166MHz, by adding a few more dummy cycles through the setting of the HS bit. Improve the condition for enabling this bit, and also make sure we set it at soon as we go over 104MHz.

---
This is a port from Linux.

---
 drivers/mtd/nand/spi/winbond.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/mtd/nand/spi/winbond.c +4 -2
index 79c3354efb65..accb46dfeb03 100644
@@ -261,16 +261,19 @@ static int w25n0xjw_hs_cfg(struct spinand_device *spinand)
        u8 sr4;
        int ret;
 
+       /*
+        * SDR dual and quad I/O operations over 104MHz require the HS bit to
+        * enable a few more dummy cycles.
+        */
        op = spinand->op_templates.read_cache;
        if (op->cmd.dtr || op->addr.dtr || op->dummy.dtr || op->data.dtr)
                hs = false;
-       else if (op->cmd.buswidth == 1 && op->addr.buswidth == 1 &&
-                op->dummy.buswidth == 1 && op->data.buswidth == 1)

drivers/mtd/nand/spi/winbond.c static int w25n0xjw_hs_cfg(struct spinand_device *spinand) · line 277

Quoted 10 lines
drivers/mtd/nand/spi/winbond.c +4 -3
+       else if (op->cmd.buswidth != 1 || op->addr.buswidth != 1)
+               hs = false;
+       else if (op->max_freq && op->max_freq <= 104 * HZ_PER_MHZ)
                hs = false;
-       else if (!op->max_freq)
-               hs = true;
        else
-               hs = false;
+               hs = true;
 
Quoted 6 lines
drivers/mtd/nand/spi/winbond.c +0 -1
        ret = spinand_read_reg_op(spinand, W25N0XJW_SR4, &sr4);
        if (ret)
 
--

2.53.0

Signature · 11 lines
Michael Nazzareno Trimarchi
Co-Founder & Chief Executive Officer
M. +39 347 913 2170
[email protected]
__________________________________

Amarula Solutions BV
Joop Geesinkweg 125, 1114 AB, Amsterdam, NL
T. +31 (0)85 111 9172
[email protected]
www.amarulasolutions.com