Driver for AT91 USART in SPI mode
Subsystems (4)
cover Driver for AT91 USART in SPI mode
Hello,
I wrote this driver for USART IP that is found in AT91 and SAMA5 SoCs. The IP has an internal chip select, but is not used because is deasserted and asserted after every byte sent over the wires. Gpio chip selects are used instead of internal one. The driver works with actual USART nodes from device tree of boards, but compatible must be changed, SCK pin muxed and cs-gpio, size-cells and address-cells must be added. Of course, at the end of the wires must be an SPI slave linked, not a serial console. :)
I tested the driver on sama5d4-xplained and sama5d3-xplained and works without issues.
Radu Pirea (3):
MAINTAINERS: add usart spi driver
dt-bindings: add binding for at91-usart in spi mode
spi: at91-usart: add driver for at91-usart as spi
.../bindings/spi/microchip,at91-usart-spi.txt | 24 + MAINTAINERS | 7 + drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/spi-at91-usart.c | 545 ++++++++++++++++++ 5 files changed, 585 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/microchip,at91-usart-spi.txt create mode 100644 drivers/spi/spi-at91-usart.c
Signature · 1 line
2.17.0
PATCH 1/3 MAINTAINERS: add usart spi driver
Add entry for at91 usart spi driver.
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -9192,6 +9192,13 @@ S: Supported F: drivers/mtd/nand/raw/atmel/* F: Documentation/devicetree/bindings/mtd/atmel-nand.txt +MICROCHIP AT91 USART SPI DRIVER +M: Radu Pirea <[email protected]> +L: [email protected] +S: Supported +F: drivers/spi/spi-at91-usart.c +F: Documentation/devicetree/bindings/spi/microchip,at91-usart-spi.txt + MICROCHIP KSZ SERIES ETHERNET SWITCH DRIVER M: Woojung Huh <[email protected]> M: Microchip Linux Driver Support <[email protected]>
Signature · 1 line
2.17.0
PATCH 3/3 spi: at91-usart: add driver for at91-usart as spi
In reply to Radu PireaThis is the driver for at91-usart in spi mode. The USART IP can be configured to work in many modes and one of them is SPI.
The driver was tested on sama5d3-xplained and sama5d4-xplained boards with enc28j60 ethernet controller as slave.
--- drivers/spi/Kconfig | 8 + drivers/spi/Makefile | 1 + drivers/spi/spi-at91-usart.c | 545 +++++++++++++++++++++++++++++++++++ 3 files changed, 554 insertions(+) create mode 100644 drivers/spi/spi-at91-usart.c
drivers/spi/Kconfig +8 -0
@@ -77,6 +77,14 @@ config SPI_ATMEL This selects a driver for the Atmel SPI Controller, present on many AT91 (ARM) chips. +config SPI_AT91_USART + tristate "Atmel USART Controller as SPI" + depends on HAS_DMA + depends on (ARCH_AT91 || COMPILE_TEST) + help + This selects a driver for the AT91 USART Controller as SPI Master, + present on AT91 and SAMA5 SoC series. + config SPI_AU1550 tristate "Au1550/Au1200/Au1300 SPI Controller" depends on MIPS_ALCHEMY
drivers/spi/Makefile +1 -0
@@ -15,6 +15,7 @@ obj-$(CONFIG_SPI_LOOPBACK_TEST) += spi-loopback-test.o obj-$(CONFIG_SPI_ALTERA) += spi-altera.o obj-$(CONFIG_SPI_ARMADA_3700) += spi-armada-3700.o obj-$(CONFIG_SPI_ATMEL) += spi-atmel.o +obj-$(CONFIG_SPI_AT91_USART) += spi-at91-usart.o obj-$(CONFIG_SPI_ATH79) += spi-ath79.o obj-$(CONFIG_SPI_AU1550) += spi-au1550.o obj-$(CONFIG_SPI_AXI_SPI_ENGINE) += spi-axi-spi-engine.o
drivers/spi/spi-at91-usart.c new file +545 -0
545 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH 2/3 dt-bindings: add binding for at91-usart in spi mode
In reply to Radu PireaThese are bindings for at91-usart IP in spi spi mode. There is no support for internal chip select. Only kind of chip selects available are gpio chip selects.
--- .../bindings/spi/microchip,at91-usart-spi.txt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/microchip,at91-usart-spi.txt
Documentation/devicetree/bindings/spi/microchip,at91-usart-spi.txt new file +24 -0
@@ -0,0 +1,24 @@ +* Universal Synchronous Asynchronous Receiver/Transmitter (USART) in SPI mode + +Required properties: +- #size-cells : Must be <0> +- #address-cells : Must be <1> +- compatible: Should be "microchip,at91sam9g45-usart-spi" or "microchip,sama5d2-usart-spi" +- reg: Should contain registers location and length +- interrupts: Should contain interrupt +- clocks: phandles to input clocks. +- clock-names: tuple listing input clock names. + Required elements: "usart" +- cs-gpios: chipselects (internal cs not supported) + +Example: + spi0: spi@f001c000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "microchip,sama5d2-usart-spi", "microchip,at91sam9g45-usart-spi"; + reg = <0xf001c000 0x100>; + interrupts = <12 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&usart0_clk>; + clock-names = "usart"; + cs-gpios = <&pioB 3 0>; + };
Signature · 1 line
2.17.0
Alexandre Belloni
maintainerRe: [PATCH 2/3] dt-bindings: add binding for at91-usart in spi mode
Quoted 24 lines · Radu Pirea
These are bindings for at91-usart IP in spi spi mode. There is no support for internal chip select. Only kind of chip selects available are gpio chip selects.
Signed-off-by Radu Pirea <[email protected]>--- .../bindings/spi/microchip,at91-usart-spi.txt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/microchip,at91-usart-spi.txtDocumentation/devicetree/bindings/spi/microchip,at91-usart-spi.txt new file +8
-0@@ -0,0 +1,24 @@ +* Universal Synchronous Asynchronous Receiver/Transmitter (USART) in SPI mode + +Required properties: +- #size-cells : Must be <0> +- #address-cells : Must be <1> +- compatible: Should be "microchip,at91sam9g45-usart-spi" or "microchip,sama5d2-usart-spi" +- reg: Should contain registers location and length +- interrupts: Should contain interrupt
Documentation/devicetree/bindings/spi/microchip,at91-usart-spi.txt line 18
Quoted 10 lines
Documentation/devicetree/bindings/spi/microchip,at91-usart-spi.txt new file +10
-0+- clocks: phandles to input clocks. +- clock-names: tuple listing input clock names. + Required elements: "usart" +- cs-gpios: chipselects (internal cs not supported) + +Example: + spi0: spi at f001c000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "microchip,sama5d2-usart-spi", "microchip,at91sam9g45-usart-spi";
I'm pretty sure this will be considered configuration rather than hardware description. Why don't you do something like the flexcom mode selection?
Quoted 9 lines
Documentation/devicetree/bindings/spi/microchip,at91-usart-spi.txt new file +6
-0+ reg = <0xf001c000 0x100>; + interrupts = <12 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&usart0_clk>; + clock-names = "usart"; + cs-gpios = <&pioB 3 0>; + };Signature · 1 line
2.17.0
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Nicolas Ferre
maintainerRe: [PATCH 2/3] dt-bindings: add binding for at91-usart in spi mode
Quoted 31 lines · Alexandre Belloni
Quoted 30 lines · Radu Pirea
These are bindings for at91-usart IP in spi spi mode. There is no support for internal chip select. Only kind of chip selects available are gpio chip selects.
Signed-off-by Radu Pirea <[email protected]>--- .../bindings/spi/microchip,at91-usart-spi.txt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+)create mode 100644
Documentation/devicetree/bindings/spi/microchip,at91-usart-spi.txtDocumentation/devicetree/bindings/spi/microchip,at91-usart-spi.txt new file +14
-0@@ -0,0 +1,24 @@ +* Universal Synchronous Asynchronous Receiver/Transmitter (USART) in SPI mode + +Required properties: +- #size-cells : Must be <0> +- #address-cells : Must be <1> +- compatible: Should be "microchip,at91sam9g45-usart-spi" or "microchip,sama5d2-usart-spi" +- reg: Should contain registers location and length +- interrupts: Should contain interrupt +- clocks: phandles to input clocks. +- clock-names: tuple listing input clock names. + Required elements: "usart" +- cs-gpios: chipselects (internal cs not supported) + +Example:
Quoted 8 lines
Documentation/devicetree/bindings/spi/microchip,at91-usart-spi.txt line 18
Quoted 4 lines
Documentation/devicetree/bindings/spi/microchip,at91-usart-spi.txt new file +4
-0+ spi0: spi at f001c000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "microchip,sama5d2-usart-spi", "microchip,at91sam9g45-usart-spi";I'm pretty sure this will be considered configuration rather than hardware description. Why don't you do something like the flexcom mode selection?
Because we are not in the same situation as having a glue layer that would select one of the already existing peripherals with associated drivers above.
This layout of the hardware is completely different from the USART one and it seems to makes sense to address it with a different hardware description and so a different compatible string.
Regards,
Nicolas
Quoted 10 lines
Quoted 9 lines
Documentation/devicetree/bindings/spi/microchip,at91-usart-spi.txt new file +6
-0+ reg = <0xf001c000 0x100>; + interrupts = <12 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&usart0_clk>; + clock-names = "usart"; + cs-gpios = <&pioB 3 0>; + };Signature · 1 line
2.17.0
Signature · 1 line
Nicolas Ferre
Alexandre Belloni
maintainerRe: [PATCH 2/3] dt-bindings: add binding for at91-usart in spi mode
Quoted 29 lines · Nicolas Ferre
Quoted 20 lines
Quoted 20 lines
Documentation/devicetree/bindings/spi/microchip,at91-usart-spi.txt new file +14
-0@@ -0,0 +1,24 @@ +* Universal Synchronous Asynchronous Receiver/Transmitter (USART) in SPI mode + +Required properties: +- #size-cells : Must be <0> +- #address-cells : Must be <1> +- compatible: Should be "microchip,at91sam9g45-usart-spi" or "microchip,sama5d2-usart-spi" +- reg: Should contain registers location and length +- interrupts: Should contain interrupt +- clocks: phandles to input clocks. +- clock-names: tuple listing input clock names. + Required elements: "usart" +- cs-gpios: chipselects (internal cs not supported) + +Example:Quoted 8 lines
Documentation/devicetree/bindings/spi/microchip,at91-usart-spi.txt line 18
Quoted 4 lines
Documentation/devicetree/bindings/spi/microchip,at91-usart-spi.txt new file +4
-0+ spi0: spi at f001c000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "microchip,sama5d2-usart-spi", "microchip,at91sam9g45-usart-spi";I'm pretty sure this will be considered configuration rather than hardware description. Why don't you do something like the flexcom mode selection?
Quoted 7 lines
Because we are not in the same situation as having a glue layer that would select one of the already existing peripherals with associated drivers above.
This layout of the hardware is completely different from the USART one and it seems to makes sense to address it with a different hardware description and so a different compatible string.
But then, you can end up with two drivers trying to use the same IP because nothing prevents you from writing a DT with both a usart and an spi node enabled for the same IP. request_mem_region() will not help here because then the working driver will depend on the probing order.
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Mark Brown
maintainerRe: [PATCH 2/3] dt-bindings: add binding for at91-usart in spi mode
Quoted 10 lines · Alexandre Belloni
Quoted 3 lines · Nicolas Ferre
This layout of the hardware is completely different from the USART one and it seems to makes sense to address it with a different hardware description and so a different compatible string.
But then, you can end up with two drivers trying to use the same IP because nothing prevents you from writing a DT with both a usart and an spi node enabled for the same IP.
request_mem_region()will not help here because then the working driver will depend on the probing order.
We don't really have too much in the way of better ideas for how to
handle this though. Take a look at how the PXA SSP stuff handles this,
though that's not really doing too much different it at least layers a
mechanism on top to avoid collisions.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180417/26668ad7/attachment.sig>
Re: [PATCH 2/3] dt-bindings: add binding for at91-usart in spi mode
Quoted 15 lines · Mark Brown
Quoted 6 lines · Alexandre Belloni
Quoted 5 lines · Nicolas Ferre
This layout of the hardware is completely different from the USART one and
it seems to makes sense to address it with a different hardware description
and so a different compatible string.Quoted 7 lines
But then, you can end up with two drivers trying to use the same IP because nothing prevents you from writing a DT with both a usart and an
spi node enabled for the same IP.request_mem_region()will not help
here because then the working driver will depend on the probing order.
Quoted 6 lines
We don't really have too much in the way of better ideas for how to handle this though. Take a look at how the PXA SSP stuff handles this,
though that's not really doing too much different it at least layers a
mechanism on top to avoid collisions.
Hi Mark,
Thank you for suggestions. I followed your advice and looked at PXA SSP driver. In my opinion it is a layer that avoids collsions and unfortunately complicates things a bit. My ideea is to keep the things as simple as possible. For example, I can enhance usart-serial and usart-spi drivers to print detailed messages if probe fails because one driver tries to request a memory region already used by another driver. What do you think? Is this approach a good way to move forward?
Alexandre Belloni
maintainerRe: [PATCH 2/3] dt-bindings: add binding for at91-usart in spi mode
In reply to Mark BrownQuoted 12 lines · Mark Brown
Quoted 10 lines · Alexandre Belloni
Quoted 3 lines · Nicolas Ferre
This layout of the hardware is completely different from the USART one and it seems to makes sense to address it with a different hardware description and so a different compatible string.
But then, you can end up with two drivers trying to use the same IP because nothing prevents you from writing a DT with both a usart and an spi node enabled for the same IP.
request_mem_region()will not help here because then the working driver will depend on the probing order.
Quoted 4 lines
We don't really have too much in the way of better ideas for how to handle this though. Take a look at how the PXA SSP stuff handles this, though that's not really doing too much different it at least layers a mechanism on top to avoid collisions.
My suggestion was to add an MFD driver that would match the current compatible and either have an atmel,usart-mode property or maybe more risky, check whether there are children nodes. Based on that, the correct platform device can be added, either an usart or an spi master device can be registered.
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Mark Brown
maintainerRe: [PATCH 2/3] dt-bindings: add binding for at91-usart in spi mode
Quoted 5 lines · Alexandre Belloni
My suggestion was to add an MFD driver that would match the current compatible and either have an atmel,usart-mode property or maybe more risky, check whether there are children nodes. Based on that, the correct platform device can be added, either an usart or an spi master device can be registered.
Yeah, that's another approach which could work and is a bit easier from
the DT point of view - the PXA stuff predated DT and was adapted into
it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180419/ad3f251e/attachment.sig>
Mark Brown
maintainerRe: [PATCH 2/3] dt-bindings: add binding for at91-usart in spi mode
In reply to Radu PireaQuoted 7 lines · Radu Pirea
Thank you for suggestions. I followed your advice and looked at PXA SSP driver. In my opinion it is a layer that avoids collsions and unfortunately complicates things a bit. My ideea is to keep the things as simple as possible. For example, I can enhance usart-serial and usart-spi drivers to print detailed messages if probe fails because one driver tries to request a memory region already used by another driver. What do you think? Is this approach a good way to move forward?
Alexandre's suggestion using a MFD with a property to select the mode
seems more solid TBH.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20180419/b5b2325f/attachment.sig>