Skip to contentSkip to conversation

spi: add support for Mediatek SPI-NAND controller

PATCH Superseded Chuanhong Guo 5 participants 12 messages Apr 7, 2022 – Apr 11, 2022

Subsystems (6)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v4 cover spi: add support for Mediatek SPI-NAND controller

Mediatek has an extended version of their NAND Flash Interface which has a SPI-NAND mode. In this mode, the controller can perform 1-bit spi-mem ops for up-to 0xa0 bytes and typical SPI-NAND single, dual and quad IO page cache ops with 2-byte address. Additionally, the page cache ops can be performed with ECC and auto data formatting using the ECC engine of the controller.

This patchset implements support of this mode as a separated SPI-MEM driver with piplined ECC engine.

Changes since v1:
add a blank line between properties in dt binding doc

 rename ecc-engine to nand-ecc-engine for the generic properties

fix warnings/errors from the CI

Changes since v2:
use streamed DMA api to avoid an extra memory copy during read make ECC engine config a per-nand context
take user-requested ECC strength into account

Change since v3:
fix a missed ecc-engine rename in doc from v1

Chuanhong Guo (5):
mtd: nand: make mtk_ecc.c a separated module
spi: add driver for MTK SPI NAND Flash Interface
mtd: nand: mtk-ecc: also parse nand-ecc-engine if available
dt-bindings: spi: add binding doc for spi-mtk-snfi
arm64: dts: mediatek: add mtk-snfi for mt7622

 .../bindings/spi/mediatek,spi-mtk-snfi.yaml   |   88 +
 arch/arm64/boot/dts/mediatek/mt7622.dtsi      |   12 +
 drivers/mtd/nand/Kconfig                      |    7 +
 drivers/mtd/nand/Makefile                     |    1 +
 drivers/mtd/nand/{raw/mtk_ecc.c => ecc-mtk.c} |    8 +-
 drivers/mtd/nand/raw/Kconfig                  |    1 +
 drivers/mtd/nand/raw/Makefile                 |    2 +-
 drivers/mtd/nand/raw/mtk_nand.c               |    2 +-
 drivers/spi/Kconfig                           |   10 +
 drivers/spi/Makefile                          |    1 +
 drivers/spi/spi-mtk-snfi.c                    | 1442 +++++++++++++++++
 .../linux/mtd/nand-ecc-mtk.h                  |    0
 12 files changed, 1569 insertions(+), 5 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/spi/mediatek,spi-mtk-snfi.yaml
 rename drivers/mtd/nand/{raw/mtk_ecc.c => ecc-mtk.c} (98%)
 create mode 100644 drivers/spi/spi-mtk-snfi.c
 rename drivers/mtd/nand/raw/mtk_ecc.h => include/linux/mtd/nand-ecc-mtk.h (100%)
Signature · 1 line
2.35.1
#1 lore raw

PATCH v4 1/5 mtd: nand: make mtk_ecc.c a separated module

this code will be used in mediatek snfi spi-mem controller with pipelined ECC engine.

---

Change since v1:
actually make it a module instead of a part of nandcore.o
(ECC_MXIC probablly needs a similar fix.)

Change since v2: None
Change since v3: None

 drivers/mtd/nand/Kconfig                                   | 7 +++++++
 drivers/mtd/nand/Makefile                                  | 1 +
 drivers/mtd/nand/{raw/mtk_ecc.c => ecc-mtk.c}              | 3 +--
 drivers/mtd/nand/raw/Kconfig                               | 1 +
 drivers/mtd/nand/raw/Makefile                              | 2 +-
 drivers/mtd/nand/raw/mtk_nand.c                            | 2 +-
 .../nand/raw/mtk_ecc.h => include/linux/mtd/nand-ecc-mtk.h | 0
 7 files changed, 12 insertions(+), 4 deletions(-)
 rename drivers/mtd/nand/{raw/mtk_ecc.c => ecc-mtk.c} (99%)
 rename drivers/mtd/nand/raw/mtk_ecc.h => include/linux/mtd/nand-ecc-mtk.h (100%)
drivers/mtd/nand/Kconfig +7 -0
index 9b249826ef93..2f3e02ab72ed 100644
@@ -53,6 +53,13 @@ config MTD_NAND_ECC_MXIC
 	help
 	  This enables support for the hardware ECC engine from Macronix.
 
+config MTD_NAND_ECC_MEDIATEK
+	tristate "Mediatek hardware ECC engine"
+	depends on HAS_IOMEM
+	select MTD_NAND_ECC
+	help
+	  This enables support for the hardware ECC engine from Mediatek.
+
 endmenu
 
 endmenu
drivers/mtd/nand/Makefile +1 -0
index a4e6b7ae0614..19e1291ac4d5 100644
@@ -2,6 +2,7 @@
 
 nandcore-objs := core.o bbt.o
 obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
+obj-$(CONFIG_MTD_NAND_ECC_MEDIATEK) += ecc-mtk.o
 
 obj-y	+= onenand/
 obj-y	+= raw/
drivers/mtd/nand/ecc-mtk.c renamed from drivers/mtd/nand/raw/mtk_ecc.c +1 -2
similarity index 99%
rename from drivers/mtd/nand/raw/mtk_ecc.c
rename to drivers/mtd/nand/ecc-mtk.c
index 49ab3448b9b1..74ddaa46ba7c 100644
@@ -15,8 +15,7 @@
 #include <linux/of.h>
 #include <linux/of_platform.h>
 #include <linux/mutex.h>
-
-#include "mtk_ecc.h"
+#include <linux/mtd/nand-ecc-mtk.h>
 
 #define ECC_IDLE_MASK		BIT(0)
 #define ECC_IRQ_EN		BIT(0)
drivers/mtd/nand/raw/Kconfig +1 -0
index 9b078e78f3fa..8b6d7a515445 100644
@@ -374,6 +374,7 @@ config MTD_NAND_QCOM
 
 config MTD_NAND_MTK
 	tristate "MTK NAND controller"
+	depends on MTD_NAND_ECC_MEDIATEK
 	depends on ARCH_MEDIATEK || COMPILE_TEST
 	depends on HAS_IOMEM
 	help
drivers/mtd/nand/raw/Makefile +1 -1
index 88a566513c56..fa1d00120310 100644
@@ -48,7 +48,7 @@ obj-$(CONFIG_MTD_NAND_SUNXI)		+= sunxi_nand.o
 obj-$(CONFIG_MTD_NAND_HISI504)	        += hisi504_nand.o
 obj-$(CONFIG_MTD_NAND_BRCMNAND)		+= brcmnand/
 obj-$(CONFIG_MTD_NAND_QCOM)		+= qcom_nandc.o
-obj-$(CONFIG_MTD_NAND_MTK)		+= mtk_ecc.o mtk_nand.o
+obj-$(CONFIG_MTD_NAND_MTK)		+= mtk_nand.o
 obj-$(CONFIG_MTD_NAND_MXIC)		+= mxic_nand.o
 obj-$(CONFIG_MTD_NAND_TEGRA)		+= tegra_nand.o
 obj-$(CONFIG_MTD_NAND_STM32_FMC2)	+= stm32_fmc2_nand.o
drivers/mtd/nand/raw/mtk_nand.c +1 -1
index 66f04c693c87..d540454cbbdf 100644
@@ -17,7 +17,7 @@
 #include <linux/iopoll.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
-#include "mtk_ecc.h"
+#include <linux/mtd/nand-ecc-mtk.h>
 
 /* NAND controller register definition */
 #define NFI_CNFG		(0x00)
include/linux/mtd/nand-ecc-mtk.h renamed from drivers/mtd/nand/raw/mtk_ecc.h +0 -0
similarity index 100%
rename from drivers/mtd/nand/raw/mtk_ecc.h
rename to include/linux/mtd/nand-ecc-mtk.h
Signature · 1 line
2.35.1
#6 lore raw

PATCH v4 2/5 spi: add driver for MTK SPI NAND Flash Interface

In reply to Chuanhong Guo

This driver implements support for the SPI-NAND mode of MTK NAND Flash Interface as a SPI-MEM controller with piplined ECC capability.

---

Change since v1:
fix CI warnings

Changes since v2:
use streamed DMA api to avoid an extra memory copy during read make ECC engine config a per-nand context
take user-requested ECC strength into account

Change since v3: none

 drivers/spi/Kconfig        |   10 +
 drivers/spi/Makefile       |    1 +
 drivers/spi/spi-mtk-snfi.c | 1442 ++++++++++++++++++++++++++++++++++++
 3 files changed, 1453 insertions(+)
 create mode 100644 drivers/spi/spi-mtk-snfi.c
drivers/spi/Kconfig +10 -0
index d2815eb361c0..739eec7d0c15 100644
@@ -590,6 +590,16 @@ config SPI_MTK_NOR
 	  SPI interface as well as several SPI NOR specific instructions
 	  via SPI MEM interface.
 
