Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

serial: 8250: 8250_omap: Avoid RS485 RTS glitch on ->set_termios()

RS485-enabled UART ports on TI Sitara SoCs with active-low polarity
exhibit a Transmit Enable glitch on ->set_termios():

omap8250_restore_regs(), which is called from omap_8250_set_termios(),
sets the TCRTLR bit in the MCR register and clears all other bits,
including RTS. If RTS uses active-low polarity, it is now asserted
for no reason.

The TCRTLR bit is subsequently cleared by writing up->mcr to the MCR
register. That variable is always zero, so the RTS bit is still cleared
(incorrectly so if RTS is active-high).

(up->mcr is not, as one might think, a cache of the MCR register's
current value. Rather, it only caches a single bit of that register,
the AFE bit. And it only does so if the UART supports the AFE bit,
which OMAP does not. For details see serial8250_do_set_termios() and
serial8250_do_set_mctrl().)

Finally at the end of omap8250_restore_regs(), the MCR register is
restored (and RTS deasserted) by a call to up->port.ops->set_mctrl()
(which equals serial8250_set_mctrl()) and serial8250_em485_stop_tx().

So there's an RTS glitch between setting TCRTLR and calling
serial8250_em485_stop_tx(). Avoid by using a read-modify-write
when setting TCRTLR.

While at it, drop a redundant initialization of up->mcr. As explained
above, the variable isn't used by the driver and it is already
initialized to zero because it is part of the static struct
serial8250_ports[] declared in 8250_core.c. (Static structs are
initialized to zero per section 6.7.8 nr. 10 of the C99 standard.)

Cc: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Su Bao Cheng <baocheng.su@siemens.com>
Tested-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Signed-off-by: Lukas Wunner <lukas@wunner.de>
Link: https://lore.kernel.org/r/6554b0241a2c7fd50f32576fdbafed96709e11e8.1664278942.git.lukas@wunner.de
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Lukas Wunner and committed by
Greg Kroah-Hartman
038ee49f 30a0b95b

+4 -3
+4 -3
drivers/tty/serial/8250/8250_omap.c
··· 292 292 { 293 293 struct omap8250_priv *priv = up->port.private_data; 294 294 struct uart_8250_dma *dma = up->dma; 295 + u8 mcr = serial8250_in_MCR(up); 295 296 296 297 if (dma && dma->tx_running) { 297 298 /* ··· 309 308 serial_out(up, UART_EFR, UART_EFR_ECB); 310 309 311 310 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_A); 312 - serial8250_out_MCR(up, UART_MCR_TCRTLR); 311 + serial8250_out_MCR(up, mcr | UART_MCR_TCRTLR); 313 312 serial_out(up, UART_FCR, up->fcr); 314 313 315 314 omap8250_update_scr(up, priv); ··· 325 324 serial_out(up, UART_LCR, 0); 326 325 327 326 /* drop TCR + TLR access, we setup XON/XOFF later */ 328 - serial8250_out_MCR(up, up->mcr); 327 + serial8250_out_MCR(up, mcr); 328 + 329 329 serial_out(up, UART_IER, up->ier); 330 330 331 331 serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B); ··· 671 669 672 670 pm_runtime_get_sync(port->dev); 673 671 674 - up->mcr = 0; 675 672 serial_out(up, UART_FCR, UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT); 676 673 677 674 serial_out(up, UART_LCR, UART_LCR_WLEN8);