Skip to contentSkip to conversation

earlycon: Let users set the clock frequency

PATCH In review Ricardo Ribalda 3 participants 7 messages Nov 24, 2022 – Dec 12, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover earlycon: Let users set the clock frequency

Some platforms, namely AMD Picasso, use non standard uart clocks (48M), witch makes it impossible to use with earlycon.

Let the user select its own frequency.

To: Jonathan Corbet <[email protected]>
To: Greg Kroah-Hartman <[email protected]>
To: Jiri Slaby <[email protected]>

---
Changes in v3:
- Revert patch to use kstrtouint for baudrate
- Parse the number not the ,number (Thanks Jiri :) )
- Add optional patch to increase the options size
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Add a patch to fix handling of baudrate
- Use kstrtouint instead of simple_strtoul
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Ricardo Ribalda (2):
earlycon: Let users set the clock frequency
earlycon: Increase options size

 Documentation/admin-guide/kernel-parameters.txt | 12 +++++++-----
 drivers/tty/serial/earlycon.c                   |  9 ++++++++-
 include/linux/serial_core.h                     |  2 +-
 3 files changed, 16 insertions(+), 7 deletions(-)

---
base-commit: 4312098baf37ee17a8350725e6e0d0e8590252d4
change-id: 20221123-serial-clk-85db701ada57

Best regards,

Signature · 1 line
Ricardo Ribalda <[email protected]>
#1 lore raw

PATCH v3 1/2 earlycon: Let users set the clock frequency

Some platforms, namely AMD Picasso, use non standard uart clocks (48M), witch makes it impossible to use with earlycon.

Let the user select its own frequency.

Documentation/admin-guide/kernel-parameters.txt +7 -5
index a465d5242774..9efb6c3b0486 100644
@@ -1182,10 +1182,10 @@
 			specified, the serial port must already be setup and
 			configured.
 
-		uart[8250],io,<addr>[,options]
-		uart[8250],mmio,<addr>[,options]
-		uart[8250],mmio32,<addr>[,options]
-		uart[8250],mmio32be,<addr>[,options]
+		uart[8250],io,<addr>[,options[,uartclk]]
+		uart[8250],mmio,<addr>[,options[,uartclk]]
+		uart[8250],mmio32,<addr>[,options[,uartclk]]
+		uart[8250],mmio32be,<addr>[,options[,uartclk]]
 		uart[8250],0x<addr>[,options]
 			Start an early, polled-mode console on the 8250/16550
 			UART at the specified I/O port or MMIO address.
@@ -1194,7 +1194,9 @@
 			If none of [io|mmio|mmio32|mmio32be], <addr> is assumed
 			to be equivalent to 'mmio'. 'options' are specified
 			in the same format described for "console=ttyS<n>"; if
-			unspecified, the h/w is not initialized.
+			unspecified, the h/w is not initialized. 'uartclk' is
+			the uart clock frequency; if unspecified, it is set
+			to 'BASE_BAUD' * 16.
 
 		pl011,<addr>
 		pl011,mmio32,<addr>
