Skip to contentSkip to conversation

Fix orphan clocks in clk-th1520-ap driver

PATCH In review Yao Zi 2 participants 7 messages Jul 10, 2025 – Jul 13, 2025

Subsystems (3)
lore
Share & tools
lore

Yao Zi

author
#0 lore raw

v2 cover Fix orphan clocks in clk-th1520-ap driver

clk_orphan_dump shows two suspicious orphan clocks on TH1520 when booting the kernel with mainline U-Boot,

        $ cat /sys/kernel/debug/clk/clk_orphan_dump | jq 'keys'
        [
          "c910",
          "osc_12m"
        ]

where the correct parents should be c910-i0 for c910, and osc_24m for osc_12m.

Note that the c910's case cannot be reproduced with vendor U-Boot, which always reparents c910 to its second parent, cpu-pll1. Another way to confirm the bug is to examine /sys/kernel/debug/clk/c910/clk_possible_parents, which obviously doesn't match c910's definition.

This series corrects the parent description of these two clocks to eliminate the orphans.

Changed from v1
- Split the two fixes into separate patches
- Add a static qualifier for the new definition of osc_12m
- Link to v1: https://lore.kernel.org/all/[email protected]/

Thanks for your time and review.

Yao Zi (2):
clk: thead: th1520-ap: Correctly refer the parent of osc_12m
clk: thead: th1520-ap: Correctly refer the parent of c910-i0

 drivers/clk/thead/clk-th1520-ap.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
Signature · 1 line
2.50.0
author
#1 lore raw

PATCH v2 1/2 clk: thead: th1520-ap: Correctly refer the parent of osc_12m

The "osc_12m" fixed factor clock refers the external oscillator by setting clk_parent_data.fw_name to osc_24m, which is obviously wrong since no clock-names property is allowed for compatible thead,th1520-clk-ap.

Refer the oscillator as parent by index instead.

Fixes ae81b69fd2b1 ("clk: thead: Add support for T-Head TH1520 AP_SUBSYS clocks")
---
 drivers/clk/thead/clk-th1520-ap.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/clk/thead/clk-th1520-ap.c +8 -1
index ebfb1d59401d..42feb4bb6329 100644
@@ -582,7 +582,14 @@ static const struct clk_parent_data peri2sys_apb_pclk_pd[] = {
 	{ .hw = &peri2sys_apb_pclk.common.hw }
 };
 
-static CLK_FIXED_FACTOR_FW_NAME(osc12m_clk, "osc_12m", "osc_24m", 2, 1, 0);
+static struct clk_fixed_factor osc12m_clk = {
+	.div		= 2,
+	.mult		= 1,
+	.hw.init	= CLK_HW_INIT_PARENTS_DATA("osc_12m",
+						   osc_24m_clk,
+						   &clk_fixed_factor_ops,
+						   0),
+};
 
 static const char * const out_parents[] = { "osc_24m", "osc_12m" };
 
Signature · 1 line
2.50.0
maintainer Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] clk: thead: th1520-ap: Correctly refer the parent of osc_12m

Quoted 35 lines · Yao Zi

The "osc_12m" fixed factor clock refers the external oscillator by setting clk_parent_data.fw_name to osc_24m, which is obviously wrong since no clock-names property is allowed for compatible thead,th1520-clk-ap.

Refer the oscillator as parent by index instead.

Fixes ae81b69fd2b1 ("clk: thead: Add support for T-Head TH1520 AP_SUBSYS clocks")
---
 drivers/clk/thead/clk-th1520-ap.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/clk/thead/clk-th1520-ap.c +8 -1
index ebfb1d59401d..42feb4bb6329 100644
@@ -582,7 +582,14 @@ static const struct clk_parent_data peri2sys_apb_pclk_pd[] = {
 	{ .hw = &peri2sys_apb_pclk.common.hw }
 };
 
