[ARM] Move AMBA bus code to drivers/amba/
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / arm / plat-omap / cpu-omap.c
CommitLineData
ec6bced6
TL
1/*
2 * linux/arch/arm/plat-omap/cpu-omap.c
3 *
4 * CPU frequency scaling for OMAP
5 *
6 * Copyright (C) 2005 Nokia Corporation
7 * Written by Tony Lindgren <tony@atomide.com>
8 *
9 * Based on cpu-sa1110.c, Copyright (C) 2001 Russell King
10 *
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.
14 */
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>
22
23#include <asm/hardware.h>
ec6bced6
TL
24#include <asm/io.h>
25#include <asm/system.h>
26
27#include <asm/hardware/clock.h>
28
29/* TODO: Add support for SDRAM timing changes */
30
31int omap_verify_speed(struct cpufreq_policy *policy)
32{
33 struct clk * mpu_clk;
34
35 if (policy->cpu)
36 return -EINVAL;
37
38 cpufreq_verify_within_limits(policy, policy->cpuinfo.min_freq,
39 policy->cpuinfo.max_freq);
40 mpu_clk = clk_get(NULL, "mpu");
41 if (IS_ERR(mpu_clk))
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);
47 clk_put(mpu_clk);
48
49 return 0;
50}
51
52unsigned int omap_getspeed(unsigned int cpu)
53{
54 struct clk * mpu_clk;
55 unsigned long rate;
56
57 if (cpu)
58 return 0;
59
60 mpu_clk = clk_get(NULL, "mpu");
61 if (IS_ERR(mpu_clk))
62 return 0;
63 rate = clk_get_rate(mpu_clk) / 1000;
64 clk_put(mpu_clk);
65
66 return rate;
67}
68
69static int omap_target(struct cpufreq_policy *policy,
70 unsigned int target_freq,
71 unsigned int relation)
72{
73 struct clk * mpu_clk;
74 struct cpufreq_freqs freqs;
75 int ret = 0;
76
77 mpu_clk = clk_get(NULL, "mpu");
78 if (IS_ERR(mpu_clk))
79 return PTR_ERR(mpu_clk);
80
81 freqs.old = omap_getspeed(0);
82 freqs.new = clk_round_rate(mpu_clk, target_freq * 1000) / 1000;
83 freqs.cpu = 0;
84
85 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
86 ret = clk_set_rate(mpu_clk, target_freq * 1000);
87 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
88 clk_put(mpu_clk);
89
90 return ret;
91}
92
93static int __init omap_cpu_init(struct cpufreq_policy *policy)
94{
95 struct clk * mpu_clk;
96
97 mpu_clk = clk_get(NULL, "mpu");
98 if (IS_ERR(mpu_clk))
99 return PTR_ERR(mpu_clk);
100
101 if (policy->cpu != 0)
102 return -EINVAL;
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;
108 clk_put(mpu_clk);
109
110 return 0;
111}
112
113static 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,
119 .name = "omap",
120};
121
122static int __init omap_cpufreq_init(void)
123{
124 return cpufreq_register_driver(&omap_driver);
125}
126
127arch_initcall(omap_cpufreq_init);