From nobody Fri Dec 19 10:36:47 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29D0C264A92 for ; Fri, 10 Oct 2025 08:41:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085694; cv=none; b=BUnkCpqbkYjBg2ryDW4laF9rCfc8LKzvElDxM/OqsIxk7FhSv4Z6pxZJVhTnt504/usviNtN31cKM4n5fn0YCjlESGjD9VhaiT/a9+Qo0zXdVl9wXf0j1ef4/kvc6po6kjfM2bxmTg7h99TC1Ay1VNS0XhCd/BKmbJTeGYU15ik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085694; c=relaxed/simple; bh=bQmXdISAbQ46rKv2iVyeALnxGy/0LVQ6ve958EU5XJI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c9vKbkOvwe24JH+Wg66AWZTzfp2nNyfck6gCEBdD9svQsijAhvf/F/KYepXUEPnZTnHSa2c/a5k/2QvMfp42r095euYxkibhJ22JXY/SVCg490/1Vp+kR3Htg7XPfxdTp5lpdLM1gdQw4zyY31yjCkH/sEEB9w9TxPNI/Lunl2U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=dA7qSXPr; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="dA7qSXPr" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 79FD41A127B; Fri, 10 Oct 2025 08:41:30 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 4F4FB60667; Fri, 10 Oct 2025 08:41:30 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 755F7102F2209; Fri, 10 Oct 2025 10:41:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760085689; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=Tz6sO687jYJvFjSGzi40jW5mXg89go39qIQP/ZY/9eU=; b=dA7qSXPr3VO1LBX9C4BFa+KRCB0w28b3tqz76DVgpL4xMVKUsiUcNDf/zvSCnw+FL3jZB4 pJSx6IqqOv/kQ2FeVbTwxZalDWG1tX5gjTC2+XeoDmTMkFTgb4q1RgpVdcIZWAKXh3dPD/ Sz6QsvviyN2nglOQiAmih0EDLg+oQd7xke0187o7QuU3RBYqpfCF9zaP552Xk0oZWdO1DF eK10tV1NqVeAPD3cXz7wr/xanU5WelK5m1GiWHCIYeecCvhLCkXitomLDWJ2nUjycaIKd5 LKF4KbV+biW8BWgfHVCTRcQ8Tmwtip/G5NI47+9nZxpqTRFpSa6LaIdBzO9H5g== From: Richard Genoud To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Wentao Liang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Thomas Petazzoni , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 01/15] mtd: rawnand: sunxi: Remove superfluous register readings Date: Fri, 10 Oct 2025 10:40:28 +0200 Message-ID: <20251010084042.341224-2-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251010084042.341224-1-richard.genoud@bootlin.com> References: <20251010084042.341224-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The register NFC_REG_ECC_CTL was read twice and the result was not used, then a third time with a mask applied. Removing those calls didn't change the behavior. Tested on H616 SoC, scrambling enabled. Signed-off-by: Richard Genoud Reviewed-by: Jernej Skrabec --- drivers/mtd/nand/raw/sunxi_nand.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 162cd5f4f234..10a48e0d361f 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -623,13 +623,12 @@ static void sunxi_nfc_randomizer_config(struct nand_c= hip *nand, int page, bool ecc) { struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); - u32 ecc_ctl =3D readl(nfc->regs + NFC_REG_ECC_CTL); + u32 ecc_ctl; u16 state; =20 if (!(nand->options & NAND_NEED_SCRAMBLING)) return; =20 - ecc_ctl =3D readl(nfc->regs + NFC_REG_ECC_CTL); state =3D sunxi_nfc_randomizer_state(nand, page, ecc); ecc_ctl =3D readl(nfc->regs + NFC_REG_ECC_CTL) & ~NFC_RANDOM_SEED_MSK; writel(ecc_ctl | NFC_RANDOM_SEED(state), nfc->regs + NFC_REG_ECC_CTL); --=20 2.47.3 From nobody Fri Dec 19 10:36:47 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AD3526AA88 for ; Fri, 10 Oct 2025 08:41:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085697; cv=none; b=be/gTJzHZioTSoaNDHyR2jby1MeHaDDuXmwmp6t32xTVdwaGXo7Qa05f6jbEaIky7kyJwpVNdjp5+oTIsWdHwB6l9DPNpZ60s+Kv+YZ1LEzRn8gRHWaymkzM5jN7rJm88kp5R0I+e28Wi48T7IcDTJj5hLIzLTCvulDgzbyrn3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085697; c=relaxed/simple; bh=4NHGTpUp810CJ5GplH14M01b1T9+wUKoWQ61R7UooCQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nhfwwCCaN9BxfhKdXUUgRXFxahPMETLkYUMez8BCrilUh47V8RdSVGsT8YMldA3Eia0g23RTFhM4G01Gsng5Zqmer8sGm18fYJjJ5p+GDJqzMY7Il7jZ7I5EkTsX1oRFMsoSV0LrbBGM/A4cVPJrUwIqNEhm4P7zjU7mUQ8Lgqg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Eu+WCS4l; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Eu+WCS4l" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id F26301A127C; Fri, 10 Oct 2025 08:41:33 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id C75BF60667; Fri, 10 Oct 2025 08:41:33 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 9A0E1102F21F6; Fri, 10 Oct 2025 10:41:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760085692; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=SMfQgmaA+NDyDK7Ueg4chV0xd3SWz/9HItTT1xnJps0=; b=Eu+WCS4l5FJHzORvSabLRwRjqt5rE+kCTzrjWvEoazmBb6vd0C+muL/EvqJHX07680Mhiw YBT6JH0YZUN/K+/uW4jtWdDu/Q3t3AJQlnX1MmKWH86xYLL2zSBEGL6EWaK5Hp7QVTpZxA E/HY8ljBCG4YQn3oxdeR+OfH51zM0Ucgc2Ha3pgVeJdL32+d9pQqYjdSEmDu9yg/PWlpOB H9jTgX4q+NKq+/JWXKDgNYYuLUTyNhJSBeLnahyskGbsU1GsP+3ErGnVgLDA7QDOCGOjKz 9Yns8KZFkbH1NkU74YPbPHiLU+Qf9id8zFMD8BIlpV7F6JLDxl3S1G4PA/IeKA== From: Richard Genoud To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Wentao Liang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Thomas Petazzoni , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 02/15] dt-bindings: mtd: sunxi: Add new compatible Date: Fri, 10 Oct 2025 10:40:29 +0200 Message-ID: <20251010084042.341224-3-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251010084042.341224-1-richard.genoud@bootlin.com> References: <20251010084042.341224-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The H616 NAND controller is quite different from the A10 and A23 ones, some registers offset changed, and some new one are introduced. Also, the DMA handling is different (it uses chained descriptors) So, introduce a new compatible to represent this version of the IP. Signed-off-by: Richard Genoud --- .../mtd/allwinner,sun4i-a10-nand.yaml | 56 ++++++++++++++----- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand= .yaml b/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml index 054b6b8bf9b9..cc63091fe936 100644 --- a/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml +++ b/Documentation/devicetree/bindings/mtd/allwinner,sun4i-a10-nand.yaml @@ -6,34 +6,64 @@ $schema: http://devicetree.org/meta-schemas/core.yaml# =20 title: Allwinner A10 NAND Controller =20 -allOf: - - $ref: nand-controller.yaml - maintainers: - Chen-Yu Tsai - Maxime Ripard =20 +allOf: + - $ref: nand-controller.yaml + + - if: + properties: + compatible: + contains: + enum: + - allwinner,sun4i-a10-nand + - allwinner,sun8i-a23-nand-controller + then: + properties: + clocks: + items: + - description: Bus Clock + - description: Module Clock + clock-names: + items: + - const: ahb + - const: mod + + - if: + properties: + compatible: + contains: + enum: + - allwinner,sun50i-h616-nand-controller + then: + properties: + clocks: + items: + - description: Bus Clock + - description: Module Clock + - description: ECC Clock + - description: MBus Clock + clock-names: + items: + - const: ahb + - const: mod + - const: ecc + - const: mbus + properties: compatible: enum: - allwinner,sun4i-a10-nand - allwinner,sun8i-a23-nand-controller + - allwinner,sun50i-h616-nand-controller reg: maxItems: 1 =20 interrupts: maxItems: 1 =20 - clocks: - items: - - description: Bus Clock - - description: Module Clock - - clock-names: - items: - - const: ahb - - const: mod - resets: maxItems: 1 =20 --=20 2.47.3 From nobody Fri Dec 19 10:36:47 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 192252652A6 for ; Fri, 10 Oct 2025 08:41:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085700; cv=none; b=SgtSCK8Lm1yWj46FUvsI9qKxenV2FYiYIVxyGkUVU1mb1T1DsOwEsiuzc++WQ8c2x9qCUZdM5pQCxT/FnCJtawI+wjU3JxnwnoBD+OH0vDLmLmAJdGCOcRh63EFJBvjJKWX5rJnC2CKFKThcFlvvpomnZSZzRqIl+hhTrDKYbUw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085700; c=relaxed/simple; bh=22swiJ90UQtWYmeqL+UpJi6ywc207cbqVKAmiXiqLpU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b9YueERF6vs5QLq2NXSLwrlxbnTj/45uu/epdlf8u1GYTazfvvJw/EXdALSM8/Ha/E1gqIdsUcI2rMoCLJ1DD7f+155pO044oRHW2YMdtbVQzz+lP7UGDj66RTWJTXT7VvLPxBNK5OYeBbKFVIi9yenTdKywhurGZ9ZLA9Bvy1Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=y8phVoq8; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="y8phVoq8" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 96B621A127D; Fri, 10 Oct 2025 08:41:37 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 6BAFB60667; Fri, 10 Oct 2025 08:41:37 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 63206102F2204; Fri, 10 Oct 2025 10:41:33 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760085696; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=QLUI3DAeOf8Gf/4795RSqwfpn1jrg6BWZGq810jHUE4=; b=y8phVoq8g2wcSrJsqn8y2JdqJUR8dFEW9/j4t3nDpBDLbY5CvPoiRl9A7HYeMR2wPcv1zn ibcYf67gZJs5b8/51Mk0vtTcg4ueao9J1qgGBTN+ZKTycbF4nnisRmVZki3vdgtyQhUw1v uT613Xta3u40dAgd+sOgVMF/305o227he+bWqA9EU6Sn14sy2PXkWqhp6OPvcSvdAmGYuN OT5zDHb93cFUxVkLC0zLof/koSW6ujqGy1LBiy9wZ1NpANCLzt/ODzCpnzIuRdBLFbpmDS nCGwsAUxWBzajNNXlJ4J21hYkp7MQFFRbVnKoO21aLKeQHODOThkXM1UhBRRxw== From: Richard Genoud To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Wentao Liang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Thomas Petazzoni , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 03/15] arm64: dts: allwinner: h616: add NAND controller Date: Fri, 10 Oct 2025 10:40:30 +0200 Message-ID: <20251010084042.341224-4-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251010084042.341224-1-richard.genoud@bootlin.com> References: <20251010084042.341224-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The H616 has a NAND controller quite similar to the A10/A23 ones, but with some register differences, more clocks (for ECC and MBUS), more ECC strengths, so this requires a new compatible string. This patch adds the NAND controller node and pins in the device tree. Signed-off-by: Richard Genoud --- .../arm64/boot/dts/allwinner/sun50i-h616.dtsi | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/arch/arm64/boot/dts/allwinner/sun50i-h616.dtsi b/arch/arm64/bo= ot/dts/allwinner/sun50i-h616.dtsi index ceedae9e399b..60626eba7f7c 100644 --- a/arch/arm64/boot/dts/allwinner/sun50i-h616.dtsi +++ b/arch/arm64/boot/dts/allwinner/sun50i-h616.dtsi @@ -278,6 +278,37 @@ ir_rx_pin: ir-rx-pin { function =3D "ir_rx"; }; =20 + nand_pins: nand-pins { + pins =3D "PC0", "PC1", "PC2", "PC5", "PC8", "PC9", + "PC10", "PC11", "PC12", "PC13", "PC14", + "PC15", "PC16"; + function =3D "nand0"; + }; + + nand_cs0_pin: nand-cs0-pin { + pins =3D "PC4"; + function =3D "nand0"; + bias-pull-up; + }; + + nand_cs1_pin: nand-cs1-pin { + pins =3D "PC3"; + function =3D "nand0"; + bias-pull-up; + }; + + nand_rb0_pin: nand-rb0-pin { + pins =3D "PC6"; + function =3D "nand0"; + bias-pull-up; + }; + + nand_rb1_pin: nand-rb1-pin { + pins =3D "PC7"; + function =3D "nand0"; + bias-pull-up; + }; + mmc0_pins: mmc0-pins { pins =3D "PF0", "PF1", "PF2", "PF3", "PF4", "PF5"; @@ -440,6 +471,25 @@ mmc2: mmc@4022000 { #size-cells =3D <0>; }; =20 + nfc: nand-controller@4011000 { + compatible =3D "allwinner,sun50i-h616-nand-controller"; + reg =3D <0x04011000 0x1000>; + interrupts =3D ; + clocks =3D <&ccu CLK_BUS_NAND>, <&ccu CLK_NAND0>, + <&ccu CLK_NAND1>, <&ccu CLK_MBUS_NAND>; + clock-names =3D "ahb", "mod", "ecc", "mbus"; + resets =3D <&ccu RST_BUS_NAND>; + reset-names =3D "ahb"; + dmas =3D <&dma 10>; + dma-names =3D "rxtx"; + pinctrl-names =3D "default"; + pinctrl-0 =3D <&nand_pins>, <&nand_cs0_pin>, + <&nand_cs1_pin>, <&nand_rb0_pin>, + <&nand_rb1_pin>; + #address-cells =3D <1>; + #size-cells =3D <0>; + }; + uart0: serial@5000000 { compatible =3D "snps,dw-apb-uart"; reg =3D <0x05000000 0x400>; --=20 2.47.3 From nobody Fri Dec 19 10:36:47 2025 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7FE622701C3 for ; Fri, 10 Oct 2025 08:41:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085703; cv=none; b=pY5sPD5RgHsf3Ufy2af7ljxmq4qC1qSZK5Fy1vfQy+6jbn9nhqpettF7K6q3oeJhZDgnq4xZch7vUhrjhFmPWABAoq3AWjwfRDFh+zfztNGWA5NTnsIyXCxq/pGoHClT3LkVTlGpDXOAvUF6vvNGmCCKx9IpnUl4wdrSOy95hcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085703; c=relaxed/simple; bh=+7V21fBKZ9/1ScwLG5W7UyIa+lYLz9cIdKSghh1Pr8s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FvlP6jX4o0FDINYU0INFOg31lkee59pNvoi9KlWXuWiOM7Lt6ksFMnsfIZuQnd7WuCvgD6O3i2g3Ez8s55XtB2CNpeBLQAOx/YXB7fWQQFqkyCzvosxJcGTQRUHLP6FGaExSi3d9c86EIFH4I75fj7buH6/PiRZleVbhecR8oJw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=G1sVoDR7; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="G1sVoDR7" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id AA9CDC08CC6; Fri, 10 Oct 2025 08:41:21 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 5410E60667; Fri, 10 Oct 2025 08:41:40 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id D5C4D102F2206; Fri, 10 Oct 2025 10:41:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760085699; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=hVZorgzw7GlkbAdhTKmVPXOZ3kOeGcl6Fd44HKki10Y=; b=G1sVoDR7mhyS/3l1/qp5qMx0gdaSfLz5nK74NQEqMU8O721Wx10zNs8xOReVRkIDWQrkuH 1YUVf5DFMkYPUIsBi36RBOJDS/qyi9OA/A5V84UmSkaGmXb4JAGIuOFYj4F8Qvry2NClc/ ayRjDsNNoVmYXZFzHo4n/xk2WYNTUnwN6NtE1KYpRTyJH17mRdWajoP6Nj+O8AeFZlV6FG 8RpPQped2jZFfI8SnyGq38Y3KspzWOb3XZMtLwip5wpel2Zj69zZW6TKof0yraQuP+SF1N JxMOsL70q7r916vYuo82Q+HhIF/duRkazFHhZ6xeomTh6t7YqNr6dsugl6NiTA== From: Richard Genoud To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Wentao Liang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Thomas Petazzoni , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 04/15] mtd: nand: sunxi: move ecc strenghts in sunxi_nfc_caps Date: Fri, 10 Oct 2025 10:40:31 +0200 Message-ID: <20251010084042.341224-5-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251010084042.341224-1-richard.genoud@bootlin.com> References: <20251010084042.341224-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" H6/H616 has more ecc strenghts. This commit prepares the change. No functional change. Signed-off-by: Richard Genoud --- drivers/mtd/nand/raw/sunxi_nand.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 10a48e0d361f..198dd40f9220 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -213,11 +213,15 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(s= truct nand_chip *nand) * through MBUS on A23/A33 needs extra configuration. * @reg_io_data: I/O data register * @dma_maxburst: DMA maxburst + * @ecc_strengths: Available ECC strengths array + * @nstrengths: Size of @ecc_strengths */ struct sunxi_nfc_caps { bool has_mdma; unsigned int reg_io_data; unsigned int dma_maxburst; + const u8 *ecc_strengths; + unsigned int nstrengths; }; =20 /** @@ -1619,9 +1623,9 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_ch= ip *nand, struct nand_ecc_ctrl *ecc, struct device_node *np) { - static const u8 strengths[] =3D { 16, 24, 28, 32, 40, 48, 56, 60, 64 }; struct sunxi_nand_chip *sunxi_nand =3D to_sunxi_nand(nand); struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); + const u8 *strengths =3D nfc->caps->ecc_strengths; struct mtd_info *mtd =3D nand_to_mtd(nand); struct nand_device *nanddev =3D mtd_to_nanddev(mtd); int nsectors; @@ -1645,7 +1649,7 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_ch= ip *nand, =20 ecc->strength =3D bytes * 8 / fls(8 * ecc->size); =20 - for (i =3D 0; i < ARRAY_SIZE(strengths); i++) { + for (i =3D 0; i < nfc->caps->nstrengths; i++) { if (strengths[i] > ecc->strength) break; } @@ -1666,7 +1670,7 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_ch= ip *nand, } =20 /* Add ECC info retrieval from DT */ - for (i =3D 0; i < ARRAY_SIZE(strengths); i++) { + for (i =3D 0; i < nfc->caps->nstrengths; i++) { if (ecc->strength <=3D strengths[i]) { /* * Update ecc->strength value with the actual strength @@ -1677,7 +1681,7 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_ch= ip *nand, } } =20 - if (i >=3D ARRAY_SIZE(strengths)) { + if (i >=3D nfc->caps->nstrengths) { dev_err(nfc->dev, "unsupported strength\n"); return -ENOTSUPP; } @@ -2167,15 +2171,23 @@ static void sunxi_nfc_remove(struct platform_device= *pdev) dma_release_channel(nfc->dmac); } =20 +static const u8 sunxi_ecc_strengths_a10[] =3D { + 16, 24, 28, 32, 40, 48, 56, 60, 64 +}; + static const struct sunxi_nfc_caps sunxi_nfc_a10_caps =3D { .reg_io_data =3D NFC_REG_A10_IO_DATA, .dma_maxburst =3D 4, + .ecc_strengths =3D sunxi_ecc_strengths_a10, + .nstrengths =3D ARRAY_SIZE(sunxi_ecc_strengths_a10), }; =20 static const struct sunxi_nfc_caps sunxi_nfc_a23_caps =3D { .has_mdma =3D true, .reg_io_data =3D NFC_REG_A23_IO_DATA, .dma_maxburst =3D 8, + .ecc_strengths =3D sunxi_ecc_strengths_a10, + .nstrengths =3D ARRAY_SIZE(sunxi_ecc_strengths_a10), }; =20 static const struct of_device_id sunxi_nfc_ids[] =3D { --=20 2.47.3 From nobody Fri Dec 19 10:36:47 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31CB727A906 for ; Fri, 10 Oct 2025 08:41:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085705; cv=none; b=RXVh3ikKrVeaeH8BeZD1HqoD9zKgyK1z5jYxkE5osARXOKYHB9WWFvhVM+RbtdY7k7mpmIUkoItQEOYfXIbH47GAOKRfp7nciWOHyuewq7KhGZy/x+XR+EAVx5jZJhcty2ZOg/tAtj/WJIJ7YeIKykFrOxEnbCXApA2c9/j+ZnA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085705; c=relaxed/simple; bh=B3vnE1vUkgPsYrYz9u4srFxYa53prKjoUq0qcehEkYM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TwSuAxyT04Fv3NwEY6uiE0CKzNuDTzyul7pjJtORhmepoHGK/4+8hKkC5uQ9Ny7SGdSZK/GAPXrBCdvUpRXMB22ldMF/kd2+/yQGNmBLAsuT/A5om7vnainPiVrhbg8DgIZKdYrOi+O/3keqvM05uxaHGR+y6voVQwHjupoGddg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=z3vbzYLO; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="z3vbzYLO" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id D64AA4E40FCC; Fri, 10 Oct 2025 08:41:42 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id A64FA60667; Fri, 10 Oct 2025 08:41:42 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id C15FB102F2207; Fri, 10 Oct 2025 10:41:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760085701; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=2eUtrmX2lFzBvooPhUwMtsD8tqiYbm1tikMSLEiK8r8=; b=z3vbzYLONLB4KTu0hnSElYAUxNvst69vE32Y1upv81SmM0jez+8uZgE+RXd5+YawIZX+Vl sRjRpK4bZlNZqkSdaPV3BfmMcIsmzTJTPoZV/yli/Oddhe7ExIAtYQaZstH9VUQz9DP7Cd 5HPvoOrXjuUD/BB0XGSXOQ1aSb4B3AkDsmy7z+Ckif7K/G9s555x7vdhTdb1Ty1/tpg6GU khq4AcHRstyN6FeSBXazAVj+hxWkCRQd3nMoxEKYZbDHU64pOAkn/y/6yf1uMWDEyC17A7 J+LEhXbDX3WZotr5alpAWu8cOjC/xOWP6oIOUDFllMyuUo2eGymUWwVHAoHQiQ== From: Richard Genoud To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Wentao Liang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Thomas Petazzoni , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 05/15] mtd: nand: sunxi: introduce reg_ecc_err_cnt in sunxi_nfc_caps Date: Fri, 10 Oct 2025 10:40:32 +0200 Message-ID: <20251010084042.341224-6-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251010084042.341224-1-richard.genoud@bootlin.com> References: <20251010084042.341224-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The H6/H616 ECC_ERR_CNT register is not at the same offset as the A10/A23 one, so move its offset into sunxi_nfc_caps No functional change. Signed-off-by: Richard Genoud --- drivers/mtd/nand/raw/sunxi_nand.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 198dd40f9220..faaac71e7be3 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -46,7 +46,8 @@ #define NFC_REG_ECC_CTL 0x0034 #define NFC_REG_ECC_ST 0x0038 #define NFC_REG_DEBUG 0x003C -#define NFC_REG_ECC_ERR_CNT(x) ((0x0040 + (x)) & ~0x3) +#define NFC_REG_A10_ECC_ERR_CNT 0x0040 +#define NFC_REG_ECC_ERR_CNT(nfc, x) ((nfc->caps->reg_ecc_err_cnt + (x)) & = ~0x3) #define NFC_REG_USER_DATA(x) (0x0050 + ((x) * 4)) #define NFC_REG_SPARE_AREA 0x00A0 #define NFC_REG_PAT_ID 0x00A4 @@ -212,6 +213,7 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(str= uct nand_chip *nand) * @has_mdma: Use mbus dma mode, otherwise general dma * through MBUS on A23/A33 needs extra configuration. * @reg_io_data: I/O data register + * @reg_ecc_err_cnt: ECC error counter register * @dma_maxburst: DMA maxburst * @ecc_strengths: Available ECC strengths array * @nstrengths: Size of @ecc_strengths @@ -219,6 +221,7 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(str= uct nand_chip *nand) struct sunxi_nfc_caps { bool has_mdma; unsigned int reg_io_data; + unsigned int reg_ecc_err_cnt; unsigned int dma_maxburst; const u8 *ecc_strengths; unsigned int nstrengths; @@ -790,7 +793,7 @@ static int sunxi_nfc_hw_ecc_correct(struct nand_chip *n= and, u8 *data, u8 *oob, return 0; } =20 - tmp =3D readl(nfc->regs + NFC_REG_ECC_ERR_CNT(step)); + tmp =3D readl(nfc->regs + NFC_REG_ECC_ERR_CNT(nfc, step)); =20 return NFC_ECC_ERR_CNT(step, tmp); } @@ -2177,6 +2180,7 @@ static const u8 sunxi_ecc_strengths_a10[] =3D { =20 static const struct sunxi_nfc_caps sunxi_nfc_a10_caps =3D { .reg_io_data =3D NFC_REG_A10_IO_DATA, + .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, .dma_maxburst =3D 4, .ecc_strengths =3D sunxi_ecc_strengths_a10, .nstrengths =3D ARRAY_SIZE(sunxi_ecc_strengths_a10), @@ -2185,6 +2189,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a10_caps= =3D { static const struct sunxi_nfc_caps sunxi_nfc_a23_caps =3D { .has_mdma =3D true, .reg_io_data =3D NFC_REG_A23_IO_DATA, + .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, .dma_maxburst =3D 8, .ecc_strengths =3D sunxi_ecc_strengths_a10, .nstrengths =3D ARRAY_SIZE(sunxi_ecc_strengths_a10), --=20 2.47.3 From nobody Fri Dec 19 10:36:47 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B851A27BF89 for ; Fri, 10 Oct 2025 08:41:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085710; cv=none; b=Yqhxs3TiFUnahXugDdAwHn4WWOn3f2SgoX3T6+TAsix5iuRRB1bzvBP+snOqL/Voqv938ZQU5pO+7kPBrNMX6xk/Ty1yn/iqSXYPbt3lYQVoikwp3vyqACVLC9kPyj/s8p32Ng1GO/v89OPKlqrjPwOiMOo4xjfVJibk9lm8ddc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085710; c=relaxed/simple; bh=f1fjm6RU57+kLetvSv8gY+IOYw/ReAHy/ATibqXmLUE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qG3JDb/C3ZpKj681Ke9Wi7LksCa6fz8LQ2JNPBbtHG7dRgtKg4ia2TmR8EMkk4w5rDLdfEN6bw+DwtEmGB6b/LEfiv8QmKqaSeuGnpS9ZggxxVJSAgi+MsBuR5LNdapw0oTWHsi5mxgvyn6f63EZDQvlLebXWyHqcPAuVnovJ8A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=LpU9p1ff; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="LpU9p1ff" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 4E0F04E40FCD; Fri, 10 Oct 2025 08:41:45 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 2464160667; Fri, 10 Oct 2025 08:41:45 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 01C7B102F2208; Fri, 10 Oct 2025 10:41:41 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760085703; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=lW1eckNNd4gUWt6X3y+zdKi8wIuDsKB6Px2Lg2bPV3A=; b=LpU9p1ffpGEUeYTIuGZkdQj3DKkIaaHGucVWXc3d0Gi4Ns0Km0feYRSJTofCozJeQozaj2 Be1IYEumru8wNU5eYF7dsZi207ezDL5VO6BWQ1zNXF35AoJX3Rm4o7VCGdA0Go7kqhZxJt V7hUrMTU/+Z2AeVWc0Ts1U3mw5mqG8vtCe6HvtwjCAjPN+Uhcb66TuI5kh71Zp+Xng1Uwy EijpeIo6uHMjV9TU3MxU2nATzwJDh4LRy5nULNT/xCLKXLZDIHbUFysBWAKVuZuwWm9JWv sXnW6Nco7YQ3BZJwa5DMnkAn0h+NY7CyFdivdpq+an/pLkuxJ9M19Ii3RJmkhg== From: Richard Genoud To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Wentao Liang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Thomas Petazzoni , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 06/15] mtd: nand: sunxi: introduce reg_user_data in sunxi_nfc_caps Date: Fri, 10 Oct 2025 10:40:33 +0200 Message-ID: <20251010084042.341224-7-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251010084042.341224-1-richard.genoud@bootlin.com> References: <20251010084042.341224-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The H6/H616 USER_DATA register is not at the same offset as the A10/A23 one, so move its offset into sunxi_nfc_caps No functional change. Signed-off-by: Richard Genoud --- drivers/mtd/nand/raw/sunxi_nand.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index faaac71e7be3..6c78370a6095 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -48,7 +48,8 @@ #define NFC_REG_DEBUG 0x003C #define NFC_REG_A10_ECC_ERR_CNT 0x0040 #define NFC_REG_ECC_ERR_CNT(nfc, x) ((nfc->caps->reg_ecc_err_cnt + (x)) & = ~0x3) -#define NFC_REG_USER_DATA(x) (0x0050 + ((x) * 4)) +#define NFC_REG_A10_USER_DATA 0x0050 +#define NFC_REG_USER_DATA(nfc, x) (nfc->caps->reg_user_data + ((x) * 4)) #define NFC_REG_SPARE_AREA 0x00A0 #define NFC_REG_PAT_ID 0x00A4 #define NFC_REG_MDMA_ADDR 0x00C0 @@ -214,6 +215,7 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(str= uct nand_chip *nand) * through MBUS on A23/A33 needs extra configuration. * @reg_io_data: I/O data register * @reg_ecc_err_cnt: ECC error counter register + * @reg_user_data: User data register * @dma_maxburst: DMA maxburst * @ecc_strengths: Available ECC strengths array * @nstrengths: Size of @ecc_strengths @@ -222,6 +224,7 @@ struct sunxi_nfc_caps { bool has_mdma; unsigned int reg_io_data; unsigned int reg_ecc_err_cnt; + unsigned int reg_user_data; unsigned int dma_maxburst; const u8 *ecc_strengths; unsigned int nstrengths; @@ -723,8 +726,8 @@ static void sunxi_nfc_hw_ecc_get_prot_oob_bytes(struct = nand_chip *nand, u8 *oob, { struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); =20 - sunxi_nfc_user_data_to_buf(readl(nfc->regs + NFC_REG_USER_DATA(step)), - oob); + sunxi_nfc_user_data_to_buf(readl(nfc->regs + + NFC_REG_USER_DATA(nfc, step)), oob); =20 /* De-randomize the Bad Block Marker. */ if (bbm && (nand->options & NAND_NEED_SCRAMBLING)) @@ -746,7 +749,7 @@ static void sunxi_nfc_hw_ecc_set_prot_oob_bytes(struct = nand_chip *nand, } =20 writel(sunxi_nfc_buf_to_user_data(oob), - nfc->regs + NFC_REG_USER_DATA(step)); + nfc->regs + NFC_REG_USER_DATA(nfc, step)); } =20 static void sunxi_nfc_hw_ecc_update_stats(struct nand_chip *nand, @@ -2181,6 +2184,7 @@ static const u8 sunxi_ecc_strengths_a10[] =3D { static const struct sunxi_nfc_caps sunxi_nfc_a10_caps =3D { .reg_io_data =3D NFC_REG_A10_IO_DATA, .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, + .reg_user_data =3D NFC_REG_A10_USER_DATA, .dma_maxburst =3D 4, .ecc_strengths =3D sunxi_ecc_strengths_a10, .nstrengths =3D ARRAY_SIZE(sunxi_ecc_strengths_a10), @@ -2190,6 +2194,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a23_caps= =3D { .has_mdma =3D true, .reg_io_data =3D NFC_REG_A23_IO_DATA, .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, + .reg_user_data =3D NFC_REG_A10_USER_DATA, .dma_maxburst =3D 8, .ecc_strengths =3D sunxi_ecc_strengths_a10, .nstrengths =3D ARRAY_SIZE(sunxi_ecc_strengths_a10), --=20 2.47.3 From nobody Fri Dec 19 10:36:47 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEB7827C854 for ; Fri, 10 Oct 2025 08:41:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085710; cv=none; b=ZXwV5ps4l7zL1//hJ0yml9tdePjHZYWLbO8lcWXmmrnxTF5unIXIHgzcYROqk3D0+jabP3tPPFiJZMC+Nk4+S8qGX/zs6cYj9NPztRBZL4kurTK4ucUw6iRuK2tuNH+4ipPFpd2hrJye6kDEAsXpEGTDqTE09NRFykR0KYRe7yE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085710; c=relaxed/simple; bh=xY10IaFW5wWlJu9ipMbJl6rBWhdmo2ezcMMl8KHJOjY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EmljVFLuBIujnX6utHqeSaE+yikHcRgDKLeGlnSaK11T0KlAIGcpcR66RxRPs7+MWzcs73cxvcdbnpHzySs9EWberRgGjFznWUMpOl98uoJkoih/EN99UYSFwmMSjOco3eMp9Rd5boTH2t3GzVc2ShdjJJFFcF0be2RvOiBcb6E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=aJmBKMEx; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="aJmBKMEx" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 423FA1A127C; Fri, 10 Oct 2025 08:41:47 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 1986F60667; Fri, 10 Oct 2025 08:41:47 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 49547102F220A; Fri, 10 Oct 2025 10:41:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760085706; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=nsm0jkpZq7oor+4Zs4Zh7Ccpu02kkLyILA1Ksn0/JSQ=; b=aJmBKMExRjWX9Zcru1X4GKU7Bv6EojWcypnflNV+u2InhDIGSJRLg28FyHDrnNFnd7alrK BsEgrqCh6NUODHQRMcQJHagUlW5L4n+sI2UF4zRp7AC2sr/mkjtogf1la1ZDyavBeJpt+3 5wuLcbfoQwcmaeHkN4XZuRYA1LKyd7GUQZMkDeIH7KZ71vOeAjig/KKxQ/0oySb/oV7sUQ +WfKOx7NSHUw18mBVN2nq4zvtgb5uwh+cQRP/c3z3DqHfzTAOGpEhxTM0ZAjz4G+K2y4b3 1Xfc3aY7kmjcC1GA2pXqCqmPwa121DmerKwzCqULWgBdpEgTBrn4iLJUxl0g6w== From: Richard Genoud To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Wentao Liang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Thomas Petazzoni , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 07/15] mtd: nand: sunxi: rework pattern found registers Date: Fri, 10 Oct 2025 10:40:34 +0200 Message-ID: <20251010084042.341224-8-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251010084042.341224-1-richard.genoud@bootlin.com> References: <20251010084042.341224-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" On H6/H616, the register ECC_PAT_FOUND is at its own address, and not part of ECC status register. So, we introduce the pattern found register offset in sunxi_nfc_caps, along with its mask. Also, introduce a non compile-time field_get() because FIELD_GET() and u32_get_bits() don't work with non compile-time constant. https://lore.kernel.org/lkml/cover.1739540679.git.geert+renesas@glider.be/ No functional change. Signed-off-by: Richard Genoud --- drivers/mtd/nand/raw/sunxi_nand.c | 36 ++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 6c78370a6095..8c0430fbbb38 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -29,6 +29,9 @@ #include #include =20 +/* non compile-time field get */ +#define field_get(_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) + #define NFC_REG_CTL 0x0000 #define NFC_REG_ST 0x0004 #define NFC_REG_INT 0x0008 @@ -150,7 +153,13 @@ /* define bit use in NFC_ECC_ST */ #define NFC_ECC_ERR(x) BIT(x) #define NFC_ECC_ERR_MSK GENMASK(15, 0) -#define NFC_ECC_PAT_FOUND(x) BIT(x + 16) + +/* + * define bit use in NFC_REG_PAT_FOUND + * For A10/A23, NFC_REG_PAT_FOUND =3D=3D NFC_ECC_ST register + */ +#define NFC_ECC_PAT_FOUND_MSK(nfc) (nfc->caps->pat_found_mask) + #define NFC_ECC_ERR_CNT(b, x) (((x) >> (((b) % 4) * 8)) & 0xff) =20 #define NFC_DEFAULT_TIMEOUT_MS 1000 @@ -216,6 +225,8 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(str= uct nand_chip *nand) * @reg_io_data: I/O data register * @reg_ecc_err_cnt: ECC error counter register * @reg_user_data: User data register + * @reg_pat_found: Data Pattern Status Register + * @pat_found_mask: ECC_PAT_FOUND mask in NFC_REG_PAT_FOUND register * @dma_maxburst: DMA maxburst * @ecc_strengths: Available ECC strengths array * @nstrengths: Size of @ecc_strengths @@ -225,6 +236,8 @@ struct sunxi_nfc_caps { unsigned int reg_io_data; unsigned int reg_ecc_err_cnt; unsigned int reg_user_data; + unsigned int reg_pat_found; + unsigned int pat_found_mask; unsigned int dma_maxburst; const u8 *ecc_strengths; unsigned int nstrengths; @@ -766,7 +779,8 @@ static void sunxi_nfc_hw_ecc_update_stats(struct nand_c= hip *nand, } =20 static int sunxi_nfc_hw_ecc_correct(struct nand_chip *nand, u8 *data, u8 *= oob, - int step, u32 status, bool *erased) + int step, u32 status, u32 pattern_found, + bool *erased) { struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); struct nand_ecc_ctrl *ecc =3D &nand->ecc; @@ -777,7 +791,7 @@ static int sunxi_nfc_hw_ecc_correct(struct nand_chip *n= and, u8 *data, u8 *oob, if (status & NFC_ECC_ERR(step)) return -EBADMSG; =20 - if (status & NFC_ECC_PAT_FOUND(step)) { + if (pattern_found & BIT(step)) { u8 pattern; =20 if (unlikely(!(readl(nfc->regs + NFC_REG_PAT_ID) & 0x1))) { @@ -811,6 +825,7 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct nand_chip= *nand, struct sunxi_nfc *nfc =3D to_sunxi_nfc(nand->controller); struct nand_ecc_ctrl *ecc =3D &nand->ecc; int raw_mode =3D 0; + u32 pattern_found; bool erased; int ret; =20 @@ -838,8 +853,12 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct nand_chi= p *nand, =20 *cur_off =3D oob_off + ecc->bytes + 4; =20 + pattern_found =3D readl(nfc->regs + nfc->caps->reg_pat_found); + pattern_found =3D field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern_found); + ret =3D sunxi_nfc_hw_ecc_correct(nand, data, oob_required ? oob : NULL, 0, readl(nfc->regs + NFC_REG_ECC_ST), + pattern_found, &erased); if (erased) return 1; @@ -920,7 +939,7 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand= _chip *nand, uint8_t *buf unsigned int max_bitflips =3D 0; int ret, i, raw_mode =3D 0; struct scatterlist sg; - u32 status, wait; + u32 status, pattern_found, wait; =20 ret =3D sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) @@ -961,6 +980,8 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand= _chip *nand, uint8_t *buf return ret; =20 status =3D readl(nfc->regs + NFC_REG_ECC_ST); + pattern_found =3D readl(nfc->regs + nfc->caps->reg_pat_found); + pattern_found =3D field_get(NFC_ECC_PAT_FOUND_MSK(nfc), pattern_found); =20 for (i =3D 0; i < nchunks; i++) { int data_off =3D i * ecc->size; @@ -971,7 +992,8 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand= _chip *nand, uint8_t *buf =20 ret =3D sunxi_nfc_hw_ecc_correct(nand, randomized ? data : NULL, oob_required ? oob : NULL, - i, status, &erased); + i, status, pattern_found, + &erased); =20 /* ECC errors are handled in the second loop. */ if (ret < 0) @@ -2185,6 +2207,8 @@ static const struct sunxi_nfc_caps sunxi_nfc_a10_caps= =3D { .reg_io_data =3D NFC_REG_A10_IO_DATA, .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, .reg_user_data =3D NFC_REG_A10_USER_DATA, + .reg_pat_found =3D NFC_REG_ECC_ST, + .pat_found_mask =3D GENMASK(31, 16), .dma_maxburst =3D 4, .ecc_strengths =3D sunxi_ecc_strengths_a10, .nstrengths =3D ARRAY_SIZE(sunxi_ecc_strengths_a10), @@ -2195,6 +2219,8 @@ static const struct sunxi_nfc_caps sunxi_nfc_a23_caps= =3D { .reg_io_data =3D NFC_REG_A23_IO_DATA, .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, .reg_user_data =3D NFC_REG_A10_USER_DATA, + .reg_pat_found =3D NFC_REG_ECC_ST, + .pat_found_mask =3D GENMASK(31, 16), .dma_maxburst =3D 8, .ecc_strengths =3D sunxi_ecc_strengths_a10, .nstrengths =3D ARRAY_SIZE(sunxi_ecc_strengths_a10), --=20 2.47.3 From nobody Fri Dec 19 10:36:47 2025 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2161B27F4C7 for ; Fri, 10 Oct 2025 08:41:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085712; cv=none; b=jg917gASBLXBxm8ocMUnPHJonQWJF1s/MFrpdFsUqMeL9+47o4ujhMAHs42zJe+Vqa5L99daeEhnowvmYaWyrMZ5lfHOIEXJ+xRWsOYTaXV803Zk2y/BMkBet0t3rTGLVKeYBBbNwimGTWU7bDGWZS1h5zLpJGW1+qGNS2Nh4iA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085712; c=relaxed/simple; bh=0AbNnOo4M+NHEvhdStfE8vWrf7XpyOL/iMHm//HtuD0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XENkK80CBMJgkMWw+uXiYh/g0VV6g9af9etlusTX9yjq5f+PO/rx6OhAtOllQY2idY79Q6XuGDLhoC17Sw4QWtlyxbtLGBIIW9LAqG+pQWxEjHLDfb7rpkxJB6Lupq2a4FGGtxeo3HQzx3GSTfWe4glPH5wXswlj9MUrpXywap0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=1QLjYHaX; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="1QLjYHaX" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id 26729C08CCA; Fri, 10 Oct 2025 08:41:31 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id C296560667; Fri, 10 Oct 2025 08:41:49 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 8957E102F21F6; Fri, 10 Oct 2025 10:41:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760085708; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=9zF3woeq5c0FzokyfhWbeyMnFFFrF+2MtT34xOty4uM=; b=1QLjYHaXbTQMeAJ1TjLK/9J6y3RtJkoTC0AvdN9nDL/1XlhwY0y/ocj5V7aFCDhtGr2Lxc ihHImlbT5bhZ0PrDbTg0LLBQF2t1ggtcd9gruEvVIi1Ry7JxfXKKRuqd+4WuORXSs0mCWp pG8vKQ9rhY01wmF1wkXMGm9nUP7tmZugdAtSzqUS0mczuiLBZTIK1hnaT4HFbpkE4ppbph XscHovJnMDuw8kdlgICl6U4loGqwr4y8d9iedLyXdg0av5aEiLlbKydVhqGlTwqti0yi3m 82i1GRRO2Eu9ukWfQS7OevbXBGRJ7T7INBitGWyC8TDHQRPDcdW7du/AXCv78w== From: Richard Genoud To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Wentao Liang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Thomas Petazzoni , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 08/15] mtd: nand: sunxi: add has_ecc_block_512 capability Date: Fri, 10 Oct 2025 10:40:35 +0200 Message-ID: <20251010084042.341224-9-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251010084042.341224-1-richard.genoud@bootlin.com> References: <20251010084042.341224-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The H6/H616 controller can't handle 512 bytes ecc block size. Let it be a capability. No functional change. Signed-off-by: Richard Genoud --- drivers/mtd/nand/raw/sunxi_nand.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 8c0430fbbb38..672e934444ca 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -222,6 +222,7 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(str= uct nand_chip *nand) * * @has_mdma: Use mbus dma mode, otherwise general dma * through MBUS on A23/A33 needs extra configuration. + * @has_ecc_block_512: If the ECC can handle 512B or only 1024B chuncks * @reg_io_data: I/O data register * @reg_ecc_err_cnt: ECC error counter register * @reg_user_data: User data register @@ -233,6 +234,7 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(str= uct nand_chip *nand) */ struct sunxi_nfc_caps { bool has_mdma; + bool has_ecc_block_512; unsigned int reg_io_data; unsigned int reg_ecc_err_cnt; unsigned int reg_user_data; @@ -1748,8 +1750,14 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_c= hip *nand, sunxi_nand->ecc.ecc_ctl =3D NFC_ECC_MODE(i) | NFC_ECC_EXCEPTION | NFC_ECC_PIPELINE | NFC_ECC_EN; =20 - if (ecc->size =3D=3D 512) - sunxi_nand->ecc.ecc_ctl |=3D NFC_ECC_BLOCK_512; + if (ecc->size =3D=3D 512) { + if (nfc->caps->has_ecc_block_512) { + sunxi_nand->ecc.ecc_ctl |=3D NFC_ECC_BLOCK_512; + } else { + dev_err(nfc->dev, "512B ECC block not supported\n"); + return -EOPNOTSUPP; + } + } =20 return 0; } @@ -2204,6 +2212,7 @@ static const u8 sunxi_ecc_strengths_a10[] =3D { }; =20 static const struct sunxi_nfc_caps sunxi_nfc_a10_caps =3D { + .has_ecc_block_512 =3D true, .reg_io_data =3D NFC_REG_A10_IO_DATA, .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, .reg_user_data =3D NFC_REG_A10_USER_DATA, @@ -2216,6 +2225,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a10_caps= =3D { =20 static const struct sunxi_nfc_caps sunxi_nfc_a23_caps =3D { .has_mdma =3D true, + .has_ecc_block_512 =3D true, .reg_io_data =3D NFC_REG_A23_IO_DATA, .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, .reg_user_data =3D NFC_REG_A10_USER_DATA, --=20 2.47.3 From nobody Fri Dec 19 10:36:47 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C13F8262FC7; Fri, 10 Oct 2025 08:41:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085715; cv=none; b=jfieXp+O5G8FdKkacQOZGonDoGxKeUn2Dlse1tDnn54/zTsxe+j3ARb47wwj/2GQW6lrH38MQyVxgKYTglKSjHSrC/uU6Iuyu9ovMS8LInQwKItnjVgwr5tw8WMkfiSdPE13iDCexrybIz4nSFbPIm7Wx1FOLYnvbvpIu33w6lk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085715; c=relaxed/simple; bh=PAmMLdlHlDf9kXLMlDlAAQe/uJWmeCwtDPMFN4M+z9A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aNiycHkhONOhqdbVfdccyCKZgHCvV6QrNifccPGCxxjh7OIM+jXAT355In7nB3yZefucPAG/1fXeFnfuvxmgydIKLR7SY9uT2gz8CdS6b2TcVppylNAt4bD/1tsDy9jSJeaswFaKO7jpI22fCW3nvZKSeY/gFUk456cpriLRCTw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=pN/JGOoG; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="pN/JGOoG" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id 7C54B1A127C; Fri, 10 Oct 2025 08:41:52 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 5248B60667; Fri, 10 Oct 2025 08:41:52 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 24F7C102F2209; Fri, 10 Oct 2025 10:41:49 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760085711; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=ug8DN5qqvBSPg1if81HDH0CRKRkJC4yZjqyuWWY99Hk=; b=pN/JGOoG8Xj9231BwoYRxSD7dXu6I5hfmzQyNq3309OvCX8kR2uULLJW2YTxv6+WdFoBOw ATpWuwab/y6iBx0/FJYrHpm0JkS8WHLQ34RdrDTFesEr2Z0yarh3Pe//iks5rGNxo26V1U HlNJ4JRkHLPgKlgCRMcbVTxCsZPs9Q6sqE9CCGdOepiE/OcTZB/o6/mL3DY+9dwS3k8viG Oh/JsFTjfJwxD27wmHxbvSCYdy2lHqCBJuMPkTV4zt/zlPW2uw0z5JSjA3UOpvA7xm8LWm TBsrzkIC9QAEN9LpwE4eL3LXY3M/fZWG0ZjFq1i6vNcwoSjYy82DpXBhyjdsxA== From: Richard Genoud To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Wentao Liang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Thomas Petazzoni , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 09/15] mtd: nand: sunxi: introduce ecc_mode_mask in sunxi_nfc_caps Date: Fri, 10 Oct 2025 10:40:36 +0200 Message-ID: <20251010084042.341224-10-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251010084042.341224-1-richard.genoud@bootlin.com> References: <20251010084042.341224-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The H6/H616 ECC_MODE field is not at the same offset, and has not the same size. So move the mask into sunxi_nfc_caps. No functional change. Signed-off-by: Richard Genoud --- drivers/mtd/nand/raw/sunxi_nand.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 672e934444ca..3c21f54e8e3f 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -29,8 +29,9 @@ #include #include =20 -/* non compile-time field get */ +/* non compile-time field get/prep */ #define field_get(_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1)) +#define field_prep(_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask)) =20 #define NFC_REG_CTL 0x0000 #define NFC_REG_ST 0x0004 @@ -145,8 +146,8 @@ #define NFC_ECC_BLOCK_512 BIT(5) #define NFC_RANDOM_EN BIT(9) #define NFC_RANDOM_DIRECTION BIT(10) -#define NFC_ECC_MODE_MSK GENMASK(15, 12) -#define NFC_ECC_MODE(x) ((x) << 12) +#define NFC_ECC_MODE_MSK(nfc) (nfc->caps->ecc_mode_mask) +#define NFC_ECC_MODE(nfc, x) field_prep(NFC_ECC_MODE_MSK(nfc), (x)) #define NFC_RANDOM_SEED_MSK GENMASK(30, 16) #define NFC_RANDOM_SEED(x) ((x) << 16) =20 @@ -227,6 +228,7 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(str= uct nand_chip *nand) * @reg_ecc_err_cnt: ECC error counter register * @reg_user_data: User data register * @reg_pat_found: Data Pattern Status Register + * @ecc_mode_mask: ECC_MODE mask in NFC_ECC_CTL register * @pat_found_mask: ECC_PAT_FOUND mask in NFC_REG_PAT_FOUND register * @dma_maxburst: DMA maxburst * @ecc_strengths: Available ECC strengths array @@ -239,6 +241,7 @@ struct sunxi_nfc_caps { unsigned int reg_ecc_err_cnt; unsigned int reg_user_data; unsigned int reg_pat_found; + unsigned int ecc_mode_mask; unsigned int pat_found_mask; unsigned int dma_maxburst; const u8 *ecc_strengths; @@ -1747,7 +1750,7 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_ch= ip *nand, ecc->read_oob_raw =3D nand_read_oob_std; ecc->write_oob_raw =3D nand_write_oob_std; =20 - sunxi_nand->ecc.ecc_ctl =3D NFC_ECC_MODE(i) | NFC_ECC_EXCEPTION | + sunxi_nand->ecc.ecc_ctl =3D NFC_ECC_MODE(nfc, i) | NFC_ECC_EXCEPTION | NFC_ECC_PIPELINE | NFC_ECC_EN; =20 if (ecc->size =3D=3D 512) { @@ -2217,6 +2220,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a10_caps= =3D { .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, .reg_user_data =3D NFC_REG_A10_USER_DATA, .reg_pat_found =3D NFC_REG_ECC_ST, + .ecc_mode_mask =3D GENMASK(15, 12), .pat_found_mask =3D GENMASK(31, 16), .dma_maxburst =3D 4, .ecc_strengths =3D sunxi_ecc_strengths_a10, @@ -2230,6 +2234,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a23_caps= =3D { .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, .reg_user_data =3D NFC_REG_A10_USER_DATA, .reg_pat_found =3D NFC_REG_ECC_ST, + .ecc_mode_mask =3D GENMASK(15, 12), .pat_found_mask =3D GENMASK(31, 16), .dma_maxburst =3D 8, .ecc_strengths =3D sunxi_ecc_strengths_a10, --=20 2.47.3 From nobody Fri Dec 19 10:36:47 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9AD11260578 for ; Fri, 10 Oct 2025 08:41:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085718; cv=none; b=GqHoo6YF8gO2o2H4L3W6L9zWwvpjW+QNotcaodFVknjYsFUEFANNs5s9EH6YnqNOVQLbGWu6weBgEUtJnIJWqys4IHtqYTX4G/KT1DBeDSh6nV1FHHBQ1P3rGVFy+gfGyjzKlJlRp+KYQcIWlh7lutB/c5Y17mmiVU+vmPqux98= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085718; c=relaxed/simple; bh=p5QkopAZtQP33YSBMYmsYHTXnor3ALffSVv8wffmeXo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YIB2HuiORQREZHU6OGHURquBycUv0X+ppMaHAs0eXM9a6s+Od7HNKD+xvq85qTv54FcRCkBhvjEpo4dPttYJLJdQEMW4Tfom/W4OwXRBlUwwriyaGDtIQkEpRgBrF3EiWZUOmHZAnySffceXn/2CXd8gQiYj6QPEOi221arlHEs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=yGbZAl6h; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="yGbZAl6h" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id F194B1A1281; Fri, 10 Oct 2025 08:41:54 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id C1A3C60667; Fri, 10 Oct 2025 08:41:54 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id B17E4102F2206; Fri, 10 Oct 2025 10:41:51 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760085713; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=0h90jbJtC3ZJW0B/G8iBt4NQc4cwXcvlZB6O9BQam/Q=; b=yGbZAl6h9oArIHNS0WWvQUnLVquve8odbHB69bXkWdK5XdI6H5rfz/p8DDVB5g3SlAuvb3 QkDt9p5i4sqY97TS+rec89beY+wTCM3t5laGq+bTjavT+dNY6BjpOth977zCuDzY/JUYvc xLvgcoUS/vucRwKwBUaLjPr9x0daK55AlODNak43ZATlAwIrK5y+Ex0tPvJvGgbc2kpnqd 1PDLCgxjwmgH/Ddl573oo4sQFsPZB/gZJ33B3EhibqvZg3+jzi4KuEHHGznZT/8AcCdvG9 IuJOOnpZI5bmzz6bgBfzptI+IcJwI/Qn2YskYu+6WWYvvsojtO/dPn3v71xA6A== From: Richard Genoud To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Wentao Liang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Thomas Petazzoni , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 10/15] mtd: nand: sunxi: introduce random en/dir in sunxi_nfc_caps Date: Fri, 10 Oct 2025 10:40:37 +0200 Message-ID: <20251010084042.341224-11-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251010084042.341224-1-richard.genoud@bootlin.com> References: <20251010084042.341224-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The H6/H616 RANDOM EN/DIRECTION masks are different from A10/A23. So move the masks into sunxi_nfc_caps. No functional change. Signed-off-by: Richard Genoud --- drivers/mtd/nand/raw/sunxi_nand.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 3c21f54e8e3f..5161dfff46ed 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -144,8 +144,8 @@ #define NFC_ECC_EXCEPTION BIT(4) #define NFC_ECC_BLOCK_SIZE_MSK BIT(5) #define NFC_ECC_BLOCK_512 BIT(5) -#define NFC_RANDOM_EN BIT(9) -#define NFC_RANDOM_DIRECTION BIT(10) +#define NFC_RANDOM_EN(nfc) (nfc->caps->random_en_mask) +#define NFC_RANDOM_DIRECTION(nfc) (nfc->caps->random_dir_mask) #define NFC_ECC_MODE_MSK(nfc) (nfc->caps->ecc_mode_mask) #define NFC_ECC_MODE(nfc, x) field_prep(NFC_ECC_MODE_MSK(nfc), (x)) #define NFC_RANDOM_SEED_MSK GENMASK(30, 16) @@ -228,6 +228,8 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(str= uct nand_chip *nand) * @reg_ecc_err_cnt: ECC error counter register * @reg_user_data: User data register * @reg_pat_found: Data Pattern Status Register + * @random_en_mask: RANDOM_EN mask in NFC_ECC_CTL register + * @random_dir_mask: RANDOM_DIRECTION mask in NFC_ECC_CTL register * @ecc_mode_mask: ECC_MODE mask in NFC_ECC_CTL register * @pat_found_mask: ECC_PAT_FOUND mask in NFC_REG_PAT_FOUND register * @dma_maxburst: DMA maxburst @@ -241,6 +243,8 @@ struct sunxi_nfc_caps { unsigned int reg_ecc_err_cnt; unsigned int reg_user_data; unsigned int reg_pat_found; + unsigned int random_en_mask; + unsigned int random_dir_mask; unsigned int ecc_mode_mask; unsigned int pat_found_mask; unsigned int dma_maxburst; @@ -669,7 +673,7 @@ static void sunxi_nfc_randomizer_enable(struct nand_chi= p *nand) if (!(nand->options & NAND_NEED_SCRAMBLING)) return; =20 - writel(readl(nfc->regs + NFC_REG_ECC_CTL) | NFC_RANDOM_EN, + writel(readl(nfc->regs + NFC_REG_ECC_CTL) | NFC_RANDOM_EN(nfc), nfc->regs + NFC_REG_ECC_CTL); } =20 @@ -680,7 +684,7 @@ static void sunxi_nfc_randomizer_disable(struct nand_ch= ip *nand) if (!(nand->options & NAND_NEED_SCRAMBLING)) return; =20 - writel(readl(nfc->regs + NFC_REG_ECC_CTL) & ~NFC_RANDOM_EN, + writel(readl(nfc->regs + NFC_REG_ECC_CTL) & ~NFC_RANDOM_EN(nfc), nfc->regs + NFC_REG_ECC_CTL); } =20 @@ -2220,6 +2224,8 @@ static const struct sunxi_nfc_caps sunxi_nfc_a10_caps= =3D { .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, .reg_user_data =3D NFC_REG_A10_USER_DATA, .reg_pat_found =3D NFC_REG_ECC_ST, + .random_en_mask =3D BIT(9), + .random_dir_mask =3D BIT(10), .ecc_mode_mask =3D GENMASK(15, 12), .pat_found_mask =3D GENMASK(31, 16), .dma_maxburst =3D 4, @@ -2234,6 +2240,8 @@ static const struct sunxi_nfc_caps sunxi_nfc_a23_caps= =3D { .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, .reg_user_data =3D NFC_REG_A10_USER_DATA, .reg_pat_found =3D NFC_REG_ECC_ST, + .random_en_mask =3D BIT(9), + .random_dir_mask =3D BIT(10), .ecc_mode_mask =3D GENMASK(15, 12), .pat_found_mask =3D GENMASK(31, 16), .dma_maxburst =3D 8, --=20 2.47.3 From nobody Fri Dec 19 10:36:47 2025 Received: from smtpout-04.galae.net (smtpout-04.galae.net [185.171.202.116]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AD48628506B for ; Fri, 10 Oct 2025 08:41:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.171.202.116 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085720; cv=none; b=TqjzL/pYEkxGXokzJdnK3WT60dKug5FBRO6INUf0ZoNoQyx7AlAnruuMYimdHEPC31tLmhSREdsw9eadvVcO6sbMK7PJEAtxrmT69GGK8syo99qMNg0ahNPoGqqUzkRHBszKw3CD80+52PYkIrGtqexAYsz7QQnsEjKObwqcJTg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085720; c=relaxed/simple; bh=tW16yu5won7yEC1m2XNdgJPgE1PL87FkX/QtU2yQWIo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cxTb5jyQqnQeQo2sP5rQnOcpt2GXDeg0hzVX60yijvHmH2ocBvmlQJxhiRkG9WNeLvZA3kyPxn8tSu3yW/PcmrQPe6L7iyJueKXQVHHgoTwWfn12PSfuCYerP4WlTw/PolOateYsipzyyoR/nCASQ1gZnWuAy106RUqOkPY2UW8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=E9WoEmn9; arc=none smtp.client-ip=185.171.202.116 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="E9WoEmn9" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-04.galae.net (Postfix) with ESMTPS id A98F4C08CCB; Fri, 10 Oct 2025 08:41:38 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 5542260667; Fri, 10 Oct 2025 08:41:57 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 1346E102F2204; Fri, 10 Oct 2025 10:41:54 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760085716; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=I9asITmUOZ5rSvaHSwS++hdYnOCMyfUki72OWs2uuxU=; b=E9WoEmn9MXmzhWLZzQfccCwt/WwmCi0naX97hCmNROjx0q6sxnbea6DiuetNEWORseU8ke VOItsmqFaJMLyQvov05heajsEuHM8h1DXTFPxTqE07dG9T1O6Q0XU97hww8XbSRHucKAOG ciHgjQ7fS6Y0oug0Fd4418oNy4jIH9qXByGRf6d9BS0O2sR2Ya/d0xaWcVil3Ofl/3+Muf nmbYmeQAMvUNftA4FbXi4a0QNsdwbopFZfZYb8jrOWG0quVNCYf+h+qvgjqCLDSCnzKRTb J5zB0H8CfW2gupB2wygQiUfnlKKDomYfwSoqvFL14hiiE7rUHb6LqJEZrR3t9Q== From: Richard Genoud To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Wentao Liang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Thomas Petazzoni , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 11/15] mtd: nand: sunxi: introduce reg_pat_id in sunxi_nfc_caps Date: Fri, 10 Oct 2025 10:40:38 +0200 Message-ID: <20251010084042.341224-12-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251010084042.341224-1-richard.genoud@bootlin.com> References: <20251010084042.341224-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The H6/H616 pattern ID register is not at the same offset as the A10/A23 one, so move its offset into sunxi_nfc_caps. No functional change. Signed-off-by: Richard Genoud --- drivers/mtd/nand/raw/sunxi_nand.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 5161dfff46ed..8921e66e0c6d 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -55,7 +55,8 @@ #define NFC_REG_A10_USER_DATA 0x0050 #define NFC_REG_USER_DATA(nfc, x) (nfc->caps->reg_user_data + ((x) * 4)) #define NFC_REG_SPARE_AREA 0x00A0 -#define NFC_REG_PAT_ID 0x00A4 +#define NFC_REG_PAT_ID(nfc) (nfc->caps->reg_pat_id) +#define NFC_REG_A10_PAT_ID 0x00A4 #define NFC_REG_MDMA_ADDR 0x00C0 #define NFC_REG_MDMA_CNT 0x00C4 #define NFC_RAM0_BASE 0x0400 @@ -227,6 +228,7 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(str= uct nand_chip *nand) * @reg_io_data: I/O data register * @reg_ecc_err_cnt: ECC error counter register * @reg_user_data: User data register + * @reg_pat_id: Pattern ID Register * @reg_pat_found: Data Pattern Status Register * @random_en_mask: RANDOM_EN mask in NFC_ECC_CTL register * @random_dir_mask: RANDOM_DIRECTION mask in NFC_ECC_CTL register @@ -242,6 +244,7 @@ struct sunxi_nfc_caps { unsigned int reg_io_data; unsigned int reg_ecc_err_cnt; unsigned int reg_user_data; + unsigned int reg_pat_id; unsigned int reg_pat_found; unsigned int random_en_mask; unsigned int random_dir_mask; @@ -803,7 +806,7 @@ static int sunxi_nfc_hw_ecc_correct(struct nand_chip *n= and, u8 *data, u8 *oob, if (pattern_found & BIT(step)) { u8 pattern; =20 - if (unlikely(!(readl(nfc->regs + NFC_REG_PAT_ID) & 0x1))) { + if (unlikely(!(readl(nfc->regs + NFC_REG_PAT_ID(nfc)) & 0x1))) { pattern =3D 0x0; } else { pattern =3D 0xff; @@ -2223,6 +2226,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a10_caps= =3D { .reg_io_data =3D NFC_REG_A10_IO_DATA, .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, .reg_user_data =3D NFC_REG_A10_USER_DATA, + .reg_pat_id =3D NFC_REG_A10_PAT_ID, .reg_pat_found =3D NFC_REG_ECC_ST, .random_en_mask =3D BIT(9), .random_dir_mask =3D BIT(10), @@ -2239,6 +2243,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a23_caps= =3D { .reg_io_data =3D NFC_REG_A23_IO_DATA, .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, .reg_user_data =3D NFC_REG_A10_USER_DATA, + .reg_pat_id =3D NFC_REG_A10_PAT_ID, .reg_pat_found =3D NFC_REG_ECC_ST, .random_en_mask =3D BIT(9), .random_dir_mask =3D BIT(10), --=20 2.47.3 From nobody Fri Dec 19 10:36:47 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A663283FFA for ; Fri, 10 Oct 2025 08:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085722; cv=none; b=NXOF7DOdGBFCjp/TNJJ71Vgf03dbLEhXg6MbE4d1mW2ybCnvFf7kE02qMDE30yEeFS/qSPAHzoK3a/vbK/s1iGIv+6QUWWZWg7VfQh2GpJgT6muv/qJVbHl8r2UmGtWjBDAzWvQandda0+5/RvMBJDWE3wt5dpHfv9y4KssQz8Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085722; c=relaxed/simple; bh=kcHjhcAS5qX/rhgd6u++hDtF8dDx/2buhJDdkmVfWo4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jHTiWZpqj2WRn7JvX3hX+sUsA/PXcKtN6GDgKKU+5ntYWO5W1842XzDxo5pTD+UjSbaFfGSpZzQj/1TBKUeceCY6LuAc2pCBjTuXFra1XZncYUc1CEjoFsQWDsMvuGXAcQ/5DJR1h6ukDtWCQji+h2nzk5xHZuwKIb/VHjJesuc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=tg/jynav; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="tg/jynav" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id A6B511A1285; Fri, 10 Oct 2025 08:41:59 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 7D32860667; Fri, 10 Oct 2025 08:41:59 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 73A52102F220B; Fri, 10 Oct 2025 10:41:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760085718; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=zrFppuVA4Tx0AXaKZV03Ob6lPPggHgdPbLxorTpS1EI=; b=tg/jynavBKvnWr887Qh4TPjrYBuOq9cxIE7UmUNIbWruIpJu0/MR30tXD5D8cFygaYJGtz Rjr0ux0r6sXvmGLC77uJVOCvPHgDg7TtY0zUEkOaxA+ByKkBaFofBwp4nOKKHgmmBZMUfd 8g2ZmUUffiNgnGm+yJd4eUxROXcUfWqhcjf/DtPAsAcLRbIFSanI6qWvRmthZpLFyCFdZc llsxWcAh7CyDxLj80s0wNPEDdluxwlGLaEDXZ78SkoDQdFSvqxgCeBkswE3O+LcZ4FWStN 4hYuwJJeAkkOmolRN2KmO2vuz0SjaGWy3jzfZs/W5RjdeYWX5Gs55lH8z8BJ9A== From: Richard Genoud To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Wentao Liang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Thomas Petazzoni , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 12/15] mtd: nand: sunxi: introduce reg_spare_area in sunxi_nfc_caps Date: Fri, 10 Oct 2025 10:40:39 +0200 Message-ID: <20251010084042.341224-13-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251010084042.341224-1-richard.genoud@bootlin.com> References: <20251010084042.341224-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The H6/H616 spare area register is not at the same offset as the A10/A23 one, so move its offset into sunxi_nfc_caps. No functional change. Signed-off-by: Richard Genoud --- drivers/mtd/nand/raw/sunxi_nand.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 8921e66e0c6d..80aafa4e1844 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -54,7 +54,8 @@ #define NFC_REG_ECC_ERR_CNT(nfc, x) ((nfc->caps->reg_ecc_err_cnt + (x)) & = ~0x3) #define NFC_REG_A10_USER_DATA 0x0050 #define NFC_REG_USER_DATA(nfc, x) (nfc->caps->reg_user_data + ((x) * 4)) -#define NFC_REG_SPARE_AREA 0x00A0 +#define NFC_REG_SPARE_AREA(nfc) (nfc->caps->reg_spare_area) +#define NFC_REG_A10_SPARE_AREA 0x00A0 #define NFC_REG_PAT_ID(nfc) (nfc->caps->reg_pat_id) #define NFC_REG_A10_PAT_ID 0x00A4 #define NFC_REG_MDMA_ADDR 0x00C0 @@ -228,6 +229,7 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(str= uct nand_chip *nand) * @reg_io_data: I/O data register * @reg_ecc_err_cnt: ECC error counter register * @reg_user_data: User data register + * @reg_spare_area: Spare Area Register * @reg_pat_id: Pattern ID Register * @reg_pat_found: Data Pattern Status Register * @random_en_mask: RANDOM_EN mask in NFC_ECC_CTL register @@ -244,6 +246,7 @@ struct sunxi_nfc_caps { unsigned int reg_io_data; unsigned int reg_ecc_err_cnt; unsigned int reg_user_data; + unsigned int reg_spare_area; unsigned int reg_pat_id; unsigned int reg_pat_found; unsigned int random_en_mask; @@ -466,7 +469,7 @@ static void sunxi_nfc_select_chip(struct nand_chip *nan= d, unsigned int cs) if (sel->rb >=3D 0) ctl |=3D NFC_RB_SEL(sel->rb); =20 - writel(mtd->writesize, nfc->regs + NFC_REG_SPARE_AREA); + writel(mtd->writesize, nfc->regs + NFC_REG_SPARE_AREA(nfc)); =20 if (nfc->clk_rate !=3D sunxi_nand->clk_rate) { clk_set_rate(nfc->mod_clk, sunxi_nand->clk_rate); @@ -2226,6 +2229,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a10_caps= =3D { .reg_io_data =3D NFC_REG_A10_IO_DATA, .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, .reg_user_data =3D NFC_REG_A10_USER_DATA, + .reg_spare_area =3D NFC_REG_A10_SPARE_AREA, .reg_pat_id =3D NFC_REG_A10_PAT_ID, .reg_pat_found =3D NFC_REG_ECC_ST, .random_en_mask =3D BIT(9), @@ -2243,6 +2247,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a23_caps= =3D { .reg_io_data =3D NFC_REG_A23_IO_DATA, .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, .reg_user_data =3D NFC_REG_A10_USER_DATA, + .reg_spare_area =3D NFC_REG_A10_SPARE_AREA, .reg_pat_id =3D NFC_REG_A10_PAT_ID, .reg_pat_found =3D NFC_REG_ECC_ST, .random_en_mask =3D BIT(9), --=20 2.47.3 From nobody Fri Dec 19 10:36:47 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 931AD288C12; Fri, 10 Oct 2025 08:42:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085725; cv=none; b=cST57WJID3ZCnILMCgJ7x7H+qHtf4EE3mZ49ylMvw2+NtDBZVXhYB46c33QZrbByO1y8OWhy50RZHwr95DGPC6UBy1smgkHx+0yfW2+Hu1FNhz5UV+8dB2MGKuXkoESC8fyF4V3ZyVuufc40agogcpN0ej0YocgyLkSxgnE6Isw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085725; c=relaxed/simple; bh=l4WAsmsuOz7Jsf+sdax9q2EP3I81f3d3ZdfPgBi4e6I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TPk6BDkH28AZ5e1VoCUFS6NlgEaQpbOaCQo4dxEdFoMHAyO5BQ+Z5QyPE3EqYcPOP9WFWGAvE01sL8jWz+ckJBpU8zGc/FYIGcvBVXwOtgl1kv9yrp5mxwlsIy++HlVip8cCB40DSZj/uK+p7lhUb86NV2Iy6uDSgm4SRcEId1M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=0HaMos45; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="0HaMos45" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 4A8434E40FCE; Fri, 10 Oct 2025 08:42:02 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 2073860667; Fri, 10 Oct 2025 08:42:02 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id D39B1102F21F6; Fri, 10 Oct 2025 10:41:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760085720; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=xBC8LNngzpgWuLk6Iaxw78Ekk5fw7GlULT04baQhk6A=; b=0HaMos45nHtmvcPEgvdxfUvSvNERAh0a4+FTd8TKlvL9WGObj5JEeNfO96cRJboo4xUElo vYvhVBBDORZahnmNc9q6goXzKfGYYOsD16spyFb+Wffjl9StdFrWfe/Hh3m8Qq4mfKViic xrOPe68/TlfY9MK8HM3RUhZEwKhJwAk6TcJUdLD3OJNvZo3JM/IEOERR/doz5znqkHblWr PUKZWObVdJCg3wBm7Y/JE6cSnLGZwntoHuSZTk+QlGfJ8Ju4CoeZQxZv+Vy0eXZtNxW9mt stdJi/uEqmsvTsauB84razb99kccAdRRJlJiQ53hDhZq7PXTkepMeCobX2ybPg== From: Richard Genoud To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Wentao Liang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Thomas Petazzoni , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 13/15] mtd: nand: sunxi: introduce ecc_err_mask in sunxi_nfc_caps Date: Fri, 10 Oct 2025 10:40:40 +0200 Message-ID: <20251010084042.341224-14-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251010084042.341224-1-richard.genoud@bootlin.com> References: <20251010084042.341224-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The H6/H616 error mask register is bigger than the A10/A23 one, so move its mask into sunxi_nfc_caps. No functional change Signed-off-by: Richard Genoud --- drivers/mtd/nand/raw/sunxi_nand.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 80aafa4e1844..3912878e7645 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -155,7 +155,7 @@ =20 /* define bit use in NFC_ECC_ST */ #define NFC_ECC_ERR(x) BIT(x) -#define NFC_ECC_ERR_MSK GENMASK(15, 0) +#define NFC_ECC_ERR_MSK(nfc) (nfc->caps->ecc_err_mask) =20 /* * define bit use in NFC_REG_PAT_FOUND @@ -235,6 +235,7 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(str= uct nand_chip *nand) * @random_en_mask: RANDOM_EN mask in NFC_ECC_CTL register * @random_dir_mask: RANDOM_DIRECTION mask in NFC_ECC_CTL register * @ecc_mode_mask: ECC_MODE mask in NFC_ECC_CTL register + * @ecc_err_mask: NFC_ECC_ERR mask in NFC_ECC_ST register * @pat_found_mask: ECC_PAT_FOUND mask in NFC_REG_PAT_FOUND register * @dma_maxburst: DMA maxburst * @ecc_strengths: Available ECC strengths array @@ -252,6 +253,7 @@ struct sunxi_nfc_caps { unsigned int random_en_mask; unsigned int random_dir_mask; unsigned int ecc_mode_mask; + unsigned int ecc_err_mask; unsigned int pat_found_mask; unsigned int dma_maxburst; const u8 *ecc_strengths; @@ -1030,7 +1032,7 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct na= nd_chip *nand, uint8_t *buf sunxi_nfc_hw_ecc_update_stats(nand, &max_bitflips, ret); } =20 - if (status & NFC_ECC_ERR_MSK) { + if (status & NFC_ECC_ERR_MSK(nfc)) { for (i =3D 0; i < nchunks; i++) { int data_off =3D i * ecc->size; int oob_off =3D i * (ecc->bytes + 4); @@ -2235,6 +2237,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a10_caps= =3D { .random_en_mask =3D BIT(9), .random_dir_mask =3D BIT(10), .ecc_mode_mask =3D GENMASK(15, 12), + .ecc_err_mask =3D GENMASK(15, 0), .pat_found_mask =3D GENMASK(31, 16), .dma_maxburst =3D 4, .ecc_strengths =3D sunxi_ecc_strengths_a10, @@ -2253,6 +2256,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a23_caps= =3D { .random_en_mask =3D BIT(9), .random_dir_mask =3D BIT(10), .ecc_mode_mask =3D GENMASK(15, 12), + .ecc_err_mask =3D GENMASK(15, 0), .pat_found_mask =3D GENMASK(31, 16), .dma_maxburst =3D 8, .ecc_strengths =3D sunxi_ecc_strengths_a10, --=20 2.47.3 From nobody Fri Dec 19 10:36:47 2025 Received: from smtpout-03.galae.net (smtpout-03.galae.net [185.246.85.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 725B828C5D5 for ; Fri, 10 Oct 2025 08:42:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.85.4 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085728; cv=none; b=cpRNxGuowmIG+xgaZ6EK8RKRvPfwxoQNlaOthjE+N9+afWAob5YIfVuvTJhW4PeJEeidro+kZ+DX4l6PCNnxzOErRfGoZFJaUt+s/w7XY1Yiy2n8Yyhj2n/CtH8lzhqZtAa5xNDEpIfHhe0OcCtZ7eBVVepKJnMgznwZja2leR0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085728; c=relaxed/simple; bh=cEQn29jCxybp0mc+vVYJ7BrpJTmfe1Rgs0CG30Yzy9M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=okLpIyzKjg5LivAR4+l1LvWcUtbssIYKn5yikhSt4emlcpHIjJshsaATNdJ2+SGjAjli1gKTxacp93020sPSc0LxLFVUw2ZGCPpeWQUGnCoysxE89mQigv2IutePg4NhQkn4wJ5m9+pOlRqJjfGGGsy3OxCjQkAqp/qqooo73Wo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Tkd4UNkK; arc=none smtp.client-ip=185.246.85.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Tkd4UNkK" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-03.galae.net (Postfix) with ESMTPS id 23F524E40FCD; Fri, 10 Oct 2025 08:42:05 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id EDA4860667; Fri, 10 Oct 2025 08:42:04 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 52819102F2207; Fri, 10 Oct 2025 10:42:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760085723; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=rRUQJ34yBDEQRJECh1MeBCDCN7q5t1MV6jZLuQSFP2g=; b=Tkd4UNkK3WjiPjOrsD0l9gsyO2oU43kzmJwd3LHFb5HHG3HmadoK0OTbXbe2yvNPk2hcTy JGpakH+FT1KoYPYtrpn7V3jmk/e5jMCjRWtz53dAoAhKaX/ZEthzuHEheFrjo+g8rAPXv9 +8ucUMMklbhZtdNIMZ2nmmMa3b1Zu3wuuGWIqNUxc+JxmxwuEYupIcBV+66dIpidQo/liK Rij+nA4++61e7BDEGN+3ppJ5wRH76YzwdLw4ak8BzoQafHvuGbLEPK+gUjE1EagJ5Wg7nX U4/T5VQHAsuxGBvS/j9/S/nNmPrceAyLBJGp3aYDeh5zMzED/DoXHg3jdyE/kQ== From: Richard Genoud To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Wentao Liang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Thomas Petazzoni , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 14/15] mtd: nand: sunxi: introduce sram_size in sunxi_nfc_caps Date: Fri, 10 Oct 2025 10:40:41 +0200 Message-ID: <20251010084042.341224-15-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251010084042.341224-1-richard.genoud@bootlin.com> References: <20251010084042.341224-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The H6/H616 the SRAM is bigger than the A10/A23 one, so move its size into sunxi_nfc_caps. No functional change Signed-off-by: Richard Genoud --- drivers/mtd/nand/raw/sunxi_nand.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index 3912878e7645..e81d74c6633a 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -167,8 +167,6 @@ =20 #define NFC_DEFAULT_TIMEOUT_MS 1000 =20 -#define NFC_SRAM_SIZE 1024 - #define NFC_MAX_CS 7 =20 /** @@ -240,6 +238,7 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(str= uct nand_chip *nand) * @dma_maxburst: DMA maxburst * @ecc_strengths: Available ECC strengths array * @nstrengths: Size of @ecc_strengths + * @sram_size: Size of the NAND controller SRAM */ struct sunxi_nfc_caps { bool has_mdma; @@ -258,6 +257,7 @@ struct sunxi_nfc_caps { unsigned int dma_maxburst; const u8 *ecc_strengths; unsigned int nstrengths; + int sram_size; }; =20 /** @@ -495,7 +495,7 @@ static void sunxi_nfc_read_buf(struct nand_chip *nand, = uint8_t *buf, int len) while (len > offs) { bool poll =3D false; =20 - cnt =3D min(len - offs, NFC_SRAM_SIZE); + cnt =3D min(len - offs, nfc->caps->sram_size); =20 ret =3D sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) @@ -533,7 +533,7 @@ static void sunxi_nfc_write_buf(struct nand_chip *nand,= const uint8_t *buf, while (len > offs) { bool poll =3D false; =20 - cnt =3D min(len - offs, NFC_SRAM_SIZE); + cnt =3D min(len - offs, nfc->caps->sram_size); =20 ret =3D sunxi_nfc_wait_cmd_fifo_empty(nfc); if (ret) @@ -1861,7 +1861,7 @@ static int sunxi_nfc_exec_subop(struct nand_chip *nan= d, case NAND_OP_DATA_OUT_INSTR: start =3D nand_subop_get_data_start_off(subop, i); remaining =3D nand_subop_get_data_len(subop, i); - cnt =3D min_t(u32, remaining, NFC_SRAM_SIZE); + cnt =3D min_t(u32, remaining, nfc->caps->sram_size); cmd |=3D NFC_DATA_TRANS | NFC_DATA_SWAP_METHOD; =20 if (instr->type =3D=3D NAND_OP_DATA_OUT_INSTR) { @@ -2242,6 +2242,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a10_caps= =3D { .dma_maxburst =3D 4, .ecc_strengths =3D sunxi_ecc_strengths_a10, .nstrengths =3D ARRAY_SIZE(sunxi_ecc_strengths_a10), + .sram_size =3D 1024, }; =20 static const struct sunxi_nfc_caps sunxi_nfc_a23_caps =3D { @@ -2261,6 +2262,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a23_caps= =3D { .dma_maxburst =3D 8, .ecc_strengths =3D sunxi_ecc_strengths_a10, .nstrengths =3D ARRAY_SIZE(sunxi_ecc_strengths_a10), + .sram_size =3D 1024, }; =20 static const struct of_device_id sunxi_nfc_ids[] =3D { --=20 2.47.3 From nobody Fri Dec 19 10:36:47 2025 Received: from smtpout-02.galae.net (smtpout-02.galae.net [185.246.84.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B54A289E07 for ; Fri, 10 Oct 2025 08:42:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.246.84.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085731; cv=none; b=fqy536TV74K+fZ41wO7EnJ9c096xltMK7pR0UTbSXVNeA5zVwIE2q6jKoz/ZuJN+olMls9pvw1S5wDp6nPVJK/t4aTZtziariMBcywZYrtKKbu9L5Vur/VpW5GTSe3IA1ru7eu9aXGuOA3GU3jjk2uqruN+nh3XCTVzi+RKu5jc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760085731; c=relaxed/simple; bh=rtdRGLejnTu67Rb9wmBHL0xESMEQ00Nn2zzDM0xi+V8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TWmxh45rXyUzws42Sx8JvQBhQbFHMhWe5YJ9jwgmNLGvQzBk0SBhBA6Rq/b213n0dSKeVSpGHufGzG1cYgvr6dg2RirKBEcM0PxkFYFADOCFnVYRJnVK4ysCDmGxTvg1PE0uJw6x9FaA0SZOSglghERB4UCbzMXJwoJXW10YfxI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=EpAFugaH; arc=none smtp.client-ip=185.246.84.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="EpAFugaH" Received: from smtpout-01.galae.net (smtpout-01.galae.net [212.83.139.233]) by smtpout-02.galae.net (Postfix) with ESMTPS id B358F1A1288; Fri, 10 Oct 2025 08:42:07 +0000 (UTC) Received: from mail.galae.net (mail.galae.net [212.83.136.155]) by smtpout-01.galae.net (Postfix) with ESMTPS id 8801A60667; Fri, 10 Oct 2025 08:42:07 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) by localhost (Mailerdaemon) with ESMTPSA id 0D95B102F220A; Fri, 10 Oct 2025 10:42:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=dkim; t=1760085726; h=from:subject:date:message-id:to:cc:mime-version: content-transfer-encoding:in-reply-to:references; bh=9kbiZUodR2cKxdISdXMzruPjD9ma3kA1eUcGB0z649o=; b=EpAFugaH5sSynwFj633gVmsUg6geDhZMyxjw06XlaGQwZCwYtcbY9KnIGTy7NNRKQ+3sl0 zZ8WmA9ZSJXzKognROe4fqPUp9ONdo7iUndO47KohQQS6F8eJFExaTgsqHRahuZY2kpGCX cIUeJzOxwLQCnukwZ+elR/fG21B4J3WTJTZ/9uxCI7ClX8nGit0bopNKbUVe9GoGeQC/Jn 4Nu/twcy43+bmLNj4WkradUg7PEBUGto2mEna4xck4LKOMFew7oVUU+8FMtzCYcInRZG3n IxF0UU0Iqm/YF7EmIKHkGbWn04+9VgL5P9beEDLDREfM5u3fLuuYiKP24fKjIw== From: Richard Genoud To: Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Wentao Liang , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , Maxime Ripard , Thomas Petazzoni , linux-mtd@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Richard Genoud Subject: [PATCH 15/15] mtd: rawnand: sunxi: Add support for H616 nand controller Date: Fri, 10 Oct 2025 10:40:42 +0200 Message-ID: <20251010084042.341224-16-richard.genoud@bootlin.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251010084042.341224-1-richard.genoud@bootlin.com> References: <20251010084042.341224-1-richard.genoud@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Last-TLS-Session-Version: TLSv1.3 Content-Type: text/plain; charset="utf-8" The H616 nand controller has the same base as A10/A23, with some differences: - mdma is based on chained buffers - its ECC supports up to 80bit per 1024bytes - some registers layouts are a bit different, mainly due do the stronger ECC. - it uses USER_DATA_LEN registers along USER_DATA registers. - it needs a specific clock for ECC and MBUS. This patch introduce the basic support, without DMA/MDMA. Tested on Whatsminer H616 board (with and without scrambling, ECC) Signed-off-by: Richard Genoud --- drivers/mtd/nand/raw/sunxi_nand.c | 182 ++++++++++++++++++++++++++++-- 1 file changed, 174 insertions(+), 8 deletions(-) diff --git a/drivers/mtd/nand/raw/sunxi_nand.c b/drivers/mtd/nand/raw/sunxi= _nand.c index e81d74c6633a..1e1185f8d980 100644 --- a/drivers/mtd/nand/raw/sunxi_nand.c +++ b/drivers/mtd/nand/raw/sunxi_nand.c @@ -49,17 +49,40 @@ #define NFC_REG_A23_IO_DATA 0x0300 #define NFC_REG_ECC_CTL 0x0034 #define NFC_REG_ECC_ST 0x0038 -#define NFC_REG_DEBUG 0x003C +#define NFC_REG_H6_PAT_FOUND 0x003C #define NFC_REG_A10_ECC_ERR_CNT 0x0040 +#define NFC_REG_H6_ECC_ERR_CNT 0x0050 #define NFC_REG_ECC_ERR_CNT(nfc, x) ((nfc->caps->reg_ecc_err_cnt + (x)) & = ~0x3) +#define NFC_REG_H6_RDATA_CTL 0x0044 +#define NFC_REG_H6_RDATA_0 0x0048 +#define NFC_REG_H6_RDATA_1 0x004C #define NFC_REG_A10_USER_DATA 0x0050 +#define NFC_REG_H6_USER_DATA 0x0080 #define NFC_REG_USER_DATA(nfc, x) (nfc->caps->reg_user_data + ((x) * 4)) +#define NFC_REG_H6_USER_DATA_LEN 0x0070 +/* A USER_DATA_LEN register can hold the length of 8 USER_DATA registers */ +#define NFC_REG_USER_DATA_LEN_CAPACITY 8 +#define NFC_REG_USER_DATA_LEN(nfc, step) \ + (nfc->caps->reg_user_data_len + \ + ((step) / NFC_REG_USER_DATA_LEN_CAPACITY) * 4) #define NFC_REG_SPARE_AREA(nfc) (nfc->caps->reg_spare_area) #define NFC_REG_A10_SPARE_AREA 0x00A0 #define NFC_REG_PAT_ID(nfc) (nfc->caps->reg_pat_id) #define NFC_REG_A10_PAT_ID 0x00A4 #define NFC_REG_MDMA_ADDR 0x00C0 #define NFC_REG_MDMA_CNT 0x00C4 +#define NFC_REG_H6_EFNAND_STATUS 0x0110 +#define NFC_REG_H6_SPARE_AREA 0x0114 +#define NFC_REG_H6_PAT_ID 0x0118 +#define NFC_REG_H6_DDR2_SPEC_CTL 0x011C +#define NFC_REG_H6_NDMA_MODE_CTL 0x0120 +#define NFC_REG_H6_MDMA_DLBA_REG 0x0200 +#define NFC_REG_H6_MDMA_STA 0x0204 +#define NFC_REG_H6_MDMA_INT_MAS 0x0208 +#define NFC_REG_H6_MDMA_DESC_ADDR 0x020C +#define NFC_REG_H6_MDMA_BUF_ADDR 0x0210 +#define NFC_REG_H6_MDMA_CNT 0x0214 + #define NFC_RAM0_BASE 0x0400 #define NFC_RAM1_BASE 0x0800 =20 @@ -71,6 +94,7 @@ #define NFC_BUS_WIDTH_16 (1 << 2) #define NFC_RB_SEL_MSK BIT(3) #define NFC_RB_SEL(x) ((x) << 3) +/* CE_SEL BIT 27 is meant to be used for GPIO chipselect */ #define NFC_CE_SEL_MSK GENMASK(26, 24) #define NFC_CE_SEL(x) ((x) << 24) #define NFC_CE_CTL BIT(6) @@ -89,6 +113,9 @@ #define NFC_STA BIT(4) #define NFC_NATCH_INT_FLAG BIT(5) #define NFC_RB_STATE(x) BIT(x + 8) +#define NFC_RB_STATE_MSK GENMASK(11, 8) +#define NDFC_RDATA_STA_1 BIT(12) +#define NDFC_RDATA_STA_0 BIT(13) =20 /* define bit use in NFC_INT */ #define NFC_B2R_INT_ENABLE BIT(0) @@ -100,6 +127,7 @@ =20 /* define bit use in NFC_TIMING_CTL */ #define NFC_TIMING_CTL_EDO BIT(8) +#define NFC_TIMING_CTL_E_EDO BIT(9) =20 /* define NFC_TIMING_CFG register layout */ #define NFC_TIMING_CFG(tWB, tADL, tWHR, tRHW, tCAD) \ @@ -107,9 +135,15 @@ (((tWHR) & 0x3) << 4) | (((tRHW) & 0x3) << 6) | \ (((tCAD) & 0x7) << 8)) =20 +#define NFC_TIMING_CFG2(tCDQSS, tSC, tCLHZ, tCSS, tWC) \ + ((((tCDQSS) & 0x1) << 11) | (((tSC) & 0x3) << 12) | \ + (((tCLHZ) & 0x3) << 14) | (((tCSS) & 0x3) << 16) | \ + (((tWC) & 0x3) << 18)) + /* define bit use in NFC_CMD */ #define NFC_CMD_LOW_BYTE_MSK GENMASK(7, 0) -#define NFC_CMD_HIGH_BYTE_MSK GENMASK(15, 8) +#define NFC_CMD_HIGH_BYTE_MSK GENMASK(15, 8) // 15-10 reserved on H6 +#define NFC_CMD_ADR_NUM_MSK GENMASK(9, 8) #define NFC_CMD(x) (x) #define NFC_ADR_NUM_MSK GENMASK(18, 16) #define NFC_ADR_NUM(x) (((x) - 1) << 16) @@ -122,6 +156,7 @@ #define NFC_SEQ BIT(25) #define NFC_DATA_SWAP_METHOD BIT(26) #define NFC_ROW_AUTO_INC BIT(27) +#define NFC_H6_SEND_RND_CMD2 BIT(27) #define NFC_SEND_CMD3 BIT(28) #define NFC_SEND_CMD4 BIT(29) #define NFC_CMD_TYPE_MSK GENMASK(31, 30) @@ -133,6 +168,7 @@ #define NFC_READ_CMD_MSK GENMASK(7, 0) #define NFC_RND_READ_CMD0_MSK GENMASK(15, 8) #define NFC_RND_READ_CMD1_MSK GENMASK(23, 16) +#define NFC_RND_READ_CMD2_MSK GENMASK(31, 24) =20 /* define bit use in NFC_WCMD_SET */ #define NFC_PROGRAM_CMD_MSK GENMASK(7, 0) @@ -150,6 +186,9 @@ #define NFC_RANDOM_DIRECTION(nfc) (nfc->caps->random_dir_mask) #define NFC_ECC_MODE_MSK(nfc) (nfc->caps->ecc_mode_mask) #define NFC_ECC_MODE(nfc, x) field_prep(NFC_ECC_MODE_MSK(nfc), (x)) +/* RANDOM_PAGE_SIZE: 0: ECC block size 1: page size */ +#define NFC_A23_RANDOM_PAGE_SIZE BIT(11) +#define NFC_H6_RANDOM_PAGE_SIZE BIT(7) #define NFC_RANDOM_SEED_MSK GENMASK(30, 16) #define NFC_RANDOM_SEED(x) ((x) << 16) =20 @@ -165,6 +204,9 @@ =20 #define NFC_ECC_ERR_CNT(b, x) (((x) >> (((b) % 4) * 8)) & 0xff) =20 +#define NFC_USER_DATA_LEN_MSK(step) \ + (0xf << (((step) % NFC_REG_USER_DATA_LEN_CAPACITY) * 4)) + #define NFC_DEFAULT_TIMEOUT_MS 1000 =20 #define NFC_MAX_CS 7 @@ -224,9 +266,11 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(st= ruct nand_chip *nand) * @has_mdma: Use mbus dma mode, otherwise general dma * through MBUS on A23/A33 needs extra configuration. * @has_ecc_block_512: If the ECC can handle 512B or only 1024B chuncks + * @has_mbus_clk: If the controller needs a mbus clock. * @reg_io_data: I/O data register * @reg_ecc_err_cnt: ECC error counter register * @reg_user_data: User data register + * @reg_user_data_len: User data length register * @reg_spare_area: Spare Area Register * @reg_pat_id: Pattern ID Register * @reg_pat_found: Data Pattern Status Register @@ -238,14 +282,23 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(s= truct nand_chip *nand) * @dma_maxburst: DMA maxburst * @ecc_strengths: Available ECC strengths array * @nstrengths: Size of @ecc_strengths + * @max_ecc_steps: Maximum supported steps for ECC, this is also the + * number of user data registers + * @user_data_len_tab: Table of lenghts supported by USER_DATA_LEN regist= er + * The table index is the value to set in NFC_USER_DATA_LEN + * registers, and the corresponding value is the number of + * bytes to write + * @nuser_data_tab: Size of @user_data_len_tab * @sram_size: Size of the NAND controller SRAM */ struct sunxi_nfc_caps { bool has_mdma; bool has_ecc_block_512; + bool has_mbus_clk; unsigned int reg_io_data; unsigned int reg_ecc_err_cnt; unsigned int reg_user_data; + unsigned int reg_user_data_len; unsigned int reg_spare_area; unsigned int reg_pat_id; unsigned int reg_pat_found; @@ -257,6 +310,9 @@ struct sunxi_nfc_caps { unsigned int dma_maxburst; const u8 *ecc_strengths; unsigned int nstrengths; + const u8 *user_data_len_tab; + unsigned int nuser_data_tab; + unsigned int max_ecc_steps; int sram_size; }; =20 @@ -268,6 +324,7 @@ struct sunxi_nfc_caps { * @regs: NAND controller registers * @ahb_clk: NAND controller AHB clock * @mod_clk: NAND controller mod clock + * @ecc_clk: NAND controller ECC clock * @reset: NAND controller reset line * @assigned_cs: bitmask describing already assigned CS lines * @clk_rate: NAND controller current clock rate @@ -282,7 +339,9 @@ struct sunxi_nfc { struct device *dev; void __iomem *regs; struct clk *ahb_clk; + struct clk *mbus_clk; struct clk *mod_clk; + struct clk *ecc_clk; struct reset_control *reset; unsigned long assigned_cs; unsigned long clk_rate; @@ -764,6 +823,53 @@ static void sunxi_nfc_hw_ecc_get_prot_oob_bytes(struct= nand_chip *nand, u8 *oob, sunxi_nfc_randomize_bbm(nand, page, oob); } =20 +/* + * On H6/H6 the user_data length has to be set in specific registers + * before writing. + */ +static void sunxi_nfc_reset_user_data_len(struct sunxi_nfc *nfc) +{ + int loop_step =3D NFC_REG_USER_DATA_LEN_CAPACITY; + + /* not all SoCs have this register */ + if (!nfc->caps->reg_user_data_len) + return; + + for (int i =3D 0; i < nfc->caps->max_ecc_steps; i +=3D loop_step) + writel(0, nfc->regs + NFC_REG_USER_DATA_LEN(nfc, i)); +} + +static void sunxi_nfc_set_user_data_len(struct sunxi_nfc *nfc, + int len, int step) +{ + bool found =3D false; + u32 val; + int i; + + /* not all SoCs have this register */ + if (!nfc->caps->reg_user_data_len) + return; + + for (i =3D 0; i < nfc->caps->nuser_data_tab; i++) { + if (len =3D=3D nfc->caps->user_data_len_tab[i]) { + found =3D true; + break; + } + } + + if (!found) { + dev_warn(nfc->dev, + "Unsupported length for user data reg: %d\n", len); + return; + } + + val =3D readl(nfc->regs + NFC_REG_USER_DATA_LEN(nfc, step)); + + val &=3D ~NFC_USER_DATA_LEN_MSK(step); + val |=3D field_prep(NFC_USER_DATA_LEN_MSK(step), i); + writel(val, nfc->regs + NFC_REG_USER_DATA_LEN(nfc, step)); +} + static void sunxi_nfc_hw_ecc_set_prot_oob_bytes(struct nand_chip *nand, const u8 *oob, int step, bool bbm, int page) @@ -858,6 +964,8 @@ static int sunxi_nfc_hw_ecc_read_chunk(struct nand_chip= *nand, if (ret) return ret; =20 + sunxi_nfc_reset_user_data_len(nfc); + sunxi_nfc_set_user_data_len(nfc, 4, 0); sunxi_nfc_randomizer_config(nand, page, false); sunxi_nfc_randomizer_enable(nand); writel(NFC_DATA_TRANS | NFC_DATA_SWAP_METHOD | NFC_ECC_OP, @@ -968,6 +1076,8 @@ static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nan= d_chip *nand, uint8_t *buf return ret; =20 sunxi_nfc_hw_ecc_enable(nand); + sunxi_nfc_reset_user_data_len(nfc); + sunxi_nfc_set_user_data_len(nfc, 4, 0); sunxi_nfc_randomizer_config(nand, page, false); sunxi_nfc_randomizer_enable(nand); =20 @@ -1100,6 +1210,8 @@ static int sunxi_nfc_hw_ecc_write_chunk(struct nand_c= hip *nand, =20 sunxi_nfc_randomizer_config(nand, page, false); sunxi_nfc_randomizer_enable(nand); + sunxi_nfc_reset_user_data_len(nfc); + sunxi_nfc_set_user_data_len(nfc, 4, 0); sunxi_nfc_hw_ecc_set_prot_oob_bytes(nand, oob, 0, bbm, page); =20 writel(NFC_DATA_TRANS | NFC_DATA_SWAP_METHOD | @@ -1344,10 +1456,12 @@ static int sunxi_nfc_hw_ecc_write_page_dma(struct n= and_chip *nand, if (ret) goto pio_fallback; =20 + sunxi_nfc_reset_user_data_len(nfc); for (i =3D 0; i < ecc->steps; i++) { const u8 *oob =3D nand->oob_poi + (i * (ecc->bytes + 4)); =20 sunxi_nfc_hw_ecc_set_prot_oob_bytes(nand, oob, i, !i, page); + sunxi_nfc_set_user_data_len(nfc, 4, i); } =20 nand_prog_page_begin_op(nand, page, 0, NULL, 0); @@ -2148,18 +2262,36 @@ static int sunxi_nfc_probe(struct platform_device *= pdev) if (irq < 0) return irq; =20 + nfc->caps =3D of_device_get_match_data(dev); + if (!nfc->caps) + return -EINVAL; + nfc->ahb_clk =3D devm_clk_get_enabled(dev, "ahb"); if (IS_ERR(nfc->ahb_clk)) { dev_err(dev, "failed to retrieve ahb clk\n"); return PTR_ERR(nfc->ahb_clk); } =20 + if (nfc->caps->has_mbus_clk) { + nfc->mbus_clk =3D devm_clk_get_enabled(dev, "mbus"); + if (IS_ERR(nfc->mbus_clk)) { + dev_err(dev, "No mbus clock specified\n"); + return PTR_ERR(nfc->mbus_clk); + } + } + nfc->mod_clk =3D devm_clk_get_enabled(dev, "mod"); if (IS_ERR(nfc->mod_clk)) { dev_err(dev, "failed to retrieve mod clk\n"); return PTR_ERR(nfc->mod_clk); } =20 + nfc->ecc_clk =3D devm_clk_get_optional_enabled(dev, "ecc"); + if (IS_ERR(nfc->ecc_clk)) { + dev_err(dev, "failed to retrieve ecc clk\n"); + return PTR_ERR(nfc->ecc_clk); + } + nfc->reset =3D devm_reset_control_get_optional_exclusive(dev, "ahb"); if (IS_ERR(nfc->reset)) return PTR_ERR(nfc->reset); @@ -2170,12 +2302,6 @@ static int sunxi_nfc_probe(struct platform_device *p= dev) return ret; } =20 - nfc->caps =3D of_device_get_match_data(&pdev->dev); - if (!nfc->caps) { - ret =3D -EINVAL; - goto out_ahb_reset_reassert; - } - ret =3D sunxi_nfc_rst(nfc); if (ret) goto out_ahb_reset_reassert; @@ -2226,8 +2352,17 @@ static const u8 sunxi_ecc_strengths_a10[] =3D { 16, 24, 28, 32, 40, 48, 56, 60, 64 }; =20 +static const u8 sunxi_ecc_strengths_h6[] =3D { + 16, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 72, 76, 80 +}; + +static const u8 sunxi_user_data_len_h6[] =3D { + 0, 4, 8, 12, 16, 20, 24, 28, 32 +}; + static const struct sunxi_nfc_caps sunxi_nfc_a10_caps =3D { .has_ecc_block_512 =3D true, + .has_mbus_clk =3D false, .reg_io_data =3D NFC_REG_A10_IO_DATA, .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, .reg_user_data =3D NFC_REG_A10_USER_DATA, @@ -2242,11 +2377,13 @@ static const struct sunxi_nfc_caps sunxi_nfc_a10_ca= ps =3D { .dma_maxburst =3D 4, .ecc_strengths =3D sunxi_ecc_strengths_a10, .nstrengths =3D ARRAY_SIZE(sunxi_ecc_strengths_a10), + .max_ecc_steps =3D 16, .sram_size =3D 1024, }; =20 static const struct sunxi_nfc_caps sunxi_nfc_a23_caps =3D { .has_mdma =3D true, + .has_mbus_clk =3D false, .has_ecc_block_512 =3D true, .reg_io_data =3D NFC_REG_A23_IO_DATA, .reg_ecc_err_cnt =3D NFC_REG_A10_ECC_ERR_CNT, @@ -2262,9 +2399,34 @@ static const struct sunxi_nfc_caps sunxi_nfc_a23_cap= s =3D { .dma_maxburst =3D 8, .ecc_strengths =3D sunxi_ecc_strengths_a10, .nstrengths =3D ARRAY_SIZE(sunxi_ecc_strengths_a10), + .max_ecc_steps =3D 16, .sram_size =3D 1024, }; =20 +static const struct sunxi_nfc_caps sunxi_nfc_h616_caps =3D { + .has_mdma =3D false, // H6 supports only chained descriptors + .has_mbus_clk =3D true, + .reg_io_data =3D NFC_REG_A23_IO_DATA, + .reg_ecc_err_cnt =3D NFC_REG_H6_ECC_ERR_CNT, + .reg_user_data =3D NFC_REG_H6_USER_DATA, + .reg_user_data_len =3D NFC_REG_H6_USER_DATA_LEN, + .reg_spare_area =3D NFC_REG_H6_SPARE_AREA, + .reg_pat_id =3D NFC_REG_H6_PAT_ID, + .reg_pat_found =3D NFC_REG_H6_PAT_FOUND, + .random_en_mask =3D BIT(5), + .random_dir_mask =3D BIT(6), + .ecc_mode_mask =3D GENMASK(15, 8), + .ecc_err_mask =3D GENMASK(31, 0), + .pat_found_mask =3D GENMASK(31, 0), + .dma_maxburst =3D 8, + .ecc_strengths =3D sunxi_ecc_strengths_h6, + .nstrengths =3D ARRAY_SIZE(sunxi_ecc_strengths_h6), + .user_data_len_tab =3D sunxi_user_data_len_h6, + .nuser_data_tab =3D ARRAY_SIZE(sunxi_user_data_len_h6), + .max_ecc_steps =3D 32, + .sram_size =3D 8192, +}; + static const struct of_device_id sunxi_nfc_ids[] =3D { { .compatible =3D "allwinner,sun4i-a10-nand", @@ -2274,6 +2436,10 @@ static const struct of_device_id sunxi_nfc_ids[] =3D= { .compatible =3D "allwinner,sun8i-a23-nand-controller", .data =3D &sunxi_nfc_a23_caps, }, + { + .compatible =3D "allwinner,sun50i-h616-nand-controller", + .data =3D &sunxi_nfc_h616_caps, + }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, sunxi_nfc_ids); --=20 2.47.3