-static CLK_FIXED_FACTOR_FW_NAME(osc12m_clk, "osc_12m", "osc_24m", 2, 1, 0);
+static struct clk_fixed_factor osc12m_clk = {
+	.div		= 2,
+	.mult		= 1,
+	.hw.init	= CLK_HW_INIT_PARENTS_DATA("osc_12m",
+						   osc_24m_clk,
+						   &clk_fixed_factor_ops,
+						   0),
+};
 
 static const char * const out_parents[] = { "osc_24m", "osc_12m" };
 
Signature · 1 line
2.50.0

Thanks for fixing this. osc_12m now appears under osc_24m in clk_summary.

Drew

maintainer
#3 lore raw

Re: [PATCH v2 1/2] clk: thead: th1520-ap: Correctly refer the parent of osc_12m

Quoted 39 lines · Drew Fustini
Quoted 35 lines · Yao Zi

The "osc_12m" fixed factor clock refers the external oscillator by setting clk_parent_data.fw_name to osc_24m, which is obviously wrong since no clock-names property is allowed for compatible thead,th1520-clk-ap.

Refer the oscillator as parent by index instead.

Fixes ae81b69fd2b1 ("clk: thead: Add support for T-Head TH1520 AP_SUBSYS clocks")
---
 drivers/clk/thead/clk-th1520-ap.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/clk/thead/clk-th1520-ap.c +8 -1
index ebfb1d59401d..42feb4bb6329 100644
@@ -582,7 +582,14 @@ static const struct clk_parent_data peri2sys_apb_pclk_pd[] = {
 	{ .hw = &peri2sys_apb_pclk.common.hw }
 };
 
-static CLK_FIXED_FACTOR_FW_NAME(osc12m_clk, "osc_12m", "osc_24m", 2, 1, 0);
+static struct clk_fixed_factor osc12m_clk = {
+	.div		= 2,
+	.mult		= 1,
+	.hw.init	= CLK_HW_INIT_PARENTS_DATA("osc_12m",
+						   osc_24m_clk,
+						   &clk_fixed_factor_ops,
+						   0),
+};
 
 static const char * const out_parents[] = { "osc_24m", "osc_12m" };
 
Signature · 1 line
2.50.0
Quoted 4 lines

Thanks for fixing this. osc_12m now appears under osc_24m in clk_summary.

Drew

Thank you for the patch. I've now applied it to thead-clk-for-next as commit d274c77ffa20 [1].

Drew

[1] https://github.com/pdp7/linux/commit/d274c77ffa202b70ad01d579f33b73b4de123375

author
#4 lore raw

PATCH v2 2/2 clk: thead: th1520-ap: Correctly refer the parent of c910-i0

In reply to Yao Zi

The correct parent of c910, c910-i0, is registered with devm_clk_hw_register_mux_parent_data_table(), which creates a clk_hw structure from scratch. But it's assigned as c910's parent by referring &c910_i0_clk.common.hw, confusing the CCF since this clk_hw structure is never registered.

Refer c910-i0 by its name instead to avoid turning c910 into an orphan clock.

Fixes ae81b69fd2b1 ("clk: thead: Add support for T-Head TH1520 AP_SUBSYS clocks")
---
 drivers/clk/thead/clk-th1520-ap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/thead/clk-th1520-ap.c +1 -1
index 42feb4bb6329..41ed72b1a915 100644
@@ -427,7 +427,7 @@ static struct ccu_mux c910_i0_clk = {
 };
 
 static const struct clk_parent_data c910_parents[] = {
-	{ .hw = &c910_i0_clk.common.hw },
+	{ .index = -1, .name = "c910-i0" },
 	{ .hw = &cpu_pll1_clk.common.hw }
 };
 
Signature · 1 line
2.50.0
maintainer
#5 lore raw

Re: [PATCH v2 2/2] clk: thead: th1520-ap: Correctly refer the parent of c910-i0

Quoted 20 lines · Yao Zi

