Skip to contentSkip to conversation

serial: 8250_of: support an optional bus clock

PATCH In review Alex Elder 3 participants 6 messages Apr 11, 2025 – Apr 12, 2025

Subsystems (3)
lore
Share & tools
lore

Alex Elder

author
#0 lore raw

v4 cover serial: 8250_of: support an optional bus clock

The SpacemiT UART hardware requires a bus clock to be enabled in addition to the primary function clock.

This series makes it possible to specify both clocks via DTS. If a bus clock is required, it and the primary clock are fetched by name.

This code is available here:
https://github.com/riscstar/linux/tree/outgoing/serial-v4

Changes between v3 and v4:
- I simplified the third patch by reusing the local variable, as suggested by Andy Shevchenko
- The first two patches are identical to what was in v3

Here is version 3 of this series:
https://lore.kernel.org/lkml/[email protected]/

Changes between v2 and v3:
- A third patch was added to disable the bus clock on suspend and enable it again on resume, as requested by Yixun Lan
- Rob's Reviewed-by tag has been added to patch 1
- The first two patches are otherwise identical to what was in v2

Here is version 2 of this series:
https://lore.kernel.org/lkml/[email protected]/

Changes between v1 and v2:
- The DT binding was fixed to properly define the number of clocks and clock names based on the compatible string, as suggested by Rob Herring
- Logic to look up the optional bus clock was changed as requested by Andy Shevchenko
- The bus clock pointer (which was never used after it was enabled) was renmoved from the of_serial_info structure

Here is the first version of this series:
https://lore.kernel.org/lkml/[email protected]/

-Alex

Alex Elder (3):
dt-bindings: serial: 8250: support an optional second clock
serial: 8250_of: add support for an optional bus clock
serial: 8250_of: manage bus clock in suspend/resume

 .../devicetree/bindings/serial/8250.yaml      | 30 ++++++++++++++++++-
 drivers/tty/serial/8250/8250_of.c             | 15 +++++++++-
 2 files changed, 43 insertions(+), 2 deletions(-)

base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8

Signature · 1 line
2.45.2
author
#1 lore raw

PATCH v4 1/3 dt-bindings: serial: 8250: support an optional second clock

The SpacemiT UART driver requires a bus clock to be enabled in addition to the primary function clock. Add the option to specify two clocks for an 8250-compatible UART, named "core" and "bus". If both are needed, require them to be named.

---
 .../devicetree/bindings/serial/8250.yaml      | 30 ++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/serial/8250.yaml +29 -1
index dc0d52920575f..33d2016b65090 100644
@@ -135,7 +135,16 @@ properties:
   clock-frequency: true
 
   clocks:
-    maxItems: 1
+    minItems: 1
+    items:
+      - description: The core function clock
+      - description: An optional bus clock
+
+  clock-names:
+    minItems: 1
+    items:
+      - const: core
+      - const: bus
 
   resets:
     maxItems: 1
@@ -224,6 +233,25 @@ required:
   - reg
   - interrupts
 
+if:
+  properties:
+    compatible:
+      contains:
+        const: spacemit,k1-uart
+then:
+  required: [clock-names]
+  properties:
+    clocks:
+      minItems: 2
+    clock-names:
+      minItems: 2
+else:
+  properties:
+    clocks:
+      maxItems: 1
+    clock-names:
+      maxItems: 1
+
 unevaluatedProperties: false
 
 examples:
Signature · 1 line
2.45.2
author
#2 lore raw

PATCH v4 2/3 serial: 8250_of: add support for an optional bus clock

In reply to Alex Elder

The SpacemiT UART requires a bus clock to be enabled, in addition to it's "normal" core clock. Look up the optional bus clock by name, and if that's found, look up the core clock using the name "core".

Supplying a bus clock is optional. If no bus clock is needed, the the first/only clock is used for the core clock.

---
 drivers/tty/serial/8250/8250_of.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_of.c +10 -1