+config SPI_MTK_SNFI
+	tristate "MediaTek SPI NAND Flash Interface"
+	depends on ARCH_MEDIATEK || COMPILE_TEST
+	depends on MTD_NAND_ECC_MEDIATEK
+	help
+	  This enables support for SPI-NAND mode on the MediaTek NAND
+	  Flash Interface found on MediaTek ARM SoCs. This controller
+	  is implemented as a SPI-MEM controller with pipelined ECC
+	  capcability.
+
 config SPI_NPCM_FIU
 	tristate "Nuvoton NPCM FLASH Interface Unit"
 	depends on ARCH_NPCM || COMPILE_TEST
drivers/spi/Makefile +1 -0
index 3aa28ed3f761..51541ff17e67 100644
@@ -76,6 +76,7 @@ obj-$(CONFIG_SPI_MPC52xx)		+= spi-mpc52xx.o
 obj-$(CONFIG_SPI_MT65XX)                += spi-mt65xx.o
 obj-$(CONFIG_SPI_MT7621)		+= spi-mt7621.o
 obj-$(CONFIG_SPI_MTK_NOR)		+= spi-mtk-nor.o
+obj-$(CONFIG_SPI_MTK_SNFI)		+= spi-mtk-snfi.o
 obj-$(CONFIG_SPI_MXIC)			+= spi-mxic.o
 obj-$(CONFIG_SPI_MXS)			+= spi-mxs.o
 obj-$(CONFIG_SPI_NPCM_FIU)		+= spi-npcm-fiu.o
drivers/spi/spi-mtk-snfi.c new file +1442 -0

1,442 lines not on this page · raw message

Signature · 1 line
2.35.1
#7 lore raw

PATCH v4 3/5 mtd: nand: mtk-ecc: also parse nand-ecc-engine if available

In reply to Chuanhong Guo

The recently added ECC engine support introduced a generic property named nand-ecc-engine for ecc engine phandle. This patch adds support for this new property.

---
Change since v1:
new patch
Change since v2: none
Change since v3: none

 drivers/mtd/nand/ecc-mtk.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/mtd/nand/ecc-mtk.c +4 -1
index 74ddaa46ba7c..9f9b201fe706 100644
@@ -279,7 +279,10 @@ struct mtk_ecc *of_mtk_ecc_get(struct device_node *of_node)
 	struct mtk_ecc *ecc = NULL;
 	struct device_node *np;
 
