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