aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2011-05-15 13:16:38 -0400
committerLinus Walleij <linus.walleij@linaro.org>2011-05-24 16:19:55 -0400
commit46936340c4e545f3be935b9d34e0554d16dbac30 (patch)
tree9c65f184d4dc3d07ee1c79f0e046cfd855fb48da /arch
parent8317797ca657081ed81312ea3501f3a3d59d52e9 (diff)
mach-ux500: move CPUfreq driver to cpufreq subsystem
As part of the ARM arch subsystem migration, move the DB8500 cpufreq driver to drivers/cpufreq as discussed with Dave Jones. The Makefile is not updated in order to avoid cross-subsystem conflicts for this file in merges. Cc: Arnd Bergmann <arnd@arndb.de> Acked-by: Dave Jones <davej@redhat.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/mach-ux500/cpufreq.c210
1 files changed, 0 insertions, 210 deletions
diff --git a/arch/arm/mach-ux500/cpufreq.c b/arch/arm/mach-ux500/cpufreq.c
deleted file mode 100644
index d196939fcdb..00000000000
--- a/arch/arm/mach-ux500/cpufreq.c
+++ /dev/null
@@ -1,210 +0,0 @@
1/*
2 * CPU frequency scaling for u8500
3 * Inspired by linux/arch/arm/mach-davinci/cpufreq.c
4 *
5 * Copyright (C) STMicroelectronics 2009
6 * Copyright (C) ST-Ericsson SA 2010
7 *
8 * License Terms: GNU General Public License v2
9 *
10 * Author: Sundar Iyer <sundar.iyer@stericsson.com>
11 * Author: Martin Persson <martin.persson@stericsson.com>
12 * Author: Jonas Aaberg <jonas.aberg@stericsson.com>
13 *
14 */
15
16#include <linux/platform_device.h>
17#include <linux/kernel.h>
18#include <linux/cpufreq.h>
19#include <linux/delay.h>
20#include <linux/mfd/db8500-prcmu.h>
21
22#include <mach/hardware.h>
23
24#define DRIVER_NAME "cpufreq-u8500"
25#define CPUFREQ_NAME "u8500"
26
27static struct device *dev;
28
29static struct cpufreq_frequency_table freq_table[] = {
30 [0] = {
31 .index = 0,
32 .frequency = 200000,
33 },
34 [1] = {
35 .index = 1,
36 .frequency = 300000,
37 },
38 [2] = {
39 .index = 2,
40 .frequency = 600000,
41 },
42 [3] = {
43 /* Used for CPU_OPP_MAX, if available */
44 .index = 3,
45 .frequency = CPUFREQ_TABLE_END,
46 },
47 [4] = {
48 .index = 4,
49 .frequency = CPUFREQ_TABLE_END,
50 },
51};
52
53static enum prcmu_cpu_opp index2opp[] = {
54 CPU_OPP_EXT_CLK,
55 CPU_OPP_50,
56 CPU_OPP_100,
57 CPU_OPP_MAX
58};
59
60static int u8500_cpufreq_verify_speed(struct cpufreq_policy *policy)
61{
62 return cpufreq_frequency_table_verify(policy, freq_table);
63}
64
65static int u8500_cpufreq_target(struct cpufreq_policy *policy,
66 unsigned int target_freq,
67 unsigned int relation)
68{
69 struct cpufreq_freqs freqs;
70 unsigned int index;
71 int ret = 0;
72
73 /*
74 * Ensure desired rate is within allowed range. Some govenors
75 * (ondemand) will just pass target_freq=0 to get the minimum.
76 */
77 if (target_freq < policy->cpuinfo.min_freq)
78 target_freq = policy->cpuinfo.min_freq;
79 if (target_freq > policy->cpuinfo.max_freq)
80 target_freq = policy->cpuinfo.max_freq;
81
82 ret = cpufreq_frequency_table_target(policy, freq_table,
83 target_freq, relation, &index);
84 if (ret < 0) {
85 dev_err(dev, "Could not look up next frequency\n");
86 return ret;
87 }
88
89 freqs.old = policy->cur;
90 freqs.new = freq_table[index].frequency;
91 freqs.cpu = policy->cpu;
92
93 if (freqs.old == freqs.new) {
94 dev_dbg(dev, "Current and target frequencies are equal\n");
95 return 0;
96 }
97
98 dev_dbg(dev, "transition: %u --> %u\n", freqs.old, freqs.new);
99 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
100
101 ret = prcmu_set_cpu_opp(index2opp[index]);
102 if (ret < 0) {
103 dev_err(dev, "Failed to set OPP level\n");
104 return ret;
105 }
106
107 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
108
109 return ret;
110}
111
112static unsigned int u8500_cpufreq_getspeed(unsigned int cpu)
113{
114 int i;
115
116 for (i = 0; prcmu_get_cpu_opp() != index2opp[i]; i++)
117 ;
118 return freq_table[i].frequency;
119}
120
121static int __cpuinit u8500_cpu_init(struct cpufreq_policy *policy)
122{
123 int res;
124
125 BUILD_BUG_ON(ARRAY_SIZE(index2opp) + 1 != ARRAY_SIZE(freq_table));
126
127 if (cpu_is_u8500v2()) {
128 freq_table[1].frequency = 400000;
129 freq_table[2].frequency = 800000;
130 if (prcmu_has_arm_maxopp())
131 freq_table[3].frequency = 1000000;
132 }
133
134 /* get policy fields based on the table */
135 res = cpufreq_frequency_table_cpuinfo(policy, freq_table);
136 if (!res)
137 cpufreq_frequency_table_get_attr(freq_table, policy->cpu);
138 else {
139 dev_err(dev, "u8500-cpufreq : Failed to read policy table\n");
140 return res;
141 }
142
143 policy->min = policy->cpuinfo.min_freq;
144 policy->max = policy->cpuinfo.max_freq;
145 policy->cur = u8500_cpufreq_getspeed(policy->cpu);
146 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
147
148 /*
149 * FIXME : Need to take time measurement across the target()
150 * function with no/some/all drivers in the notification
151 * list.
152 */
153 policy->cpuinfo.transition_latency = 200 * 1000; /* in ns */
154
155 /* policy sharing between dual CPUs */
156 cpumask_copy(policy->cpus, &cpu_present_map);
157
158 policy->shared_type = CPUFREQ_SHARED_TYPE_ALL;
159
160 return res;
161}
162
163static struct freq_attr *u8500_cpufreq_attr[] = {
164 &cpufreq_freq_attr_scaling_available_freqs,
165 NULL,
166};
167static int u8500_cpu_exit(struct cpufreq_policy *policy)
168{
169 cpufreq_frequency_table_put_attr(policy->cpu);
170 return 0;
171}
172
173static struct cpufreq_driver u8500_driver = {
174 .owner = THIS_MODULE,
175 .flags = CPUFREQ_STICKY,
176 .verify = u8500_cpufreq_verify_speed,
177 .target = u8500_cpufreq_target,
178 .get = u8500_cpufreq_getspeed,
179 .init = u8500_cpu_init,
180 .exit = u8500_cpu_exit,
181 .name = CPUFREQ_NAME,
182 .attr = u8500_cpufreq_attr,
183};
184
185static int __init u8500_cpufreq_probe(struct platform_device *pdev)
186{
187 dev = &pdev->dev;
188 return cpufreq_register_driver(&u8500_driver);
189}
190
191static int __exit u8500_cpufreq_remove(struct platform_device *pdev)
192{
193 return cpufreq_unregister_driver(&u8500_driver);
194}
195
196static struct platform_driver u8500_cpufreq_driver = {
197 .driver = {
198 .name = DRIVER_NAME,
199 .owner = THIS_MODULE,
200 },
201 .remove = __exit_p(u8500_cpufreq_remove),
202};
203
204static int __init u8500_cpufreq_init(void)
205{
206 return platform_driver_probe(&u8500_cpufreq_driver,
207 &u8500_cpufreq_probe);
208}
209
210device_initcall(u8500_cpufreq_init);