mtd: spinand: winbond: Misc fixes
Subsystems (2)
Miquel Raynal
maintainercover 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]>
Miquel Raynal
maintainerPATCH 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
@@ -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
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.
Signed-off-by Miquel Raynal <[email protected]>--- cmd/mtd.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)cmd/mtd.c +6
-1@@ -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
-1continue ; } --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
Miquel Raynal
maintainerPATCH 2/3 mtd: spinand: winbond: Add missing QE bit on W25NxxJW devices
In reply to Miquel RaynalThese 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
@@ -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
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.
Signed-off-by Miquel Raynal <[email protected]>--- drivers/mtd/nand/spi/winbond.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/mtd/nand/spi/winbond.c +1
-1@@ -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
Miquel Raynal
maintainerPATCH 3/3 mtd: spinand: winbond: Clarify when to enable the HS bit
In reply to Miquel RaynalAbove 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
@@ -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
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.
Signed-off-by Miquel Raynal <[email protected]>---
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@@ -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
-1ret =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