package: add fitblk util to release /dev/fit* devices
[openwrt/staging/dangole.git] / target / linux / mediatek / patches-5.15 / 350-03-cpufreq-mediatek-Enable-clocks-and-regulators.patch
1 From 342d5545e9f40496db9ae0d31c2427dd5f369a43 Mon Sep 17 00:00:00 2001
2 From: Jia-Wei Chang <jia-wei.chang@mediatek.com>
3 Date: Fri, 8 Apr 2022 12:58:58 +0800
4 Subject: [PATCH 03/21] cpufreq: mediatek: Enable clocks and regulators
5
6 We need to enable regulators so that the max and min requested values will
7 be recorded.
8 The intermediate clock is not always enabled by CCF in different projects,
9 so we should enable it in the cpufreq driver.
10
11 Signed-off-by: Andrew-sh.Cheng <andrew-sh.cheng@mediatek.com>
12 Signed-off-by: Jia-Wei Chang <jia-wei.chang@mediatek.com>
13 Signed-off-by: Rex-BC Chen <rex-bc.chen@mediatek.com>
14 Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
15 Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
16 ---
17 drivers/cpufreq/mediatek-cpufreq.c | 50 +++++++++++++++++++++++++++---
18 1 file changed, 45 insertions(+), 5 deletions(-)
19
20 --- a/drivers/cpufreq/mediatek-cpufreq.c
21 +++ b/drivers/cpufreq/mediatek-cpufreq.c
22 @@ -334,10 +334,23 @@ static int mtk_cpu_dvfs_info_init(struct
23 goto out_free_resources;
24 }
25
26 + ret = regulator_enable(info->proc_reg);
27 + if (ret) {
28 + dev_warn(cpu_dev, "cpu%d: failed to enable vproc\n", cpu);
29 + goto out_free_resources;
30 + }
31 +
32 /* Both presence and absence of sram regulator are valid cases. */
33 info->sram_reg = regulator_get_exclusive(cpu_dev, "sram");
34 if (IS_ERR(info->sram_reg))
35 info->sram_reg = NULL;
36 + else {
37 + ret = regulator_enable(info->sram_reg);
38 + if (ret) {
39 + dev_warn(cpu_dev, "cpu%d: failed to enable vsram\n", cpu);
40 + goto out_free_resources;
41 + }
42 + }
43
44 /* Get OPP-sharing information from "operating-points-v2" bindings */
45 ret = dev_pm_opp_of_get_sharing_cpus(cpu_dev, &info->cpus);
46 @@ -353,13 +366,21 @@ static int mtk_cpu_dvfs_info_init(struct
47 goto out_free_resources;
48 }
49
50 + ret = clk_prepare_enable(info->cpu_clk);
51 + if (ret)
52 + goto out_free_opp_table;
53 +
54 + ret = clk_prepare_enable(info->inter_clk);
55 + if (ret)
56 + goto out_disable_mux_clock;
57 +
58 /* Search a safe voltage for intermediate frequency. */
59 rate = clk_get_rate(info->inter_clk);
60 opp = dev_pm_opp_find_freq_ceil(cpu_dev, &rate);
61 if (IS_ERR(opp)) {
62 dev_err(cpu_dev, "cpu%d: failed to get intermediate opp\n", cpu);
63 ret = PTR_ERR(opp);
64 - goto out_free_opp_table;
65 + goto out_disable_inter_clock;
66 }
67 info->intermediate_voltage = dev_pm_opp_get_voltage(opp);
68 dev_pm_opp_put(opp);
69 @@ -372,10 +393,21 @@ static int mtk_cpu_dvfs_info_init(struct
70
71 return 0;
72
73 +out_disable_inter_clock:
74 + clk_disable_unprepare(info->inter_clk);
75 +
76 +out_disable_mux_clock:
77 + clk_disable_unprepare(info->cpu_clk);
78 +
79 out_free_opp_table:
80 dev_pm_opp_of_cpumask_remove_table(&info->cpus);
81
82 out_free_resources:
83 + if (regulator_is_enabled(info->proc_reg))
84 + regulator_disable(info->proc_reg);
85 + if (info->sram_reg && regulator_is_enabled(info->sram_reg))
86 + regulator_disable(info->sram_reg);
87 +
88 if (!IS_ERR(info->proc_reg))
89 regulator_put(info->proc_reg);
90 if (!IS_ERR(info->sram_reg))
91 @@ -390,14 +422,22 @@ out_free_resources:
92
93 static void mtk_cpu_dvfs_info_release(struct mtk_cpu_dvfs_info *info)
94 {
95 - if (!IS_ERR(info->proc_reg))
96 + if (!IS_ERR(info->proc_reg)) {
97 + regulator_disable(info->proc_reg);
98 regulator_put(info->proc_reg);
99 - if (!IS_ERR(info->sram_reg))
100 + }
101 + if (!IS_ERR(info->sram_reg)) {
102 + regulator_disable(info->sram_reg);
103 regulator_put(info->sram_reg);
104 - if (!IS_ERR(info->cpu_clk))
105 + }
106 + if (!IS_ERR(info->cpu_clk)) {
107 + clk_disable_unprepare(info->cpu_clk);
108 clk_put(info->cpu_clk);
109 - if (!IS_ERR(info->inter_clk))
110 + }
111 + if (!IS_ERR(info->inter_clk)) {
112 + clk_disable_unprepare(info->inter_clk);
113 clk_put(info->inter_clk);
114 + }
115
116 dev_pm_opp_of_cpumask_remove_table(&info->cpus);
117 }