]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
cpufreq-dt: Add L2 frequency scaling support
authorGeorgi Djakov <georgi.djakov@linaro.org>
Tue, 8 Sep 2015 08:24:41 +0000 (11:24 +0300)
committerSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Mon, 11 Jan 2016 09:55:18 +0000 (09:55 +0000)
Signed-off-by: Georgi Djakov <georgi.djakov@linaro.org>
Conflicts:
drivers/cpufreq/cpufreq-dt.c

drivers/cpufreq/cpufreq-dt.c
include/linux/cpufreq.h

index 5b06bc34ed0ccf9066917c62ec59cca23e8d13ea..5b422a51f6da149b613799df6ce90c7f76c7cc4d 100644 (file)
@@ -86,11 +86,13 @@ static int set_target(struct cpufreq_policy *policy, unsigned int index)
        struct dev_pm_opp *opp;
        struct cpufreq_frequency_table *freq_table = policy->freq_table;
        struct clk *cpu_clk = policy->clk;
+       struct clk *l2_clk = policy->l2_clk;
        struct private_data *priv = policy->driver_data;
        struct device *cpu_dev = priv->cpu_dev;
        struct regulator *cpu_reg = priv->cpu_reg;
        unsigned long volt = 0, volt_old = 0, tol = 0;
-       unsigned int old_freq, new_freq;
+       unsigned int old_freq, new_freq, l2_freq;
+       unsigned long new_l2_freq = 0;
        long freq_Hz, freq_exact;
        unsigned long opp_freq = 0;
        int ret;
@@ -146,6 +148,30 @@ static int set_target(struct cpufreq_policy *policy, unsigned int index)
                goto out;
        }
 
+       if (!IS_ERR(l2_clk) && policy->l2_rate[0] && policy->l2_rate[1] &&
+           policy->l2_rate[2]) {
+               static unsigned long krait_l2[CONFIG_NR_CPUS] = { };
+               int cpu, ret = 0;
+
+               if (freq_exact >= policy->l2_rate[2])
+                       new_l2_freq = policy->l2_rate[2];
+               else if (freq_exact >= policy->l2_rate[1])
+                       new_l2_freq = policy->l2_rate[1];
+               else
+                       new_l2_freq = policy->l2_rate[0];
+
+               krait_l2[policy->cpu] = new_l2_freq;
+               for_each_present_cpu(cpu)
+                       new_l2_freq = max(new_l2_freq, krait_l2[cpu]);
+
+               l2_freq = clk_get_rate(l2_clk);
+
+               if (l2_freq != new_l2_freq) {
+                       /* scale l2 with the core */
+                       ret = clk_set_rate(l2_clk, new_l2_freq);
+               }
+       }
+
        /* scaling down?  scale voltage after frequency */
        if (!IS_ERR(cpu_reg) && new_freq < old_freq) {
                ret = regulator_set_voltage_tol(cpu_reg, volt, tol);
@@ -156,18 +182,21 @@ static int set_target(struct cpufreq_policy *policy, unsigned int index)
                        goto out;
                }
        }
+
        priv->opp_freq = opp_freq;
+
 out:
        mutex_unlock(&priv->lock);
        return ret;
 }
 
 static int allocate_resources(int cpu, struct device **cdev,
-                             struct regulator **creg, struct clk **cclk)
+                             struct regulator **creg, struct clk **cclk,
+                             struct clk **l2)
 {
        struct device *cpu_dev;
        struct regulator *cpu_reg;
-       struct clk *cpu_clk;
+       struct clk *cpu_clk, *l2_clk = NULL;
        int ret = 0;
        char *reg_cpu0 = "cpu0", *reg_cpu = "cpu", *reg;
 
@@ -227,6 +256,10 @@ try_again:
                *cdev = cpu_dev;
                *creg = cpu_reg;
                *cclk = cpu_clk;
+
+               l2_clk = clk_get(cpu_dev, "l2");
+               if (!IS_ERR(l2_clk))
+                       *l2 = l2_clk;
        }
 
        return ret;
@@ -236,18 +269,20 @@ static int cpufreq_init(struct cpufreq_policy *policy)
 {
        struct cpufreq_frequency_table *freq_table;
        struct device_node *np;
+       struct device_node *l2_np;
        struct private_data *priv;
        struct device *cpu_dev;
        struct regulator *cpu_reg;
-       struct clk *cpu_clk;
        struct dev_pm_opp *suspend_opp;
+       struct clk *cpu_clk, *l2_clk;
        unsigned long min_uV = ~0, max_uV = 0;
        unsigned int transition_latency;
        bool need_update = false;
        int ret;
        struct srcu_notifier_head *opp_srcu_head;
 
-       ret = allocate_resources(policy->cpu, &cpu_dev, &cpu_reg, &cpu_clk);
+       ret = allocate_resources(policy->cpu, &cpu_dev, &cpu_reg, &cpu_clk,
+                                &l2_clk);
        if (ret) {
                pr_err("%s: Failed to allocate resources: %d\n", __func__, ret);
                return ret;
@@ -398,6 +433,11 @@ static int cpufreq_init(struct cpufreq_policy *policy)
        if (suspend_opp)
                policy->suspend_freq = dev_pm_opp_get_freq(suspend_opp) / 1000;
        rcu_read_unlock();
+       policy->l2_clk = l2_clk;
+
+       l2_np = of_find_node_by_name(NULL, "qcom,l2");
+       if (l2_np)
+               of_property_read_u32_array(l2_np, "qcom,l2-rates", policy->l2_rate, 3);
 
        ret = cpufreq_table_validate_and_show(policy, freq_table);
        if (ret) {
@@ -498,7 +538,7 @@ static int dt_cpufreq_probe(struct platform_device *pdev)
 {
        struct device *cpu_dev;
        struct regulator *cpu_reg;
-       struct clk *cpu_clk;
+       struct clk *cpu_clk, *l2_clk;
        int ret;
 
        /*
@@ -508,7 +548,7 @@ static int dt_cpufreq_probe(struct platform_device *pdev)
         *
         * FIXME: Is checking this only for CPU0 sufficient ?
         */
-       ret = allocate_resources(0, &cpu_dev, &cpu_reg, &cpu_clk);
+       ret = allocate_resources(0, &cpu_dev, &cpu_reg, &cpu_clk, &l2_clk);
        if (ret)
                return ret;
 
index 177c7680c1a8a81bcc942497ee228c148fbf5a0b..7d4391a256e19945070163632e8c9c4645ec1700 100644 (file)
@@ -67,6 +67,8 @@ struct cpufreq_policy {
        unsigned int            cpu;    /* cpu managing this policy, must be online */
 
        struct clk              *clk;
+       struct clk              *l2_clk; /* L2 clock */
+       unsigned int            l2_rate[3]; /* L2 bus clock rate thresholds */
        struct cpufreq_cpuinfo  cpuinfo;/* see above */
 
        unsigned int            min;    /* in kHz */