Skip to contentSkip to conversation

serial: 8250_of: support an optional bus clock

PATCH Superseded Alex Elder 3 participants 7 messages Apr 9, 2025 – Apr 10, 2025

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Alex Elder

author
#0 lore raw

v2 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.

Since the first version, the DT binding (which had errors) was updated to properly define the number of clocks and clock names, dependent on the compatible string as suggested by Rob Herring.

The logic that looks up the optional bus clock has also been changed, as requested by Andy Shevchenko. In addition, the bus clock pointer (which was never used after it was enabled) is no longer stored in the of_serial_info structure.

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

-Alex

Alex Elder (2):
dt-bindings: serial: 8250: support an optional second clock
serial: 8250_of: add support for an optional bus clock

 .../devicetree/bindings/serial/8250.yaml      | 30 ++++++++++++++++++-
 drivers/tty/serial/8250/8250_of.c             | 11 ++++++-
 2 files changed, 39 insertions(+), 2 deletions(-)
Signature · 1 line
2.45.2
author
#1 lore raw

PATCH v2 1/2 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.

---
v2: Require both clocks to be specified with names for SpacemiT

 .../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
maintainer Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: serial: 8250: support an optional second clock

Quoted 5 lines · Alex Elder

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.

Quoted 7 lines

---
v2: Require both clocks to be specified with names for SpacemiT

 .../devicetree/bindings/serial/8250.yaml      | 30 ++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
author
#3 lore raw

PATCH v2 2/2 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.

---
v2: Update logic to more check for the optional bus clock first

 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
#4 lore raw

Re: [PATCH v2 2/2] serial: 8250_of: add support for an optional bus clock

Hi Alex,

Quoted 19 lines · 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.

---
v2: Update logic to more check for the optional bus clock first

 drivers/tty/serial/8250/8250_of.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_of.c +0 -0
index 11c860ea80f60..a90a5462aa72a 100644

drivers/tty/serial/8250/8250_of.c static int of_platform_serial_setup(struct platform_device *ofdev, · line 126

Quoted 5 lines
drivers/tty/serial/8250/8250_of.c +1 -1
@@ -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;

we also need to handle clk in suspend/resume procedure, so I think you need to put bus_clk inside struct of_serial_info..

drivers/tty/serial/8250/8250_of.c static int of_platform_serial_setup(struct platform_device *ofdev, · line 128

Quoted 2 lines
drivers/tty/serial/8250/8250_of.c +2 -0
+
+		bus_clk = devm_clk_get_optional_enabled(dev, "bus");

for the 'optional', we can interpret it's optional for other vendor UART, but a must required clk for SpacemiT's k1 UART controller

would it better to guard this inside a compatible test or even introduce a flag in compatible data?

	if (of_device_is_compatible(pdev->dev.of_node, "spacemit,k1-uart")) {
		bus_clk = devm_clk_get_enabled(dev, "bus");
		..
	}

}

Quoted 13 lines
drivers/tty/serial/8250/8250_of.c +7 -0
+		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
Signature · 3 lines
Yixun Lan (dlan)
Gentoo Linux Developer
GPG Key ID AABEFD55
author
#5 lore raw

Re: [PATCH v2 2/2] serial: 8250_of: add support for an optional bus clock

Quoted 23 lines · Yixun Lan

Hi Alex,

Quoted 20 lines · 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.

---
v2: Update logic to more check for the optional bus clock first

  drivers/tty/serial/8250/8250_of.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_of.c +0 -0
index 11c860ea80f60..a90a5462aa72a 100644
@@ -123,7 +123,16 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
 
Quoted 6 lines

drivers/tty/serial/8250/8250_of.c static int of_platform_serial_setup(struct platform_device *ofdev, · line 126

Quoted 4 lines
drivers/tty/serial/8250/8250_of.c +1 -1
  	/* Get clk rate through clk driver if present */
  	if (!port->uartclk) {
-		info->clk = devm_clk_get_enabled(dev, NULL);
+		struct clk *bus_clk;

we also need to handle clk in suspend/resume procedure, so I think you need to put bus_clk inside struct of_serial_info..

OK, I didn't do anything for that in previous versions of the series.

I think that means we'd call clk_disable_unprepare() on the bus clock after doing so for the function clock. And clk_prepare_enable() on the bus clock before doing that for the function clock in of_serial_resume(). That's easy.

Is there anything further you think is required? There is no clock rate associated with the bus clock that I know of, so even if the function clock rate changes, the bus clock can remain as-is.

Quoted 8 lines

drivers/tty/serial/8250/8250_of.c static int of_platform_serial_setup(struct platform_device *ofdev, · line 128

Quoted 3 lines
drivers/tty/serial/8250/8250_of.c +2 -0
+
+		bus_clk = devm_clk_get_optional_enabled(dev, "bus");

for the 'optional', we can interpret it's optional for other vendor UART, but a must required clk for SpacemiT's k1 UART controller

would it better to guard this inside a compatible test or even introduce a flag in compatible data?

I don't personally think so. We could, but the DT binding is going out of its way to define when the bus clock is required. This is simpler, and generic.

-Alex

Quoted 20 lines
	if (of_device_is_compatible(pdev->dev.of_node, "spacemit,k1-uart")) {
		bus_clk = devm_clk_get_enabled(dev, "bus");
		..
	}

}

Quoted 13 lines
drivers/tty/serial/8250/8250_of.c +7 -0
+		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
#6 lore raw

Re: [PATCH v2 2/2] serial: 8250_of: add support for an optional bus clock

Hi Alex,

Quoted 31 lines · Alex Elder
Quoted 23 lines · Yixun Lan

Hi Alex,

Quoted 20 lines · 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.

---
v2: Update logic to more check for the optional bus clock first

  drivers/tty/serial/8250/8250_of.c | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_of.c +0 -0
index 11c860ea80f60..a90a5462aa72a 100644
@@ -123,7 +123,16 @@ static int of_platform_serial_setup(struct platform_device *ofdev,
 
Quoted 6 lines

drivers/tty/serial/8250/8250_of.c static int of_platform_serial_setup(struct platform_device *ofdev, · line 126

Quoted 4 lines
drivers/tty/serial/8250/8250_of.c +1 -1
  	/* Get clk rate through clk driver if present */
  	if (!port->uartclk) {
-		info->clk = devm_clk_get_enabled(dev, NULL);
+		struct clk *bus_clk;

we also need to handle clk in suspend/resume procedure, so I think you need to put bus_clk inside struct of_serial_info..

Quoted 8 lines

OK, I didn't do anything for that in previous versions of the series.

I think that means we'd call clk_disable_unprepare() on the bus clock after doing so for the function clock. And clk_prepare_enable() on the bus clock before doing that for the function clock in of_serial_resume(). That's easy.

right, pretty much similar to info->clk

Quoted 5 lines

Is there anything further you think is required? There is no clock rate associated with the bus clock that I know of, so even if the function clock rate changes, the bus clock can remain as-is.

no further info I know of, my best guess, the rate doesn't really matter, a wide clk range should just work fine.

Quoted 6 lines
Quoted 6 lines

drivers/tty/serial/8250/8250_of.c static int of_platform_serial_setup(struct platform_device *ofdev, · line 128

Quoted 3 lines
drivers/tty/serial/8250/8250_of.c +2 -0
+
+		bus_clk = devm_clk_get_optional_enabled(dev, "bus");

for the 'optional', we can interpret it's optional for other vendor UART, but a must required clk for SpacemiT's k1 UART controller

Quoted 7 lines
Quoted 2 lines

would it better to guard this inside a compatible test or even introduce a flag in compatible data?

I don't personally think so. We could, but the DT binding is going out of its way to define when the bus clock is required. This is simpler, and generic.

I would personally choose the way of introducing a flag of compatible data, but it's a lot change of the code (may not worth the effort)..

anyway, I'm fine with your current version, and yes, it's generic thanks for doing this..

Signature · 3 lines
Yixun Lan (dlan)
Gentoo Linux Developer
GPG Key ID AABEFD55