[PATCH v2] mtd: nand: spi: add Etron EM73C044VCF support
From: Florian Fainelli
Date: Tue Dec 01 2026 - 14:05:20 EST
From: David Regan <david.regan@xxxxxxxxxxxx>
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. With
a 4-bit ECC strength the MTD bitflip threshold is 3, so any corrected
bitflip is reported to upper layers as -EUCLEAN.
The ECC-free OOB region starts at offset 2, past the 2 byte bad block
marker the SPI-NAND core reads and writes.
Per the datasheet the device needs the QE bit (B0[0]) set to use Quad
SPI, is identified with Read ID followed by an address byte, and uses a
single dummy byte (2 clock cycles) for Read from Cache Quad IO (EBH).
Signed-off-by: David Regan <david.regan@xxxxxxxxxxxx>
[florian: forward porting, commit message]
Signed-off-by: Florian Fainelli <florian.fainelli@xxxxxxxxxxxx>
---
Changes in v2:
- Reserve 2 bytes for the BBM in etron_ooblayout_free() (offset 2, length
oobsize/2 - 2) so the free OOB region no longer overlaps the 2 byte bad block
marker used by the SPI-NAND core.
- Set SPINAND_HAS_QE_BIT: the datasheet requires B0[0] (QE) to be set for Quad
SPI and it defaults to 0.
- Use 1 dummy byte instead of 2 for Read from Cache Quad IO (EBH), matching the
datasheet timing diagram (2 dummy clocks at x4).
- Use SPINAND_READID_METHOD_OPCODE_ADDR, as the datasheet defines Read ID as
9Fh followed by an address byte.
- Rewrite the ECC status comment and move it above etron_ecc_get_status(). The
v1 comment described an 8-bit device and did not match the code. It now
explains that both reported values (3 and 4) reach the MTD bitflip threshold of
3 and so return -EUCLEAN.
- Prefix the ECC limit macro with ETRON_ and rename the manufacturer ops to
etron_spinand_manuf_ops, as in the other SPI-NAND drivers.
- Fix the commit message (4-bit ECC, not 8-bit) and document the BBM, QE, dummy
byte and Read ID points.
drivers/mtd/nand/spi/Makefile | 2 +-
drivers/mtd/nand/spi/core.c | 1 +
drivers/mtd/nand/spi/etron.c | 119 ++++++++++++++++++++++++++++++++++
include/linux/mtd/spinand.h | 1 +
4 files changed, 122 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..66f3af1cfb57
--- /dev/null
+++ b/drivers/mtd/nand/spi/etron.c
@@ -0,0 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022 Broadcom
+ *
+ * Author: David Regan <david.regan@xxxxxxxxxxxx>
+ */
+
+#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, 1, 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 2 bytes for the BBM. */
+ region->offset = 2;
+ region->length = (mtd->oobsize / 2) - 2;
+
+ 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).
+ *
+ * The MTD bitflip threshold for a 4-bit ECC strength is 3, so both states
+ * make the MTD core return -EUCLEAN. Any corrected bitflip is therefore
+ * reported for scrubbing, which may cause more block relocations than
+ * strictly needed.
+ */
+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_ADDR, 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),
+ SPINAND_HAS_QE_BIT,
+ 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