clk: thead: th1520-ap: Correctly refer the parent for c910 and osc_12m
Subsystems (3)
PATCH 1/1 clk: thead: th1520-ap: Correctly refer the parent for c910 and osc_12m
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.
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.
Meanwhile, osc_12m 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.
For c910, refer c910-i0 by its name; for osc_12m, refer the external clock input by index. This eliminates these orphan clocks.
--- drivers/clk/thead/clk-th1520-ap.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/clk/thead/clk-th1520-ap.c +9 -2
@@ -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 } };
@@ -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); +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.49.0
Drew Fustini
maintainerQuoted 11 lines · Yao Zi
clk_orphan_dumpshows 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_24mforosc_12m.
Thanks for sending this patch. However, I only see "osc_12m" listed in clk_orphan_dump. I tried the current next, torvalds master and v6.15 but I didn't ever see "c910" appear [1]. What branch are you using?
I think it would be best for this patch to be split into separate patches for osc_12m and c910.
Quoted 5 lines
The correct parent of c910, c910-i0, is registered with
devm_clk_hw_register_mux_parent_data_table(), which creates aclk_hwstructure from scratch. But it's assigned as c910's parent by referring &c910_i0_clk.common.hw, confusing the CCF since thisclk_hwstructure is never registered.
I recall Stephen Boyd had the feedback when trying to upstream this driver to avoid strings for parents and instead use clk_parent_data or clk_hw pointers directly [2]. It was difficult to find alternitves to parent strings in all instances.
Quoted 18 lines
Meanwhile,
osc_12mrefers the external oscillator by setting clk_parent_data.fw_name toosc_24m, which is obviously wrong since no clock-names property is allowed for compatible thead,th1520-clk-ap.For c910, refer c910-i0 by its name; for
osc_12m, refer the external clock input by index. This eliminates these orphan clocks.Fixes ae81b69fd2b1 ("clk: thead: Add support for T-Head TH1520 AP_SUBSYS clocks")Signed-off-by Yao Zi <[email protected]>--- drivers/clk/thead/clk-th1520-ap.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/clk/thead/clk-th1520-ap.c +0
-0
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" },
Stephen - would this use of a parent string be acceptable?
Quoted 6 lines
drivers/clk/thead/clk-th1520-ap.c +0
-0{ .hw = &cpu_pll1_clk.common.hw } };@@ -582,7 +582,14 @@ static const struct clk_parent_data peri2sys_apb_pclk_pd[] = { { .hw = &peri2sys_apb_pclk.common.hw } };
drivers/clk/thead/clk-th1520-ap.c static const struct clk_parent_data peri2sys_apb_pclk_pd[] = { · line 592
Quoted 10 lines
drivers/clk/thead/clk-th1520-ap.c +8
-1-static CLK_FIXED_FACTOR_FW_NAME(osc12m_clk, "osc_12m", "osc_24m", 2, 1, 0); +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 ), +};
I think this hunk is a good fix for osc_12m. I applied the patch and osc_12m no longer appears in clk_orphan_dump [3]. clk_summary now shows osc_12m under osc_24m.
Quoted 6 lines
drivers/clk/thead/clk-th1520-ap.c +0
-0static const char *const out_parents[] = {"osc_24m" ,"osc_12m" };Signature · 1 line
2.49.0
[1] https://gist.github.com/pdp7/d00f0f4fe3fcf368ce253d606dc7b01f
[2] https://lore.kernel.org/all/[email protected]/
[3] https://gist.github.com/pdp7/30e51ed013d4bedf0c6abc5717e0b6a5
Quoted 10 lines · Drew Fustini
Quoted 9 lines · Yao Zi
clk_orphan_dumpshows 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" ]
Quoted 6 lines
Quoted 2 lines
where the correct parents should be c910-i0 for c910, and
osc_24mforosc_12m.Thanks for sending this patch. However, I only see "
osc_12m" listed inclk_orphan_dump. I tried the current next, torvalds master and v6.15 but I didn't ever see "c910" appear [1]. What branch are you using?
I think it has something to do with the bootloader: as you could see in your clk_orphan_dump, the c910 clock is reparented to cpu-pll1, the second possible parent which could be correctly resolved by the CCF, thus c910 doesn't appear in the clk_orphan_dump.
But with the mainline U-Boot which doesn't reparent or reclock c910 on startup, c910 should remain the reset state and take c910-i0 as parent, and appear in the clk_orphan_dump.
Another way to confirm the bug is to examine /sys/kernel/debug/clk/c910/clk_possible_parents: without the patch, it should be something like
osc_24m cpu-pll1
c910's parents are defined as
static const struct clk_parent_data c910_parents[] = {
{ .hw = &c910_i0_clk.common.hw },
{ .hw = &cpu_pll1_clk.common.hw }
};and the debugfs output looks obviously wrong.
There's another bug in CCF[1] which causes unresolvable parents are shown as the clock-output-names of the clock controller's first parent in debugfs, explaining the output.
Quoted 2 lines
I think it would be best for this patch to be split into separate patches for
osc_12mand c910.
Okay, I originally thought these are relatively small fixes targeting a single driver, hence put them together. I'll split it into two patches in v2.
Quoted 10 lines
Quoted 5 lines
The correct parent of c910, c910-i0, is registered with
devm_clk_hw_register_mux_parent_data_table(), which creates aclk_hwstructure from scratch. But it's assigned as c910's parent by referring &c910_i0_clk.common.hw, confusing the CCF since thisclk_hwstructure is never registered.I recall Stephen Boyd had the feedback when trying to upstream this driver to avoid strings for parents and instead use
clk_parent_dataorclk_hwpointers directly [2]. It was difficult to find alternitves to parent strings in all instances.
Yes, especially the predefined clock types which always allocate a new struct clk_hw, so one has to choose between filling the parent data dynamically or using the parent's name.
Quoted 33 lines
Quoted 18 lines
Meanwhile,
osc_12mrefers the external oscillator by setting clk_parent_data.fw_name toosc_24m, which is obviously wrong since no clock-names property is allowed for compatible thead,th1520-clk-ap.For c910, refer c910-i0 by its name; for
osc_12m, refer the external clock input by index. This eliminates these orphan clocks.Fixes ae81b69fd2b1 ("clk: thead: Add support for T-Head TH1520 AP_SUBSYS clocks")Signed-off-by Yao Zi <[email protected]>--- drivers/clk/thead/clk-th1520-ap.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/clk/thead/clk-th1520-ap.c +0
-0drivers/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" },Stephen - would this use of a parent string be acceptable?
Quoted 7 lines
drivers/clk/thead/clk-th1520-ap.c +0
-0{ .hw = &cpu_pll1_clk.common.hw } };@@ -582,7 +582,14 @@ static const struct clk_parent_data peri2sys_apb_pclk_pd[] = { { .hw = &peri2sys_apb_pclk.common.hw } };
Quoted 13 lines
drivers/clk/thead/clk-th1520-ap.c static const struct clk_parent_data peri2sys_apb_pclk_pd[] = { · line 592
Quoted 9 lines
drivers/clk/thead/clk-th1520-ap.c +8
-1-static CLK_FIXED_FACTOR_FW_NAME(osc12m_clk, "osc_12m", "osc_24m", 2, 1, 0); +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 ), +};I think this hunk is a good fix for
osc_12m. I applied the patch andosc_12mno longer appears inclk_orphan_dump[3].clk_summarynow showsosc_12munderosc_24m.
Thanks for the confirmation!
Quoted 10 lines
Quoted 6 lines
drivers/clk/thead/clk-th1520-ap.c +0
-0static const char *const out_parents[] = {"osc_24m" ,"osc_12m" };Signature · 1 line
2.49.0[1] https://gist.github.com/pdp7/d00f0f4fe3fcf368ce253d606dc7b01f
[2] https://lore.kernel.org/all/[email protected]/
[3] https://gist.github.com/pdp7/30e51ed013d4bedf0c6abc5717e0b6a5
Regards,
Yao Zi
Drew Fustini
maintainerQuoted 18 lines · Yao Zi
Quoted 10 lines · Drew Fustini
Quoted 9 lines · Yao Zi
clk_orphan_dumpshows 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" ]Quoted 6 lines
Quoted 2 lines
where the correct parents should be c910-i0 for c910, and
osc_24mforosc_12m.Thanks for sending this patch. However, I only see "
osc_12m" listed inclk_orphan_dump. I tried the current next, torvalds master and v6.15 but I didn't ever see "c910" appear [1]. What branch are you using?
Quoted 8 lines
I think it has something to do with the bootloader: as you could see in your
clk_orphan_dump, the c910 clock is reparented to cpu-pll1, the second possible parent which could be correctly resolved by the CCF, thus c910 doesn't appear in theclk_orphan_dump.But with the mainline U-Boot which doesn't reparent or reclock c910 on startup, c910 should remain the reset state and take c910-i0 as parent, and appear in the
clk_orphan_dump.
Ah, thanks for the explanation. I'm on an old build:
U-Boot SPL 2020.01-g55b713fa (Jan 12 2024 - 02:17:34 +0000) FM[1] lpddr4x dualrank freq=3733 64bit dbi_off=n sdram init U-Boot 2020.01-g55b713fa (Jan 12 2024 - 02:17:34 +0000)
I would like to run mainline but I have the 8GB RAM LPi4a. Does mainline only work for the 16GB version right now?
Quoted 6 lines
Another way to confirm the bug is to examine
/sys/kernel/debug/clk/c910/clk_possible_parents: without the patch, it should be something likeosc_24m cpu-pll1
Quoted 8 lines
c910's parents are defined as
static const struct clk_parent_data c910_parents[] = { { .hw = &c910_i0_clk.common.hw }, { .hw = &cpu_pll1_clk.common.hw } };and the debugfs output looks obviously wrong.
Thanks, yeah, without the patch I also see:
==> c910-i0/clk_possible_parents <==
cpu-pll0 osc_24m
Quoted 4 lines
There's another bug in CCF[1] which causes unresolvable parents are shown as the clock-output-names of the clock controller's first parent in debugfs, explaining the output.
Thanks for that fix. I now see '(missing)' for c910 too when I apply that patch:
root@lpi4amain:/sys/kernel/debug/clk# head c910/clk_possible_parents (missing) cpu-pll1
Quoted 7 lines
Quoted 3 lines
I think it would be best for this patch to be split into separate patches for
osc_12mand c910.Okay, I originally thought these are relatively small fixes targeting a single driver, hence put them together. I'll split it into two patches in v2.
I think the osc_12m is good as-is but I'm not sure what Stephen will think about using the string "c910-i0" in c910_parents[]. I think splitting it up will make discussion go faster.
Thanks,
Drew
Quoted 28 lines · Drew Fustini
Quoted 18 lines · Yao Zi
Quoted 10 lines · Drew Fustini
Quoted 9 lines · Yao Zi
clk_orphan_dumpshows 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" ]Quoted 6 lines
Quoted 2 lines
where the correct parents should be c910-i0 for c910, and
osc_24mforosc_12m.Thanks for sending this patch. However, I only see "
osc_12m" listed inclk_orphan_dump. I tried the current next, torvalds master and v6.15 but I didn't ever see "c910" appear [1]. What branch are you using?Quoted 8 lines
I think it has something to do with the bootloader: as you could see in your
clk_orphan_dump, the c910 clock is reparented to cpu-pll1, the second possible parent which could be correctly resolved by the CCF, thus c910 doesn't appear in theclk_orphan_dump.But with the mainline U-Boot which doesn't reparent or reclock c910 on startup, c910 should remain the reset state and take c910-i0 as parent, and appear in the
clk_orphan_dump.
Quoted 8 lines
Ah, thanks for the explanation. I'm on an old build:
U-Boot SPL 2020.01-g55b713fa (Jan 12 2024 - 02:17:34 +0000) FM[1] lpddr4x dualrank freq=3733 64bit dbi_off=n sdram init U-Boot 2020.01-g55b713fa (Jan 12 2024 - 02:17:34 +0000)
I would like to run mainline but I have the 8GB RAM LPi4a. Does mainline only work for the 16GB version right now?
I only tested the DRAM driver on the 16GiB version, but have seen some working reports on the 8GiB one. Btw, the mainline U-Boot is still in an early stage (only MMC/eMMC is working and netboot is still WIP).
Quoted 35 lines
Quoted 6 lines
Another way to confirm the bug is to examine
/sys/kernel/debug/clk/c910/clk_possible_parents: without the patch, it should be something likeosc_24m cpu-pll1Quoted 8 lines
c910's parents are defined as
static const struct clk_parent_data c910_parents[] = { { .hw = &c910_i0_clk.common.hw }, { .hw = &cpu_pll1_clk.common.hw } };and the debugfs output looks obviously wrong.
Thanks, yeah, without the patch I also see:
==> c910-i0/clk_possible_parents <==
cpu-pll0osc_24mQuoted 4 lines
There's another bug in CCF[1] which causes unresolvable parents are shown as the clock-output-names of the clock controller's first parent in debugfs, explaining the output.
Thanks for that fix. I now see '(missing)' for c910 too when I apply that patch:
root@lpi4amain:/sys/kernel/debug/clk# head c910/clk_possible_parents (missing) cpu-pll1Quoted 4 lines
Quoted 3 lines
I think it would be best for this patch to be split into separate patches for
osc_12mand c910.
Quoted 7 lines
Quoted 3 lines
Okay, I originally thought these are relatively small fixes targeting a single driver, hence put them together. I'll split it into two patches in v2.
I think the
osc_12mis good as-is but I'm not sure what Stephen will think about using the string "c910-i0" in c910_parents[]. I think splitting it up will make discussion go faster.
Okay, I'm willing to do so.
Quoted 2 lines
Thanks,
Drew
Best regards,
Yao Zi
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Yao,
kernel test robot noticed the following build warnings:
[auto build test WARNING on clk/clk-next]
[also build test WARNING on linus/master v6.16-rc5 next-20250708] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Yao-Zi/clk-thead-th1520-ap-Correctly-refer-the-parent-for-c910-and-osc_12m/20250705-132237 base: https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git clk-next patch link: https://lore.kernel.org/r/20250705052028.24611-1-ziyao%40disroot.org patch subject: [PATCH] clk: thead: th1520-ap: Correctly refer the parent for c910 and osc_12m config: riscv-randconfig-r131-20250709 (https://download.01.org/0day-ci/archive/20250709/[email protected]/config) compiler: riscv64-linux-gcc (GCC) 15.1.0 reproduce: (https://download.01.org/0day-ci/archive/20250709/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
WARNING: invalid argument to '-march': '_zacas_zabha'
>> drivers/clk/thead/clk-th1520-ap.c:585:25: sparse: sparse: symbol 'osc12m_clk' was not declared. Should it be static?
vim +/osc12m_clk +585 drivers/clk/thead/clk-th1520-ap.c
584
> 585 struct clk_fixed_factor osc12m_clk = {
586 .div = 2,
587 .mult = 1,
588 .hw.init = CLK_HW_INIT_PARENTS_DATA("osc_12m",
589 osc_24m_clk,
590 &clk_fixed_factor_ops,
591 0), 592 };
593
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki