Re: [PATCH V2] tty: serial: fsl_lpuart: disable transmitter before changing RS485 related registers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 11. 03. 25, 3:55, Sherry Sun wrote:
According to the LPUART reference manual, TXRTSE and TXRTSPOL of MODIR
register only can be changed when the transmitter is disabled.
So disable the transmitter before changing RS485 related registers and
re-enable it after the change is done.

Fixes: 67b01837861c ("tty: serial: lpuart: Add RS485 support for 32-bit uart flavour")
Signed-off-by: Sherry Sun <sherry.sun@xxxxxxx>
Reviewed-by: Frank Li <Frank.Li@xxxxxxx>
---
Changes in V2:
1. Add TE bit polling read to ensure TE is really become 0 before proceeding.
2. Add Reviewed-by tag.
---
  drivers/tty/serial/fsl_lpuart.c | 17 +++++++++++++++++
  1 file changed, 17 insertions(+)

diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 91d02c55c470..6b2f3a73a367 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -1484,6 +1484,19 @@ static int lpuart32_config_rs485(struct uart_port *port, struct ktermios *termio
unsigned long modem = lpuart32_read(&sport->port, UARTMODIR)
  				& ~(UARTMODIR_TXRTSPOL | UARTMODIR_TXRTSE);

This is unrelated, but why is the above ulong?

+	u32 ctrl;
+
+	/* TXRTSE and TXRTSPOL only can be changed when transmitter is disabled. */
+	ctrl = lpuart32_read(&sport->port, UARTCTRL);
+	if (ctrl & UARTCTRL_TE) {
+		/* wait transmit engin complete */

wait for the transmit engine to complete

+		lpuart32_wait_bit_set(&sport->port, UARTSTAT, UARTSTAT_TC);

Both this ^^ and:

+		lpuart32_write(&sport->port, ctrl & ~UARTCTRL_TE, UARTCTRL);
+
+		while (lpuart32_read(&sport->port, UARTCTRL) & UARTCTRL_TE)
+			cpu_relax();

this ^^ are unbound loops in case the hardware gets mad :(.

Anyway, IIUC, after the TE clear from CTRL by the above write, the TE bit is really cleared by the HW from CTRL only after it is really disabled, so has to be checked?

+	}
+


thanks,
--
js
suse labs




[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux