From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.97 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796151916; b=RqDQjT6MD5YKCe4rgK0XK0g8SpR8JnsCvoZpJ2Y4JNB0px0XRiZ/xUfC8lssa7iJPHFF hZjaNgC4p93wiObNwtPx6QUDsslzvwiqHHlxm70T2EqROfuTO/ay39/HbXfXC/U+K4Pp+ hFjEXHZmoJmYDKcE4/UIGnv5LpV45iJthLvFhigvzYLXby+nRgNlx424VACrhKzw9jJh9 /c+1eNscIH8GNDHjEnuhtvaZXEAM/sJQEyz3NjNoUuLpmGH2Xf95xJlUH66ImIAUFeJz4 NgBEPLIoCKwB+u2z8PmpWCYYjDcS01xE+ZtwWnc4igEFhICB4WUWKtCPMUX46IdqQAg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796151916; h=DMARC-Filter:Received:X-Google-DKIM-Signature:X-Forwarded-Encrypted: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:X-Relaying-Domain: X-CFilter-Loop:Received:DKIM-Signature:X-Forwarded-Encrypted: X-Received:X-Received:Received:From:To:Cc:Subject:Date:Message-Id: X-Mailer:MIME-Version:Content-Transfer-Encoding: X-DetectorID-Processed; bh=sj+F8wSBsQp6ZRn46eGfzM1A9YRGUwX3GnRpjlgrIk0=; b=s2ODD156osH/gvQwnbF5G11IP8J+24Gri4PWK3tFVBBKksFWxdBS46sC3C7hsKvpl9Ki WeoHYZiSAhJAHkWqPenMyb2XBDjuWTTAx3XtPvsn96bIP1TrW6vbmVMHFOANdzGvQWtmp teJeCJPFh1B/Y04UtUn0Ws1nJ5u9chzSJ5/FcnptUrALPVVLDmtkD5r1Ys89hEJSQAFPL S24qQYQrSppgn3vmr6CdsmYQOQaGY2v/sLt1ifWODZOBI6/7pM4ogjqkuhtgzwoXPWsYc UrE5pmDZv26ExuYO2P7op4nFXP8GY5PeZApO3srZuhpTc7ia58jasEKpnuz6VwmdGWg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=broadcom.com; spf=fail smtp.mailfrom=broadcom.com; dkim=pass header.d=broadcom.com header.i=@broadcom.com header.a=rsa-sha256 header.s=google header.b=iFXbJQkA; arc=none smtp.remote-ip=209.85.216.97 Received: from mail-pj1-f97.google.com (mail-pj1-f97.google.com [209.85.216.97]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E8D46606A320 for ; Tue, 1 Dec 2026 19:05:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E8D46606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=broadcom.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=broadcom.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=broadcom.com header.i=@broadcom.com header.a=rsa-sha256 header.s=google header.b=iFXbJQkA Received: by mail-pj1-f97.google.com with SMTP id 98e67ed59e1d1-3b413d04c93so6869702a91.1 for ; Tue, 01 Dec 2026 11:05:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796151915; x=1796756715; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dkim-signature:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=sj+F8wSBsQp6ZRn46eGfzM1A9YRGUwX3GnRpjlgrIk0=; b=pT68BfpI1/2xXlNRDJhfntOXbn3pe8sULHKE4b5s1//AoJu7EtB81U//y0CGo/lQjU rmze/7wjILXV0occcPypPVY5rTiTshbnc4o9fXDykR2ikovPXBl2MxQDO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JcIHwuWhUuqQ+fSQKk+DAgshN7miHiO6i7JLbgmHu +7Uhk+0SqJRIuhEvid4uUGqluPfWfvrXPyjFLkwIcd X-Received: by 2002:a17:90b:3d90:b0:3ab:b39f:41b9 with SMTP id 98e67ed59e1d1-3b41cb42c13mr33761816a91.61.1796151914855; Tue, 01 Dec 2026 11:05:14 -0800 (PST) Received: from smtp-us-east1-p01-i01-si01.dlp.protect.broadcom.com (address-144-49-247-28.dlp.protect.broadcom.com. [144.49.247.28]) by smtp-relay.gmail.com with ESMTPS id 98e67ed59e1d1-3b4d00c6137sm16143619a91.5.2026.12.01.11.05.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Dec 2026 11:05:14 -0800 (PST) X-Relaying-Domain: broadcom.com X-CFilter-Loop: Reflected Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-93f32050e72so2632959885a.1 for ; Tue, 01 Dec 2026 11:05:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1796151913; x=1796756713; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=sj+F8wSBsQp6ZRn46eGfzM1A9YRGUwX3GnRpjlgrIk0=; b=iFXbJQkAZDikvqi5w5SCbIvfvUWUUWjO1f2HIVlefsVyiHrs80RQtPlEGXmQIYZZlO BkmM3Dt7Nyt6k9TKt0kNOHFuDMDpM+Jbgnn11tGgmDvDW7BYE7ZgU8dFmtS2sinTuLPO QIDS0AejWGJwMFFPEsI5hNQnA+YEYMo8mZdbg= X-Forwarded-Encrypted: i=1; AL+hErGWBkTUw5X3BR+RJsFzN5WB7K5i9wbLA3F1MNLr5XTDSgqTlIijiqLq6W7NFKsgA3Ytdmj4Bdad4hySCCk=@vger.kernel.org X-Received: by 2002:a05:620a:462a:b0:949:7472:b845 with SMTP id af79cd13be357-949bab0dc11mr6702275285a.55.1796151913050; Tue, 01 Dec 2026 11:05:13 -0800 (PST) X-Received: by 2002:a05:620a:462a:b0:949:7472:b845 with SMTP id af79cd13be357-949bab0dc11mr6702269685a.55.1796151912440; Tue, 01 Dec 2026 11:05:12 -0800 (PST) Received: from stbirv-lnx-1.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id af79cd13be357-949bb34ac11sm2900724385a.14.2026.12.01.11.05.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 11:05:11 -0800 (PST) From: Florian Fainelli To: linux-mtd@lists.infradead.org Cc: bcm-kernel-feedback-list@broadcom.com, David Regan , Florian Fainelli , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Sasha Levin , Mikhail Kshevetskiy , Frieder Schrempf , =?UTF-8?q?Nuno=20S=C3=A1?= , Han Xu , David LaPorte , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2] mtd: nand: spi: add Etron EM73C044VCF support Date: Tue, 1 Dec 2026 11:05:02 -0800 Message-Id: <20261201190503.4023210-1-florian.fainelli@broadcom.com> X-Mailer: git-send-email 2.34.1 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-DetectorID-Processed: b00c1d49-9d2e-4205-b15f-d015386d3d5e From: David Regan 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 [florian: forward porting, commit message] Signed-off-by: Florian Fainelli --- 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 + */ + +#include +#include +#include + +#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