Skip to contentSkip to conversation

mtd: spinand: winbond: add support for W25N04LV

PATCH In review Huasin Liao 3 participants 4 messages Aug 16 – Aug 25

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

PATCH 1/1 mtd: spinand: winbond: add support for W25N04LV

Add support for the Winbond W25N04LV. Tested on an Airoha AN7581-based board with the on-board W25N04LV, verified erase/read/write.

---
 drivers/mtd/nand/spi/winbond.c | 38 ++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
drivers/mtd/nand/spi/winbond.c +38 -0
index 9b78c1e6cbc9..892220a12b22 100644
@@ -345,6 +345,35 @@ static const struct mtd_ooblayout_ops w25n02kv_ooblayout = {
 	.free = w25n02kv_ooblayout_free,
 };
 
+static int w25n04lv_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 w25n04lv_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 w25n04lv_ooblayout = {
+	.ecc = w25n04lv_ooblayout_ecc,
+	.free = w25n04lv_ooblayout_free,
+};
+
 static int w25n01jw_ooblayout_ecc(struct mtd_info *mtd, int section,
 				  struct mtd_oob_region *region)
 {
@@ -759,6 +788,15 @@ static const struct spinand_info winbond_spinand_table[] = {
 					      &update_cache_variants),
 		     0,
 		     SPINAND_ECCINFO(&w25n02kv_ooblayout, w25n02kv_ecc_get_status)),
+	SPINAND_INFO("W25N04LV", /* 3.3V */
+		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x8b, 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(&w25n04lv_ooblayout, w25n02kv_ecc_get_status)),
 	SPINAND_INFO("W25N04KW", /* 1.8V */
 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xba, 0x23),
 		     NAND_MEMORG(1, 2048, 128, 64, 4096, 40, 1, 1, 1),
Signature · 1 line
2.39.3 (Apple Git-146)
#1 lore raw

Huasin Liao wrote on Sun, Aug 16, 2026 at 05:31:24PM +0800:

Quoted 25 lines
drivers/mtd/nand/spi/winbond.c +17 -0
index 9b78c1e6cbc9..892220a12b22 100644
@@ -345,6 +345,35 @@ static const struct mtd_ooblayout_ops w25n02kv_ooblayout = {
 	.free = w25n02kv_ooblayout_free,
 };
 
+static int w25n04lv_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 w25n04lv_ooblayout_free(struct mtd_info *mtd, int section,
+				   struct mtd_oob_region *region)
+{
+	if (section > 7)
+		return -ERANGE;

drivers/mtd/nand/spi/winbond.c static const struct mtd_ooblayout_ops w25n02kv_ooblayout = { · line 374

Quoted 10 lines
drivers/mtd/nand/spi/winbond.c +10 -0
+
+	region->offset = (16 * section) + 2;
+	region->length = 14;
+
+	return 0;
+}
+
+static const struct mtd_ooblayout_ops w25n04lv_ooblayout = {
+	.ecc = w25n04lv_ooblayout_ecc,
+	.free = w25n04lv_ooblayout_free,

FWIW, these two are the same as what I consolidated in
https://lore.kernel.org/r/[email protected]
using oobsize, so we probably want to reuse that here too

(Should I split the patch?)

Signature · 1 line
Dominique Martinet | Asmadeus
#2 lore raw

Dominique Martinet wrote on Sun, Aug 16, 2026 at 20:19:02 +0900:

Quoted 32 lines

Huasin Liao wrote on Sun, Aug 16, 2026 at 05:31:24PM +0800:

Quoted 31 lines
drivers/mtd/nand/spi/winbond.c +23 -0
index 9b78c1e6cbc9..892220a12b22 100644
@@ -345,6 +345,35 @@ static const struct mtd_ooblayout_ops w25n02kv_ooblayout = {
 	.free = w25n02kv_ooblayout_free,
 };
 
+static int w25n04lv_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 w25n04lv_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;
+}
Quoted 8 lines

drivers/mtd/nand/spi/winbond.c static const struct mtd_ooblayout_ops w25n02kv_ooblayout = { · line 374

Quoted 4 lines
drivers/mtd/nand/spi/winbond.c +4 -0
+
+static const struct mtd_ooblayout_ops w25n04lv_ooblayout = {
+	.ecc = w25n04lv_ooblayout_ecc,
+	.free = w25n04lv_ooblayout_free,

FWIW, these two are the same as what I consolidated in
https://lore.kernel.org/r/[email protected]
using oobsize, so we probably want to reuse that here too

Thanks for the pointer, and good to see Miquel is fine with reusing w25n02kv_ooblayout. Once your patch lands, I'll rebase on top of it and switch from w25n04lv_ooblayout to w25n02kv_ooblayout — is that in line with what you'd expect?

Huasin Liao

maintainer
#3 lore raw
Quoted 9 lines
Quoted 8 lines

drivers/mtd/nand/spi/winbond.c static const struct mtd_ooblayout_ops w25n02kv_ooblayout = { · line 374

Quoted 4 lines
drivers/mtd/nand/spi/winbond.c +3 -0
+static const struct mtd_ooblayout_ops w25n04lv_ooblayout = {
+	.ecc = w25n04lv_ooblayout_ecc,
+	.free = w25n04lv_ooblayout_free,

FWIW, these two are the same as what I consolidated in
https://lore.kernel.org/r/[email protected]
using oobsize, so we probably want to reuse that here too

Quoted 4 lines

Thanks for the pointer, and good to see Miquel is fine with reusing w25n02kv_ooblayout. Once your patch lands, I'll rebase on top of it and switch from w25n04lv_ooblayout to w25n02kv_ooblayout — is that in line with what you'd expect?

I guess so, thanks!

Miquèl