Skip to contentSkip to conversation

serial: 8250: add CONFIG_SERIAL_8250_PROBE_BAUD option

PATCH Superseded Sheng Yu 2 participants 2 messages Feb 1 – Feb 8 TTY layer and serial drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Sheng Yu

author
#0 lore raw

PATCH 1/1 serial: 8250: add CONFIG_SERIAL_8250_PROBE_BAUD option

Currently, the 8250 driver defaults to 9600 baud if no console options are provided via the command line. This can result in garbled output if the firmware or bootloader has already initialized the UART to a different speed.

Introduce CONFIG_SERIAL_8250_PROBE_BAUD. When enabled, the driver will attempt to read the current baud rate from the hardware registers if no options are specified, rather than forcing the 9600 default.

---
 drivers/tty/serial/8250/8250_core.c |  2 +-
 drivers/tty/serial/8250/8250_port.c |  5 ++++-
 drivers/tty/serial/8250/Kconfig     | 12 ++++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_core.c +1 -1
index 0e81f78c6063..c11b19921a1f 100644
@@ -427,7 +427,7 @@ static int univ8250_console_setup(struct console *co, char *options)
 	/* link port to console */
 	uart_port_set_cons(port, co);
 
-	retval = serial8250_console_setup(port, options, false);
+	retval = serial8250_console_setup(port, options, IS_ENABLED(CONFIG_SERIAL_8250_PROBE_BAUD));
 	if (retval != 0)
 		uart_port_set_cons(port, NULL);
 	return retval;
drivers/tty/serial/8250/8250_port.c +4 -1
index 719faf92aa8a..5309b921e7b7 100644
@@ -3399,8 +3399,11 @@ int serial8250_console_setup(struct uart_port *port, char *options, bool probe)
 
 	if (options)
 		uart_parse_options(options, &baud, &parity, &bits, &flow);
-	else if (probe)
+	else if (probe) {
 		baud = probe_baud(port);
+		pr_info("console [%s%d] probed baud rate: %d\n",
+			port->cons->name, port->cons->index, baud);
+	}
 
 	ret = uart_set_options(port, port->cons, baud, parity, bits, flow);
 	if (ret)
drivers/tty/serial/8250/Kconfig +12 -0
index c488ff6f2865..bee6a82023d4 100644
@@ -596,3 +596,15 @@ config SERIAL_OF_PLATFORM
 	  are probed through devicetree, including Open Firmware based
 	  PowerPC systems and embedded systems on architectures using the
 	  flattened device tree format.
+
+config SERIAL_8250_PROBE_BAUD
+	bool "Probe baud rate if console options are missing"
+	depends on SERIAL_8250
+	help
+	  If the "console=" command line parameter is missing options (e.g.,
+	  "console=ttyS0" instead of "console=ttyS0,115200n8"), this option
+	  allows the kernel to probe the baud rate from hardware instead of
+	  defaulting to 9600.
+
+	  If a baud rate is explicitly provided in the options, that value
+	  is always respected.
Signature · 1 line
2.51.0
maintainer
#1 lore raw
Quoted 70 lines · Sheng Yu

Currently, the 8250 driver defaults to 9600 baud if no console options are provided via the command line. This can result in garbled output if the firmware or bootloader has already initialized the UART to a different speed.

Introduce CONFIG_SERIAL_8250_PROBE_BAUD. When enabled, the driver will attempt to read the current baud rate from the hardware registers if no options are specified, rather than forcing the 9600 default.

---
 drivers/tty/serial/8250/8250_core.c |  2 +-
 drivers/tty/serial/8250/8250_port.c |  5 ++++-
 drivers/tty/serial/8250/Kconfig     | 12 ++++++++++++
 3 files changed, 17 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_core.c +1 -1
index 0e81f78c6063..c11b19921a1f 100644
@@ -427,7 +427,7 @@ static int univ8250_console_setup(struct console *co, char *options)
 	/* link port to console */
 	uart_port_set_cons(port, co);
 
-	retval = serial8250_console_setup(port, options, false);
+	retval = serial8250_console_setup(port, options, IS_ENABLED(CONFIG_SERIAL_8250_PROBE_BAUD));
 	if (retval != 0)
 		uart_port_set_cons(port, NULL);
 	return retval;
drivers/tty/serial/8250/8250_port.c +4 -1
index 719faf92aa8a..5309b921e7b7 100644
@@ -3399,8 +3399,11 @@ int serial8250_console_setup(struct uart_port *port, char *options, bool probe)
 
 	if (options)
 		uart_parse_options(options, &baud, &parity, &bits, &flow);
-	else if (probe)
+	else if (probe) {
 		baud = probe_baud(port);
+		pr_info("console [%s%d] probed baud rate: %d\n",
+			port->cons->name, port->cons->index, baud);
+	}
 
 	ret = uart_set_options(port, port->cons, baud, parity, bits, flow);
 	if (ret)
drivers/tty/serial/8250/Kconfig +12 -0
index c488ff6f2865..bee6a82023d4 100644
@@ -596,3 +596,15 @@ config SERIAL_OF_PLATFORM
 	  are probed through devicetree, including Open Firmware based
 	  PowerPC systems and embedded systems on architectures using the
 	  flattened device tree format.
+
+config SERIAL_8250_PROBE_BAUD
+	bool "Probe baud rate if console options are missing"
+	depends on SERIAL_8250
+	help
+	  If the "console=" command line parameter is missing options (e.g.,
+	  "console=ttyS0" instead of "console=ttyS0,115200n8"), this option
+	  allows the kernel to probe the baud rate from hardware instead of
+	  defaulting to 9600.
+
+	  If a baud rate is explicitly provided in the options, that value
+	  is always respected.
Signature · 1 line
2.51.0

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.

You are receiving this message because of the following common error(s) as indicated below:

- This looks like a new version of a previously submitted patch, but you did not list below the --- line any changes from the previous version. Please read the section entitled "The canonical patch format" in the kernel file, Documentation/process/submitting-patches.rst for what needs to be done here to properly describe this.

If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.

thanks,

greg k-h's patch email bot