kernel: move mv88e6xxx fix to generic backports
[openwrt/openwrt.git] / target / linux / ipq806x / patches-5.4 / 0055-cpufreq-dt-Add-L2-frequency-scaling-support.patch
1 --- a/drivers/cpufreq/cpufreq-dt.c
2 +++ b/drivers/cpufreq/cpufreq-dt.c
3 @@ -39,20 +39,85 @@ static struct freq_attr *cpufreq_dt_attr
4 NULL,
5 };
6
7 +struct shared_data {
8 + unsigned long *curr_freq_table;
9 + unsigned long curr_l2_freq;
10 + unsigned long curr_l2_volt;
11 +};
12 +
13 +static struct shared_data *cpus_shared_data;
14 +
15 static int set_target(struct cpufreq_policy *policy, unsigned int index)
16 {
17 struct private_data *priv = policy->driver_data;
18 unsigned long freq = policy->freq_table[index].frequency;
19 + struct clk *l2_clk = policy->l2_clk;
20 + struct regulator *l2_regulator = policy->l2_regulator;
21 + unsigned long l2_freq, target_l2_freq;
22 + unsigned long l2_vol, target_l2_volt;
23 + unsigned long target_freq;
24 int ret;
25
26 mutex_lock(&priv->lock);
27 ret = dev_pm_opp_set_rate(priv->cpu_dev, freq * 1000);
28
29 if (!ret) {
30 + if (policy->l2_rate_set) {
31 + int cpu, l2_index, tol = 0;
32 + target_freq = freq * 1000;
33 +
34 + cpus_shared_data->curr_freq_table[policy->cpu] = target_freq;
35 + for_each_present_cpu(cpu)
36 + if (cpu != policy->cpu)
37 + target_freq = max(target_freq, cpus_shared_data->curr_freq_table[cpu]);
38 +
39 + for (l2_index = 2; l2_index > 0; l2_index--)
40 + if (target_freq >= policy->l2_cpufreq[l2_index])
41 + break;
42 +
43 + l2_freq = cpus_shared_data->curr_l2_freq;
44 + target_l2_freq = policy->l2_rate[l2_index];
45 +
46 + if (l2_freq != target_l2_freq) {
47 +
48 + /*
49 + * Set to idle bin if switching from normal to high bin
50 + * or vice versa
51 + */
52 + if ( (l2_index == 2 && l2_freq == policy->l2_rate[1]) ||
53 + (l2_index == 1 && l2_freq == policy->l2_rate[2]) ) {
54 + ret = clk_set_rate(l2_clk, policy->l2_rate[0]);
55 + if (ret)
56 + goto exit;
57 + }
58 +
59 + /* scale l2 with the core */
60 + ret = clk_set_rate(l2_clk, target_l2_freq);
61 + if (ret)
62 + goto exit;
63 + cpus_shared_data->curr_l2_freq = target_l2_freq;
64 +
65 + if (policy->l2_volt_set) {
66 +
67 + l2_vol = cpus_shared_data->curr_l2_volt;
68 + target_l2_volt = policy->l2_volt[l2_index];
69 +
70 + if (l2_vol != target_l2_volt) {
71 + tol = target_l2_volt * policy->l2_volt_tol / 100;
72 + ret = regulator_set_voltage_tol(l2_regulator,target_l2_volt,tol);
73 + if (ret)
74 + goto exit;
75 + cpus_shared_data->curr_l2_volt = target_l2_volt;
76 + }
77 + }
78 + }
79 + }
80 priv->opp_freq = freq * 1000;
81 arch_set_freq_scale(policy->related_cpus, freq,
82 policy->cpuinfo.max_freq);
83 }
84 +
85 +exit:
86 mutex_unlock(&priv->lock);
87
88 return ret;
89 @@ -195,6 +260,9 @@ static int cpufreq_init(struct cpufreq_p
90 bool fallback = false;
91 const char *name;
92 int ret;
93 + struct device_node *np, *l2_np;
94 + struct clk *l2_clk = NULL;
95 + struct regulator *l2_regulator = NULL;
96
97 cpu_dev = get_cpu_device(policy->cpu);
98 if (!cpu_dev) {
99 @@ -302,6 +370,57 @@ static int cpufreq_init(struct cpufreq_p
100
101 policy->suspend_freq = dev_pm_opp_get_suspend_opp_freq(cpu_dev) / 1000;
102
103 + policy->l2_rate_set = false;
104 + policy->l2_volt_set = false;
105 +
106 + l2_clk = clk_get(cpu_dev, "l2");
107 + if (!IS_ERR(l2_clk))
108 + policy->l2_clk = l2_clk;
109 +
110 + l2_np = of_find_node_by_name(NULL, "qcom,l2");
111 + if (l2_np) {
112 + struct device_node *vdd;
113 + np = of_node_get(priv->cpu_dev->of_node);
114 +
115 + if (np)
116 + of_property_read_u32(np, "voltage-tolerance", &policy->l2_volt_tol);
117 +
118 + of_property_read_u32_array(l2_np, "qcom,l2-rates", policy->l2_rate, 3);
119 + if (policy->l2_rate[0] && policy->l2_rate[1] && policy->l2_rate[2]) {
120 + policy->l2_rate_set = true;
121 + of_property_read_u32_array(l2_np, "qcom,l2-cpufreq", policy->l2_cpufreq, 3);
122 + of_property_read_u32_array(l2_np, "qcom,l2-volt", policy->l2_volt, 3);
123 + } else
124 + pr_warn("L2: failed to parse L2 rates\n");
125 +
126 + if (!policy->l2_cpufreq[0] && !policy->l2_cpufreq[1] &&
127 + !policy->l2_cpufreq[2] && policy->l2_rate_set) {
128 + int i;
129 +
130 + pr_warn("L2: failed to parse target cpu freq, using defaults\n");
131 + for (i = 0; i < 3; i++)
132 + policy->l2_cpufreq[i] = policy->l2_rate[i];
133 + }
134 +
135 + if (policy->l2_volt[0] && policy->l2_volt[1] && policy->l2_volt[2] &&
136 + policy->l2_volt_tol && policy->l2_rate_set) {
137 + vdd = of_parse_phandle(l2_np, "qcom,l2-supply", 0);
138 +
139 + if (vdd) {
140 + l2_regulator = devm_regulator_get(cpu_dev, vdd->name);
141 + if (!IS_ERR(l2_regulator)) {
142 + policy->l2_regulator = l2_regulator;
143 + policy->l2_volt_set = true;
144 + } else {
145 + pr_warn("failed to get l2 supply\n");
146 + l2_regulator = NULL;
147 + }
148 +
149 + of_node_put(vdd);
150 + }
151 + }
152 + }
153 +
154 /* Support turbo/boost mode */
155 if (policy_has_boost_freq(policy)) {
156 /* This gets disabled by core on driver unregister */
157 @@ -401,6 +520,14 @@ static int dt_cpufreq_probe(struct platf
158 if (ret)
159 return ret;
160
161 + cpus_shared_data = kzalloc(sizeof(struct shared_data), GFP_KERNEL);
162 + if (!cpus_shared_data)
163 + return -ENOMEM;
164 +
165 + cpus_shared_data->curr_freq_table = kzalloc(sizeof(int) * CONFIG_NR_CPUS, GFP_KERNEL);
166 + if (!cpus_shared_data->curr_freq_table)
167 + return -ENOMEM;
168 +
169 if (data) {
170 if (data->have_governor_per_policy)
171 dt_cpufreq_driver.flags |= CPUFREQ_HAVE_GOVERNOR_PER_POLICY;
172 @@ -419,6 +546,8 @@ static int dt_cpufreq_probe(struct platf
173
174 static int dt_cpufreq_remove(struct platform_device *pdev)
175 {
176 + kfree(cpus_shared_data->curr_freq_table);
177 + kfree(cpus_shared_data);
178 cpufreq_unregister_driver(&dt_cpufreq_driver);
179 return 0;
180 }
181 --- a/include/linux/cpufreq.h
182 +++ b/include/linux/cpufreq.h
183 @@ -58,7 +58,15 @@ struct cpufreq_policy {
184 should set cpufreq */
185 unsigned int cpu; /* cpu managing this policy, must be online */
186
187 - struct clk *clk;
188 + struct clk *clk;
189 + struct clk *l2_clk; /* L2 clock */
190 + struct regulator *l2_regulator; /* L2 supply */
191 + unsigned int l2_rate[3]; /* L2 bus clock rate */
192 + bool l2_rate_set;
193 + unsigned int l2_cpufreq[3]; /* L2 target CPU frequency */
194 + unsigned int l2_volt[3]; /* L2 voltage array */
195 + bool l2_volt_set;
196 + unsigned int l2_volt_tol; /* L2 voltage tolerance */
197 struct cpufreq_cpuinfo cpuinfo;/* see above */
198
199 unsigned int min; /* in kHz */