The correct parent of c910, c910-i0, is registered with devm_clk_hw_register_mux_parent_data_table(), which creates a clk_hw structure from scratch. But it's assigned as c910's parent by referring &c910_i0_clk.common.hw, confusing the CCF since this clk_hw structure is never registered.

Refer c910-i0 by its name instead to avoid turning c910 into an orphan clock.

Fixes ae81b69fd2b1 ("clk: thead: Add support for T-Head TH1520 AP_SUBSYS clocks")
---
 drivers/clk/thead/clk-th1520-ap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/thead/clk-th1520-ap.c +0 -0
index 42feb4bb6329..41ed72b1a915 100644

drivers/clk/thead/clk-th1520-ap.c static struct ccu_mux c910_i0_clk = { · line 430

Quoted 5 lines
drivers/clk/thead/clk-th1520-ap.c +1 -1
@@ -427,7 +427,7 @@ static struct ccu_mux c910_i0_clk = {
 };
 
 static const struct clk_parent_data c910_parents[] = {
-	{ .hw = &c910_i0_clk.common.hw },
+	{ .index = -1, .name = "c910-i0" },

Thanks for the patch. Unfortunately, I chatted with Stephen about this on irc and we need to avoid using strings in clk_parent_data. I'm trying to see how to correctly assign the pointer in the c910_parents[] after c910_io_clk has been registered.

Thanks,
Drew

author
#6 lore raw

Re: [PATCH v2 2/2] clk: thead: th1520-ap: Correctly refer the parent of c910-i0

Quoted 23 lines · Drew Fustini
Quoted 22 lines · Yao Zi

The correct parent of c910, c910-i0, is registered with devm_clk_hw_register_mux_parent_data_table(), which creates a clk_hw structure from scratch. But it's assigned as c910's parent by referring &c910_i0_clk.common.hw, confusing the CCF since this clk_hw structure is never registered.

Refer c910-i0 by its name instead to avoid turning c910 into an orphan clock.

Fixes ae81b69fd2b1 ("clk: thead: Add support for T-Head TH1520 AP_SUBSYS clocks")
---
 drivers/clk/thead/clk-th1520-ap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/clk/thead/clk-th1520-ap.c +0 -0
index 42feb4bb6329..41ed72b1a915 100644
@@ -427,7 +427,7 @@ static struct ccu_mux c910_i0_clk = {
 };
 
Quoted 8 lines

drivers/clk/thead/clk-th1520-ap.c static struct ccu_mux c910_i0_clk = { · line 430

Quoted 3 lines
drivers/clk/thead/clk-th1520-ap.c +1 -1
 static const struct clk_parent_data c910_parents[] = {
-	{ .hw = &c910_i0_clk.common.hw },
+	{ .index = -1, .name = "c910-i0" },

Thanks for the patch. Unfortunately, I chatted with Stephen about this on irc and we need to avoid using strings in clk_parent_data. I'm trying to see how to correctly assign the pointer in the c910_parents[] after c910_io_clk has been registered.

If we stop using *_register_mux() for all the muxes, the problem should go away: the key cause is that *_register_mux() always allocates a new clk_mux structure, which in turn contains a new clk_hw structure.

We could avoid the ccu_mux structure, instead defining clk_muxes directly and register them with devm_clk_hw_register(), for example,

	static struct clk_mux c910_i0_clk = {
		.reg		= 0x100,
		.mask		= BIT(0),
		.shift		= 1,
		.hw.init	= CLK_HW_INIT_PARENT_DATA("c910-i0",
							  c910_i0_parents,
							  &clk_mux_ops,
							  0),
	};

	c910_i0_clk.reg += base;
	ret = devm_clk_hw_register(dev, &c910_i0_clk.hw);

(not tested, just for demostration)

Now no new clk_hw structure is created and we could refer to muxes by its hw member when defining other clocks.

Quoted 2 lines

Thanks,
Drew

Regards,
Yao Zi