aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Wunner <lukas@wunner.de>2017-11-24 17:26:40 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-11-28 10:04:57 -0500
commit743f93f822be1b54f3f9bd53d13f02192e65ce0b (patch)
tree3669b746f6b68b6f9c9f77bbcdf35233dd554f52
parentcda64188ca918fcddc8c6e89bbee5a38b029117a (diff)
serial: Make retrieval of rs485 properties platform-agnostic
Commit ef838a81dd4d ("serial: Add common rs485 device tree parsing function") consolidated retrieval of rs485 OF properties in a common helper function but did not #ifdef it to CONFIG_OF. The function is therefore included on ACPI platforms as well even though it's not used. On the other hand ACPI platforms with rs485 do exist (e.g. Siemens IOT2040) and they may leverage _DSD to store rs485 properties. Likewise, UART platform devices instantiated from an MFD should be able to specify rs485 properties. In fact, the tty subsystem maintainer had asked for a "generic" function during review of commit ef838a81dd4d: https://marc.info/?l=linux-serial&m=150143441725194&w=4 Thus, instead of constraining the helper to OF platforms, make it platform-agnostic by converting it to device_property_*() functions and renaming it accordingly. In imx.c, move the invocation of uart_get_rs485_mode() from serial_imx_probe_dt() to serial_imx_probe() so that it also gets called for non-OF devices. In omap-serial.c, move its invocation further up within serial_omap_probe_rs485() so that the RTS polarity can be overridden with the driver-specific "rs485-rts-active-high" property once we introduce a generic "rs485-rts-active-low" property. Cc: Jan Kiszka <jan.kiszka@siemens.com> Cc: Richard Genoud <richard.genoud@gmail.com> 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>
-rw-r--r--drivers/tty/serial/atmel_serial.c2
-rw-r--r--drivers/tty/serial/fsl_lpuart.c2
-rw-r--r--drivers/tty/serial/imx.c4
-rw-r--r--drivers/tty/serial/omap-serial.c4
-rw-r--r--drivers/tty/serial/serial_core.c15
-rw-r--r--include/linux/serial_core.h6
6 files changed, 15 insertions, 18 deletions
diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c
index efa25611ca0c..df46a9e88c34 100644
--- a/drivers/tty/serial/atmel_serial.c
+++ b/drivers/tty/serial/atmel_serial.c
@@ -2345,7 +2345,7 @@ static int atmel_init_port(struct atmel_uart_port *atmel_port,
2345 atmel_init_property(atmel_port, pdev); 2345 atmel_init_property(atmel_port, pdev);
2346 atmel_set_ops(port); 2346 atmel_set_ops(port);
2347 2347
2348 of_get_rs485_mode(pdev->dev.of_node, &port->rs485); 2348 uart_get_rs485_mode(&pdev->dev, &port->rs485);
2349 2349
2350 port->iotype = UPIO_MEM; 2350 port->iotype = UPIO_MEM;
2351 port->flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP; 2351 port->flags = UPF_BOOT_AUTOCONF | UPF_IOREMAP;
diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 1c4d3f387138..38e76f95490e 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -2206,7 +2206,7 @@ static int lpuart_probe(struct platform_device *pdev)
2206 if (ret) 2206 if (ret)
2207 goto failed_attach_port; 2207 goto failed_attach_port;
2208 2208
2209 of_get_rs485_mode(np, &sport->port.rs485); 2209 uart_get_rs485_mode(&pdev->dev, &sport->port.rs485);
2210 2210
2211 if (sport->port.rs485.flags & SER_RS485_RX_DURING_TX) { 2211 if (sport->port.rs485.flags & SER_RS485_RX_DURING_TX) {
2212 dev_err(&pdev->dev, "driver doesn't support RX during TX\n"); 2212 dev_err(&pdev->dev, "driver doesn't support RX during TX\n");
diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
index 16311a24b483..aca3b7dbd09c 100644
--- a/drivers/tty/serial/imx.c
+++ b/drivers/tty/serial/imx.c
@@ -1999,8 +1999,6 @@ static int serial_imx_probe_dt(struct imx_port *sport,
1999 if (of_get_property(np, "rts-gpios", NULL)) 1999 if (of_get_property(np, "rts-gpios", NULL))
2000 sport->have_rtsgpio = 1; 2000 sport->have_rtsgpio = 1;
2001 2001
2002 of_get_rs485_mode(np, &sport->port.rs485);
2003
2004 return 0; 2002 return 0;
2005} 2003}
2006#else 2004#else
@@ -2093,6 +2091,8 @@ static int serial_imx_probe(struct platform_device *pdev)
2093 return ret; 2091 return ret;
2094 } 2092 }
2095 2093
2094 uart_get_rs485_mode(&pdev->dev, &sport->port.rs485);
2095
2096 /* Disable interrupts before requesting them */ 2096 /* Disable interrupts before requesting them */
2097 reg = readl_relaxed(sport->port.membase + UCR1); 2097 reg = readl_relaxed(sport->port.membase + UCR1);
2098 reg &= ~(UCR1_ADEN | UCR1_TRDYEN | UCR1_IDEN | UCR1_RRDYEN | 2098 reg &= ~(UCR1_ADEN | UCR1_TRDYEN | UCR1_IDEN | UCR1_RRDYEN |
diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index 53d59e9b944a..227347548fff 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -1611,6 +1611,8 @@ static int serial_omap_probe_rs485(struct uart_omap_port *up,
1611 if (!np) 1611 if (!np)
1612 return 0; 1612 return 0;
1613 1613
1614 uart_get_rs485_mode(up->dev, rs485conf);
1615
1614 if (of_property_read_bool(np, "rs485-rts-active-high")) 1616 if (of_property_read_bool(np, "rs485-rts-active-high"))
1615 rs485conf->flags |= SER_RS485_RTS_ON_SEND; 1617 rs485conf->flags |= SER_RS485_RTS_ON_SEND;
1616 else 1618 else
@@ -1632,8 +1634,6 @@ static int serial_omap_probe_rs485(struct uart_omap_port *up,
1632 up->rts_gpio = -EINVAL; 1634 up->rts_gpio = -EINVAL;
1633 } 1635 }
1634 1636
1635 of_get_rs485_mode(np, rs485conf);
1636
1637 return 0; 1637 return 0;
1638} 1638}
1639 1639
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 854995e1cae7..a59184a7afb0 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -3013,19 +3013,20 @@ EXPORT_SYMBOL(uart_add_one_port);
3013EXPORT_SYMBOL(uart_remove_one_port); 3013EXPORT_SYMBOL(uart_remove_one_port);
3014 3014
3015/** 3015/**
3016 * of_get_rs485_mode() - Implement parsing rs485 properties 3016 * uart_get_rs485_mode() - retrieve rs485 properties for given uart
3017 * @np: uart node 3017 * @dev: uart device
3018 * @rs485conf: output parameter 3018 * @rs485conf: output parameter
3019 * 3019 *
3020 * This function implements the device tree binding described in 3020 * This function implements the device tree binding described in
3021 * Documentation/devicetree/bindings/serial/rs485.txt. 3021 * Documentation/devicetree/bindings/serial/rs485.txt.
3022 */ 3022 */
3023void of_get_rs485_mode(struct device_node *np, struct serial_rs485 *rs485conf) 3023void uart_get_rs485_mode(struct device *dev, struct serial_rs485 *rs485conf)
3024{ 3024{
3025 u32 rs485_delay[2]; 3025 u32 rs485_delay[2];
3026 int ret; 3026 int ret;
3027 3027
3028 ret = of_property_read_u32_array(np, "rs485-rts-delay", rs485_delay, 2); 3028 ret = device_property_read_u32_array(dev, "rs485-rts-delay",
3029 rs485_delay, 2);
3029 if (!ret) { 3030 if (!ret) {
3030 rs485conf->delay_rts_before_send = rs485_delay[0]; 3031 rs485conf->delay_rts_before_send = rs485_delay[0];
3031 rs485conf->delay_rts_after_send = rs485_delay[1]; 3032 rs485conf->delay_rts_after_send = rs485_delay[1];
@@ -3040,13 +3041,13 @@ void of_get_rs485_mode(struct device_node *np, struct serial_rs485 *rs485conf)
3040 */ 3041 */
3041 rs485conf->flags &= ~(SER_RS485_RX_DURING_TX | SER_RS485_ENABLED); 3042 rs485conf->flags &= ~(SER_RS485_RX_DURING_TX | SER_RS485_ENABLED);
3042 3043
3043 if (of_property_read_bool(np, "rs485-rx-during-tx")) 3044 if (device_property_read_bool(dev, "rs485-rx-during-tx"))
3044 rs485conf->flags |= SER_RS485_RX_DURING_TX; 3045 rs485conf->flags |= SER_RS485_RX_DURING_TX;
3045 3046
3046 if (of_property_read_bool(np, "linux,rs485-enabled-at-boot-time")) 3047 if (device_property_read_bool(dev, "linux,rs485-enabled-at-boot-time"))
3047 rs485conf->flags |= SER_RS485_ENABLED; 3048 rs485conf->flags |= SER_RS485_ENABLED;
3048} 3049}
3049EXPORT_SYMBOL_GPL(of_get_rs485_mode); 3050EXPORT_SYMBOL_GPL(uart_get_rs485_mode);
3050 3051
3051MODULE_DESCRIPTION("Serial driver core"); 3052MODULE_DESCRIPTION("Serial driver core");
3052MODULE_LICENSE("GPL"); 3053MODULE_LICENSE("GPL");
diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h
index 37b044e78333..b60b225c0a59 100644
--- a/include/linux/serial_core.h
+++ b/include/linux/serial_core.h
@@ -501,9 +501,5 @@ static inline int uart_handle_break(struct uart_port *port)
501 (cflag) & CRTSCTS || \ 501 (cflag) & CRTSCTS || \
502 !((cflag) & CLOCAL)) 502 !((cflag) & CLOCAL))
503 503
504/* 504void uart_get_rs485_mode(struct device *dev, struct serial_rs485 *rs485conf);
505 * Common device tree parsing helpers
506 */
507void of_get_rs485_mode(struct device_node *np, struct serial_rs485 *rs485conf);
508
509#endif /* LINUX_SERIAL_CORE_H */ 505#endif /* LINUX_SERIAL_CORE_H */