Discussion:
[PATCH v4 0/9] Add and make use of a common rs485 device tree parsing function
Uwe Kleine-König
2017-07-18 10:59:39 UTC
Permalink
Hello,

this is v4 of the series. Compared to v3 It fixes a compile error and is
rebased to a newer kernel to apply fine on Greg's tree.

Sascha Hauer (6):
serial: Add common rs485 device tree parsing function
serial: atmel: Use common rs485 device tree parsing function
serial: fsl_lpuart: Use common rs485 device tree parsing function
serial: omap-serial: Use common rs485 device tree parsing function
serial: imx: default to half duplex rs485
serial: imx: Use common rs485 device tree parsing function

Uwe Kleine-König (3):
serial: fsl_lpuart: clear unsupported options in .rs485_config()
dt-bindings: serial/rs485: make rs485-rts-delay optional
dt-bindings: serial: document rs485 bindings for various devices

.../devicetree/bindings/serial/atmel-usart.txt | 1 +
.../devicetree/bindings/serial/fsl-imx-uart.txt | 1 +
.../devicetree/bindings/serial/fsl-lpuart.txt | 1 +
.../devicetree/bindings/serial/omap_serial.txt | 1 +
Documentation/devicetree/bindings/serial/rs485.txt | 5 +--
drivers/tty/serial/Kconfig | 4 ++
drivers/tty/serial/Makefile | 2 +
drivers/tty/serial/atmel_serial.c | 25 +-----------
drivers/tty/serial/fsl_lpuart.c | 29 ++++++++++---
drivers/tty/serial/imx.c | 5 ++-
drivers/tty/serial/of.c | 47 ++++++++++++++++++++++
drivers/tty/serial/omap-serial.c | 13 +-----
include/linux/serial_core.h | 13 ++++++
13 files changed, 100 insertions(+), 47 deletions(-)
create mode 100644 drivers/tty/serial/of.c
--
2.11.0
Uwe Kleine-König
2017-07-18 10:59:40 UTC
Permalink
The struct serial_rs485 parameter is both input and output and is
supposed to hold the actually used configuration on return. So clear
unsupported settings.

