serial: core: Support common rs485 binding for RTS polarity
authorLukas Wunner <lukas@wunner.de>
Fri, 24 Nov 2017 22:26:40 +0000 (23:26 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 28 Nov 2017 15:05:19 +0000 (16:05 +0100)
When a driver invokes the uart_get_rs485_mode() helper, set the RTS
polarity to active high by default unless the newly introduced
"rs485-rts-active-low" property was specified.

imx contains a line to set the default RTS polarity to active high,
it is now superfluous and hence deleted.

omap-serial historically defaults to active low and supports an
"rs485-rts-active-high" property to inverse the polarity.
Retain that behavior for compatibility.

Cc: Mark Jackson <mpfj@newflow.co.uk>
Cc: Michał Oleszczyk <oleszczyk.m@gmail.com>
Cc: Rafael Gago Castano <rgc@hms.se>
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Acked-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/imx.c
drivers/tty/serial/omap-serial.c
drivers/tty/serial/serial_core.c

index aca3b7dbd09c8929952afd2f7549d06db64f5cb9..d2c7d88d5774156d1c49371b1760e066ff5d9ae3 100644 (file)
@@ -2060,7 +2060,6 @@ 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;
        sport->port.flags = UPF_BOOT_AUTOCONF;
        timer_setup(&sport->timer, imx_timeout, 0);
 
index 227347548fff61790e1f4974f2f5b19231e3d93b..56e683373d6d62cee46bbcfadd87aa442ad3a30d 100644 (file)
@@ -1613,10 +1613,13 @@ static int serial_omap_probe_rs485(struct uart_omap_port *up,
 
        uart_get_rs485_mode(up->dev, rs485conf);
 
-       if (of_property_read_bool(np, "rs485-rts-active-high"))
+       if (of_property_read_bool(np, "rs485-rts-active-high")) {
                rs485conf->flags |= SER_RS485_RTS_ON_SEND;
-       else
+               rs485conf->flags &= ~SER_RS485_RTS_AFTER_SEND;
+       } else {
+               rs485conf->flags &= ~SER_RS485_RTS_ON_SEND;
                rs485conf->flags |= SER_RS485_RTS_AFTER_SEND;
+       }
 
        /* check for tx enable gpio */
        up->rts_gpio = of_get_named_gpio_flags(np, "rts-gpio", 0, &flags);
index a59184a7afb03f2f7d63af0a2c7d9f86240603fa..f57969de2f1cb2c57401b12f8d9f7580de32ff3f 100644 (file)
@@ -3036,16 +3036,23 @@ void uart_get_rs485_mode(struct device *dev, struct serial_rs485 *rs485conf)
        }
 
        /*
-        * clear full-duplex and enabled flags to get to a defined state with
-        * the two following properties.
+        * Clear full-duplex and enabled flags, set RTS polarity to active high
+        * to get to a defined state with the following properties:
         */
-       rs485conf->flags &= ~(SER_RS485_RX_DURING_TX | SER_RS485_ENABLED);
+       rs485conf->flags &= ~(SER_RS485_RX_DURING_TX | SER_RS485_ENABLED |
+                             SER_RS485_RTS_AFTER_SEND);
+       rs485conf->flags |= SER_RS485_RTS_ON_SEND;
 
        if (device_property_read_bool(dev, "rs485-rx-during-tx"))
                rs485conf->flags |= SER_RS485_RX_DURING_TX;
 
        if (device_property_read_bool(dev, "linux,rs485-enabled-at-boot-time"))
                rs485conf->flags |= SER_RS485_ENABLED;
+
+       if (device_property_read_bool(dev, "rs485-rts-active-low")) {
+               rs485conf->flags &= ~SER_RS485_RTS_ON_SEND;
+               rs485conf->flags |= SER_RS485_RTS_AFTER_SEND;
+       }
 }
 EXPORT_SYMBOL_GPL(uart_get_rs485_mode);