Skip to content

Commit 33af962

Browse files
sremmind
authored andcommitted
clk: rockchip: rk3588: register GATE_LINK later
The proper GATE_LINK implementation will use runtime PM to handle the linked gate clocks, which requires device context. Currently all clocks are registered early via CLK_OF_DECLARE, which is before the kernel knows about devices. Moving the full clocks registration to the probe routine does not work, since the clocks needed for timers must be registered early. To work around this issue, most of the clock tree is registered early, but GATE_LINK clocks are handled in the probe routine. Since the resets are not needed early either, they have also been moved to the probe routine. Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Link: https://lore.kernel.org/r/20241211165957.94922-3-sebastian.reichel@collabora.com Signed-off-by: Heiko Stuebner <heiko@sntech.de>
1 parent 9e89f02 commit 33af962

File tree

1 file changed

+58
-8
lines changed

1 file changed

+58
-8
lines changed

drivers/clk/rockchip/clk-rk3588.c

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ static struct rockchip_pll_rate_table rk3588_pll_rates[] = {
266266
}, \
267267
}
268268

269+
static struct rockchip_clk_provider *early_ctx;
270+
269271
static struct rockchip_cpuclk_rate_table rk3588_cpub0clk_rates[] __initdata = {
270272
RK3588_CPUB01CLK_RATE(2496000000, 1),
271273
RK3588_CPUB01CLK_RATE(2400000000, 1),
@@ -694,7 +696,7 @@ static struct rockchip_pll_clock rk3588_pll_clks[] __initdata = {
694696
RK3588_MODE_CON0, 10, 15, 0, rk3588_pll_rates),
695697
};
696698