Signed-off-by: Uwe Kleine-König <u.kleine-***@pengutronix.de>
---
drivers/tty/serial/fsl_lpuart.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 343de8c384b0..4becfbf35c4c 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -1019,6 +1019,11 @@ static int lpuart_config_rs485(struct uart_port *port,
~(UARTMODEM_TXRTSPOL | UARTMODEM_TXRTSE);
writeb(modem, sport->port.membase + UARTMODEM);

+ /* clear unsupported configurations */
+ rs485->delay_rts_before_send = 0;
+ rs485->delay_rts_after_send = 0;
+ rs485->flags &= ~SER_RS485_RX_DURING_TX;
+
if (rs485->flags & SER_RS485_ENABLED) {
/* Enable auto RS-485 RTS mode */
modem |= UARTMODEM_TXRTSE;
--
2.11.0
Uwe Kleine-König
2017-07-18 10:59:42 UTC
Permalink
From: Sascha Hauer <***@pengutronix.de>

Several drivers have the same device tree parsing code. Create
a common helper function for it.

Signed-off-by: Sascha Hauer <***@pengutronix.de>
[ukl: implement default <0 0> for rts-delay, unset unspecified flags]
Acked-by: Nicolas Ferre <***@microchip.com>
Signed-off-by: Uwe Kleine-König <u.kleine-***@pengutronix.de>
---
drivers/tty/serial/Kconfig | 4 ++++
drivers/tty/serial/Makefile | 2 ++
drivers/tty/serial/of.c | 47 +++++++++++++++++++++++++++++++++++++++++++++
include/linux/serial_core.h | 13 +++++++++++++
4 files changed, 66 insertions(+)
create mode 100644 drivers/tty/serial/of.c

diff --git a/drivers/tty/serial/Kconfig b/drivers/tty/serial/Kconfig
index 1f096e2bb398..f7d7e4936940 100644
--- a/drivers/tty/serial/Kconfig
+++ b/drivers/tty/serial/Kconfig
@@ -14,6 +14,10 @@ config SERIAL_EARLYCON
the console before standard serial driver is probed. The console is
enabled when early_param is processed.

+config OF_SERIAL
+ depends on SERIAL_CORE
+ def_bool y
+
source "drivers/tty/serial/8250/Kconfig"

comment "Non-8250 serial port support"
diff --git a/drivers/tty/serial/Makefile b/drivers/tty/serial/Makefile
index fe88a75d9a59..a755faa25485 100644
--- a/drivers/tty/serial/Makefile
+++ b/drivers/tty/serial/Makefile
@@ -7,6 +7,8 @@ obj-$(CONFIG_SERIAL_CORE) += serial_core.o
obj-$(CONFIG_SERIAL_EARLYCON) += earlycon.o
obj-$(CONFIG_SERIAL_EARLYCON_ARM_SEMIHOST) += earlycon-arm-semihost.o

+obj-$(CONFIG_OF_SERIAL) += of.o
+
# These Sparc drivers have to appear before others such as 8250
# which share ttySx minor node space. Otherwise console device
# names change and other unplesantries.
diff --git a/drivers/tty/serial/of.c b/drivers/tty/serial/of.c
new file mode 100644
index 000000000000..2830c688bb5d
--- /dev/null
+++ b/drivers/tty/serial/of.c
@@ -0,0 +1,47 @@
+#include <linux/kernel.h>
+#include <linux/export.h>
+#include <linux/of.h>
+#include <linux/serial_core.h>
+
+/**
+ * of_get_rs485_mode() - Implement parsing rs485 properties
+ * @np: uart node
+ * @rs485conf: output parameter
+ *
+ * This function implements the device tree binding described in
+ * Documentation/devicetree/bindings/serial/rs485.txt.
+ *
+ * Return: 0 on success, 1 if the node doesn't contain rs485 stuff.
+ */
+int of_get_rs485_mode(struct device_node *np, struct serial_rs485 *rs485conf)
+{
+ u32 rs485_delay[2];
+ int ret;
+
+ if (!IS_ENABLED(CONFIG_OF) || !np)
+ return 1;
+
+ ret = of_property_read_u32_array(np, "rs485-rts-delay", rs485_delay, 2);
+ if (!ret) {
+ rs485conf->delay_rts_before_send = rs485_delay[0];
+ rs485conf->delay_rts_after_send = rs485_delay[1];
+ } else {
+ rs485conf->delay_rts_before_send = 0;
+ rs485conf->delay_rts_after_send = 0;
+ }
+
+ /*
+ * clear full-duplex and enabled flags to get to a defined state with
+ * the two following properties.
+ */
+ rs485conf->flags &= ~(SER_RS485_RX_DURING_TX | SER_RS485_ENABLED);
+
+ if (of_property_read_bool(np, "rs485-rx-during-tx"))
+ rs485conf->flags |= SER_RS485_RX_DURING_TX;
+
+ if (of_property_read_bool(np, "linux,rs485-enabled-at-boot-time"))
+ rs485conf->flags |= SER_RS485_ENABLED;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(of_get_rs485_mode);
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 1775500294bb..3a89e8925722 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -501,4 +501,17 @@ static inline int uart_handle_break(struct uart_port *port)
(cflag) & CRTSCTS || \
!((cflag) & CLOCAL))

+/*
+ * Common device tree parsing helpers
+ */
+#ifdef CONFIG_OF_SERIAL
+int of_get_rs485_mode(struct device_node *np, struct serial_rs485 *rs485conf);
+#else
+static inline int of_get_rs485_mode(struct device_node *np,
+ struct serial_rs485 *rs485conf)
+{
+ return 1;
+}
+#endif
+
#endif /* LINUX_SERIAL_CORE_H */
--
2.11.0
Uwe Kleine-König
2017-07-18 10:59:43 UTC
Permalink
From: Sascha Hauer <***@pengutronix.de>

We just got a common helper for parsing the rs485 specific
device tree properties. Use it and drop the open coded parser.

Note that there is a small difference between the removed and the now
used implementation: The former cleared flags to 0 if rs485-rts-delay
was given, the common helper clears SER_RS485_RX_DURING_TX and
SER_RS485_ENABLED only but always which makes more sense.

Signed-off-by: Sascha Hauer <***@pengutronix.de>
[ukleinek: point out semantic change in commit log]
Acked-by: Nicolas Ferre <***@microchip.com>
Acked-by: Richard Genoud <***@gmail.com>
Signed-off-by: Uwe Kleine-König <u.kleine-***@pengutronix.de>
---
drivers/tty/serial/atmel_serial.c | 25 +------------------------
1 file changed, 1 insertion(+), 24 deletions(-)

diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index 7551cab438ff..04e55f010894 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -1667,29 +1667,6 @@ static void atmel_init_property(struct atmel_uart_port *atmel_port,
}
}

-static void atmel_init_rs485(struct uart_port *port,
- struct platform_device *pdev)
-{
- struct device_node *np = pdev->dev.of_node;
-
- struct serial_rs485 *rs485conf = &port->rs485;
- u32 rs485_delay[2];
-
- /* rs485 properties */
- if (of_property_read_u32_array(np, "rs485-rts-delay",
- rs485_delay, 2) == 0) {
- rs485conf->delay_rts_before_send = rs485_delay[0];
- rs485conf->delay_rts_after_send = rs485_delay[1];
- rs485conf->flags = 0;
- }
-
- if (of_get_property(np, "rs485-rx-during-tx", NULL))
- rs485conf->flags |= SER_RS485_RX_DURING_TX;
-
- if (of_get_property(np, "linux,rs485-enabled-at-boot-time", NULL))
- rs485conf->flags |= SER_RS485_ENABLED;
-}
-
static void atmel_set_ops(struct uart_port *port)
{
struct atmel_uart_port *atmel_port = to_atmel_uart_port(port);
@@ -2373,7 +2350,7 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port,
atmel_init_property(atmel_port, pdev);
atmel_set_ops(port);

- atmel_init_rs485(port, pdev);
+ of_get_rs485_mode(pdev->dev.of_node, &port->rs485);

port->iotype = UPIO_MEM;
port->flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP;
--
2.11.0
Uwe Kleine-König
2017-07-18 10:59:41 UTC
Permalink
There are a few device trees that specify one of the already optional
properties without also having the up to now required property
rs485-rts-delay. Additionally there is no technical reason to require
rs485-rts-delay and that's also what most drivers implement.

So give existing users and implementers a blessing and document
rs485-rts-delay as optional.

Signed-off-by: Uwe Kleine-König <u.kleine-***@pengutronix.de>
Acked-by: Rob Herring <***@kernel.org>
---
Documentation/devicetree/bindings/serial/rs485.txt | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/serial/rs485.txt b/Documentation/devicetree/bindings/serial/rs485.txt
index 32b1fa1f2a5b..b8415936dfdb 100644
--- a/Documentation/devicetree/bindings/serial/rs485.txt
+++ b/Documentation/devicetree/bindings/serial/rs485.txt
@@ -5,14 +5,13 @@ the built-in half-duplex mode.
The properties described hereafter shall be given to a half-duplex capable
UART node.

-Required properties:
+Optional properties:
- rs485-rts-delay: prop-encoded-array <a b> where:
* a is the delay between rts signal and beginning of data sent in milliseconds.
it corresponds to the delay before sending data.
* b is the delay between end of data sent and rts signal in milliseconds
it corresponds to the delay after sending data and actual release of the line.
-
-Optional properties:
+ If this property is not specified, <0 0> is assumed.
- linux,rs485-enabled-at-boot-time: empty property telling to enable the rs485
feature at boot time. It can be disabled later with proper ioctl.
- rs485-rx-during-tx: empty property that enables the receiving of data even
--
2.11.0
Uwe Kleine-König
2017-07-18 10:59:47 UTC
Permalink
From: Sascha Hauer <***@pengutronix.de>

This adds support for the rs485 specific properties defined in
Documentation/devicetree/bindings/serial/rs485.txt.

Signed-off-by: Sascha Hauer <***@pengutronix.de>
Signed-off-by: Uwe Kleine-König <u.kleine-***@pengutronix.de>
---
drivers/tty/serial/imx.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index bb5cd8ff7d86..88957f31d8ed 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -2059,6 +2059,8 @@ static int serial_imx_probe_dt(struct imx_port *sport,
if (of_get_property(np, "rts-gpios", NULL))
sport->have_rtsgpio = 1;

+ of_get_rs485_mode(np, &sport->port.rs485);
+
return 0;
}
#else
--
2.11.0
Uwe Kleine-König
2017-07-18 10:59:45 UTC
Permalink
From: Sascha Hauer <***@pengutronix.de>

We just got a common helper for parsing the rs485 specific
device tree properties. Use it and drop the open coded parser.

Signed-off-by: Sascha Hauer <***@pengutronix.de>
Signed-off-by: Uwe Kleine-König <u.kleine-***@pengutronix.de>
---
drivers/tty/serial/omap-serial.c | 13 +------------
1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index 1ea05ac57aa7..6d22097e6dd0 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -1607,7 +1607,6 @@ static int serial_omap_probe_rs485(struct uart_omap_port *up,
struct device_node *np)
{
struct serial_rs485 *rs485conf = &up->port.rs485;
- u32 rs485_delay[2];
enum of_gpio_flags flags;
int ret;

@@ -1638,17 +1637,7 @@ static int serial_omap_probe_rs485(struct uart_omap_port *up,
up->rts_gpio = -EINVAL;
}

- if (of_property_read_u32_array(np, "rs485-rts-delay",
- rs485_delay, 2) == 0) {
- rs485conf->delay_rts_before_send = rs485_delay[0];
- rs485conf->delay_rts_after_send = rs485_delay[1];
- }
-
- if (of_property_read_bool(np, "rs485-rx-during-tx"))
- rs485conf->flags |= SER_RS485_RX_DURING_TX;
-
- if (of_property_read_bool(np, "linux,rs485-enabled-at-boot-time"))
- rs485conf->flags |= SER_RS485_ENABLED;
+ of_get_rs485_mode(np, rs485conf);

return 0;
}
--
2.11.0
Uwe Kleine-König
2017-07-18 10:59:44 UTC
Permalink
From: Sascha Hauer <***@pengutronix.de>

We just got a common helper for parsing the rs485 specific
device tree properties. Use it and drop the open coded parser.

As a side effect this adds support for parsing rs485-rts-delay and
rs485-rx-during-tx. As the driver doesn't support this though, probing
fails if these are defined.

Signed-off-by: Sascha Hauer <***@pengutronix.de>
Signed-off-by: Uwe Kleine-König <u.kleine-***@pengutronix.de>
---
drivers/tty/serial/fsl_lpuart.c | 24 ++++++++++++++++++------
1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 4becfbf35c4c..cac81b143abe 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -2161,6 +2161,24 @@ static int lpuart_probe(struct platform_device *pdev)
return ret;
}

+ of_get_rs485_mode(np, &sport->port.rs485);
+
+ if (sport->port.rs485.flags & SER_RS485_RX_DURING_TX) {
+ dev_err(&pdev->dev, "driver doesn't support RX during TX\n");
+ return -ENOSYS;
+ }
+
+ if (sport->port.rs485.delay_rts_before_send ||
+ sport->port.rs485.delay_rts_after_send) {
+ dev_err(&pdev->dev, "driver doesn't support RTS delays\n");
+ return -ENOSYS;
+ }
+
+ if (sport->port.rs485.flags & SER_RS485_ENABLED) {
+ sport->port.rs485.flags |= SER_RS485_RTS_ON_SEND;
+ writeb(UARTMODEM_TXRTSE, sport->port.membase + UARTMODEM);
+ }
+
sport->dma_tx_chan = dma_request_slave_channel(sport->port.dev, "tx");
if (!sport->dma_tx_chan)
dev_info(sport->port.dev, "DMA tx channel request failed, "
@@ -2171,12 +2189,6 @@ static int lpuart_probe(struct platform_device *pdev)
dev_info(sport->port.dev, "DMA rx channel request failed, "
"operating without rx DMA\n");

- if (of_property_read_bool(np, "linux,rs485-enabled-at-boot-time")) {
- sport->port.rs485.flags |= SER_RS485_ENABLED;
- sport->port.rs485.flags |= SER_RS485_RTS_ON_SEND;
- writeb(UARTMODEM_TXRTSE, sport->port.membase + UARTMODEM);
- }
-
return 0;
}
--
2.11.0
Uwe Kleine-König
2017-07-18 10:59:46 UTC
Permalink
From: Sascha Hauer <***@pengutronix.de>

The i.MX driver defaulted to full duplex rs485 which is rather
unusual and doesn't match the default implemented in other drivers.

So change the default to half duplex.

Signed-off-by: Sascha Hauer <***@pengutronix.de>
Signed-off-by: Uwe Kleine-König <u.kleine-***@pengutronix.de>
---
drivers/tty/serial/imx.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 80934e7bd67f..bb5cd8ff7d86 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -2120,8 +2120,7 @@ static int serial_imx_probe(struct platform_device *pdev)
sport->port.fifosize = 32;
sport->port.ops = &imx_pops;
sport->port.rs485_config = imx_rs485_config;
- sport->port.rs485.flags =
- SER_RS485_RTS_ON_SEND | SER_RS485_RX_DURING_TX;
+ sport->port.rs485.flags = SER_RS485_RTS_ON_SEND;
sport->port.flags = UPF_BOOT_AUTOCONF;
init_timer(&sport->timer);
sport->timer.function = imx_timeout;
--
2.11.0
Uwe Kleine-König
2017-07-18 10:59:48 UTC
Permalink
Atmel USART, Freescale UARTs and OMAP UART all support the rs485 binding
described in rs485.txt, this commit just makes that explicit.

Acked-by: Nicolas Ferre <***@microchip.com>
Acked-by: Rob Herring <***@kernel.org>
Signed-off-by: Uwe Kleine-König <u.kleine-***@pengutronix.de>
---
Documentation/devicetree/bindings/serial/atmel-usart.txt | 1 +
Documentation/devicetree/bindings/serial/fsl-imx-uart.txt | 1 +
Documentation/devicetree/bindings/serial/fsl-lpuart.txt | 1 +
Documentation/devicetree/bindings/serial/omap_serial.txt | 1 +
4 files changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/serial/atmel-usart.txt b/Documentation/devicetree/bindings/serial/atmel-usart.txt
index e6e6142e33ac..7c0d6b2f53e4 100644
--- a/Documentation/devicetree/bindings/serial/atmel-usart.txt
+++ b/Documentation/devicetree/bindings/serial/atmel-usart.txt
@@ -24,6 +24,7 @@ Optional properties:
- dma-names: "rx" for RX channel, "tx" for TX channel.
- atmel,fifo-size: maximum number of data the RX and TX FIFOs can store for FIFO
capable USARTs.
+- rs485-rts-delay, rs485-rx-during-tx, linux,rs485-enabled-at-boot-time: see rs485.txt

<chip> compatible description:
- at91rm9200: legacy USART support
diff --git a/Documentation/devicetree/bindings/serial/fsl-imx-uart.txt b/Documentation/devicetree/bindings/serial/fsl-imx-uart.txt
index 574c3a2c77d5..860a9559839a 100644
--- a/Documentation/devicetree/bindings/serial/fsl-imx-uart.txt
+++ b/Documentation/devicetree/bindings/serial/fsl-imx-uart.txt
@@ -9,6 +9,7 @@ Optional properties:
- fsl,irda-mode : Indicate the uart supports irda mode
- fsl,dte-mode : Indicate the uart works in DTE mode. The uart works
in DCE mode by default.
+- rs485-rts-delay, rs485-rx-during-tx, linux,rs485-enabled-at-boot-time: see rs485.txt

Please check Documentation/devicetree/bindings/serial/serial.txt
for the complete list of generic properties.
diff --git a/Documentation/devicetree/bindings/serial/fsl-lpuart.txt b/Documentation/devicetree/bindings/serial/fsl-lpuart.txt
index a1252a047f78..59567b51cf09 100644
--- a/Documentation/devicetree/bindings/serial/fsl-lpuart.txt
+++ b/Documentation/devicetree/bindings/serial/fsl-lpuart.txt
@@ -16,6 +16,7 @@ Required properties:
Optional properties:
- dmas: A list of two dma specifiers, one for each entry in dma-names.
- dma-names: should contain "tx" and "rx".
+- rs485-rts-delay, rs485-rx-during-tx, linux,rs485-enabled-at-boot-time: see rs485.txt

Note: Optional properties for DMA support. Write them both or both not.

diff --git a/Documentation/devicetree/bindings/serial/omap_serial.txt b/Documentation/devicetree/bindings/serial/omap_serial.txt
index 7a71b5de77d6..43eac675f21f 100644
--- a/Documentation/devicetree/bindings/serial/omap_serial.txt
+++ b/Documentation/devicetree/bindings/serial/omap_serial.txt
@@ -19,6 +19,7 @@ Optional properties:
- dmas : DMA specifier, consisting of a phandle to the DMA controller
node and a DMA channel number.
- dma-names : "rx" for receive channel, "tx" for transmit channel.
+- rs485-rts-delay, rs485-rx-during-tx, linux,rs485-enabled-at-boot-time: see rs485.txt

Example:
--
2.11.0
Loading...