[PATCH 4.14 161/173] earlycon: Initialize port->uartclk based on clock-frequency property

From: Greg Kroah-Hartman
Date: Mon Sep 24 2018 - 08:25:30 EST

4.14-stable review patch. If anyone has any objections, please let me know.


From: Michal Simek <michal.simek@xxxxxxxxxx>

commit 814453adea7d081ad8917aa0f32d6a14165a3563 upstream.

On DT based platforms when current-speed property is present baudrate
is setup. Also port->uartclk is initialized to bogus BASE_BAUD * 16
value. Drivers like uartps/ns16550 contain logic when baudrate and
uartclk is used for baudrate calculation.

The patch is reading optional clock-frequency property to replace bogus
BASE_BAUD * 16 calculation to have proper baudrate calculation.

[-stable comment: commit 31cb9a8575ca ("earlycon: initialise baud field
of earlycon device structure") has changed 8250_early.c behavior which
now tries to setup UART speed. Ignoring clock-frequency results in
wrong value of calculated divisor & malformed early console output.]

Fixes: 31cb9a8575ca ("earlycon: initialise baud field of earlycon device structure")
Signed-off-by: Michal Simek <michal.simek@xxxxxxxxxx>
[rmilecki: add -stable comment and Fixes tag]
Signed-off-by: RafaÅ MiÅecki <rafal@xxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

drivers/tty/serial/earlycon.c | 4 ++++
1 file changed, 4 insertions(+)

--- a/drivers/tty/serial/earlycon.c
+++ b/drivers/tty/serial/earlycon.c
@@ -289,6 +289,10 @@ int __init of_setup_earlycon(const struc
if (val)
early_console_dev.baud = be32_to_cpu(*val);

+ val = of_get_flat_dt_prop(node, "clock-frequency", NULL);
+ if (val)
+ port->uartclk = be32_to_cpu(*val);
if (options) {
early_console_dev.baud = simple_strtoul(options, NULL, 0);
strlcpy(early_console_dev.options, options,