summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Krummenacher <max.krummenacher@toradex.com>2021-01-13 19:39:15 +0100
committerMax Krummenacher <max.krummenacher@toradex.com>2021-02-01 10:47:56 +0100
commitbd1f6dd6086ed960602c2a19ea19baccb8501204 (patch)
treecc7a06afda5a454b3b36193a9ce99d007c0e3bdc
parent132df0e541bcb1ee28a7a4eeb85c6c48961ddad2 (diff)
tty: serial: fsl_lpuart: fix uart baud divider overflow
For low baudrates the uart baudrate divider can overflow, i.e. the sbr register must stay within [1..8191]. With an input frequency of 80MHz and a baudrate of 1200 the following register settings are calculated. sbr: 16666, osr: 4 Fix this. Related-to: ELB-3517 Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
-rw-r--r--drivers/tty/serial/fsl_lpuart.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index b822e54f2d13..f460ac06ffa5 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -2159,10 +2159,15 @@ lpuart32_serial_setbrg(struct lpuart_port *sport, unsigned int baudrate)
sbr = 0;
for (tmp_osr = 4; tmp_osr <= 32; tmp_osr++) {
- /* calculate the temporary sbr value */
+ /*
+ * calculate the temporary sbr value, sbr must be in 1..8191,
+ * limit to 8190, as the loop checks for sbr and sbr + 1
+ */
tmp_sbr = (clk / (baudrate * tmp_osr));
if (tmp_sbr == 0)
tmp_sbr = 1;
+ if (tmp_sbr > 8190)
+ tmp_sbr = 8190;
/*
* calculate the baud rate difference based on the temporary