First Support on Ginger and OMAP TI
[linux-ginger.git] / arch / arm / plat-omap / cpu-omap.c
blobf9b480d2b7eecafdb8e0eba965debcdcfaa84a65
1 /*
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 * Copyright (C) 2007-2008 Texas Instruments, Inc.
12 * Updated to support OMAP3
13 * Rajendra Nayak <rnayak@ti.com>
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License version 2 as
17 * published by the Free Software Foundation.
19 #include <linux/types.h>
20 #include <linux/kernel.h>
21 #include <linux/sched.h>
22 #include <linux/cpufreq.h>
23 #include <linux/delay.h>
24 #include <linux/init.h>
25 #include <linux/err.h>
26 #include <linux/clk.h>
27 #include <linux/io.h>
29 #include <mach/hardware.h>
30 #include <plat/clock.h>
31 #include <asm/system.h>
33 #if defined(CONFIG_ARCH_OMAP3) && !defined(CONFIG_OMAP_PM_NONE)
34 #include <plat/omap-pm.h>
35 #endif
37 #define VERY_HI_RATE 900000000
39 static struct cpufreq_frequency_table *freq_table;
41 #ifdef CONFIG_ARCH_OMAP1
42 #define MPU_CLK "mpu"
43 #elif CONFIG_ARCH_OMAP3
44 #define MPU_CLK "arm_fck"
45 #else
46 #define MPU_CLK "virt_prcm_set"
47 #endif
49 static struct clk *mpu_clk;
51 /* TODO: Add support for SDRAM timing changes */
53 int omap_verify_speed(struct cpufreq_policy *policy)
55 if (freq_table)
56 return cpufreq_frequency_table_verify(policy, freq_table);
58 if (policy->cpu)
59 return -EINVAL;
61 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
62 policy->cpuinfo.max_freq);
64 policy->min = clk_round_rate(mpu_clk, policy->min * 1000) / 1000;
65 policy->max = clk_round_rate(mpu_clk, policy->max * 1000) / 1000;
66 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
67 policy->cpuinfo.max_freq);
68 return 0;
71 unsigned int omap_getspeed(unsigned int cpu)
73 unsigned long rate;
75 if (cpu)
76 return 0;
78 rate = clk_get_rate(mpu_clk) / 1000;
79 return rate;
82 static int omap_target(struct cpufreq_policy *policy,
83 unsigned int target_freq,
84 unsigned int relation)
86 #ifdef CONFIG_ARCH_OMAP1
87 struct cpufreq_freqs freqs;
88 #endif
89 int ret = 0;
91 /* Ensure desired rate is within allowed range. Some govenors
92 * (ondemand) will just pass target_freq=0 to get the minimum. */
93 if (target_freq < policy->min)
94 target_freq = policy->min;
95 if (target_freq > policy->max)
96 target_freq = policy->max;
98 #ifdef CONFIG_ARCH_OMAP1
99 freqs.old = omap_getspeed(0);
100 freqs.new = clk_round_rate(mpu_clk, target_freq * 1000) / 1000;
101 freqs.cpu = 0;
103 if (freqs.old == freqs.new)
104 return ret;
105 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
106 #ifdef CONFIG_CPU_FREQ_DEBUG
107 printk(KERN_DEBUG "cpufreq-omap: transition: %u --> %u\n",
108 freqs.old, freqs.new);
109 #endif
110 ret = clk_set_rate(mpu_clk, freqs.new * 1000);
111 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
112 #elif defined(CONFIG_ARCH_OMAP3) && !defined(CONFIG_OMAP_PM_NONE)
113 if (mpu_opps) {
114 int ind;
115 for (ind = 1; ind <= MAX_VDD1_OPP; ind++) {
116 if (mpu_opps[ind].rate/1000 >= target_freq) {
117 omap_pm_cpu_set_freq
118 (mpu_opps[ind].rate);
119 break;
123 #endif
124 return ret;
127 static int __init omap_cpu_init(struct cpufreq_policy *policy)
129 int result = 0;
131 mpu_clk = clk_get(NULL, MPU_CLK);
132 if (IS_ERR(mpu_clk))
133 return PTR_ERR(mpu_clk);
135 if (policy->cpu != 0)
136 return -EINVAL;
138 policy->cur = policy->min = policy->max = omap_getspeed(0);
140 clk_init_cpufreq_table(&freq_table);
141 if (freq_table) {
142 result = cpufreq_frequency_table_cpuinfo(policy, freq_table);
143 if (!result)
144 cpufreq_frequency_table_get_attr(freq_table,
145 policy->cpu);
146 } else {
147 policy->cpuinfo.min_freq = clk_round_rate(mpu_clk, 0) / 1000;
148 policy->cpuinfo.max_freq = clk_round_rate(mpu_clk,
149 VERY_HI_RATE) / 1000;
152 clk_set_rate(mpu_clk, policy->cpuinfo.max_freq * 1000);
154 policy->min = policy->cpuinfo.min_freq;
155 policy->max = policy->cpuinfo.max_freq;
156 policy->cur = omap_getspeed(0);
158 /* FIXME: what's the actual transition time? */
159 policy->cpuinfo.transition_latency = 10 * 1000 * 1000;
160 return 0;
163 static int omap_cpu_exit(struct cpufreq_policy *policy)
165 clk_put(mpu_clk);
166 return 0;
169 static struct freq_attr *omap_cpufreq_attr[] = {
170 &cpufreq_freq_attr_scaling_available_freqs,
171 NULL,
174 static struct cpufreq_driver omap_driver = {
175 .flags = CPUFREQ_STICKY,
176 .verify = omap_verify_speed,
177 .target = omap_target,
178 .get = omap_getspeed,
179 .init = omap_cpu_init,
180 .exit = omap_cpu_exit,
181 .name = "omap",
182 .attr = omap_cpufreq_attr,
185 static int __init omap_cpufreq_init(void)
187 return cpufreq_register_driver(&omap_driver);
190 late_initcall(omap_cpufreq_init);
193 * if ever we want to remove this, upon cleanup call:
195 * cpufreq_unregister_driver()
196 * cpufreq_frequency_table_put_attr()