Add support for the Airoha EN7523 SPI controller
Subsystems (2)
v2 cover Add support for the Airoha EN7523 SPI controller
This driver will likely also work on other Airoha SoCs, but this will need testing. Only basic single- and dual-bit transfers are supported for now, with DMA mode support yet to come.
v2:
- Drop clock name
- Make driver callbacks static, as reported by the bot
- Syntax fixes in DT binding docs
Bert Vermeulen (3):
dt-bindings: arm: airoha: Add documentation for Airoha SPI controller
spi: Add support for the Airoha EN7523 SoC SPI controller
ARM: dts: en7523: Add SPI node
.../bindings/spi/airoha,en7523-spi.yaml | 45 +++ arch/arm/boot/dts/en7523-evb.dts | 20 ++ arch/arm/boot/dts/en7523.dtsi | 10 + drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/spi-en7523.c | 305 ++++++++++++++++++ 6 files changed, 388 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/airoha,en7523-spi.yaml create mode 100644 drivers/spi/spi-en7523.c
Signature · 1 line
2.25.1
PATCH v2 1/3 dt-bindings: arm: airoha: Add documentation for Airoha SPI controller
Create documentation for accessing the Airoha EN7523 SPI controller.
--- .../bindings/spi/airoha,en7523-spi.yaml | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/airoha,en7523-spi.yaml
Documentation/devicetree/bindings/spi/airoha,en7523-spi.yaml new file +45 -0
@@ -0,0 +1,45 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/spi/airoha,en7523-spi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha EN7523 SPI controller + +maintainers: + - Bert Vermeulen <[email protected]> + +description: | + This binding describes the SPI controller on Airoha EN7523 SoCs. + +allOf: + - $ref: spi-controller.yaml# + +properties: + compatible: + items: + - const: airoha,en7523-spi + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + +required: + - compatible + - reg + - clocks + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/clock/en7523-clk.h> + spi0: spi@1fa10000 { + compatible = "airoha,en7523-spi"; + reg = <0x1fa10000 0x10000>; + clocks = <&scu EN7523_CLK_SPI>; + #address-cells = <1>; + #size-cells = <0>; + };
Signature · 1 line
2.25.1
Re: [PATCH v2 1/3] dt-bindings: arm: airoha: Add documentation for Airoha SPI controller
Quoted 8 lines · Bert Vermeulen
Create documentation for accessing the Airoha EN7523 SPI controller.
Signed-off-by Bert Vermeulen <[email protected]>--- .../bindings/spi/airoha,en7523-spi.yaml | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/airoha,en7523-spi.yaml
Re: [PATCH v2 1/3] dt-bindings: arm: airoha: Add documentation for Airoha SPI controller
In reply to Bert VermeulenQuoted 3 lines · Bert Vermeulen
Create documentation for accessing the Airoha EN7523 SPI controller.
Signed-off-by Bert Vermeulen <[email protected]>
Use subject prefixes matching the subsystem (git log --oneline -- ...).
Quoted 21 lines
--- .../bindings/spi/airoha,en7523-spi.yaml | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/airoha,en7523-spi.yamlDocumentation/devicetree/bindings/spi/airoha,en7523-spi.yaml new file +10
-0@@ -0,0 +1,45 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/spi/airoha,en7523-spi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha EN7523 SPI controller + +maintainers: + - Bert Vermeulen <[email protected]>
Documentation/devicetree/bindings/spi/airoha,en7523-spi.yaml line 20
Quoted 10 lines
Documentation/devicetree/bindings/spi/airoha,en7523-spi.yaml new file +10
-0+ +description: | + This binding describes the SPI controller on Airoha EN7523 SoCs. + +allOf: + - $ref: spi-controller.yaml# + +properties: + compatible: + items:
Drop "items:" and leading hyphen from line below.
Documentation/devicetree/bindings/spi/airoha,en7523-spi.yaml line 21
Quoted 1 line
Documentation/devicetree/bindings/spi/airoha,en7523-spi.yaml new file +1
-0+ - const: airoha,en7523-spi
Best regards,
Krzysztof
PATCH v2 2/3 spi: Add support for the Airoha EN7523 SoC SPI controller
In reply to Bert VermeulenThis SPI driver primarily drives the SoC-internal state machine doing the actual transfers. This allows transfers to be transparently queued in hardware.
DMA mode is not yet supported.
--- drivers/spi/Kconfig | 7 + drivers/spi/Makefile | 1 + drivers/spi/spi-en7523.c | 305 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 313 insertions(+) create mode 100644 drivers/spi/spi-en7523.c
drivers/spi/Kconfig +7 -0
@@ -57,6 +57,13 @@ config SPI_MEM comment "SPI Master Controller Drivers" +config SPI_AIROHA_EN7523 + bool "Airoha EN7523 SPI controller support" + depends on ARCH_AIROHA + default ARCH_AIROHA + help + This enables SPI controller support for the Airoha EN7523 SoC. + config SPI_ALTERA tristate "Altera SPI Controller platform driver" select SPI_ALTERA_CORE
drivers/spi/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_SPI_SPIDEV) += spidev.o obj-$(CONFIG_SPI_LOOPBACK_TEST) += spi-loopback-test.o # SPI master controller drivers (bus) +obj-$(CONFIG_SPI_AIROHA_EN7523) += spi-en7523.o obj-$(CONFIG_SPI_ALTERA) += spi-altera-platform.o obj-$(CONFIG_SPI_ALTERA_CORE) += spi-altera-core.o obj-$(CONFIG_SPI_ALTERA_DFL) += spi-altera-dfl.o
drivers/spi/spi-en7523.c new file +305 -0
305 lines not on this page · raw message
Signature · 1 line
2.25.1
Mark Brown
maintainerRe: [PATCH v2 2/3] spi: Add support for the Airoha EN7523 SoC SPI controller
drivers/spi/Kconfig config SPI_MEM · line 61
Quoted 3 lines · Bert Vermeulen
drivers/spi/Kconfig +2
-0+config SPI_AIROHA_EN7523 + bool "Airoha EN7523 SPI controller support"
Why not tristate?
drivers/spi/Kconfig config SPI_MEM · line 62
Quoted 1 line
drivers/spi/Kconfig +1
-0+ depends on ARCH_AIROHA
I don't see a reason we couldn't have an || COMPILE_TEST here to improve coverage?
drivers/spi/Kconfig config SPI_MEM · line 63
Quoted 1 line
drivers/spi/Kconfig +1
-0+ default ARCH_AIROHA
It's unusual to default a SPI controller on, they tend not to be ultra critical like a clock driver or similar can be?
Quoted 1 line
+static void
__iomem*iobase;
This should be driver data rather than a global, your current SoC might only have one controller but some other model might build two and it's fairly trivial to do.
drivers/spi/spi-en7523.c line 72
Quoted 10 lines
drivers/spi/spi-en7523.c new file +10
-0+static void opfifo_write (u32 cmd,u32 len) +{ +u32 tmp = ((cmd &0x1f ) <<9 ) | (len &0x1ff ); + +writel (tmp,REG (ENSPI_MANUAL_OPFIFO_WDATA )); + +/* Wait for room in OPFIFO */ +while (readl (REG (ENSPI_MANUAL_OPFIFO_FULL ))) +cpu_relax (); +
Some sort of timeout would be good with these loops, if things go wrong we'll just lock up which isn't good.
drivers/spi/spi-en7523.c line 156
Quoted 3 lines
drivers/spi/spi-en7523.c new file +3
-0+ ret =clk_prepare_enable (clk); +if (ret) +return ret;
Nothing ever reverses this unless clk_set_rate() fails.
drivers/spi/spi-en7523.c line 162
Quoted 5 lines
drivers/spi/spi-en7523.c new file +5
-0+ ret =clk_set_rate (clk,40000000 ); +if (ret) { +clk_disable_unprepare (clk); +return ret; + }
Could this be pushed into DT via the clock bindings? The hard coded number might need to vary by SoC.
drivers/spi/spi-en7523.c line 179
Quoted 13 lines
drivers/spi/spi-en7523.c new file +13
-0+static int xfer_read (struct spi_transfer *xfer) +{ +int opcode; +uint8_t *buf = xfer->rx_buf; + +switch (xfer->rx_nbits) { +case SPI_NBITS_SINGLE : + opcode =OP_INS ; +break ; +case SPI_NBITS_DUAL : + opcode =OP_IND ; +break ; + }
This should have a default case that returns an error.
drivers/spi/spi-en7523.c line 230
Quoted 7 lines
drivers/spi/spi-en7523.c new file +7
-0+static int transfer_one_message (struct spi_controller *ctrl,struct spi_message *msg) +{ +struct spi_transfer *xfer; +int next_xfer_is_rx =0 ; + +manual_begin_cmd (); +set_cs (0 );
The driver should not be setting chip select itself, it should just provide the set_cs() operation to the core and let the core worry about when to call it.
drivers/spi/spi-en7523.c line 282
Quoted 6 lines
drivers/spi/spi-en7523.c new file +6
-0+ ctrl->transfer_one_message = transfer_one_message; + err =devm_spi_register_controller (&pdev->dev, ctrl); +if (err) { +dev_err (&pdev->dev,"Could not register SPI controller\n" ); +return -ENODEV ; + }
Don't discard the error code that registeration returned, include it in the log message and pass it back to the caller.
Re: [PATCH v2 2/3] spi: Add support for the Airoha EN7523 SoC SPI controller
On 9/27/22 14:23, Mark Brown wrote:
Hi Mark,
Thanks for reviewing.
Quoted 8 lines · Bert Vermeulen
drivers/spi/Kconfig config SPI_MEM · line 61
Quoted 4 lines
drivers/spi/Kconfig +2
-0+config SPI_AIROHA_EN7523 + bool "Airoha EN7523 SPI controller support"Why not tristate?
Quoted 6 lines
drivers/spi/Kconfig config SPI_MEM · line 62
Quoted 1 line
drivers/spi/Kconfig +1
-0+ depends on ARCH_AIROHAI don't see a reason we couldn't have an ||
COMPILE_TESThere to improve coverage?drivers/spi/Kconfig config SPI_MEM · line 63
Quoted 1 line
drivers/spi/Kconfig +1
-0+ default ARCH_AIROHA
In both cases, because SPi boot flash is the only way to boot this SoC that I know of. However as you say this may not be the case on different SoCs, and indeed I believe this SPI core is in lots of stuff already.
So I'll fix this, and also address your other comments.
Quoted 75 lines
It's unusual to default a SPI controller on, they tend not to be ultra critical like a clock driver or similar can be?
Quoted 1 line
+static void
__iomem*iobase;This should be driver data rather than a global, your current SoC might only have one controller but some other model might build two and it's fairly trivial to do.
drivers/spi/spi-en7523.c line 72
Quoted 10 lines
drivers/spi/spi-en7523.c new file +10
-0+static void opfifo_write (u32 cmd,u32 len) +{ +u32 tmp = ((cmd &0x1f ) <<9 ) | (len &0x1ff ); + +writel (tmp,REG (ENSPI_MANUAL_OPFIFO_WDATA )); + +/* Wait for room in OPFIFO */ +while (readl (REG (ENSPI_MANUAL_OPFIFO_FULL ))) +cpu_relax (); +Some sort of timeout would be good with these loops, if things go wrong we'll just lock up which isn't good.
drivers/spi/spi-en7523.c line 156
Quoted 3 lines
drivers/spi/spi-en7523.c new file +3
-0+ ret =clk_prepare_enable (clk); +if (ret) +return ret;Nothing ever reverses this unless
clk_set_rate()fails.drivers/spi/spi-en7523.c line 162
Quoted 5 lines
drivers/spi/spi-en7523.c new file +5
-0+ ret =clk_set_rate (clk,40000000 ); +if (ret) { +clk_disable_unprepare (clk); +return ret; + }Could this be pushed into DT via the clock bindings? The hard coded number might need to vary by SoC.
drivers/spi/spi-en7523.c line 179
Quoted 13 lines
drivers/spi/spi-en7523.c new file +13
-0+static int xfer_read (struct spi_transfer *xfer) +{ +int opcode; +uint8_t *buf = xfer->rx_buf; + +switch (xfer->rx_nbits) { +case SPI_NBITS_SINGLE : + opcode =OP_INS ; +break ; +case SPI_NBITS_DUAL : + opcode =OP_IND ; +break ; + }This should have a default case that returns an error.
drivers/spi/spi-en7523.c line 230
Quoted 7 lines
drivers/spi/spi-en7523.c new file +7
-0+static int transfer_one_message (struct spi_controller *ctrl,struct spi_message *msg) +{ +struct spi_transfer *xfer; +int next_xfer_is_rx =0 ; + +manual_begin_cmd (); +set_cs (0 );The driver should not be setting chip select itself, it should just provide the
set_cs()operation to the core and let the core worry about when to call it.drivers/spi/spi-en7523.c line 282
Quoted 6 lines
drivers/spi/spi-en7523.c new file +6
-0+ ctrl->transfer_one_message = transfer_one_message; + err =devm_spi_register_controller (&pdev->dev, ctrl); +if (err) { +dev_err (&pdev->dev,"Could not register SPI controller\n" ); +return -ENODEV ; + }Don't discard the error code that registeration returned, include it in the log message and pass it back to the caller.
Signature · 2 lines
Bert Vermeulen [email protected]
PATCH v2 3/3 ARM: dts: en7523: Add SPI node
In reply to Bert VermeulenThis adds an SPI node for the EN7523, so far only used for hooking up the NAND boot flash.
--- arch/arm/boot/dts/en7523-evb.dts | 20 ++++++++++++++++++++ arch/arm/boot/dts/en7523.dtsi | 10 ++++++++++ 2 files changed, 30 insertions(+)
arch/arm/boot/dts/en7523-evb.dts +20 -0
@@ -26,6 +26,26 @@ memory@80000000 { }; }; +&spi0 { + nand: nand@0 { + compatible = "spi-nand"; + reg = <0>; + nand-ecc-engine = <&nand>; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@0 { + label = "u-boot"; + reg = <0x0 0x80000>; + read-only; + }; + }; + }; +}; + &gpio0 { status = "okay"; };
arch/arm/boot/dts/en7523.dtsi +10 -0
@@ -201,4 +201,14 @@ pcie_intc1: interrupt-controller { #interrupt-cells = <1>; }; }; + + spi0: spi@1fa10000 { + compatible = "airoha,en7523-spi"; + reg = <0x1fa10000 0x10000>; + #address-cells = <1>; + #size-cells = <0>; + clocks = <&scu EN7523_CLK_SPI>; + spi-rx-bus-width = <2>; + spi-tx-bus-width = <2>; + }; };
Signature · 1 line
2.25.1