2022-04-24 19:25:24

by Chuanhong Guo

[permalink] [raw]
Subject: [PATCH v6 0/5] 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 pipelined 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

Changes since v4:
fix typo: piplined -> pipelined
fix missing OOB write in snfi driver
print page format with dev_dbg instead
replace uint*_t copied from vendor driver with u*

Changes since v5:
add missing nfi mode register configuration in probe
fix an off-by-one bug in mtk_snand_mac_io

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
spi: dt-bindings: 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 | 1470 +++++++++++++++++
.../linux/mtd/nand-ecc-mtk.h | 0
12 files changed, 1597 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%)

--
2.35.1


2022-04-24 20:18:21

by Chuanhong Guo

[permalink] [raw]
Subject: [PATCH v6 3/5] mtd: nand: mtk-ecc: also parse nand-ecc-engine if available

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.

Signed-off-by: Chuanhong Guo <[email protected]>
---
Change since v1:
new patch
Change in v2-v6: None

drivers/mtd/nand/ecc-mtk.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/nand/ecc-mtk.c b/drivers/mtd/nand/ecc-mtk.c
index 74ddaa46ba7c..9f9b201fe706 100644
--- a/drivers/mtd/nand/ecc-mtk.c
+++ b/drivers/mtd/nand/ecc-mtk.c
@@ -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);
--
2.35.1

2022-04-25 07:50:44

by Chuanhong Guo

[permalink] [raw]
Subject: [PATCH v6 4/5] spi: dt-bindings: add binding doc for spi-mtk-snfi

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

Signed-off-by: Chuanhong Guo <[email protected]>
Reviewed-by: Krzysztof Kozlowski <[email protected]>
---
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
Change since v4: fix typo: piplined -> pipelined
Change since v5: none

.../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

diff --git a/Documentation/devicetree/bindings/spi/mediatek,spi-mtk-snfi.yaml b/Documentation/devicetree/bindings/spi/mediatek,spi-mtk-snfi.yaml
new file mode 100644
index 000000000000..6e6e02c91780
--- /dev/null
+++ b/Documentation/devicetree/bindings/spi/mediatek,spi-mtk-snfi.yaml
@@ -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 pipelined 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>;
+ };
+ };
+ };
--
2.35.1

2022-04-27 11:37:22

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH v6 0/5] spi: add support for Mediatek SPI-NAND controller

Hi Mark,

[email protected] wrote on Sun, 24 Apr 2022 11:25:22 +0800:

> 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 pipelined ECC engine.


[...]

The patch actually look independent, so if it's fine for you I can take
the two mtd patches and let you merge the spi/binding changes.

Would this work for you?

> 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
> spi: dt-bindings: 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 | 1470 +++++++++++++++++
> .../linux/mtd/nand-ecc-mtk.h | 0
> 12 files changed, 1597 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%)
>


Thanks,
Miquèl

2022-04-27 13:39:09

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v6 0/5] spi: add support for Mediatek SPI-NAND controller

On Wed, Apr 27, 2022 at 11:28:57AM +0200, Miquel Raynal wrote:

> The patch actually look independent, so if it's fine for you I can take
> the two mtd patches and let you merge the spi/binding changes.

> Would this work for you?

That sounds great.


Attachments:
(No filename) (259.00 B)
signature.asc (499.00 B)
Download all attachments

2022-04-27 14:33:48

by Chuanhong Guo

[permalink] [raw]
Subject: Re: [PATCH v6 0/5] spi: add support for Mediatek SPI-NAND controller

Hi Miquel!

On Wed, Apr 27, 2022 at 5:29 PM Miquel Raynal <[email protected]> wrote:
>
> [...]
>
> The patch actually look independent, so if it's fine for you I can take
> the two mtd patches and let you merge the spi/binding changes.

Out of curiosity:
Wouldn't that break the build for spi subsystem? Because...

> > rename drivers/mtd/nand/raw/mtk_ecc.h => include/linux/mtd/nand-ecc-mtk.h (100%)

The spi driver needs this header file which is moved in the mtd patch.

--
Regards,
Chuanhong Guo

2022-04-27 14:41:46

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v6 0/5] spi: add support for Mediatek SPI-NAND controller

On Wed, Apr 27, 2022 at 10:04:57PM +0800, Chuanhong Guo wrote:
> On Wed, Apr 27, 2022 at 5:29 PM Miquel Raynal <[email protected]> wrote:

> > The patch actually look independent, so if it's fine for you I can take
> > the two mtd patches and let you merge the spi/binding changes.

> Out of curiosity:
> Wouldn't that break the build for spi subsystem? Because...

> > > rename drivers/mtd/nand/raw/mtk_ecc.h => include/linux/mtd/nand-ecc-mtk.h (100%)

> The spi driver needs this header file which is moved in the mtd patch.

Ah, that'll be an issue indeed - if I could get a signed tag with the
dependency in it I can go ahead with the SPI bits?


Attachments:
(No filename) (673.00 B)
signature.asc (499.00 B)
Download all attachments

2022-04-27 15:40:22

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH v6 0/5] spi: add support for Mediatek SPI-NAND controller

Hi Mark,

[email protected] wrote on Wed, 27 Apr 2022 15:13:42 +0100:

> On Wed, Apr 27, 2022 at 10:04:57PM +0800, Chuanhong Guo wrote:
> > On Wed, Apr 27, 2022 at 5:29 PM Miquel Raynal <[email protected]> wrote:
>
> > > The patch actually look independent, so if it's fine for you I can take
> > > the two mtd patches and let you merge the spi/binding changes.
>
> > Out of curiosity:
> > Wouldn't that break the build for spi subsystem? Because...
>
> > > > rename drivers/mtd/nand/raw/mtk_ecc.h => include/linux/mtd/nand-ecc-mtk.h (100%)
>
> > The spi driver needs this header file which is moved in the mtd patch.

Ah, yeah, right.

> Ah, that'll be an issue indeed - if I could get a signed tag with the
> dependency in it I can go ahead with the SPI bits?

Ok, I'll share an immutable tag.

Thanks,
Miquèl

2022-04-27 16:50:24

by Miquel Raynal

[permalink] [raw]
Subject: Re: [PATCH v6 0/5] spi: add support for Mediatek SPI-NAND controller

Hello,

[email protected] wrote on Wed, 27 Apr 2022 15:13:42 +0100:

> On Wed, Apr 27, 2022 at 10:04:57PM +0800, Chuanhong Guo wrote:
> > On Wed, Apr 27, 2022 at 5:29 PM Miquel Raynal <[email protected]> wrote:
>
> > > The patch actually look independent, so if it's fine for you I can take
> > > the two mtd patches and let you merge the spi/binding changes.
>
> > Out of curiosity:
> > Wouldn't that break the build for spi subsystem? Because...
>
> > > > rename drivers/mtd/nand/raw/mtk_ecc.h => include/linux/mtd/nand-ecc-mtk.h (100%)
>
> > The spi driver needs this header file which is moved in the mtd patch.
>
> Ah, that'll be an issue indeed - if I could get a signed tag with the
> dependency in it I can go ahead with the SPI bits?

I pulled the two patches, here is a tag with these patches for you,
Mark.

The following changes since commit 3123109284176b1532874591f7c81f3837bbdc17:

Linux 5.18-rc1 (2022-04-03 14:08:21 -0700)

are available in the Git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/mtd/linux.git tags/mtd/mtk-spi-nand-for-5.19

for you to fetch changes up to 4c5bf4b51c9857e20c5f5e9d74b86aa1bd1def40:

mtd: nand: mtk-ecc: also parse nand-ecc-engine if available (2022-04-27 18:12:43 +0200)

----------------------------------------------------------------
Mediatek ECC changes:
* Also parse the default nand-ecc-engine property if available
* Make mtk_ecc.c a separated module

----------------------------------------------------------------
Chuanhong Guo (2):
mtd: nand: make mtk_ecc.c a separated module
mtd: nand: mtk-ecc: also parse nand-ecc-engine if available

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/mtd/nand/raw/mtk_ecc.h => include/linux/mtd/nand-ecc-mtk.h | 0
7 files changed, 16 insertions(+), 5 deletions(-)
rename drivers/mtd/nand/{raw/mtk_ecc.c => ecc-mtk.c} (98%)
rename drivers/mtd/nand/raw/mtk_ecc.h => include/linux/mtd/nand-ecc-mtk.h (100%)

2022-04-27 22:37:29

by Mark Brown

[permalink] [raw]
Subject: Re: (subset) [PATCH v6 0/5] spi: add support for Mediatek SPI-NAND controller

On Sun, 24 Apr 2022 11:25:22 +0800, Chuanhong Guo wrote:
> 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.
>
> [...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[2/5] spi: add driver for MTK SPI NAND Flash Interface
commit: 764f1b7481645b2b4488eda26c4da7f331697e6b
[4/5] spi: dt-bindings: add binding doc for spi-mtk-snfi
commit: 69bb9b29bf67e850beece45e9c99ca707eac7e41

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark