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>
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>
37 #define VERY_HI_RATE 900000000
39 static struct cpufreq_frequency_table
*freq_table
;
41 #ifdef CONFIG_ARCH_OMAP1
43 #elif CONFIG_ARCH_OMAP3
44 #define MPU_CLK "arm_fck"
46 #define MPU_CLK "virt_prcm_set"
49 static struct clk
*mpu_clk
;
51 /* TODO: Add support for SDRAM timing changes */
53 int omap_verify_speed(struct cpufreq_policy
*policy
)
56 return cpufreq_frequency_table_verify(policy
, freq_table
);
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
);
71 unsigned int omap_getspeed(unsigned int cpu
)
78 rate
= clk_get_rate(mpu_clk
) / 1000;
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
;
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;
103 if (freqs
.old
== freqs
.new)
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);
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)
115 for (ind
= 1; ind
<= MAX_VDD1_OPP
; ind
++) {
116 if (mpu_opps
[ind
].rate
/1000 >= target_freq
) {
118 (mpu_opps
[ind
].rate
);
127 static int __init
omap_cpu_init(struct cpufreq_policy
*policy
)
131 mpu_clk
= clk_get(NULL
, MPU_CLK
);
133 return PTR_ERR(mpu_clk
);
135 if (policy
->cpu
!= 0)
138 policy
->cur
= policy
->min
= policy
->max
= omap_getspeed(0);
140 clk_init_cpufreq_table(&freq_table
);
142 result
= cpufreq_frequency_table_cpuinfo(policy
, freq_table
);
144 cpufreq_frequency_table_get_attr(freq_table
,
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;
163 static int omap_cpu_exit(struct cpufreq_policy
*policy
)
169 static struct freq_attr
*omap_cpufreq_attr
[] = {
170 &cpufreq_freq_attr_scaling_available_freqs
,
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
,
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()