Skip to content

Commit bcda841

Browse files
Sam ProtsenkoSylwester Nawrocki
authored andcommitted
clk: samsung: exynos850: Register clocks early
Some clocks must be registered before init calls. For example MCT clock (from CMU_PERI) is needed for MCT timer driver, which is registered with TIMER_OF_DECLARE(). By the time we get to core_initcall() used for clk-exynos850 platform driver init, it's already too late. Inability to get "mct" clock in MCT driver leads to kernel panic, as functions registered with *_OF_DECLARE() can't do deferred calls. MCT timer driver can't be fixed either, as it's acting as a clock source and it's essential to register it in start_kernel() -> time_init(). Let's register CMU_PERI clocks early, using CLK_OF_DECLARE(). CMU_TOP generates clocks needed for CMU_PERI, but it's already registered early. While at it, let's cleanup the code a bit, by extracting everything related to CMU initialization and registration to the separate function. Similar issue was discussed at [1] and addressed in commit 1f7db7b ("clk: renesas: cpg-mssr: Add early clock support"), as well as in drivers/clk/mediatek/clk-mt2712.c. [1] https://patchwork.kernel.org/project/linux-renesas-soc/patch/[email protected]/ Signed-off-by: Sam Protsenko <[email protected]> Signed-off-by: Sylwester Nawrocki <[email protected]> Reviewed-by: Krzysztof Kozlowski <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 6904d7e commit bcda841

File tree

1 file changed

+49
-21
lines changed

1 file changed

+49
-21
lines changed

drivers/clk/samsung/clk-exynos850.c

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,43 @@ static void __init exynos850_init_clocks(struct device_node *np,
6060
iounmap(reg_base);
6161
}
6262

63+
/**
64+
* exynos850_register_cmu - Register specified Exynos850 CMU domain
65+
* @dev: Device object; may be NULL if this function is not being
66+
* called from platform driver probe function
67+
* @np: CMU device tree node
68+
* @cmu: CMU data
69+
*
70+
* Register specified CMU domain, which includes next steps:
71+
*
72+
* 1. Enable parent clock of @cmu CMU
73+
* 2. Set initial registers configuration for @cmu CMU clocks
74+
* 3. Register @cmu CMU clocks using Samsung clock framework API
75+
*/
76+
static void __init exynos850_register_cmu(struct device *dev,
77+
struct device_node *np, const struct samsung_cmu_info *cmu)
78+
{
79+
/* Keep CMU parent clock running (needed for CMU registers access) */
80+
if (cmu->clk_name) {
81+
struct clk *parent_clk;
82+
83+
if (dev)
84+
parent_clk = clk_get(dev, cmu->clk_name);
85+
else
86+
parent_clk = of_clk_get_by_name(np, cmu->clk_name);
87+
88+
if (IS_ERR(parent_clk)) {
89+
pr_err("%s: could not find bus clock %s; err = %ld\n",
90+
__func__, cmu->clk_name, PTR_ERR(parent_clk));
91+
} else {
92+
clk_prepare_enable(parent_clk);
93+
}
94+
}
95+
96+
exynos850_init_clocks(np, cmu->clk_regs, cmu->nr_clk_regs);
97+
samsung_cmu_register_one(np, cmu);
98+
}
99+
63100
/* ---- CMU_TOP ------------------------------------------------------------- */
64101

65102
/* Register Offset definitions for CMU_TOP (0x120e0000) */
@@ -367,10 +404,10 @@ static const struct samsung_cmu_info top_cmu_info __initconst = {
367404

368405
static void __init exynos850_cmu_top_init(struct device_node *np)
369406
{
370-
exynos850_init_clocks(np, top_clk_regs, ARRAY_SIZE(top_clk_regs));
371-
samsung_cmu_register_one(np, &top_cmu_info);
407+
exynos850_register_cmu(NULL, np, &top_cmu_info);
372408
}
373409

410+
/* Register CMU_TOP early, as it's a dependency for other early domains */
374411
CLK_OF_DECLARE(exynos850_cmu_top, "samsung,exynos850-cmu-top",
375412
exynos850_cmu_top_init);
376413

@@ -853,6 +890,15 @@ static const struct samsung_cmu_info peri_cmu_info __initconst = {
853890
.clk_name = "dout_peri_bus",
854891
};
855892

893+
static void __init exynos850_cmu_peri_init(struct device_node *np)
894+
{
895+
exynos850_register_cmu(NULL, np, &peri_cmu_info);
896+
}
897+
898+
/* Register CMU_PERI early, as it's needed for MCT timer */
899+
CLK_OF_DECLARE(exynos850_cmu_peri, "samsung,exynos850-cmu-peri",
900+
exynos850_cmu_peri_init);
901+
856902
/* ---- CMU_CORE ------------------------------------------------------------ */
857903

858904
/* Register Offset definitions for CMU_CORE (0x12000000) */
@@ -1021,24 +1067,9 @@ static int __init exynos850_cmu_probe(struct platform_device *pdev)
10211067
{
10221068
const struct samsung_cmu_info *info;
10231069
struct device *dev = &pdev->dev;
1024-
struct device_node *np = dev->of_node;
10251070

10261071
info = of_device_get_match_data(dev);
1027-
exynos850_init_clocks(np, info->clk_regs, info->nr_clk_regs);
1028-
samsung_cmu_register_one(np, info);
1029-
1030-
/* Keep bus clock running, so it's possible to access CMU registers */
1031-
if (info->clk_name) {
1032-
struct clk *bus_clk;
1033-
1034-
bus_clk = clk_get(dev, info->clk_name);
1035-
if (IS_ERR(bus_clk)) {
1036-
pr_err("%s: could not find bus clock %s; err = %ld\n",
1037-
__func__, info->clk_name, PTR_ERR(bus_clk));
1038-
} else {
1039-
clk_prepare_enable(bus_clk);
1040-
}
1041-
}
1072+
exynos850_register_cmu(dev, dev->of_node, info);
10421073

10431074
return 0;
10441075
}
@@ -1053,9 +1084,6 @@ static const struct of_device_id exynos850_cmu_of_match[] = {
10531084
}, {
10541085
.compatible = "samsung,exynos850-cmu-hsi",
10551086
.data = &hsi_cmu_info,
1056-
}, {
1057-
.compatible = "samsung,exynos850-cmu-peri",
1058-
.data = &peri_cmu_info,
10591087
}, {
10601088
.compatible = "samsung,exynos850-cmu-core",
10611089
.data = &core_cmu_info,

0 commit comments

Comments
 (0)