Skip to content

Commit

Permalink
Revert "Revert "serial: Deassert Transmit Enable on probe in driver-s…
Browse files Browse the repository at this point in the history
…pecific way""

This reverts commit 9ce2640.

This re-introduces the upstream linux-stable changes and makes future
upgrades/merges easier.

Work has been scheduled to fix the affected RS-485 serial ATS tests which
incorrectly configured the RS-485 flags and caused the failures that
prompted the original revert.

Signed-off-by: Gratian Crisan <[email protected]>
  • Loading branch information
gratian committed Jan 11, 2023
1 parent 9423c38 commit fdca62b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 40 deletions.
3 changes: 3 additions & 0 deletions drivers/tty/serial/8250/8250_omap.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ static void omap8250_restore_regs(struct uart_8250_port *up)
omap8250_update_mdr1(up, priv);

__omap8250_set_mctrl(&up->port, up->port.mctrl);

if (up->port.rs485.flags & SER_RS485_ENABLED)
serial8250_em485_stop_tx(up);
}

/*
Expand Down
9 changes: 1 addition & 8 deletions drivers/tty/serial/8250/8250_pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -1739,7 +1739,6 @@ static int pci_fintek_init(struct pci_dev *dev)
resource_size_t bar_data[3];
u8 config_base;
struct serial_private *priv = pci_get_drvdata(dev);
struct uart_8250_port *port;

if (!(pci_resource_flags(dev, 5) & IORESOURCE_IO) ||
!(pci_resource_flags(dev, 4) & IORESOURCE_IO) ||
Expand Down Expand Up @@ -1786,13 +1785,7 @@ static int pci_fintek_init(struct pci_dev *dev)

pci_write_config_byte(dev, config_base + 0x06, dev->irq);

if (priv) {
/* re-apply RS232/485 mode when
* pciserial_resume_ports()
*/
port = serial8250_get_port(priv->line[i]);
pci_fintek_rs485_config(&port->port, NULL);
} else {
if (!priv) {
/* First init without port data
* force init to RS232 Mode
*/
Expand Down
12 changes: 7 additions & 5 deletions drivers/tty/serial/8250/8250_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ EXPORT_SYMBOL_GPL(serial8250_rpm_put);
static int serial8250_em485_init(struct uart_8250_port *p)
{
if (p->em485)
return 0;
goto deassert_rts;

p->em485 = kmalloc(sizeof(struct uart_8250_em485), GFP_ATOMIC);
if (!p->em485)
Expand All @@ -630,7 +630,9 @@ static int serial8250_em485_init(struct uart_8250_port *p)
p->em485->active_timer = NULL;
p->em485->tx_stopped = true;

p->rs485_stop_tx(p);
deassert_rts:
if (p->em485->tx_stopped)
p->rs485_stop_tx(p);

return 0;
}
Expand Down Expand Up @@ -2051,6 +2053,9 @@ EXPORT_SYMBOL_GPL(serial8250_do_set_mctrl);

static void serial8250_set_mctrl(struct uart_port *port, unsigned int mctrl)
{
if (port->rs485.flags & SER_RS485_ENABLED)
return;

if (port->set_mctrl)
port->set_mctrl(port, mctrl);
else
Expand Down Expand Up @@ -3201,9 +3206,6 @@ static void serial8250_config_port(struct uart_port *port, int flags)
if (flags & UART_CONFIG_TYPE)
autoconfig(up);

if (port->rs485.flags & SER_RS485_ENABLED)
port->rs485_config(port, &port->rs485);

/* if access method is AU, it is a 16550 with a quirk */
if (port->type == PORT_16550A && port->iotype == UPIO_AU)
up->bugs |= UART_BUG_NOMSR;
Expand Down
8 changes: 3 additions & 5 deletions drivers/tty/serial/fsl_lpuart.c
Original file line number Diff line number Diff line change
Expand Up @@ -2761,10 +2761,6 @@ static int lpuart_probe(struct platform_device *pdev)
if (ret)
goto failed_reset;

ret = uart_add_one_port(&lpuart_reg, &sport->port);
if (ret)
goto failed_attach_port;

ret = uart_get_rs485_mode(&sport->port);
if (ret)
goto failed_get_rs485;
Expand All @@ -2776,7 +2772,9 @@ 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);
ret = uart_add_one_port(&lpuart_reg, &sport->port);
if (ret)
goto failed_attach_port;

ret = devm_request_irq(&pdev->dev, sport->port.irq, handler, 0,
DRIVER_NAME, sport);
Expand Down
8 changes: 2 additions & 6 deletions drivers/tty/serial/imx.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,7 @@ static void imx_uart_rts_active(struct imx_port *sport, u32 *ucr2)
{
*ucr2 &= ~(UCR2_CTSC | UCR2_CTS);

sport->port.mctrl |= TIOCM_RTS;
mctrl_gpio_set(sport->gpios, sport->port.mctrl);
mctrl_gpio_set(sport->gpios, sport->port.mctrl | TIOCM_RTS);
}

/* called with port.lock taken and irqs caller dependent */
Expand All @@ -390,8 +389,7 @@ static void imx_uart_rts_inactive(struct imx_port *sport, u32 *ucr2)
*ucr2 &= ~UCR2_CTSC;
*ucr2 |= UCR2_CTS;

sport->port.mctrl &= ~TIOCM_RTS;
mctrl_gpio_set(sport->gpios, sport->port.mctrl);
mctrl_gpio_set(sport->gpios, sport->port.mctrl & ~TIOCM_RTS);
}

static void start_hrtimer_ms(struct hrtimer *hrt, unsigned long msec)
Expand Down Expand Up @@ -2318,8 +2316,6 @@ 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);