-	np = of_parse_phandle(of_node, "ecc-engine", 0);
+	np = of_parse_phandle(of_node, "nand-ecc-engine", 0);
+	/* for backward compatibility */
+	if (!np)
+		np = of_parse_phandle(of_node, "ecc-engine", 0);
 	if (np) {
 		ecc = mtk_ecc_get(np);
 		of_node_put(np);
Signature · 1 line
2.35.1
#8 lore raw

PATCH v4 4/5 dt-bindings: spi: add binding doc for spi-mtk-snfi

In reply to Chuanhong Guo

Add device-tree binding documentation for Mediatek SPI-NAND Flash Interface.

---

Changes since v1:
1. add a blank line between properties in dt binding doc
2. rename ecc-engine to nand-ecc-engine for the generic properties

Change since v2: none
Change since v3: fix a missing rename in v1

 .../bindings/spi/mediatek,spi-mtk-snfi.yaml   | 88 +++++++++++++++++++
 1 file changed, 88 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/mediatek,spi-mtk-snfi.yaml
Documentation/devicetree/bindings/spi/mediatek,spi-mtk-snfi.yaml new file +88 -0
new file mode 100644
index 000000000000..686b69e4924c
@@ -0,0 +1,88 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/spi/mediatek,spi-mtk-snfi.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: SPI-NAND flash controller for MediaTek ARM SoCs
+
+maintainers:
+  - Chuanhong Guo <[email protected]>
+
+description: |
+  The Mediatek SPI-NAND flash controller is an extended version of
+  the Mediatek NAND flash controller. It can perform standard SPI
+  instructions with one continuous write and one read for up-to 0xa0
+  bytes. It also supports typical SPI-NAND page cache operations
+  in single, dual or quad IO mode with piplined ECC encoding/decoding
+  using the accompanying ECC engine. There should be only one spi
+  slave device following generic spi bindings.
+
+allOf:
+  - $ref: /schemas/spi/spi-controller.yaml#
+
+properties:
+  compatible:
+    enum:
+      - mediatek,mt7622-snand
+      - mediatek,mt7629-snand
+
+  reg:
+    items:
+      - description: core registers
+
+  interrupts:
+    items:
+      - description: NFI interrupt
+
+  clocks:
+    items:
+      - description: clock used for the controller
+      - description: clock used for the SPI bus
+
+  clock-names:
+    items:
+      - const: nfi_clk
+      - const: pad_clk
+
+  nand-ecc-engine:
+    description: device-tree node of the accompanying ECC engine.
+    $ref: /schemas/types.yaml#/definitions/phandle
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - nand-ecc-engine
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/mt7622-clk.h>
+    soc {
+      #address-cells = <2>;
+      #size-cells = <2>;
+      snfi: spi@1100d000 {
+        compatible = "mediatek,mt7622-snand";
+        reg = <0 0x1100d000 0 0x1000>;
+        interrupts = <GIC_SPI 96 IRQ_TYPE_LEVEL_LOW>;
+        clocks = <&pericfg CLK_PERI_NFI_PD>, <&pericfg CLK_PERI_SNFI_PD>;
+        clock-names = "nfi_clk", "pad_clk";
+        nand-ecc-engine = <&bch>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        flash@0 {
+          compatible = "spi-nand";
+          reg = <0>;
+          spi-tx-bus-width = <4>;
+          spi-rx-bus-width = <4>;
+          nand-ecc-engine = <&snfi>;
+        };
+      };
+    };
Signature · 1 line
2.35.1
#10 lore raw

PATCH v4 5/5 arm64: dts: mediatek: add mtk-snfi for mt7622

In reply to Chuanhong Guo

This patch adds a device-tree node for the MTK SPI-NAND Flash Interface for MT7622 device tree.

---
Changes since v1:
1. use the newly introduced nand-ecc-engine instead
2. reword commit message
Change since v2: none
Change since v3: none

 arch/arm64/boot/dts/mediatek/mt7622.dtsi | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/arm64/boot/dts/mediatek/mt7622.dtsi +12 -0
index 6f8cb3ad1e84..4b8f7dc1ec23 100644
@@ -545,6 +545,18 @@ nandc: nfi@1100d000 {
 		status = "disabled";
 	};
 
+	snfi: spi@1100d000 {
+		compatible = "mediatek,mt7622-snand";
+		reg = <0 0x1100d000 0 0x1000>;
+		interrupts = <GIC_SPI 96 IRQ_TYPE_LEVEL_LOW>;
+		clocks = <&pericfg CLK_PERI_NFI_PD>, <&pericfg CLK_PERI_SNFI_PD>;
+		clock-names = "nfi_clk", "pad_clk";
+		nand-ecc-engine = <&bch>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+		status = "disabled";
+	};
+
 	bch: ecc@1100e000 {
 		compatible = "mediatek,mt7622-ecc";
 		reg = <0 0x1100e000 0 0x1000>;
Signature · 1 line
2.35.1
Reviewed-by on v4 4/5
#9 lore raw

Re: [PATCH v4 4/5] dt-bindings: spi: add binding doc for spi-mtk-snfi

In reply to Chuanhong Guo
Quoted 6 lines · Chuanhong Guo

Add device-tree binding documentation for Mediatek SPI-NAND Flash Interface.

---

Looks good. The subject should be rather "spi: dt-bindings:" (as requirement for SPI subsystem).

Best regards,
Krzysztof

Tested-by on the v4 series
#11 lore raw
In reply to Chuanhong Guo
Quoted 9 lines · Chuanhong Guo

Mediatek has an extended version of their NAND Flash Interface which has a SPI-NAND mode. In this mode, the controller can perform 1-bit spi-mem ops for up-to 0xa0 bytes and typical SPI-NAND single, dual and quad IO page cache ops with 2-byte address. Additionally, the page cache ops can be performed with ECC and auto data formatting using the ECC engine of the controller.

This patchset implements support of this mode as a separated SPI-MEM driver with piplined ECC engine.

              ^^^^^^^^

missing 'e': pipelined

For the whole series:

Quoted 47 lines

Changes since v1:
add a blank line between properties in dt binding doc

 rename ecc-engine to nand-ecc-engine for the generic properties

fix warnings/errors from the CI

Changes since v2:
use streamed DMA api to avoid an extra memory copy during read make ECC engine config a per-nand context
take user-requested ECC strength into account

Change since v3:
fix a missed ecc-engine rename in doc from v1

Chuanhong Guo (5):
mtd: nand: make mtk_ecc.c a separated module
spi: add driver for MTK SPI NAND Flash Interface
mtd: nand: mtk-ecc: also parse nand-ecc-engine if available
dt-bindings: spi: add binding doc for spi-mtk-snfi
arm64: dts: mediatek: add mtk-snfi for mt7622

 .../bindings/spi/mediatek,spi-mtk-snfi.yaml   |   88 +
 arch/arm64/boot/dts/mediatek/mt7622.dtsi      |   12 +
 drivers/mtd/nand/Kconfig                      |    7 +
 drivers/mtd/nand/Makefile                     |    1 +
 drivers/mtd/nand/{raw/mtk_ecc.c => ecc-mtk.c} |    8 +-
 drivers/mtd/nand/raw/Kconfig                  |    1 +
 drivers/mtd/nand/raw/Makefile                 |    2 +-
 drivers/mtd/nand/raw/mtk_nand.c               |    2 +-
 drivers/spi/Kconfig                           |   10 +
 drivers/spi/Makefile                          |    1 +
 drivers/spi/spi-mtk-snfi.c                    | 1442 +++++++++++++++++
 .../linux/mtd/nand-ecc-mtk.h                  |    0
 12 files changed, 1569 insertions(+), 5 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/spi/mediatek,spi-mtk-snfi.yaml
 rename drivers/mtd/nand/{raw/mtk_ecc.c => ecc-mtk.c} (98%)
 create mode 100644 drivers/spi/spi-mtk-snfi.c
 rename drivers/mtd/nand/raw/mtk_ecc.h => include/linux/mtd/nand-ecc-mtk.h (100%)
Signature · 7 lines
2.35.1


_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
maintainer
#2 lore raw

Re: [PATCH v4 1/5] mtd: nand: make mtk_ecc.c a separated module

In reply to Chuanhong Guo

Hi Chuanhong,

[email protected] wrote on Thu, 7 Apr 2022 23:06:48 +0800:

Quoted 9 lines

this code will be used in mediatek snfi spi-mem controller with pipelined ECC engine.

---

Change since v1:
actually make it a module instead of a part of nandcore.o
(ECC_MXIC probablly needs a similar fix.)

Please do not hesitate to propose something about it.

Otherwise on the MTD side the series looks good (besides the two comments you already received).

I don't know if something changed regarding the comments style in the spi subsystem, but using // everywhere looks strange, it's usually reserved for the SPDX tag, but I'll let Mark comment on it.

Otherwise, MTD patches 1 and 3 look fine.

Thanks,
Miquèl

maintainer
#3 lore raw

Re: [PATCH v4 1/5] mtd: nand: make mtk_ecc.c a separated module

Quoted 2 lines · Miquel Raynal

Otherwise on the MTD side the series looks good (besides the two comments you already received).

What's the plan for merging then?

Quoted 3 lines

I don't know if something changed regarding the comments style in the spi subsystem, but using // everywhere looks strange, it's usually reserved for the SPDX tag, but I'll let Mark comment on it.

I generally request that, it looks messy if the comment block at the top mixes styles.

#4 lore raw

Re: [PATCH v4 1/5] mtd: nand: make mtk_ecc.c a separated module

Hi Mark!

Quoted 7 lines · Mark Brown
Quoted 2 lines · Miquel Raynal

Otherwise on the MTD side the series looks good (besides the two comments you already received).

What's the plan for merging then?

I just tested this driver on a different chip and found out it's buggy there. I'm still debugging.
Please wait for v5 of this series. Sorry.

Signature · 2 lines
Regards,
Chuanhong Guo
maintainer
#5 lore raw

Re: [PATCH v4 1/5] mtd: nand: make mtk_ecc.c a separated module

Hi Mark,

[email protected] wrote on Sat, 9 Apr 2022 19:08:57 +0800:

Quoted 6 lines

Hi Mark!

Quoted 3 lines · Mark Brown

On Fri, Apr 08, 2022 at 08:32:14AM +0200, Miquel Raynal wrote:

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Otherwise on the MTD side the series looks good (besides the two comments you already received).

What's the plan for merging then?

I just tested this driver on a different chip and found out it's buggy there. I'm still debugging.
Please wait for v5 of this series. Sorry.

We need to merge this series in an immutable branch. Perhaps as the big "part" is the SPI controller driver, it should preferably go through spi, but I'm fine either ways, let me know what you prefer.

Thanks,
Miquèl