blob: ee87f4ef10b67ede7182485ed0e0e3262adc2a92 [file] [log] [blame]
developer2cdaeb12022-10-04 20:25:05 +08001diff --git a/drivers/cpufreq/mediatek-cpufreq.c b/drivers/cpufreq/mediatek-cpufreq.c
2index 010a947..291f629 100644
3--- a/drivers/cpufreq/mediatek-cpufreq.c
4+++ b/drivers/cpufreq/mediatek-cpufreq.c
5@@ -38,6 +38,7 @@ struct mtk_cpu_dvfs_info {
6 struct regulator *proc_reg;
7 struct regulator *sram_reg;
8 struct clk *cpu_clk;
9+ struct clk *cci_clk;
10 struct clk *inter_clk;
11 struct list_head list_head;
12 int intermediate_voltage;
13@@ -205,15 +206,24 @@ static int mtk_cpufreq_set_target(struct cpufreq_policy *policy,
14 struct cpufreq_frequency_table *freq_table = policy->freq_table;
15 struct clk *cpu_clk = policy->clk;
16 struct clk *armpll = clk_get_parent(cpu_clk);
17+ struct clk *cci_clk = ERR_PTR(-ENODEV);
18+ struct clk *ccipll;
19 struct mtk_cpu_dvfs_info *info = policy->driver_data;
20 struct device *cpu_dev = info->cpu_dev;
21 struct dev_pm_opp *opp;
22- long freq_hz, old_freq_hz;
23+ long freq_hz, old_freq_hz, cci_freq_hz, cci_old_freq_hz;
24 int vproc, old_vproc, inter_vproc, target_vproc, ret;
25
26 inter_vproc = info->intermediate_voltage;
27
28 old_freq_hz = clk_get_rate(cpu_clk);
29+
30+ if (!IS_ERR(info->cci_clk)) {
31+ cci_clk = info->cci_clk;
32+ ccipll = clk_get_parent(cci_clk);
33+ cci_old_freq_hz = clk_get_rate(cci_clk);
34+ }
35+
36 old_vproc = regulator_get_voltage(info->proc_reg);
37 if (old_vproc < 0) {
38 pr_err("%s: invalid Vproc value: %d\n", __func__, old_vproc);
39@@ -221,6 +231,7 @@ static int mtk_cpufreq_set_target(struct cpufreq_policy *policy,
40 }
41
42 freq_hz = freq_table[index].frequency * 1000;
43+ cci_freq_hz = freq_table[index].frequency * 600;
44
45 opp = dev_pm_opp_find_freq_ceil(cpu_dev, &freq_hz);
46 if (IS_ERR(opp)) {
47@@ -246,6 +257,18 @@ static int mtk_cpufreq_set_target(struct cpufreq_policy *policy,
48 }
49 }
50
51+ /* Reparent the CCI clock to intermediate clock. */
52+ if (!IS_ERR(cci_clk)) {
53+ ret = clk_set_parent(cci_clk, info->inter_clk);
54+ if (ret) {
55+ pr_err("cpu%d: failed to re-parent cci clock!\n",
56+ policy->cpu);
57+ mtk_cpufreq_set_voltage(info, old_vproc);
58+ WARN_ON(1);
59+ return ret;
60+ }
61+ }
62+
63 /* Reparent the CPU clock to intermediate clock. */
64 ret = clk_set_parent(cpu_clk, info->inter_clk);
65 if (ret) {
66@@ -266,6 +289,18 @@ static int mtk_cpufreq_set_target(struct cpufreq_policy *policy,
67 return ret;
68 }
69
70+ /* Set the original PLL to target rate. */
71+ if (!IS_ERR(cci_clk)) {
72+ ret = clk_set_rate(ccipll, cci_freq_hz);
73+ if (ret) {
74+ pr_err("cpu%d: failed to scale cci clock rate!\n",
75+ policy->cpu);
76+ clk_set_parent(cci_clk, ccipll);
77+ mtk_cpufreq_set_voltage(info, old_vproc);
78+ return ret;
79+ }
80+ }
81+
82 /* Set parent of CPU clock back to the original PLL. */
83 ret = clk_set_parent(cpu_clk, armpll);
84 if (ret) {
85@@ -276,6 +311,17 @@ static int mtk_cpufreq_set_target(struct cpufreq_policy *policy,
86 return ret;
87 }
88
89+ /* Set parent of CCI clock back to the original PLL. */
90+ if (!IS_ERR(cci_clk)) {
91+ ret = clk_set_parent(cci_clk, ccipll);
92+ if (ret) {
93+ pr_err("cpu%d: failed to re-parent cci clock!\n",
94+ policy->cpu);
95+ mtk_cpufreq_set_voltage(info, inter_vproc);
96+ WARN_ON(1);
97+ return ret;
98+ }
99+ }
100 /*
101 * If the new voltage is lower than the intermediate voltage or the
102 * original voltage, scale down to the new voltage.
103@@ -285,9 +331,20 @@ static int mtk_cpufreq_set_target(struct cpufreq_policy *policy,
104 if (ret) {
105 pr_err("cpu%d: failed to scale down voltage!\n",
106 policy->cpu);
107+ if (!IS_ERR(cci_clk))
108+ clk_set_parent(cci_clk, info->inter_clk);
109+
110 clk_set_parent(cpu_clk, info->inter_clk);
111 clk_set_rate(armpll, old_freq_hz);
112+
113+ if (!IS_ERR(cci_clk))
114+ clk_set_rate(ccipll, cci_old_freq_hz);
115+
116 clk_set_parent(cpu_clk, armpll);
117+
118+ if (!IS_ERR(cci_clk))
119+ clk_set_parent(cci_clk, ccipll);
120+
121 return ret;
122 }
123 }
124@@ -303,6 +360,7 @@ static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
125 struct regulator *proc_reg = ERR_PTR(-ENODEV);
126 struct regulator *sram_reg = ERR_PTR(-ENODEV);
127 struct clk *cpu_clk = ERR_PTR(-ENODEV);
128+ struct clk *cci_clk = ERR_PTR(-ENODEV);
129 struct clk *inter_clk = ERR_PTR(-ENODEV);
130 struct dev_pm_opp *opp;
131 unsigned long rate;
132@@ -338,6 +396,8 @@ static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
133 goto out_free_resources;
134 }
135
136+ cci_clk = clk_get(cpu_dev, "cci");
137+
138 proc_reg = regulator_get_optional(cpu_dev, "proc");
139 if (IS_ERR(proc_reg)) {
140 if (PTR_ERR(proc_reg) == -EPROBE_DEFER)
141@@ -379,16 +439,23 @@ static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
142 goto out_free_opp_table;
143
144 ret = clk_prepare_enable(inter_clk);
145+
146 if (ret)
147 goto out_disable_mux_clock;
148
149+ if(!(IS_ERR(cci_clk))) {
150+ ret = clk_prepare_enable(cci_clk);
151+ if(ret)
152+ goto out_disable_inter_clock;
153+ }
154+
155 /* Search a safe voltage for intermediate frequency. */
156 rate = clk_get_rate(inter_clk);
157 opp = dev_pm_opp_find_freq_ceil(cpu_dev, &rate);
158 if (IS_ERR(opp)) {
159 pr_err("failed to get intermediate opp for cpu%d\n", cpu);
160 ret = PTR_ERR(opp);
161- goto out_disable_inter_clock;
162+ goto out_disable_cci_clock;
163 }
164 info->intermediate_voltage = dev_pm_opp_get_voltage(opp);
165 dev_pm_opp_put(opp);
166@@ -397,6 +464,7 @@ static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
167 info->proc_reg = proc_reg;
168 info->sram_reg = IS_ERR(sram_reg) ? NULL : sram_reg;
169 info->cpu_clk = cpu_clk;
170+ info->cci_clk = cci_clk;
171 info->inter_clk = inter_clk;
172
173 /*
174@@ -407,6 +475,10 @@ static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
175
176 return 0;
177
178+out_disable_cci_clock:
179+ if(!IS_ERR(cci_clk))
180+ clk_disable_unprepare(cci_clk);
181+
182 out_disable_inter_clock:
183 if(!IS_ERR(inter_clk))
184 clk_disable_unprepare(inter_clk);
185@@ -432,6 +504,8 @@ out_free_resources:
186 clk_put(cpu_clk);
187 if (!IS_ERR(inter_clk))
188 clk_put(inter_clk);
189+ if (!IS_ERR(cci_clk))
190+ clk_put(cci_clk);
191
192 return ret;
193 }
194@@ -452,6 +526,10 @@ static void mtk_cpu_dvfs_info_release(struct mtk_cpu_dvfs_info *info)
195 clk_disable_unprepare(info->inter_clk);
196 clk_put(info->inter_clk);
197 }
198+ if (!IS_ERR(info->cci_clk)){
199+ clk_disable_unprepare(info->cci_clk);
200+ clk_put(info->cci_clk);
201+ }
202
203 dev_pm_opp_of_cpumask_remove_table(&info->cpus);
204 }
205@@ -570,6 +648,7 @@ static const struct of_device_id mtk_cpufreq_machines[] __initconst = {
206 { .compatible = "mediatek,mt8176", },
207 { .compatible = "mediatek,mt8183", },
208 { .compatible = "mediatek,mt8516", },
209+ { .compatible = "mediatek,mt7988", },
210
211 { }
212 };