From: Uwe Kleine-König Date: Wed, 13 Sep 2017 08:18:27 +0000 (+0200) Subject: serial: Add common rs485 device tree parsing function X-Git-Tag: v4.19~2225^2~104 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ef838a81dd4de1e08454406812e42d7b9b417c4d;p=platform%2Fkernel%2Flinux-rpi.git 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 Signed-off-by: Greg Kroah-Hartman --- diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index 3a14ccc..f4e6c866 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"); diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index 5553e04..37b044e 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -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 */