Driver for at91 usart in spi mode
Subsystems (8)
v7 cover Driver for at91 usart in spi mode
Hello,
This is the second version of driver. I added a mfd driver which by default probes atmel_serial driver and if in dt is specified to probe the spi driver, then the spi-at91-usart driver will be probed. The compatible for atmel_serial is now the compatible for at91-usart mfd driver and compatilbe for atmel_serial driver was changed in order to keep the bindings for serial as they are.
Changes in v7:
- synced up SPDIX license with module license
- numbering of usart modes starts from 0 insteand of 1
Changes in v6:
- removed unused compatible strings from serial and spi drivers
Changes in v5:
- fixed usage of stdout-path property with atmel_serial driver
Changes in v4:
- modified the spi driver to use cs gpio support form spi subsystem
- fixed dma transfers for serial driver
- squashed binding for spi and serial and moved them to mfd/atmel-usart.txt
Changes in v3:
- fixed spi slaves probing
Changes in v2:
- added at91-usart mfd driver
- modified spi-at91-usart driver to work as mfd driver child
- modified atmel_serial driver to work as mfd driver child
Changes in v1:
- added spi-at91-usart driver
Radu Pirea (6):
MAINTAINERS: add at91 usart mfd driver
dt-bindings: add binding for atmel-usart in SPI mode
mfd: at91-usart: added mfd driver for usart
MAINTAINERS: add at91 usart spi driver
spi: at91-usart: add driver for at91-usart as spi tty/serial: atmel: change the driver to work under at91-usart mfd
.../bindings/{serial => mfd}/atmel-usart.txt | 25 +-
MAINTAINERS | 16 +
drivers/mfd/Kconfig | 9 +
drivers/mfd/Makefile | 1 +
drivers/mfd/at91-usart.c | 69 +++
drivers/spi/Kconfig | 9 +
drivers/spi/Makefile | 1 +
drivers/spi/spi-at91-usart.c | 434 ++++++++++++++++++
drivers/tty/serial/Kconfig | 1 +
drivers/tty/serial/atmel_serial.c | 42 +-
include/dt-bindings/mfd/at91-usart.h | 17 +
11 files changed, 607 insertions(+), 17 deletions(-)
rename Documentation/devicetree/bindings/{serial => mfd}/atmel-usart.txt (76%)
create mode 100644 drivers/mfd/at91-usart.c
create mode 100644 drivers/spi/spi-at91-usart.c
create mode 100644 include/dt-bindings/mfd/at91-usart.hSignature · 1 line
2.17.1
PATCH v7 1/6 MAINTAINERS: add at91 usart mfd driver
Added entry for at91 usart mfd driver.
--- MAINTAINERS | 9 +++++++++ 1 file changed, 9 insertions(+)
MAINTAINERS +9 -0
@@ -9160,6 +9160,7 @@ M: Richard Genoud <[email protected]> S: Maintained F: drivers/tty/serial/atmel_serial.c F: drivers/tty/serial/atmel_serial.h +F: Documentation/devicetree/bindings/mfd/atmel-usart.txt MICROCHIP / ATMEL DMA DRIVER M: Ludovic Desroches <[email protected]>
@@ -9192,6 +9193,14 @@ S: Supported F: drivers/mtd/nand/raw/atmel/* F: Documentation/devicetree/bindings/mtd/atmel-nand.txt +MICROCHIP AT91 USART MFD DRIVER +M: Radu Pirea <[email protected]> +L: linux-kernel at vger.kernel.org +S: Supported +F: drivers/mfd/at91-usart.c +F: include/dt-bindings/mfd/at91-usart.h +F: Documentation/devicetree/bindings/mfd/atmel-usart.txt + MICROCHIP KSZ SERIES ETHERNET SWITCH DRIVER M: Woojung Huh <[email protected]> M: Microchip Linux Driver Support <[email protected]>
Signature · 1 line
2.17.1
PATCH v7 2/6 dt-bindings: add binding for atmel-usart in SPI mode
In reply to Radu PireaThis patch moves the bindings for serial from serial/atmel-usart.txt to mfd/atmel-usart.txt and adds bindings for USART in SPI mode.
---
.../bindings/{serial => mfd}/atmel-usart.txt | 25 +++++++++++++++++--
include/dt-bindings/mfd/at91-usart.h | 17 +++++++++++++
2 files changed, 40 insertions(+), 2 deletions(-)
rename Documentation/devicetree/bindings/{serial => mfd}/atmel-usart.txt (76%)
create mode 100644 include/dt-bindings/mfd/at91-usart.hDocumentation/devicetree/bindings/mfd/atmel-usart.txt renamed from Documentation/devicetree/bindings/serial/atmel-usart.txt +23 -2
@@ -1,6 +1,6 @@ * Atmel Universal Synchronous Asynchronous Receiver/Transmitter (USART) -Required properties: +Required properties for USART: - compatible: Should be "atmel,<chip>-usart" or "atmel,<chip>-dbgu" The compatible <chip> indicated will be the first SoC to support an additional mode or an USART new feature.
@@ -11,7 +11,13 @@ Required properties: Required elements: "usart" - clocks: phandles to input clocks. -Optional properties: +Required properties for USART in SPI mode: +- #size-cells : Must be <0> +- #address-cells : Must be <1> +- cs-gpios: chipselects (internal cs not supported) +- atmel,usart-mode : Must be <USART_MODE_SPI> (found in dt-bindings/mfd/at91-usart.h) + +Optional properties in serial mode: - atmel,use-dma-rx: use of PDC or DMA for receiving data - atmel,use-dma-tx: use of PDC or DMA for transmitting data - {rts,cts,dtr,dsr,rng,dcd}-gpios: specify a GPIO for RTS/CTS/DTR/DSR/RI/DCD line respectively.
@@ -62,3 +68,18 @@ Example: dma-names = "tx", "rx"; atmel,fifo-size = <32>; }; + +- SPI mode: + #include <dt-bindings/mfd/at91-usart.h> + + spi0: spi at f001c000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "atmel,at91rm9200-usart", "atmel,at91sam9260-usart"; + atmel,usart-mode = <USART_MODE_SPI>; + reg = <0xf001c000 0x100>; + interrupts = <12 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&usart0_clk>; + clock-names = "usart"; + cs-gpios = <&pioB 3 0>; + };
include/dt-bindings/mfd/at91-usart.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* This header provides macros for AT91 USART DT bindings. +* +* Copyright (C) 2018 Microchip Technology +* +* Author: Radu Pirea <[email protected]> +* +*/ + +#ifndef __DT_BINDINGS_AT91_USART_H__ +#define __DT_BINDINGS_AT91_USART_H__ + +#define AT91_USART_MODE_SERIAL 0 +#define AT91_USART_MODE_SPI 1 + +#endif /* __DT_BINDINGS_AT91_USART_H__ */
Signature · 1 line
2.17.1
PATCH v7 3/6 mfd: at91-usart: added mfd driver for usart
In reply to Radu PireaThis mfd driver is just a wrapper over atmel_serial driver and spi-at91-usart driver. Selection of one of the drivers is based on a property from device tree. If the property is not specified, the default driver is atmel_serial.
--- drivers/mfd/Kconfig | 9 ++++++ drivers/mfd/Makefile | 1 + drivers/mfd/at91-usart.c | 69 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 drivers/mfd/at91-usart.c
drivers/mfd/Kconfig +9 -0
@@ -99,6 +99,15 @@ config MFD_AAT2870_CORE additional drivers must be enabled in order to use the functionality of the device. +config MFD_AT91_USART + tristate "AT91 USART Driver" + select MFD_CORE + help + Select this to get support for AT91 USART IP. This is a wrapper + over at91-usart-serial driver and usart-spi-driver. Only one function + can be used at a time. The choice is done at boot time by the probe + function of this MFD driver according to a device tree property. + config MFD_ATMEL_FLEXCOM tristate "Atmel Flexcom (Flexible Serial Communication Unit)" select MFD_CORE
drivers/mfd/Makefile +1 -0
@@ -185,6 +185,7 @@ obj-$(CONFIG_MFD_SPMI_PMIC) += qcom-spmi-pmic.o obj-$(CONFIG_TPS65911_COMPARATOR) += tps65911-comparator.o obj-$(CONFIG_MFD_TPS65090) += tps65090.o obj-$(CONFIG_MFD_AAT2870_CORE) += aat2870-core.o +obj-$(CONFIG_MFD_AT91_USART) += at91-usart.o obj-$(CONFIG_MFD_ATMEL_FLEXCOM) += atmel-flexcom.o obj-$(CONFIG_MFD_ATMEL_HLCDC) += atmel-hlcdc.o obj-$(CONFIG_MFD_ATMEL_SMC) += atmel-smc.o
drivers/mfd/at91-usart.c new file +69 -0
69 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v7 4/6 MAINTAINERS: add at91 usart spi driver
In reply to Radu PireaAdded entry for at91 usart mfd driver.
--- MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -9201,6 +9201,13 @@ F: drivers/mfd/at91-usart.c F: include/dt-bindings/mfd/at91-usart.h F: Documentation/devicetree/bindings/mfd/atmel-usart.txt +MICROCHIP AT91 USART SPI DRIVER +M: Radu Pirea <[email protected]> +L: linux-spi at vger.kernel.org +S: Supported +F: drivers/spi/spi-at91-usart.c +F: Documentation/devicetree/bindings/mfd/atmel-usart.txt + MICROCHIP KSZ SERIES ETHERNET SWITCH DRIVER M: Woojung Huh <[email protected]> M: Microchip Linux Driver Support <[email protected]>
Signature · 1 line
2.17.1
PATCH v7 5/6 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 | 9 + drivers/spi/Makefile | 1 + drivers/spi/spi-at91-usart.c | 434 +++++++++++++++++++++++++++++++++++ 3 files changed, 444 insertions(+) create mode 100644 drivers/spi/spi-at91-usart.c
drivers/spi/Kconfig +9 -0
@@ -77,6 +77,15 @@ 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 SPI driver" + depends on HAS_DMA + depends on (ARCH_AT91 || COMPILE_TEST) + select MFD_AT91_USART + 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 +434 -0
434 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH v7 6/6 tty/serial: atmel: change the driver to work under at91-usart mfd
In reply to Radu PireaThis patch modifies the place where resources and device tree properties are searched.
--- drivers/tty/serial/Kconfig | 1 + drivers/tty/serial/atmel_serial.c | 42 ++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 15 deletions(-)
drivers/tty/serial/Kconfig +1 -0
@@ -119,6 +119,7 @@ config SERIAL_ATMEL depends on ARCH_AT91 || COMPILE_TEST select SERIAL_CORE select SERIAL_MCTRL_GPIO if GPIOLIB + select MFD_AT91_USART help This enables the driver for the on-chip UARTs of the Atmel AT91 processors.
drivers/tty/serial/atmel_serial.c +27 -15
130 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v7 3/6] mfd: at91-usart: added mfd driver for usart
In reply to Radu PireaQuoted 86 lines · Radu Pirea
This mfd driver is just a wrapper over
atmel_serialdriver and spi-at91-usart driver. Selection of one of the drivers is based on a property from device tree. If the property is not specified, the default driver isatmel_serial.Signed-off-by Radu Pirea <[email protected]>Acked-by Rob Herring <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Acked-for-MFD-by Lee Jones <[email protected]>--- drivers/mfd/Kconfig | 9 ++++++ drivers/mfd/Makefile | 1 + drivers/mfd/at91-usart.c | 69 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 drivers/mfd/at91-usart.cdrivers/mfd/Kconfig +9
-0@@ -99,6 +99,15 @@ config MFD_AAT2870_CORE additional drivers must be enabled in order to use the functionality of the device. +config MFD_AT91_USART + tristate "AT91 USART Driver" + select MFD_CORE + help + Select this to get support for AT91 USART IP. This is a wrapper + over at91-usart-serial driver and usart-spi-driver. Only one function + can be used at a time. The choice is done at boot time by the probe + function of this MFD driver according to a device tree property. + config MFD_ATMEL_FLEXCOM tristate "Atmel Flexcom (Flexible Serial Communication Unit)" select MFD_COREdrivers/mfd/Makefile +1
-0@@ -185,6 +185,7 @@ obj-$(CONFIG_MFD_SPMI_PMIC) += qcom-spmi-pmic.o obj-$(CONFIG_TPS65911_COMPARATOR) += tps65911-comparator.o obj-$(CONFIG_MFD_TPS65090) += tps65090.o obj-$(CONFIG_MFD_AAT2870_CORE) += aat2870-core.o +obj-$(CONFIG_MFD_AT91_USART) += at91-usart.o obj-$(CONFIG_MFD_ATMEL_FLEXCOM) += atmel-flexcom.o obj-$(CONFIG_MFD_ATMEL_HLCDC) += atmel-hlcdc.o obj-$(CONFIG_MFD_ATMEL_SMC) += atmel-smc.odrivers/mfd/at91-usart.c new file +32
-0@@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for AT91 USART +* +* Copyright (C) 2018 Microchip Technology +* +* Author: Radu Pirea <[email protected]> +* +*/ + +#include <dt-bindings/mfd/at91-usart.h> + +#include <linux/module.h> +#include <linux/mfd/core.h> +#include <linux/property.h> + +static struct mfd_cell at91_usart_spi_subdev = { + .name ="at91_usart_spi" , + .of_compatible ="microchip,at91sam9g45-usart-spi" , + }; + +static struct mfd_cell at91_usart_serial_subdev = { + .name ="atmel_usart_serial" , + .of_compatible ="atmel,at91rm9200-usart-serial" , + }; + +static int at91_usart_mode_probe (struct platform_device *pdev) +{ +struct mfd_cell cell; +u32 opmode =AT91_USART_MODE_SERIAL ; + +device_property_read_u32 (&pdev->dev,"atmel,usart-mode" , &opmode);
drivers/mfd/at91-usart.c line 42
Quoted 10 lines
drivers/mfd/at91-usart.c new file +10
-0+ +switch (opmode) { +case AT91_USART_MODE_SPI : + cell = at91_usart_spi_subdev; +break ; +case AT91_USART_MODE_SERIAL : + cell = at91_usart_serial_subdev; +break ; +default : +break ;
If there is an invalid opmode from the DT, you will pass a non initialized cell to mfd_add_device().
Regards
Ludovic
Quoted 35 lines
drivers/mfd/at91-usart.c new file +27
-0+ } + +return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_AUTO , &cell,1 , +NULL ,0 ,NULL ); +} + +static const struct of_device_id at91_usart_mode_of_match[] = { + { .compatible ="atmel,at91rm9200-usart" }, + { .compatible ="atmel,at91sam9260-usart" }, + {/* sentinel */ } +}; + +MODULE_DEVICE_TABLE (of, at91_flexcom_of_match); + +static struct platform_driver at91_usart_mfd = { + .probe = at91_usart_mode_probe, + .driver = { + .name ="at91_usart_mode" , + .of_match_table = at91_usart_mode_of_match, + }, +}; + +module_platform_driver (at91_usart_mfd); + +MODULE_AUTHOR ("Radu Pirea <[email protected]>" ); +MODULE_DESCRIPTION ("AT91 USART MFD driver" ); +MODULE_LICENSE ("GPL v2" );Signature · 7 lines
2.17.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel at lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Re: [PATCH v7 3/6] mfd: at91-usart: added mfd driver for usart
Quoted 101 lines · Ludovic Desroches
Quoted 86 lines · Radu Pirea
This mfd driver is just a wrapper over
atmel_serialdriver and spi-at91-usart driver. Selection of one of the drivers is based on a property from device tree. If the property is not specified, the default driver isatmel_serial.Signed-off-by Radu Pirea <[email protected]>Acked-by Rob Herring <[email protected]>Reviewed-by Andy Shevchenko <[email protected]>Acked-for-MFD-by Lee Jones <[email protected]>--- drivers/mfd/Kconfig | 9 ++++++ drivers/mfd/Makefile | 1 + drivers/mfd/at91-usart.c | 69 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+)create mode 100644
drivers/mfd/at91-usart.cdrivers/mfd/Kconfig +9
-0@@ -99,6 +99,15 @@ config MFD_AAT2870_CORE additional drivers must be enabled in order to use the functionality of the device. +config MFD_AT91_USART + tristate "AT91 USART Driver" + select MFD_CORE + help + Select this to get support for AT91 USART IP. This is a wrapper + over at91-usart-serial driver and usart-spi-driver. Only one function + can be used at a time. The choice is done at boot time by the probe + function of this MFD driver according to a device tree property. + config MFD_ATMEL_FLEXCOM tristate "Atmel Flexcom (Flexible Serial Communication Unit)" select MFD_COREdrivers/mfd/Makefile +1
-0@@ -185,6 +185,7 @@ obj-$(CONFIG_MFD_SPMI_PMIC) += qcom-spmi-pmic.o obj-$(CONFIG_TPS65911_COMPARATOR) += tps65911-comparator.o obj-$(CONFIG_MFD_TPS65090) += tps65090.o obj-$(CONFIG_MFD_AAT2870_CORE) += aat2870-core.o +obj-$(CONFIG_MFD_AT91_USART) += at91-usart.o obj-$(CONFIG_MFD_ATMEL_FLEXCOM) += atmel-flexcom.o obj-$(CONFIG_MFD_ATMEL_HLCDC) += atmel-hlcdc.o obj-$(CONFIG_MFD_ATMEL_SMC) += atmel-smc.odrivers/mfd/at91-usart.c new file +32
-0@@ -0,0 +1,69 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Driver for AT91 USART +* +* Copyright (C) 2018 Microchip Technology +* +* Author: Radu Pirea <[email protected]> +* +*/ + +#include <dt-bindings/mfd/at91-usart.h> + +#include <linux/module.h> +#include <linux/mfd/core.h> +#include <linux/property.h> + +static struct mfd_cell at91_usart_spi_subdev = { + .name ="at91_usart_spi" , + .of_compatible ="microchip,at91sam9g45-usart-spi" , + }; + +static struct mfd_cell at91_usart_serial_subdev = { + .name ="atmel_usart_serial" , + .of_compatible ="atmel,at91rm9200-usart-serial" , + }; + +static int at91_usart_mode_probe (struct platform_device *pdev) +{ +struct mfd_cell cell; +u32 opmode =AT91_USART_MODE_SERIAL ; + +device_property_read_u32 (&pdev->dev,"atmel,usart-mode" , &opmode);drivers/mfd/at91-usart.c line 42
Quoted 10 lines
drivers/mfd/at91-usart.c new file +10
-0+ +switch (opmode) { +case AT91_USART_MODE_SPI : + cell = at91_usart_spi_subdev; +break ; +case AT91_USART_MODE_SERIAL : + cell = at91_usart_serial_subdev; +break ; +default : +break ;If there is an invalid opmode from the DT, you will pass a non initialized cell to
mfd_add_device().
Quoted 3 lines
Regards
Ludovic
Hi Ludovic,
Tnx. That's true. How is better to do if atmel,usart-mode has an invalid value? To initialize cell with at91_usart_serial_subdev or to print an error message and return -EINVAL?
Regards.
Radu Pirea
Quoted 36 lines
Quoted 36 lines
drivers/mfd/at91-usart.c new file +27
-0+ } + +return devm_mfd_add_devices (&pdev->dev,PLATFORM_DEVID_AUTO , &cell,1 , +NULL ,0 ,NULL ); +} + +static const struct of_device_id at91_usart_mode_of_match[] = { + { .compatible ="atmel,at91rm9200-usart" }, + { .compatible ="atmel,at91sam9260-usart" }, + {/* sentinel */ } +}; + +MODULE_DEVICE_TABLE (of, at91_flexcom_of_match); + +static struct platform_driver at91_usart_mfd = { + .probe = at91_usart_mode_probe, + .driver = { + .name ="at91_usart_mode" , + .of_match_table = at91_usart_mode_of_match, + }, +}; + +module_platform_driver (at91_usart_mfd); + +MODULE_AUTHOR ("Radu Pirea <[email protected]>" ); +MODULE_DESCRIPTION ("AT91 USART MFD driver" ); +MODULE_LICENSE ("GPL v2" );Signature · 7 lines
2.17.1 _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Alexandre Belloni
maintainerRe: [PATCH v7 3/6] mfd: at91-usart: added mfd driver for usart
Quoted 23 lines · Radu Pirea
Quoted 22 lines · Ludovic Desroches
Quoted 6 lines
drivers/mfd/at91-usart.c new file +6
-0+static int at91_usart_mode_probe (struct platform_device *pdev) +{ +struct mfd_cell cell; +u32 opmode =AT91_USART_MODE_SERIAL ; + +device_property_read_u32 (&pdev->dev,"atmel,usart-mode" , &opmode);drivers/mfd/at91-usart.c line 42
Quoted 10 lines
drivers/mfd/at91-usart.c new file +10
-0+ +switch (opmode) { +case AT91_USART_MODE_SPI : + cell = at91_usart_spi_subdev; +break ; +case AT91_USART_MODE_SERIAL : + cell = at91_usart_serial_subdev; +break ; +default : +break ;If there is an invalid opmode from the DT, you will pass a non initialized cell to
mfd_add_device().Regards
Quoted 8 lines
Quoted 1 line
Ludovic
Hi Ludovic,
Tnx. That's true. How is better to do if atmel,usart-mode has an invalid value? To initialize cell with
at91_usart_serial_subdevor to print an error message and return-EINVAL?
Returning an error is probably the correct choice because it means the DT has an invalid value (something was done and is wrong).
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com