Skip to contentSkip to conversation

mtd: spinand: winbond: add support for additional SPI-NAND devices

PATCH In review Md Sadre Alam 3 participants 11 messages Aug 7 – Aug 11

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

cover mtd: spinand: winbond: add support for additional SPI-NAND devices

This series adds support for three Winbond SPI-NAND devices that are currently not recognized by the winbond SPI-NAND driver.

The W25N01KW and W25N02LW share page geometry and ECC handling with existing supported devices and therefore reuse the existing OOB layout definitions and ECC status callbacks.

The W25N04LW uses a different page and spare-area organization from the existing W25N04KV/W25N04KW devices and requires a dedicated OOB layout description.

Md Sadre Alam (2):
mtd: spinand: winbond: add support for W25N04LW
mtd: spinand: winbond: Add support for W25N01KW and W25N02LW

 drivers/mtd/nand/spi/winbond.c | 50 ++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 mtd: spinand: winbond: add support for W25N04LW

Add support for Winbond W25N04LW 4Gbit SPI-NAND. It has 8-bit on-die ECC and a 4096+256 byte page (4096 byte main area, 128 byte usable OOB once on-chip ECC hides the 128 byte parity area), organized as 2048 blocks of 64 pages each, unlike the existing 2048 byte page W25N04KV/W25N04KW parts.

---
 drivers/mtd/nand/spi/winbond.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
drivers/mtd/nand/spi/winbond.c +32 -0
index 9b78c1e6cbc9..b0147b7cb76f 100644
@@ -345,6 +345,29 @@ static const struct mtd_ooblayout_ops w25n02kv_ooblayout = {
 	.free = w25n02kv_ooblayout_free,
 };
 
+static int w25n04lw_ooblayout_ecc(struct mtd_info *mtd, int section,
+				  struct mtd_oob_region *region)
+{
+	return -ERANGE;
+}
+
+static int w25n04lw_ooblayout_free(struct mtd_info *mtd, int section,
+				   struct mtd_oob_region *region)
+{
+	if (section)
+		return -ERANGE;
+
+	region->offset = 2;
+	region->length = mtd->oobsize - 2;
+
+	return 0;
+}
+
+static const struct mtd_ooblayout_ops w25n04lw_ooblayout = {
+	.ecc = w25n04lw_ooblayout_ecc,
+	.free = w25n04lw_ooblayout_free,
+};
+
 static int w25n01jw_ooblayout_ecc(struct mtd_info *mtd, int section,
 				  struct mtd_oob_region *region)
 {
@@ -768,6 +791,15 @@ static const struct spinand_info winbond_spinand_table[] = {
 					      &update_cache_variants),
 		     0,
 		     SPINAND_ECCINFO(&w25n02kv_ooblayout, w25n02kv_ecc_get_status)),
+	SPINAND_INFO("W25N04LW", /* 1.8V */
+		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xb2, 0x23),
+		     NAND_MEMORG(1, 4096, 128, 64, 2048, 40, 1, 1, 1),
+		     NAND_ECCREQ(8, 512),
+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+					      &write_cache_variants,
+					      &update_cache_variants),
+		     0,
+		     SPINAND_ECCINFO(&w25n04lw_ooblayout, w25n02kv_ecc_get_status)),
 	SPINAND_INFO("W35N04JW", /* 1.8V */
 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xdf, 0x23),
 		     NAND_MEMORG(1, 4096, 128, 64, 512, 10, 1, 4, 1),
Signature · 1 line
2.34.1
maintainer
#2 lore raw

Re: [PATCH 1/2] mtd: spinand: winbond: add support for W25N04LW

Quoted 4 lines · Md Sadre Alam

Add support for Winbond W25N04LW 4Gbit SPI-NAND. It has 8-bit on-die ECC and a 4096+256 byte page (4096 byte main area, 128 byte usable OOB once on-chip ECC hides the 128 byte parity area),

That is not what you did below. Below you declare 254 free bytes.

Thanks,
Miquèl

#3 lore raw

Re: [PATCH 1/2] mtd: spinand: winbond: add support for W25N04LW

In reply to Md Sadre Alam

Md Sadre Alam wrote on Fri, Aug 07, 2026 at 12:13:38PM +0530:

Quoted 6 lines

