diff options
author | Max Krummenacher <max.krummenacher@toradex.com> | 2021-01-13 19:39:15 +0100 |
---|---|---|
committer | Max Krummenacher <max.krummenacher@toradex.com> | 2021-02-01 10:05:43 +0100 |
commit | 399758c48f7680e0e80f67a2ad49207f51cb41dd (patch) | |
tree | 0a6008464d87239d1d5ac65ba5db4c04e6260b4e | |
parent | 1266d0110fcedb08c996124ddb33bddd98ed61f5 (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.c | 7 |
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 |