hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/cpufreq/imx6q-cpufreq.c
....@@ -1,15 +1,11 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (C) 2013 Freescale Semiconductor, Inc.
3
- *
4
- * This program is free software; you can redistribute it and/or modify
5
- * it under the terms of the GNU General Public License version 2 as
6
- * published by the Free Software Foundation.
74 */
85
96 #include <linux/clk.h>
107 #include <linux/cpu.h>
118 #include <linux/cpufreq.h>
12
-#include <linux/cpu_cooling.h>
139 #include <linux/err.h>
1410 #include <linux/module.h>
1511 #include <linux/nvmem-consumer.h>
....@@ -52,8 +48,6 @@
5248 };
5349
5450 static struct device *cpu_dev;
55
-static struct thermal_cooling_device *cdev;
56
-static bool free_opp;
5751 static struct cpufreq_frequency_table *freq_table;
5852 static unsigned int max_freq;
5953 static unsigned int transition_latency;
....@@ -177,65 +171,40 @@
177171 /* scaling down? scale voltage after frequency */
178172 if (new_freq < old_freq) {
179173 ret = regulator_set_voltage_tol(arm_reg, volt, 0);
180
- if (ret) {
174
+ if (ret)
181175 dev_warn(cpu_dev,
182176 "failed to scale vddarm down: %d\n", ret);
183
- ret = 0;
184
- }
185177 ret = regulator_set_voltage_tol(soc_reg, imx6_soc_volt[index], 0);
186
- if (ret) {
178
+ if (ret)
187179 dev_warn(cpu_dev, "failed to scale vddsoc down: %d\n", ret);
188
- ret = 0;
189
- }
190180 if (!IS_ERR(pu_reg)) {
191181 ret = regulator_set_voltage_tol(pu_reg, imx6_soc_volt[index], 0);
192
- if (ret) {
182
+ if (ret)
193183 dev_warn(cpu_dev, "failed to scale vddpu down: %d\n", ret);
194
- ret = 0;
195
- }
196184 }
197185 }
198186
199187 return 0;
200188 }
201189
202
-static void imx6q_cpufreq_ready(struct cpufreq_policy *policy)
203
-{
204
- cdev = of_cpufreq_cooling_register(policy);
205
-
206
- if (!cdev)
207
- dev_err(cpu_dev,
208
- "running cpufreq without cooling device: %ld\n",
209
- PTR_ERR(cdev));
210
-}
211
-
212190 static int imx6q_cpufreq_init(struct cpufreq_policy *policy)
213191 {
214
- int ret;
215
-
216192 policy->clk = clks[ARM].clk;
217
- ret = cpufreq_generic_init(policy, freq_table, transition_latency);
193
+ cpufreq_generic_init(policy, freq_table, transition_latency);
218194 policy->suspend_freq = max_freq;
219
-
220
- return ret;
221
-}
222
-
223
-static int imx6q_cpufreq_exit(struct cpufreq_policy *policy)
224
-{
225
- cpufreq_cooling_unregister(cdev);
195
+ dev_pm_opp_of_register_em(cpu_dev, policy->cpus);
226196
227197 return 0;
228198 }
229199
230200 static struct cpufreq_driver imx6q_cpufreq_driver = {
231
- .flags = CPUFREQ_NEED_INITIAL_FREQ_CHECK,
201
+ .flags = CPUFREQ_NEED_INITIAL_FREQ_CHECK |
202
+ CPUFREQ_IS_COOLING_DEV,
232203 .verify = cpufreq_generic_frequency_table_verify,
233204 .target_index = imx6q_set_target,
234205 .get = cpufreq_generic_get,
235206 .init = imx6q_cpufreq_init,
236
- .exit = imx6q_cpufreq_exit,
237207 .name = "imx6q-cpufreq",
238
- .ready = imx6q_cpufreq_ready,
239208 .attr = cpufreq_generic_attr,
240209 .suspend = cpufreq_generic_suspend,
241210 };
....@@ -246,31 +215,41 @@
246215 #define OCOTP_CFG3_SPEED_996MHZ 0x2
247216 #define OCOTP_CFG3_SPEED_852MHZ 0x1
248217
249
-static void imx6q_opp_check_speed_grading(struct device *dev)
218
+static int imx6q_opp_check_speed_grading(struct device *dev)
250219 {
251220 struct device_node *np;
252221 void __iomem *base;
253222 u32 val;
223
+ int ret;
254224
255
- np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-ocotp");
256
- if (!np)
257
- return;
225
+ if (of_find_property(dev->of_node, "nvmem-cells", NULL)) {
226
+ ret = nvmem_cell_read_u32(dev, "speed_grade", &val);
227
+ if (ret)
228
+ return ret;
229
+ } else {
230
+ np = of_find_compatible_node(NULL, NULL, "fsl,imx6q-ocotp");
231
+ if (!np)
232
+ return -ENOENT;
258233
259
- base = of_iomap(np, 0);
260
- if (!base) {
261
- dev_err(dev, "failed to map ocotp\n");
262
- goto put_node;
234
+ base = of_iomap(np, 0);
235
+ of_node_put(np);
236
+ if (!base) {
237
+ dev_err(dev, "failed to map ocotp\n");
238
+ return -EFAULT;
239
+ }
240
+
241
+ /*
242
+ * SPEED_GRADING[1:0] defines the max speed of ARM:
243
+ * 2b'11: 1200000000Hz;
244
+ * 2b'10: 996000000Hz;
245
+ * 2b'01: 852000000Hz; -- i.MX6Q Only, exclusive with 996MHz.
246
+ * 2b'00: 792000000Hz;
247
+ * We need to set the max speed of ARM according to fuse map.
248
+ */
249
+ val = readl_relaxed(base + OCOTP_CFG3);
250
+ iounmap(base);
263251 }
264252
265
- /*
266
- * SPEED_GRADING[1:0] defines the max speed of ARM:
267
- * 2b'11: 1200000000Hz;
268
- * 2b'10: 996000000Hz;
269
- * 2b'01: 852000000Hz; -- i.MX6Q Only, exclusive with 996MHz.
270
- * 2b'00: 792000000Hz;
271
- * We need to set the max speed of ARM according to fuse map.
272
- */
273
- val = readl_relaxed(base + OCOTP_CFG3);
274253 val >>= OCOTP_CFG3_SPEED_SHIFT;
275254 val &= 0x3;
276255
....@@ -287,9 +266,8 @@
287266 if (dev_pm_opp_disable(dev, 1200000000))
288267 dev_warn(dev, "failed to disable 1.2GHz OPP\n");
289268 }
290
- iounmap(base);
291
-put_node:
292
- of_node_put(np);
269
+
270
+ return 0;
293271 }
294272
295273 #define OCOTP_CFG3_6UL_SPEED_696MHZ 0x2
....@@ -414,19 +392,16 @@
414392 if (of_machine_is_compatible("fsl,imx6ul") ||
415393 of_machine_is_compatible("fsl,imx6ull")) {
416394 ret = imx6ul_opp_check_speed_grading(cpu_dev);
417
- if (ret == -EPROBE_DEFER)
418
- return ret;
419
- if (ret) {
395
+ } else {
396
+ ret = imx6q_opp_check_speed_grading(cpu_dev);
397
+ }
398
+ if (ret) {
399
+ if (ret != -EPROBE_DEFER)
420400 dev_err(cpu_dev, "failed to read ocotp: %d\n",
421401 ret);
422
- return ret;
423
- }
424
- } else {
425
- imx6q_opp_check_speed_grading(cpu_dev);
402
+ goto out_free_opp;
426403 }
427404
428
- /* Because we have added the OPPs here, we must free them */
429
- free_opp = true;
430405 num = dev_pm_opp_get_opp_count(cpu_dev);
431406 if (num < 0) {
432407 ret = num;
....@@ -528,8 +503,7 @@
528503 free_freq_table:
529504 dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table);
530505 out_free_opp:
531
- if (free_opp)
532
- dev_pm_opp_of_remove_table(cpu_dev);
506
+ dev_pm_opp_of_remove_table(cpu_dev);
533507 put_reg:
534508 if (!IS_ERR(arm_reg))
535509 regulator_put(arm_reg);
....@@ -549,8 +523,7 @@
549523 {
550524 cpufreq_unregister_driver(&imx6q_cpufreq_driver);
551525 dev_pm_opp_free_cpufreq_table(cpu_dev, &freq_table);
552
- if (free_opp)
553
- dev_pm_opp_of_remove_table(cpu_dev);
526
+ dev_pm_opp_of_remove_table(cpu_dev);
554527 regulator_put(arm_reg);
555528 if (!IS_ERR(pu_reg))
556529 regulator_put(pu_reg);