serial: Add uart_rs485_config()
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Mon, 6 Jun 2022 10:03:58 +0000 (13:03 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 10 Jun 2022 11:49:24 +0000 (13:49 +0200)
A few serial drivers make a call to rs485_config() themselves (all
these seem to relate to init). Convert them all to use a common helper
which makes it easy to make adjustments on tasks related to it as
serial_rs485 struct sanitization is going to be added.

In pci_fintek_setup() (in 8250_pci.c), the rs485_config() call was made
with NULL, however, it can be changed to pass uart_port's rs485 struct.
No other callers should pass NULL into rs485_config() so the NULL check
can now be eliminated.

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://lore.kernel.org/r/20220606100433.13793-2-ilpo.jarvinen@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/8250/8250_pci.c
drivers/tty/serial/8250/8250_port.c
drivers/tty/serial/fsl_lpuart.c
drivers/tty/serial/imx.c
drivers/tty/serial/serial_core.c
include/linux/serial_core.h

index a17619d..fb0a49e 100644 (file)
@@ -1562,9 +1562,7 @@ static int pci_fintek_rs485_config(struct uart_port *port,
 
        pci_read_config_byte(pci_dev, 0x40 + 8 * *index + 7, &setting);
 
-       if (!rs485)
-               rs485 = &port->rs485;
-       else if (rs485->flags & SER_RS485_ENABLED)
+       if (rs485->flags & SER_RS485_ENABLED)
                memset(rs485->padding, 0, sizeof(rs485->padding));
        else
                memset(rs485, 0, sizeof(*rs485));
@@ -1689,7 +1687,7 @@ static int pci_fintek_init(struct pci_dev *dev)
                         * pciserial_resume_ports()
                         */
                        port = serial8250_get_port(priv->line[i]);
-                       pci_fintek_rs485_config(&port->port, NULL);
+                       uart_rs485_config(&port->port);
                } else {
                        /* First init without port data
                         * force init to RS232 Mode
index 30e0aaf..af550a4 100644 (file)
@@ -3191,7 +3191,7 @@ static void serial8250_config_port(struct uart_port *port, int flags)
                autoconfig(up);
 
        if (port->rs485.flags & SER_RS485_ENABLED)
-               port->rs485_config(port, &port->rs485);
+               uart_rs485_config(port);
 
        /* if access method is AU, it is a 16550 with a quirk */
        if (port->type == PORT_16550A && port->iotype == UPIO_AU)
index 0d6e62f..509a791 100644 (file)
@@ -2724,7 +2724,7 @@ static int lpuart_probe(struct platform_device *pdev)
            sport->port.rs485.delay_rts_after_send)
                dev_err(&pdev->dev, "driver doesn't support RTS delays\n");
 
-       sport->port.rs485_config(&sport->port, &sport->port.rs485);
+       uart_rs485_config(&sport->port);
 
        ret = devm_request_irq(&pdev->dev, sport->port.irq, handler, 0,
                                DRIVER_NAME, sport);
index 30edb35..17fb9a5 100644 (file)
@@ -2338,7 +2338,7 @@ static int imx_uart_probe(struct platform_device *pdev)
                dev_err(&pdev->dev,
                        "low-active RTS not possible when receiver is off, enabling receiver\n");
 
-       imx_uart_rs485_config(&sport->port, &sport->port.rs485);
+       uart_rs485_config(&sport->port);
 
        /* Disable interrupts before requesting them */
        ucr1 = imx_uart_readl(sport, UCR1);
index 9a85b41..8466181 100644 (file)
@@ -1276,6 +1276,12 @@ static int uart_get_icount(struct tty_struct *tty,
        return 0;
 }
 
+int uart_rs485_config(struct uart_port *port)
+{
+       return port->rs485_config(port, &port->rs485);
+}
+EXPORT_SYMBOL_GPL(uart_rs485_config);
+
 static int uart_get_rs485_config(struct uart_port *port,
                         struct serial_rs485 __user *rs485)
 {
index cbd5070..d3ebb4d 100644 (file)
@@ -592,4 +592,5 @@ static inline int uart_handle_break(struct uart_port *port)
                                         !((cflag) & CLOCAL))
 
 int uart_get_rs485_mode(struct uart_port *port);
+int uart_rs485_config(struct uart_port *port);
 #endif /* LINUX_SERIAL_CORE_H */