* [PATCH v4 0/9] Add and make use of a common rs485 device tree parsing function
@ 2017-07-18 10:59 Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 1/9] serial: fsl_lpuart: clear unsupported options in .rs485_config() Uwe Kleine-König
` (8 more replies)
0 siblings, 9 replies; 14+ messages in thread
From: Uwe Kleine-König @ 2017-07-18 10:59 UTC (permalink / raw)
To: linux-arm-kernel
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
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v4 1/9] serial: fsl_lpuart: clear unsupported options in .rs485_config()
2017-07-18 10:59 [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 ` Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 2/9] dt-bindings: serial/rs485: make rs485-rts-delay optional Uwe Kleine-König
` (7 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: Uwe Kleine-König @ 2017-07-18 10:59 UTC (permalink / raw)
To: linux-arm-kernel
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-koenig@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
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v4 2/9] dt-bindings: serial/rs485: make rs485-rts-delay optional
2017-07-18 10:59 [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 ` [PATCH v4 1/9] serial: fsl_lpuart: clear unsupported options in .rs485_config() Uwe Kleine-König
@ 2017-07-18 10:59 ` Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 3/9] serial: Add common rs485 device tree parsing function Uwe Kleine-König
` (6 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: Uwe Kleine-König @ 2017-07-18 10:59 UTC (permalink / raw)
To: linux-arm-kernel
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-koenig@pengutronix.de>
Acked-by: Rob Herring <robh@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
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v4 3/9] serial: Add common rs485 device tree parsing function
2017-07-18 10:59 [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 ` [PATCH v4 1/9] serial: fsl_lpuart: clear unsupported options in .rs485_config() Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 2/9] dt-bindings: serial/rs485: make rs485-rts-delay optional Uwe Kleine-König
@ 2017-07-18 10:59 ` Uwe Kleine-König
2017-07-30 14:49 ` Greg KH
2017-07-18 10:59 ` [PATCH v4 4/9] serial: atmel: Use " Uwe Kleine-König
` (5 subsequent siblings)
8 siblings, 1 reply; 14+ messages in thread
From: Uwe Kleine-König @ 2017-07-18 10:59 UTC (permalink / raw)
To: linux-arm-kernel
From: Sascha Hauer <s.hauer@pengutronix.de>
Several drivers have the same device tree parsing code. Create
a common helper function for it.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
[ukl: implement default <0 0> for rts-delay, unset unspecified flags]
Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@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
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v4 4/9] serial: atmel: Use common rs485 device tree parsing function
2017-07-18 10:59 [PATCH v4 0/9] Add and make use of a common rs485 device tree parsing function Uwe Kleine-König
` (2 preceding siblings ...)
2017-07-18 10:59 ` [PATCH v4 3/9] serial: Add common rs485 device tree parsing function Uwe Kleine-König
@ 2017-07-18 10:59 ` Uwe Kleine-König
2017-07-30 14:50 ` Greg KH
2017-07-18 10:59 ` [PATCH v4 5/9] serial: fsl_lpuart: " Uwe Kleine-König
` (4 subsequent siblings)
8 siblings, 1 reply; 14+ messages in thread
From: Uwe Kleine-König @ 2017-07-18 10:59 UTC (permalink / raw)
To: linux-arm-kernel
From: Sascha Hauer <s.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 <s.hauer@pengutronix.de>
[ukleinek: point out semantic change in commit log]
Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
Acked-by: Richard Genoud <richard.genoud@gmail.com>
Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@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
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v4 5/9] serial: fsl_lpuart: Use common rs485 device tree parsing function
2017-07-18 10:59 [PATCH v4 0/9] Add and make use of a common rs485 device tree parsing function Uwe Kleine-König
` (3 preceding siblings ...)
2017-07-18 10:59 ` [PATCH v4 4/9] serial: atmel: Use " Uwe Kleine-König
@ 2017-07-18 10:59 ` Uwe Kleine-König
2017-07-30 14:50 ` Greg KH
2017-07-18 10:59 ` [PATCH v4 6/9] serial: omap-serial: " Uwe Kleine-König
` (3 subsequent siblings)
8 siblings, 1 reply; 14+ messages in thread
From: Uwe Kleine-König @ 2017-07-18 10:59 UTC (permalink / raw)
To: linux-arm-kernel
From: Sascha Hauer <s.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 <s.hauer@pengutronix.de>
Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@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
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v4 6/9] serial: omap-serial: Use common rs485 device tree parsing function
2017-07-18 10:59 [PATCH v4 0/9] Add and make use of a common rs485 device tree parsing function Uwe Kleine-König
` (4 preceding siblings ...)
2017-07-18 10:59 ` [PATCH v4 5/9] serial: fsl_lpuart: " Uwe Kleine-König
@ 2017-07-18 10:59 ` Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 7/9] serial: imx: default to half duplex rs485 Uwe Kleine-König
` (2 subsequent siblings)
8 siblings, 0 replies; 14+ messages in thread
From: Uwe Kleine-König @ 2017-07-18 10:59 UTC (permalink / raw)
To: linux-arm-kernel
From: Sascha Hauer <s.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 <s.hauer@pengutronix.de>
Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@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
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v4 7/9] serial: imx: default to half duplex rs485
2017-07-18 10:59 [PATCH v4 0/9] Add and make use of a common rs485 device tree parsing function Uwe Kleine-König
` (5 preceding siblings ...)
2017-07-18 10:59 ` [PATCH v4 6/9] serial: omap-serial: " Uwe Kleine-König
@ 2017-07-18 10:59 ` Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 8/9] serial: imx: Use common rs485 device tree parsing function Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 9/9] dt-bindings: serial: document rs485 bindings for various devices Uwe Kleine-König
8 siblings, 0 replies; 14+ messages in thread
From: Uwe Kleine-König @ 2017-07-18 10:59 UTC (permalink / raw)
To: linux-arm-kernel
From: Sascha Hauer <s.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 <s.hauer@pengutronix.de>
Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@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
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v4 8/9] serial: imx: Use common rs485 device tree parsing function
2017-07-18 10:59 [PATCH v4 0/9] Add and make use of a common rs485 device tree parsing function Uwe Kleine-König
` (6 preceding siblings ...)
2017-07-18 10:59 ` [PATCH v4 7/9] serial: imx: default to half duplex rs485 Uwe Kleine-König
@ 2017-07-18 10:59 ` Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 9/9] dt-bindings: serial: document rs485 bindings for various devices Uwe Kleine-König
8 siblings, 0 replies; 14+ messages in thread
From: Uwe Kleine-König @ 2017-07-18 10:59 UTC (permalink / raw)
To: linux-arm-kernel
From: Sascha Hauer <s.hauer@pengutronix.de>
This adds support for the rs485 specific properties defined in
Documentation/devicetree/bindings/serial/rs485.txt.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@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
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v4 9/9] dt-bindings: serial: document rs485 bindings for various devices
2017-07-18 10:59 [PATCH v4 0/9] Add and make use of a common rs485 device tree parsing function Uwe Kleine-König
` (7 preceding siblings ...)
2017-07-18 10:59 ` [PATCH v4 8/9] serial: imx: Use common rs485 device tree parsing function Uwe Kleine-König
@ 2017-07-18 10:59 ` Uwe Kleine-König
8 siblings, 0 replies; 14+ messages in thread
From: Uwe Kleine-König @ 2017-07-18 10:59 UTC (permalink / raw)
To: linux-arm-kernel
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 <nicolas.ferre@microchip.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@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
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH v4 3/9] serial: Add common rs485 device tree parsing function
2017-07-18 10:59 ` [PATCH v4 3/9] serial: Add common rs485 device tree parsing function Uwe Kleine-König
@ 2017-07-30 14:49 ` Greg KH
2017-07-31 7:42 ` Uwe Kleine-König
0 siblings, 1 reply; 14+ messages in thread
From: Greg KH @ 2017-07-30 14:49 UTC (permalink / raw)
To: linux-arm-kernel
On Tue, Jul 18, 2017 at 12:59:42PM +0200, Uwe Kleine-K?nig wrote:
> From: Sascha Hauer <s.hauer@pengutronix.de>
>
> Several drivers have the same device tree parsing code. Create
> a common helper function for it.
>
> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> [ukl: implement default <0 0> for rts-delay, unset unspecified flags]
> Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
> Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de>
> ---
> drivers/tty/serial/Kconfig | 4 ++++
> drivers/tty/serial/Makefile | 2 ++
> drivers/tty/serial/of.c | 47 +++++++++++++++++++++++++++++++++++++++++++++
Why is this a separate file, with a Kconfig option that is always
enabled? Why not just add the single function to the serial core?
> +/**
> + * 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.
1 is not an error code :(
Return a proper error please.
> + */
> +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;
Again, a real error.
And why not have a "generic" firmware function for this that defaults to
the of_ for that platform type if present? What's the odds that acpi
will need/want this soon anyway?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v4 4/9] serial: atmel: Use common rs485 device tree parsing function
2017-07-18 10:59 ` [PATCH v4 4/9] serial: atmel: Use " Uwe Kleine-König
@ 2017-07-30 14:50 ` Greg KH
0 siblings, 0 replies; 14+ messages in thread
From: Greg KH @ 2017-07-30 14:50 UTC (permalink / raw)
To: linux-arm-kernel
On Tue, Jul 18, 2017 at 12:59:43PM +0200, Uwe Kleine-K?nig wrote:
> From: Sascha Hauer <s.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 <s.hauer@pengutronix.de>
> [ukleinek: point out semantic change in commit log]
> Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
> Acked-by: Richard Genoud <richard.genoud@gmail.com>
> Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@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);
No error checking?
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v4 5/9] serial: fsl_lpuart: Use common rs485 device tree parsing function
2017-07-18 10:59 ` [PATCH v4 5/9] serial: fsl_lpuart: " Uwe Kleine-König
@ 2017-07-30 14:50 ` Greg KH
0 siblings, 0 replies; 14+ messages in thread
From: Greg KH @ 2017-07-30 14:50 UTC (permalink / raw)
To: linux-arm-kernel
On Tue, Jul 18, 2017 at 12:59:44PM +0200, Uwe Kleine-K?nig wrote:
> From: Sascha Hauer <s.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 <s.hauer@pengutronix.de>
> Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@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);
error checking?
Elsewhere in this series as well.
Also, why did you not cc: me on this series so I am sure to see it?
thanks,
greg k-h
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH v4 3/9] serial: Add common rs485 device tree parsing function
2017-07-30 14:49 ` Greg KH
@ 2017-07-31 7:42 ` Uwe Kleine-König
0 siblings, 0 replies; 14+ messages in thread
From: Uwe Kleine-König @ 2017-07-31 7:42 UTC (permalink / raw)
To: linux-arm-kernel
On Sun, Jul 30, 2017 at 07:49:47AM -0700, Greg KH wrote:
> On Tue, Jul 18, 2017 at 12:59:42PM +0200, Uwe Kleine-K?nig wrote:
> > From: Sascha Hauer <s.hauer@pengutronix.de>
> >
> > Several drivers have the same device tree parsing code. Create
> > a common helper function for it.
> >
> > Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
> > [ukl: implement default <0 0> for rts-delay, unset unspecified flags]
> > Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com>
> > Signed-off-by: Uwe Kleine-K?nig <u.kleine-koenig@pengutronix.de>
> > ---
> > drivers/tty/serial/Kconfig | 4 ++++
> > drivers/tty/serial/Makefile | 2 ++
> > drivers/tty/serial/of.c | 47 +++++++++++++++++++++++++++++++++++++++++++++
>
> Why is this a separate file, with a Kconfig option that is always
> enabled? Why not just add the single function to the serial core?
Probably just a matter of taste. If you prefer I can put it into
drivers/tty/serial/serial_core.c
> > +/**
> > + * 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.
>
> 1 is not an error code :(
>
> Return a proper error please.
Well, it's not an error. These properties are optional and if I return
(say) -ENOENT in this case, a caller looks as follows:
ret = of_get_rs485_mode(...);
if (ret == -ENOENT) {
/*
* hmm, does this mean there are no rs485 properties, or
* is this a different error that I should propagate
* because there is a problem with the device tree?
* I'm optimistic and assume the former.
* As of_get_rs485_mode already did everything
* necessary, there is no need to do anything else.
*/
} else if (ret < 0) {
return ret;
}
With the semantic I chose it is just:
ret = of_get_rs485_mode(...);
if (ret < 0)
return ret;
without any guessing.
> > + */
> > +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;
>
> Again, a real error.
OK, I could agree to return -ENOSYS here. I predict I get complaints
about this though and people will do:
ret = of_get_rs485_mode(...);
if (ret == -ENOSYS) {
/* ignore */
} else if (ret < 0) {
return ret;
}
which one might consider troublesome or even wrong. (See the same
discussions about 22c403676dbbb7c6f186099527af7f065498ef45 where I
wanted to keep -ENOSYS.)
> And why not have a "generic" firmware function for this that defaults to
> the of_ for that platform type if present? What's the odds that acpi
> will need/want this soon anyway?
I don't know about ACPI and all systems I care about are using dt. So
I'd suggest we stick to dt and switch to "generic" if and when the need
arises?
Best regards
Uwe
--
Pengutronix e.K. | Uwe Kleine-K?nig |
Industrial Linux Solutions | http://www.pengutronix.de/ |
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2017-07-31 7:42 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-18 10:59 [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 ` [PATCH v4 1/9] serial: fsl_lpuart: clear unsupported options in .rs485_config() Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 2/9] dt-bindings: serial/rs485: make rs485-rts-delay optional Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 3/9] serial: Add common rs485 device tree parsing function Uwe Kleine-König
2017-07-30 14:49 ` Greg KH
2017-07-31 7:42 ` Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 4/9] serial: atmel: Use " Uwe Kleine-König
2017-07-30 14:50 ` Greg KH
2017-07-18 10:59 ` [PATCH v4 5/9] serial: fsl_lpuart: " Uwe Kleine-König
2017-07-30 14:50 ` Greg KH
2017-07-18 10:59 ` [PATCH v4 6/9] serial: omap-serial: " Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 7/9] serial: imx: default to half duplex rs485 Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 8/9] serial: imx: Use common rs485 device tree parsing function Uwe Kleine-König
2017-07-18 10:59 ` [PATCH v4 9/9] dt-bindings: serial: document rs485 bindings for various devices Uwe Kleine-König
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).