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>
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.
16 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
18 drivers/tty/serial/8250/8250_exar.c | 38 +++++++++++++++++++----------
19 1 file changed, 25 insertions(+), 13 deletions(-)
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,
29 +static int generic_rs485_config(struct uart_port *port,
30 + struct serial_rs485 *rs485)
32 + bool is_rs485 = !!(rs485->flags & SER_RS485_ENABLED);
33 + u8 __iomem *p = port->membase;
36 + value = readb(p + UART_EXAR_FCTR);
38 + value |= UART_FCTR_EXAR_485;
40 + value &= ~UART_FCTR_EXAR_485;
42 + writeb(value, p + UART_EXAR_FCTR);
45 + writeb(UART_EXAR_RS485_DLY(4), p + UART_MSR);
47 + port->rs485 = *rs485;
52 static const struct exar8250_platform exar8250_default_platform = {
53 .register_gpio = xr17v35x_register_gpio,
54 + .rs485_config = generic_rs485_config,
57 static int iot2040_rs485_config(struct uart_port *port,
58 @@ -309,19 +333,7 @@ static int iot2040_rs485_config(struct uart_port *port,
60 writeb(value, p + UART_EXAR_MPIOLVL_7_0);
62 - value = readb(p + UART_EXAR_FCTR);
64 - value |= UART_FCTR_EXAR_485;
66 - value &= ~UART_FCTR_EXAR_485;
67 - writeb(value, p + UART_EXAR_FCTR);
70 - writeb(UART_EXAR_RS485_DLY(4), p + UART_MSR);
72 - port->rs485 = *rs485;
75 + return generic_rs485_config(port, rs485);
78 static const struct property_entry iot2040_gpio_properties[] = {