blob: 2fa9359cf72d4527b596e7dff0994d050f549b5a [file] [log] [blame]
developer2cdaeb12022-10-04 20:25:05 +08001diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c
2index 03bb7b5..010a947 100644
3--- a/drivers/cpufreq/mediatek-cpufreq.c
4+++ b/drivers/cpufreq/mediatek-cpufreq.c
5@@ -351,6 +351,12 @@ static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
6 goto out_free_resources;
7 }
8
9+ ret = regulator_enable(proc_reg);
10+ if (ret) {
11+ dev_warn(cpu_dev, "cpu%d: failed to enable vproc\n", cpu);
12+ goto out_free_resources;
13+ }
14+
15 /* Both presence and absence of sram regulator are valid cases. */
16 sram_reg = regulator_get_exclusive(cpu_dev, "sram");
17
18@@ -368,13 +374,21 @@ static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
19 goto out_free_resources;
20 }
21
22+ ret = clk_prepare_enable(cpu_clk);
23+ if (ret)
24+ goto out_free_opp_table;
25+
26+ ret = clk_prepare_enable(inter_clk);
27+ if (ret)
28+ goto out_disable_mux_clock;
29+
30 /* Search a safe voltage for intermediate frequency. */
31 rate = clk_get_rate(inter_clk);
32 opp = dev_pm_opp_find_freq_ceil(cpu_dev, &rate);
33 if (IS_ERR(opp)) {
34 pr_err("failed to get intermediate opp for cpu%d\n", cpu);
35 ret = PTR_ERR(opp);
36- goto out_free_opp_table;
37+ goto out_disable_inter_clock;
38 }
39 info->intermediate_voltage = dev_pm_opp_get_voltage(opp);
40 dev_pm_opp_put(opp);
41@@ -393,10 +407,23 @@ static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
42
43 return 0;
44
45+out_disable_inter_clock:
46+ if(!IS_ERR(inter_clk))
47+ clk_disable_unprepare(inter_clk);
48+
49+out_disable_mux_clock:
50+ if(!IS_ERR(cpu_clk))
51+ clk_disable_unprepare(cpu_clk);
52+
53 out_free_opp_table:
54 dev_pm_opp_of_cpumask_remove_table(&info->cpus);
55
56 out_free_resources:
57+ if (!IS_ERR(proc_reg)) {
58+ if (regulator_is_enabled(proc_reg))
59+ regulator_disable(proc_reg);
60+ }
61+
62 if (!IS_ERR(proc_reg))
63 regulator_put(proc_reg);
64 if (!IS_ERR(sram_reg))
65@@ -411,14 +438,20 @@ out_free_resources:
66
67 static void mtk_cpu_dvfs_info_release(struct mtk_cpu_dvfs_info *info)
68 {
69- if (!IS_ERR(info->proc_reg))
70+ if (!IS_ERR(info->proc_reg)){
71+ regulator_disable(info->proc_reg);
72 regulator_put(info->proc_reg);
73+ }
74 if (!IS_ERR(info->sram_reg))
75 regulator_put(info->sram_reg);
76- if (!IS_ERR(info->cpu_clk))
77+ if (!IS_ERR(info->cpu_clk)){
78+ clk_disable_unprepare(info->cpu_clk);
79 clk_put(info->cpu_clk);
80- if (!IS_ERR(info->inter_clk))
81+ }
82+ if (!IS_ERR(info->inter_clk)){
83+ clk_disable_unprepare(info->inter_clk);
84 clk_put(info->inter_clk);
85+ }
86
87 dev_pm_opp_of_cpumask_remove_table(&info->cpus);
88 }