index 11c860ea80f60..a90a5462aa72a 100644
@@ -123,7 +123,16 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
 
 	/* Get clk rate through clk driver if present */
 	if (!port->uartclk) {
-		info->clk = devm_clk_get_enabled(dev, NULL);
+		struct clk *bus_clk;
+
+		bus_clk = devm_clk_get_optional_enabled(dev, "bus");
+		if (IS_ERR(bus_clk)) {
+			ret = dev_err_probe(dev, PTR_ERR(bus_clk), "failed to get bus clock\n");
+			goto err_pmruntime;
+		}
+
+		/* If the bus clock is required, core clock must be named */
+		info->clk = devm_clk_get_enabled(dev, bus_clk ? "core" : NULL);
 		if (IS_ERR(info->clk)) {
 			ret = dev_err_probe(dev, PTR_ERR(info->clk), "failed to get clock\n");
 			goto err_pmruntime;
Signature · 1 line
2.45.2
author
#3 lore raw

PATCH v4 3/3 serial: 8250_of: manage bus clock in suspend/resume

In reply to Alex Elder

Save the bus clock pointer in the of_serial_info structure, and use that to disable the bus clock on suspend and re-enable it on resume.

---
 drivers/tty/serial/8250/8250_of.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/tty/serial/8250/8250_of.c +4 -0
index a90a5462aa72a..d178b6c54ea18 100644
@@ -24,6 +24,7 @@
 
 struct of_serial_info {
 	struct clk *clk;
+	struct clk *bus_clk;
 	struct reset_control *rst;
 	int type;
 	int line;
@@ -138,6 +139,7 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
 			goto err_pmruntime;
 		}
 
+		info->bus_clk = bus_clk;
 		port->uartclk = clk_get_rate(info->clk);
 	}
 	/* If current-speed was set, then try not to change it. */
@@ -299,6 +301,7 @@ static int of_serial_suspend(struct device *dev)
 	if (!uart_console(port) || console_suspend_enabled) {
 		pm_runtime_put_sync(dev);
 		clk_disable_unprepare(info->clk);
+		clk_disable_unprepare(info->bus_clk);
 	}
 	return 0;
 }
@@ -311,6 +314,7 @@ static int of_serial_resume(struct device *dev)
 
 	if (!uart_console(port) || console_suspend_enabled) {
 		pm_runtime_get_sync(dev);
+		clk_prepare_enable(info->bus_clk);
 		clk_prepare_enable(info->clk);
 	}
 
Signature · 1 line
2.45.2
Reviewed-by on v4 3/3
#4 lore raw

Re: [PATCH v4 3/3] serial: 8250_of: manage bus clock in suspend/resume

hi Alex,

Glad to see first 2 patches already accepted
This version is better than v3, thanks

Quoted 4 lines · Alex Elder

Save the bus clock pointer in the of_serial_info structure, and use that to disable the bus clock on suspend and re-enable it on resume.

Quoted 44 lines
---
 drivers/tty/serial/8250/8250_of.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/tty/serial/8250/8250_of.c +4 -0
index a90a5462aa72a..d178b6c54ea18 100644
@@ -24,6 +24,7 @@
 
 struct of_serial_info {
 	struct clk *clk;
+	struct clk *bus_clk;
 	struct reset_control *rst;
 	int type;
 	int line;
@@ -138,6 +139,7 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
 			goto err_pmruntime;
 		}
 
+		info->bus_clk = bus_clk;
 		port->uartclk = clk_get_rate(info->clk);
 	}
 	/* If current-speed was set, then try not to change it. */
@@ -299,6 +301,7 @@ static int of_serial_suspend(struct device *dev)
 	if (!uart_console(port) || console_suspend_enabled) {
 		pm_runtime_put_sync(dev);
 		clk_disable_unprepare(info->clk);
+		clk_disable_unprepare(info->bus_clk);
 	}
 	return 0;
 }
@@ -311,6 +314,7 @@ static int of_serial_resume(struct device *dev)
 
 	if (!uart_console(port) || console_suspend_enabled) {
 		pm_runtime_get_sync(dev);
+		clk_prepare_enable(info->bus_clk);
 		clk_prepare_enable(info->clk);
 	}
 
Signature · 1 line
2.45.2
Signature · 3 lines
Yixun Lan (dlan)
Gentoo Linux Developer
GPG Key ID AABEFD55
Reviewed-by
#5 lore raw

Re: [PATCH v4 3/3] serial: 8250_of: manage bus clock in suspend/resume

Quoted 5 lines · Yixun Lan

hi Alex,

Glad to see first 2 patches already accepted
This version is better than v3, thanks

Exactly! I'm not sure this series can be applied due to that. You need to rebase on top of tty-next.

Quoted 6 lines · Alex Elder
Quoted 4 lines

Save the bus clock pointer in the of_serial_info structure, and use that to disable the bus clock on suspend and re-enable it on resume.

Code wise this one is what I have expected, thanks!

Signature · 2 lines
With Best Regards,
Andy Shevchenko