serial: Add uart_rs485_config()

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>
This commit is contained in:
Ilpo Järvinen 2022-06-06 13:03:58 +03:00 committed by Greg Kroah-Hartman
parent af14f3007e
commit 8322b1f527
6 changed files with 12 additions and 7 deletions

View 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); pci_read_config_byte(pci_dev, 0x40 + 8 * *index + 7, &setting);
if (!rs485) if (rs485->flags & SER_RS485_ENABLED)
rs485 = &port->rs485;
else if (rs485->flags & SER_RS485_ENABLED)
memset(rs485->padding, 0, sizeof(rs485->padding)); memset(rs485->padding, 0, sizeof(rs485->padding));
else else
memset(rs485, 0, sizeof(*rs485)); memset(rs485, 0, sizeof(*rs485));
@ -1689,7 +1687,7 @@ static int pci_fintek_init(struct pci_dev *dev)
* pciserial_resume_ports() * pciserial_resume_ports()
*/ */
port = serial8250_get_port(priv->line[i]); port = serial8250_get_port(priv->line[i]);
pci_fintek_rs485_config(&port->port, NULL); uart_rs485_config(&port->port);
} else { } else {
/* First init without port data /* First init without port data
* force init to RS232 Mode * force init to RS232 Mode

View File

@ -3191,7 +3191,7 @@ static void serial8250_config_port(struct uart_port *port, int flags)
autoconfig(up); autoconfig(up);
if (port->rs485.flags & SER_RS485_ENABLED) 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 access method is AU, it is a 16550 with a quirk */
if (port->type == PORT_16550A && port->iotype == UPIO_AU) if (port->type == PORT_16550A && port->iotype == UPIO_AU)

View File

@ -2724,7 +2724,7 @@ static int lpuart_probe(struct platform_device *pdev)
sport->port.rs485.delay_rts_after_send) sport->port.rs485.delay_rts_after_send)
dev_err(&pdev->dev, "driver doesn't support RTS delays\n"); 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, ret = devm_request_irq(&pdev->dev, sport->port.irq, handler, 0,
DRIVER_NAME, sport); DRIVER_NAME, sport);

View File

@ -2338,7 +2338,7 @@ static int imx_uart_probe(struct platform_device *pdev)
dev_err(&pdev->dev, dev_err(&pdev->dev,
"low-active RTS not possible when receiver is off, enabling receiver\n"); "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 */ /* Disable interrupts before requesting them */
ucr1 = imx_uart_readl(sport, UCR1); ucr1 = imx_uart_readl(sport, UCR1);

View File

@ -1276,6 +1276,12 @@ static int uart_get_icount(struct tty_struct *tty,
return 0; 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, static int uart_get_rs485_config(struct uart_port *port,
struct serial_rs485 __user *rs485) struct serial_rs485 __user *rs485)
{ {

View File

@ -592,4 +592,5 @@ static inline int uart_handle_break(struct uart_port *port)
!((cflag) & CLOCAL)) !((cflag) & CLOCAL))
int uart_get_rs485_mode(struct uart_port *port); int uart_get_rs485_mode(struct uart_port *port);
int uart_rs485_config(struct uart_port *port);
#endif /* LINUX_SERIAL_CORE_H */ #endif /* LINUX_SERIAL_CORE_H */