serial: 8250_bcm7271: UART errors after resuming from S2

There is a small window in time during resume where the hardware
flow control signal RTS can be asserted (which allows a sender to
resume sending data to the UART) but the baud rate has not yet
been restored. This will cause corrupted data and FRAMING, OVERRUN
and BREAK errors. This is happening because the MCTRL register is
shadowed in uart_port struct and is later used during resume to set
the MCTRL register during both serial8250_do_startup() and
uart_resume_port(). Unfortunately, serial8250_do_startup()
happens before the UART baud rate is restored. The fix is to clear
the shadowed mctrl value at the end of suspend and restore it at the
end of resume.

Fixes: 41a469482de2 ("serial: 8250: Add new 8250-core based Broadcom STB driver")
Acked-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Al Cooper <alcooperx@gmail.com>
Link: https://lore.kernel.org/r/20211201201402.47446-1-alcooperx@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by Al Cooper and committed by Greg Kroah-Hartman 9cabe26e bb1201d4

Changed files
+13
drivers
tty
serial
+13
drivers/tty/serial/8250/8250_bcm7271.c
··· 237 237 u32 rx_err; 238 238 u32 rx_timeout; 239 239 u32 rx_abort; 240 + u32 saved_mctrl; 240 241 }; 241 242 242 243 static struct dentry *brcmuart_debugfs_root; ··· 1134 1133 static int __maybe_unused brcmuart_suspend(struct device *dev) 1135 1134 { 1136 1135 struct brcmuart_priv *priv = dev_get_drvdata(dev); 1136 + struct uart_8250_port *up = serial8250_get_port(priv->line); 1137 + struct uart_port *port = &up->port; 1137 1138 1138 1139 serial8250_suspend_port(priv->line); 1139 1140 clk_disable_unprepare(priv->baud_mux_clk); 1141 + 1142 + /* 1143 + * This will prevent resume from enabling RTS before the 1144 + * baud rate has been resored. 1145 + */ 1146 + priv->saved_mctrl = port->mctrl; 1147 + port->mctrl = 0; 1140 1148 1141 1149 return 0; 1142 1150 } ··· 1153 1143 static int __maybe_unused brcmuart_resume(struct device *dev) 1154 1144 { 1155 1145 struct brcmuart_priv *priv = dev_get_drvdata(dev); 1146 + struct uart_8250_port *up = serial8250_get_port(priv->line); 1147 + struct uart_port *port = &up->port; 1156 1148 int ret; 1157 1149 1158 1150 ret = clk_prepare_enable(priv->baud_mux_clk); ··· 1177 1165 start_rx_dma(serial8250_get_port(priv->line)); 1178 1166 } 1179 1167 serial8250_resume_port(priv->line); 1168 + port->mctrl = priv->saved_mctrl; 1180 1169 return 0; 1181 1170 } 1182 1171