drivers/tty/serial/earlycon.c +8 -1
index a5f380584cda..3a0c88419b6c 100644
@@ -120,7 +120,13 @@ static int __init parse_options(struct earlycon_device *device, char *options)
 	}
 
 	if (options) {
+		char *uartclk;
+
 		device->baud = simple_strtoul(options, NULL, 0);
+		uartclk = strchr(options, ',');
+		if (uartclk && kstrtouint(uartclk + 1, 0, &port->uartclk) < 0)
+			pr_warn("[%s] unsupported earlycon uart clkrate option\n",
+				options);
 		length = min(strcspn(options, " ") + 1,
 			     (size_t)(sizeof(device->options)));
 		strscpy(device->options, options, length);
@@ -139,7 +145,8 @@ static int __init register_earlycon(char *buf, const struct earlycon_id *match)
 		buf = NULL;
 
 	spin_lock_init(&port->lock);
-	port->uartclk = BASE_BAUD * 16;
+	if (!port->uartclk)
+		port->uartclk = BASE_BAUD * 16;
 	if (port->mapbase)
 		port->membase = earlycon_map(port->mapbase, 64);
 
Signature · 1 line
b4 0.11.0-dev-d93f8
#2 lore raw

Hi Jiri

is there something else that I am missing here?

Thanks!

Quoted 69 lines · Ricardo Ribalda

Some platforms, namely AMD Picasso, use non standard uart clocks (48M), witch makes it impossible to use with earlycon.

Let the user select its own frequency.

Documentation/admin-guide/kernel-parameters.txt +7 -5
index a465d5242774..9efb6c3b0486 100644
@@ -1182,10 +1182,10 @@
                        specified, the serial port must already be setup and
                        configured.
 
-               uart[8250],io,<addr>[,options]
-               uart[8250],mmio,<addr>[,options]
-               uart[8250],mmio32,<addr>[,options]
-               uart[8250],mmio32be,<addr>[,options]
+               uart[8250],io,<addr>[,options[,uartclk]]
+               uart[8250],mmio,<addr>[,options[,uartclk]]
+               uart[8250],mmio32,<addr>[,options[,uartclk]]
+               uart[8250],mmio32be,<addr>[,options[,uartclk]]
                uart[8250],0x<addr>[,options]
                        Start an early, polled-mode console on the 8250/16550
                        UART at the specified I/O port or MMIO address.
@@ -1194,7 +1194,9 @@
                        If none of [io|mmio|mmio32|mmio32be], <addr> is assumed
                        to be equivalent to 'mmio'. 'options' are specified
                        in the same format described for "console=ttyS<n>"; if
-                       unspecified, the h/w is not initialized.
+                       unspecified, the h/w is not initialized. 'uartclk' is
+                       the uart clock frequency; if unspecified, it is set
+                       to 'BASE_BAUD' * 16.
 
                pl011,<addr>
                pl011,mmio32,<addr>
drivers/tty/serial/earlycon.c +8 -2
index a5f380584cda..3a0c88419b6c 100644
@@ -120,7 +120,13 @@ static int __init parse_options(struct earlycon_device *device, char *options)
        }
 
        if (options) {
+               char *uartclk;
+
                device->baud = simple_strtoul(options, NULL, 0);
+               uartclk = strchr(options, ',');
+               if (uartclk && kstrtouint(uartclk + 1, 0, &port->uartclk) < 0)
+                       pr_warn("[%s] unsupported earlycon uart clkrate option\n",
+                               options);
                length = min(strcspn(options, " ") + 1,
                             (size_t)(sizeof(device->options)));
                strscpy(device->options, options, length);
@@ -139,7 +145,8 @@ static int __init register_earlycon(char *buf, const struct earlycon_id *match)
                buf = NULL;
 
        spin_lock_init(&port->lock);
-       port->uartclk = BASE_BAUD * 16;
+       if (!port->uartclk)
+               port->uartclk = BASE_BAUD * 16;
        if (port->mapbase)
                port->membase = earlycon_map(port->mapbase, 64);
 
 
--

b4 0.11.0-dev-d93f8

Signature · 1 line
Ricardo Ribalda
#3 lore raw
Quoted 3 lines · Ricardo Ribalda

Hi Jiri

is there something else that I am missing here?

Sorry, been busy with other reviews. I will queue this up after 6.2-rc1 is out, thanks.

greg k-h

maintainer Reviewed-by on v3 1/2
#4 lore raw
In reply to Ricardo Ribalda
Quoted 6 lines · Ricardo Ribalda

Some platforms, namely AMD Picasso, use non standard uart clocks (48M), witch makes it impossible to use with earlycon.

Let the user select its own frequency.

Quoted 59 lines
Documentation/admin-guide/kernel-parameters.txt +7 -5
index a465d5242774..9efb6c3b0486 100644
@@ -1182,10 +1182,10 @@
  			specified, the serial port must already be setup and
  			configured.
 
-		uart[8250],io,<addr>[,options]
-		uart[8250],mmio,<addr>[,options]
-		uart[8250],mmio32,<addr>[,options]
-		uart[8250],mmio32be,<addr>[,options]
+		uart[8250],io,<addr>[,options[,uartclk]]
+		uart[8250],mmio,<addr>[,options[,uartclk]]
+		uart[8250],mmio32,<addr>[,options[,uartclk]]
+		uart[8250],mmio32be,<addr>[,options[,uartclk]]
  		uart[8250],0x<addr>[,options]
  			Start an early, polled-mode console on the 8250/16550
  			UART at the specified I/O port or MMIO address.
@@ -1194,7 +1194,9 @@
  			If none of [io|mmio|mmio32|mmio32be], <addr> is assumed
  			to be equivalent to 'mmio'. 'options' are specified
  			in the same format described for "console=ttyS<n>"; if
-			unspecified, the h/w is not initialized.
+			unspecified, the h/w is not initialized. 'uartclk' is
+			the uart clock frequency; if unspecified, it is set
+			to 'BASE_BAUD' * 16.
 
  		pl011,<addr>
  		pl011,mmio32,<addr>
drivers/tty/serial/earlycon.c +8 -1
index a5f380584cda..3a0c88419b6c 100644
@@ -120,7 +120,13 @@ static int __init parse_options(struct earlycon_device *device, char *options)
  	}
 
  	if (options) {
+		char *uartclk;
+
  		device->baud = simple_strtoul(options, NULL, 0);
+		uartclk = strchr(options, ',');
+		if (uartclk && kstrtouint(uartclk + 1, 0, &port->uartclk) < 0)
+			pr_warn("[%s] unsupported earlycon uart clkrate option\n",
+				options);
  		length = min(strcspn(options, " ") + 1,
  			     (size_t)(sizeof(device->options)));
  		strscpy(device->options, options, length);
@@ -139,7 +145,8 @@ static int __init register_earlycon(char *buf, const struct earlycon_id *match)
  		buf = NULL;
 
  	spin_lock_init(&port->lock);
-	port->uartclk = BASE_BAUD * 16;
+	if (!port->uartclk)
+		port->uartclk = BASE_BAUD * 16;
  	if (port->mapbase)
  		port->membase = earlycon_map(port->mapbase, 64);
 
Signature · 2 lines
js
suse labs
#5 lore raw

PATCH v3 2/2 earlycon: Increase options size

In reply to Ricardo Ribalda

Now that the clock frequency is also part of the options, 16 bytes is too little.

Without this patch dmesg does not show the whole options, Eg:

earlycon: uart0 at MMIO32 0x00000000fedc9000 (options '115200n8,480000')

instead of: '115200n8,48000000'

include/linux/serial_core.h +1 -1
index d657f2a42a7b..f555927195da 100644
@@ -701,7 +701,7 @@ static inline int uart_poll_timeout(struct uart_port *port)
 struct earlycon_device {
 	struct console *con;
 	struct uart_port port;
-	char options[16];		/* e.g., 115200n8 */
+	char options[32];		/* e.g., 115200n8 */
 	unsigned int baud;
 };
 
Signature · 1 line
b4 0.11.0-dev-d93f8
maintainer Reviewed-by on v3 2/2
#6 lore raw

Re: [PATCH v3 2/2] earlycon: Increase options size

Quoted 10 lines · Ricardo Ribalda

Now that the clock frequency is also part of the options, 16 bytes is too little.

Without this patch dmesg does not show the whole options, Eg:

earlycon: uart0 at MMIO32 0x00000000fedc9000 (options '115200n8,480000')

instead of: '115200n8,48000000'

Quoted 14 lines
include/linux/serial_core.h +1 -1
index d657f2a42a7b..f555927195da 100644
@@ -701,7 +701,7 @@ static inline int uart_poll_timeout(struct uart_port *port)
  struct earlycon_device {
  	struct console *con;
  	struct uart_port port;
-	char options[16];		/* e.g., 115200n8 */
+	char options[32];		/* e.g., 115200n8 */
  	unsigned int baud;
  };
 
Signature · 2 lines
js
suse labs