Skip to contentSkip to conversation

earlycon: Let users set the clock frequency

PATCH Superseded Ricardo Ribalda 2 participants 5 messages Nov 24, 2022

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 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 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: Replace simple_strtoul with kstrtouint
earlycon: Let users set the clock frequency

 Documentation/admin-guide/kernel-parameters.txt | 12 +++++++-----
 drivers/tty/serial/earlycon.c                   | 17 ++++++++++++++---
 2 files changed, 21 insertions(+), 8 deletions(-)

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

Best regards,

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

PATCH v2 1/2 earlycon: Replace simple_strtoul with kstrtouint

Baud rate is declared as unsigned integer. Use the right function.

drivers/tty/serial/earlycon.c +6 -2
index a5f380584cda..5b73da9487b1 100644
@@ -120,7 +120,9 @@ static int __init parse_options(struct earlycon_device *device, char *options)
 	}
 
 	if (options) {
-		device->baud = simple_strtoul(options, NULL, 0);
+		if (kstrtouint(options, 0, &device->baud) < 0)
+			pr_warn("[%s] unsupported earlycon baud rate option\n",
+				options);
 		length = min(strcspn(options, " ") + 1,
 			     (size_t)(sizeof(device->options)));
 		strscpy(device->options, options, length);
@@ -303,7 +305,9 @@ int __init of_setup_earlycon(const struct earlycon_id *match,
 		port->uartclk = be32_to_cpu(*val);
 
 	if (options) {
-		early_console_dev.baud = simple_strtoul(options, NULL, 0);
+		if (kstrtouint(options, 0, &early_console_dev.baud) < 0)
+			pr_warn("[%s] unsupported earlycon baud rate options\n",
+				options);
 		strscpy(early_console_dev.options, options,
 			sizeof(early_console_dev.options));
 	}
Signature · 1 line
b4 0.11.0-dev-d93f8
#2 lore raw

PATCH v2 2/2 earlycon: Let users set the clock frequency

In reply to 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 -1
index 5b73da9487b1..2db92d36351b 100644
@@ -120,9 +120,15 @@ static int __init parse_options(struct earlycon_device *device, char *options)
 	}
 
 	if (options) {
+		char *uartclk;
+
 		if (kstrtouint(options, 0, &device->baud) < 0)
 			pr_warn("[%s] unsupported earlycon baud rate option\n",
 				options);
+		uartclk = strchr(options, ',');
+		if (uartclk && kstrtouint(uartclk, 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);
@@ -141,7 +147,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
maintainer
#3 lore raw

Hi,

On 24. 11. 22, 11:02, Ricardo Ribalda wrote:
...

drivers/tty/serial/earlycon.c static int __init parse_options(struct earlycon_device *device, char *options) · line 127

Quoted 11 lines
drivers/tty/serial/earlycon.c +2 -0
@@ -120,9 +120,15 @@ static int __init parse_options(struct earlycon_device *device, char *options)
  	}
 
  	if (options) {
+		char *uartclk;
+
  		if (kstrtouint(options, 0, &device->baud) < 0)
  			pr_warn("[%s] unsupported earlycon baud rate option\n",
  				options);

IMO this won't work if there is a comma in options (i.e. your new clkrate param). kstrtouint will return -EINVAL in that case.

drivers/tty/serial/earlycon.c static int __init parse_options(struct earlycon_device *device, char *options) · line 129

Quoted 2 lines
drivers/tty/serial/earlycon.c +2 -0
+		uartclk = strchr(options, ',');
+		if (uartclk && kstrtouint(uartclk, 0, &port->uartclk) < 0)

You are giving ",number" to kstrtouint, right? That won't work either ;).

regards,

Signature · 1 line
js
#4 lore raw
Quoted 20 lines · Jiri Slaby

Hi,

On 24. 11. 22, 11:02, Ricardo Ribalda wrote:
...

drivers/tty/serial/earlycon.c static int __init parse_options(struct earlycon_device *device, char *options) · line 127

Quoted 11 lines
drivers/tty/serial/earlycon.c +2 -0
@@ -120,9 +120,15 @@ static int __init parse_options(struct earlycon_device *device, char *options)
      }
 
      if (options) {
+             char *uartclk;
+
              if (kstrtouint(options, 0, &device->baud) < 0)
                      pr_warn("[%s] unsupported earlycon baud rate option\n",
                              options);

IMO this won't work if there is a comma in options (i.e. your new clkrate param). kstrtouint will return -EINVAL in that case.

Quoted 4 lines

drivers/tty/serial/earlycon.c static int __init parse_options(struct earlycon_device *device, char *options) · line 129

Quoted 2 lines
drivers/tty/serial/earlycon.c +2 -0
+             uartclk = strchr(options, ',');
+             if (uartclk && kstrtouint(uartclk, 0, &port->uartclk) < 0)

You are giving ",number" to kstrtouint, right? That won't work either ;).

The fun thing is that it worked because it fell back to the acpi parameters :). Will send a v3

Thanks!

Quoted 5 lines

regards,
--
js

Signature · 1 line
Ricardo Ribalda