56930520c9acfe053b42be090ce6cb20d0ae568c
[librecmc/librecmc.git] / target / linux / ipq806x / patches-4.4 / 173-cpufreq-dt-Add-L2-frequency-scaling-support.patch
1 From b4629f9e30e865402c643de6d4668be790fc0539 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: cpufreq-dt: Add L2 frequency scaling support
5
6 Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
7
8 Conflicts:
9         drivers/cpufreq/cpufreq-dt.c
10 ---
11  drivers/cpufreq/cpufreq-dt.c | 54 ++++++++++++++++++++++++++++++++++++++------
12  include/linux/cpufreq.h      |  2 ++
13  2 files changed, 49 insertions(+), 7 deletions(-)
14
15 --- a/drivers/cpufreq/cpufreq-dt.c
16 +++ b/drivers/cpufreq/cpufreq-dt.c
17 @@ -86,11 +86,13 @@ static int set_target(struct cpufreq_pol
18         struct dev_pm_opp *opp;
19         struct cpufreq_frequency_table *freq_table = policy->freq_table;
20         struct clk *cpu_clk = policy->clk;
21 +       struct clk *l2_clk = policy->l2_clk;
22         struct private_data *priv = policy->driver_data;
23         struct device *cpu_dev = priv->cpu_dev;
24         struct regulator *cpu_reg = priv->cpu_reg;
25         unsigned long volt = 0, volt_old = 0, tol = 0;
26 -       unsigned int old_freq, new_freq;
27 +       unsigned int old_freq, new_freq, l2_freq;
28 +       unsigned long new_l2_freq = 0;
29         long freq_Hz, freq_exact;
30         unsigned long opp_freq = 0;
31         int ret;
32 @@ -146,6 +148,30 @@ static int set_target(struct cpufreq_pol
33                 goto out;
34         }
35  
36 +       if (!IS_ERR(l2_clk) && policy->l2_rate[0] && policy->l2_rate[1] &&
37 +           policy->l2_rate[2]) {
38 +               static unsigned long krait_l2[CONFIG_NR_CPUS] = { };
39 +               int cpu, ret = 0;
40 +
41 +               if (freq_exact >= policy->l2_rate[2])
42 +                       new_l2_freq = policy->l2_rate[2];
43 +               else if (freq_exact >= policy->l2_rate[1])
44 +                       new_l2_freq = policy->l2_rate[1];
45 +               else
46 +                       new_l2_freq = policy->l2_rate[0];
47 +
48 +               krait_l2[policy->cpu] = new_l2_freq;
49 +               for_each_present_cpu(cpu)
50 +                       new_l2_freq = max(new_l2_freq, krait_l2[cpu]);
51 +
52 +               l2_freq = clk_get_rate(l2_clk);
53 +
54 +               if (l2_freq != new_l2_freq) {
55 +                       /* scale l2 with the core */
56 +                       ret = clk_set_rate(l2_clk, new_l2_freq);
57 +               }
58 +       }
59 +
60         /* scaling down?  scale voltage after frequency */
61         if (!IS_ERR(cpu_reg) && new_freq < old_freq) {
62                 ret = regulator_set_voltage_tol(cpu_reg, volt, tol);
63 @@ -156,18 +182,21 @@ static int set_target(struct cpufreq_pol
64                         goto out;
65                 }
66         }
67 +
68         priv->opp_freq = opp_freq;
69 +
70  out:
71         mutex_unlock(&priv->lock);
72         return ret;
73  }
74  
75  static int allocate_resources(int cpu, struct device **cdev,
76 -                             struct regulator **creg, struct clk **cclk)
77 +                             struct regulator **creg, struct clk **cclk,
78 +                             struct clk **l2)
79  {
80         struct device *cpu_dev;
81         struct regulator *cpu_reg;
82 -       struct clk *cpu_clk;
83 +       struct clk *cpu_clk, *l2_clk = NULL;
84         int ret = 0;
85         char *reg_cpu0 = "cpu0", *reg_cpu = "cpu", *reg;
86  
87 @@ -227,6 +256,10 @@ try_again:
88                 *cdev = cpu_dev;
89                 *creg = cpu_reg;
90                 *cclk = cpu_clk;
91 +
92 +               l2_clk = clk_get(cpu_dev, "l2");
93 +               if (!IS_ERR(l2_clk))
94 +                       *l2 = l2_clk;
95         }
96  
97         return ret;
98 @@ -236,18 +269,20 @@ static int cpufreq_init(struct cpufreq_p
99  {
100         struct cpufreq_frequency_table *freq_table;
101         struct device_node *np;
102 +       struct device_node *l2_np;
103         struct private_data *priv;
104         struct device *cpu_dev;
105         struct regulator *cpu_reg;
106 -       struct clk *cpu_clk;
107         struct dev_pm_opp *suspend_opp;
108 +       struct clk *cpu_clk, *l2_clk;
109         unsigned long min_uV = ~0, max_uV = 0;
110         unsigned int transition_latency;
111         bool need_update = false;
112         int ret;
113         struct srcu_notifier_head *opp_srcu_head;
114  
115 -       ret = allocate_resources(policy->cpu, &cpu_dev, &cpu_reg, &cpu_clk);
116 +       ret = allocate_resources(policy->cpu, &cpu_dev, &cpu_reg, &cpu_clk,
117 +                                &l2_clk);
118         if (ret) {
119                 pr_err("%s: Failed to allocate resources: %d\n", __func__, ret);
120                 return ret;
121 @@ -398,6 +433,11 @@ static int cpufreq_init(struct cpufreq_p
122         if (suspend_opp)
123                 policy->suspend_freq = dev_pm_opp_get_freq(suspend_opp) / 1000;
124         rcu_read_unlock();
125 +       policy->l2_clk = l2_clk;
126 +
127 +       l2_np = of_find_node_by_name(NULL, "qcom,l2");
128 +       if (l2_np)
129 +               of_property_read_u32_array(l2_np, "qcom,l2-rates", policy->l2_rate, 3);
130  
131         ret = cpufreq_table_validate_and_show(policy, freq_table);
132         if (ret) {
133 @@ -498,7 +538,7 @@ static int dt_cpufreq_probe(struct platf
134  {
135         struct device *cpu_dev;
136         struct regulator *cpu_reg;
137 -       struct clk *cpu_clk;
138 +       struct clk *cpu_clk, *l2_clk;
139         int ret;
140  
141         /*
142 @@ -508,7 +548,7 @@ static int dt_cpufreq_probe(struct platf
143          *
144          * FIXME: Is checking this only for CPU0 sufficient ?
145          */
146 -       ret = allocate_resources(0, &cpu_dev, &cpu_reg, &cpu_clk);
147 +       ret = allocate_resources(0, &cpu_dev, &cpu_reg, &cpu_clk, &l2_clk);
148         if (ret)
149                 return ret;
150  
151 --- a/include/linux/cpufreq.h
152 +++ b/include/linux/cpufreq.h
153 @@ -67,6 +67,8 @@ struct cpufreq_policy {
154         unsigned int            cpu;    /* cpu managing this policy, must be online */
155  
156         struct clk              *clk;
157 +       struct clk              *l2_clk; /* L2 clock */
158 +       unsigned int            l2_rate[3]; /* L2 bus clock rate thresholds */
159         struct cpufreq_cpuinfo  cpuinfo;/* see above */
160  
161         unsigned int            min;    /* in kHz */