]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/cpufreq/omap-cpufreq.c
Merge branch 'x86-efi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[karo-tx-linux.git] / drivers / cpufreq / omap-cpufreq.c
index 8f778b9dbb46bd8e7da5443521404adfe08565ba..5d04c57aae30d7b330846a8d8e64c8d59c08a0d1 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/io.h>
 #include <linux/opp.h>
 #include <linux/cpu.h>
+#include <linux/module.h>
 
 #include <asm/system.h>
 #include <asm/smp_plat.h>
@@ -32,6 +33,7 @@
 #include <plat/clock.h>
 #include <plat/omap-pm.h>
 #include <plat/common.h>
+#include <plat/omap_device.h>
 
 #include <mach/hardware.h>
 
@@ -46,6 +48,7 @@ static struct lpj_info global_lpj_ref;
 #endif
 
 static struct cpufreq_frequency_table *freq_table;
+static atomic_t freq_table_users = ATOMIC_INIT(0);
 static struct clk *mpu_clk;
 static char *mpu_clk_name;
 static struct device *mpu_dev;
@@ -150,6 +153,12 @@ static int omap_target(struct cpufreq_policy *policy,
        return ret;
 }
 
+static inline void freq_table_free(void)
+{
+       if (atomic_dec_and_test(&freq_table_users))
+               opp_free_cpufreq_table(mpu_dev, &freq_table);
+}
+
 static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
 {
        int result = 0;
@@ -158,21 +167,27 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
        if (IS_ERR(mpu_clk))
                return PTR_ERR(mpu_clk);
 
-       if (policy->cpu >= NR_CPUS)
-               return -EINVAL;
+       if (policy->cpu >= NR_CPUS) {
+               result = -EINVAL;
+               goto fail_ck;
+       }
 
        policy->cur = policy->min = policy->max = omap_getspeed(policy->cpu);
-       result = opp_init_cpufreq_table(mpu_dev, &freq_table);
+
+       if (atomic_inc_return(&freq_table_users) == 1)
+               result = opp_init_cpufreq_table(mpu_dev, &freq_table);
 
        if (result) {
                dev_err(mpu_dev, "%s: cpu%d: failed creating freq table[%d]\n",
                                __func__, policy->cpu, result);
-               return result;
+               goto fail_ck;
        }
 
        result = cpufreq_frequency_table_cpuinfo(policy, freq_table);
-       if (!result)
-               cpufreq_frequency_table_get_attr(freq_table, policy->cpu);
+       if (result)
+               goto fail_table;
+
+       cpufreq_frequency_table_get_attr(freq_table, policy->cpu);
 
        policy->min = policy->cpuinfo.min_freq;
        policy->max = policy->cpuinfo.max_freq;
@@ -194,10 +209,17 @@ static int __cpuinit omap_cpu_init(struct cpufreq_policy *policy)
        policy->cpuinfo.transition_latency = 300 * 1000;
 
        return 0;
+
+fail_table:
+       freq_table_free();
+fail_ck:
+       clk_put(mpu_clk);
+       return result;
 }
 
 static int omap_cpu_exit(struct cpufreq_policy *policy)
 {
+       freq_table_free();
        clk_put(mpu_clk);
        return 0;
 }
@@ -232,7 +254,7 @@ static int __init omap_cpufreq_init(void)
                return -EINVAL;
        }
 
-       mpu_dev = omap2_get_mpuss_device();
+       mpu_dev = omap_device_get_by_hwmod_name("mpu");
        if (!mpu_dev) {
                pr_warning("%s: unable to get the mpu device\n", __func__);
                return -EINVAL;