mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] console: honour OF current-speed property if available
@ 2024-08-01  7:09 Ahmad Fatoum
  2024-08-01 11:36 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2024-08-01  7:09 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

current-speed describes the current baud rate the device operates at.
It's not used often in DT, but we should honour it if available.

This gives boards the ability to configure consoles that are activated
early (e.g. ACTIVATE_ALL) with the correct baud rate from the beginning
instead of activating it at CONFIG_BAUDRATE and then switching the
baudrate at environment load time.

Additionally, this can be used to work around following bug:

 - Console is added, but not activated automatically
 - NV sets cs0.active="ioe" cs0.baudrate="4000000"
 - .active parameter is applied first, so CONFIG_BAUDRATE is configured
 - .baudrate parameter is applied second, so baudrate switch happens
 - System hangs until Enter is pressed:
   ## Switch baudrate on console serial1 to 4000000 bps and press ENTER

until it's resolved in a cleaner manner.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 common/console.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/common/console.c b/common/console.c
index 9db994220e67..310959eeb8b4 100644
--- a/common/console.c
+++ b/common/console.c
@@ -331,7 +331,7 @@ int console_register(struct console_device *newcdev)
 	struct device_node *serdev_node = console_is_serdev_node(newcdev);
 	struct device *dev = &newcdev->class_dev;
 	int activate = 0, ret;
-	unsigned baudrate = CONFIG_BAUDRATE;
+	unsigned of_baudrate = 0, baudrate = CONFIG_BAUDRATE;
 
 	if (!serdev_node && initialized == CONSOLE_UNINITIALIZED)
 		console_init_early();
@@ -367,6 +367,11 @@ int console_register(struct console_device *newcdev)
 		console_set_stdoutpath(newcdev, baudrate);
 	}
 
+	/* Honour the previous baudrate if it is set to a non-zero value */
+	of_property_read_u32(dev->of_node, "current-speed", &of_baudrate);
+	if (of_baudrate)
+		baudrate = of_baudrate;
+
 	console_add_earlycon_param(newcdev, baudrate);
 
 	if (newcdev->setbrg) {
-- 
2.39.2




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-08-01 11:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-08-01  7:09 [PATCH] console: honour OF current-speed property if available Ahmad Fatoum
2024-08-01 11:36 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox