* [PATCH] mtd: nand: spi: add Etron EM73C044VCF support
@ 2026-11-30 22:53 Florian Fainelli
2026-11-30 23:03 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Florian Fainelli @ 2026-11-30 22:53 UTC (permalink / raw)
To: linux-mtd
Cc: bcm-kernel-feedback-list, David Regan, Florian Fainelli,
Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
Ahmed Naseef, Aleksei Sviridkin, Jeff Kim, Han Xu, Bill Lee,
Tudor Ambarus, Gabor Juhos, Nuno Sá, Kees Cook,
Frieder Schrempf, open list
From: David Regan <david.regan@broadcom.com>
Add support for the Etron EM73C044VCF SPI-NAND chip (manufacturer ID
0xD5, 1Gb/3.3V, 4-bit ECC). The device only reports four ECC status
states on read, so the exact number of corrected bitflips is not known
for the "some bitflips corrected" state and the maximum for that state
(3) is reported. The "correction limit reached" state reports 4.
Signed-off-by: David Regan <david.regan@broadcom.com>
[florian: forward porting, commit message]
Signed-off-by: Florian Fainelli <florian.fainelli@broadcom.com>
---
drivers/mtd/nand/spi/Makefile | 2 +-
drivers/mtd/nand/spi/core.c | 1 +
drivers/mtd/nand/spi/etron.c | 116 ++++++++++++++++++++++++++++++++++
include/linux/mtd/spinand.h | 1 +
4 files changed, 119 insertions(+), 1 deletion(-)
create mode 100644 drivers/mtd/nand/spi/etron.c
diff --git a/drivers/mtd/nand/spi/Makefile b/drivers/mtd/nand/spi/Makefile
index f6b2a094fafc..02c27ec2ea67 100644
--- a/drivers/mtd/nand/spi/Makefile
+++ b/drivers/mtd/nand/spi/Makefile
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: GPL-2.0
spinand-objs := core.o otp.o
-spinand-objs += alliancememory.o ato.o dosilicon.o esmt.o fmsh.o foresee.o gigadevice.o heyangtek.o
+spinand-objs += alliancememory.o ato.o dosilicon.o esmt.o etron.o fmsh.o foresee.o gigadevice.o heyangtek.o
spinand-objs += issi.o macronix.o micron.o paragon.o skyhigh.o toshiba.o winbond.o xtx.o
obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index 0fd5ce99b23b..5fdceae0fc2e 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -1381,6 +1381,7 @@ static const struct spinand_manufacturer *spinand_manufacturers[] = {
&dosilicon_spinand_manufacturer,
&esmt_8c_spinand_manufacturer,
&esmt_c8_spinand_manufacturer,
+ &etron_spinand_manufacturer,
&fmsh_spinand_manufacturer,
&foresee_spinand_manufacturer,
&gigadevice_spinand_manufacturer,
diff --git a/drivers/mtd/nand/spi/etron.c b/drivers/mtd/nand/spi/etron.c
new file mode 100644
index 000000000000..7f75f8968fad
--- /dev/null
+++ b/drivers/mtd/nand/spi/etron.c
@@ -0,0 +1,116 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022 Broadcom
+ *
+ * Author: David Regan <david.regan@broadcom.com>
+ */
+
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/mtd/spinand.h>
+
+#define SPINAND_MFR_ETRON 0xD5
+
+#define ETRON_STATUS_ECC_LIMIT_BITFLIPS (3 << 4)
+
+static SPINAND_OP_VARIANTS(read_cache_variants,
+ SPINAND_PAGE_READ_FROM_CACHE_1S_4S_4S_OP(0, 2, NULL, 0, 0),
+ SPINAND_PAGE_READ_FROM_CACHE_1S_1S_4S_OP(0, 1, NULL, 0, 0),
+ SPINAND_PAGE_READ_FROM_CACHE_1S_2S_2S_OP(0, 1, NULL, 0, 0),
+ SPINAND_PAGE_READ_FROM_CACHE_1S_1S_2S_OP(0, 1, NULL, 0, 0),
+ SPINAND_PAGE_READ_FROM_CACHE_FAST_1S_1S_1S_OP(0, 1, NULL, 0, 0),
+ SPINAND_PAGE_READ_FROM_CACHE_1S_1S_1S_OP(0, 1, NULL, 0, 0));
+
+static SPINAND_OP_VARIANTS(write_cache_variants,
+ SPINAND_PROG_LOAD_1S_1S_4S_OP(true, 0, NULL, 0),
+ SPINAND_PROG_LOAD_1S_1S_1S_OP(true, 0, NULL, 0));
+
+static SPINAND_OP_VARIANTS(update_cache_variants,
+ SPINAND_PROG_LOAD_1S_1S_4S_OP(false, 0, NULL, 0),
+ SPINAND_PROG_LOAD_1S_1S_1S_OP(false, 0, NULL, 0));
+
+static int etron_ooblayout_ecc(struct mtd_info *mtd, int section,
+ struct mtd_oob_region *region)
+{
+ if (section)
+ return -ERANGE;
+
+ region->offset = mtd->oobsize / 2;
+ region->length = mtd->oobsize / 2;
+
+ return 0;
+}
+
+static int etron_ooblayout_free(struct mtd_info *mtd, int section,
+ struct mtd_oob_region *region)
+{
+ if (section)
+ return -ERANGE;
+
+ /* Reserve 1 byte for the BBM. */
+ region->offset = 1;
+ region->length = (mtd->oobsize / 2) - 1;
+
+ return 0;
+}
+
+static const struct mtd_ooblayout_ops etron_ooblayout = {
+ .ecc = etron_ooblayout_ecc,
+ .free = etron_ooblayout_free,
+};
+
+/*
+ * The EM73C044VCF only reports four ECC status states when reading a page:
+ * no bitflips, some bitflips corrected, correction limit reached, and
+ * uncorrectable. The exact bitflip count is not available for the "some
+ * bitflips corrected" state, so the maximum for that state (3) is reported.
+ * The "limit reached" state reports the full ECC strength (4), which is
+ * what makes the MTD core return -EUCLEAN and ask for the data to be
+ * scrubbed.
+ */
+static int etron_ecc_get_status(struct spinand_device *spinand,
+ u8 status)
+{
+ switch (status & STATUS_ECC_MASK) {
+ case STATUS_ECC_NO_BITFLIPS:
+ return 0;
+
+ case STATUS_ECC_UNCOR_ERROR:
+ return -EBADMSG;
+
+ case STATUS_ECC_HAS_BITFLIPS:
+ return 3;
+
+ case ETRON_STATUS_ECC_LIMIT_BITFLIPS:
+ return 4;
+
+ default:
+ break;
+ }
+
+ return -EINVAL;
+}
+
+static const struct spinand_info etron_spinand_table[] = {
+ /* EM73C 1Gb 3.3V */
+ SPINAND_INFO("EM73C044VCF",
+ SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x25),
+ NAND_MEMORG(1, 2048, 64, 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(&etron_ooblayout, etron_ecc_get_status)),
+};
+
+static const struct spinand_manufacturer_ops etron_spinand_manuf_ops = {
+};
+
+const struct spinand_manufacturer etron_spinand_manufacturer = {
+ .id = SPINAND_MFR_ETRON,
+ .name = "Etron",
+ .chips = etron_spinand_table,
+ .nchips = ARRAY_SIZE(etron_spinand_table),
+ .ops = &etron_spinand_manuf_ops,
+};
diff --git a/include/linux/mtd/spinand.h b/include/linux/mtd/spinand.h
index a51829a8cdea..e9eea7060390 100644
--- a/include/linux/mtd/spinand.h
+++ b/include/linux/mtd/spinand.h
@@ -434,6 +434,7 @@ extern const struct spinand_manufacturer ato_spinand_manufacturer;
extern const struct spinand_manufacturer dosilicon_spinand_manufacturer;
extern const struct spinand_manufacturer esmt_8c_spinand_manufacturer;
extern const struct spinand_manufacturer esmt_c8_spinand_manufacturer;
+extern const struct spinand_manufacturer etron_spinand_manufacturer;
extern const struct spinand_manufacturer fmsh_spinand_manufacturer;
extern const struct spinand_manufacturer foresee_spinand_manufacturer;
extern const struct spinand_manufacturer gigadevice_spinand_manufacturer;
--
2.34.1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] mtd: nand: spi: add Etron EM73C044VCF support
2026-11-30 22:53 [PATCH] mtd: nand: spi: add Etron EM73C044VCF support Florian Fainelli
@ 2026-11-30 23:03 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-30 23:03 UTC (permalink / raw)
To: Florian Fainelli, linux-mtd
Cc: bcm-kernel-feedback-list, David Regan, Miquel Raynal,
Richard Weinberger, Vignesh Raghavendra, Ahmed Naseef,
Aleksei Sviridkin, Jeff Kim, Han Xu, Bill Lee, Tudor Ambarus,
Gabor Juhos, Nuno Sá, Kees Cook, Frieder Schrempf
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [High] mtd: spinand: etron: etron_ooblayout_free() overlaps 2-byte bad
block marker
- [Medium] mtd: spinand: etron: etron_ecc_get_status() triggers
premature -EUCLEAN
- [Medium] mtd: spinand: etron: missing SPINAND_HAS_QE_BIT flag for
EM73C044VCF quad ops
--
commit ca2416b337259cb1a2d85354a17e3134dc74ab5d
Author: David Regan <david.regan@broadcom.com>
mtd: nand: spi: add Etron EM73C044VCF support
This commit adds SPI-NAND support for the Etron EM73C044VCF 1Gb 3.3V flash
chip with 4-bit on-die ECC.
> diff --git a/drivers/mtd/nand/spi/etron.c b/drivers/mtd/nand/spi/etron.c
> new file mode 100644
> index 0000000000000..7f75f8968fad0
> --- /dev/null
> +++ b/drivers/mtd/nand/spi/etron.c
> @@ -0,0 +1,116 @@
[ ... ]
> +static SPINAND_OP_VARIANTS(read_cache_variants,
> + SPINAND_PAGE_READ_FROM_CACHE_1S_4S_4S_OP(0, 2, NULL, 0, 0),
> + SPINAND_PAGE_READ_FROM_CACHE_1S_1S_4S_OP(0, 1, NULL, 0, 0),
> + SPINAND_PAGE_READ_FROM_CACHE_1S_2S_2S_OP(0, 1, NULL, 0, 0),
> + SPINAND_PAGE_READ_FROM_CACHE_1S_1S_2S_OP(0, 1, NULL, 0, 0),
> + SPINAND_PAGE_READ_FROM_CACHE_FAST_1S_1S_1S_OP(0, 1, NULL, 0, 0),
> + SPINAND_PAGE_READ_FROM_CACHE_1S_1S_1S_OP(0, 1, NULL, 0, 0));
> +
> +static SPINAND_OP_VARIANTS(write_cache_variants,
> + SPINAND_PROG_LOAD_1S_1S_4S_OP(true, 0, NULL, 0),
> + SPINAND_PROG_LOAD_1S_1S_1S_OP(true, 0, NULL, 0));
> +
> +static SPINAND_OP_VARIANTS(update_cache_variants,
> + SPINAND_PROG_LOAD_1S_1S_4S_OP(false, 0, NULL, 0),
> + SPINAND_PROG_LOAD_1S_1S_1S_OP(false, 0, NULL, 0));
[ ... ]
> +static int etron_ooblayout_free(struct mtd_info *mtd, int section,
> + struct mtd_oob_region *region)
> +{
> + if (section)
> + return -ERANGE;
> +
> + /* Reserve 1 byte for the BBM. */
> + region->offset = 1;
> + region->length = (mtd->oobsize / 2) - 1;
> +
> + return 0;
> +}
[Severity: High]
Does reserving only 1 byte for the bad block marker cause
etron_ooblayout_free() to overlap the 2-byte marker used by the SPI-NAND
core?
spinand_isbad() and spinand_markbad() read and write a 2-byte marker at
OOB offsets 0 and 1, and spinand_isbad() treats a block as bad if either
marker[0] != 0xff or marker[1] != 0xff. Exposing OOB offset 1 as the
first free OOB byte means any MTD_OPS_AUTO_OOB write (such as JFFS2
cleanmarkers) that stores a non-0xff byte at free OOB offset 0 on the
first page of an eraseblock will cause subsequent bad-block scans to
classify good eraseblocks as bad.
Should region->offset be 2 and region->length be (mtd->oobsize / 2) - 2?
> +
> +static const struct mtd_ooblayout_ops etron_ooblayout = {
> + .ecc = etron_ooblayout_ecc,
> + .free = etron_ooblayout_free,
> +};
> +
> +/*
> + * The EM73C044VCF only reports four ECC status states when reading a page:
> + * no bitflips, some bitflips corrected, correction limit reached, and
> + * uncorrectable. The exact bitflip count is not available for the "some
> + * bitflips corrected" state, so the maximum for that state (3) is reported.
> + * The "limit reached" state reports the full ECC strength (4), which is
> + * what makes the MTD core return -EUCLEAN and ask for the data to be
> + * scrubbed.
> + */
> +static int etron_ecc_get_status(struct spinand_device *spinand,
> + u8 status)
> +{
> + switch (status & STATUS_ECC_MASK) {
> + case STATUS_ECC_NO_BITFLIPS:
> + return 0;
> +
> + case STATUS_ECC_UNCOR_ERROR:
> + return -EBADMSG;
> +
> + case STATUS_ECC_HAS_BITFLIPS:
> + return 3;
> +
> + case ETRON_STATUS_ECC_LIMIT_BITFLIPS:
> + return 4;
[Severity: Medium]
Does returning 3 for STATUS_ECC_HAS_BITFLIPS cause mtd_read_oob() to
return -EUCLEAN even when only a single bitflip was corrected?
For NAND_ECCREQ(4, 512), spinand_init() sets mtd->bitflip_threshold to
DIV_ROUND_UP(mtd->ecc_strength * 3, 4), which is 3. Because
mtd_read_oob() returns -EUCLEAN whenever ret_code >=
mtd->bitflip_threshold, returning 3 for STATUS_ECC_HAS_BITFLIPS triggers
-EUCLEAN and eraseblock scrubbing before ETRON_STATUS_ECC_LIMIT_BITFLIPS
is reached.
[ ... ]
> +static const struct spinand_info etron_spinand_table[] = {
> + /* EM73C 1Gb 3.3V */
> + SPINAND_INFO("EM73C044VCF",
> + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x25),
> + NAND_MEMORG(1, 2048, 64, 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(&etron_ooblayout, etron_ecc_get_status)),
> +};
[Severity: Medium]
Should the flags argument here include SPINAND_HAS_QE_BIT?
read_cache_variants, write_cache_variants and update_cache_variants
include 4-bit Quad SPI operations, but spinand_configure_chip() only calls
spinand_init_quad_enable() to set CFG_QUAD_ENABLE in feature register 0xB0
when SPINAND_HAS_QE_BIT is set. Without it, Quad SPI transfers will fail
on quad-capable controllers unless the bootloader already enabled the QE
bit.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261130225341.1989256-1-florian.fainelli@broadcom.com?part=1
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 23:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 22:53 [PATCH] mtd: nand: spi: add Etron EM73C044VCF support Florian Fainelli
2026-11-30 23:03 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox