cpufreq: OMAP: ensure valid clock rate before scaling
[firefly-linux-kernel-4.4.55.git] / drivers / cpufreq / omap-cpufreq.c
index b47034e650a579b9d0263f8d0a03af2ecc8b3aa7..0fe395aea114c0b8f036196261bc36e2a80deeb7 100644 (file)
 /* OPP tolerance in percentage */
 #define        OPP_TOLERANCE   4
 
-#ifdef CONFIG_SMP
-struct lpj_info {
-       unsigned long   ref;
-       unsigned int    freq;
-};
-
-static DEFINE_PER_CPU(struct lpj_info, lpj_ref);
-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;
@@ -118,6 +108,14 @@ static int omap_target(struct cpufreq_policy *policy,
        }
 
        freq = freqs.new * 1000;
+       ret = clk_round_rate(mpu_clk, freq);
+       if (IS_ERR_VALUE(ret)) {
+               dev_warn(mpu_dev,
+                        "CPUfreq: Cannot find matching frequency for %lu\n",
+                        freq);
+               return ret;
+       }
+       freq = ret;
 
        if (mpu_reg) {
                opp = opp_find_freq_ceil(mpu_dev, &freq);
@@ -161,31 +159,6 @@ static int omap_target(struct cpufreq_policy *policy,
        }
 
        freqs.new = omap_getspeed(policy->cpu);
-#ifdef CONFIG_SMP
-       /*
-        * Note that loops_per_jiffy is not updated on SMP systems in
-        * cpufreq driver. So, update the per-CPU loops_per_jiffy value
-        * on frequency transition. We need to update all dependent CPUs.
-        */
-       for_each_cpu(i, policy->cpus) {
-               struct lpj_info *lpj = &per_cpu(lpj_ref, i);
-               if (!lpj->freq) {
-                       lpj->ref = per_cpu(cpu_data, i).loops_per_jiffy;
-                       lpj->freq = freqs.old;
-               }
-
-               per_cpu(cpu_data, i).loops_per_jiffy =
-                       cpufreq_scale(lpj->ref, lpj->freq, freqs.new);
-       }
-
-       /* And don't forget to adjust the global one */
-       if (!global_lpj_ref.freq) {
-               global_lpj_ref.ref = loops_per_jiffy;
-               global_lpj_ref.freq = freqs.old;
-       }
-       loops_per_jiffy = cpufreq_scale(global_lpj_ref.ref, global_lpj_ref.freq,
-                                       freqs.new);
-#endif
 
 done:
        /* notifiers */
@@ -301,9 +274,9 @@ static int __init omap_cpufreq_init(void)
        }
 
        mpu_dev = omap_device_get_by_hwmod_name("mpu");
-       if (!mpu_dev) {
+       if (IS_ERR(mpu_dev)) {
                pr_warning("%s: unable to get the mpu device\n", __func__);
-               return -EINVAL;
+               return PTR_ERR(mpu_dev);
        }
 
        mpu_reg = regulator_get(mpu_dev, "vcc");