Add support for Winbond W25N04LW 4Gbit SPI-NAND. It has 8-bit on-die ECC and a 4096+256 byte page (4096 byte main area, 128 byte usable OOB once on-chip ECC hides the 128 byte parity area), organized as 2048 blocks of 64 pages each, unlike the existing 2048 byte page W25N04KV/W25N04KW parts.

This is pretty good timing, I was just looking at sending a patch for W25N04LW myself!

I agree with Miquèl that your patch looks odd, you wrote

Review

Quoted 1 line
(quoted diff) +1 -0
+		     NAND_MEMORG(1, 4096, 128, 64, 2048, 40, 1, 1, 1),

but the erase blocks are 256K long so it should be
+ NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),

did you actually test this device?

If it helps, the datasheet for W25N04LWZExx / W25N04LWTBxx is freely
available from digikey here[1]
[1] https://mm.digikey.com/Volume0/opasdata/d220001/medias/docus/7182/W25N04LWZExx_W25N04LWTBxx_RevD_2025-08-05.pdf

(And it also supports continuous read, so I'm curious to see if it'd
work with the recent continous read support from Miquèl[2] merged in
7.2... I'm not familiar with the subsystem so will need a bit of time to
plug all the hooks in properly)
[2] https://lore.kernel.org/linux-mtd/20260429-winbond-v6-18-rc1-cont-read-v3-0-0f38b3c229ad@bootlin.com/

FWIW, I've confirmed it works with the following diff (at least up to the point of creating an ubi volume and booting from it); happy to send this as a patch if this has indeed not been tested
------------

drivers/mtd/nand/spi/winbond.c +38 -0
index 9b78c1e6cbc9..43a4886dc4a5 100644
@@ -335,6 +335,30 @@ static int w25n02kv_ooblayout_free(struct mtd_info *mtd, int section,
 	return 0;
 }
 
+static int w25n04lw_ooblayout_ecc(struct mtd_info *mtd, int section,
+				  struct mtd_oob_region *region)
+{
+	if (section > 7)
+		return -ERANGE;
+
+	region->offset = 128 + (16 * section);
+	region->length = 13;
+
+	return 0;
+}
+
+static int w25n04lw_ooblayout_free(struct mtd_info *mtd, int section,
+				   struct mtd_oob_region *region)
+{
+	if (section > 7)
+		return -ERANGE;
+
+	region->offset = (16 * section) + 2;
+	region->length = 14;
+
+	return 0;
+}
+
 static const struct mtd_ooblayout_ops w25n01kv_ooblayout = {
 	.ecc = w25n01kv_ooblayout_ecc,
 	.free = w25n02kv_ooblayout_free,
@@ -345,6 +369,11 @@ static const struct mtd_ooblayout_ops w25n02kv_ooblayout = {
 	.free = w25n02kv_ooblayout_free,
 };
 
+static const struct mtd_ooblayout_ops w25n04lw_ooblayout = {
+	.ecc = w25n04lw_ooblayout_ecc,
+	.free = w25n04lw_ooblayout_free,
+};
+
 static int w25n01jw_ooblayout_ecc(struct mtd_info *mtd, int section,
 				  struct mtd_oob_region *region)
 {
@@ -768,6 +797,15 @@ static const struct spinand_info winbond_spinand_table[] = {
 					      &update_cache_variants),
 		     0,
 		     SPINAND_ECCINFO(&w25n02kv_ooblayout, w25n02kv_ecc_get_status)),
+	SPINAND_INFO("W25N04LW", /* 1.8V */
+		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xb2, 0x23),
+		     NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
+		     NAND_ECCREQ(8, 512),
+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+					      &write_cache_variants,
+					      &update_cache_variants),
+		     0,
+		     SPINAND_ECCINFO(&w25n04lw_ooblayout, w25n02kv_ecc_get_status)),
 	SPINAND_INFO("W35N04JW", /* 1.8V */
 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xdf, 0x23),
 		     NAND_MEMORG(1, 4096, 128, 64, 512, 10, 1, 4, 1),

-----------------

Thanks,

Signature · 5 lines
Dominique Martinet | Asmadeus

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
maintainer
#4 lore raw

Re: [PATCH 1/2] mtd: spinand: winbond: add support for W25N04LW

Hi Dominique,

Quoted 16 lines · Dominique MARTINET

Md Sadre Alam wrote on Fri, Aug 07, 2026 at 12:13:38PM +0530:

Quoted 6 lines

