rewrite mtk-quadspi spi-nor driver with spi-mem
Subsystems (5)
v2 cover rewrite mtk-quadspi spi-nor driver with spi-mem
This patchset adds a spi-mem driver for Mediatek SPI-NOR controller, which already has limited support by mtk-quadspi. This new driver can make use of full quadspi capability of this controller.
1st new commit makes spi-max-frequency optional to match current binding doc and make this new driver compatible with old driver dt bindings.
Changes since v1:
two new commits.
Chuanhong Guo (4):
spi: make spi-max-frequency optional
spi: add support for mediatek spi-nor controller
dt-bindings: convert mtk-quadspi binding doc for spi-mtk-nor
mtd: spi-nor: remove mtk-quadspi driver
.../mtk-quadspi.txt => spi/spi-mtk-nor.txt} | 34 +-
drivers/mtd/spi-nor/Kconfig | 8 -
drivers/mtd/spi-nor/Makefile | 1 -
drivers/mtd/spi-nor/mtk-quadspi.c | 565 --------------
drivers/spi/Kconfig | 10 +
drivers/spi/Makefile | 1 +
drivers/spi/spi-mtk-nor.c | 689 ++++++++++++++++++
drivers/spi/spi.c | 9 +-
8 files changed, 717 insertions(+), 600 deletions(-)
rename Documentation/devicetree/bindings/{mtd/mtk-quadspi.txt => spi/spi-mtk-nor.txt} (62%)
delete mode 100644 drivers/mtd/spi-nor/mtk-quadspi.c
create mode 100644 drivers/spi/spi-mtk-nor.cSignature · 1 line
2.24.1
PATCH v2 1/4 spi: make spi-max-frequency optional
We only need a spi-max-frequency when we specifically request a spi frequency lower than the max speed of spi host.
This property is already documented as optional property and current host drivers are implemented to operate at highest speed possible when spi->max_speed_hz is 0.
This patch makes spi-max-frequency an optional property so that we could just omit it to use max controller speed.
---
Change since v1:
new commit
drivers/spi/spi.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/spi/spi.c +2 -7
@@ -1955,13 +1955,8 @@ static int of_spi_parse_dt(struct spi_controller *ctlr, struct spi_device *spi, spi->mode |=SPI_CS_HIGH ;/* Device speed */ - rc =of_property_read_u32 (nc,"spi-max-frequency" , &value); -if (rc) { -dev_err (&ctlr->dev, -"%pOF has no valid 'spi-max-frequency' property (%d)\n" , nc, rc); -return rc; - } - spi->max_speed_hz = value; +if (!of_property_read_u32 (nc,"spi-max-frequency" , &value)) + spi->max_speed_hz = value;return 0 ; }
Signature · 1 line
2.24.1
PATCH v2 2/4 spi: add support for mediatek spi-nor controller
In reply to Chuanhong GuoThis is a driver for mtk spi-nor controller using spi-mem interface. The same controller already has limited support provided by mtk-quadspi driver under spi-nor framework and this new driver is a replacement for the old one.
Comparing to the old driver, this driver has following advantages:
1. It can handle any full-duplex spi transfer up to 6 bytes, and this is implemented using generic spi interface.
2. It take account into command opcode properly. The reading routine in this controller can only use 0x03 or 0x0b as opcode on 1-1-1 transfers, but old driver doesn't implement this properly. This driver checks supported opcode explicitly and use (1) to perform unmatched operations.
3. It properly handles SFDP reading. Old driver can't read SFDP due to the bug mentioned in (2).
4. It can do 1-2-2 and 1-4-4 fast reading on spi-nor. These two ops requires parsing SFDP, which isn't possible in old driver. And the old driver is only flagged to support 1-1-2 mode.
5. It takes advantage of the DMA feature in this controller for long reads and supports IRQ on DMA requests to free cpu cycles from polling status registers on long DMA reading. It achieves up to 17.5MB/s reading speed (1-4-4 mode) which is way faster than the old one. IRQ is implemented as optional to maintain backward compatibility.
---
Change since v1:
none
drivers/spi/Kconfig | 10 + drivers/spi/Makefile | 1 + drivers/spi/spi-mtk-nor.c | 689 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 700 insertions(+) create mode 100644 drivers/spi/spi-mtk-nor.c
drivers/spi/Kconfig +10 -0
@@ -450,6 +450,16 @@ config SPI_MT7621 help This selects a driver for the MediaTek MT7621 SPI Controller. +config SPI_MTK_NOR + tristate "MediaTek SPI NOR controller" + depends on ARCH_MEDIATEK || COMPILE_TEST + help + This enables support for SPI NOR controller found on MediaTek + ARM SoCs. This is a controller specifically for SPI-NOR flash. + It can perform generic SPI transfers up to 6 bytes via generic + SPI interface as well as several SPI-NOR specific instructions + via SPI MEM interface. + config SPI_NPCM_FIU tristate "Nuvoton NPCM FLASH Interface Unit" depends on ARCH_NPCM || COMPILE_TEST
drivers/spi/Makefile +1 -0
@@ -64,6 +64,7 @@ obj-$(CONFIG_SPI_MPC52xx_PSC) += spi-mpc52xx-psc.o 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_MXIC) += spi-mxic.o obj-$(CONFIG_SPI_MXS) += spi-mxs.o obj-$(CONFIG_SPI_NPCM_FIU) += spi-npcm-fiu.o
drivers/spi/spi-mtk-nor.c new file +689 -0
689 lines not on this page · raw message
Signature · 1 line
2.24.1
PATCH v2 3/4 dt-bindings: convert mtk-quadspi binding doc for spi-mtk-nor
In reply to Chuanhong Guospi-mtk-nor is a driver to replace mtk-quadspi and they have almost the same device-tree bindings. Reuse this binding documentation and convert it for new driver:
1. "Mediatek SoCs" -> "Mediatek ARM SoCs" because MTK MIPS SoCs use different controllers.
2. document "interrupts" as a required property because it's available on all SoCs with this controller and new driver takes advantages of it. It's implemented as optional only to maintain backward compatibility.
3. replace binding example with a mt7629 one because this is the only one I know the interrupt assignment.
---
Change since v1:
none
.../mtk-quadspi.txt => spi/spi-mtk-nor.txt} | 34 ++++++++-----------
1 file changed, 15 insertions(+), 19 deletions(-)
rename Documentation/devicetree/bindings/{mtd/mtk-quadspi.txt => spi/spi-mtk-nor.txt} (62%)Documentation/devicetree/bindings/spi/spi-mtk-nor.txt renamed from Documentation/devicetree/bindings/mtd/mtk-quadspi.txt +15 -19
@@ -1,4 +1,4 @@ -* Serial NOR flash controller for MediaTek SoCs +* SPI NOR flash controller for MediaTek ARM SoCs Required properties: - compatible: For mt8173, compatible should be "mediatek,mt8173-nor",
@@ -13,6 +13,7 @@ Required properties: "mediatek,mt7629-nor", "mediatek,mt8173-nor" "mediatek,mt8173-nor" - reg: physical base address and length of the controller's register +- interrupts: Interrupt number used by the controller. - clocks: the phandle of the clocks needed by the nor controller - clock-names: the names of the clocks the clocks should be named "spi" and "sf". "spi" is used for spi bus,
@@ -22,29 +23,24 @@ Required properties: - #address-cells: should be <1> - #size-cells: should be <0> -The SPI flash must be a child of the nor_flash node and must have a -compatible property. Also see jedec,spi-nor.txt. - -Required properties: -- compatible: May include a device-specific string consisting of the manufacturer - and name of the chip. Must also include "jedec,spi-nor" for any - SPI NOR flash that can be identified by the JEDEC READ ID opcode (0x9F). -- reg : Chip-Select number +There should be only one spi slave device following generic spi bindings. +It's not recommended to use this controller for devices other than SPI NOR +flash due to limited transfer capability of this controller. Example: +#include <dt-bindings/interrupt-controller/irq.h> +#include <dt-bindings/interrupt-controller/arm-gic.h> +#include <dt-bindings/clock/mt7629-clk.h> -nor_flash: spi@1100d000 { - compatible = "mediatek,mt8173-nor"; - reg = <0 0x1100d000 0 0xe0>; - clocks = <&pericfg CLK_PERI_SPI>, - <&topckgen CLK_TOP_SPINFI_IFR_SEL>; +spi_nor: spi@11014000 { + compatible = "mediatek,mt7629-nor", + "mediatek,mt8173-nor"; + reg = <0x11014000 0xe0>; + interrupts = <GIC_SPI 88 IRQ_TYPE_LEVEL_LOW>; + clocks = <&pericfg CLK_PERI_FLASH_PD>, + <&topckgen CLK_TOP_FLASH_SEL>; clock-names = "spi", "sf"; #address-cells = <1>; #size-cells = <0>; - - flash@0 { - compatible = "jedec,spi-nor"; - reg = <0>; - }; };
Signature · 1 line
2.24.1
Rob Herring
maintainerRe: [PATCH v2 3/4] dt-bindings: convert mtk-quadspi binding doc for spi-mtk-nor
Quoted 4 lines · Chuanhong Guo
spi-mtk-nor is a driver to replace mtk-quadspi and they have almost the same device-tree bindings. Reuse this binding documentation and convert it for new driver:
Quoted 8 lines
1. "Mediatek SoCs" -> "Mediatek ARM SoCs" because MTK MIPS SoCs use different controllers.
2. document "interrupts" as a required property because it's available on all SoCs with this controller and new driver takes advantages of it. It's implemented as optional only to maintain backward compatibility.
3. replace binding example with a mt7629 one because this is the only one I know the interrupt assignment.
That doesn't really matter. It would be less churn without that change and examples are just examples.
Quoted 62 lines
Signed-off-by Chuanhong Guo <[email protected]>---
Change since v1:
none.../mtk-quadspi.txt => spi/spi-mtk-nor.txt} | 34 ++++++++----------- 1 file changed, 15 insertions(+), 19 deletions(-) rename Documentation/devicetree/bindings/{mtd/mtk-quadspi.txt => spi/spi-mtk-nor.txt} (62%)Documentation/devicetree/bindings/spi/spi-mtk-nor.txt renamed from Documentation/devicetree/bindings/mtd/mtk-quadspi.txt +13
-14@@ -1,4 +1,4 @@ -* Serial NOR flash controller for MediaTek SoCs +* SPI NOR flash controller for MediaTek ARM SoCs Required properties: - compatible: For mt8173, compatible should be "mediatek,mt8173-nor",@@ -13,6 +13,7 @@ Required properties: "mediatek,mt7629-nor", "mediatek,mt8173-nor" "mediatek,mt8173-nor" - reg: physical base address and length of the controller's register +- interrupts: Interrupt number used by the controller. - clocks: the phandle of the clocks needed by the nor controller - clock-names: the names of the clocks the clocks should be named "spi" and "sf". "spi" is used for spi bus,@@ -22,29 +23,24 @@ Required properties: - #address-cells: should be <1> - #size-cells: should be <0> -The SPI flash must be a child of the nor_flash node and must have a -compatible property. Also see jedec,spi-nor.txt. - -Required properties: -- compatible: May include a device-specific string consisting of the manufacturer - and name of the chip. Must also include "jedec,spi-nor" for any - SPI NOR flash that can be identified by the JEDEC READ ID opcode (0x9F). -- reg : Chip-Select number +There should be only one spi slave device following generic spi bindings. +It's not recommended to use this controller for devices other than SPI NOR +flash due to limited transfer capability of this controller. Example: +#include <dt-bindings/interrupt-controller/irq.h> +#include <dt-bindings/interrupt-controller/arm-gic.h> +#include <dt-bindings/clock/mt7629-clk.h> -nor_flash: spi@1100d000 { - compatible = "mediatek,mt8173-nor"; - reg = <0 0x1100d000 0 0xe0>; - clocks = <&pericfg CLK_PERI_SPI>, - <&topckgen CLK_TOP_SPINFI_IFR_SEL>; +spi_nor: spi@11014000 { + compatible = "mediatek,mt7629-nor", + "mediatek,mt8173-nor"; + reg = <0x11014000 0xe0>; + interrupts = <GIC_SPI 88 IRQ_TYPE_LEVEL_LOW>;
Documentation/devicetree/bindings/spi/spi-mtk-nor.txt Required properties: · line 48
Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-mtk-nor.txt renamed from Documentation/devicetree/bindings/mtd/mtk-quadspi.txt +2
-5+ clocks = <&pericfg CLK_PERI_FLASH_PD>, + <&topckgen CLK_TOP_FLASH_SEL>; clock-names = "spi", "sf"; #address-cells = <1>; #size-cells = <0>; - - flash@0 { - compatible = "jedec,spi-nor"; - reg = <0>; - };
Better to leave this in the example IMO.
Rob
Re: [PATCH v2 3/4] dt-bindings: convert mtk-quadspi binding doc for spi-mtk-nor
Quoted 12 lines · Rob Herring
Quoted 2 lines
3. replace binding example with a mt7629 one because this is the only one I know the interrupt assignment.
That doesn't really matter. It would be less churn without that change and examples are just examples.
[...]Documentation/devicetree/bindings/spi/spi-mtk-nor.txt Required properties: · line 48
Quoted 5 lines
Documentation/devicetree/bindings/spi/spi-mtk-nor.txt renamed from Documentation/devicetree/bindings/mtd/mtk-quadspi.txt +0
-5- - flash@0 { - compatible = "jedec,spi-nor"; - reg = <0>; - };
Quoted 3 lines
Better to leave this in the example IMO.
Rob
I'll revert example changes and add a dummy interrupt binding instead in v3.
Signature · 2 lines
Regards, Chuanhong Guo
PATCH v2 4/4 mtd: spi-nor: remove mtk-quadspi driver
In reply to Chuanhong GuoThis driver is superseded by the new spi-mtk-nor driver.
---
Change since v1:
new commit
drivers/mtd/spi-nor/Kconfig | 8 - drivers/mtd/spi-nor/Makefile | 1 - drivers/mtd/spi-nor/mtk-quadspi.c | 565 ------------------------------ 3 files changed, 574 deletions(-) delete mode 100644 drivers/mtd/spi-nor/mtk-quadspi.c
drivers/mtd/spi-nor/Kconfig +0 -8
@@ -52,14 +52,6 @@ config SPI_HISI_SFC help This enables support for HiSilicon FMC SPI-NOR flash controller. -config SPI_MTK_QUADSPI - tristate "MediaTek Quad SPI controller" - depends on HAS_IOMEM - help - This enables support for the Quad SPI controller in master mode. - This controller does not support generic SPI. It only supports - SPI NOR. - config SPI_NXP_SPIFI tristate "NXP SPI Flash Interface (SPIFI)" depends on OF && (ARCH_LPC18XX || COMPILE_TEST)
drivers/mtd/spi-nor/Makefile +0 -1
@@ -3,7 +3,6 @@ obj-$(CONFIG_MTD_SPI_NOR) += spi-nor.o obj-$(CONFIG_SPI_ASPEED_SMC) += aspeed-smc.o obj-$(CONFIG_SPI_CADENCE_QUADSPI) += cadence-quadspi.o obj-$(CONFIG_SPI_HISI_SFC) += hisi-sfc.o -obj-$(CONFIG_SPI_MTK_QUADSPI) += mtk-quadspi.o obj-$(CONFIG_SPI_NXP_SPIFI) += nxp-spifi.o obj-$(CONFIG_SPI_INTEL_SPI) += intel-spi.o obj-$(CONFIG_SPI_INTEL_SPI_PCI) += intel-spi-pci.o
drivers/mtd/spi-nor/mtk-quadspi.c deleted +0 -565
565 lines not on this page · raw message
Signature · 1 line
2.24.1