ramips: drop support for kernel 4.14
[openwrt/openwrt.git] / target / linux / generic / backport-4.14 / 950-tty-serial-exar-generalize-rs485-setup.patch
1 From 9d9398944488cd3a3e1e0912b26fbc4d5921e547 Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Mon, 4 Jun 2018 23:33:07 +0200
4 Subject: [PATCH] tty: serial: exar: generalize RS485 setup
5
6 Move the non-board-specific part of the RS485 initialization from
7 iot2040_rs485_config function to a new generic function used also for
8 other boards.
9 This allows using TIOCGRS485 and TIOCSRS485 on boards (such as mPCIe
10 serial IO modules) which are hard-wired to RS485 or have jumpers for
11 their configurations.
12
13 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
14 Reviewed-by: Jan Kiszka <jan.kiszka@siemens.com>
15 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
16 ---
17 drivers/tty/serial/8250/8250_exar.c | 38 +++++++++++++++++++----------
18 1 file changed, 25 insertions(+), 13 deletions(-)
19
20 --- a/drivers/tty/serial/8250/8250_exar.c
21 +++ b/drivers/tty/serial/8250/8250_exar.c
22 @@ -293,8 +293,32 @@ static int xr17v35x_register_gpio(struct
23 return 0;
24 }
25
26 +static int generic_rs485_config(struct uart_port *port,
27 + struct serial_rs485 *rs485)
28 +{
29 + bool is_rs485 = !!(rs485->flags & SER_RS485_ENABLED);
30 + u8 __iomem *p = port->membase;
31 + u8 value;
32 +
33 + value = readb(p + UART_EXAR_FCTR);
34 + if (is_rs485)
35 + value |= UART_FCTR_EXAR_485;
36 + else
37 + value &= ~UART_FCTR_EXAR_485;
38 +
39 + writeb(value, p + UART_EXAR_FCTR);
40 +
41 + if (is_rs485)
42 + writeb(UART_EXAR_RS485_DLY(4), p + UART_MSR);
43 +
44 + port->rs485 = *rs485;
45 +
46 + return 0;
47 +}
48 +
49 static const struct exar8250_platform exar8250_default_platform = {
50 .register_gpio = xr17v35x_register_gpio,
51 + .rs485_config = generic_rs485_config,
52 };
53
54 static int iot2040_rs485_config(struct uart_port *port,
55 @@ -327,19 +351,7 @@ static int iot2040_rs485_config(struct u
56 value |= mode;
57 writeb(value, p + UART_EXAR_MPIOLVL_7_0);
58
59 - value = readb(p + UART_EXAR_FCTR);
60 - if (is_rs485)
61 - value |= UART_FCTR_EXAR_485;
62 - else
63 - value &= ~UART_FCTR_EXAR_485;
64 - writeb(value, p + UART_EXAR_FCTR);
65 -
66 - if (is_rs485)
67 - writeb(UART_EXAR_RS485_DLY(4), p + UART_MSR);
68 -
69 - port->rs485 = *rs485;
70 -
71 - return 0;
72 + return generic_rs485_config(port, rs485);
73 }
74
75 static const struct property_entry iot2040_gpio_properties[] = {