Add support for Winbond W25N04LW 4Gbit SPI-NAND. It has 8-bit on-die ECC and a 4096+256 byte page (4096 byte main area, 128 byte usable OOB once on-chip ECC hides the 128 byte parity area), organized as 2048 blocks of 64 pages each, unlike the existing 2048 byte page W25N04KV/W25N04KW parts.

This is pretty good timing, I was just looking at sending a patch for W25N04LW myself!

I agree with Miquèl that your patch looks odd, you wrote

Review

Quoted 1 line
(quoted diff) +1 -0
+		     NAND_MEMORG(1, 4096, 128, 64, 2048, 40, 1, 1, 1),

but the erase blocks are 256K long so it should be

drivers/mtd/nand/spi/winbond.c +1 -0
+		     NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
Quoted 5 lines

did you actually test this device?

If it helps, the datasheet for W25N04LWZExx / W25N04LWTBxx is freely
available from digikey here[1]
[1] https://mm.digikey.com/Volume0/opasdata/d220001/medias/docus/7182/W25N04LWZExx_W25N04LWTBxx_RevD_2025-08-05.pdf

Thanks for all the feedback, Sadre, can you please propose an udpate with these details and changes?

Quoted 6 lines

(And it also supports continuous read, so I'm curious to see if it'd work with the recent continous read support from Miquèl[2] merged in 7.2... I'm not familiar with the subsystem so will need a bit of time to plug all the hooks in properly)
[2]
https://lore.kernel.org/linux-mtd/20260429-winbond-v6-18-rc1-cont-read-v3-0-0f38b3c229ad@bootlin.com/

If it has continuous read, it requires the flag and a hook to enable/disable the feature. The existing Winbond helper may already be enough for it. You can test it with a recent version of mtd-utils, I added options to nanddump, nandbiterrs and flash_speed for that.

If Sadre dooesn't do it, you can propose a follow-up patch.

Thanks,
Miquèl

#5 lore raw

Re: [PATCH 1/2] mtd: spinand: winbond: add support for W25N04LW

Quoted 20 lines · Miquel Raynal

Hi Dominique,

Quoted 16 lines · Dominique MARTINET

Md Sadre Alam wrote on Fri, Aug 07, 2026 at 12:13:38PM +0530:

Quoted 6 lines

Add support for Winbond W25N04LW 4Gbit SPI-NAND. It has 8-bit on-die ECC and a 4096+256 byte page (4096 byte main area, 128 byte usable OOB once on-chip ECC hides the 128 byte parity area), organized as 2048 blocks of 64 pages each, unlike the existing 2048 byte page W25N04KV/W25N04KW parts.

This is pretty good timing, I was just looking at sending a patch for W25N04LW myself!

I agree with Miquèl that your patch looks odd, you wrote

Review

Quoted 1 line
(quoted diff) +1 -0
+		     NAND_MEMORG(1, 4096, 128, 64, 2048, 40, 1, 1, 1),

but the erase blocks are 256K long so it should be

drivers/mtd/nand/spi/winbond.c +1 -0
+		     NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),
Quoted 8 lines
Quoted 5 lines

did you actually test this device?

If it helps, the datasheet for W25N04LWZExx / W25N04LWTBxx is freely
available from digikey here[1]
[1] https://mm.digikey.com/Volume0/opasdata/d220001/medias/docus/7182/W25N04LWZExx_W25N04LWTBxx_RevD_2025-08-05.pdf

Thanks for all the feedback, Sadre, can you please propose an udpate with these details and changes?

I do not currently have access to this device, so I cannot properly validate an updated version on hardware.

Given that the current patch needs the OOB size fixed to 256, and likely the OOB layout adjusted accordingly, I think it is better if Dominique sends his tested version. I am fine with him taking over this patch.

Quoted 8 lines
Quoted 7 lines

(And it also supports continuous read, so I'm curious to see if it'd work with the recent continous read support from Miquèl[2] merged in 7.2... I'm not familiar with the subsystem so will need a bit of time to plug all the hooks in properly)
[2]
https://lore.kernel.org/linux-mtd/20260429-winbond-v6-18-rc1-cont-read-v3-0-0f38b3c229ad@bootlin.com/

Quoted 6 lines

If it has continuous read, it requires the flag and a hook to enable/disable the feature. The existing Winbond helper may already be enough for it. You can test it with a recent version of mtd-utils, I added options to nanddump, nandbiterrs and flash_speed for that.

If Sadre dooesn't do it, you can propose a follow-up patch.

I currently do not have access to this device to test continuous read, so please go ahead with the follow-up patch if you have hardware to validate it.

Thanks,
Alam.

#6 lore raw

Re: [PATCH 1/2] mtd: spinand: winbond: add support for W25N04LW

In reply to Dominique MARTINET
Quoted 29 lines · Dominique MARTINET

Md Sadre Alam wrote on Fri, Aug 07, 2026 at 12:13:38PM +0530:

Quoted 6 lines

Add support for Winbond W25N04LW 4Gbit SPI-NAND. It has 8-bit on-die ECC and a 4096+256 byte page (4096 byte main area, 128 byte usable OOB once on-chip ECC hides the 128 byte parity area), organized as 2048 blocks of 64 pages each, unlike the existing 2048 byte page W25N04KV/W25N04KW parts.

This is pretty good timing, I was just looking at sending a patch for W25N04LW myself!

I agree with Miquèl that your patch looks odd, you wrote

Review

Quoted 1 line
(quoted diff) +1 -0
+		     NAND_MEMORG(1, 4096, 128, 64, 2048, 40, 1, 1, 1),

but the erase blocks are 256K long so it should be

drivers/mtd/nand/spi/winbond.c +1 -0
+		     NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),

did you actually test this device?

If it helps, the datasheet for W25N04LWZExx / W25N04LWTBxx is freely
available from digikey here[1]
[1] https://mm.digikey.com/Volume0/opasdata/d220001/medias/docus/7182/W25N04LWZExx_W25N04LWTBxx_RevD_2025-08-05.pdf

(And it also supports continuous read, so I'm curious to see if it'd
work with the recent continous read support from Miquèl[2] merged in
7.2... I'm not familiar with the subsystem so will need a bit of time to
plug all the hooks in properly)
[2] https://lore.kernel.org/linux-mtd/20260429-winbond-v6-18-rc1-cont-read-v3-0-0f38b3c229ad@bootlin.com/

Quoted 3 lines

FWIW, I've confirmed it works with the following diff (at least up to the point of creating an ubi volume and booting from it); happy to send this as a patch if this has indeed not been tested

This device was supported in our downstream tree and was tested there. I picked that patch and posted it upstream assuming the configuration was already correct.
The 128 in:
NAND_MEMORG(1, 4096, 128, 64, 2048, 40, 1, 1, 1)
was my mistake. It should indeed be 256, matching the 4096 + 256 page layout in the W25N04LW datasheet.
Please go ahead and post your tested patch. I do not currently have this device available to retest the upstream version.

Thanks,
Alam.

#7 lore raw

Re: [PATCH 1/2] mtd: spinand: winbond: add support for W25N04LW

Md Sadre Alam wrote on Tue, Aug 11, 2026 at 06:10:50PM +0530:

Quoted 4 lines

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

Quoted 4 lines

I agree with Miquèl that your patch looks odd, you wrote

Review

Quoted 1 line
(quoted diff) +1 -0
+		     NAND_MEMORG(1, 4096, 128, 64, 2048, 40, 1, 1, 1),

but the erase blocks are 256K long so it should be

drivers/mtd/nand/spi/winbond.c +1 -0
+		     NAND_MEMORG(1, 4096, 256, 64, 2048, 40, 1, 1, 1),

(I misremembered NAND_MEMORG() fields, the 256 is indeed the OOB area size as you pointed out; the erase blocks were already correct at 64 pages = 256KB so while the settings were wrong this might actually not be visible at all in quick testing; sorry)

Quoted 4 lines
Quoted 3 lines

FWIW, I've confirmed it works with the following diff (at least up to the point of creating an ubi volume and booting from it); happy to send this as a patch if this has indeed not been tested

Quoted 9 lines

This device was supported in our downstream tree and was tested there. I picked that patch and posted it upstream assuming the configuration was already correct.
The 128 in:
NAND_MEMORG(1, 4096, 128, 64, 2048, 40, 1, 1, 1)
was my mistake. It should indeed be 256, matching the 4096 + 256 page layout in the W25N04LW datasheet.
Please go ahead and post your tested patch. I do not currently have this device available to retest the upstream version.

Ok, let me do some slightly more thorough checks and clean up a bit and I'll send a v2 later this week/early next week

