serial: Add common rs485 device tree parsing function
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Wed, 13 Sep 2017 08:18:27 +0000 (10:18 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 18 Sep 2017 16:36:25 +0000 (18:36 +0200)
Several drivers have the same device tree parsing code. Create
a common helper function for it.

This patch bases on work done by Sascha Hauer.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/serial_core.c
include/linux/serial_core.h

index 3a14ccc..f4e6c86 100644 (file)
@@ -3026,5 +3026,41 @@ EXPORT_SYMBOL(uart_resume_port);
 EXPORT_SYMBOL(uart_add_one_port);
 EXPORT_SYMBOL(uart_remove_one_port);
 
+/**
+ * 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.
+ */
+void of_get_rs485_mode(struct device_node *np, struct serial_rs485 *rs485conf)
+{
+       u32 rs485_delay[2];
+       int ret;
+
+       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;
+}
+EXPORT_SYMBOL_GPL(of_get_rs485_mode);
+
 MODULE_DESCRIPTION("Serial driver core");
 MODULE_LICENSE("GPL");
index 5553e04..37b044e 100644 (file)
@@ -501,4 +501,9 @@ static inline int uart_handle_break(struct uart_port *port)
                                         (cflag) & CRTSCTS || \
                                         !((cflag) & CLOCAL))
 
+/*
+ * Common device tree parsing helpers
+ */
+void of_get_rs485_mode(struct device_node *np, struct serial_rs485 *rs485conf);
+
 #endif /* LINUX_SERIAL_CORE_H */