1 --- a/drivers/cpufreq/cpufreq-dt.c
2 +++ b/drivers/cpufreq/cpufreq-dt.c
3 @@ -48,16 +48,71 @@ static int set_target(struct cpufreq_pol
5 struct private_data *priv = policy->driver_data;
6 unsigned long freq = policy->freq_table[index].frequency;
7 + struct clk *l2_clk = policy->l2_clk;
8 + struct regulator *l2_regulator = policy->l2_regulator;
9 + unsigned long l2_freq, target_l2_freq;
10 + unsigned long l2_vol, target_l2_vol;
11 + unsigned long target_freq;
14 mutex_lock(&priv->lock);
15 ret = dev_pm_opp_set_rate(priv->cpu_dev, freq * 1000);
18 + if (policy->l2_rate_set) {
19 + static unsigned long krait_l2[CONFIG_NR_CPUS] = { };
20 + int cpu, l2_index, tol = 0;
22 + target_freq = freq * 1000;
24 + krait_l2[policy->cpu] = target_freq;
25 + for_each_present_cpu(cpu)
26 + target_freq = max(target_freq, krait_l2[cpu]);
28 + for (l2_index = 2; l2_index >= 0; l2_index--)
29 + if (target_freq >= policy->l2_cpufreq[l2_index])
32 + l2_freq = clk_get_rate(l2_clk);
33 + target_l2_freq = policy->l2_rate[l2_index];
35 + if (l2_freq != target_l2_freq) {
38 + * Set to idle bin if switching from normal to high bin
41 + if ( (l2_index == 2 && l2_freq == policy->l2_rate[1]) ||
42 + (l2_index == 1 && l2_freq == policy->l2_rate[2]) ) {
43 + ret = clk_set_rate(l2_clk, policy->l2_rate[0]);
47 + /* scale l2 with the core */
48 + ret = clk_set_rate(l2_clk, target_l2_freq);
52 + if (policy->l2_volt_set) {
54 + l2_vol = regulator_get_voltage(l2_regulator);
55 + target_l2_vol = policy->l2_volt[l2_index];
57 + if (l2_vol != target_l2_vol) {
58 + tol = target_l2_vol * policy->l2_volt_tol / 100;
59 + ret = regulator_set_voltage_tol(l2_regulator,target_l2_vol,tol);
66 priv->opp_freq = freq * 1000;
67 arch_set_freq_scale(policy->related_cpus, freq,
68 policy->cpuinfo.max_freq);
72 mutex_unlock(&priv->lock);
75 @@ -200,6 +255,9 @@ static int cpufreq_init(struct cpufreq_p
76 bool fallback = false;
79 + struct device_node *np, *l2_np;
80 + struct clk *l2_clk = NULL;
81 + struct regulator *l2_regulator = NULL;
83 cpu_dev = get_cpu_device(policy->cpu);
85 @@ -307,6 +365,57 @@ static int cpufreq_init(struct cpufreq_p
87 policy->suspend_freq = dev_pm_opp_get_suspend_opp_freq(cpu_dev) / 1000;
89 + policy->l2_rate_set = false;
90 + policy->l2_volt_set = false;
92 + l2_clk = clk_get(cpu_dev, "l2");
93 + if (!IS_ERR(l2_clk))
94 + policy->l2_clk = l2_clk;
96 + l2_np = of_find_node_by_name(NULL, "qcom,l2");
98 + struct device_node *vdd;
99 + np = of_node_get(priv->cpu_dev->of_node);
102 + of_property_read_u32(np, "voltage-tolerance", &policy->l2_volt_tol);
104 + of_property_read_u32_array(l2_np, "qcom,l2-rates", policy->l2_rate, 3);
105 + if (policy->l2_rate[0] && policy->l2_rate[1] && policy->l2_rate[2]) {
106 + policy->l2_rate_set = true;
107 + of_property_read_u32_array(l2_np, "qcom,l2-cpufreq", policy->l2_cpufreq, 3);
108 + of_property_read_u32_array(l2_np, "qcom,l2-volt", policy->l2_volt, 3);
110 + pr_warn("L2: failed to parse L2 rates\n");
112 + if (!policy->l2_cpufreq[0] && !policy->l2_cpufreq[1] &&
113 + !policy->l2_cpufreq[2] && policy->l2_rate_set) {
116 + pr_warn("L2: failed to parse target cpu freq, using defaults\n");
117 + for (i = 0; i < 3; i++)
118 + policy->l2_cpufreq[i] = policy->l2_rate[i];
121 + if (policy->l2_volt[0] && policy->l2_volt[1] && policy->l2_volt[2] &&
122 + policy->l2_volt_tol && policy->l2_rate_set) {
123 + vdd = of_parse_phandle(l2_np, "qcom,l2-supply", 0);
126 + l2_regulator = devm_regulator_get(cpu_dev, vdd->name);
127 + if (!IS_ERR(l2_regulator)) {
128 + policy->l2_regulator = l2_regulator;
129 + policy->l2_volt_set = true;
131 + pr_warn("failed to get l2 supply\n");
132 + l2_regulator = NULL;
140 /* Support turbo/boost mode */
141 if (policy_has_boost_freq(policy)) {
142 /* This gets disabled by core on driver unregister */
143 --- a/include/linux/cpufreq.h
144 +++ b/include/linux/cpufreq.h
145 @@ -72,7 +72,15 @@ struct cpufreq_policy {
146 should set cpufreq */
147 unsigned int cpu; /* cpu managing this policy, must be online */
151 + struct clk *l2_clk; /* L2 clock */
152 + struct regulator *l2_regulator; /* L2 supply */
153 + unsigned int l2_rate[3]; /* L2 bus clock rate */
155 + unsigned int l2_cpufreq[3]; /* L2 target CPU frequency */
156 + unsigned int l2_volt[3]; /* L2 voltage array */
158 + unsigned int l2_volt_tol; /* L2 voltage tolerance */
159 struct cpufreq_cpuinfo cpuinfo;/* see above */
161 unsigned int min; /* in kHz */