697-
static struct rockchip_clk_branch rk3588_clk_branches[] __initdata = {
699+
static struct rockchip_clk_branch rk3588_early_clk_branches[] __initdata = {
698700
/*
699701
* CRU Clock-Architecture
700702
*/
@@ -2428,7 +2430,9 @@ static struct rockchip_clk_branch rk3588_clk_branches[] __initdata = {
24282430
RK3588_CLKGATE_CON(68), 5, GFLAGS),
24292431
GATE(ACLK_AV1, "aclk_av1", "aclk_av1_pre", 0,
24302432
RK3588_CLKGATE_CON(68), 2, GFLAGS),
2433+
};
24312434

2435+
static struct rockchip_clk_branch rk3588_clk_branches[] = {
24322436
GATE_LINK(ACLK_ISP1_PRE, "aclk_isp1_pre", "aclk_isp1_root", ACLK_VI_ROOT, 0, RK3588_CLKGATE_CON(26), 6, GFLAGS),
24332437
GATE_LINK(HCLK_ISP1_PRE, "hclk_isp1_pre", "hclk_isp1_root", HCLK_VI_ROOT, 0, RK3588_CLKGATE_CON(26), 8, GFLAGS),
24342438
GATE_LINK(HCLK_NVM, "hclk_nvm", "hclk_nvm_root", ACLK_NVM_ROOT, RK3588_LINKED_CLK, RK3588_CLKGATE_CON(31), 2, GFLAGS),
@@ -2453,26 +2457,31 @@ static struct rockchip_clk_branch rk3588_clk_branches[] __initdata = {
24532457
GATE_LINK(PCLK_VO1GRF, "pclk_vo1grf", "pclk_vo1_root", HCLK_VO1, CLK_IGNORE_UNUSED, RK3588_CLKGATE_CON(59), 12, GFLAGS),
24542458
};
24552459

2456-
static void __init rk3588_clk_init(struct device_node *np)
2460+
static void __init rk3588_clk_early_init(struct device_node *np)
24572461
{
24582462
struct rockchip_clk_provider *ctx;
2459-
unsigned long clk_nr_clks;
2463+
unsigned long clk_nr_clks, max_clk_id1, max_clk_id2;
24602464
void __iomem *reg_base;
24612465

2462-
clk_nr_clks = rockchip_clk_find_max_clk_id(rk3588_clk_branches,
2463-
ARRAY_SIZE(rk3588_clk_branches)) + 1;
2466+
max_clk_id1 = rockchip_clk_find_max_clk_id(rk3588_clk_branches,
2467+
ARRAY_SIZE(rk3588_clk_branches));
2468+
max_clk_id2 = rockchip_clk_find_max_clk_id(rk3588_early_clk_branches,
2469+
ARRAY_SIZE(rk3588_early_clk_branches));
2470+
clk_nr_clks = max(max_clk_id1, max_clk_id2) + 1;
2471+
24642472
reg_base = of_iomap(np, 0);
24652473
if (!reg_base) {
24662474
pr_err("%s: could not map cru region\n", __func__);
24672475
return;
24682476
}
24692477

2470-
ctx = rockchip_clk_init(np, reg_base, clk_nr_clks);
2478+
ctx = rockchip_clk_init_early(np, reg_base, clk_nr_clks);
24712479
if (IS_ERR(ctx)) {
24722480
pr_err("%s: rockchip clk init failed\n", __func__);
24732481
iounmap(reg_base);
24742482
return;
24752483
}
2484+
early_ctx = ctx;
24762485

24772486
rockchip_clk_register_plls(ctx, rk3588_pll_clks,
24782487
ARRAY_SIZE(rk3588_pll_clks),
@@ -2491,14 +2500,55 @@ static void __init rk3588_clk_init(struct device_node *np)
24912500
&rk3588_cpub1clk_data, rk3588_cpub1clk_rates,
24922501
ARRAY_SIZE(rk3588_cpub1clk_rates));
24932502

2503+
rockchip_clk_register_branches(ctx, rk3588_early_clk_branches,
2504+
ARRAY_SIZE(rk3588_early_clk_branches));
2505+
2506+
rockchip_clk_of_add_provider(np, ctx);
2507+
}
2508+
CLK_OF_DECLARE_DRIVER(rk3588_cru, "rockchip,rk3588-cru", rk3588_clk_early_init);
2509+
2510+
static int clk_rk3588_probe(struct platform_device *pdev)
2511+
{
2512+
struct rockchip_clk_provider *ctx = early_ctx;
2513+
struct device *dev = &pdev->dev;
2514+
struct device_node *np = dev->of_node;
2515+
24942516
rockchip_clk_register_branches(ctx, rk3588_clk_branches,
24952517
ARRAY_SIZE(rk3588_clk_branches));
24962518

2497-
rk3588_rst_init(np, reg_base);
2519+
rockchip_clk_finalize(ctx);
24982520

2521+
rk3588_rst_init(np, ctx->reg_base);
24992522
rockchip_register_restart_notifier(ctx, RK3588_GLB_SRST_FST, NULL);
25002523

2524+
/*
2525+
* Re-add clock provider, so that the newly added clocks are also
2526+
* re-parented and get their defaults configured.
2527+
*/
2528+
of_clk_del_provider(np);
25012529
rockchip_clk_of_add_provider(np, ctx);
2530+
2531+
return 0;
25022532
}
25032533

2504-
CLK_OF_DECLARE(rk3588_cru, "rockchip,rk3588-cru", rk3588_clk_init);
2534+
static const struct of_device_id clk_rk3588_match_table[] = {
2535+
{
2536+
.compatible = "rockchip,rk3588-cru",
2537+
},
2538+
{ }
2539+
};
2540+
2541+
static struct platform_driver clk_rk3588_driver = {
2542+
.probe = clk_rk3588_probe,
2543+
.driver = {
2544+
.name = "clk-rk3588",
2545+
.of_match_table = clk_rk3588_match_table,
2546+
.suppress_bind_attrs = true,
2547+
},
2548+
};
2549+
2550+
static int __init rockchip_clk_rk3588_drv_register(void)
2551+
{
2552+
return platform_driver_register(&clk_rk3588_driver);
2553+
}
2554+
core_initcall(rockchip_clk_rk3588_drv_register);

0 commit comments

Comments
 (0)