]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * linux/arch/arm/mach-integrator/cpu.c | |
3 | * | |
4 | * Copyright (C) 2001-2002 Deep Blue Solutions Ltd. | |
5 | * | |
1da177e4 LT |
6 | * This program is free software; you can redistribute it and/or modify |
7 | * it under the terms of the GNU General Public License version 2 as | |
8 | * published by the Free Software Foundation. | |
9 | * | |
10 | * CPU support functions | |
11 | */ | |
12 | #include <linux/module.h> | |
13 | #include <linux/types.h> | |
14 | #include <linux/kernel.h> | |
15 | #include <linux/cpufreq.h> | |
1da177e4 LT |
16 | #include <linux/sched.h> |
17 | #include <linux/smp.h> | |
18 | #include <linux/init.h> | |
fced80c7 | 19 | #include <linux/io.h> |
1da177e4 | 20 | |
a09e64fb | 21 | #include <mach/hardware.h> |
1da177e4 LT |
22 | #include <asm/mach-types.h> |
23 | #include <asm/hardware/icst525.h> | |
24 | ||
25 | static struct cpufreq_driver integrator_driver; | |
26 | ||
27 | #define CM_ID (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_ID_OFFSET) | |
28 | #define CM_OSC (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_OSC_OFFSET) | |
29 | #define CM_STAT (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_STAT_OFFSET) | |
30 | #define CM_LOCK (IO_ADDRESS(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_LOCK_OFFSET) | |
31 | ||
32 | static const struct icst525_params lclk_params = { | |
33 | .ref = 24000, | |
34 | .vco_max = 320000, | |
35 | .vd_min = 8, | |
36 | .vd_max = 132, | |
37 | .rd_min = 24, | |
38 | .rd_max = 24, | |
39 | }; | |
40 | ||
41 | static const struct icst525_params cclk_params = { | |
42 | .ref = 24000, | |
43 | .vco_max = 320000, | |
44 | .vd_min = 12, | |
45 | .vd_max = 160, | |
46 | .rd_min = 24, | |
47 | .rd_max = 24, | |
48 | }; | |
49 | ||
50 | /* | |
51 | * Validate the speed policy. | |
52 | */ | |
53 | static int integrator_verify_policy(struct cpufreq_policy *policy) | |
54 | { | |
55 | struct icst525_vco vco; | |
56 | ||
57 | cpufreq_verify_within_limits(policy, | |
58 | policy->cpuinfo.min_freq, | |
59 | policy->cpuinfo.max_freq); | |
60 | ||
61 | vco = icst525_khz_to_vco(&cclk_params, policy->max); | |
62 | policy->max = icst525_khz(&cclk_params, vco); | |
63 | ||
64 | vco = icst525_khz_to_vco(&cclk_params, policy->min); | |
65 | policy->min = icst525_khz(&cclk_params, vco); | |
66 | ||
67 | cpufreq_verify_within_limits(policy, | |
68 | policy->cpuinfo.min_freq, | |
69 | policy->cpuinfo.max_freq); | |
70 | ||
71 | return 0; | |
72 | } | |
73 | ||
74 | ||
75 | static int integrator_set_target(struct cpufreq_policy *policy, | |
76 | unsigned int target_freq, | |
77 | unsigned int relation) | |
78 | { | |
79 | cpumask_t cpus_allowed; | |
80 | int cpu = policy->cpu; | |
81 | struct icst525_vco vco; | |
82 | struct cpufreq_freqs freqs; | |
83 | u_int cm_osc; | |
84 | ||
85 | /* | |
86 | * Save this threads cpus_allowed mask. | |
87 | */ | |
88 | cpus_allowed = current->cpus_allowed; | |
89 | ||
90 | /* | |
91 | * Bind to the specified CPU. When this call returns, | |
92 | * we should be running on the right CPU. | |
93 | */ | |
94 | set_cpus_allowed(current, cpumask_of_cpu(cpu)); | |
95 | BUG_ON(cpu != smp_processor_id()); | |
96 | ||
97 | /* get current setting */ | |
98 | cm_osc = __raw_readl(CM_OSC); | |
99 | ||
100 | if (machine_is_integrator()) { | |
101 | vco.s = (cm_osc >> 8) & 7; | |
102 | } else if (machine_is_cintegrator()) { | |
103 | vco.s = 1; | |
104 | } | |
105 | vco.v = cm_osc & 255; | |
106 | vco.r = 22; | |
107 | freqs.old = icst525_khz(&cclk_params, vco); | |
108 | ||
109 | /* icst525_khz_to_vco rounds down -- so we need the next | |
110 | * larger freq in case of CPUFREQ_RELATION_L. | |
111 | */ | |
112 | if (relation == CPUFREQ_RELATION_L) | |
113 | target_freq += 999; | |
114 | if (target_freq > policy->max) | |
115 | target_freq = policy->max; | |
116 | vco = icst525_khz_to_vco(&cclk_params, target_freq); | |
117 | freqs.new = icst525_khz(&cclk_params, vco); | |
118 | ||
119 | freqs.cpu = policy->cpu; | |
120 | ||
121 | if (freqs.old == freqs.new) { | |
122 | set_cpus_allowed(current, cpus_allowed); | |
123 | return 0; | |
124 | } | |
125 | ||
126 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | |
127 | ||
128 | cm_osc = __raw_readl(CM_OSC); | |
129 | ||
130 | if (machine_is_integrator()) { | |
131 | cm_osc &= 0xfffff800; | |
132 | cm_osc |= vco.s << 8; | |
133 | } else if (machine_is_cintegrator()) { | |
134 | cm_osc &= 0xffffff00; | |
135 | } | |
136 | cm_osc |= vco.v; | |
137 | ||
138 | __raw_writel(0xa05f, CM_LOCK); | |
139 | __raw_writel(cm_osc, CM_OSC); | |
140 | __raw_writel(0, CM_LOCK); | |
141 | ||
142 | /* | |
143 | * Restore the CPUs allowed mask. | |
144 | */ | |
145 | set_cpus_allowed(current, cpus_allowed); | |
146 | ||
147 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | |
148 | ||
149 | return 0; | |
150 | } | |
151 | ||
152 | static unsigned int integrator_get(unsigned int cpu) | |
153 | { | |
154 | cpumask_t cpus_allowed; | |
155 | unsigned int current_freq; | |
156 | u_int cm_osc; | |
157 | struct icst525_vco vco; | |
158 | ||
159 | cpus_allowed = current->cpus_allowed; | |
160 | ||
161 | set_cpus_allowed(current, cpumask_of_cpu(cpu)); | |
162 | BUG_ON(cpu != smp_processor_id()); | |
163 | ||
164 | /* detect memory etc. */ | |
165 | cm_osc = __raw_readl(CM_OSC); | |
166 | ||
167 | if (machine_is_integrator()) { | |
168 | vco.s = (cm_osc >> 8) & 7; | |
169 | } else if (machine_is_cintegrator()) { | |
170 | vco.s = 1; | |
171 | } | |
172 | vco.v = cm_osc & 255; | |
173 | vco.r = 22; | |
174 | ||
175 | current_freq = icst525_khz(&cclk_params, vco); /* current freq */ | |
176 | ||
177 | set_cpus_allowed(current, cpus_allowed); | |
178 | ||
179 | return current_freq; | |
180 | } | |
181 | ||
182 | static int integrator_cpufreq_init(struct cpufreq_policy *policy) | |
183 | { | |
184 | ||
185 | /* set default policy and cpuinfo */ | |
1da177e4 LT |
186 | policy->cpuinfo.max_freq = 160000; |
187 | policy->cpuinfo.min_freq = 12000; | |
188 | policy->cpuinfo.transition_latency = 1000000; /* 1 ms, assumed */ | |
189 | policy->cur = policy->min = policy->max = integrator_get(policy->cpu); | |
190 | ||
191 | return 0; | |
192 | } | |
193 | ||
194 | static struct cpufreq_driver integrator_driver = { | |
195 | .verify = integrator_verify_policy, | |
196 | .target = integrator_set_target, | |
197 | .get = integrator_get, | |
198 | .init = integrator_cpufreq_init, | |
199 | .name = "integrator", | |
200 | }; | |
201 | ||
202 | static int __init integrator_cpu_init(void) | |
203 | { | |
204 | return cpufreq_register_driver(&integrator_driver); | |
205 | } | |
206 | ||
207 | static void __exit integrator_cpu_exit(void) | |
208 | { | |
209 | cpufreq_unregister_driver(&integrator_driver); | |
210 | } | |
211 | ||
212 | MODULE_AUTHOR ("Russell M. King"); | |
213 | MODULE_DESCRIPTION ("cpufreq driver for ARM Integrator CPUs"); | |
214 | MODULE_LICENSE ("GPL"); | |
215 | ||
216 | module_init(integrator_cpu_init); | |
217 | module_exit(integrator_cpu_exit); |