tty: serial: fsl_lpuart: don't break the on-going transfer when global reset
PATCH v2 1/1 tty: serial: fsl_lpuart: don't break the on-going transfer when global reset
lpuart_global_reset() shouldn't break the on-going transmit engin, need to recover the on-going data transfer after reset.
This can help earlycon here, since commit 60f361722ad2 ("serial:fsl_lpuart: Reset prior to registration") moved lpuart_global_reset() before uart_add_one_port(), earlycon is writing during global reset, as global reset will disable the TX and clear the baud rate register, which caused the earlycon cannot work any more after reset, needs to restore the baud rate and re-enable the transmitter to recover the earlycon write.
---
Changes in V2:
1. The while loop may never exit as the stat and sfifo are not re-read inside the loop, fix that.
--- drivers/tty/serial/fsl_lpuart.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
drivers/tty/serial/fsl_lpuart.c +19 -3
@@ -408,11 +408,9 @@ static int lpuart_global_reset(struct lpuart_port *sport) {struct uart_port *port = &sport->port;void __iomem *global_addr; +unsigned long tx_enable, bd;int ret; -if (uart_console (port)) -return 0 ; - ret =clk_prepare_enable (sport->ipg_clk);if (ret) {dev_err (sport->port.dev,"failed to enable uart ipg clk: %d\n" , ret);
@@ -420,11 +418,29 @@ static int lpuart_global_reset(struct lpuart_port *sport) }if (is_imx7ulp_lpuart (sport) ||is_imx8qxp_lpuart (sport)) { +/* +* If the transmitter is used by earlycon, wait transmit engin complete +* and then reset +*/ + tx_enable =lpuart32_read (port,UARTCTRL ) &UARTCTRL_TE ; +if (tx_enable) { + bd =lpuart32_read (&sport->port,UARTBAUD ); +while (!(lpuart32_read (port,UARTSTAT ) &UARTSTAT_TC && +lpuart32_read (port,UARTFIFO ) &UARTFIFO_TXEMPT )) +cpu_relax (); + } + global_addr = port->membase +UART_GLOBAL -IMX_REG_OFF ;writel (UART_GLOBAL_RST , global_addr);usleep_range (GLOBAL_RST_MIN_US ,GLOBAL_RST_MAX_US );writel (0 , global_addr);usleep_range (GLOBAL_RST_MIN_US ,GLOBAL_RST_MAX_US ); + +/* Recover the transmitter for earlycon */ +if (tx_enable) { +lpuart32_write (port, bd,UARTBAUD ); +lpuart32_write (port,UARTCTRL_TE ,UARTCTRL ); + } }clk_disable_unprepare (sport->ipg_clk);
Signature · 1 line
2.17.1
Quoted 67 lines
-----Original Message-----
From: Sherry Sun <[email protected]>
Sent: Wednesday, October 19, 2022 6:07 AM
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: [PATCH V2] tty: serial:fsl_lpuart: don't break the on-going transfer when global reset
lpuart_global_reset()shouldn't break the on-going transmit engin, need to recover the on-going data transfer after reset.This can help earlycon here, since commit
60f361722ad2("serial:fsl_lpuart: Reset prior to registration") movedlpuart_global_reset()beforeuart_add_one_port(), earlycon is writing during global reset, as global reset will disable the TX and clear the baud rate register, which caused the earlycon cannot work any more after reset, needs to restore the baud rate and re-enable the transmitter to recover the earlycon write.Fixes bd5305dcabbc ("tty: serial: fsl_lpuart: do software reset for imx7ulp andimx8qxp")
Signed-off-by Sherry Sun <[email protected]>---
Changes in V2:
1. The while loop may never exit as the stat and sfifo are not re-read inside the loop, fix that.--- drivers/tty/serial/fsl_lpuart.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)drivers/tty/serial/fsl_lpuart.c index renamed from drivers/tty/serial/fsl_lpuart.c +0
-0
67fa113f77d4..9a0781395b1f100644drivers/tty/serial/fsl_lpuart.c +1
-3@@ -408,11 +408,9 @@ static int lpuart_global_reset(struct lpuart_port *sport) {struct uart_port *port = &sport->port;void __iomem *global_addr; +unsigned long tx_enable, bd;int ret; -if (uart_console (port)) -return 0 ; - ret =clk_prepare_enable (sport->ipg_clk);if (ret) { dev_err(sport->port.dev, "failed to enable uart ipg clk: %d\n",ret); @@ -420,11 +418,29 @@ static int
lpuart_global_reset(struct lpuart_port *sport)drivers/tty/serial/fsl_lpuart.c +2
-0}if (is_imx7ulp_lpuart (sport) ||is_imx8qxp_lpuart (sport)) { +/* +* If the transmitter is used by earlycon, wait transmit engin complete
drivers/tty/serial/fsl_lpuart.c +6
-0+* and then reset +*/ + tx_enable =lpuart32_read (port,UARTCTRL ) &UARTCTRL_TE ; +if (tx_enable) { + bd =lpuart32_read (&sport->port,UARTBAUD ); + while (!(lpuart32_read(port, UARTSTAT) &
UARTSTAT_TC&&drivers/tty/serial/fsl_lpuart.c +1
-0+ lpuart32_read(port, UARTFIFO) &
UARTFIFO_TXEMPT))
drivers/tty/serial/fsl_lpuart.c static int lpuart_global_reset(struct lpuart_port *sport) · line 435
Quoted 6 lines
drivers/tty/serial/fsl_lpuart.c +3
-0+cpu_relax (); + } + global_addr = port->membase +UART_GLOBAL -IMX_REG_OFF ;writel (UART_GLOBAL_RST , global_addr);usleep_range (GLOBAL_RST_MIN_US ,GLOBAL_RST_MAX_US );
According to the statement in the RM, you don't need to add delay here. "There is no minimum delay required before clearing the software reset."
drivers/tty/serial/fsl_lpuart.c static int lpuart_global_reset(struct lpuart_port *sport) · line 437
Quoted 2 lines
drivers/tty/serial/fsl_lpuart.c +0
-0writel (0 , global_addr);usleep_range (GLOBAL_RST_MIN_US ,GLOBAL_RST_MAX_US );
[...]
Regards,
Shenwei
Quoted 11 lines
drivers/tty/serial/fsl_lpuart.c +6
-1+ +/* Recover the transmitter for earlycon */ +if (tx_enable) { +lpuart32_write (port, bd,UARTBAUD ); +lpuart32_write (port,UARTCTRL_TE ,UARTCTRL ); + } }clk_disable_unprepare (sport->ipg_clk); --2.17.1
Quoted 75 lines
Quoted 14 lines
-----Original Message-----
From: Sherry Sun <[email protected]>
Sent: Wednesday, October 19, 2022 6:07 AM
To: [email protected]; [email protected]; [email protected]; [email protected]
Cc: [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: [PATCH V2] tty: serial:fsl_lpuart: don't break the on-going transfer when global reset
lpuart_global_reset()shouldn't break the on-going transmit engin, need to recover the on-going data transfer after reset.Quoted 6 lines
This can help earlycon here, since commit
60f361722ad2("serial:fsl_lpuart: Reset prior to registration") movedlpuart_global_reset()beforeuart_add_one_port(), earlycon is writing during global reset, as global reset will disable the TX and clear the baud rate register, which caused the earlycon cannot work any more after reset, needs to restore the baud rate and re-enable the transmitter to recover the earlyconwrite.
Quoted 49 lines
Fixes bd5305dcabbc ("tty: serial: fsl_lpuart: do software reset forimx7ulp and
imx8qxp")Signed-off-by Sherry Sun <[email protected]>---
Changes in V2:
1. The while loop may never exit as the stat and sfifo are not re-read inside the loop, fix that.--- drivers/tty/serial/fsl_lpuart.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)(quoted diff) +0
-0
b/drivers/tty/serial/fsl_lpuart.cindex67fa113f77d4..9a0781395b1f100644drivers/tty/serial/fsl_lpuart.c +1
-3@@ -408,11 +408,9 @@ static int lpuart_global_reset(struct lpuart_port *sport) {struct uart_port *port = &sport->port;void __iomem *global_addr; +unsigned long tx_enable, bd;int ret; -if (uart_console (port)) -return 0 ; - ret =clk_prepare_enable (sport->ipg_clk);if (ret) { dev_err(sport->port.dev, "failed to enable uart ipg clk: %d\n",ret); @@ -420,11 +418,29 @@ static int lpuart_global_reset(struct
lpuart_port
*sport)drivers/tty/serial/fsl_lpuart.c +2
-0}if (is_imx7ulp_lpuart (sport) ||is_imx8qxp_lpuart (sport)) { +/* +* If the transmitter is used by earlycon, wait transmit engin complete
drivers/tty/serial/fsl_lpuart.c +6
-0+* and then reset +*/ + tx_enable =lpuart32_read (port,UARTCTRL ) &UARTCTRL_TE ; +if (tx_enable) { + bd =lpuart32_read (&sport->port,UARTBAUD ); + while (!(lpuart32_read(port, UARTSTAT) &
UARTSTAT_TC&&drivers/tty/serial/fsl_lpuart.c +1
-0+ lpuart32_read(port, UARTFIFO) &
UARTFIFO_TXEMPT))drivers/tty/serial/fsl_lpuart.c static int lpuart_global_reset(struct lpuart_port *sport)
Quoted 4 lines
drivers/tty/serial/fsl_lpuart.c +3
-0+cpu_relax (); + } + global_addr = port->membase + UART_GLOBAL -
IMX_REG_OFF;
Quoted 6 lines
drivers/tty/serial/fsl_lpuart.c
Quoted 2 lines
drivers/tty/serial/fsl_lpuart.c +0
-0writel (UART_GLOBAL_RST , global_addr);usleep_range (GLOBAL_RST_MIN_US ,GLOBAL_RST_MAX_US );According to the statement in the RM, you don't need to add delay here. "There is no minimum delay required before clearing the software reset."
Hi Shenwei,
Assuming you are referencing the imx8ulp lpuart RM, yes, for imx8ulp/imx93 lpuart, no minimum delay is required before clearing the software reset. But for imx7ulp and imx8qxp lpuart here, the minimum delay is required before clearing the software reset, so here the usleep is needed.
Best Regards
Sherry
Jiri Slaby
maintainerQuoted 1 line · Sherry Sun
lpuart_global_reset()shouldn't break the on-going transmit engin, need
"engine"
Quoted 38 lines
to recover the on-going data transfer after reset.
This can help earlycon here, since commit
60f361722ad2("serial:fsl_lpuart: Reset prior to registration") movedlpuart_global_reset()beforeuart_add_one_port(), earlycon is writing during global reset, as global reset will disable the TX and clear the baud rate register, which caused the earlycon cannot work any more after reset, needs to restore the baud rate and re-enable the transmitter to recover the earlycon write.Fixes bd5305dcabbc ("tty: serial: fsl_lpuart: do software reset for imx7ulp and imx8qxp")Signed-off-by Sherry Sun <[email protected]>---
Changes in V2:
1. The while loop may never exit as the stat and sfifo are not re-read inside the loop, fix that.--- drivers/tty/serial/fsl_lpuart.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)drivers/tty/serial/fsl_lpuart.c +1
-3@@ -408,11 +408,9 @@ static int lpuart_global_reset(struct lpuart_port *sport) {struct uart_port *port = &sport->port;void __iomem *global_addr; +unsigned long tx_enable, bd;int ret; -if (uart_console (port)) -return 0 ; - ret =clk_prepare_enable (sport->ipg_clk);if (ret) {dev_err (sport->port.dev,"failed to enable uart ipg clk: %d\n" , ret);
drivers/tty/serial/fsl_lpuart.c static int lpuart_global_reset(struct lpuart_port *sport) · line 422
Quoted 5 lines
drivers/tty/serial/fsl_lpuart.c +2
-0@@ -420,11 +418,29 @@ static int lpuart_global_reset(struct lpuart_port *sport) }if (is_imx7ulp_lpuart (sport) ||is_imx8qxp_lpuart (sport)) { +/* +* If the transmitter is used by earlycon, wait transmit engin complete
"wait for transmit engine to complete"
drivers/tty/serial/fsl_lpuart.c static int lpuart_global_reset(struct lpuart_port *sport) · line 423
Quoted 1 line
drivers/tty/serial/fsl_lpuart.c +1
-0+* and then reset
"." (add a period)
drivers/tty/serial/fsl_lpuart.c static int lpuart_global_reset(struct lpuart_port *sport) · line 430
Quoted 7 lines
drivers/tty/serial/fsl_lpuart.c +7
-0+*/ + tx_enable =lpuart32_read (port,UARTCTRL ) &UARTCTRL_TE ; +if (tx_enable) { + bd =lpuart32_read (&sport->port,UARTBAUD ); +while (!(lpuart32_read (port,UARTSTAT ) &UARTSTAT_TC && +lpuart32_read (port,UARTFIFO ) &UARTFIFO_TXEMPT )) +cpu_relax ();
If the HW is stuck, you make the kernel stuck too. What about read_poll_timeout_atomic(). Or at least a custom timeout.
drivers/tty/serial/fsl_lpuart.c static int lpuart_global_reset(struct lpuart_port *sport) · line 442
Quoted 12 lines
drivers/tty/serial/fsl_lpuart.c +7
-0+ } + global_addr = port->membase +UART_GLOBAL -IMX_REG_OFF ;writel (UART_GLOBAL_RST , global_addr);usleep_range (GLOBAL_RST_MIN_US ,GLOBAL_RST_MAX_US );writel (0 , global_addr);usleep_range (GLOBAL_RST_MIN_US ,GLOBAL_RST_MAX_US ); + +/* Recover the transmitter for earlycon */ +if (tx_enable) { +lpuart32_write (port, bd,UARTBAUD ); +lpuart32_write (port,UARTCTRL_TE ,UARTCTRL );
I don't know the HW. Is it enough to write TE here? IOW shouldn't we preserve the whole register content from the above read here?
thanks,
Signature · 2 lines
js suse labs
Quoted 6 lines · Sherry Sun
Quoted 2 lines
lpuart_global_reset()shouldn't break the on-going transmit engin, need"engine"
Will fix it in V3.
Quoted 52 lines
drivers/tty/serial/fsl_lpuart.c static int lpuart_global_reset(struct lpuart_port
Quoted 28 lines
to recover the on-going data transfer after reset.
This can help earlycon here, since commit
60f361722ad2("serial:fsl_lpuart: Reset prior to registration") movedlpuart_global_reset()beforeuart_add_one_port(), earlycon is writing during global reset, as global reset will disable the TX and clear the baud rate register, which caused the earlycon cannot work any more after reset, needs to restore the baud rate and re-enable the transmitter to recover the earlycon write.Fixes bd5305dcabbc ("tty: serial: fsl_lpuart: do software reset forimx7ulp and imx8qxp")
Signed-off-by Sherry Sun <[email protected]>---
Changes in V2:
1. The while loop may never exit as the stat and sfifo are not re-read inside the loop, fix that.--- drivers/tty/serial/fsl_lpuart.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)(quoted diff) +0
-0
b/drivers/tty/serial/fsl_lpuart.cindex67fa113f77d4..9a0781395b1f100644drivers/tty/serial/fsl_lpuart.c +0
-0@@ -408,11 +408,9 @@ static int lpuart_global_reset(struct lpuart_port*sport)
Quoted 12 lines
drivers/tty/serial/fsl_lpuart.c +1
-3{struct uart_port *port = &sport->port;void __iomem *global_addr; +unsigned long tx_enable, bd;int ret; -if (uart_console (port)) -return 0 ; - ret =clk_prepare_enable (sport->ipg_clk);if (ret) { dev_err(sport->port.dev, "failed to enable uart ipg clk: %d\n",Quoted 1 line
ret); @@ -420,11 +418,29 @@ static int lpuart_global_reset(struct
lpuart_port*sport)drivers/tty/serial/fsl_lpuart.c
Quoted 6 lines
} if (is_imx7ulp_lpuart(sport) || is_imx8qxp_lpuart(sport)) {drivers/tty/serial/fsl_lpuart.c +3
-0+/* +* If the transmitter is used by earlycon, wait transmit engin +complete "wait for transmit engine to complete"
Quoted 3 lines
drivers/tty/serial/fsl_lpuart.c static int lpuart_global_reset(struct lpuart_port *sport) · line 423
Quoted 1 line
drivers/tty/serial/fsl_lpuart.c +1
-0+* and then reset "." (add a period)
Will fix it in V3.
Quoted 7 lines
drivers/tty/serial/fsl_lpuart.c static int lpuart_global_reset(struct lpuart_port *sport)
Quoted 6 lines
drivers/tty/serial/fsl_lpuart.c +5
-0+*/ + tx_enable =lpuart32_read (port,UARTCTRL ) &UARTCTRL_TE ; +if (tx_enable) { + bd =lpuart32_read (&sport->port,UARTBAUD ); + while (!(lpuart32_read(port, UARTSTAT) &
UARTSTAT_TC&&
Quoted 6 lines
drivers/tty/serial/fsl_lpuart.c
Quoted 1 line
drivers/tty/serial/fsl_lpuart.c +1
-0+ lpuart32_read(port, UARTFIFO) &
UARTFIFO_TXEMPT))drivers/tty/serial/fsl_lpuart.c static int lpuart_global_reset(struct lpuart_port *sport) · line 430
Quoted 1 line
drivers/tty/serial/fsl_lpuart.c +1
-0+cpu_relax ();If the HW is stuck, you make the kernel stuck too. What about
read_poll_timeout_atomic(). Or at least a custom timeout.
Seems use read_poll_timeout_atomic() is a good idea, I will try that.
Quoted 5 lines
drivers/tty/serial/fsl_lpuart.c static int lpuart_global_reset(struct lpuart_port *sport)
Quoted 4 lines
drivers/tty/serial/fsl_lpuart.c +2
-0+ } + global_addr = port->membase + UART_GLOBAL -
IMX_REG_OFF;
Quoted 12 lines
drivers/tty/serial/fsl_lpuart.c static int lpuart_global_reset(struct lpuart_port *sport) · line 442
Quoted 9 lines
writel(UART_GLOBAL_RST, global_addr); usleep_range(GLOBAL_RST_MIN_US, GLOBAL_RST_MAX_US); writel(0, global_addr); usleep_range(GLOBAL_RST_MIN_US, GLOBAL_RST_MAX_US);drivers/tty/serial/fsl_lpuart.c +5
-0+ +/* Recover the transmitter for earlycon */ +if (tx_enable) { +lpuart32_write (port, bd,UARTBAUD ); +lpuart32_write (port,UARTCTRL_TE ,UARTCTRL );I don't know the HW. Is it enough to write TE here? IOW shouldn't we preserve the whole register content from the above read here?
Yes, maybe restore the whole ctrl register here would be better to avoid any confusion, will do that in V3. Thanks.
Best Regards
Sherry