diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2017-09-13 11:18:27 +0300 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2017-09-18 19:36:25 +0300 |
commit | ef838a81dd4de1e08454406812e42d7b9b417c4d (patch) | |
tree | f4b6199f8e7add38f65e5dd62a0c425db7c9fec2 /drivers/tty/serial/serial_core.c | |
parent | c45e2d2547cb2ba0ee8391d8cb2fd2f7cdc016f5 (diff) | |
download | linux-ef838a81dd4de1e08454406812e42d7b9b417c4d.tar.xz |
serial: Add common rs485 device tree parsing function
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>
Diffstat (limited to 'drivers/tty/serial/serial_core.c')
-rw-r--r-- | drivers/tty/serial/serial_core.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 3a14cccbd7ff..f4e6c8662987 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -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"); |