16 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <linux/sched.h>
27 #include <linux/module.h>
34 #define OPP_TOLERANCE 4
38 static struct clk *mpu_clk;
39 static struct device *mpu_dev;
49 static unsigned int omap_getspeed(
unsigned int cpu)
61 unsigned int target_freq,
62 unsigned int relation)
68 unsigned long freq, volt = 0, volt_old = 0, tol = 0;
71 dev_err(mpu_dev,
"%s: cpu%d: no freq table!\n", __func__,
79 dev_dbg(mpu_dev,
"%s: cpu%d: no freq match for %d(ret=%d)\n",
80 __func__, policy->
cpu, target_freq, ret);
85 dev_err(mpu_dev,
"%s: cpu%d: no match for freq %d\n", __func__,
86 policy->
cpu, target_freq);
90 freqs.old = omap_getspeed(policy->
cpu);
91 freqs.cpu = policy->
cpu;
93 if (freqs.old == freqs.new && policy->
cur == freqs.new)
102 freq = freqs.new * 1000;
106 "CPUfreq: Cannot find matching frequency for %lu\n",
115 dev_err(mpu_dev,
"%s: unable to find MPU OPP for %d\n",
116 __func__, freqs.new);
124 dev_dbg(mpu_dev,
"cpufreq-omap: %u MHz, %ld mV --> %u MHz, %ld mV\n",
125 freqs.old / 1000, volt_old ? volt_old / 1000 : -1,
126 freqs.new / 1000, volt ? volt / 1000 : -1);
129 if (mpu_reg && (freqs.new > freqs.old)) {
132 dev_warn(mpu_dev,
"%s: unable to scale voltage up.\n",
134 freqs.new = freqs.old;
142 if (mpu_reg && (freqs.new < freqs.old)) {
145 dev_warn(mpu_dev,
"%s: unable to scale voltage down.\n",
148 freqs.new = freqs.old;
153 freqs.new = omap_getspeed(policy->
cpu);
165 static inline void freq_table_free(
void)
168 opp_free_cpufreq_table(mpu_dev, &freq_table);
177 return PTR_ERR(mpu_clk);
184 policy->
cur = policy->
min = policy->
max = omap_getspeed(policy->
cpu);
187 result = opp_init_cpufreq_table(mpu_dev, &freq_table);
190 dev_err(mpu_dev,
"%s: cpu%d: failed creating freq table[%d]\n",
191 __func__, policy->
cpu, result);
205 policy->
cur = omap_getspeed(policy->
cpu);
216 cpumask_setall(policy->
cpus);
220 policy->
cpuinfo.transition_latency = 300 * 1000;
238 static struct freq_attr *omap_cpufreq_attr[] = {
245 .verify = omap_verify_speed,
246 .target = omap_target,
247 .get = omap_getspeed,
248 .init = omap_cpu_init,
249 .exit = omap_cpu_exit,
251 .attr = omap_cpufreq_attr,
254 static int __init omap_cpufreq_init(
void)
258 pr_warning(
"%s: unable to get the mpu device\n", __func__);
263 if (IS_ERR(mpu_reg)) {
264 pr_warning(
"%s: unable to get MPU regulator\n", __func__);
272 pr_warn(
"%s: physical regulator not present for MPU\n",
282 static void __exit omap_cpufreq_exit(
void)