1c26650b785c06257fbf018794c30563b9a3af5b
[openwrt/openwrt.git] / target / linux / ipq806x / patches-4.14 / 0055-cpufreq-dt-Add-L2-frequency-scaling-support.patch
1 From 0759cdff49f1cf361bf503c13f7bcb33da43ab95 Mon Sep 17 00:00:00 2001
2 From: Georgi Djakov <georgi.djakov@linaro.org>
3 Date: Tue, 8 Sep 2015 11:24:41 +0300
4 Subject: [PATCH 55/69] cpufreq-dt: Add L2 frequency scaling support
5
6 Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
7 ---
8 drivers/cpufreq/cpufreq-dt.c | 41 ++++++++++++++++++++++++++++++++++++++++-
9 include/linux/cpufreq.h | 2 ++
10 2 files changed, 42 insertions(+), 1 deletion(-)
11
12 --- a/drivers/cpufreq/cpufreq-dt.c
13 +++ b/drivers/cpufreq/cpufreq-dt.c
14 @@ -49,11 +49,41 @@ static int set_target(struct cpufreq_pol
15 struct private_data *priv = policy->driver_data;
16 int ret;
17 unsigned long target_freq = policy->freq_table[index].frequency * 1000;
18 + struct clk *l2_clk = policy->l2_clk;
19 + unsigned int l2_freq;
20 + unsigned long new_l2_freq = 0;
21
22 mutex_lock(&priv->lock);
23 ret = dev_pm_opp_set_rate(priv->cpu_dev, target_freq);
24 - if (!ret)
25 +
26 + if (!ret) {
27 + if (!IS_ERR(l2_clk) && policy->l2_rate[0] && policy->l2_rate[1] &&
28 + policy->l2_rate[2]) {
29 + static unsigned long krait_l2[CONFIG_NR_CPUS] = { };
30 + int cpu, ret = 0;
31 +
32 + if (target_freq >= policy->l2_rate[2])
33 + new_l2_freq = policy->l2_rate[2];
34 + else if (target_freq >= policy->l2_rate[1])
35 + new_l2_freq = policy->l2_rate[1];
36 + else
37 + new_l2_freq = policy->l2_rate[0];
38 +
39 + krait_l2[policy->cpu] = new_l2_freq;
40 + for_each_present_cpu(cpu)
41 + new_l2_freq = max(new_l2_freq, krait_l2[cpu]);
42 +
43 + l2_freq = clk_get_rate(l2_clk);
44 +
45 + if (l2_freq != new_l2_freq) {
46 + /* scale l2 with the core */
47 + ret = clk_set_rate(l2_clk, new_l2_freq);
48 + }
49 + }
50 +
51 priv->opp_freq = target_freq;
52 + }
53 +
54 mutex_unlock(&priv->lock);
55
56 return ret;
57 @@ -197,6 +227,8 @@ static int cpufreq_init(struct cpufreq_p
58 const char *name;
59 int ret;
60 struct srcu_notifier_head *opp_srcu_head;
61 + struct device_node *l2_np;
62 + struct clk *l2_clk = NULL;
63
64 cpu_dev = get_cpu_device(policy->cpu);
65 if (!cpu_dev) {
66 @@ -305,6 +337,13 @@ static int cpufreq_init(struct cpufreq_p
67
68 policy->suspend_freq = dev_pm_opp_get_suspend_opp_freq(cpu_dev) / 1000;
69
70 + l2_clk = clk_get(cpu_dev, "l2");
71 + if (!IS_ERR(l2_clk))
72 + policy->l2_clk = l2_clk;
73 + l2_np = of_find_node_by_name(NULL, "qcom,l2");
74 + if (l2_np)
75 + of_property_read_u32_array(l2_np, "qcom,l2-rates", policy->l2_rate, 3);
76 +
77 ret = cpufreq_table_validate_and_show(policy, freq_table);
78 if (ret) {
79 dev_err(cpu_dev, "%s: invalid frequency table: %d\n", __func__,
80 --- a/include/linux/cpufreq.h
81 +++ b/include/linux/cpufreq.h
82 @@ -73,6 +73,8 @@ struct cpufreq_policy {
83 unsigned int cpu; /* cpu managing this policy, must be online */
84
85 struct clk *clk;
86 + struct clk *l2_clk; /* L2 clock */
87 + unsigned int l2_rate[3]; /* L2 bus clock rate thresholds */
88 struct cpufreq_cpuinfo cpuinfo;/* see above */
89
90 unsigned int min; /* in kHz */