The continuous read feature also definitely is interesting to me and I'll be testing it later, but it's "just" a performance improvement so I'll be taking a bit longer; I'll come back with either a patch or questions hopefully by next month ish

Thanks,

Signature · 1 line
Dominique
#8 lore raw

PATCH 2/2 mtd: spinand: winbond: add support for W25N01KW and W25N02LW

In reply to Md Sadre Alam

Add support for the Winbond W25N01KW and W25N02LW SPI-NAND devices.

The W25N01KW shares the same geometry, OOB layout, and ECC status handling as the existing W25N01KV, while the W25N02LW matches the existing W25N02KV/W25N02KW devices and reuses their OOB layout and ECC status callback.

---
 drivers/mtd/nand/spi/winbond.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/mtd/nand/spi/winbond.c +18 -0
index b0147b7cb76f..3bffa13bfa68 100644
@@ -704,6 +704,15 @@ static const struct spinand_info winbond_spinand_table[] = {
 					      &update_cache_variants),
 		     0,
 		     SPINAND_ECCINFO(&w25n01kv_ooblayout, w25n02kv_ecc_get_status)),
+	SPINAND_INFO("W25N01KW", /* 1.8V */
+		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xbe, 0x21),
+		     NAND_MEMORG(1, 2048, 96, 64, 1024, 20, 1, 1, 1),
+		     NAND_ECCREQ(4, 512),
+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+					      &write_cache_variants,
+					      &update_cache_variants),
+		     0,
+		     SPINAND_ECCINFO(&w25n01kv_ooblayout, w25n02kv_ecc_get_status)),
 	SPINAND_INFO("W35N01JW", /* 1.8V */
 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xdc, 0x21),
 		     NAND_MEMORG(1, 4096, 128, 64, 512, 10, 1, 1, 1),
@@ -759,6 +768,15 @@ static const struct spinand_info winbond_spinand_table[] = {
 					      &update_cache_variants),
 		     0,
 		     SPINAND_ECCINFO(&w25n02kv_ooblayout, w25n02kv_ecc_get_status)),
+	SPINAND_INFO("W25N02LW", /* 1.8V */
+		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x12, 0x22),
+		     NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
+		     NAND_ECCREQ(8, 512),
+		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
+					      &write_cache_variants,
+					      &update_cache_variants),
+		     0,
+		     SPINAND_ECCINFO(&w25n02kv_ooblayout, w25n02kv_ecc_get_status)),
 	SPINAND_INFO("W35N02JW", /* 1.8V */
 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xdf, 0x22),
 		     NAND_MEMORG(1, 4096, 128, 64, 512, 10, 1, 2, 1),
Signature · 1 line
2.34.1
maintainer
#9 lore raw

Re: [PATCH 2/2] mtd: spinand: winbond: add support for W25N01KW and W25N02LW

Hi Sadre,

Quoted 10 lines · Md Sadre Alam

Add support for the Winbond W25N01KW and W25N02LW SPI-NAND devices.

The W25N01KW shares the same geometry, OOB layout, and ECC status handling as the existing W25N01KV, while the W25N02LW matches the existing W25N02KV/W25N02KW devices and reuses their OOB layout and ECC status callback.

---

Sashiko raises a point:

- [Medium] The device ID 0x12, 0x22 for W25N02LW breaks the established pattern for Winbond 1.8V SPI NAND devices and is highly likely a typo for 0xb2, 0x22.

Can you please check?

Thanks,
Miquèl

#10 lore raw

Re: [PATCH 2/2] mtd: spinand: winbond: add support for W25N01KW and W25N02LW

Quoted 15 lines · Miquel Raynal

Hi Sadre,

Quoted 10 lines · Md Sadre Alam

Add support for the Winbond W25N01KW and W25N02LW SPI-NAND devices.

The W25N01KW shares the same geometry, OOB layout, and ECC status handling as the existing W25N01KV, while the W25N02LW matches the existing W25N02KV/W25N02KW devices and reuses their OOB layout and ECC status callback.

---

Quoted 7 lines

Sashiko raises a point:

- [Medium] The device ID 0x12, 0x22 for W25N02LW breaks the established pattern for Winbond 1.8V SPI NAND devices and is highly likely a typo for 0xb2, 0x22.

Can you please check?

I checked the W25N02LW datasheet, section 8.1.1 "Manufacturer and Device Identification". It lists the W25N02LW Device ID as 1222h.

Thanks,
Alam.