/* Disable interrupts before requesting them */
ucr1 = imx_uart_readl(sport, UCR1);
ucr1 &= ~(UCR1_ADEN | UCR1_TRDYEN | UCR1_IDEN | UCR1_RRDYEN | UCR1_RTSDEN);
Expand Down
33 changes: 17 additions & 16 deletions drivers/tty/serial/serial_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,10 @@ uart_update_mctrl(struct uart_port *port, unsigned int set, unsigned int clear)
unsigned long flags;
unsigned int old;

if (port->rs485.flags & SER_RS485_ENABLED) {
set &= ~TIOCM_RTS;
clear &= ~TIOCM_RTS;
}

spin_lock_irqsave(&port->lock, flags);
old = port->mctrl;
port->mctrl = (old & ~clear) | set;
if (old != port->mctrl)
if (old != port->mctrl && !(port->rs485.flags & SER_RS485_ENABLED))
port->ops->set_mctrl(port, port->mctrl);
spin_unlock_irqrestore(&port->lock, flags);
}
Expand Down Expand Up @@ -1336,8 +1331,13 @@ static int uart_set_rs485_config(struct uart_port *port,

spin_lock_irqsave(&port->lock, flags);
ret = port->rs485_config(port, &rs485);
if (!ret)
if (!ret) {
port->rs485 = rs485;

/* Reset RTS and other mctrl lines when disabling RS485 */
if (!(rs485.flags & SER_RS485_ENABLED))
port->ops->set_mctrl(port, port->mctrl);
}
spin_unlock_irqrestore(&port->lock, flags);
if (ret)
return ret;
Expand Down Expand Up @@ -2314,7 +2314,8 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)

uart_change_pm(state, UART_PM_STATE_ON);
spin_lock_irq(&uport->lock);
ops->set_mctrl(uport, 0);
if (!(uport->rs485.flags & SER_RS485_ENABLED))
ops->set_mctrl(uport, 0);
spin_unlock_irq(&uport->lock);
if (console_suspend_enabled || !uart_console(uport)) {
/* Protected by port mutex for now */
Expand All @@ -2325,10 +2326,10 @@ int uart_resume_port(struct uart_driver *drv, struct uart_port *uport)
if (tty)
uart_change_speed(tty, state, NULL);
spin_lock_irq(&uport->lock);
if (uport->rs485_config)
uport->rs485_config(uport,
&uport->rs485);
ops->set_mctrl(uport, uport->mctrl);
if (!(uport->rs485.flags & SER_RS485_ENABLED))
ops->set_mctrl(uport, uport->mctrl);
else
uport->rs485_config(uport, &uport->rs485);
ops->start_tx(uport);
spin_unlock_irq(&uport->lock);
tty_port_set_initialized(port, 1);
Expand Down Expand Up @@ -2434,10 +2435,10 @@ uart_configure_port(struct uart_driver *drv, struct uart_state *state,
*/
spin_lock_irqsave(&port->lock, flags);
port->mctrl &= TIOCM_DTR;
if (port->rs485.flags & SER_RS485_ENABLED &&
!(port->rs485.flags & SER_RS485_RTS_AFTER_SEND))
port->mctrl |= TIOCM_RTS;
port->ops->set_mctrl(port, port->mctrl);
if (!(port->rs485.flags & SER_RS485_ENABLED))
port->ops->set_mctrl(port, port->mctrl);
else
port->rs485_config(port, &port->rs485);
spin_unlock_irqrestore(&port->lock, flags);

/*
Expand Down

0 comments on commit fdca62b

Please sign in to comment.