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