Driver for at91 usart in spi mode
Subsystems (8)
v4 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 v1:
- added spi-at91-usart driver
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 v3:
- fixed spi slaves probing
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
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: changed the driver to work under at91-usart mfd
.../bindings/{serial => mfd}/atmel-usart.txt | 25 +-
MAINTAINERS | 16 +
drivers/mfd/Kconfig | 10 +
drivers/mfd/Makefile | 1 +
drivers/mfd/at91-usart.c | 75 +++
drivers/spi/Kconfig | 9 +
drivers/spi/Makefile | 1 +
drivers/spi/spi-at91-usart.c | 431 ++++++++++++++++++
drivers/tty/serial/Kconfig | 1 +
drivers/tty/serial/atmel_serial.c | 40 +-
include/dt-bindings/mfd/at91-usart.h | 17 +
11 files changed, 606 insertions(+), 20 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.0
PATCH v4 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.0
PATCH v4 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 +++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
rename Documentation/devicetree/bindings/{serial => mfd}/atmel-usart.txt (76%)Documentation/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>; + };
Signature · 1 line
2.17.0
PATCH v4 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 | 10 ++++ drivers/mfd/Makefile | 1 + drivers/mfd/at91-usart.c | 75 ++++++++++++++++++++++++++++ include/dt-bindings/mfd/at91-usart.h | 17 +++++++ 4 files changed, 103 insertions(+) create mode 100644 drivers/mfd/at91-usart.c create mode 100644 include/dt-bindings/mfd/at91-usart.h
drivers/mfd/Kconfig +10 -0
@@ -99,6 +99,16 @@ 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 + depends on OF + 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 +75 -0
75 lines not on this page · raw message
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 1 +#define AT91_USART_MODE_SPI 2 + +#endif /* __DT_BINDINGS_AT91_USART_H__ */
Signature · 1 line
2.17.0
PATCH v4 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.0
PATCH v4 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 | 431 +++++++++++++++++++++++++++++++++++ 3 files changed, 441 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 +431 -0
431 lines not on this page · raw message
Signature · 1 line
2.17.0
PATCH v4 6/6 tty/serial: atmel: changed 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 | 40 +++++++++++++++++-------------- 2 files changed, 23 insertions(+), 18 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 +22 -18
@@ -193,8 +193,8 @@ static struct console atmel_console;#if defined(CONFIG_OF )static const struct of_device_id atmel_serial_dt_ids[] = { - { .compatible ="atmel,at91rm9200-usart" }, - { .compatible ="atmel,at91sam9260-usart" }, + { .compatible ="atmel,at91rm9200-usart-serial" }, + { .compatible ="atmel,at91sam9260-usart-serial" }, {/* sentinel */ } };#endif
@@ -915,6 +915,7 @@ static void atmel_tx_dma(struct uart_port *port)static int atmel_prepare_tx_dma (struct uart_port *port) {struct atmel_uart_port *atmel_port =to_atmel_uart_port (port); +struct device *mfd_dev = port->dev->parent;dma_cap_mask_t mask;struct dma_slave_config config;int ret, nent;
@@ -922,7 +923,7 @@ static int atmel_prepare_tx_dma(struct uart_port *port)dma_cap_zero (mask);dma_cap_set (DMA_SLAVE , mask); - atmel_port->chan_tx =dma_request_slave_channel (port->dev,"tx" ); + atmel_port->chan_tx =dma_request_slave_channel (mfd_dev,"tx" );if (atmel_port->chan_tx ==NULL ) goto chan_err; dev_info(port->dev, "using %s for tx DMA transfers\n",
@@ -1093,6 +1094,7 @@ static void atmel_rx_from_dma(struct uart_port *port)static int atmel_prepare_rx_dma (struct uart_port *port) {struct atmel_uart_port *atmel_port =to_atmel_uart_port (port); +struct device *mfd_dev = port->dev->parent;struct dma_async_tx_descriptor *desc;dma_cap_mask_t mask;struct dma_slave_config config;
@@ -1104,7 +1106,7 @@ static int atmel_prepare_rx_dma(struct uart_port *port)dma_cap_zero (mask);dma_cap_set (DMA_CYCLIC , mask); - atmel_port->chan_rx =dma_request_slave_channel (port->dev,"rx" ); + atmel_port->chan_rx =dma_request_slave_channel (mfd_dev,"rx" );if (atmel_port->chan_rx ==NULL ) goto chan_err; dev_info(port->dev, "using %s for rx DMA transfers\n",
@@ -1631,7 +1633,7 @@ static void atmel_tasklet_tx_func(unsigned long data)static void atmel_init_property (struct atmel_uart_port *atmel_port,struct platform_device *pdev) { -struct device_node *np = pdev->dev.of_node; +struct device_node *np = pdev->dev.parent->of_node;/* DMA/PDC usage specification */ if (of_property_read_bool (np,"atmel,use-dma-rx" )) {
@@ -2222,8 +2224,8 @@ static const char *atmel_type(struct uart_port *port)*/ static void atmel_release_port (struct uart_port *port) { -struct platform_device *pdev =to_platform_device (port->dev); -int size = pdev->resource[0 ].end - pdev->resource[0 ].start +1 ; +struct platform_device *mpdev =to_platform_device (port->dev->parent); +int size =resource_size (mpdev->resource);release_mem_region (port->mapbase, size);
@@ -2238,8 +2240,8 @@ static void atmel_release_port(struct uart_port *port)*/ static int atmel_request_port (struct uart_port *port) { -struct platform_device *pdev =to_platform_device (port->dev); -int size = pdev->resource[0 ].end - pdev->resource[0 ].start +1 ; +struct platform_device *mpdev =to_platform_device (port->dev->parent); +int size =resource_size (mpdev->resource);if (!request_mem_region (port->mapbase, size,"atmel_serial" ))return -EBUSY ;
@@ -2341,27 +2343,28 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port, {int ret;struct uart_port *port = &atmel_port->uart; +struct platform_device *mpdev =to_platform_device (pdev->dev.parent);atmel_init_property (atmel_port, pdev);atmel_set_ops (port); -uart_get_rs485_mode (&pdev->dev, &port->rs485); +uart_get_rs485_mode (&mpdev->dev, &port->rs485); port->iotype =UPIO_MEM ; port->flags =UPF_BOOT_AUTOCONF |UPF_IOREMAP ; port->ops = &atmel_pops; port->fifosize =1 ; port->dev = &pdev->dev; - port->mapbase = pdev->resource[0 ].start; - port->irq = pdev->resource[1 ].start; + port->mapbase = mpdev->resource[0 ].start; + port->irq = mpdev->resource[1 ].start; port->rs485_config = atmel_config_rs485; - port->membase =NULL ; + port->membase =NULL ;memset (&atmel_port->rx_ring,0 ,sizeof (atmel_port->rx_ring));/* for console, the clock could already be configured */ if (!atmel_port->clk) { - atmel_port->clk =clk_get (&pdev->dev,"usart" ); + atmel_port->clk =clk_get (&mpdev->dev,"usart" );if (IS_ERR (atmel_port->clk)) { ret =PTR_ERR (atmel_port->clk); atmel_port->clk =NULL ;
@@ -2652,11 +2655,13 @@ static int atmel_serial_resume(struct platform_device *pdev)static void atmel_serial_probe_fifos (struct atmel_uart_port *atmel_port,struct platform_device *pdev) { +struct device *dev = pdev->dev.parent; + atmel_port->fifo_size =0 ; atmel_port->rts_low =0 ; atmel_port->rts_high =0 ; -if (of_property_read_u32 (pdev->dev.of_node, +if (of_property_read_u32 (dev->of_node,"atmel,fifo-size" , &atmel_port->fifo_size))return ;
@@ -2694,11 +2699,10 @@ static void atmel_serial_probe_fifos(struct atmel_uart_port *atmel_port,static int atmel_serial_probe (struct platform_device *pdev) {struct atmel_uart_port *atmel_port; -struct device_node *np = pdev->dev.of_node; +struct device_node *np = pdev->dev.parent->of_node;void *data;int ret = -ENODEV ;bool rs485_enabled; -BUILD_BUG_ON (ATMEL_SERIAL_RINGSIZE & (ATMEL_SERIAL_RINGSIZE -1 )); ret =of_alias_get_id (np,"serial" );
@@ -2845,7 +2849,7 @@ static struct platform_driver atmel_serial_driver = { .suspend = atmel_serial_suspend, .resume = atmel_serial_resume, .driver = { - .name = "atmel_usart", + .name = "atmel_usart_serial", .of_match_table = of_match_ptr(atmel_serial_dt_ids), }, };
Signature · 1 line
2.17.0
Re: [PATCH v4 3/6] mfd: at91-usart: added mfd driver for usart
In reply to Radu PireaQuoted 6 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.+ depends on OF
What makes this driver OF specific?
drivers/mfd/at91-usart.c line 18
Quoted 2 lines
drivers/mfd/at91-usart.c new file +2
-0+#include <linux/of.h> +#include <linux/of_platform.h>
Ditto.
Quoted 1 line
+#include <
linux/pinctrl/pinctrl.h>
How exactly is this used?
drivers/mfd/at91-usart.c line 21
Quoted 3 lines
drivers/mfd/at91-usart.c new file +2
-0+#include <linux/platform_device.h> +#include <linux/slab.h>
Ditto.
drivers/mfd/at91-usart.c line 41
Quoted 11 lines
drivers/mfd/at91-usart.c new file +9
-0+#include <linux/types.h> +static int at91_usart_mode_probe (struct platform_device *pdev) +{ +struct device_node *np = pdev->dev.of_node; +struct mfd_cell cell; +u32 opmode; +int err; + + err =of_property_read_u32 (np,"atmel,usart-mode" , &opmode);
Check unified device property API.
drivers/mfd/at91-usart.c line 53
Quoted 2 lines
drivers/mfd/at91-usart.c new file +2
-0+return mfd_add_devices (&pdev->dev,PLATFORM_DEVID_AUTO , &cell,1 , +NULL ,0 ,NULL );
No devm_ and no ->remove(). Why to leak resources?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v4 5/6] spi: at91-usart: add driver for at91-usart as spi
In reply to Radu PireaQuoted 7 lines · Radu Pirea
This 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.
+#include <
linux/of_gpio.h>
What is the use of it?
drivers/spi/spi-at91-usart.c line 59
Quoted 2 lines
drivers/spi/spi-at91-usart.c new file +2
-0+#define US_INIT (US_MR_SPI_MASTER | US_MR_CHRL | US_MR_CLKO | \ + US_MR_WRDBT)
Don't split lines like this, it's hard to read.
#define FOO \
(BAR1 | BAR2)
I think I already told this to someone recently, maybe to you.
drivers/spi/spi-at91-usart.c line 70
Quoted 10 lines
drivers/spi/spi-at91-usart.c new file +10
-0+/* Register access macros */ +#define spi_readl (port, reg) \ + readl_relaxed((port)->regs + US_##reg) +#define spi_writel (port, reg, value) \ + writel_relaxed((value), (port)->regs + US_##reg) + +#define spi_readb (port, reg) \ + readb_relaxed((port)->regs + US_##reg) +#define spi_writeb (port, reg, value) \ + writeb_relaxed((value), (port)->regs + US_##reg)
Names are too generic. You better to use the same prefix as for the rest, i.e. at91_spi_
Quoted 1 line
+ /*used in interrupt to protect data reading*/
Comment style.
You need to read some existing code, perhaps, to see how it's done.
drivers/spi/spi-at91-usart.c line 120
Quoted 9 lines
drivers/spi/spi-at91-usart.c new file +8
-0+static inline void at91_usart_spi_tx (struct at91_usart_spi *aus) +{ +unsigned int len = aus->current_transfer->len; +unsigned int remaining = aus->current_tx_remaining_bytes; +const u8 *tx_buf = aus->current_transfer->tx_buf; + +if (remaining) +if (at91_usart_spi_tx_ready (aus)) {
if (x) {
if (y) {
...
}
}
is equivalent to if (x && y) {}.
Though, considering your intention here, I would rather go with better pattern, i.e.
if (!remaining)
return;
drivers/spi/spi-at91-usart.c line 135
Quoted 12 lines
drivers/spi/spi-at91-usart.c new file +11
-0+spi_writeb (aus,THR , tx_buf[len - remaining]); + aus->current_tx_remaining_bytes--; + } +} + +static inline void at91_usart_spi_rx (struct at91_usart_spi *aus) +{ +if (remaining) { + rx_buf[len - remaining] =spi_readb (aus,RHR ); + aus->current_rx_remaining_bytes--; + }
Ditto.
drivers/spi/spi-at91-usart.c line 284
Quoted 7 lines
drivers/spi/spi-at91-usart.c new file +4
-0+} +static int at91_usart_gpio_setup (struct platform_device *pdev) +{ +struct device_node *np = pdev->dev.parent->of_node;
Your driver is not OF specific as far as I can see. Drop all these device_node stuff and change API calls respectively.
drivers/spi/spi-at91-usart.c line 287
Quoted 4 lines
drivers/spi/spi-at91-usart.c new file +3
-0+int i; +int ret =0 ; +int nb =0 ;
What happened to indentation?
Redundnant assignment for both.
Quoted 19 lines
drivers/spi/spi-at91-usart.c new file +19
-0+if (!np) +return -EINVAL ; + + nb =of_gpio_named_count (np,"cs-gpios" ); +for (i =0 ; i < nb; i++) { +int cs_gpio =of_get_named_gpio (np,"cs-gpios" , i); + +if (cs_gpio <0 ) +return cs_gpio; + +if (gpio_is_valid (cs_gpio)) { + ret =devm_gpio_request_one (&pdev->dev, cs_gpio, +GPIOF_DIR_OUT , +dev_name (&pdev->dev)); +if (ret) +return ret; + } + } +
drivers/spi/spi-at91-usart.c line 323
Quoted 10 lines
drivers/spi/spi-at91-usart.c new file +9
-0+return 0 ; +} + +static int at91_usart_spi_probe (struct platform_device *pdev) +{ + regs =platform_get_resource (to_platform_device (pdev->dev.parent), +IORESOURCE_MEM ,0 ); +if (!regs) +return -EINVAL ;
This looks weird. Supply resource to _this_ device in your MFD code.
drivers/spi/spi-at91-usart.c line 389
Quoted 4 lines
drivers/spi/spi-at91-usart.c new file +4
-0+dev_info (&pdev->dev, +"Atmel USART SPI Controller version 0x%x at 0x%08lx (irq %d)\n" , +spi_readl (aus,VERSION ), + (unsigned long )regs->start, irq);
I think I already told you, don't use explicit casting when print. If it wasn't you, do you homework then. But above is no go.
drivers/spi/spi-at91-usart.c line 422
Quoted 7 lines
drivers/spi/spi-at91-usart.c new file +5
-0+return 0 ; +static struct platform_driver at91_usart_spi_driver = { + .driver = { + .name ="at91_usart_spi" , + .of_match_table =of_match_ptr (at91_usart_spi_dt_ids),
Drop of_match_ptr(). It's not needed.
drivers/spi/spi-at91-usart.c line 425
Quoted 4 lines
drivers/spi/spi-at91-usart.c new file +3
-0+ }, + .probe = at91_usart_spi_probe, + .remove = at91_usart_spi_remove, };
Already told ya, split lines correctly.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v4 6/6] tty/serial: atmel: changed the driver to work under at91-usart mfd
In reply to Radu PireaQuoted 8 lines · Radu Pirea
This patch modifies the place where resources and device tree properties are searched.
Signed-off-by Radu Pirea <[email protected]>--- drivers/tty/serial/Kconfig | 1 + drivers/tty/serial/atmel_serial.c | 40 +++++++++++++++++-------------- 2 files changed, 23 insertions(+), 18 deletions(-)
the stdout-path property of the chosen node is still broken in this verion. if :
stdout-path = "serial0:115200n8";
is set in the DTS, the console output should go on serial0 (aka dbgu) cf Documentation/devicetree/bindings/chosen.txt
With this patch applied, this is not the case anymore. Adding console=ttyS0,115200 in the chosen node is not the solution here.
regards,
Richard.
Re: [PATCH v4 6/6] tty/serial: atmel: changed the driver to work under at91-usart mfd
Quoted 9 lines · Richard Genoud
Quoted 8 lines · Radu Pirea
This patch modifies the place where resources and device tree properties are searched.
Signed-off-by Radu Pirea <[email protected]>--- drivers/tty/serial/Kconfig | 1 + drivers/tty/serial/atmel_serial.c | 40 +++++++++++++++++-------------- 2 files changed, 23 insertions(+), 18 deletions(-)
Quoted 9 lines
the stdout-path property of the chosen node is still broken in this verion. if :
stdout-path = "serial0:115200n8";
is set in the DTS, the console output should go on serial0 (aka dbgu) cfDocumentation/devicetree/bindings/chosen.txtWith this patch applied, this is not the case anymore. Adding console=ttyS0,115200 in the chosen node is not the solution here.
I fixed the issue few minutes ago :)
I hope DMA setup is ok now.
Quoted 4 lines
regards,
Richard.
Alexandre Belloni
maintainerRe: [PATCH v4 3/6] mfd: at91-usart: added mfd driver for usart
In reply to Andy ShevchenkoQuoted 6 lines · Andy Shevchenko
Quoted 4 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.
Quoted 8 lines
Quoted 1 line
+ depends on OF
What makes this driver OF specific?
Quoted 1 line
+ err =
of_property_read_u32(np, "atmel,usart-mode", &opmode);Check unified device property API.
We don't care, this makes the driver OF specific and this is the correct thing to do.
Signature · 3 lines
Alexandre Belloni, Bootlin (formerly Free Electrons) Embedded Linux and Kernel engineering https://bootlin.com
Re: [PATCH v4 5/6] spi: at91-usart: add driver for at91-usart as spi
In reply to Andy ShevchenkoQuoted 10 lines · Andy Shevchenko
Quoted 7 lines · Radu Pirea
This 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.
+#include <
linux/of_gpio.h>What is the use of it?
I need of_gpio.h for of_gpio_named_count, of_get_named_gpio and devm_gpio_request_one(found in gpio.h)
Quoted 8 lines
drivers/spi/spi-at91-usart.c line 59
Quoted 3 lines
drivers/spi/spi-at91-usart.c new file +2
-0+#define US_INIT (US_MR_SPI_MASTER | US_MR_CHRL | US_MR_CLKO | \ + US_MR_WRDBT)Don't split lines like this, it's hard to read.
#define FOO \
(BAR1 | BAR2)
I'll fix it.
Quoted 16 lines
I think I already told this to someone recently, maybe to you.
drivers/spi/spi-at91-usart.c line 70
Quoted 10 lines
drivers/spi/spi-at91-usart.c new file +10
-0+/* Register access macros */ +#define spi_readl (port, reg) \ + readl_relaxed((port)->regs + US_##reg) +#define spi_writel (port, reg, value) \ + writel_relaxed((value), (port)->regs + US_##reg) + +#define spi_readb (port, reg) \ + readb_relaxed((port)->regs + US_##reg) +#define spi_writeb (port, reg, value) \ + writeb_relaxed((value), (port)->regs + US_##reg)Names are too generic. You better to use the same prefix as for the rest, i.e.
at91_spi_
Good ideea. I will change the names.
Quoted 6 lines
Quoted 2 lines
+ /*used in interrupt to protect data reading*/
Comment style.
You need to read some existing code, perhaps, to see how it's done.
Ok. I will add the comment.
Quoted 17 lines
drivers/spi/spi-at91-usart.c line 120
Quoted 10 lines
drivers/spi/spi-at91-usart.c new file +8
-0+static inline void at91_usart_spi_tx (struct at91_usart_spi *aus) +{ +unsigned int len = aus->current_transfer->len; +unsigned int remaining = aus->current_tx_remaining_bytes; +const u8 *tx_buf = aus->current_transfer->tx_buf; + +if (remaining) +if (at91_usart_spi_tx_ready (aus)) {if (x) {
if (y) {
...
}
}
Quoted 7 lines
is equivalent to if (x && y) {}.
Though, considering your intention here, I would rather go with better pattern, i.e.
if (!remaining)
return;
Thank for suggestion. I will change.
Quoted 19 lines
drivers/spi/spi-at91-usart.c line 135
Quoted 13 lines
drivers/spi/spi-at91-usart.c new file +11
-0+spi_writeb (aus,THR , tx_buf[len - remaining]); + aus->current_tx_remaining_bytes--; + } +} + +static inline void at91_usart_spi_rx (struct at91_usart_spi *aus) +{ +if (remaining) { + rx_buf[len - remaining] =spi_readb (aus,RHR ); + aus->current_rx_remaining_bytes--; + }Ditto.
Quoted 1 line
+}
Quoted 7 lines
drivers/spi/spi-at91-usart.c line 284
Quoted 4 lines
drivers/spi/spi-at91-usart.c new file +3
-0+static int at91_usart_gpio_setup (struct platform_device *pdev) +{ +struct device_node *np = pdev->dev.parent->of_node;Your driver is not OF specific as far as I can see. Drop all these
device_nodestuff and change API calls respectively.
Ok. What do you suggest to use instead of OF API to get the count of cs-gpios and to read their values one by one?
Quoted 35 lines
drivers/spi/spi-at91-usart.c line 287
Quoted 5 lines
drivers/spi/spi-at91-usart.c new file +3
-0+int i; +int ret =0 ; +int nb =0 ;What happened to indentation?
Redundnant assignment for both.
Quoted 24 lines
drivers/spi/spi-at91-usart.c new file +24
-0+if (!np) +return -EINVAL ; + + nb =of_gpio_named_count (np,"cs-gpios" ); +for (i =0 ; i < nb; i++) { +int cs_gpio =of_get_named_gpio (np,"cs-gpios" , i); + +if (cs_gpio <0 ) +return cs_gpio; + +if (gpio_is_valid (cs_gpio)) { + ret =devm_gpio_request_one (&pdev->dev, cs_gpio, +GPIOF_DIR_OUT , +dev_name (&pdev->dev)); +if (ret) +return ret; + } + } + +return 0 ; +} + +static int at91_usart_spi_probe (struct platform_device *pdev) +{
Quoted 6 lines
drivers/spi/spi-at91-usart.c line 323
Quoted 4 lines
drivers/spi/spi-at91-usart.c new file +4
-0+ regs =platform_get_resource (to_platform_device (pdev->dev.parent), +IORESOURCE_MEM ,0 ); +if (!regs) +return -EINVAL ;This looks weird. Supply resource to _this_ device in your MFD code.
I know weird, but is the safest way to pass the resource and the of_node.
Quoted 25 lines
drivers/spi/spi-at91-usart.c line 389
Quoted 5 lines
drivers/spi/spi-at91-usart.c new file +4
-0+dev_info (&pdev->dev, +"Atmel USART SPI Controller version 0x%x at 0x%08lx (irq %d)\n" , +spi_readl (aus,VERSION ), + (unsigned long )regs->start, irq);I think I already told you, don't use explicit casting when print. If it wasn't you, do you homework then. But above is no go. >
drivers/spi/spi-at91-usart.c line 422
Quoted 7 lines
drivers/spi/spi-at91-usart.c new file +5
-0+return 0 ; +static struct platform_driver at91_usart_spi_driver = { + .driver = { + .name ="at91_usart_spi" , + .of_match_table =of_match_ptr (at91_usart_spi_dt_ids),Drop
of_match_ptr(). It's not needed.drivers/spi/spi-at91-usart.c line 425
Quoted 4 lines
drivers/spi/spi-at91-usart.c new file +3
-0+ }, + .probe = at91_usart_spi_probe, + .remove = at91_usart_spi_remove, };Already told ya, split lines correctly.
Nicolas Ferre
maintainerRe: [PATCH v4 5/6] spi: at91-usart: add driver for at91-usart as spi
Quoted 6 lines · Radu Pirea
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Radu Pirea
This 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.
[..]
Quoted 10 lines
Quoted 7 lines
drivers/spi/spi-at91-usart.c line 284
Quoted 4 lines
drivers/spi/spi-at91-usart.c new file +3
-0+static int at91_usart_gpio_setup (struct platform_device *pdev) +{ +struct device_node *np = pdev->dev.parent->of_node;Your driver is not OF specific as far as I can see. Drop all these
device_nodestuff and change API calls respectively.Ok. What do you suggest to use instead of OF API to get the count of cs-gpios and to read their values one by one?
As Alexandre said, we can make this driver OF specific.
What could be interesting is to use the gpio descriptors API and not the older one. This would allow us to have far more control over the gpio that we use in our drivers (Ludovic is converting our drivers to only use gpiod structures).
Regards,
Nicolas
Quoted 32 lines
Quoted 32 lines
drivers/spi/spi-at91-usart.c line 287
Quoted 6 lines
drivers/spi/spi-at91-usart.c new file +3
-0+int i; +int ret =0 ; +int nb =0 ;What happened to indentation?
Redundnant assignment for both.
Quoted 21 lines
drivers/spi/spi-at91-usart.c new file +21
-0+if (!np) +return -EINVAL ; + + nb =of_gpio_named_count (np,"cs-gpios" ); +for (i =0 ; i < nb; i++) { +int cs_gpio =of_get_named_gpio (np,"cs-gpios" , i); + +if (cs_gpio <0 ) +return cs_gpio; + +if (gpio_is_valid (cs_gpio)) { + ret =devm_gpio_request_one (&pdev->dev, cs_gpio, +GPIOF_DIR_OUT , +dev_name (&pdev->dev)); +if (ret) +return ret; + } + } + +return 0 ; +}
[..]
Signature · 1 line
Nicolas Ferre
Nicolas Ferre
maintainerRe: [PATCH v4 5/6] spi: at91-usart: add driver for at91-usart as spi
Quoted 21 lines · Nicolas Ferre
Quoted 6 lines · Radu Pirea
Quoted 3 lines · Andy Shevchenko
Quoted 2 lines · Radu Pirea
This 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.
[..]
Quoted 10 lines
Quoted 7 lines
drivers/spi/spi-at91-usart.c line 284
Quoted 4 lines
drivers/spi/spi-at91-usart.c new file +3
-0+static int at91_usart_gpio_setup (struct platform_device *pdev) +{ +struct device_node *np = pdev->dev.parent->of_node;Your driver is not OF specific as far as I can see. Drop all these
device_nodestuff and change API calls respectively.Ok. What do you suggest to use instead of OF API to get the count of cs-gpios and to read their values one by one?
Quoted 6 lines
As Alexandre said, we can make this driver OF specific.
What could be interesting is to use the gpio descriptors API and not the older one. This would allow us to have far more control over the gpio that we use in our drivers (Ludovic is converting our drivers to only use gpiod structures).
Oh, but we already said that we cannot.
Disregard my comment then, sorry for the noise.
Quoted 37 lines
Regards,
NicolasQuoted 32 lines
Quoted 32 lines
drivers/spi/spi-at91-usart.c line 287
Quoted 6 lines
drivers/spi/spi-at91-usart.c new file +3
-0+int i; +int ret =0 ; +int nb =0 ;What happened to indentation?
Redundnant assignment for both.
Quoted 21 lines
drivers/spi/spi-at91-usart.c new file +21
-0+if (!np) +return -EINVAL ; + + nb =of_gpio_named_count (np,"cs-gpios" ); +for (i =0 ; i < nb; i++) { +int cs_gpio =of_get_named_gpio (np,"cs-gpios" , i); + +if (cs_gpio <0 ) +return cs_gpio; + +if (gpio_is_valid (cs_gpio)) { + ret =devm_gpio_request_one (&pdev->dev, cs_gpio, +GPIOF_DIR_OUT , +dev_name (&pdev->dev)); +if (ret) +return ret; + } + } + +return 0 ; +}[..]
Signature · 1 line
Nicolas Ferre
Re: [PATCH v4 2/6] dt-bindings: add binding for atmel-usart in SPI mode
In reply to Radu PireaQuoted 8 lines · Radu Pirea
This patch moves the bindings for serial from
serial/atmel-usart.txttomfd/atmel-usart.txtand adds bindings for USART in SPI mode.Signed-off-by Radu Pirea <[email protected]>--- .../bindings/{serial => mfd}/atmel-usart.txt | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) rename Documentation/devicetree/bindings/{serial => mfd}/atmel-usart.txt (76%)
Re: [PATCH v4 3/6] mfd: at91-usart: added mfd driver for usart
In reply to Radu PireaQuoted 5 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.
Quoted 7 lines
Signed-off-by Radu Pirea <[email protected]>--- drivers/mfd/Kconfig | 10 ++++ drivers/mfd/Makefile | 1 + drivers/mfd/at91-usart.c | 75 ++++++++++++++++++++++++++++include/dt-bindings/mfd/at91-usart.h | 17 +++++++
This really should be part of the binding patch.
Quoted 3 lines
4 files changed, 103 insertions(+) create mode 100644 drivers/mfd/at91-usart.c create mode 100644 include/dt-bindings/mfd/at91-usart.h
Re: [PATCH v4 2/6] dt-bindings: add binding for atmel-usart in SPI mode
In reply to Radu PireaQuoted 8 lines · Radu Pirea
This patch moves the bindings for serial from
serial/atmel-usart.txttomfd/atmel-usart.txtand adds bindings for USART in SPI mode.Signed-off-by Radu Pirea <[email protected]>--- .../bindings/{serial => mfd}/atmel-usart.txt | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) rename Documentation/devicetree/bindings/{serial => mfd}/atmel-usart.txt (76%)
For my own reference:
Signature · 4 lines
Lee Jones [???] Linaro Services Technical Lead Linaro.org ? Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog