hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/cpufreq/mediatek-cpufreq.c
....@@ -1,20 +1,11 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright (c) 2015 Linaro Ltd.
34 * Author: Pi-Cheng Chen <pi-cheng.chen@linaro.org>
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License version 2 as
7
- * published by the Free Software Foundation.
8
- *
9
- * This program is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
- * GNU General Public License for more details.
135 */
146
157 #include <linux/clk.h>
168 #include <linux/cpu.h>
17
-#include <linux/cpu_cooling.h>
189 #include <linux/cpufreq.h>
1910 #include <linux/cpumask.h>
2011 #include <linux/module.h>
....@@ -48,11 +39,12 @@
4839 struct regulator *sram_reg;
4940 struct clk *cpu_clk;
5041 struct clk *inter_clk;
51
- struct thermal_cooling_device *cdev;
5242 struct list_head list_head;
5343 int intermediate_voltage;
5444 bool need_voltage_tracking;
5545 };
46
+
47
+static struct platform_device *cpufreq_pdev;
5648
5749 static LIST_HEAD(dvfs_info_list);
5850
....@@ -307,13 +299,6 @@
307299
308300 #define DYNAMIC_POWER "dynamic-power-coefficient"
309301
310
-static void mtk_cpufreq_ready(struct cpufreq_policy *policy)
311
-{
312
- struct mtk_cpu_dvfs_info *info = policy->driver_data;
313
-
314
- info->cdev = of_cpufreq_cooling_register(policy);
315
-}
316
-
317302 static int mtk_cpu_dvfs_info_init(struct mtk_cpu_dvfs_info *info, int cpu)
318303 {
319304 struct device *cpu_dev;
....@@ -355,7 +340,7 @@
355340 goto out_free_resources;
356341 }
357342
358
- proc_reg = regulator_get_exclusive(cpu_dev, "proc");
343
+ proc_reg = regulator_get_optional(cpu_dev, "proc");
359344 if (IS_ERR(proc_reg)) {
360345 if (PTR_ERR(proc_reg) == -EPROBE_DEFER)
361346 pr_warn("proc regulator for cpu%d not ready, retry.\n",
....@@ -465,6 +450,8 @@
465450 policy->driver_data = info;
466451 policy->clk = info->cpu_clk;
467452
453
+ dev_pm_opp_of_register_em(info->cpu_dev, policy->cpus);
454
+
468455 return 0;
469456 }
470457
....@@ -472,7 +459,6 @@
472459 {
473460 struct mtk_cpu_dvfs_info *info = policy->driver_data;
474461
475
- cpufreq_cooling_unregister(info->cdev);
476462 dev_pm_opp_free_cpufreq_table(info->cpu_dev, &policy->freq_table);
477463
478464 return 0;
....@@ -480,13 +466,13 @@
480466
481467 static struct cpufreq_driver mtk_cpufreq_driver = {
482468 .flags = CPUFREQ_STICKY | CPUFREQ_NEED_INITIAL_FREQ_CHECK |
483
- CPUFREQ_HAVE_GOVERNOR_PER_POLICY,
469
+ CPUFREQ_HAVE_GOVERNOR_PER_POLICY |
470
+ CPUFREQ_IS_COOLING_DEV,
484471 .verify = cpufreq_generic_frequency_table_verify,
485472 .target_index = mtk_cpufreq_set_target,
486473 .get = cpufreq_generic_get,
487474 .init = mtk_cpufreq_init,
488475 .exit = mtk_cpufreq_exit,
489
- .ready = mtk_cpufreq_ready,
490476 .name = "mtk-cpufreq",
491477 .attr = cpufreq_generic_attr,
492478 };
....@@ -551,6 +537,8 @@
551537 { .compatible = "mediatek,mt817x", },
552538 { .compatible = "mediatek,mt8173", },
553539 { .compatible = "mediatek,mt8176", },
540
+ { .compatible = "mediatek,mt8183", },
541
+ { .compatible = "mediatek,mt8516", },
554542
555543 { }
556544 };
....@@ -560,7 +548,6 @@
560548 {
561549 struct device_node *np;
562550 const struct of_device_id *match;
563
- struct platform_device *pdev;
564551 int err;
565552
566553 np = of_find_node_by_path("/");
....@@ -584,15 +571,23 @@
584571 * and the device registration codes are put here to handle defer
585572 * probing.
586573 */
587
- pdev = platform_device_register_simple("mtk-cpufreq", -1, NULL, 0);
588
- if (IS_ERR(pdev)) {
574
+ cpufreq_pdev = platform_device_register_simple("mtk-cpufreq", -1, NULL, 0);
575
+ if (IS_ERR(cpufreq_pdev)) {
589576 pr_err("failed to register mtk-cpufreq platform device\n");
590
- return PTR_ERR(pdev);
577
+ platform_driver_unregister(&mtk_cpufreq_platdrv);
578
+ return PTR_ERR(cpufreq_pdev);
591579 }
592580
593581 return 0;
594582 }
595
-device_initcall(mtk_cpufreq_driver_init);
583
+module_init(mtk_cpufreq_driver_init)
584
+
585
+static void __exit mtk_cpufreq_driver_exit(void)
586
+{
587
+ platform_device_unregister(cpufreq_pdev);
588
+ platform_driver_unregister(&mtk_cpufreq_platdrv);
589
+}
590
+module_exit(mtk_cpufreq_driver_exit)
596591
597592 MODULE_DESCRIPTION("MediaTek CPUFreq driver");
598593 MODULE_AUTHOR("Pi-Cheng Chen <pi-cheng.chen@linaro.org>");