2 * linux/arch/arm/plat-omap/cpu-omap.c
4 * CPU frequency scaling for OMAP
6 * Copyright (C) 2005 Nokia Corporation
7 * Written by Tony Lindgren <tony@atomide.com>
9 * Based on cpu-sa1110.c, Copyright (C) 2001 Russell King
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/sched.h>
18 #include <linux/cpufreq.h>
19 #include <linux/delay.h>
20 #include <linux/init.h>
21 #include <linux/err.h>
23 #include <asm/hardware.h>
25 #include <asm/system.h>
27 #include <asm/hardware/clock.h>
29 /* TODO: Add support for SDRAM timing changes */
31 int omap_verify_speed(struct cpufreq_policy *policy)
38 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
39 policy->cpuinfo.max_freq);
40 mpu_clk = clk_get(NULL, "mpu");
42 return PTR_ERR(mpu_clk);
43 policy->min = clk_round_rate(mpu_clk, policy->min * 1000) / 1000;
44 policy->max = clk_round_rate(mpu_clk, policy->max * 1000) / 1000;
45 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
46 policy->cpuinfo.max_freq);
52 unsigned int omap_getspeed(unsigned int cpu)
60 mpu_clk = clk_get(NULL, "mpu");
63 rate = clk_get_rate(mpu_clk) / 1000;
69 static int omap_target(struct cpufreq_policy *policy,
70 unsigned int target_freq,
71 unsigned int relation)
74 struct cpufreq_freqs freqs;
77 mpu_clk = clk_get(NULL, "mpu");
79 return PTR_ERR(mpu_clk);
81 freqs.old = omap_getspeed(0);
82 freqs.new = clk_round_rate(mpu_clk, target_freq * 1000) / 1000;
85 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
86 ret = clk_set_rate(mpu_clk, target_freq * 1000);
87 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
93 static int __init omap_cpu_init(struct cpufreq_policy *policy)
97 mpu_clk = clk_get(NULL, "mpu");
99 return PTR_ERR(mpu_clk);
101 if (policy->cpu != 0)
103 policy->cur = policy->min = policy->max = omap_getspeed(0);
104 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
105 policy->cpuinfo.min_freq = clk_round_rate(mpu_clk, 0) / 1000;
106 policy->cpuinfo.max_freq = clk_round_rate(mpu_clk, 216000000) / 1000;
107 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
113 static struct cpufreq_driver omap_driver = {
114 .flags = CPUFREQ_STICKY,
115 .verify = omap_verify_speed,
116 .target = omap_target,
117 .get = omap_getspeed,
118 .init = omap_cpu_init,
122 static int __init omap_cpufreq_init(void)
124 return cpufreq_register_driver(&omap_driver);
127 arch_initcall(omap_cpufreq_init);