Commit 7b14dedd1fe72f33e128ed1b0cbf96d06acc7e9c
Committed by
Dave Jones
1 parent
7970e08bf0
Exists in
master
and in
39 other branches
[CPUFREQ] drivers/cpufreq/cpufreq.c: static functions mustn't be exported
This patch removes the EXPORT_SYMBOL_GPL of the static function cpufreq_parse_governor(). Signed-off-by: Adrian Bunk <bunk@stusta.de> Signed-off-by: Dave Jones <davej@redhat.com>
Showing 1 changed file with 0 additions and 1 deletions Inline Diff
drivers/cpufreq/cpufreq.c
1 | /* | 1 | /* |
2 | * linux/drivers/cpufreq/cpufreq.c | 2 | * linux/drivers/cpufreq/cpufreq.c |
3 | * | 3 | * |
4 | * Copyright (C) 2001 Russell King | 4 | * Copyright (C) 2001 Russell King |
5 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> | 5 | * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de> |
6 | * | 6 | * |
7 | * Oct 2005 - Ashok Raj <ashok.raj@intel.com> | 7 | * Oct 2005 - Ashok Raj <ashok.raj@intel.com> |
8 | * Added handling for CPU hotplug | 8 | * Added handling for CPU hotplug |
9 | * Feb 2006 - Jacob Shin <jacob.shin@amd.com> | 9 | * Feb 2006 - Jacob Shin <jacob.shin@amd.com> |
10 | * Fix handling for CPU hotplug -- affected CPUs | 10 | * Fix handling for CPU hotplug -- affected CPUs |
11 | * | 11 | * |
12 | * This program is free software; you can redistribute it and/or modify | 12 | * This program is free software; you can redistribute it and/or modify |
13 | * it under the terms of the GNU General Public License version 2 as | 13 | * it under the terms of the GNU General Public License version 2 as |
14 | * published by the Free Software Foundation. | 14 | * published by the Free Software Foundation. |
15 | * | 15 | * |
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include <linux/config.h> | 18 | #include <linux/config.h> |
19 | #include <linux/kernel.h> | 19 | #include <linux/kernel.h> |
20 | #include <linux/module.h> | 20 | #include <linux/module.h> |
21 | #include <linux/init.h> | 21 | #include <linux/init.h> |
22 | #include <linux/notifier.h> | 22 | #include <linux/notifier.h> |
23 | #include <linux/cpufreq.h> | 23 | #include <linux/cpufreq.h> |
24 | #include <linux/delay.h> | 24 | #include <linux/delay.h> |
25 | #include <linux/interrupt.h> | 25 | #include <linux/interrupt.h> |
26 | #include <linux/spinlock.h> | 26 | #include <linux/spinlock.h> |
27 | #include <linux/device.h> | 27 | #include <linux/device.h> |
28 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
29 | #include <linux/cpu.h> | 29 | #include <linux/cpu.h> |
30 | #include <linux/completion.h> | 30 | #include <linux/completion.h> |
31 | #include <linux/mutex.h> | 31 | #include <linux/mutex.h> |
32 | 32 | ||
33 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_CORE, "cpufreq-core", msg) | 33 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_CORE, "cpufreq-core", msg) |
34 | 34 | ||
35 | /** | 35 | /** |
36 | * The "cpufreq driver" - the arch- or hardware-dependend low | 36 | * The "cpufreq driver" - the arch- or hardware-dependend low |
37 | * level driver of CPUFreq support, and its spinlock. This lock | 37 | * level driver of CPUFreq support, and its spinlock. This lock |
38 | * also protects the cpufreq_cpu_data array. | 38 | * also protects the cpufreq_cpu_data array. |
39 | */ | 39 | */ |
40 | static struct cpufreq_driver *cpufreq_driver; | 40 | static struct cpufreq_driver *cpufreq_driver; |
41 | static struct cpufreq_policy *cpufreq_cpu_data[NR_CPUS]; | 41 | static struct cpufreq_policy *cpufreq_cpu_data[NR_CPUS]; |
42 | static DEFINE_SPINLOCK(cpufreq_driver_lock); | 42 | static DEFINE_SPINLOCK(cpufreq_driver_lock); |
43 | 43 | ||
44 | /* internal prototypes */ | 44 | /* internal prototypes */ |
45 | static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event); | 45 | static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event); |
46 | static void handle_update(void *data); | 46 | static void handle_update(void *data); |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Two notifier lists: the "policy" list is involved in the | 49 | * Two notifier lists: the "policy" list is involved in the |
50 | * validation process for a new CPU frequency policy; the | 50 | * validation process for a new CPU frequency policy; the |
51 | * "transition" list for kernel code that needs to handle | 51 | * "transition" list for kernel code that needs to handle |
52 | * changes to devices when the CPU clock speed changes. | 52 | * changes to devices when the CPU clock speed changes. |
53 | * The mutex locks both lists. | 53 | * The mutex locks both lists. |
54 | */ | 54 | */ |
55 | static BLOCKING_NOTIFIER_HEAD(cpufreq_policy_notifier_list); | 55 | static BLOCKING_NOTIFIER_HEAD(cpufreq_policy_notifier_list); |
56 | static BLOCKING_NOTIFIER_HEAD(cpufreq_transition_notifier_list); | 56 | static BLOCKING_NOTIFIER_HEAD(cpufreq_transition_notifier_list); |
57 | 57 | ||
58 | 58 | ||
59 | static LIST_HEAD(cpufreq_governor_list); | 59 | static LIST_HEAD(cpufreq_governor_list); |
60 | static DEFINE_MUTEX (cpufreq_governor_mutex); | 60 | static DEFINE_MUTEX (cpufreq_governor_mutex); |
61 | 61 | ||
62 | struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) | 62 | struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu) |
63 | { | 63 | { |
64 | struct cpufreq_policy *data; | 64 | struct cpufreq_policy *data; |
65 | unsigned long flags; | 65 | unsigned long flags; |
66 | 66 | ||
67 | if (cpu >= NR_CPUS) | 67 | if (cpu >= NR_CPUS) |
68 | goto err_out; | 68 | goto err_out; |
69 | 69 | ||
70 | /* get the cpufreq driver */ | 70 | /* get the cpufreq driver */ |
71 | spin_lock_irqsave(&cpufreq_driver_lock, flags); | 71 | spin_lock_irqsave(&cpufreq_driver_lock, flags); |
72 | 72 | ||
73 | if (!cpufreq_driver) | 73 | if (!cpufreq_driver) |
74 | goto err_out_unlock; | 74 | goto err_out_unlock; |
75 | 75 | ||
76 | if (!try_module_get(cpufreq_driver->owner)) | 76 | if (!try_module_get(cpufreq_driver->owner)) |
77 | goto err_out_unlock; | 77 | goto err_out_unlock; |
78 | 78 | ||
79 | 79 | ||
80 | /* get the CPU */ | 80 | /* get the CPU */ |
81 | data = cpufreq_cpu_data[cpu]; | 81 | data = cpufreq_cpu_data[cpu]; |
82 | 82 | ||
83 | if (!data) | 83 | if (!data) |
84 | goto err_out_put_module; | 84 | goto err_out_put_module; |
85 | 85 | ||
86 | if (!kobject_get(&data->kobj)) | 86 | if (!kobject_get(&data->kobj)) |
87 | goto err_out_put_module; | 87 | goto err_out_put_module; |
88 | 88 | ||
89 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 89 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
90 | return data; | 90 | return data; |
91 | 91 | ||
92 | err_out_put_module: | 92 | err_out_put_module: |
93 | module_put(cpufreq_driver->owner); | 93 | module_put(cpufreq_driver->owner); |
94 | err_out_unlock: | 94 | err_out_unlock: |
95 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 95 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
96 | err_out: | 96 | err_out: |
97 | return NULL; | 97 | return NULL; |
98 | } | 98 | } |
99 | EXPORT_SYMBOL_GPL(cpufreq_cpu_get); | 99 | EXPORT_SYMBOL_GPL(cpufreq_cpu_get); |
100 | 100 | ||
101 | 101 | ||
102 | void cpufreq_cpu_put(struct cpufreq_policy *data) | 102 | void cpufreq_cpu_put(struct cpufreq_policy *data) |
103 | { | 103 | { |
104 | kobject_put(&data->kobj); | 104 | kobject_put(&data->kobj); |
105 | module_put(cpufreq_driver->owner); | 105 | module_put(cpufreq_driver->owner); |
106 | } | 106 | } |
107 | EXPORT_SYMBOL_GPL(cpufreq_cpu_put); | 107 | EXPORT_SYMBOL_GPL(cpufreq_cpu_put); |
108 | 108 | ||
109 | 109 | ||
110 | /********************************************************************* | 110 | /********************************************************************* |
111 | * UNIFIED DEBUG HELPERS * | 111 | * UNIFIED DEBUG HELPERS * |
112 | *********************************************************************/ | 112 | *********************************************************************/ |
113 | #ifdef CONFIG_CPU_FREQ_DEBUG | 113 | #ifdef CONFIG_CPU_FREQ_DEBUG |
114 | 114 | ||
115 | /* what part(s) of the CPUfreq subsystem are debugged? */ | 115 | /* what part(s) of the CPUfreq subsystem are debugged? */ |
116 | static unsigned int debug; | 116 | static unsigned int debug; |
117 | 117 | ||
118 | /* is the debug output ratelimit'ed using printk_ratelimit? User can | 118 | /* is the debug output ratelimit'ed using printk_ratelimit? User can |
119 | * set or modify this value. | 119 | * set or modify this value. |
120 | */ | 120 | */ |
121 | static unsigned int debug_ratelimit = 1; | 121 | static unsigned int debug_ratelimit = 1; |
122 | 122 | ||
123 | /* is the printk_ratelimit'ing enabled? It's enabled after a successful | 123 | /* is the printk_ratelimit'ing enabled? It's enabled after a successful |
124 | * loading of a cpufreq driver, temporarily disabled when a new policy | 124 | * loading of a cpufreq driver, temporarily disabled when a new policy |
125 | * is set, and disabled upon cpufreq driver removal | 125 | * is set, and disabled upon cpufreq driver removal |
126 | */ | 126 | */ |
127 | static unsigned int disable_ratelimit = 1; | 127 | static unsigned int disable_ratelimit = 1; |
128 | static DEFINE_SPINLOCK(disable_ratelimit_lock); | 128 | static DEFINE_SPINLOCK(disable_ratelimit_lock); |
129 | 129 | ||
130 | static void cpufreq_debug_enable_ratelimit(void) | 130 | static void cpufreq_debug_enable_ratelimit(void) |
131 | { | 131 | { |
132 | unsigned long flags; | 132 | unsigned long flags; |
133 | 133 | ||
134 | spin_lock_irqsave(&disable_ratelimit_lock, flags); | 134 | spin_lock_irqsave(&disable_ratelimit_lock, flags); |
135 | if (disable_ratelimit) | 135 | if (disable_ratelimit) |
136 | disable_ratelimit--; | 136 | disable_ratelimit--; |
137 | spin_unlock_irqrestore(&disable_ratelimit_lock, flags); | 137 | spin_unlock_irqrestore(&disable_ratelimit_lock, flags); |
138 | } | 138 | } |
139 | 139 | ||
140 | static void cpufreq_debug_disable_ratelimit(void) | 140 | static void cpufreq_debug_disable_ratelimit(void) |
141 | { | 141 | { |
142 | unsigned long flags; | 142 | unsigned long flags; |
143 | 143 | ||
144 | spin_lock_irqsave(&disable_ratelimit_lock, flags); | 144 | spin_lock_irqsave(&disable_ratelimit_lock, flags); |
145 | disable_ratelimit++; | 145 | disable_ratelimit++; |
146 | spin_unlock_irqrestore(&disable_ratelimit_lock, flags); | 146 | spin_unlock_irqrestore(&disable_ratelimit_lock, flags); |
147 | } | 147 | } |
148 | 148 | ||
149 | void cpufreq_debug_printk(unsigned int type, const char *prefix, const char *fmt, ...) | 149 | void cpufreq_debug_printk(unsigned int type, const char *prefix, const char *fmt, ...) |
150 | { | 150 | { |
151 | char s[256]; | 151 | char s[256]; |
152 | va_list args; | 152 | va_list args; |
153 | unsigned int len; | 153 | unsigned int len; |
154 | unsigned long flags; | 154 | unsigned long flags; |
155 | 155 | ||
156 | WARN_ON(!prefix); | 156 | WARN_ON(!prefix); |
157 | if (type & debug) { | 157 | if (type & debug) { |
158 | spin_lock_irqsave(&disable_ratelimit_lock, flags); | 158 | spin_lock_irqsave(&disable_ratelimit_lock, flags); |
159 | if (!disable_ratelimit && debug_ratelimit && !printk_ratelimit()) { | 159 | if (!disable_ratelimit && debug_ratelimit && !printk_ratelimit()) { |
160 | spin_unlock_irqrestore(&disable_ratelimit_lock, flags); | 160 | spin_unlock_irqrestore(&disable_ratelimit_lock, flags); |
161 | return; | 161 | return; |
162 | } | 162 | } |
163 | spin_unlock_irqrestore(&disable_ratelimit_lock, flags); | 163 | spin_unlock_irqrestore(&disable_ratelimit_lock, flags); |
164 | 164 | ||
165 | len = snprintf(s, 256, KERN_DEBUG "%s: ", prefix); | 165 | len = snprintf(s, 256, KERN_DEBUG "%s: ", prefix); |
166 | 166 | ||
167 | va_start(args, fmt); | 167 | va_start(args, fmt); |
168 | len += vsnprintf(&s[len], (256 - len), fmt, args); | 168 | len += vsnprintf(&s[len], (256 - len), fmt, args); |
169 | va_end(args); | 169 | va_end(args); |
170 | 170 | ||
171 | printk(s); | 171 | printk(s); |
172 | 172 | ||
173 | WARN_ON(len < 5); | 173 | WARN_ON(len < 5); |
174 | } | 174 | } |
175 | } | 175 | } |
176 | EXPORT_SYMBOL(cpufreq_debug_printk); | 176 | EXPORT_SYMBOL(cpufreq_debug_printk); |
177 | 177 | ||
178 | 178 | ||
179 | module_param(debug, uint, 0644); | 179 | module_param(debug, uint, 0644); |
180 | MODULE_PARM_DESC(debug, "CPUfreq debugging: add 1 to debug core, 2 to debug drivers, and 4 to debug governors."); | 180 | MODULE_PARM_DESC(debug, "CPUfreq debugging: add 1 to debug core, 2 to debug drivers, and 4 to debug governors."); |
181 | 181 | ||
182 | module_param(debug_ratelimit, uint, 0644); | 182 | module_param(debug_ratelimit, uint, 0644); |
183 | MODULE_PARM_DESC(debug_ratelimit, "CPUfreq debugging: set to 0 to disable ratelimiting."); | 183 | MODULE_PARM_DESC(debug_ratelimit, "CPUfreq debugging: set to 0 to disable ratelimiting."); |
184 | 184 | ||
185 | #else /* !CONFIG_CPU_FREQ_DEBUG */ | 185 | #else /* !CONFIG_CPU_FREQ_DEBUG */ |
186 | 186 | ||
187 | static inline void cpufreq_debug_enable_ratelimit(void) { return; } | 187 | static inline void cpufreq_debug_enable_ratelimit(void) { return; } |
188 | static inline void cpufreq_debug_disable_ratelimit(void) { return; } | 188 | static inline void cpufreq_debug_disable_ratelimit(void) { return; } |
189 | 189 | ||
190 | #endif /* CONFIG_CPU_FREQ_DEBUG */ | 190 | #endif /* CONFIG_CPU_FREQ_DEBUG */ |
191 | 191 | ||
192 | 192 | ||
193 | /********************************************************************* | 193 | /********************************************************************* |
194 | * EXTERNALLY AFFECTING FREQUENCY CHANGES * | 194 | * EXTERNALLY AFFECTING FREQUENCY CHANGES * |
195 | *********************************************************************/ | 195 | *********************************************************************/ |
196 | 196 | ||
197 | /** | 197 | /** |
198 | * adjust_jiffies - adjust the system "loops_per_jiffy" | 198 | * adjust_jiffies - adjust the system "loops_per_jiffy" |
199 | * | 199 | * |
200 | * This function alters the system "loops_per_jiffy" for the clock | 200 | * This function alters the system "loops_per_jiffy" for the clock |
201 | * speed change. Note that loops_per_jiffy cannot be updated on SMP | 201 | * speed change. Note that loops_per_jiffy cannot be updated on SMP |
202 | * systems as each CPU might be scaled differently. So, use the arch | 202 | * systems as each CPU might be scaled differently. So, use the arch |
203 | * per-CPU loops_per_jiffy value wherever possible. | 203 | * per-CPU loops_per_jiffy value wherever possible. |
204 | */ | 204 | */ |
205 | #ifndef CONFIG_SMP | 205 | #ifndef CONFIG_SMP |
206 | static unsigned long l_p_j_ref; | 206 | static unsigned long l_p_j_ref; |
207 | static unsigned int l_p_j_ref_freq; | 207 | static unsigned int l_p_j_ref_freq; |
208 | 208 | ||
209 | static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci) | 209 | static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci) |
210 | { | 210 | { |
211 | if (ci->flags & CPUFREQ_CONST_LOOPS) | 211 | if (ci->flags & CPUFREQ_CONST_LOOPS) |
212 | return; | 212 | return; |
213 | 213 | ||
214 | if (!l_p_j_ref_freq) { | 214 | if (!l_p_j_ref_freq) { |
215 | l_p_j_ref = loops_per_jiffy; | 215 | l_p_j_ref = loops_per_jiffy; |
216 | l_p_j_ref_freq = ci->old; | 216 | l_p_j_ref_freq = ci->old; |
217 | dprintk("saving %lu as reference value for loops_per_jiffy; freq is %u kHz\n", l_p_j_ref, l_p_j_ref_freq); | 217 | dprintk("saving %lu as reference value for loops_per_jiffy; freq is %u kHz\n", l_p_j_ref, l_p_j_ref_freq); |
218 | } | 218 | } |
219 | if ((val == CPUFREQ_PRECHANGE && ci->old < ci->new) || | 219 | if ((val == CPUFREQ_PRECHANGE && ci->old < ci->new) || |
220 | (val == CPUFREQ_POSTCHANGE && ci->old > ci->new) || | 220 | (val == CPUFREQ_POSTCHANGE && ci->old > ci->new) || |
221 | (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) { | 221 | (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) { |
222 | loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq, ci->new); | 222 | loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq, ci->new); |
223 | dprintk("scaling loops_per_jiffy to %lu for frequency %u kHz\n", loops_per_jiffy, ci->new); | 223 | dprintk("scaling loops_per_jiffy to %lu for frequency %u kHz\n", loops_per_jiffy, ci->new); |
224 | } | 224 | } |
225 | } | 225 | } |
226 | #else | 226 | #else |
227 | static inline void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci) { return; } | 227 | static inline void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci) { return; } |
228 | #endif | 228 | #endif |
229 | 229 | ||
230 | 230 | ||
231 | /** | 231 | /** |
232 | * cpufreq_notify_transition - call notifier chain and adjust_jiffies | 232 | * cpufreq_notify_transition - call notifier chain and adjust_jiffies |
233 | * on frequency transition. | 233 | * on frequency transition. |
234 | * | 234 | * |
235 | * This function calls the transition notifiers and the "adjust_jiffies" | 235 | * This function calls the transition notifiers and the "adjust_jiffies" |
236 | * function. It is called twice on all CPU frequency changes that have | 236 | * function. It is called twice on all CPU frequency changes that have |
237 | * external effects. | 237 | * external effects. |
238 | */ | 238 | */ |
239 | void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state) | 239 | void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state) |
240 | { | 240 | { |
241 | struct cpufreq_policy *policy; | 241 | struct cpufreq_policy *policy; |
242 | 242 | ||
243 | BUG_ON(irqs_disabled()); | 243 | BUG_ON(irqs_disabled()); |
244 | 244 | ||
245 | freqs->flags = cpufreq_driver->flags; | 245 | freqs->flags = cpufreq_driver->flags; |
246 | dprintk("notification %u of frequency transition to %u kHz\n", | 246 | dprintk("notification %u of frequency transition to %u kHz\n", |
247 | state, freqs->new); | 247 | state, freqs->new); |
248 | 248 | ||
249 | policy = cpufreq_cpu_data[freqs->cpu]; | 249 | policy = cpufreq_cpu_data[freqs->cpu]; |
250 | switch (state) { | 250 | switch (state) { |
251 | 251 | ||
252 | case CPUFREQ_PRECHANGE: | 252 | case CPUFREQ_PRECHANGE: |
253 | /* detect if the driver reported a value as "old frequency" | 253 | /* detect if the driver reported a value as "old frequency" |
254 | * which is not equal to what the cpufreq core thinks is | 254 | * which is not equal to what the cpufreq core thinks is |
255 | * "old frequency". | 255 | * "old frequency". |
256 | */ | 256 | */ |
257 | if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { | 257 | if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { |
258 | if ((policy) && (policy->cpu == freqs->cpu) && | 258 | if ((policy) && (policy->cpu == freqs->cpu) && |
259 | (policy->cur) && (policy->cur != freqs->old)) { | 259 | (policy->cur) && (policy->cur != freqs->old)) { |
260 | dprintk(KERN_WARNING "Warning: CPU frequency is" | 260 | dprintk(KERN_WARNING "Warning: CPU frequency is" |
261 | " %u, cpufreq assumed %u kHz.\n", | 261 | " %u, cpufreq assumed %u kHz.\n", |
262 | freqs->old, policy->cur); | 262 | freqs->old, policy->cur); |
263 | freqs->old = policy->cur; | 263 | freqs->old = policy->cur; |
264 | } | 264 | } |
265 | } | 265 | } |
266 | blocking_notifier_call_chain(&cpufreq_transition_notifier_list, | 266 | blocking_notifier_call_chain(&cpufreq_transition_notifier_list, |
267 | CPUFREQ_PRECHANGE, freqs); | 267 | CPUFREQ_PRECHANGE, freqs); |
268 | adjust_jiffies(CPUFREQ_PRECHANGE, freqs); | 268 | adjust_jiffies(CPUFREQ_PRECHANGE, freqs); |
269 | break; | 269 | break; |
270 | 270 | ||
271 | case CPUFREQ_POSTCHANGE: | 271 | case CPUFREQ_POSTCHANGE: |
272 | adjust_jiffies(CPUFREQ_POSTCHANGE, freqs); | 272 | adjust_jiffies(CPUFREQ_POSTCHANGE, freqs); |
273 | blocking_notifier_call_chain(&cpufreq_transition_notifier_list, | 273 | blocking_notifier_call_chain(&cpufreq_transition_notifier_list, |
274 | CPUFREQ_POSTCHANGE, freqs); | 274 | CPUFREQ_POSTCHANGE, freqs); |
275 | if (likely(policy) && likely(policy->cpu == freqs->cpu)) | 275 | if (likely(policy) && likely(policy->cpu == freqs->cpu)) |
276 | policy->cur = freqs->new; | 276 | policy->cur = freqs->new; |
277 | break; | 277 | break; |
278 | } | 278 | } |
279 | } | 279 | } |
280 | EXPORT_SYMBOL_GPL(cpufreq_notify_transition); | 280 | EXPORT_SYMBOL_GPL(cpufreq_notify_transition); |
281 | 281 | ||
282 | 282 | ||
283 | 283 | ||
284 | /********************************************************************* | 284 | /********************************************************************* |
285 | * SYSFS INTERFACE * | 285 | * SYSFS INTERFACE * |
286 | *********************************************************************/ | 286 | *********************************************************************/ |
287 | 287 | ||
288 | /** | 288 | /** |
289 | * cpufreq_parse_governor - parse a governor string | 289 | * cpufreq_parse_governor - parse a governor string |
290 | */ | 290 | */ |
291 | static int cpufreq_parse_governor (char *str_governor, unsigned int *policy, | 291 | static int cpufreq_parse_governor (char *str_governor, unsigned int *policy, |
292 | struct cpufreq_governor **governor) | 292 | struct cpufreq_governor **governor) |
293 | { | 293 | { |
294 | if (!cpufreq_driver) | 294 | if (!cpufreq_driver) |
295 | return -EINVAL; | 295 | return -EINVAL; |
296 | if (cpufreq_driver->setpolicy) { | 296 | if (cpufreq_driver->setpolicy) { |
297 | if (!strnicmp(str_governor, "performance", CPUFREQ_NAME_LEN)) { | 297 | if (!strnicmp(str_governor, "performance", CPUFREQ_NAME_LEN)) { |
298 | *policy = CPUFREQ_POLICY_PERFORMANCE; | 298 | *policy = CPUFREQ_POLICY_PERFORMANCE; |
299 | return 0; | 299 | return 0; |
300 | } else if (!strnicmp(str_governor, "powersave", CPUFREQ_NAME_LEN)) { | 300 | } else if (!strnicmp(str_governor, "powersave", CPUFREQ_NAME_LEN)) { |
301 | *policy = CPUFREQ_POLICY_POWERSAVE; | 301 | *policy = CPUFREQ_POLICY_POWERSAVE; |
302 | return 0; | 302 | return 0; |
303 | } | 303 | } |
304 | return -EINVAL; | 304 | return -EINVAL; |
305 | } else { | 305 | } else { |
306 | struct cpufreq_governor *t; | 306 | struct cpufreq_governor *t; |
307 | mutex_lock(&cpufreq_governor_mutex); | 307 | mutex_lock(&cpufreq_governor_mutex); |
308 | if (!cpufreq_driver || !cpufreq_driver->target) | 308 | if (!cpufreq_driver || !cpufreq_driver->target) |
309 | goto out; | 309 | goto out; |
310 | list_for_each_entry(t, &cpufreq_governor_list, governor_list) { | 310 | list_for_each_entry(t, &cpufreq_governor_list, governor_list) { |
311 | if (!strnicmp(str_governor,t->name,CPUFREQ_NAME_LEN)) { | 311 | if (!strnicmp(str_governor,t->name,CPUFREQ_NAME_LEN)) { |
312 | *governor = t; | 312 | *governor = t; |
313 | mutex_unlock(&cpufreq_governor_mutex); | 313 | mutex_unlock(&cpufreq_governor_mutex); |
314 | return 0; | 314 | return 0; |
315 | } | 315 | } |
316 | } | 316 | } |
317 | out: | 317 | out: |
318 | mutex_unlock(&cpufreq_governor_mutex); | 318 | mutex_unlock(&cpufreq_governor_mutex); |
319 | } | 319 | } |
320 | return -EINVAL; | 320 | return -EINVAL; |
321 | } | 321 | } |
322 | EXPORT_SYMBOL_GPL(cpufreq_parse_governor); | ||
323 | 322 | ||
324 | 323 | ||
325 | /* drivers/base/cpu.c */ | 324 | /* drivers/base/cpu.c */ |
326 | extern struct sysdev_class cpu_sysdev_class; | 325 | extern struct sysdev_class cpu_sysdev_class; |
327 | 326 | ||
328 | 327 | ||
329 | /** | 328 | /** |
330 | * cpufreq_per_cpu_attr_read() / show_##file_name() - print out cpufreq information | 329 | * cpufreq_per_cpu_attr_read() / show_##file_name() - print out cpufreq information |
331 | * | 330 | * |
332 | * Write out information from cpufreq_driver->policy[cpu]; object must be | 331 | * Write out information from cpufreq_driver->policy[cpu]; object must be |
333 | * "unsigned int". | 332 | * "unsigned int". |
334 | */ | 333 | */ |
335 | 334 | ||
336 | #define show_one(file_name, object) \ | 335 | #define show_one(file_name, object) \ |
337 | static ssize_t show_##file_name \ | 336 | static ssize_t show_##file_name \ |
338 | (struct cpufreq_policy * policy, char *buf) \ | 337 | (struct cpufreq_policy * policy, char *buf) \ |
339 | { \ | 338 | { \ |
340 | return sprintf (buf, "%u\n", policy->object); \ | 339 | return sprintf (buf, "%u\n", policy->object); \ |
341 | } | 340 | } |
342 | 341 | ||
343 | show_one(cpuinfo_min_freq, cpuinfo.min_freq); | 342 | show_one(cpuinfo_min_freq, cpuinfo.min_freq); |
344 | show_one(cpuinfo_max_freq, cpuinfo.max_freq); | 343 | show_one(cpuinfo_max_freq, cpuinfo.max_freq); |
345 | show_one(scaling_min_freq, min); | 344 | show_one(scaling_min_freq, min); |
346 | show_one(scaling_max_freq, max); | 345 | show_one(scaling_max_freq, max); |
347 | show_one(scaling_cur_freq, cur); | 346 | show_one(scaling_cur_freq, cur); |
348 | 347 | ||
349 | static int __cpufreq_set_policy(struct cpufreq_policy *data, struct cpufreq_policy *policy); | 348 | static int __cpufreq_set_policy(struct cpufreq_policy *data, struct cpufreq_policy *policy); |
350 | 349 | ||
351 | /** | 350 | /** |
352 | * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access | 351 | * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access |
353 | */ | 352 | */ |
354 | #define store_one(file_name, object) \ | 353 | #define store_one(file_name, object) \ |
355 | static ssize_t store_##file_name \ | 354 | static ssize_t store_##file_name \ |
356 | (struct cpufreq_policy * policy, const char *buf, size_t count) \ | 355 | (struct cpufreq_policy * policy, const char *buf, size_t count) \ |
357 | { \ | 356 | { \ |
358 | unsigned int ret = -EINVAL; \ | 357 | unsigned int ret = -EINVAL; \ |
359 | struct cpufreq_policy new_policy; \ | 358 | struct cpufreq_policy new_policy; \ |
360 | \ | 359 | \ |
361 | ret = cpufreq_get_policy(&new_policy, policy->cpu); \ | 360 | ret = cpufreq_get_policy(&new_policy, policy->cpu); \ |
362 | if (ret) \ | 361 | if (ret) \ |
363 | return -EINVAL; \ | 362 | return -EINVAL; \ |
364 | \ | 363 | \ |
365 | ret = sscanf (buf, "%u", &new_policy.object); \ | 364 | ret = sscanf (buf, "%u", &new_policy.object); \ |
366 | if (ret != 1) \ | 365 | if (ret != 1) \ |
367 | return -EINVAL; \ | 366 | return -EINVAL; \ |
368 | \ | 367 | \ |
369 | mutex_lock(&policy->lock); \ | 368 | mutex_lock(&policy->lock); \ |
370 | ret = __cpufreq_set_policy(policy, &new_policy); \ | 369 | ret = __cpufreq_set_policy(policy, &new_policy); \ |
371 | policy->user_policy.object = policy->object; \ | 370 | policy->user_policy.object = policy->object; \ |
372 | mutex_unlock(&policy->lock); \ | 371 | mutex_unlock(&policy->lock); \ |
373 | \ | 372 | \ |
374 | return ret ? ret : count; \ | 373 | return ret ? ret : count; \ |
375 | } | 374 | } |
376 | 375 | ||
377 | store_one(scaling_min_freq,min); | 376 | store_one(scaling_min_freq,min); |
378 | store_one(scaling_max_freq,max); | 377 | store_one(scaling_max_freq,max); |
379 | 378 | ||
380 | /** | 379 | /** |
381 | * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware | 380 | * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware |
382 | */ | 381 | */ |
383 | static ssize_t show_cpuinfo_cur_freq (struct cpufreq_policy * policy, char *buf) | 382 | static ssize_t show_cpuinfo_cur_freq (struct cpufreq_policy * policy, char *buf) |
384 | { | 383 | { |
385 | unsigned int cur_freq = cpufreq_get(policy->cpu); | 384 | unsigned int cur_freq = cpufreq_get(policy->cpu); |
386 | if (!cur_freq) | 385 | if (!cur_freq) |
387 | return sprintf(buf, "<unknown>"); | 386 | return sprintf(buf, "<unknown>"); |
388 | return sprintf(buf, "%u\n", cur_freq); | 387 | return sprintf(buf, "%u\n", cur_freq); |
389 | } | 388 | } |
390 | 389 | ||
391 | 390 | ||
392 | /** | 391 | /** |
393 | * show_scaling_governor - show the current policy for the specified CPU | 392 | * show_scaling_governor - show the current policy for the specified CPU |
394 | */ | 393 | */ |
395 | static ssize_t show_scaling_governor (struct cpufreq_policy * policy, char *buf) | 394 | static ssize_t show_scaling_governor (struct cpufreq_policy * policy, char *buf) |
396 | { | 395 | { |
397 | if(policy->policy == CPUFREQ_POLICY_POWERSAVE) | 396 | if(policy->policy == CPUFREQ_POLICY_POWERSAVE) |
398 | return sprintf(buf, "powersave\n"); | 397 | return sprintf(buf, "powersave\n"); |
399 | else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) | 398 | else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) |
400 | return sprintf(buf, "performance\n"); | 399 | return sprintf(buf, "performance\n"); |
401 | else if (policy->governor) | 400 | else if (policy->governor) |
402 | return scnprintf(buf, CPUFREQ_NAME_LEN, "%s\n", policy->governor->name); | 401 | return scnprintf(buf, CPUFREQ_NAME_LEN, "%s\n", policy->governor->name); |
403 | return -EINVAL; | 402 | return -EINVAL; |
404 | } | 403 | } |
405 | 404 | ||
406 | 405 | ||
407 | /** | 406 | /** |
408 | * store_scaling_governor - store policy for the specified CPU | 407 | * store_scaling_governor - store policy for the specified CPU |
409 | */ | 408 | */ |
410 | static ssize_t store_scaling_governor (struct cpufreq_policy * policy, | 409 | static ssize_t store_scaling_governor (struct cpufreq_policy * policy, |
411 | const char *buf, size_t count) | 410 | const char *buf, size_t count) |
412 | { | 411 | { |
413 | unsigned int ret = -EINVAL; | 412 | unsigned int ret = -EINVAL; |
414 | char str_governor[16]; | 413 | char str_governor[16]; |
415 | struct cpufreq_policy new_policy; | 414 | struct cpufreq_policy new_policy; |
416 | 415 | ||
417 | ret = cpufreq_get_policy(&new_policy, policy->cpu); | 416 | ret = cpufreq_get_policy(&new_policy, policy->cpu); |
418 | if (ret) | 417 | if (ret) |
419 | return ret; | 418 | return ret; |
420 | 419 | ||
421 | ret = sscanf (buf, "%15s", str_governor); | 420 | ret = sscanf (buf, "%15s", str_governor); |
422 | if (ret != 1) | 421 | if (ret != 1) |
423 | return -EINVAL; | 422 | return -EINVAL; |
424 | 423 | ||
425 | if (cpufreq_parse_governor(str_governor, &new_policy.policy, &new_policy.governor)) | 424 | if (cpufreq_parse_governor(str_governor, &new_policy.policy, &new_policy.governor)) |
426 | return -EINVAL; | 425 | return -EINVAL; |
427 | 426 | ||
428 | /* Do not use cpufreq_set_policy here or the user_policy.max | 427 | /* Do not use cpufreq_set_policy here or the user_policy.max |
429 | will be wrongly overridden */ | 428 | will be wrongly overridden */ |
430 | mutex_lock(&policy->lock); | 429 | mutex_lock(&policy->lock); |
431 | ret = __cpufreq_set_policy(policy, &new_policy); | 430 | ret = __cpufreq_set_policy(policy, &new_policy); |
432 | 431 | ||
433 | policy->user_policy.policy = policy->policy; | 432 | policy->user_policy.policy = policy->policy; |
434 | policy->user_policy.governor = policy->governor; | 433 | policy->user_policy.governor = policy->governor; |
435 | mutex_unlock(&policy->lock); | 434 | mutex_unlock(&policy->lock); |
436 | 435 | ||
437 | return ret ? ret : count; | 436 | return ret ? ret : count; |
438 | } | 437 | } |
439 | 438 | ||
440 | /** | 439 | /** |
441 | * show_scaling_driver - show the cpufreq driver currently loaded | 440 | * show_scaling_driver - show the cpufreq driver currently loaded |
442 | */ | 441 | */ |
443 | static ssize_t show_scaling_driver (struct cpufreq_policy * policy, char *buf) | 442 | static ssize_t show_scaling_driver (struct cpufreq_policy * policy, char *buf) |
444 | { | 443 | { |
445 | return scnprintf(buf, CPUFREQ_NAME_LEN, "%s\n", cpufreq_driver->name); | 444 | return scnprintf(buf, CPUFREQ_NAME_LEN, "%s\n", cpufreq_driver->name); |
446 | } | 445 | } |
447 | 446 | ||
448 | /** | 447 | /** |
449 | * show_scaling_available_governors - show the available CPUfreq governors | 448 | * show_scaling_available_governors - show the available CPUfreq governors |
450 | */ | 449 | */ |
451 | static ssize_t show_scaling_available_governors (struct cpufreq_policy * policy, | 450 | static ssize_t show_scaling_available_governors (struct cpufreq_policy * policy, |
452 | char *buf) | 451 | char *buf) |
453 | { | 452 | { |
454 | ssize_t i = 0; | 453 | ssize_t i = 0; |
455 | struct cpufreq_governor *t; | 454 | struct cpufreq_governor *t; |
456 | 455 | ||
457 | if (!cpufreq_driver->target) { | 456 | if (!cpufreq_driver->target) { |
458 | i += sprintf(buf, "performance powersave"); | 457 | i += sprintf(buf, "performance powersave"); |
459 | goto out; | 458 | goto out; |
460 | } | 459 | } |
461 | 460 | ||
462 | list_for_each_entry(t, &cpufreq_governor_list, governor_list) { | 461 | list_for_each_entry(t, &cpufreq_governor_list, governor_list) { |
463 | if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char)) - (CPUFREQ_NAME_LEN + 2))) | 462 | if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char)) - (CPUFREQ_NAME_LEN + 2))) |
464 | goto out; | 463 | goto out; |
465 | i += scnprintf(&buf[i], CPUFREQ_NAME_LEN, "%s ", t->name); | 464 | i += scnprintf(&buf[i], CPUFREQ_NAME_LEN, "%s ", t->name); |
466 | } | 465 | } |
467 | out: | 466 | out: |
468 | i += sprintf(&buf[i], "\n"); | 467 | i += sprintf(&buf[i], "\n"); |
469 | return i; | 468 | return i; |
470 | } | 469 | } |
471 | /** | 470 | /** |
472 | * show_affected_cpus - show the CPUs affected by each transition | 471 | * show_affected_cpus - show the CPUs affected by each transition |
473 | */ | 472 | */ |
474 | static ssize_t show_affected_cpus (struct cpufreq_policy * policy, char *buf) | 473 | static ssize_t show_affected_cpus (struct cpufreq_policy * policy, char *buf) |
475 | { | 474 | { |
476 | ssize_t i = 0; | 475 | ssize_t i = 0; |
477 | unsigned int cpu; | 476 | unsigned int cpu; |
478 | 477 | ||
479 | for_each_cpu_mask(cpu, policy->cpus) { | 478 | for_each_cpu_mask(cpu, policy->cpus) { |
480 | if (i) | 479 | if (i) |
481 | i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " "); | 480 | i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " "); |
482 | i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu); | 481 | i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu); |
483 | if (i >= (PAGE_SIZE - 5)) | 482 | if (i >= (PAGE_SIZE - 5)) |
484 | break; | 483 | break; |
485 | } | 484 | } |
486 | i += sprintf(&buf[i], "\n"); | 485 | i += sprintf(&buf[i], "\n"); |
487 | return i; | 486 | return i; |
488 | } | 487 | } |
489 | 488 | ||
490 | 489 | ||
491 | #define define_one_ro(_name) \ | 490 | #define define_one_ro(_name) \ |
492 | static struct freq_attr _name = \ | 491 | static struct freq_attr _name = \ |
493 | __ATTR(_name, 0444, show_##_name, NULL) | 492 | __ATTR(_name, 0444, show_##_name, NULL) |
494 | 493 | ||
495 | #define define_one_ro0400(_name) \ | 494 | #define define_one_ro0400(_name) \ |
496 | static struct freq_attr _name = \ | 495 | static struct freq_attr _name = \ |
497 | __ATTR(_name, 0400, show_##_name, NULL) | 496 | __ATTR(_name, 0400, show_##_name, NULL) |
498 | 497 | ||
499 | #define define_one_rw(_name) \ | 498 | #define define_one_rw(_name) \ |
500 | static struct freq_attr _name = \ | 499 | static struct freq_attr _name = \ |
501 | __ATTR(_name, 0644, show_##_name, store_##_name) | 500 | __ATTR(_name, 0644, show_##_name, store_##_name) |
502 | 501 | ||
503 | define_one_ro0400(cpuinfo_cur_freq); | 502 | define_one_ro0400(cpuinfo_cur_freq); |
504 | define_one_ro(cpuinfo_min_freq); | 503 | define_one_ro(cpuinfo_min_freq); |
505 | define_one_ro(cpuinfo_max_freq); | 504 | define_one_ro(cpuinfo_max_freq); |
506 | define_one_ro(scaling_available_governors); | 505 | define_one_ro(scaling_available_governors); |
507 | define_one_ro(scaling_driver); | 506 | define_one_ro(scaling_driver); |
508 | define_one_ro(scaling_cur_freq); | 507 | define_one_ro(scaling_cur_freq); |
509 | define_one_ro(affected_cpus); | 508 | define_one_ro(affected_cpus); |
510 | define_one_rw(scaling_min_freq); | 509 | define_one_rw(scaling_min_freq); |
511 | define_one_rw(scaling_max_freq); | 510 | define_one_rw(scaling_max_freq); |
512 | define_one_rw(scaling_governor); | 511 | define_one_rw(scaling_governor); |
513 | 512 | ||
514 | static struct attribute * default_attrs[] = { | 513 | static struct attribute * default_attrs[] = { |
515 | &cpuinfo_min_freq.attr, | 514 | &cpuinfo_min_freq.attr, |
516 | &cpuinfo_max_freq.attr, | 515 | &cpuinfo_max_freq.attr, |
517 | &scaling_min_freq.attr, | 516 | &scaling_min_freq.attr, |
518 | &scaling_max_freq.attr, | 517 | &scaling_max_freq.attr, |
519 | &affected_cpus.attr, | 518 | &affected_cpus.attr, |
520 | &scaling_governor.attr, | 519 | &scaling_governor.attr, |
521 | &scaling_driver.attr, | 520 | &scaling_driver.attr, |
522 | &scaling_available_governors.attr, | 521 | &scaling_available_governors.attr, |
523 | NULL | 522 | NULL |
524 | }; | 523 | }; |
525 | 524 | ||
526 | #define to_policy(k) container_of(k,struct cpufreq_policy,kobj) | 525 | #define to_policy(k) container_of(k,struct cpufreq_policy,kobj) |
527 | #define to_attr(a) container_of(a,struct freq_attr,attr) | 526 | #define to_attr(a) container_of(a,struct freq_attr,attr) |
528 | 527 | ||
529 | static ssize_t show(struct kobject * kobj, struct attribute * attr ,char * buf) | 528 | static ssize_t show(struct kobject * kobj, struct attribute * attr ,char * buf) |
530 | { | 529 | { |
531 | struct cpufreq_policy * policy = to_policy(kobj); | 530 | struct cpufreq_policy * policy = to_policy(kobj); |
532 | struct freq_attr * fattr = to_attr(attr); | 531 | struct freq_attr * fattr = to_attr(attr); |
533 | ssize_t ret; | 532 | ssize_t ret; |
534 | policy = cpufreq_cpu_get(policy->cpu); | 533 | policy = cpufreq_cpu_get(policy->cpu); |
535 | if (!policy) | 534 | if (!policy) |
536 | return -EINVAL; | 535 | return -EINVAL; |
537 | ret = fattr->show ? fattr->show(policy,buf) : -EIO; | 536 | ret = fattr->show ? fattr->show(policy,buf) : -EIO; |
538 | cpufreq_cpu_put(policy); | 537 | cpufreq_cpu_put(policy); |
539 | return ret; | 538 | return ret; |
540 | } | 539 | } |
541 | 540 | ||
542 | static ssize_t store(struct kobject * kobj, struct attribute * attr, | 541 | static ssize_t store(struct kobject * kobj, struct attribute * attr, |
543 | const char * buf, size_t count) | 542 | const char * buf, size_t count) |
544 | { | 543 | { |
545 | struct cpufreq_policy * policy = to_policy(kobj); | 544 | struct cpufreq_policy * policy = to_policy(kobj); |
546 | struct freq_attr * fattr = to_attr(attr); | 545 | struct freq_attr * fattr = to_attr(attr); |
547 | ssize_t ret; | 546 | ssize_t ret; |
548 | policy = cpufreq_cpu_get(policy->cpu); | 547 | policy = cpufreq_cpu_get(policy->cpu); |
549 | if (!policy) | 548 | if (!policy) |
550 | return -EINVAL; | 549 | return -EINVAL; |
551 | ret = fattr->store ? fattr->store(policy,buf,count) : -EIO; | 550 | ret = fattr->store ? fattr->store(policy,buf,count) : -EIO; |
552 | cpufreq_cpu_put(policy); | 551 | cpufreq_cpu_put(policy); |
553 | return ret; | 552 | return ret; |
554 | } | 553 | } |
555 | 554 | ||
556 | static void cpufreq_sysfs_release(struct kobject * kobj) | 555 | static void cpufreq_sysfs_release(struct kobject * kobj) |
557 | { | 556 | { |
558 | struct cpufreq_policy * policy = to_policy(kobj); | 557 | struct cpufreq_policy * policy = to_policy(kobj); |
559 | dprintk("last reference is dropped\n"); | 558 | dprintk("last reference is dropped\n"); |
560 | complete(&policy->kobj_unregister); | 559 | complete(&policy->kobj_unregister); |
561 | } | 560 | } |
562 | 561 | ||
563 | static struct sysfs_ops sysfs_ops = { | 562 | static struct sysfs_ops sysfs_ops = { |
564 | .show = show, | 563 | .show = show, |
565 | .store = store, | 564 | .store = store, |
566 | }; | 565 | }; |
567 | 566 | ||
568 | static struct kobj_type ktype_cpufreq = { | 567 | static struct kobj_type ktype_cpufreq = { |
569 | .sysfs_ops = &sysfs_ops, | 568 | .sysfs_ops = &sysfs_ops, |
570 | .default_attrs = default_attrs, | 569 | .default_attrs = default_attrs, |
571 | .release = cpufreq_sysfs_release, | 570 | .release = cpufreq_sysfs_release, |
572 | }; | 571 | }; |
573 | 572 | ||
574 | 573 | ||
575 | /** | 574 | /** |
576 | * cpufreq_add_dev - add a CPU device | 575 | * cpufreq_add_dev - add a CPU device |
577 | * | 576 | * |
578 | * Adds the cpufreq interface for a CPU device. | 577 | * Adds the cpufreq interface for a CPU device. |
579 | */ | 578 | */ |
580 | static int cpufreq_add_dev (struct sys_device * sys_dev) | 579 | static int cpufreq_add_dev (struct sys_device * sys_dev) |
581 | { | 580 | { |
582 | unsigned int cpu = sys_dev->id; | 581 | unsigned int cpu = sys_dev->id; |
583 | int ret = 0; | 582 | int ret = 0; |
584 | struct cpufreq_policy new_policy; | 583 | struct cpufreq_policy new_policy; |
585 | struct cpufreq_policy *policy; | 584 | struct cpufreq_policy *policy; |
586 | struct freq_attr **drv_attr; | 585 | struct freq_attr **drv_attr; |
587 | struct sys_device *cpu_sys_dev; | 586 | struct sys_device *cpu_sys_dev; |
588 | unsigned long flags; | 587 | unsigned long flags; |
589 | unsigned int j; | 588 | unsigned int j; |
590 | #ifdef CONFIG_SMP | 589 | #ifdef CONFIG_SMP |
591 | struct cpufreq_policy *managed_policy; | 590 | struct cpufreq_policy *managed_policy; |
592 | #endif | 591 | #endif |
593 | 592 | ||
594 | if (cpu_is_offline(cpu)) | 593 | if (cpu_is_offline(cpu)) |
595 | return 0; | 594 | return 0; |
596 | 595 | ||
597 | cpufreq_debug_disable_ratelimit(); | 596 | cpufreq_debug_disable_ratelimit(); |
598 | dprintk("adding CPU %u\n", cpu); | 597 | dprintk("adding CPU %u\n", cpu); |
599 | 598 | ||
600 | #ifdef CONFIG_SMP | 599 | #ifdef CONFIG_SMP |
601 | /* check whether a different CPU already registered this | 600 | /* check whether a different CPU already registered this |
602 | * CPU because it is in the same boat. */ | 601 | * CPU because it is in the same boat. */ |
603 | policy = cpufreq_cpu_get(cpu); | 602 | policy = cpufreq_cpu_get(cpu); |
604 | if (unlikely(policy)) { | 603 | if (unlikely(policy)) { |
605 | cpufreq_cpu_put(policy); | 604 | cpufreq_cpu_put(policy); |
606 | cpufreq_debug_enable_ratelimit(); | 605 | cpufreq_debug_enable_ratelimit(); |
607 | return 0; | 606 | return 0; |
608 | } | 607 | } |
609 | #endif | 608 | #endif |
610 | 609 | ||
611 | if (!try_module_get(cpufreq_driver->owner)) { | 610 | if (!try_module_get(cpufreq_driver->owner)) { |
612 | ret = -EINVAL; | 611 | ret = -EINVAL; |
613 | goto module_out; | 612 | goto module_out; |
614 | } | 613 | } |
615 | 614 | ||
616 | policy = kzalloc(sizeof(struct cpufreq_policy), GFP_KERNEL); | 615 | policy = kzalloc(sizeof(struct cpufreq_policy), GFP_KERNEL); |
617 | if (!policy) { | 616 | if (!policy) { |
618 | ret = -ENOMEM; | 617 | ret = -ENOMEM; |
619 | goto nomem_out; | 618 | goto nomem_out; |
620 | } | 619 | } |
621 | 620 | ||
622 | policy->cpu = cpu; | 621 | policy->cpu = cpu; |
623 | policy->cpus = cpumask_of_cpu(cpu); | 622 | policy->cpus = cpumask_of_cpu(cpu); |
624 | 623 | ||
625 | mutex_init(&policy->lock); | 624 | mutex_init(&policy->lock); |
626 | mutex_lock(&policy->lock); | 625 | mutex_lock(&policy->lock); |
627 | init_completion(&policy->kobj_unregister); | 626 | init_completion(&policy->kobj_unregister); |
628 | INIT_WORK(&policy->update, handle_update, (void *)(long)cpu); | 627 | INIT_WORK(&policy->update, handle_update, (void *)(long)cpu); |
629 | 628 | ||
630 | /* call driver. From then on the cpufreq must be able | 629 | /* call driver. From then on the cpufreq must be able |
631 | * to accept all calls to ->verify and ->setpolicy for this CPU | 630 | * to accept all calls to ->verify and ->setpolicy for this CPU |
632 | */ | 631 | */ |
633 | ret = cpufreq_driver->init(policy); | 632 | ret = cpufreq_driver->init(policy); |
634 | if (ret) { | 633 | if (ret) { |
635 | dprintk("initialization failed\n"); | 634 | dprintk("initialization failed\n"); |
636 | mutex_unlock(&policy->lock); | 635 | mutex_unlock(&policy->lock); |
637 | goto err_out; | 636 | goto err_out; |
638 | } | 637 | } |
639 | 638 | ||
640 | #ifdef CONFIG_SMP | 639 | #ifdef CONFIG_SMP |
641 | for_each_cpu_mask(j, policy->cpus) { | 640 | for_each_cpu_mask(j, policy->cpus) { |
642 | if (cpu == j) | 641 | if (cpu == j) |
643 | continue; | 642 | continue; |
644 | 643 | ||
645 | /* check for existing affected CPUs. They may not be aware | 644 | /* check for existing affected CPUs. They may not be aware |
646 | * of it due to CPU Hotplug. | 645 | * of it due to CPU Hotplug. |
647 | */ | 646 | */ |
648 | managed_policy = cpufreq_cpu_get(j); | 647 | managed_policy = cpufreq_cpu_get(j); |
649 | if (unlikely(managed_policy)) { | 648 | if (unlikely(managed_policy)) { |
650 | spin_lock_irqsave(&cpufreq_driver_lock, flags); | 649 | spin_lock_irqsave(&cpufreq_driver_lock, flags); |
651 | managed_policy->cpus = policy->cpus; | 650 | managed_policy->cpus = policy->cpus; |
652 | cpufreq_cpu_data[cpu] = managed_policy; | 651 | cpufreq_cpu_data[cpu] = managed_policy; |
653 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 652 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
654 | 653 | ||
655 | dprintk("CPU already managed, adding link\n"); | 654 | dprintk("CPU already managed, adding link\n"); |
656 | sysfs_create_link(&sys_dev->kobj, | 655 | sysfs_create_link(&sys_dev->kobj, |
657 | &managed_policy->kobj, "cpufreq"); | 656 | &managed_policy->kobj, "cpufreq"); |
658 | 657 | ||
659 | cpufreq_debug_enable_ratelimit(); | 658 | cpufreq_debug_enable_ratelimit(); |
660 | mutex_unlock(&policy->lock); | 659 | mutex_unlock(&policy->lock); |
661 | ret = 0; | 660 | ret = 0; |
662 | goto err_out_driver_exit; /* call driver->exit() */ | 661 | goto err_out_driver_exit; /* call driver->exit() */ |
663 | } | 662 | } |
664 | } | 663 | } |
665 | #endif | 664 | #endif |
666 | memcpy(&new_policy, policy, sizeof(struct cpufreq_policy)); | 665 | memcpy(&new_policy, policy, sizeof(struct cpufreq_policy)); |
667 | 666 | ||
668 | /* prepare interface data */ | 667 | /* prepare interface data */ |
669 | policy->kobj.parent = &sys_dev->kobj; | 668 | policy->kobj.parent = &sys_dev->kobj; |
670 | policy->kobj.ktype = &ktype_cpufreq; | 669 | policy->kobj.ktype = &ktype_cpufreq; |
671 | strlcpy(policy->kobj.name, "cpufreq", KOBJ_NAME_LEN); | 670 | strlcpy(policy->kobj.name, "cpufreq", KOBJ_NAME_LEN); |
672 | 671 | ||
673 | ret = kobject_register(&policy->kobj); | 672 | ret = kobject_register(&policy->kobj); |
674 | if (ret) { | 673 | if (ret) { |
675 | mutex_unlock(&policy->lock); | 674 | mutex_unlock(&policy->lock); |
676 | goto err_out_driver_exit; | 675 | goto err_out_driver_exit; |
677 | } | 676 | } |
678 | /* set up files for this cpu device */ | 677 | /* set up files for this cpu device */ |
679 | drv_attr = cpufreq_driver->attr; | 678 | drv_attr = cpufreq_driver->attr; |
680 | while ((drv_attr) && (*drv_attr)) { | 679 | while ((drv_attr) && (*drv_attr)) { |
681 | sysfs_create_file(&policy->kobj, &((*drv_attr)->attr)); | 680 | sysfs_create_file(&policy->kobj, &((*drv_attr)->attr)); |
682 | drv_attr++; | 681 | drv_attr++; |
683 | } | 682 | } |
684 | if (cpufreq_driver->get) | 683 | if (cpufreq_driver->get) |
685 | sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr); | 684 | sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr); |
686 | if (cpufreq_driver->target) | 685 | if (cpufreq_driver->target) |
687 | sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr); | 686 | sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr); |
688 | 687 | ||
689 | spin_lock_irqsave(&cpufreq_driver_lock, flags); | 688 | spin_lock_irqsave(&cpufreq_driver_lock, flags); |
690 | for_each_cpu_mask(j, policy->cpus) | 689 | for_each_cpu_mask(j, policy->cpus) |
691 | cpufreq_cpu_data[j] = policy; | 690 | cpufreq_cpu_data[j] = policy; |
692 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 691 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
693 | 692 | ||
694 | /* symlink affected CPUs */ | 693 | /* symlink affected CPUs */ |
695 | for_each_cpu_mask(j, policy->cpus) { | 694 | for_each_cpu_mask(j, policy->cpus) { |
696 | if (j == cpu) | 695 | if (j == cpu) |
697 | continue; | 696 | continue; |
698 | if (!cpu_online(j)) | 697 | if (!cpu_online(j)) |
699 | continue; | 698 | continue; |
700 | 699 | ||
701 | dprintk("CPU %u already managed, adding link\n", j); | 700 | dprintk("CPU %u already managed, adding link\n", j); |
702 | cpufreq_cpu_get(cpu); | 701 | cpufreq_cpu_get(cpu); |
703 | cpu_sys_dev = get_cpu_sysdev(j); | 702 | cpu_sys_dev = get_cpu_sysdev(j); |
704 | sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj, | 703 | sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj, |
705 | "cpufreq"); | 704 | "cpufreq"); |
706 | } | 705 | } |
707 | 706 | ||
708 | policy->governor = NULL; /* to assure that the starting sequence is | 707 | policy->governor = NULL; /* to assure that the starting sequence is |
709 | * run in cpufreq_set_policy */ | 708 | * run in cpufreq_set_policy */ |
710 | mutex_unlock(&policy->lock); | 709 | mutex_unlock(&policy->lock); |
711 | 710 | ||
712 | /* set default policy */ | 711 | /* set default policy */ |
713 | ret = cpufreq_set_policy(&new_policy); | 712 | ret = cpufreq_set_policy(&new_policy); |
714 | if (ret) { | 713 | if (ret) { |
715 | dprintk("setting policy failed\n"); | 714 | dprintk("setting policy failed\n"); |
716 | goto err_out_unregister; | 715 | goto err_out_unregister; |
717 | } | 716 | } |
718 | 717 | ||
719 | module_put(cpufreq_driver->owner); | 718 | module_put(cpufreq_driver->owner); |
720 | dprintk("initialization complete\n"); | 719 | dprintk("initialization complete\n"); |
721 | cpufreq_debug_enable_ratelimit(); | 720 | cpufreq_debug_enable_ratelimit(); |
722 | 721 | ||
723 | return 0; | 722 | return 0; |
724 | 723 | ||
725 | 724 | ||
726 | err_out_unregister: | 725 | err_out_unregister: |
727 | spin_lock_irqsave(&cpufreq_driver_lock, flags); | 726 | spin_lock_irqsave(&cpufreq_driver_lock, flags); |
728 | for_each_cpu_mask(j, policy->cpus) | 727 | for_each_cpu_mask(j, policy->cpus) |
729 | cpufreq_cpu_data[j] = NULL; | 728 | cpufreq_cpu_data[j] = NULL; |
730 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 729 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
731 | 730 | ||
732 | kobject_unregister(&policy->kobj); | 731 | kobject_unregister(&policy->kobj); |
733 | wait_for_completion(&policy->kobj_unregister); | 732 | wait_for_completion(&policy->kobj_unregister); |
734 | 733 | ||
735 | err_out_driver_exit: | 734 | err_out_driver_exit: |
736 | if (cpufreq_driver->exit) | 735 | if (cpufreq_driver->exit) |
737 | cpufreq_driver->exit(policy); | 736 | cpufreq_driver->exit(policy); |
738 | 737 | ||
739 | err_out: | 738 | err_out: |
740 | kfree(policy); | 739 | kfree(policy); |
741 | 740 | ||
742 | nomem_out: | 741 | nomem_out: |
743 | module_put(cpufreq_driver->owner); | 742 | module_put(cpufreq_driver->owner); |
744 | module_out: | 743 | module_out: |
745 | cpufreq_debug_enable_ratelimit(); | 744 | cpufreq_debug_enable_ratelimit(); |
746 | return ret; | 745 | return ret; |
747 | } | 746 | } |
748 | 747 | ||
749 | 748 | ||
750 | /** | 749 | /** |
751 | * cpufreq_remove_dev - remove a CPU device | 750 | * cpufreq_remove_dev - remove a CPU device |
752 | * | 751 | * |
753 | * Removes the cpufreq interface for a CPU device. | 752 | * Removes the cpufreq interface for a CPU device. |
754 | */ | 753 | */ |
755 | static int cpufreq_remove_dev (struct sys_device * sys_dev) | 754 | static int cpufreq_remove_dev (struct sys_device * sys_dev) |
756 | { | 755 | { |
757 | unsigned int cpu = sys_dev->id; | 756 | unsigned int cpu = sys_dev->id; |
758 | unsigned long flags; | 757 | unsigned long flags; |
759 | struct cpufreq_policy *data; | 758 | struct cpufreq_policy *data; |
760 | #ifdef CONFIG_SMP | 759 | #ifdef CONFIG_SMP |
761 | struct sys_device *cpu_sys_dev; | 760 | struct sys_device *cpu_sys_dev; |
762 | unsigned int j; | 761 | unsigned int j; |
763 | #endif | 762 | #endif |
764 | 763 | ||
765 | cpufreq_debug_disable_ratelimit(); | 764 | cpufreq_debug_disable_ratelimit(); |
766 | dprintk("unregistering CPU %u\n", cpu); | 765 | dprintk("unregistering CPU %u\n", cpu); |
767 | 766 | ||
768 | spin_lock_irqsave(&cpufreq_driver_lock, flags); | 767 | spin_lock_irqsave(&cpufreq_driver_lock, flags); |
769 | data = cpufreq_cpu_data[cpu]; | 768 | data = cpufreq_cpu_data[cpu]; |
770 | 769 | ||
771 | if (!data) { | 770 | if (!data) { |
772 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 771 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
773 | cpufreq_debug_enable_ratelimit(); | 772 | cpufreq_debug_enable_ratelimit(); |
774 | return -EINVAL; | 773 | return -EINVAL; |
775 | } | 774 | } |
776 | cpufreq_cpu_data[cpu] = NULL; | 775 | cpufreq_cpu_data[cpu] = NULL; |
777 | 776 | ||
778 | 777 | ||
779 | #ifdef CONFIG_SMP | 778 | #ifdef CONFIG_SMP |
780 | /* if this isn't the CPU which is the parent of the kobj, we | 779 | /* if this isn't the CPU which is the parent of the kobj, we |
781 | * only need to unlink, put and exit | 780 | * only need to unlink, put and exit |
782 | */ | 781 | */ |
783 | if (unlikely(cpu != data->cpu)) { | 782 | if (unlikely(cpu != data->cpu)) { |
784 | dprintk("removing link\n"); | 783 | dprintk("removing link\n"); |
785 | cpu_clear(cpu, data->cpus); | 784 | cpu_clear(cpu, data->cpus); |
786 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 785 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
787 | sysfs_remove_link(&sys_dev->kobj, "cpufreq"); | 786 | sysfs_remove_link(&sys_dev->kobj, "cpufreq"); |
788 | cpufreq_cpu_put(data); | 787 | cpufreq_cpu_put(data); |
789 | cpufreq_debug_enable_ratelimit(); | 788 | cpufreq_debug_enable_ratelimit(); |
790 | return 0; | 789 | return 0; |
791 | } | 790 | } |
792 | #endif | 791 | #endif |
793 | 792 | ||
794 | 793 | ||
795 | if (!kobject_get(&data->kobj)) { | 794 | if (!kobject_get(&data->kobj)) { |
796 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 795 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
797 | cpufreq_debug_enable_ratelimit(); | 796 | cpufreq_debug_enable_ratelimit(); |
798 | return -EFAULT; | 797 | return -EFAULT; |
799 | } | 798 | } |
800 | 799 | ||
801 | #ifdef CONFIG_SMP | 800 | #ifdef CONFIG_SMP |
802 | /* if we have other CPUs still registered, we need to unlink them, | 801 | /* if we have other CPUs still registered, we need to unlink them, |
803 | * or else wait_for_completion below will lock up. Clean the | 802 | * or else wait_for_completion below will lock up. Clean the |
804 | * cpufreq_cpu_data[] while holding the lock, and remove the sysfs | 803 | * cpufreq_cpu_data[] while holding the lock, and remove the sysfs |
805 | * links afterwards. | 804 | * links afterwards. |
806 | */ | 805 | */ |
807 | if (unlikely(cpus_weight(data->cpus) > 1)) { | 806 | if (unlikely(cpus_weight(data->cpus) > 1)) { |
808 | for_each_cpu_mask(j, data->cpus) { | 807 | for_each_cpu_mask(j, data->cpus) { |
809 | if (j == cpu) | 808 | if (j == cpu) |
810 | continue; | 809 | continue; |
811 | cpufreq_cpu_data[j] = NULL; | 810 | cpufreq_cpu_data[j] = NULL; |
812 | } | 811 | } |
813 | } | 812 | } |
814 | 813 | ||
815 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 814 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
816 | 815 | ||
817 | if (unlikely(cpus_weight(data->cpus) > 1)) { | 816 | if (unlikely(cpus_weight(data->cpus) > 1)) { |
818 | for_each_cpu_mask(j, data->cpus) { | 817 | for_each_cpu_mask(j, data->cpus) { |
819 | if (j == cpu) | 818 | if (j == cpu) |
820 | continue; | 819 | continue; |
821 | dprintk("removing link for cpu %u\n", j); | 820 | dprintk("removing link for cpu %u\n", j); |
822 | cpu_sys_dev = get_cpu_sysdev(j); | 821 | cpu_sys_dev = get_cpu_sysdev(j); |
823 | sysfs_remove_link(&cpu_sys_dev->kobj, "cpufreq"); | 822 | sysfs_remove_link(&cpu_sys_dev->kobj, "cpufreq"); |
824 | cpufreq_cpu_put(data); | 823 | cpufreq_cpu_put(data); |
825 | } | 824 | } |
826 | } | 825 | } |
827 | #else | 826 | #else |
828 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 827 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
829 | #endif | 828 | #endif |
830 | 829 | ||
831 | mutex_lock(&data->lock); | 830 | mutex_lock(&data->lock); |
832 | if (cpufreq_driver->target) | 831 | if (cpufreq_driver->target) |
833 | __cpufreq_governor(data, CPUFREQ_GOV_STOP); | 832 | __cpufreq_governor(data, CPUFREQ_GOV_STOP); |
834 | mutex_unlock(&data->lock); | 833 | mutex_unlock(&data->lock); |
835 | 834 | ||
836 | kobject_unregister(&data->kobj); | 835 | kobject_unregister(&data->kobj); |
837 | 836 | ||
838 | kobject_put(&data->kobj); | 837 | kobject_put(&data->kobj); |
839 | 838 | ||
840 | /* we need to make sure that the underlying kobj is actually | 839 | /* we need to make sure that the underlying kobj is actually |
841 | * not referenced anymore by anybody before we proceed with | 840 | * not referenced anymore by anybody before we proceed with |
842 | * unloading. | 841 | * unloading. |
843 | */ | 842 | */ |
844 | dprintk("waiting for dropping of refcount\n"); | 843 | dprintk("waiting for dropping of refcount\n"); |
845 | wait_for_completion(&data->kobj_unregister); | 844 | wait_for_completion(&data->kobj_unregister); |
846 | dprintk("wait complete\n"); | 845 | dprintk("wait complete\n"); |
847 | 846 | ||
848 | if (cpufreq_driver->exit) | 847 | if (cpufreq_driver->exit) |
849 | cpufreq_driver->exit(data); | 848 | cpufreq_driver->exit(data); |
850 | 849 | ||
851 | kfree(data); | 850 | kfree(data); |
852 | 851 | ||
853 | cpufreq_debug_enable_ratelimit(); | 852 | cpufreq_debug_enable_ratelimit(); |
854 | return 0; | 853 | return 0; |
855 | } | 854 | } |
856 | 855 | ||
857 | 856 | ||
858 | static void handle_update(void *data) | 857 | static void handle_update(void *data) |
859 | { | 858 | { |
860 | unsigned int cpu = (unsigned int)(long)data; | 859 | unsigned int cpu = (unsigned int)(long)data; |
861 | dprintk("handle_update for cpu %u called\n", cpu); | 860 | dprintk("handle_update for cpu %u called\n", cpu); |
862 | cpufreq_update_policy(cpu); | 861 | cpufreq_update_policy(cpu); |
863 | } | 862 | } |
864 | 863 | ||
865 | /** | 864 | /** |
866 | * cpufreq_out_of_sync - If actual and saved CPU frequency differs, we're in deep trouble. | 865 | * cpufreq_out_of_sync - If actual and saved CPU frequency differs, we're in deep trouble. |
867 | * @cpu: cpu number | 866 | * @cpu: cpu number |
868 | * @old_freq: CPU frequency the kernel thinks the CPU runs at | 867 | * @old_freq: CPU frequency the kernel thinks the CPU runs at |
869 | * @new_freq: CPU frequency the CPU actually runs at | 868 | * @new_freq: CPU frequency the CPU actually runs at |
870 | * | 869 | * |
871 | * We adjust to current frequency first, and need to clean up later. So either call | 870 | * We adjust to current frequency first, and need to clean up later. So either call |
872 | * to cpufreq_update_policy() or schedule handle_update()). | 871 | * to cpufreq_update_policy() or schedule handle_update()). |
873 | */ | 872 | */ |
874 | static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq, unsigned int new_freq) | 873 | static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq, unsigned int new_freq) |
875 | { | 874 | { |
876 | struct cpufreq_freqs freqs; | 875 | struct cpufreq_freqs freqs; |
877 | 876 | ||
878 | dprintk(KERN_WARNING "Warning: CPU frequency out of sync: cpufreq and timing " | 877 | dprintk(KERN_WARNING "Warning: CPU frequency out of sync: cpufreq and timing " |
879 | "core thinks of %u, is %u kHz.\n", old_freq, new_freq); | 878 | "core thinks of %u, is %u kHz.\n", old_freq, new_freq); |
880 | 879 | ||
881 | freqs.cpu = cpu; | 880 | freqs.cpu = cpu; |
882 | freqs.old = old_freq; | 881 | freqs.old = old_freq; |
883 | freqs.new = new_freq; | 882 | freqs.new = new_freq; |
884 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); | 883 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); |
885 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); | 884 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); |
886 | } | 885 | } |
887 | 886 | ||
888 | 887 | ||
889 | /** | 888 | /** |
890 | * cpufreq_quick_get - get the CPU frequency (in kHz) frpm policy->cur | 889 | * cpufreq_quick_get - get the CPU frequency (in kHz) frpm policy->cur |
891 | * @cpu: CPU number | 890 | * @cpu: CPU number |
892 | * | 891 | * |
893 | * This is the last known freq, without actually getting it from the driver. | 892 | * This is the last known freq, without actually getting it from the driver. |
894 | * Return value will be same as what is shown in scaling_cur_freq in sysfs. | 893 | * Return value will be same as what is shown in scaling_cur_freq in sysfs. |
895 | */ | 894 | */ |
896 | unsigned int cpufreq_quick_get(unsigned int cpu) | 895 | unsigned int cpufreq_quick_get(unsigned int cpu) |
897 | { | 896 | { |
898 | struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); | 897 | struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); |
899 | unsigned int ret = 0; | 898 | unsigned int ret = 0; |
900 | 899 | ||
901 | if (policy) { | 900 | if (policy) { |
902 | mutex_lock(&policy->lock); | 901 | mutex_lock(&policy->lock); |
903 | ret = policy->cur; | 902 | ret = policy->cur; |
904 | mutex_unlock(&policy->lock); | 903 | mutex_unlock(&policy->lock); |
905 | cpufreq_cpu_put(policy); | 904 | cpufreq_cpu_put(policy); |
906 | } | 905 | } |
907 | 906 | ||
908 | return (ret); | 907 | return (ret); |
909 | } | 908 | } |
910 | EXPORT_SYMBOL(cpufreq_quick_get); | 909 | EXPORT_SYMBOL(cpufreq_quick_get); |
911 | 910 | ||
912 | 911 | ||
913 | /** | 912 | /** |
914 | * cpufreq_get - get the current CPU frequency (in kHz) | 913 | * cpufreq_get - get the current CPU frequency (in kHz) |
915 | * @cpu: CPU number | 914 | * @cpu: CPU number |
916 | * | 915 | * |
917 | * Get the CPU current (static) CPU frequency | 916 | * Get the CPU current (static) CPU frequency |
918 | */ | 917 | */ |
919 | unsigned int cpufreq_get(unsigned int cpu) | 918 | unsigned int cpufreq_get(unsigned int cpu) |
920 | { | 919 | { |
921 | struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); | 920 | struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); |
922 | unsigned int ret = 0; | 921 | unsigned int ret = 0; |
923 | 922 | ||
924 | if (!policy) | 923 | if (!policy) |
925 | return 0; | 924 | return 0; |
926 | 925 | ||
927 | if (!cpufreq_driver->get) | 926 | if (!cpufreq_driver->get) |
928 | goto out; | 927 | goto out; |
929 | 928 | ||
930 | mutex_lock(&policy->lock); | 929 | mutex_lock(&policy->lock); |
931 | 930 | ||
932 | ret = cpufreq_driver->get(cpu); | 931 | ret = cpufreq_driver->get(cpu); |
933 | 932 | ||
934 | if (ret && policy->cur && !(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { | 933 | if (ret && policy->cur && !(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { |
935 | /* verify no discrepancy between actual and saved value exists */ | 934 | /* verify no discrepancy between actual and saved value exists */ |
936 | if (unlikely(ret != policy->cur)) { | 935 | if (unlikely(ret != policy->cur)) { |
937 | cpufreq_out_of_sync(cpu, policy->cur, ret); | 936 | cpufreq_out_of_sync(cpu, policy->cur, ret); |
938 | schedule_work(&policy->update); | 937 | schedule_work(&policy->update); |
939 | } | 938 | } |
940 | } | 939 | } |
941 | 940 | ||
942 | mutex_unlock(&policy->lock); | 941 | mutex_unlock(&policy->lock); |
943 | 942 | ||
944 | out: | 943 | out: |
945 | cpufreq_cpu_put(policy); | 944 | cpufreq_cpu_put(policy); |
946 | 945 | ||
947 | return (ret); | 946 | return (ret); |
948 | } | 947 | } |
949 | EXPORT_SYMBOL(cpufreq_get); | 948 | EXPORT_SYMBOL(cpufreq_get); |
950 | 949 | ||
951 | 950 | ||
952 | /** | 951 | /** |
953 | * cpufreq_suspend - let the low level driver prepare for suspend | 952 | * cpufreq_suspend - let the low level driver prepare for suspend |
954 | */ | 953 | */ |
955 | 954 | ||
956 | static int cpufreq_suspend(struct sys_device * sysdev, pm_message_t pmsg) | 955 | static int cpufreq_suspend(struct sys_device * sysdev, pm_message_t pmsg) |
957 | { | 956 | { |
958 | int cpu = sysdev->id; | 957 | int cpu = sysdev->id; |
959 | unsigned int ret = 0; | 958 | unsigned int ret = 0; |
960 | unsigned int cur_freq = 0; | 959 | unsigned int cur_freq = 0; |
961 | struct cpufreq_policy *cpu_policy; | 960 | struct cpufreq_policy *cpu_policy; |
962 | 961 | ||
963 | dprintk("resuming cpu %u\n", cpu); | 962 | dprintk("resuming cpu %u\n", cpu); |
964 | 963 | ||
965 | if (!cpu_online(cpu)) | 964 | if (!cpu_online(cpu)) |
966 | return 0; | 965 | return 0; |
967 | 966 | ||
968 | /* we may be lax here as interrupts are off. Nonetheless | 967 | /* we may be lax here as interrupts are off. Nonetheless |
969 | * we need to grab the correct cpu policy, as to check | 968 | * we need to grab the correct cpu policy, as to check |
970 | * whether we really run on this CPU. | 969 | * whether we really run on this CPU. |
971 | */ | 970 | */ |
972 | 971 | ||
973 | cpu_policy = cpufreq_cpu_get(cpu); | 972 | cpu_policy = cpufreq_cpu_get(cpu); |
974 | if (!cpu_policy) | 973 | if (!cpu_policy) |
975 | return -EINVAL; | 974 | return -EINVAL; |
976 | 975 | ||
977 | /* only handle each CPU group once */ | 976 | /* only handle each CPU group once */ |
978 | if (unlikely(cpu_policy->cpu != cpu)) { | 977 | if (unlikely(cpu_policy->cpu != cpu)) { |
979 | cpufreq_cpu_put(cpu_policy); | 978 | cpufreq_cpu_put(cpu_policy); |
980 | return 0; | 979 | return 0; |
981 | } | 980 | } |
982 | 981 | ||
983 | if (cpufreq_driver->suspend) { | 982 | if (cpufreq_driver->suspend) { |
984 | ret = cpufreq_driver->suspend(cpu_policy, pmsg); | 983 | ret = cpufreq_driver->suspend(cpu_policy, pmsg); |
985 | if (ret) { | 984 | if (ret) { |
986 | printk(KERN_ERR "cpufreq: suspend failed in ->suspend " | 985 | printk(KERN_ERR "cpufreq: suspend failed in ->suspend " |
987 | "step on CPU %u\n", cpu_policy->cpu); | 986 | "step on CPU %u\n", cpu_policy->cpu); |
988 | cpufreq_cpu_put(cpu_policy); | 987 | cpufreq_cpu_put(cpu_policy); |
989 | return ret; | 988 | return ret; |
990 | } | 989 | } |
991 | } | 990 | } |
992 | 991 | ||
993 | 992 | ||
994 | if (cpufreq_driver->flags & CPUFREQ_CONST_LOOPS) | 993 | if (cpufreq_driver->flags & CPUFREQ_CONST_LOOPS) |
995 | goto out; | 994 | goto out; |
996 | 995 | ||
997 | if (cpufreq_driver->get) | 996 | if (cpufreq_driver->get) |
998 | cur_freq = cpufreq_driver->get(cpu_policy->cpu); | 997 | cur_freq = cpufreq_driver->get(cpu_policy->cpu); |
999 | 998 | ||
1000 | if (!cur_freq || !cpu_policy->cur) { | 999 | if (!cur_freq || !cpu_policy->cur) { |
1001 | printk(KERN_ERR "cpufreq: suspend failed to assert current " | 1000 | printk(KERN_ERR "cpufreq: suspend failed to assert current " |
1002 | "frequency is what timing core thinks it is.\n"); | 1001 | "frequency is what timing core thinks it is.\n"); |
1003 | goto out; | 1002 | goto out; |
1004 | } | 1003 | } |
1005 | 1004 | ||
1006 | if (unlikely(cur_freq != cpu_policy->cur)) { | 1005 | if (unlikely(cur_freq != cpu_policy->cur)) { |
1007 | struct cpufreq_freqs freqs; | 1006 | struct cpufreq_freqs freqs; |
1008 | 1007 | ||
1009 | if (!(cpufreq_driver->flags & CPUFREQ_PM_NO_WARN)) | 1008 | if (!(cpufreq_driver->flags & CPUFREQ_PM_NO_WARN)) |
1010 | dprintk(KERN_DEBUG "Warning: CPU frequency is %u, " | 1009 | dprintk(KERN_DEBUG "Warning: CPU frequency is %u, " |
1011 | "cpufreq assumed %u kHz.\n", | 1010 | "cpufreq assumed %u kHz.\n", |
1012 | cur_freq, cpu_policy->cur); | 1011 | cur_freq, cpu_policy->cur); |
1013 | 1012 | ||
1014 | freqs.cpu = cpu; | 1013 | freqs.cpu = cpu; |
1015 | freqs.old = cpu_policy->cur; | 1014 | freqs.old = cpu_policy->cur; |
1016 | freqs.new = cur_freq; | 1015 | freqs.new = cur_freq; |
1017 | 1016 | ||
1018 | blocking_notifier_call_chain(&cpufreq_transition_notifier_list, | 1017 | blocking_notifier_call_chain(&cpufreq_transition_notifier_list, |
1019 | CPUFREQ_SUSPENDCHANGE, &freqs); | 1018 | CPUFREQ_SUSPENDCHANGE, &freqs); |
1020 | adjust_jiffies(CPUFREQ_SUSPENDCHANGE, &freqs); | 1019 | adjust_jiffies(CPUFREQ_SUSPENDCHANGE, &freqs); |
1021 | 1020 | ||
1022 | cpu_policy->cur = cur_freq; | 1021 | cpu_policy->cur = cur_freq; |
1023 | } | 1022 | } |
1024 | 1023 | ||
1025 | out: | 1024 | out: |
1026 | cpufreq_cpu_put(cpu_policy); | 1025 | cpufreq_cpu_put(cpu_policy); |
1027 | return 0; | 1026 | return 0; |
1028 | } | 1027 | } |
1029 | 1028 | ||
1030 | /** | 1029 | /** |
1031 | * cpufreq_resume - restore proper CPU frequency handling after resume | 1030 | * cpufreq_resume - restore proper CPU frequency handling after resume |
1032 | * | 1031 | * |
1033 | * 1.) resume CPUfreq hardware support (cpufreq_driver->resume()) | 1032 | * 1.) resume CPUfreq hardware support (cpufreq_driver->resume()) |
1034 | * 2.) if ->target and !CPUFREQ_CONST_LOOPS: verify we're in sync | 1033 | * 2.) if ->target and !CPUFREQ_CONST_LOOPS: verify we're in sync |
1035 | * 3.) schedule call cpufreq_update_policy() ASAP as interrupts are | 1034 | * 3.) schedule call cpufreq_update_policy() ASAP as interrupts are |
1036 | * restored. | 1035 | * restored. |
1037 | */ | 1036 | */ |
1038 | static int cpufreq_resume(struct sys_device * sysdev) | 1037 | static int cpufreq_resume(struct sys_device * sysdev) |
1039 | { | 1038 | { |
1040 | int cpu = sysdev->id; | 1039 | int cpu = sysdev->id; |
1041 | unsigned int ret = 0; | 1040 | unsigned int ret = 0; |
1042 | struct cpufreq_policy *cpu_policy; | 1041 | struct cpufreq_policy *cpu_policy; |
1043 | 1042 | ||
1044 | dprintk("resuming cpu %u\n", cpu); | 1043 | dprintk("resuming cpu %u\n", cpu); |
1045 | 1044 | ||
1046 | if (!cpu_online(cpu)) | 1045 | if (!cpu_online(cpu)) |
1047 | return 0; | 1046 | return 0; |
1048 | 1047 | ||
1049 | /* we may be lax here as interrupts are off. Nonetheless | 1048 | /* we may be lax here as interrupts are off. Nonetheless |
1050 | * we need to grab the correct cpu policy, as to check | 1049 | * we need to grab the correct cpu policy, as to check |
1051 | * whether we really run on this CPU. | 1050 | * whether we really run on this CPU. |
1052 | */ | 1051 | */ |
1053 | 1052 | ||
1054 | cpu_policy = cpufreq_cpu_get(cpu); | 1053 | cpu_policy = cpufreq_cpu_get(cpu); |
1055 | if (!cpu_policy) | 1054 | if (!cpu_policy) |
1056 | return -EINVAL; | 1055 | return -EINVAL; |
1057 | 1056 | ||
1058 | /* only handle each CPU group once */ | 1057 | /* only handle each CPU group once */ |
1059 | if (unlikely(cpu_policy->cpu != cpu)) { | 1058 | if (unlikely(cpu_policy->cpu != cpu)) { |
1060 | cpufreq_cpu_put(cpu_policy); | 1059 | cpufreq_cpu_put(cpu_policy); |
1061 | return 0; | 1060 | return 0; |
1062 | } | 1061 | } |
1063 | 1062 | ||
1064 | if (cpufreq_driver->resume) { | 1063 | if (cpufreq_driver->resume) { |
1065 | ret = cpufreq_driver->resume(cpu_policy); | 1064 | ret = cpufreq_driver->resume(cpu_policy); |
1066 | if (ret) { | 1065 | if (ret) { |
1067 | printk(KERN_ERR "cpufreq: resume failed in ->resume " | 1066 | printk(KERN_ERR "cpufreq: resume failed in ->resume " |
1068 | "step on CPU %u\n", cpu_policy->cpu); | 1067 | "step on CPU %u\n", cpu_policy->cpu); |
1069 | cpufreq_cpu_put(cpu_policy); | 1068 | cpufreq_cpu_put(cpu_policy); |
1070 | return ret; | 1069 | return ret; |
1071 | } | 1070 | } |
1072 | } | 1071 | } |
1073 | 1072 | ||
1074 | if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { | 1073 | if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) { |
1075 | unsigned int cur_freq = 0; | 1074 | unsigned int cur_freq = 0; |
1076 | 1075 | ||
1077 | if (cpufreq_driver->get) | 1076 | if (cpufreq_driver->get) |
1078 | cur_freq = cpufreq_driver->get(cpu_policy->cpu); | 1077 | cur_freq = cpufreq_driver->get(cpu_policy->cpu); |
1079 | 1078 | ||
1080 | if (!cur_freq || !cpu_policy->cur) { | 1079 | if (!cur_freq || !cpu_policy->cur) { |
1081 | printk(KERN_ERR "cpufreq: resume failed to assert " | 1080 | printk(KERN_ERR "cpufreq: resume failed to assert " |
1082 | "current frequency is what timing core " | 1081 | "current frequency is what timing core " |
1083 | "thinks it is.\n"); | 1082 | "thinks it is.\n"); |
1084 | goto out; | 1083 | goto out; |
1085 | } | 1084 | } |
1086 | 1085 | ||
1087 | if (unlikely(cur_freq != cpu_policy->cur)) { | 1086 | if (unlikely(cur_freq != cpu_policy->cur)) { |
1088 | struct cpufreq_freqs freqs; | 1087 | struct cpufreq_freqs freqs; |
1089 | 1088 | ||
1090 | if (!(cpufreq_driver->flags & CPUFREQ_PM_NO_WARN)) | 1089 | if (!(cpufreq_driver->flags & CPUFREQ_PM_NO_WARN)) |
1091 | dprintk(KERN_WARNING "Warning: CPU frequency" | 1090 | dprintk(KERN_WARNING "Warning: CPU frequency" |
1092 | "is %u, cpufreq assumed %u kHz.\n", | 1091 | "is %u, cpufreq assumed %u kHz.\n", |
1093 | cur_freq, cpu_policy->cur); | 1092 | cur_freq, cpu_policy->cur); |
1094 | 1093 | ||
1095 | freqs.cpu = cpu; | 1094 | freqs.cpu = cpu; |
1096 | freqs.old = cpu_policy->cur; | 1095 | freqs.old = cpu_policy->cur; |
1097 | freqs.new = cur_freq; | 1096 | freqs.new = cur_freq; |
1098 | 1097 | ||
1099 | blocking_notifier_call_chain( | 1098 | blocking_notifier_call_chain( |
1100 | &cpufreq_transition_notifier_list, | 1099 | &cpufreq_transition_notifier_list, |
1101 | CPUFREQ_RESUMECHANGE, &freqs); | 1100 | CPUFREQ_RESUMECHANGE, &freqs); |
1102 | adjust_jiffies(CPUFREQ_RESUMECHANGE, &freqs); | 1101 | adjust_jiffies(CPUFREQ_RESUMECHANGE, &freqs); |
1103 | 1102 | ||
1104 | cpu_policy->cur = cur_freq; | 1103 | cpu_policy->cur = cur_freq; |
1105 | } | 1104 | } |
1106 | } | 1105 | } |
1107 | 1106 | ||
1108 | out: | 1107 | out: |
1109 | schedule_work(&cpu_policy->update); | 1108 | schedule_work(&cpu_policy->update); |
1110 | cpufreq_cpu_put(cpu_policy); | 1109 | cpufreq_cpu_put(cpu_policy); |
1111 | return ret; | 1110 | return ret; |
1112 | } | 1111 | } |
1113 | 1112 | ||
1114 | static struct sysdev_driver cpufreq_sysdev_driver = { | 1113 | static struct sysdev_driver cpufreq_sysdev_driver = { |
1115 | .add = cpufreq_add_dev, | 1114 | .add = cpufreq_add_dev, |
1116 | .remove = cpufreq_remove_dev, | 1115 | .remove = cpufreq_remove_dev, |
1117 | .suspend = cpufreq_suspend, | 1116 | .suspend = cpufreq_suspend, |
1118 | .resume = cpufreq_resume, | 1117 | .resume = cpufreq_resume, |
1119 | }; | 1118 | }; |
1120 | 1119 | ||
1121 | 1120 | ||
1122 | /********************************************************************* | 1121 | /********************************************************************* |
1123 | * NOTIFIER LISTS INTERFACE * | 1122 | * NOTIFIER LISTS INTERFACE * |
1124 | *********************************************************************/ | 1123 | *********************************************************************/ |
1125 | 1124 | ||
1126 | /** | 1125 | /** |
1127 | * cpufreq_register_notifier - register a driver with cpufreq | 1126 | * cpufreq_register_notifier - register a driver with cpufreq |
1128 | * @nb: notifier function to register | 1127 | * @nb: notifier function to register |
1129 | * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER | 1128 | * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER |
1130 | * | 1129 | * |
1131 | * Add a driver to one of two lists: either a list of drivers that | 1130 | * Add a driver to one of two lists: either a list of drivers that |
1132 | * are notified about clock rate changes (once before and once after | 1131 | * are notified about clock rate changes (once before and once after |
1133 | * the transition), or a list of drivers that are notified about | 1132 | * the transition), or a list of drivers that are notified about |
1134 | * changes in cpufreq policy. | 1133 | * changes in cpufreq policy. |
1135 | * | 1134 | * |
1136 | * This function may sleep, and has the same return conditions as | 1135 | * This function may sleep, and has the same return conditions as |
1137 | * blocking_notifier_chain_register. | 1136 | * blocking_notifier_chain_register. |
1138 | */ | 1137 | */ |
1139 | int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list) | 1138 | int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list) |
1140 | { | 1139 | { |
1141 | int ret; | 1140 | int ret; |
1142 | 1141 | ||
1143 | switch (list) { | 1142 | switch (list) { |
1144 | case CPUFREQ_TRANSITION_NOTIFIER: | 1143 | case CPUFREQ_TRANSITION_NOTIFIER: |
1145 | ret = blocking_notifier_chain_register( | 1144 | ret = blocking_notifier_chain_register( |
1146 | &cpufreq_transition_notifier_list, nb); | 1145 | &cpufreq_transition_notifier_list, nb); |
1147 | break; | 1146 | break; |
1148 | case CPUFREQ_POLICY_NOTIFIER: | 1147 | case CPUFREQ_POLICY_NOTIFIER: |
1149 | ret = blocking_notifier_chain_register( | 1148 | ret = blocking_notifier_chain_register( |
1150 | &cpufreq_policy_notifier_list, nb); | 1149 | &cpufreq_policy_notifier_list, nb); |
1151 | break; | 1150 | break; |
1152 | default: | 1151 | default: |
1153 | ret = -EINVAL; | 1152 | ret = -EINVAL; |
1154 | } | 1153 | } |
1155 | 1154 | ||
1156 | return ret; | 1155 | return ret; |
1157 | } | 1156 | } |
1158 | EXPORT_SYMBOL(cpufreq_register_notifier); | 1157 | EXPORT_SYMBOL(cpufreq_register_notifier); |
1159 | 1158 | ||
1160 | 1159 | ||
1161 | /** | 1160 | /** |
1162 | * cpufreq_unregister_notifier - unregister a driver with cpufreq | 1161 | * cpufreq_unregister_notifier - unregister a driver with cpufreq |
1163 | * @nb: notifier block to be unregistered | 1162 | * @nb: notifier block to be unregistered |
1164 | * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER | 1163 | * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER |
1165 | * | 1164 | * |
1166 | * Remove a driver from the CPU frequency notifier list. | 1165 | * Remove a driver from the CPU frequency notifier list. |
1167 | * | 1166 | * |
1168 | * This function may sleep, and has the same return conditions as | 1167 | * This function may sleep, and has the same return conditions as |
1169 | * blocking_notifier_chain_unregister. | 1168 | * blocking_notifier_chain_unregister. |
1170 | */ | 1169 | */ |
1171 | int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list) | 1170 | int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list) |
1172 | { | 1171 | { |
1173 | int ret; | 1172 | int ret; |
1174 | 1173 | ||
1175 | switch (list) { | 1174 | switch (list) { |
1176 | case CPUFREQ_TRANSITION_NOTIFIER: | 1175 | case CPUFREQ_TRANSITION_NOTIFIER: |
1177 | ret = blocking_notifier_chain_unregister( | 1176 | ret = blocking_notifier_chain_unregister( |
1178 | &cpufreq_transition_notifier_list, nb); | 1177 | &cpufreq_transition_notifier_list, nb); |
1179 | break; | 1178 | break; |
1180 | case CPUFREQ_POLICY_NOTIFIER: | 1179 | case CPUFREQ_POLICY_NOTIFIER: |
1181 | ret = blocking_notifier_chain_unregister( | 1180 | ret = blocking_notifier_chain_unregister( |
1182 | &cpufreq_policy_notifier_list, nb); | 1181 | &cpufreq_policy_notifier_list, nb); |
1183 | break; | 1182 | break; |
1184 | default: | 1183 | default: |
1185 | ret = -EINVAL; | 1184 | ret = -EINVAL; |
1186 | } | 1185 | } |
1187 | 1186 | ||
1188 | return ret; | 1187 | return ret; |
1189 | } | 1188 | } |
1190 | EXPORT_SYMBOL(cpufreq_unregister_notifier); | 1189 | EXPORT_SYMBOL(cpufreq_unregister_notifier); |
1191 | 1190 | ||
1192 | 1191 | ||
1193 | /********************************************************************* | 1192 | /********************************************************************* |
1194 | * GOVERNORS * | 1193 | * GOVERNORS * |
1195 | *********************************************************************/ | 1194 | *********************************************************************/ |
1196 | 1195 | ||
1197 | 1196 | ||
1198 | int __cpufreq_driver_target(struct cpufreq_policy *policy, | 1197 | int __cpufreq_driver_target(struct cpufreq_policy *policy, |
1199 | unsigned int target_freq, | 1198 | unsigned int target_freq, |
1200 | unsigned int relation) | 1199 | unsigned int relation) |
1201 | { | 1200 | { |
1202 | int retval = -EINVAL; | 1201 | int retval = -EINVAL; |
1203 | 1202 | ||
1204 | lock_cpu_hotplug(); | 1203 | lock_cpu_hotplug(); |
1205 | dprintk("target for CPU %u: %u kHz, relation %u\n", policy->cpu, | 1204 | dprintk("target for CPU %u: %u kHz, relation %u\n", policy->cpu, |
1206 | target_freq, relation); | 1205 | target_freq, relation); |
1207 | if (cpu_online(policy->cpu) && cpufreq_driver->target) | 1206 | if (cpu_online(policy->cpu) && cpufreq_driver->target) |
1208 | retval = cpufreq_driver->target(policy, target_freq, relation); | 1207 | retval = cpufreq_driver->target(policy, target_freq, relation); |
1209 | 1208 | ||
1210 | unlock_cpu_hotplug(); | 1209 | unlock_cpu_hotplug(); |
1211 | 1210 | ||
1212 | return retval; | 1211 | return retval; |
1213 | } | 1212 | } |
1214 | EXPORT_SYMBOL_GPL(__cpufreq_driver_target); | 1213 | EXPORT_SYMBOL_GPL(__cpufreq_driver_target); |
1215 | 1214 | ||
1216 | int cpufreq_driver_target(struct cpufreq_policy *policy, | 1215 | int cpufreq_driver_target(struct cpufreq_policy *policy, |
1217 | unsigned int target_freq, | 1216 | unsigned int target_freq, |
1218 | unsigned int relation) | 1217 | unsigned int relation) |
1219 | { | 1218 | { |
1220 | int ret; | 1219 | int ret; |
1221 | 1220 | ||
1222 | policy = cpufreq_cpu_get(policy->cpu); | 1221 | policy = cpufreq_cpu_get(policy->cpu); |
1223 | if (!policy) | 1222 | if (!policy) |
1224 | return -EINVAL; | 1223 | return -EINVAL; |
1225 | 1224 | ||
1226 | mutex_lock(&policy->lock); | 1225 | mutex_lock(&policy->lock); |
1227 | 1226 | ||
1228 | ret = __cpufreq_driver_target(policy, target_freq, relation); | 1227 | ret = __cpufreq_driver_target(policy, target_freq, relation); |
1229 | 1228 | ||
1230 | mutex_unlock(&policy->lock); | 1229 | mutex_unlock(&policy->lock); |
1231 | 1230 | ||
1232 | cpufreq_cpu_put(policy); | 1231 | cpufreq_cpu_put(policy); |
1233 | return ret; | 1232 | return ret; |
1234 | } | 1233 | } |
1235 | EXPORT_SYMBOL_GPL(cpufreq_driver_target); | 1234 | EXPORT_SYMBOL_GPL(cpufreq_driver_target); |
1236 | 1235 | ||
1237 | 1236 | ||
1238 | static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event) | 1237 | static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event) |
1239 | { | 1238 | { |
1240 | int ret; | 1239 | int ret; |
1241 | 1240 | ||
1242 | if (!try_module_get(policy->governor->owner)) | 1241 | if (!try_module_get(policy->governor->owner)) |
1243 | return -EINVAL; | 1242 | return -EINVAL; |
1244 | 1243 | ||
1245 | dprintk("__cpufreq_governor for CPU %u, event %u\n", policy->cpu, event); | 1244 | dprintk("__cpufreq_governor for CPU %u, event %u\n", policy->cpu, event); |
1246 | ret = policy->governor->governor(policy, event); | 1245 | ret = policy->governor->governor(policy, event); |
1247 | 1246 | ||
1248 | /* we keep one module reference alive for each CPU governed by this CPU */ | 1247 | /* we keep one module reference alive for each CPU governed by this CPU */ |
1249 | if ((event != CPUFREQ_GOV_START) || ret) | 1248 | if ((event != CPUFREQ_GOV_START) || ret) |
1250 | module_put(policy->governor->owner); | 1249 | module_put(policy->governor->owner); |
1251 | if ((event == CPUFREQ_GOV_STOP) && !ret) | 1250 | if ((event == CPUFREQ_GOV_STOP) && !ret) |
1252 | module_put(policy->governor->owner); | 1251 | module_put(policy->governor->owner); |
1253 | 1252 | ||
1254 | return ret; | 1253 | return ret; |
1255 | } | 1254 | } |
1256 | 1255 | ||
1257 | 1256 | ||
1258 | int cpufreq_governor(unsigned int cpu, unsigned int event) | 1257 | int cpufreq_governor(unsigned int cpu, unsigned int event) |
1259 | { | 1258 | { |
1260 | int ret = 0; | 1259 | int ret = 0; |
1261 | struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); | 1260 | struct cpufreq_policy *policy = cpufreq_cpu_get(cpu); |
1262 | 1261 | ||
1263 | if (!policy) | 1262 | if (!policy) |
1264 | return -EINVAL; | 1263 | return -EINVAL; |
1265 | 1264 | ||
1266 | mutex_lock(&policy->lock); | 1265 | mutex_lock(&policy->lock); |
1267 | ret = __cpufreq_governor(policy, event); | 1266 | ret = __cpufreq_governor(policy, event); |
1268 | mutex_unlock(&policy->lock); | 1267 | mutex_unlock(&policy->lock); |
1269 | 1268 | ||
1270 | cpufreq_cpu_put(policy); | 1269 | cpufreq_cpu_put(policy); |
1271 | return ret; | 1270 | return ret; |
1272 | } | 1271 | } |
1273 | EXPORT_SYMBOL_GPL(cpufreq_governor); | 1272 | EXPORT_SYMBOL_GPL(cpufreq_governor); |
1274 | 1273 | ||
1275 | 1274 | ||
1276 | int cpufreq_register_governor(struct cpufreq_governor *governor) | 1275 | int cpufreq_register_governor(struct cpufreq_governor *governor) |
1277 | { | 1276 | { |
1278 | struct cpufreq_governor *t; | 1277 | struct cpufreq_governor *t; |
1279 | 1278 | ||
1280 | if (!governor) | 1279 | if (!governor) |
1281 | return -EINVAL; | 1280 | return -EINVAL; |
1282 | 1281 | ||
1283 | mutex_lock(&cpufreq_governor_mutex); | 1282 | mutex_lock(&cpufreq_governor_mutex); |
1284 | 1283 | ||
1285 | list_for_each_entry(t, &cpufreq_governor_list, governor_list) { | 1284 | list_for_each_entry(t, &cpufreq_governor_list, governor_list) { |
1286 | if (!strnicmp(governor->name,t->name,CPUFREQ_NAME_LEN)) { | 1285 | if (!strnicmp(governor->name,t->name,CPUFREQ_NAME_LEN)) { |
1287 | mutex_unlock(&cpufreq_governor_mutex); | 1286 | mutex_unlock(&cpufreq_governor_mutex); |
1288 | return -EBUSY; | 1287 | return -EBUSY; |
1289 | } | 1288 | } |
1290 | } | 1289 | } |
1291 | list_add(&governor->governor_list, &cpufreq_governor_list); | 1290 | list_add(&governor->governor_list, &cpufreq_governor_list); |
1292 | 1291 | ||
1293 | mutex_unlock(&cpufreq_governor_mutex); | 1292 | mutex_unlock(&cpufreq_governor_mutex); |
1294 | return 0; | 1293 | return 0; |
1295 | } | 1294 | } |
1296 | EXPORT_SYMBOL_GPL(cpufreq_register_governor); | 1295 | EXPORT_SYMBOL_GPL(cpufreq_register_governor); |
1297 | 1296 | ||
1298 | 1297 | ||
1299 | void cpufreq_unregister_governor(struct cpufreq_governor *governor) | 1298 | void cpufreq_unregister_governor(struct cpufreq_governor *governor) |
1300 | { | 1299 | { |
1301 | if (!governor) | 1300 | if (!governor) |
1302 | return; | 1301 | return; |
1303 | 1302 | ||
1304 | mutex_lock(&cpufreq_governor_mutex); | 1303 | mutex_lock(&cpufreq_governor_mutex); |
1305 | list_del(&governor->governor_list); | 1304 | list_del(&governor->governor_list); |
1306 | mutex_unlock(&cpufreq_governor_mutex); | 1305 | mutex_unlock(&cpufreq_governor_mutex); |
1307 | return; | 1306 | return; |
1308 | } | 1307 | } |
1309 | EXPORT_SYMBOL_GPL(cpufreq_unregister_governor); | 1308 | EXPORT_SYMBOL_GPL(cpufreq_unregister_governor); |
1310 | 1309 | ||
1311 | 1310 | ||
1312 | 1311 | ||
1313 | /********************************************************************* | 1312 | /********************************************************************* |
1314 | * POLICY INTERFACE * | 1313 | * POLICY INTERFACE * |
1315 | *********************************************************************/ | 1314 | *********************************************************************/ |
1316 | 1315 | ||
1317 | /** | 1316 | /** |
1318 | * cpufreq_get_policy - get the current cpufreq_policy | 1317 | * cpufreq_get_policy - get the current cpufreq_policy |
1319 | * @policy: struct cpufreq_policy into which the current cpufreq_policy is written | 1318 | * @policy: struct cpufreq_policy into which the current cpufreq_policy is written |
1320 | * | 1319 | * |
1321 | * Reads the current cpufreq policy. | 1320 | * Reads the current cpufreq policy. |
1322 | */ | 1321 | */ |
1323 | int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu) | 1322 | int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu) |
1324 | { | 1323 | { |
1325 | struct cpufreq_policy *cpu_policy; | 1324 | struct cpufreq_policy *cpu_policy; |
1326 | if (!policy) | 1325 | if (!policy) |
1327 | return -EINVAL; | 1326 | return -EINVAL; |
1328 | 1327 | ||
1329 | cpu_policy = cpufreq_cpu_get(cpu); | 1328 | cpu_policy = cpufreq_cpu_get(cpu); |
1330 | if (!cpu_policy) | 1329 | if (!cpu_policy) |
1331 | return -EINVAL; | 1330 | return -EINVAL; |
1332 | 1331 | ||
1333 | mutex_lock(&cpu_policy->lock); | 1332 | mutex_lock(&cpu_policy->lock); |
1334 | memcpy(policy, cpu_policy, sizeof(struct cpufreq_policy)); | 1333 | memcpy(policy, cpu_policy, sizeof(struct cpufreq_policy)); |
1335 | mutex_unlock(&cpu_policy->lock); | 1334 | mutex_unlock(&cpu_policy->lock); |
1336 | 1335 | ||
1337 | cpufreq_cpu_put(cpu_policy); | 1336 | cpufreq_cpu_put(cpu_policy); |
1338 | return 0; | 1337 | return 0; |
1339 | } | 1338 | } |
1340 | EXPORT_SYMBOL(cpufreq_get_policy); | 1339 | EXPORT_SYMBOL(cpufreq_get_policy); |
1341 | 1340 | ||
1342 | 1341 | ||
1343 | static int __cpufreq_set_policy(struct cpufreq_policy *data, struct cpufreq_policy *policy) | 1342 | static int __cpufreq_set_policy(struct cpufreq_policy *data, struct cpufreq_policy *policy) |
1344 | { | 1343 | { |
1345 | int ret = 0; | 1344 | int ret = 0; |
1346 | 1345 | ||
1347 | cpufreq_debug_disable_ratelimit(); | 1346 | cpufreq_debug_disable_ratelimit(); |
1348 | dprintk("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu, | 1347 | dprintk("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu, |
1349 | policy->min, policy->max); | 1348 | policy->min, policy->max); |
1350 | 1349 | ||
1351 | memcpy(&policy->cpuinfo, &data->cpuinfo, sizeof(struct cpufreq_cpuinfo)); | 1350 | memcpy(&policy->cpuinfo, &data->cpuinfo, sizeof(struct cpufreq_cpuinfo)); |
1352 | 1351 | ||
1353 | /* verify the cpu speed can be set within this limit */ | 1352 | /* verify the cpu speed can be set within this limit */ |
1354 | ret = cpufreq_driver->verify(policy); | 1353 | ret = cpufreq_driver->verify(policy); |
1355 | if (ret) | 1354 | if (ret) |
1356 | goto error_out; | 1355 | goto error_out; |
1357 | 1356 | ||
1358 | /* adjust if necessary - all reasons */ | 1357 | /* adjust if necessary - all reasons */ |
1359 | blocking_notifier_call_chain(&cpufreq_policy_notifier_list, | 1358 | blocking_notifier_call_chain(&cpufreq_policy_notifier_list, |
1360 | CPUFREQ_ADJUST, policy); | 1359 | CPUFREQ_ADJUST, policy); |
1361 | 1360 | ||
1362 | /* adjust if necessary - hardware incompatibility*/ | 1361 | /* adjust if necessary - hardware incompatibility*/ |
1363 | blocking_notifier_call_chain(&cpufreq_policy_notifier_list, | 1362 | blocking_notifier_call_chain(&cpufreq_policy_notifier_list, |
1364 | CPUFREQ_INCOMPATIBLE, policy); | 1363 | CPUFREQ_INCOMPATIBLE, policy); |
1365 | 1364 | ||
1366 | /* verify the cpu speed can be set within this limit, | 1365 | /* verify the cpu speed can be set within this limit, |
1367 | which might be different to the first one */ | 1366 | which might be different to the first one */ |
1368 | ret = cpufreq_driver->verify(policy); | 1367 | ret = cpufreq_driver->verify(policy); |
1369 | if (ret) | 1368 | if (ret) |
1370 | goto error_out; | 1369 | goto error_out; |
1371 | 1370 | ||
1372 | /* notification of the new policy */ | 1371 | /* notification of the new policy */ |
1373 | blocking_notifier_call_chain(&cpufreq_policy_notifier_list, | 1372 | blocking_notifier_call_chain(&cpufreq_policy_notifier_list, |
1374 | CPUFREQ_NOTIFY, policy); | 1373 | CPUFREQ_NOTIFY, policy); |
1375 | 1374 | ||
1376 | data->min = policy->min; | 1375 | data->min = policy->min; |
1377 | data->max = policy->max; | 1376 | data->max = policy->max; |
1378 | 1377 | ||
1379 | dprintk("new min and max freqs are %u - %u kHz\n", data->min, data->max); | 1378 | dprintk("new min and max freqs are %u - %u kHz\n", data->min, data->max); |
1380 | 1379 | ||
1381 | if (cpufreq_driver->setpolicy) { | 1380 | if (cpufreq_driver->setpolicy) { |
1382 | data->policy = policy->policy; | 1381 | data->policy = policy->policy; |
1383 | dprintk("setting range\n"); | 1382 | dprintk("setting range\n"); |
1384 | ret = cpufreq_driver->setpolicy(policy); | 1383 | ret = cpufreq_driver->setpolicy(policy); |
1385 | } else { | 1384 | } else { |
1386 | if (policy->governor != data->governor) { | 1385 | if (policy->governor != data->governor) { |
1387 | /* save old, working values */ | 1386 | /* save old, working values */ |
1388 | struct cpufreq_governor *old_gov = data->governor; | 1387 | struct cpufreq_governor *old_gov = data->governor; |
1389 | 1388 | ||
1390 | dprintk("governor switch\n"); | 1389 | dprintk("governor switch\n"); |
1391 | 1390 | ||
1392 | /* end old governor */ | 1391 | /* end old governor */ |
1393 | if (data->governor) | 1392 | if (data->governor) |
1394 | __cpufreq_governor(data, CPUFREQ_GOV_STOP); | 1393 | __cpufreq_governor(data, CPUFREQ_GOV_STOP); |
1395 | 1394 | ||
1396 | /* start new governor */ | 1395 | /* start new governor */ |
1397 | data->governor = policy->governor; | 1396 | data->governor = policy->governor; |
1398 | if (__cpufreq_governor(data, CPUFREQ_GOV_START)) { | 1397 | if (__cpufreq_governor(data, CPUFREQ_GOV_START)) { |
1399 | /* new governor failed, so re-start old one */ | 1398 | /* new governor failed, so re-start old one */ |
1400 | dprintk("starting governor %s failed\n", data->governor->name); | 1399 | dprintk("starting governor %s failed\n", data->governor->name); |
1401 | if (old_gov) { | 1400 | if (old_gov) { |
1402 | data->governor = old_gov; | 1401 | data->governor = old_gov; |
1403 | __cpufreq_governor(data, CPUFREQ_GOV_START); | 1402 | __cpufreq_governor(data, CPUFREQ_GOV_START); |
1404 | } | 1403 | } |
1405 | ret = -EINVAL; | 1404 | ret = -EINVAL; |
1406 | goto error_out; | 1405 | goto error_out; |
1407 | } | 1406 | } |
1408 | /* might be a policy change, too, so fall through */ | 1407 | /* might be a policy change, too, so fall through */ |
1409 | } | 1408 | } |
1410 | dprintk("governor: change or update limits\n"); | 1409 | dprintk("governor: change or update limits\n"); |
1411 | __cpufreq_governor(data, CPUFREQ_GOV_LIMITS); | 1410 | __cpufreq_governor(data, CPUFREQ_GOV_LIMITS); |
1412 | } | 1411 | } |
1413 | 1412 | ||
1414 | error_out: | 1413 | error_out: |
1415 | cpufreq_debug_enable_ratelimit(); | 1414 | cpufreq_debug_enable_ratelimit(); |
1416 | return ret; | 1415 | return ret; |
1417 | } | 1416 | } |
1418 | 1417 | ||
1419 | /** | 1418 | /** |
1420 | * cpufreq_set_policy - set a new CPUFreq policy | 1419 | * cpufreq_set_policy - set a new CPUFreq policy |
1421 | * @policy: policy to be set. | 1420 | * @policy: policy to be set. |
1422 | * | 1421 | * |
1423 | * Sets a new CPU frequency and voltage scaling policy. | 1422 | * Sets a new CPU frequency and voltage scaling policy. |
1424 | */ | 1423 | */ |
1425 | int cpufreq_set_policy(struct cpufreq_policy *policy) | 1424 | int cpufreq_set_policy(struct cpufreq_policy *policy) |
1426 | { | 1425 | { |
1427 | int ret = 0; | 1426 | int ret = 0; |
1428 | struct cpufreq_policy *data; | 1427 | struct cpufreq_policy *data; |
1429 | 1428 | ||
1430 | if (!policy) | 1429 | if (!policy) |
1431 | return -EINVAL; | 1430 | return -EINVAL; |
1432 | 1431 | ||
1433 | data = cpufreq_cpu_get(policy->cpu); | 1432 | data = cpufreq_cpu_get(policy->cpu); |
1434 | if (!data) | 1433 | if (!data) |
1435 | return -EINVAL; | 1434 | return -EINVAL; |
1436 | 1435 | ||
1437 | /* lock this CPU */ | 1436 | /* lock this CPU */ |
1438 | mutex_lock(&data->lock); | 1437 | mutex_lock(&data->lock); |
1439 | 1438 | ||
1440 | ret = __cpufreq_set_policy(data, policy); | 1439 | ret = __cpufreq_set_policy(data, policy); |
1441 | data->user_policy.min = data->min; | 1440 | data->user_policy.min = data->min; |
1442 | data->user_policy.max = data->max; | 1441 | data->user_policy.max = data->max; |
1443 | data->user_policy.policy = data->policy; | 1442 | data->user_policy.policy = data->policy; |
1444 | data->user_policy.governor = data->governor; | 1443 | data->user_policy.governor = data->governor; |
1445 | 1444 | ||
1446 | mutex_unlock(&data->lock); | 1445 | mutex_unlock(&data->lock); |
1447 | cpufreq_cpu_put(data); | 1446 | cpufreq_cpu_put(data); |
1448 | 1447 | ||
1449 | return ret; | 1448 | return ret; |
1450 | } | 1449 | } |
1451 | EXPORT_SYMBOL(cpufreq_set_policy); | 1450 | EXPORT_SYMBOL(cpufreq_set_policy); |
1452 | 1451 | ||
1453 | 1452 | ||
1454 | /** | 1453 | /** |
1455 | * cpufreq_update_policy - re-evaluate an existing cpufreq policy | 1454 | * cpufreq_update_policy - re-evaluate an existing cpufreq policy |
1456 | * @cpu: CPU which shall be re-evaluated | 1455 | * @cpu: CPU which shall be re-evaluated |
1457 | * | 1456 | * |
1458 | * Usefull for policy notifiers which have different necessities | 1457 | * Usefull for policy notifiers which have different necessities |
1459 | * at different times. | 1458 | * at different times. |
1460 | */ | 1459 | */ |
1461 | int cpufreq_update_policy(unsigned int cpu) | 1460 | int cpufreq_update_policy(unsigned int cpu) |
1462 | { | 1461 | { |
1463 | struct cpufreq_policy *data = cpufreq_cpu_get(cpu); | 1462 | struct cpufreq_policy *data = cpufreq_cpu_get(cpu); |
1464 | struct cpufreq_policy policy; | 1463 | struct cpufreq_policy policy; |
1465 | int ret = 0; | 1464 | int ret = 0; |
1466 | 1465 | ||
1467 | if (!data) | 1466 | if (!data) |
1468 | return -ENODEV; | 1467 | return -ENODEV; |
1469 | 1468 | ||
1470 | mutex_lock(&data->lock); | 1469 | mutex_lock(&data->lock); |
1471 | 1470 | ||
1472 | dprintk("updating policy for CPU %u\n", cpu); | 1471 | dprintk("updating policy for CPU %u\n", cpu); |
1473 | memcpy(&policy, data, sizeof(struct cpufreq_policy)); | 1472 | memcpy(&policy, data, sizeof(struct cpufreq_policy)); |
1474 | policy.min = data->user_policy.min; | 1473 | policy.min = data->user_policy.min; |
1475 | policy.max = data->user_policy.max; | 1474 | policy.max = data->user_policy.max; |
1476 | policy.policy = data->user_policy.policy; | 1475 | policy.policy = data->user_policy.policy; |
1477 | policy.governor = data->user_policy.governor; | 1476 | policy.governor = data->user_policy.governor; |
1478 | 1477 | ||
1479 | /* BIOS might change freq behind our back | 1478 | /* BIOS might change freq behind our back |
1480 | -> ask driver for current freq and notify governors about a change */ | 1479 | -> ask driver for current freq and notify governors about a change */ |
1481 | if (cpufreq_driver->get) { | 1480 | if (cpufreq_driver->get) { |
1482 | policy.cur = cpufreq_driver->get(cpu); | 1481 | policy.cur = cpufreq_driver->get(cpu); |
1483 | if (!data->cur) { | 1482 | if (!data->cur) { |
1484 | dprintk("Driver did not initialize current freq"); | 1483 | dprintk("Driver did not initialize current freq"); |
1485 | data->cur = policy.cur; | 1484 | data->cur = policy.cur; |
1486 | } else { | 1485 | } else { |
1487 | if (data->cur != policy.cur) | 1486 | if (data->cur != policy.cur) |
1488 | cpufreq_out_of_sync(cpu, data->cur, policy.cur); | 1487 | cpufreq_out_of_sync(cpu, data->cur, policy.cur); |
1489 | } | 1488 | } |
1490 | } | 1489 | } |
1491 | 1490 | ||
1492 | ret = __cpufreq_set_policy(data, &policy); | 1491 | ret = __cpufreq_set_policy(data, &policy); |
1493 | 1492 | ||
1494 | mutex_unlock(&data->lock); | 1493 | mutex_unlock(&data->lock); |
1495 | 1494 | ||
1496 | cpufreq_cpu_put(data); | 1495 | cpufreq_cpu_put(data); |
1497 | return ret; | 1496 | return ret; |
1498 | } | 1497 | } |
1499 | EXPORT_SYMBOL(cpufreq_update_policy); | 1498 | EXPORT_SYMBOL(cpufreq_update_policy); |
1500 | 1499 | ||
1501 | static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb, | 1500 | static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb, |
1502 | unsigned long action, void *hcpu) | 1501 | unsigned long action, void *hcpu) |
1503 | { | 1502 | { |
1504 | unsigned int cpu = (unsigned long)hcpu; | 1503 | unsigned int cpu = (unsigned long)hcpu; |
1505 | struct cpufreq_policy *policy; | 1504 | struct cpufreq_policy *policy; |
1506 | struct sys_device *sys_dev; | 1505 | struct sys_device *sys_dev; |
1507 | 1506 | ||
1508 | sys_dev = get_cpu_sysdev(cpu); | 1507 | sys_dev = get_cpu_sysdev(cpu); |
1509 | 1508 | ||
1510 | if (sys_dev) { | 1509 | if (sys_dev) { |
1511 | switch (action) { | 1510 | switch (action) { |
1512 | case CPU_ONLINE: | 1511 | case CPU_ONLINE: |
1513 | cpufreq_add_dev(sys_dev); | 1512 | cpufreq_add_dev(sys_dev); |
1514 | break; | 1513 | break; |
1515 | case CPU_DOWN_PREPARE: | 1514 | case CPU_DOWN_PREPARE: |
1516 | /* | 1515 | /* |
1517 | * We attempt to put this cpu in lowest frequency | 1516 | * We attempt to put this cpu in lowest frequency |
1518 | * possible before going down. This will permit | 1517 | * possible before going down. This will permit |
1519 | * hardware-managed P-State to switch other related | 1518 | * hardware-managed P-State to switch other related |
1520 | * threads to min or higher speeds if possible. | 1519 | * threads to min or higher speeds if possible. |
1521 | */ | 1520 | */ |
1522 | policy = cpufreq_cpu_data[cpu]; | 1521 | policy = cpufreq_cpu_data[cpu]; |
1523 | if (policy) { | 1522 | if (policy) { |
1524 | cpufreq_driver_target(policy, policy->min, | 1523 | cpufreq_driver_target(policy, policy->min, |
1525 | CPUFREQ_RELATION_H); | 1524 | CPUFREQ_RELATION_H); |
1526 | } | 1525 | } |
1527 | break; | 1526 | break; |
1528 | case CPU_DEAD: | 1527 | case CPU_DEAD: |
1529 | cpufreq_remove_dev(sys_dev); | 1528 | cpufreq_remove_dev(sys_dev); |
1530 | break; | 1529 | break; |
1531 | } | 1530 | } |
1532 | } | 1531 | } |
1533 | return NOTIFY_OK; | 1532 | return NOTIFY_OK; |
1534 | } | 1533 | } |
1535 | 1534 | ||
1536 | static struct notifier_block cpufreq_cpu_notifier = | 1535 | static struct notifier_block cpufreq_cpu_notifier = |
1537 | { | 1536 | { |
1538 | .notifier_call = cpufreq_cpu_callback, | 1537 | .notifier_call = cpufreq_cpu_callback, |
1539 | }; | 1538 | }; |
1540 | 1539 | ||
1541 | /********************************************************************* | 1540 | /********************************************************************* |
1542 | * REGISTER / UNREGISTER CPUFREQ DRIVER * | 1541 | * REGISTER / UNREGISTER CPUFREQ DRIVER * |
1543 | *********************************************************************/ | 1542 | *********************************************************************/ |
1544 | 1543 | ||
1545 | /** | 1544 | /** |
1546 | * cpufreq_register_driver - register a CPU Frequency driver | 1545 | * cpufreq_register_driver - register a CPU Frequency driver |
1547 | * @driver_data: A struct cpufreq_driver containing the values# | 1546 | * @driver_data: A struct cpufreq_driver containing the values# |
1548 | * submitted by the CPU Frequency driver. | 1547 | * submitted by the CPU Frequency driver. |
1549 | * | 1548 | * |
1550 | * Registers a CPU Frequency driver to this core code. This code | 1549 | * Registers a CPU Frequency driver to this core code. This code |
1551 | * returns zero on success, -EBUSY when another driver got here first | 1550 | * returns zero on success, -EBUSY when another driver got here first |
1552 | * (and isn't unregistered in the meantime). | 1551 | * (and isn't unregistered in the meantime). |
1553 | * | 1552 | * |
1554 | */ | 1553 | */ |
1555 | int cpufreq_register_driver(struct cpufreq_driver *driver_data) | 1554 | int cpufreq_register_driver(struct cpufreq_driver *driver_data) |
1556 | { | 1555 | { |
1557 | unsigned long flags; | 1556 | unsigned long flags; |
1558 | int ret; | 1557 | int ret; |
1559 | 1558 | ||
1560 | if (!driver_data || !driver_data->verify || !driver_data->init || | 1559 | if (!driver_data || !driver_data->verify || !driver_data->init || |
1561 | ((!driver_data->setpolicy) && (!driver_data->target))) | 1560 | ((!driver_data->setpolicy) && (!driver_data->target))) |
1562 | return -EINVAL; | 1561 | return -EINVAL; |
1563 | 1562 | ||
1564 | dprintk("trying to register driver %s\n", driver_data->name); | 1563 | dprintk("trying to register driver %s\n", driver_data->name); |
1565 | 1564 | ||
1566 | if (driver_data->setpolicy) | 1565 | if (driver_data->setpolicy) |
1567 | driver_data->flags |= CPUFREQ_CONST_LOOPS; | 1566 | driver_data->flags |= CPUFREQ_CONST_LOOPS; |
1568 | 1567 | ||
1569 | spin_lock_irqsave(&cpufreq_driver_lock, flags); | 1568 | spin_lock_irqsave(&cpufreq_driver_lock, flags); |
1570 | if (cpufreq_driver) { | 1569 | if (cpufreq_driver) { |
1571 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 1570 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
1572 | return -EBUSY; | 1571 | return -EBUSY; |
1573 | } | 1572 | } |
1574 | cpufreq_driver = driver_data; | 1573 | cpufreq_driver = driver_data; |
1575 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 1574 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
1576 | 1575 | ||
1577 | ret = sysdev_driver_register(&cpu_sysdev_class,&cpufreq_sysdev_driver); | 1576 | ret = sysdev_driver_register(&cpu_sysdev_class,&cpufreq_sysdev_driver); |
1578 | 1577 | ||
1579 | if ((!ret) && !(cpufreq_driver->flags & CPUFREQ_STICKY)) { | 1578 | if ((!ret) && !(cpufreq_driver->flags & CPUFREQ_STICKY)) { |
1580 | int i; | 1579 | int i; |
1581 | ret = -ENODEV; | 1580 | ret = -ENODEV; |
1582 | 1581 | ||
1583 | /* check for at least one working CPU */ | 1582 | /* check for at least one working CPU */ |
1584 | for (i=0; i<NR_CPUS; i++) | 1583 | for (i=0; i<NR_CPUS; i++) |
1585 | if (cpufreq_cpu_data[i]) | 1584 | if (cpufreq_cpu_data[i]) |
1586 | ret = 0; | 1585 | ret = 0; |
1587 | 1586 | ||
1588 | /* if all ->init() calls failed, unregister */ | 1587 | /* if all ->init() calls failed, unregister */ |
1589 | if (ret) { | 1588 | if (ret) { |
1590 | dprintk("no CPU initialized for driver %s\n", driver_data->name); | 1589 | dprintk("no CPU initialized for driver %s\n", driver_data->name); |
1591 | sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver); | 1590 | sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver); |
1592 | 1591 | ||
1593 | spin_lock_irqsave(&cpufreq_driver_lock, flags); | 1592 | spin_lock_irqsave(&cpufreq_driver_lock, flags); |
1594 | cpufreq_driver = NULL; | 1593 | cpufreq_driver = NULL; |
1595 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 1594 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
1596 | } | 1595 | } |
1597 | } | 1596 | } |
1598 | 1597 | ||
1599 | if (!ret) { | 1598 | if (!ret) { |
1600 | register_cpu_notifier(&cpufreq_cpu_notifier); | 1599 | register_cpu_notifier(&cpufreq_cpu_notifier); |
1601 | dprintk("driver %s up and running\n", driver_data->name); | 1600 | dprintk("driver %s up and running\n", driver_data->name); |
1602 | cpufreq_debug_enable_ratelimit(); | 1601 | cpufreq_debug_enable_ratelimit(); |
1603 | } | 1602 | } |
1604 | 1603 | ||
1605 | return (ret); | 1604 | return (ret); |
1606 | } | 1605 | } |
1607 | EXPORT_SYMBOL_GPL(cpufreq_register_driver); | 1606 | EXPORT_SYMBOL_GPL(cpufreq_register_driver); |
1608 | 1607 | ||
1609 | 1608 | ||
1610 | /** | 1609 | /** |
1611 | * cpufreq_unregister_driver - unregister the current CPUFreq driver | 1610 | * cpufreq_unregister_driver - unregister the current CPUFreq driver |
1612 | * | 1611 | * |
1613 | * Unregister the current CPUFreq driver. Only call this if you have | 1612 | * Unregister the current CPUFreq driver. Only call this if you have |
1614 | * the right to do so, i.e. if you have succeeded in initialising before! | 1613 | * the right to do so, i.e. if you have succeeded in initialising before! |
1615 | * Returns zero if successful, and -EINVAL if the cpufreq_driver is | 1614 | * Returns zero if successful, and -EINVAL if the cpufreq_driver is |
1616 | * currently not initialised. | 1615 | * currently not initialised. |
1617 | */ | 1616 | */ |
1618 | int cpufreq_unregister_driver(struct cpufreq_driver *driver) | 1617 | int cpufreq_unregister_driver(struct cpufreq_driver *driver) |
1619 | { | 1618 | { |
1620 | unsigned long flags; | 1619 | unsigned long flags; |
1621 | 1620 | ||
1622 | cpufreq_debug_disable_ratelimit(); | 1621 | cpufreq_debug_disable_ratelimit(); |
1623 | 1622 | ||
1624 | if (!cpufreq_driver || (driver != cpufreq_driver)) { | 1623 | if (!cpufreq_driver || (driver != cpufreq_driver)) { |
1625 | cpufreq_debug_enable_ratelimit(); | 1624 | cpufreq_debug_enable_ratelimit(); |
1626 | return -EINVAL; | 1625 | return -EINVAL; |
1627 | } | 1626 | } |
1628 | 1627 | ||
1629 | dprintk("unregistering driver %s\n", driver->name); | 1628 | dprintk("unregistering driver %s\n", driver->name); |
1630 | 1629 | ||
1631 | sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver); | 1630 | sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver); |
1632 | unregister_cpu_notifier(&cpufreq_cpu_notifier); | 1631 | unregister_cpu_notifier(&cpufreq_cpu_notifier); |
1633 | 1632 | ||
1634 | spin_lock_irqsave(&cpufreq_driver_lock, flags); | 1633 | spin_lock_irqsave(&cpufreq_driver_lock, flags); |
1635 | cpufreq_driver = NULL; | 1634 | cpufreq_driver = NULL; |
1636 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); | 1635 | spin_unlock_irqrestore(&cpufreq_driver_lock, flags); |
1637 | 1636 | ||
1638 | return 0; | 1637 | return 0; |
1639 | } | 1638 | } |
1640 | EXPORT_SYMBOL_GPL(cpufreq_unregister_driver); | 1639 | EXPORT_SYMBOL_GPL(cpufreq_unregister_driver); |
1641 | 1640 |