blob: aed80e6aec6dd3dd96b63034136670757b3e40b8 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/cpufreq/cpufreq.c
3 *
4 * Copyright (C) 2001 Russell King
5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
6 *
Ashok Rajc32b6b82005-10-30 14:59:54 -08007 * Oct 2005 - Ashok Raj <ashok.raj@intel.com>
Dave Jones32ee8c32006-02-28 00:43:23 -05008 * Added handling for CPU hotplug
Dave Jones8ff69732006-03-05 03:37:23 -05009 * Feb 2006 - Jacob Shin <jacob.shin@amd.com>
10 * Fix handling for CPU hotplug -- affected CPUs
Ashok Rajc32b6b82005-10-30 14:59:54 -080011 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 * 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
14 * published by the Free Software Foundation.
15 *
16 */
17
18#include <linux/config.h>
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/notifier.h>
23#include <linux/cpufreq.h>
24#include <linux/delay.h>
25#include <linux/interrupt.h>
26#include <linux/spinlock.h>
27#include <linux/device.h>
28#include <linux/slab.h>
29#include <linux/cpu.h>
30#include <linux/completion.h>
akpm@osdl.org3fc54d32006-01-13 15:54:22 -080031#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_CORE, "cpufreq-core", msg)
34
35/**
36 * The "cpufreq driver" - the arch- or hardware-dependend low
37 * level driver of CPUFreq support, and its spinlock. This lock
38 * also protects the cpufreq_cpu_data array.
39 */
Dave Jones7d5e3502006-02-02 17:03:42 -050040static struct cpufreq_driver *cpufreq_driver;
41static struct cpufreq_policy *cpufreq_cpu_data[NR_CPUS];
Linus Torvalds1da177e2005-04-16 15:20:36 -070042static DEFINE_SPINLOCK(cpufreq_driver_lock);
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/* internal prototypes */
45static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event);
46static void handle_update(void *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
48/**
Dave Jones32ee8c32006-02-28 00:43:23 -050049 * Two notifier lists: the "policy" list is involved in the
50 * validation process for a new CPU frequency policy; the
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 * "transition" list for kernel code that needs to handle
52 * changes to devices when the CPU clock speed changes.
53 * The mutex locks both lists.
54 */
Dave Jones7d5e3502006-02-02 17:03:42 -050055static struct notifier_block *cpufreq_policy_notifier_list;
56static struct notifier_block *cpufreq_transition_notifier_list;
57static DECLARE_RWSEM (cpufreq_notifier_rwsem);
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
59
60static LIST_HEAD(cpufreq_governor_list);
Dave Jones7d5e3502006-02-02 17:03:42 -050061static DEFINE_MUTEX (cpufreq_governor_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Dave Jones7d5e3502006-02-02 17:03:42 -050063struct cpufreq_policy *cpufreq_cpu_get(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
65 struct cpufreq_policy *data;
66 unsigned long flags;
67
68 if (cpu >= NR_CPUS)
69 goto err_out;
70
71 /* get the cpufreq driver */
72 spin_lock_irqsave(&cpufreq_driver_lock, flags);
73
74 if (!cpufreq_driver)
75 goto err_out_unlock;
76
77 if (!try_module_get(cpufreq_driver->owner))
78 goto err_out_unlock;
79
80
81 /* get the CPU */
82 data = cpufreq_cpu_data[cpu];
83
84 if (!data)
85 goto err_out_put_module;
86
87 if (!kobject_get(&data->kobj))
88 goto err_out_put_module;
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 return data;
92
Dave Jones7d5e3502006-02-02 17:03:42 -050093err_out_put_module:
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 module_put(cpufreq_driver->owner);
Dave Jones7d5e3502006-02-02 17:03:42 -050095err_out_unlock:
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
Dave Jones7d5e3502006-02-02 17:03:42 -050097err_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 return NULL;
99}
100EXPORT_SYMBOL_GPL(cpufreq_cpu_get);
101
Dave Jones7d5e3502006-02-02 17:03:42 -0500102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103void cpufreq_cpu_put(struct cpufreq_policy *data)
104{
105 kobject_put(&data->kobj);
106 module_put(cpufreq_driver->owner);
107}
108EXPORT_SYMBOL_GPL(cpufreq_cpu_put);
109
110
111/*********************************************************************
112 * UNIFIED DEBUG HELPERS *
113 *********************************************************************/
114#ifdef CONFIG_CPU_FREQ_DEBUG
115
116/* what part(s) of the CPUfreq subsystem are debugged? */
117static unsigned int debug;
118
119/* is the debug output ratelimit'ed using printk_ratelimit? User can
120 * set or modify this value.
121 */
122static unsigned int debug_ratelimit = 1;
123
124/* is the printk_ratelimit'ing enabled? It's enabled after a successful
125 * loading of a cpufreq driver, temporarily disabled when a new policy
126 * is set, and disabled upon cpufreq driver removal
127 */
128static unsigned int disable_ratelimit = 1;
129static DEFINE_SPINLOCK(disable_ratelimit_lock);
130
Arjan van de Ven858119e2006-01-14 13:20:43 -0800131static void cpufreq_debug_enable_ratelimit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
133 unsigned long flags;
134
135 spin_lock_irqsave(&disable_ratelimit_lock, flags);
136 if (disable_ratelimit)
137 disable_ratelimit--;
138 spin_unlock_irqrestore(&disable_ratelimit_lock, flags);
139}
140
Arjan van de Ven858119e2006-01-14 13:20:43 -0800141static void cpufreq_debug_disable_ratelimit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142{
143 unsigned long flags;
144
145 spin_lock_irqsave(&disable_ratelimit_lock, flags);
146 disable_ratelimit++;
147 spin_unlock_irqrestore(&disable_ratelimit_lock, flags);
148}
149
150void cpufreq_debug_printk(unsigned int type, const char *prefix, const char *fmt, ...)
151{
152 char s[256];
153 va_list args;
154 unsigned int len;
155 unsigned long flags;
Dave Jones32ee8c32006-02-28 00:43:23 -0500156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 WARN_ON(!prefix);
158 if (type & debug) {
159 spin_lock_irqsave(&disable_ratelimit_lock, flags);
160 if (!disable_ratelimit && debug_ratelimit && !printk_ratelimit()) {
161 spin_unlock_irqrestore(&disable_ratelimit_lock, flags);
162 return;
163 }
164 spin_unlock_irqrestore(&disable_ratelimit_lock, flags);
165
166 len = snprintf(s, 256, KERN_DEBUG "%s: ", prefix);
167
168 va_start(args, fmt);
169 len += vsnprintf(&s[len], (256 - len), fmt, args);
170 va_end(args);
171
172 printk(s);
173
174 WARN_ON(len < 5);
175 }
176}
177EXPORT_SYMBOL(cpufreq_debug_printk);
178
179
180module_param(debug, uint, 0644);
181MODULE_PARM_DESC(debug, "CPUfreq debugging: add 1 to debug core, 2 to debug drivers, and 4 to debug governors.");
182
183module_param(debug_ratelimit, uint, 0644);
184MODULE_PARM_DESC(debug_ratelimit, "CPUfreq debugging: set to 0 to disable ratelimiting.");
185
186#else /* !CONFIG_CPU_FREQ_DEBUG */
187
188static inline void cpufreq_debug_enable_ratelimit(void) { return; }
189static inline void cpufreq_debug_disable_ratelimit(void) { return; }
190
191#endif /* CONFIG_CPU_FREQ_DEBUG */
192
193
194/*********************************************************************
195 * EXTERNALLY AFFECTING FREQUENCY CHANGES *
196 *********************************************************************/
197
198/**
199 * adjust_jiffies - adjust the system "loops_per_jiffy"
200 *
201 * This function alters the system "loops_per_jiffy" for the clock
202 * speed change. Note that loops_per_jiffy cannot be updated on SMP
Dave Jones32ee8c32006-02-28 00:43:23 -0500203 * systems as each CPU might be scaled differently. So, use the arch
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 * per-CPU loops_per_jiffy value wherever possible.
205 */
206#ifndef CONFIG_SMP
207static unsigned long l_p_j_ref;
208static unsigned int l_p_j_ref_freq;
209
Arjan van de Ven858119e2006-01-14 13:20:43 -0800210static void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211{
212 if (ci->flags & CPUFREQ_CONST_LOOPS)
213 return;
214
215 if (!l_p_j_ref_freq) {
216 l_p_j_ref = loops_per_jiffy;
217 l_p_j_ref_freq = ci->old;
218 dprintk("saving %lu as reference value for loops_per_jiffy; freq is %u kHz\n", l_p_j_ref, l_p_j_ref_freq);
219 }
220 if ((val == CPUFREQ_PRECHANGE && ci->old < ci->new) ||
221 (val == CPUFREQ_POSTCHANGE && ci->old > ci->new) ||
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -0700222 (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq, ci->new);
224 dprintk("scaling loops_per_jiffy to %lu for frequency %u kHz\n", loops_per_jiffy, ci->new);
225 }
226}
227#else
228static inline void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci) { return; }
229#endif
230
231
232/**
Dave Jonese4472cb2006-01-31 15:53:55 -0800233 * cpufreq_notify_transition - call notifier chain and adjust_jiffies
234 * on frequency transition.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 *
Dave Jonese4472cb2006-01-31 15:53:55 -0800236 * This function calls the transition notifiers and the "adjust_jiffies"
237 * function. It is called twice on all CPU frequency changes that have
Dave Jones32ee8c32006-02-28 00:43:23 -0500238 * external effects.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 */
240void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state)
241{
Dave Jonese4472cb2006-01-31 15:53:55 -0800242 struct cpufreq_policy *policy;
243
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 BUG_ON(irqs_disabled());
245
246 freqs->flags = cpufreq_driver->flags;
Dave Jonese4472cb2006-01-31 15:53:55 -0800247 dprintk("notification %u of frequency transition to %u kHz\n",
248 state, freqs->new);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
250 down_read(&cpufreq_notifier_rwsem);
Dave Jonese4472cb2006-01-31 15:53:55 -0800251
252 policy = cpufreq_cpu_data[freqs->cpu];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 switch (state) {
Dave Jonese4472cb2006-01-31 15:53:55 -0800254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 case CPUFREQ_PRECHANGE:
Dave Jones32ee8c32006-02-28 00:43:23 -0500256 /* detect if the driver reported a value as "old frequency"
Dave Jonese4472cb2006-01-31 15:53:55 -0800257 * which is not equal to what the cpufreq core thinks is
258 * "old frequency".
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 */
260 if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
Dave Jonese4472cb2006-01-31 15:53:55 -0800261 if ((policy) && (policy->cpu == freqs->cpu) &&
262 (policy->cur) && (policy->cur != freqs->old)) {
263 dprintk(KERN_WARNING "Warning: CPU frequency is"
264 " %u, cpufreq assumed %u kHz.\n",
265 freqs->old, policy->cur);
266 freqs->old = policy->cur;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 }
268 }
Dave Jonese4472cb2006-01-31 15:53:55 -0800269 notifier_call_chain(&cpufreq_transition_notifier_list,
270 CPUFREQ_PRECHANGE, freqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 adjust_jiffies(CPUFREQ_PRECHANGE, freqs);
272 break;
Dave Jonese4472cb2006-01-31 15:53:55 -0800273
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 case CPUFREQ_POSTCHANGE:
275 adjust_jiffies(CPUFREQ_POSTCHANGE, freqs);
Dave Jonese4472cb2006-01-31 15:53:55 -0800276 notifier_call_chain(&cpufreq_transition_notifier_list,
277 CPUFREQ_POSTCHANGE, freqs);
278 if (likely(policy) && likely(policy->cpu == freqs->cpu))
279 policy->cur = freqs->new;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 break;
281 }
282 up_read(&cpufreq_notifier_rwsem);
283}
284EXPORT_SYMBOL_GPL(cpufreq_notify_transition);
285
286
287
288/*********************************************************************
289 * SYSFS INTERFACE *
290 *********************************************************************/
291
292/**
293 * cpufreq_parse_governor - parse a governor string
294 */
295static int cpufreq_parse_governor (char *str_governor, unsigned int *policy,
296 struct cpufreq_governor **governor)
297{
298 if (!cpufreq_driver)
299 return -EINVAL;
300 if (cpufreq_driver->setpolicy) {
301 if (!strnicmp(str_governor, "performance", CPUFREQ_NAME_LEN)) {
302 *policy = CPUFREQ_POLICY_PERFORMANCE;
303 return 0;
304 } else if (!strnicmp(str_governor, "powersave", CPUFREQ_NAME_LEN)) {
305 *policy = CPUFREQ_POLICY_POWERSAVE;
306 return 0;
307 }
308 return -EINVAL;
309 } else {
310 struct cpufreq_governor *t;
akpm@osdl.org3fc54d32006-01-13 15:54:22 -0800311 mutex_lock(&cpufreq_governor_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 if (!cpufreq_driver || !cpufreq_driver->target)
313 goto out;
314 list_for_each_entry(t, &cpufreq_governor_list, governor_list) {
315 if (!strnicmp(str_governor,t->name,CPUFREQ_NAME_LEN)) {
316 *governor = t;
akpm@osdl.org3fc54d32006-01-13 15:54:22 -0800317 mutex_unlock(&cpufreq_governor_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 return 0;
319 }
320 }
Dave Jones7d5e3502006-02-02 17:03:42 -0500321out:
akpm@osdl.org3fc54d32006-01-13 15:54:22 -0800322 mutex_unlock(&cpufreq_governor_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 }
324 return -EINVAL;
325}
326EXPORT_SYMBOL_GPL(cpufreq_parse_governor);
327
328
329/* drivers/base/cpu.c */
330extern struct sysdev_class cpu_sysdev_class;
331
332
333/**
334 * cpufreq_per_cpu_attr_read() / show_##file_name() - print out cpufreq information
335 *
336 * Write out information from cpufreq_driver->policy[cpu]; object must be
337 * "unsigned int".
338 */
339
Dave Jones32ee8c32006-02-28 00:43:23 -0500340#define show_one(file_name, object) \
341static ssize_t show_##file_name \
342(struct cpufreq_policy * policy, char *buf) \
343{ \
344 return sprintf (buf, "%u\n", policy->object); \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345}
346
347show_one(cpuinfo_min_freq, cpuinfo.min_freq);
348show_one(cpuinfo_max_freq, cpuinfo.max_freq);
349show_one(scaling_min_freq, min);
350show_one(scaling_max_freq, max);
351show_one(scaling_cur_freq, cur);
352
353/**
354 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
355 */
356#define store_one(file_name, object) \
357static ssize_t store_##file_name \
358(struct cpufreq_policy * policy, const char *buf, size_t count) \
359{ \
360 unsigned int ret = -EINVAL; \
361 struct cpufreq_policy new_policy; \
362 \
363 ret = cpufreq_get_policy(&new_policy, policy->cpu); \
364 if (ret) \
365 return -EINVAL; \
366 \
367 ret = sscanf (buf, "%u", &new_policy.object); \
368 if (ret != 1) \
369 return -EINVAL; \
370 \
371 ret = cpufreq_set_policy(&new_policy); \
372 \
373 return ret ? ret : count; \
374}
375
376store_one(scaling_min_freq,min);
377store_one(scaling_max_freq,max);
378
379/**
380 * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
381 */
382static ssize_t show_cpuinfo_cur_freq (struct cpufreq_policy * policy, char *buf)
383{
384 unsigned int cur_freq = cpufreq_get(policy->cpu);
385 if (!cur_freq)
386 return sprintf(buf, "<unknown>");
387 return sprintf(buf, "%u\n", cur_freq);
388}
389
390
391/**
392 * show_scaling_governor - show the current policy for the specified CPU
393 */
394static ssize_t show_scaling_governor (struct cpufreq_policy * policy, char *buf)
395{
396 if(policy->policy == CPUFREQ_POLICY_POWERSAVE)
397 return sprintf(buf, "powersave\n");
398 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE)
399 return sprintf(buf, "performance\n");
400 else if (policy->governor)
401 return scnprintf(buf, CPUFREQ_NAME_LEN, "%s\n", policy->governor->name);
402 return -EINVAL;
403}
404
405
406/**
407 * store_scaling_governor - store policy for the specified CPU
408 */
Dave Jones32ee8c32006-02-28 00:43:23 -0500409static ssize_t store_scaling_governor (struct cpufreq_policy * policy,
410 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
412 unsigned int ret = -EINVAL;
413 char str_governor[16];
414 struct cpufreq_policy new_policy;
415
416 ret = cpufreq_get_policy(&new_policy, policy->cpu);
417 if (ret)
418 return ret;
419
420 ret = sscanf (buf, "%15s", str_governor);
421 if (ret != 1)
422 return -EINVAL;
423
424 if (cpufreq_parse_governor(str_governor, &new_policy.policy, &new_policy.governor))
425 return -EINVAL;
426
427 ret = cpufreq_set_policy(&new_policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 return ret ? ret : count;
429}
430
431/**
432 * show_scaling_driver - show the cpufreq driver currently loaded
433 */
434static ssize_t show_scaling_driver (struct cpufreq_policy * policy, char *buf)
435{
436 return scnprintf(buf, CPUFREQ_NAME_LEN, "%s\n", cpufreq_driver->name);
437}
438
439/**
440 * show_scaling_available_governors - show the available CPUfreq governors
441 */
442static ssize_t show_scaling_available_governors (struct cpufreq_policy * policy,
443 char *buf)
444{
445 ssize_t i = 0;
446 struct cpufreq_governor *t;
447
448 if (!cpufreq_driver->target) {
449 i += sprintf(buf, "performance powersave");
450 goto out;
451 }
452
453 list_for_each_entry(t, &cpufreq_governor_list, governor_list) {
454 if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char)) - (CPUFREQ_NAME_LEN + 2)))
455 goto out;
456 i += scnprintf(&buf[i], CPUFREQ_NAME_LEN, "%s ", t->name);
457 }
Dave Jones7d5e3502006-02-02 17:03:42 -0500458out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 i += sprintf(&buf[i], "\n");
460 return i;
461}
462/**
463 * show_affected_cpus - show the CPUs affected by each transition
464 */
465static ssize_t show_affected_cpus (struct cpufreq_policy * policy, char *buf)
466{
467 ssize_t i = 0;
468 unsigned int cpu;
469
470 for_each_cpu_mask(cpu, policy->cpus) {
471 if (i)
472 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " ");
473 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu);
474 if (i >= (PAGE_SIZE - 5))
475 break;
476 }
477 i += sprintf(&buf[i], "\n");
478 return i;
479}
480
481
482#define define_one_ro(_name) \
483static struct freq_attr _name = \
484__ATTR(_name, 0444, show_##_name, NULL)
485
486#define define_one_ro0400(_name) \
487static struct freq_attr _name = \
488__ATTR(_name, 0400, show_##_name, NULL)
489
490#define define_one_rw(_name) \
491static struct freq_attr _name = \
492__ATTR(_name, 0644, show_##_name, store_##_name)
493
494define_one_ro0400(cpuinfo_cur_freq);
495define_one_ro(cpuinfo_min_freq);
496define_one_ro(cpuinfo_max_freq);
497define_one_ro(scaling_available_governors);
498define_one_ro(scaling_driver);
499define_one_ro(scaling_cur_freq);
500define_one_ro(affected_cpus);
501define_one_rw(scaling_min_freq);
502define_one_rw(scaling_max_freq);
503define_one_rw(scaling_governor);
504
505static struct attribute * default_attrs[] = {
506 &cpuinfo_min_freq.attr,
507 &cpuinfo_max_freq.attr,
508 &scaling_min_freq.attr,
509 &scaling_max_freq.attr,
510 &affected_cpus.attr,
511 &scaling_governor.attr,
512 &scaling_driver.attr,
513 &scaling_available_governors.attr,
514 NULL
515};
516
517#define to_policy(k) container_of(k,struct cpufreq_policy,kobj)
518#define to_attr(a) container_of(a,struct freq_attr,attr)
519
520static ssize_t show(struct kobject * kobj, struct attribute * attr ,char * buf)
521{
522 struct cpufreq_policy * policy = to_policy(kobj);
523 struct freq_attr * fattr = to_attr(attr);
524 ssize_t ret;
525 policy = cpufreq_cpu_get(policy->cpu);
526 if (!policy)
527 return -EINVAL;
Dmitry Torokhov70f28172005-04-29 01:27:34 -0500528 ret = fattr->show ? fattr->show(policy,buf) : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 cpufreq_cpu_put(policy);
530 return ret;
531}
532
Dave Jones32ee8c32006-02-28 00:43:23 -0500533static ssize_t store(struct kobject * kobj, struct attribute * attr,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 const char * buf, size_t count)
535{
536 struct cpufreq_policy * policy = to_policy(kobj);
537 struct freq_attr * fattr = to_attr(attr);
538 ssize_t ret;
539 policy = cpufreq_cpu_get(policy->cpu);
540 if (!policy)
541 return -EINVAL;
Dmitry Torokhov70f28172005-04-29 01:27:34 -0500542 ret = fattr->store ? fattr->store(policy,buf,count) : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 cpufreq_cpu_put(policy);
544 return ret;
545}
546
547static void cpufreq_sysfs_release(struct kobject * kobj)
548{
549 struct cpufreq_policy * policy = to_policy(kobj);
550 dprintk("last reference is dropped\n");
551 complete(&policy->kobj_unregister);
552}
553
554static struct sysfs_ops sysfs_ops = {
555 .show = show,
556 .store = store,
557};
558
559static struct kobj_type ktype_cpufreq = {
560 .sysfs_ops = &sysfs_ops,
561 .default_attrs = default_attrs,
562 .release = cpufreq_sysfs_release,
563};
564
565
566/**
567 * cpufreq_add_dev - add a CPU device
568 *
Dave Jones32ee8c32006-02-28 00:43:23 -0500569 * Adds the cpufreq interface for a CPU device.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 */
571static int cpufreq_add_dev (struct sys_device * sys_dev)
572{
573 unsigned int cpu = sys_dev->id;
574 int ret = 0;
575 struct cpufreq_policy new_policy;
576 struct cpufreq_policy *policy;
577 struct freq_attr **drv_attr;
Dave Jones8ff69732006-03-05 03:37:23 -0500578 struct sys_device *cpu_sys_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 unsigned long flags;
580 unsigned int j;
Dave Jones8ff69732006-03-05 03:37:23 -0500581#ifdef CONFIG_SMP
582 struct cpufreq_policy *managed_policy;
583#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Ashok Rajc32b6b82005-10-30 14:59:54 -0800585 if (cpu_is_offline(cpu))
586 return 0;
587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 cpufreq_debug_disable_ratelimit();
589 dprintk("adding CPU %u\n", cpu);
590
591#ifdef CONFIG_SMP
592 /* check whether a different CPU already registered this
593 * CPU because it is in the same boat. */
594 policy = cpufreq_cpu_get(cpu);
595 if (unlikely(policy)) {
Dave Jones8ff69732006-03-05 03:37:23 -0500596 cpufreq_cpu_put(policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 cpufreq_debug_enable_ratelimit();
598 return 0;
599 }
600#endif
601
602 if (!try_module_get(cpufreq_driver->owner)) {
603 ret = -EINVAL;
604 goto module_out;
605 }
606
Dave Jonese98df502005-10-20 15:17:43 -0700607 policy = kzalloc(sizeof(struct cpufreq_policy), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 if (!policy) {
609 ret = -ENOMEM;
610 goto nomem_out;
611 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613 policy->cpu = cpu;
614 policy->cpus = cpumask_of_cpu(cpu);
615
Arjan van de Ven83933af2006-01-14 16:01:49 +0100616 mutex_init(&policy->lock);
617 mutex_lock(&policy->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 init_completion(&policy->kobj_unregister);
619 INIT_WORK(&policy->update, handle_update, (void *)(long)cpu);
620
621 /* call driver. From then on the cpufreq must be able
622 * to accept all calls to ->verify and ->setpolicy for this CPU
623 */
624 ret = cpufreq_driver->init(policy);
625 if (ret) {
626 dprintk("initialization failed\n");
Andrew Mortonf3876c12006-01-18 13:40:54 -0800627 mutex_unlock(&policy->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 goto err_out;
629 }
630
Dave Jones8ff69732006-03-05 03:37:23 -0500631#ifdef CONFIG_SMP
632 for_each_cpu_mask(j, policy->cpus) {
633 if (cpu == j)
634 continue;
635
636 /* check for existing affected CPUs. They may not be aware
637 * of it due to CPU Hotplug.
638 */
639 managed_policy = cpufreq_cpu_get(j);
640 if (unlikely(managed_policy)) {
641 spin_lock_irqsave(&cpufreq_driver_lock, flags);
642 managed_policy->cpus = policy->cpus;
643 cpufreq_cpu_data[cpu] = managed_policy;
644 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
645
646 dprintk("CPU already managed, adding link\n");
647 sysfs_create_link(&sys_dev->kobj,
648 &managed_policy->kobj, "cpufreq");
649
650 cpufreq_debug_enable_ratelimit();
651 mutex_unlock(&policy->lock);
652 ret = 0;
653 goto err_out_driver_exit; /* call driver->exit() */
654 }
655 }
656#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 memcpy(&new_policy, policy, sizeof(struct cpufreq_policy));
658
659 /* prepare interface data */
660 policy->kobj.parent = &sys_dev->kobj;
661 policy->kobj.ktype = &ktype_cpufreq;
662 strlcpy(policy->kobj.name, "cpufreq", KOBJ_NAME_LEN);
663
664 ret = kobject_register(&policy->kobj);
Andrew Mortonf3876c12006-01-18 13:40:54 -0800665 if (ret) {
666 mutex_unlock(&policy->lock);
Venkatesh Pallipadi8085e1f2005-08-25 13:14:06 -0700667 goto err_out_driver_exit;
Andrew Mortonf3876c12006-01-18 13:40:54 -0800668 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 /* set up files for this cpu device */
670 drv_attr = cpufreq_driver->attr;
671 while ((drv_attr) && (*drv_attr)) {
672 sysfs_create_file(&policy->kobj, &((*drv_attr)->attr));
673 drv_attr++;
674 }
675 if (cpufreq_driver->get)
676 sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr);
677 if (cpufreq_driver->target)
678 sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr);
679
680 spin_lock_irqsave(&cpufreq_driver_lock, flags);
681 for_each_cpu_mask(j, policy->cpus)
682 cpufreq_cpu_data[j] = policy;
683 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
Dave Jones8ff69732006-03-05 03:37:23 -0500684
685 /* symlink affected CPUs */
686 for_each_cpu_mask(j, policy->cpus) {
687 if (j == cpu)
688 continue;
689 if (!cpu_online(j))
690 continue;
691
692 dprintk("CPU already managed, adding link\n");
693 cpufreq_cpu_get(cpu);
694 cpu_sys_dev = get_cpu_sysdev(j);
695 sysfs_create_link(&cpu_sys_dev->kobj, &policy->kobj,
696 "cpufreq");
697 }
698
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 policy->governor = NULL; /* to assure that the starting sequence is
700 * run in cpufreq_set_policy */
Arjan van de Ven83933af2006-01-14 16:01:49 +0100701 mutex_unlock(&policy->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
703 /* set default policy */
704
705 ret = cpufreq_set_policy(&new_policy);
706 if (ret) {
707 dprintk("setting policy failed\n");
708 goto err_out_unregister;
709 }
710
711 module_put(cpufreq_driver->owner);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 dprintk("initialization complete\n");
713 cpufreq_debug_enable_ratelimit();
714
715 return 0;
716
717
718err_out_unregister:
719 spin_lock_irqsave(&cpufreq_driver_lock, flags);
720 for_each_cpu_mask(j, policy->cpus)
721 cpufreq_cpu_data[j] = NULL;
722 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
723
724 kobject_unregister(&policy->kobj);
725 wait_for_completion(&policy->kobj_unregister);
726
Venkatesh Pallipadi8085e1f2005-08-25 13:14:06 -0700727err_out_driver_exit:
728 if (cpufreq_driver->exit)
729 cpufreq_driver->exit(policy);
730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731err_out:
732 kfree(policy);
733
734nomem_out:
735 module_put(cpufreq_driver->owner);
Ashok Rajc32b6b82005-10-30 14:59:54 -0800736module_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 cpufreq_debug_enable_ratelimit();
738 return ret;
739}
740
741
742/**
743 * cpufreq_remove_dev - remove a CPU device
744 *
745 * Removes the cpufreq interface for a CPU device.
746 */
747static int cpufreq_remove_dev (struct sys_device * sys_dev)
748{
749 unsigned int cpu = sys_dev->id;
750 unsigned long flags;
751 struct cpufreq_policy *data;
752#ifdef CONFIG_SMP
Grant Coadye738cf62005-11-21 21:32:28 -0800753 struct sys_device *cpu_sys_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 unsigned int j;
755#endif
756
757 cpufreq_debug_disable_ratelimit();
758 dprintk("unregistering CPU %u\n", cpu);
759
760 spin_lock_irqsave(&cpufreq_driver_lock, flags);
761 data = cpufreq_cpu_data[cpu];
762
763 if (!data) {
764 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 cpufreq_debug_enable_ratelimit();
766 return -EINVAL;
767 }
768 cpufreq_cpu_data[cpu] = NULL;
769
770
771#ifdef CONFIG_SMP
772 /* if this isn't the CPU which is the parent of the kobj, we
Dave Jones32ee8c32006-02-28 00:43:23 -0500773 * only need to unlink, put and exit
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 */
775 if (unlikely(cpu != data->cpu)) {
776 dprintk("removing link\n");
Dave Jones8ff69732006-03-05 03:37:23 -0500777 cpu_clear(cpu, data->cpus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
779 sysfs_remove_link(&sys_dev->kobj, "cpufreq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 cpufreq_cpu_put(data);
781 cpufreq_debug_enable_ratelimit();
782 return 0;
783 }
784#endif
785
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 if (!kobject_get(&data->kobj)) {
788 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
789 cpufreq_debug_enable_ratelimit();
Dave Jones32ee8c32006-02-28 00:43:23 -0500790 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 }
792
793#ifdef CONFIG_SMP
794 /* if we have other CPUs still registered, we need to unlink them,
795 * or else wait_for_completion below will lock up. Clean the
796 * cpufreq_cpu_data[] while holding the lock, and remove the sysfs
797 * links afterwards.
798 */
799 if (unlikely(cpus_weight(data->cpus) > 1)) {
800 for_each_cpu_mask(j, data->cpus) {
801 if (j == cpu)
802 continue;
803 cpufreq_cpu_data[j] = NULL;
804 }
805 }
806
807 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
808
809 if (unlikely(cpus_weight(data->cpus) > 1)) {
810 for_each_cpu_mask(j, data->cpus) {
811 if (j == cpu)
812 continue;
813 dprintk("removing link for cpu %u\n", j);
Ashok Rajd434fca2005-10-30 14:59:52 -0800814 cpu_sys_dev = get_cpu_sysdev(j);
815 sysfs_remove_link(&cpu_sys_dev->kobj, "cpufreq");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 cpufreq_cpu_put(data);
817 }
818 }
819#else
820 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
821#endif
822
Arjan van de Ven83933af2006-01-14 16:01:49 +0100823 mutex_lock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 if (cpufreq_driver->target)
825 __cpufreq_governor(data, CPUFREQ_GOV_STOP);
Arjan van de Ven83933af2006-01-14 16:01:49 +0100826 mutex_unlock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827
828 kobject_unregister(&data->kobj);
829
830 kobject_put(&data->kobj);
831
832 /* we need to make sure that the underlying kobj is actually
Dave Jones32ee8c32006-02-28 00:43:23 -0500833 * not referenced anymore by anybody before we proceed with
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 * unloading.
835 */
836 dprintk("waiting for dropping of refcount\n");
837 wait_for_completion(&data->kobj_unregister);
838 dprintk("wait complete\n");
839
840 if (cpufreq_driver->exit)
841 cpufreq_driver->exit(data);
842
843 kfree(data);
844
845 cpufreq_debug_enable_ratelimit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 return 0;
847}
848
849
850static void handle_update(void *data)
851{
852 unsigned int cpu = (unsigned int)(long)data;
853 dprintk("handle_update for cpu %u called\n", cpu);
854 cpufreq_update_policy(cpu);
855}
856
857/**
858 * cpufreq_out_of_sync - If actual and saved CPU frequency differs, we're in deep trouble.
859 * @cpu: cpu number
860 * @old_freq: CPU frequency the kernel thinks the CPU runs at
861 * @new_freq: CPU frequency the CPU actually runs at
862 *
863 * We adjust to current frequency first, and need to clean up later. So either call
864 * to cpufreq_update_policy() or schedule handle_update()).
865 */
866static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq, unsigned int new_freq)
867{
868 struct cpufreq_freqs freqs;
869
Dave Jones78ee9982005-05-31 19:03:43 -0700870 dprintk(KERN_WARNING "Warning: CPU frequency out of sync: cpufreq and timing "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 "core thinks of %u, is %u kHz.\n", old_freq, new_freq);
872
873 freqs.cpu = cpu;
874 freqs.old = old_freq;
875 freqs.new = new_freq;
876 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
877 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
878}
879
880
Dave Jones32ee8c32006-02-28 00:43:23 -0500881/**
Venkatesh Pallipadi95235ca2005-12-02 10:43:20 -0800882 * cpufreq_quick_get - get the CPU frequency (in kHz) frpm policy->cur
883 * @cpu: CPU number
884 *
885 * This is the last known freq, without actually getting it from the driver.
886 * Return value will be same as what is shown in scaling_cur_freq in sysfs.
887 */
888unsigned int cpufreq_quick_get(unsigned int cpu)
889{
890 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
891 unsigned int ret = 0;
892
893 if (policy) {
Arjan van de Ven83933af2006-01-14 16:01:49 +0100894 mutex_lock(&policy->lock);
Venkatesh Pallipadi95235ca2005-12-02 10:43:20 -0800895 ret = policy->cur;
Arjan van de Ven83933af2006-01-14 16:01:49 +0100896 mutex_unlock(&policy->lock);
Venkatesh Pallipadi95235ca2005-12-02 10:43:20 -0800897 cpufreq_cpu_put(policy);
898 }
899
900 return (ret);
901}
902EXPORT_SYMBOL(cpufreq_quick_get);
903
904
Dave Jones32ee8c32006-02-28 00:43:23 -0500905/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 * cpufreq_get - get the current CPU frequency (in kHz)
907 * @cpu: CPU number
908 *
909 * Get the CPU current (static) CPU frequency
910 */
911unsigned int cpufreq_get(unsigned int cpu)
912{
913 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
914 unsigned int ret = 0;
915
916 if (!policy)
917 return 0;
918
919 if (!cpufreq_driver->get)
920 goto out;
921
Arjan van de Ven83933af2006-01-14 16:01:49 +0100922 mutex_lock(&policy->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923
924 ret = cpufreq_driver->get(cpu);
925
Dave Jones7d5e3502006-02-02 17:03:42 -0500926 if (ret && policy->cur && !(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927 /* verify no discrepancy between actual and saved value exists */
928 if (unlikely(ret != policy->cur)) {
929 cpufreq_out_of_sync(cpu, policy->cur, ret);
930 schedule_work(&policy->update);
931 }
932 }
933
Arjan van de Ven83933af2006-01-14 16:01:49 +0100934 mutex_unlock(&policy->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
Dave Jones7d5e3502006-02-02 17:03:42 -0500936out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 cpufreq_cpu_put(policy);
938
939 return (ret);
940}
941EXPORT_SYMBOL(cpufreq_get);
942
943
944/**
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -0700945 * cpufreq_suspend - let the low level driver prepare for suspend
946 */
947
Bernard Blackhame00d99672005-07-07 17:56:42 -0700948static int cpufreq_suspend(struct sys_device * sysdev, pm_message_t pmsg)
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -0700949{
950 int cpu = sysdev->id;
951 unsigned int ret = 0;
952 unsigned int cur_freq = 0;
953 struct cpufreq_policy *cpu_policy;
954
955 dprintk("resuming cpu %u\n", cpu);
956
957 if (!cpu_online(cpu))
958 return 0;
959
960 /* we may be lax here as interrupts are off. Nonetheless
961 * we need to grab the correct cpu policy, as to check
962 * whether we really run on this CPU.
963 */
964
965 cpu_policy = cpufreq_cpu_get(cpu);
966 if (!cpu_policy)
967 return -EINVAL;
968
969 /* only handle each CPU group once */
970 if (unlikely(cpu_policy->cpu != cpu)) {
971 cpufreq_cpu_put(cpu_policy);
972 return 0;
973 }
974
975 if (cpufreq_driver->suspend) {
Bernard Blackhame00d99672005-07-07 17:56:42 -0700976 ret = cpufreq_driver->suspend(cpu_policy, pmsg);
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -0700977 if (ret) {
978 printk(KERN_ERR "cpufreq: suspend failed in ->suspend "
979 "step on CPU %u\n", cpu_policy->cpu);
980 cpufreq_cpu_put(cpu_policy);
981 return ret;
982 }
983 }
984
985
986 if (cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)
987 goto out;
988
989 if (cpufreq_driver->get)
990 cur_freq = cpufreq_driver->get(cpu_policy->cpu);
991
992 if (!cur_freq || !cpu_policy->cur) {
993 printk(KERN_ERR "cpufreq: suspend failed to assert current "
994 "frequency is what timing core thinks it is.\n");
995 goto out;
996 }
997
998 if (unlikely(cur_freq != cpu_policy->cur)) {
999 struct cpufreq_freqs freqs;
1000
1001 if (!(cpufreq_driver->flags & CPUFREQ_PM_NO_WARN))
Dave Jones78ee9982005-05-31 19:03:43 -07001002 dprintk(KERN_DEBUG "Warning: CPU frequency is %u, "
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -07001003 "cpufreq assumed %u kHz.\n",
1004 cur_freq, cpu_policy->cur);
1005
1006 freqs.cpu = cpu;
1007 freqs.old = cpu_policy->cur;
1008 freqs.new = cur_freq;
1009
1010 notifier_call_chain(&cpufreq_transition_notifier_list,
1011 CPUFREQ_SUSPENDCHANGE, &freqs);
1012 adjust_jiffies(CPUFREQ_SUSPENDCHANGE, &freqs);
1013
1014 cpu_policy->cur = cur_freq;
1015 }
1016
Dave Jones7d5e3502006-02-02 17:03:42 -05001017out:
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -07001018 cpufreq_cpu_put(cpu_policy);
1019 return 0;
1020}
1021
1022/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023 * cpufreq_resume - restore proper CPU frequency handling after resume
1024 *
1025 * 1.) resume CPUfreq hardware support (cpufreq_driver->resume())
1026 * 2.) if ->target and !CPUFREQ_CONST_LOOPS: verify we're in sync
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -07001027 * 3.) schedule call cpufreq_update_policy() ASAP as interrupts are
1028 * restored.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 */
1030static int cpufreq_resume(struct sys_device * sysdev)
1031{
1032 int cpu = sysdev->id;
1033 unsigned int ret = 0;
1034 struct cpufreq_policy *cpu_policy;
1035
1036 dprintk("resuming cpu %u\n", cpu);
1037
1038 if (!cpu_online(cpu))
1039 return 0;
1040
1041 /* we may be lax here as interrupts are off. Nonetheless
1042 * we need to grab the correct cpu policy, as to check
1043 * whether we really run on this CPU.
1044 */
1045
1046 cpu_policy = cpufreq_cpu_get(cpu);
1047 if (!cpu_policy)
1048 return -EINVAL;
1049
1050 /* only handle each CPU group once */
1051 if (unlikely(cpu_policy->cpu != cpu)) {
1052 cpufreq_cpu_put(cpu_policy);
1053 return 0;
1054 }
1055
1056 if (cpufreq_driver->resume) {
1057 ret = cpufreq_driver->resume(cpu_policy);
1058 if (ret) {
1059 printk(KERN_ERR "cpufreq: resume failed in ->resume "
1060 "step on CPU %u\n", cpu_policy->cpu);
1061 cpufreq_cpu_put(cpu_policy);
1062 return ret;
1063 }
1064 }
1065
1066 if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
1067 unsigned int cur_freq = 0;
1068
1069 if (cpufreq_driver->get)
1070 cur_freq = cpufreq_driver->get(cpu_policy->cpu);
1071
1072 if (!cur_freq || !cpu_policy->cur) {
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -07001073 printk(KERN_ERR "cpufreq: resume failed to assert "
1074 "current frequency is what timing core "
1075 "thinks it is.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 goto out;
1077 }
1078
1079 if (unlikely(cur_freq != cpu_policy->cur)) {
1080 struct cpufreq_freqs freqs;
1081
Benjamin Herrenschmidtac09f692005-05-02 16:25:10 +10001082 if (!(cpufreq_driver->flags & CPUFREQ_PM_NO_WARN))
Dave Jones78ee9982005-05-31 19:03:43 -07001083 dprintk(KERN_WARNING "Warning: CPU frequency"
Benjamin Herrenschmidtac09f692005-05-02 16:25:10 +10001084 "is %u, cpufreq assumed %u kHz.\n",
1085 cur_freq, cpu_policy->cur);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
1087 freqs.cpu = cpu;
1088 freqs.old = cpu_policy->cur;
1089 freqs.new = cur_freq;
1090
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -07001091 notifier_call_chain(&cpufreq_transition_notifier_list,
1092 CPUFREQ_RESUMECHANGE, &freqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 adjust_jiffies(CPUFREQ_RESUMECHANGE, &freqs);
1094
1095 cpu_policy->cur = cur_freq;
1096 }
1097 }
1098
1099out:
1100 schedule_work(&cpu_policy->update);
1101 cpufreq_cpu_put(cpu_policy);
1102 return ret;
1103}
1104
1105static struct sysdev_driver cpufreq_sysdev_driver = {
1106 .add = cpufreq_add_dev,
1107 .remove = cpufreq_remove_dev,
Benjamin Herrenschmidt42d4dc32005-04-29 07:40:12 -07001108 .suspend = cpufreq_suspend,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 .resume = cpufreq_resume,
1110};
1111
1112
1113/*********************************************************************
1114 * NOTIFIER LISTS INTERFACE *
1115 *********************************************************************/
1116
1117/**
1118 * cpufreq_register_notifier - register a driver with cpufreq
1119 * @nb: notifier function to register
1120 * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER
1121 *
Dave Jones32ee8c32006-02-28 00:43:23 -05001122 * Add a driver to one of two lists: either a list of drivers that
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123 * are notified about clock rate changes (once before and once after
1124 * the transition), or a list of drivers that are notified about
1125 * changes in cpufreq policy.
1126 *
1127 * This function may sleep, and has the same return conditions as
1128 * notifier_chain_register.
1129 */
1130int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list)
1131{
1132 int ret;
1133
1134 down_write(&cpufreq_notifier_rwsem);
1135 switch (list) {
1136 case CPUFREQ_TRANSITION_NOTIFIER:
1137 ret = notifier_chain_register(&cpufreq_transition_notifier_list, nb);
1138 break;
1139 case CPUFREQ_POLICY_NOTIFIER:
1140 ret = notifier_chain_register(&cpufreq_policy_notifier_list, nb);
1141 break;
1142 default:
1143 ret = -EINVAL;
1144 }
1145 up_write(&cpufreq_notifier_rwsem);
1146
1147 return ret;
1148}
1149EXPORT_SYMBOL(cpufreq_register_notifier);
1150
1151
1152/**
1153 * cpufreq_unregister_notifier - unregister a driver with cpufreq
1154 * @nb: notifier block to be unregistered
1155 * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER
1156 *
1157 * Remove a driver from the CPU frequency notifier list.
1158 *
1159 * This function may sleep, and has the same return conditions as
1160 * notifier_chain_unregister.
1161 */
1162int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list)
1163{
1164 int ret;
1165
1166 down_write(&cpufreq_notifier_rwsem);
1167 switch (list) {
1168 case CPUFREQ_TRANSITION_NOTIFIER:
1169 ret = notifier_chain_unregister(&cpufreq_transition_notifier_list, nb);
1170 break;
1171 case CPUFREQ_POLICY_NOTIFIER:
1172 ret = notifier_chain_unregister(&cpufreq_policy_notifier_list, nb);
1173 break;
1174 default:
1175 ret = -EINVAL;
1176 }
1177 up_write(&cpufreq_notifier_rwsem);
1178
1179 return ret;
1180}
1181EXPORT_SYMBOL(cpufreq_unregister_notifier);
1182
1183
1184/*********************************************************************
1185 * GOVERNORS *
1186 *********************************************************************/
1187
1188
1189int __cpufreq_driver_target(struct cpufreq_policy *policy,
1190 unsigned int target_freq,
1191 unsigned int relation)
1192{
1193 int retval = -EINVAL;
Ashok Rajc32b6b82005-10-30 14:59:54 -08001194
Ashok Raja9d9baa2005-11-28 13:43:46 -08001195 lock_cpu_hotplug();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 dprintk("target for CPU %u: %u kHz, relation %u\n", policy->cpu,
1197 target_freq, relation);
1198 if (cpu_online(policy->cpu) && cpufreq_driver->target)
1199 retval = cpufreq_driver->target(policy, target_freq, relation);
Ashok Raj90d45d12005-11-08 21:34:24 -08001200
Ashok Raja9d9baa2005-11-28 13:43:46 -08001201 unlock_cpu_hotplug();
Ashok Raj90d45d12005-11-08 21:34:24 -08001202
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 return retval;
1204}
1205EXPORT_SYMBOL_GPL(__cpufreq_driver_target);
1206
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207int cpufreq_driver_target(struct cpufreq_policy *policy,
1208 unsigned int target_freq,
1209 unsigned int relation)
1210{
Dave Jonescc993ca2005-07-28 09:43:56 -07001211 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212
1213 policy = cpufreq_cpu_get(policy->cpu);
1214 if (!policy)
1215 return -EINVAL;
1216
Arjan van de Ven83933af2006-01-14 16:01:49 +01001217 mutex_lock(&policy->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218
1219 ret = __cpufreq_driver_target(policy, target_freq, relation);
1220
Arjan van de Ven83933af2006-01-14 16:01:49 +01001221 mutex_unlock(&policy->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001222
1223 cpufreq_cpu_put(policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 return ret;
1225}
1226EXPORT_SYMBOL_GPL(cpufreq_driver_target);
1227
1228
1229static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event)
1230{
Dave Jonescc993ca2005-07-28 09:43:56 -07001231 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232
1233 if (!try_module_get(policy->governor->owner))
1234 return -EINVAL;
1235
1236 dprintk("__cpufreq_governor for CPU %u, event %u\n", policy->cpu, event);
1237 ret = policy->governor->governor(policy, event);
1238
1239 /* we keep one module reference alive for each CPU governed by this CPU */
1240 if ((event != CPUFREQ_GOV_START) || ret)
1241 module_put(policy->governor->owner);
1242 if ((event == CPUFREQ_GOV_STOP) && !ret)
1243 module_put(policy->governor->owner);
1244
1245 return ret;
1246}
1247
1248
1249int cpufreq_governor(unsigned int cpu, unsigned int event)
1250{
1251 int ret = 0;
1252 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1253
1254 if (!policy)
1255 return -EINVAL;
1256
Arjan van de Ven83933af2006-01-14 16:01:49 +01001257 mutex_lock(&policy->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 ret = __cpufreq_governor(policy, event);
Arjan van de Ven83933af2006-01-14 16:01:49 +01001259 mutex_unlock(&policy->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260
1261 cpufreq_cpu_put(policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 return ret;
1263}
1264EXPORT_SYMBOL_GPL(cpufreq_governor);
1265
1266
1267int cpufreq_register_governor(struct cpufreq_governor *governor)
1268{
1269 struct cpufreq_governor *t;
1270
1271 if (!governor)
1272 return -EINVAL;
1273
akpm@osdl.org3fc54d32006-01-13 15:54:22 -08001274 mutex_lock(&cpufreq_governor_mutex);
Dave Jones32ee8c32006-02-28 00:43:23 -05001275
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 list_for_each_entry(t, &cpufreq_governor_list, governor_list) {
1277 if (!strnicmp(governor->name,t->name,CPUFREQ_NAME_LEN)) {
akpm@osdl.org3fc54d32006-01-13 15:54:22 -08001278 mutex_unlock(&cpufreq_governor_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 return -EBUSY;
1280 }
1281 }
1282 list_add(&governor->governor_list, &cpufreq_governor_list);
1283
Dave Jones32ee8c32006-02-28 00:43:23 -05001284 mutex_unlock(&cpufreq_governor_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 return 0;
1286}
1287EXPORT_SYMBOL_GPL(cpufreq_register_governor);
1288
1289
1290void cpufreq_unregister_governor(struct cpufreq_governor *governor)
1291{
1292 if (!governor)
1293 return;
1294
akpm@osdl.org3fc54d32006-01-13 15:54:22 -08001295 mutex_lock(&cpufreq_governor_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 list_del(&governor->governor_list);
akpm@osdl.org3fc54d32006-01-13 15:54:22 -08001297 mutex_unlock(&cpufreq_governor_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 return;
1299}
1300EXPORT_SYMBOL_GPL(cpufreq_unregister_governor);
1301
1302
1303
1304/*********************************************************************
1305 * POLICY INTERFACE *
1306 *********************************************************************/
1307
1308/**
1309 * cpufreq_get_policy - get the current cpufreq_policy
1310 * @policy: struct cpufreq_policy into which the current cpufreq_policy is written
1311 *
1312 * Reads the current cpufreq policy.
1313 */
1314int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)
1315{
1316 struct cpufreq_policy *cpu_policy;
1317 if (!policy)
1318 return -EINVAL;
1319
1320 cpu_policy = cpufreq_cpu_get(cpu);
1321 if (!cpu_policy)
1322 return -EINVAL;
1323
Arjan van de Ven83933af2006-01-14 16:01:49 +01001324 mutex_lock(&cpu_policy->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 memcpy(policy, cpu_policy, sizeof(struct cpufreq_policy));
Arjan van de Ven83933af2006-01-14 16:01:49 +01001326 mutex_unlock(&cpu_policy->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
1328 cpufreq_cpu_put(cpu_policy);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001329 return 0;
1330}
1331EXPORT_SYMBOL(cpufreq_get_policy);
1332
1333
1334static int __cpufreq_set_policy(struct cpufreq_policy *data, struct cpufreq_policy *policy)
1335{
1336 int ret = 0;
1337
1338 cpufreq_debug_disable_ratelimit();
1339 dprintk("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu,
1340 policy->min, policy->max);
1341
Dave Jones7d5e3502006-02-02 17:03:42 -05001342 memcpy(&policy->cpuinfo, &data->cpuinfo, sizeof(struct cpufreq_cpuinfo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
1344 /* verify the cpu speed can be set within this limit */
1345 ret = cpufreq_driver->verify(policy);
1346 if (ret)
1347 goto error_out;
1348
1349 down_read(&cpufreq_notifier_rwsem);
1350
1351 /* adjust if necessary - all reasons */
1352 notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_ADJUST,
1353 policy);
1354
1355 /* adjust if necessary - hardware incompatibility*/
1356 notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_INCOMPATIBLE,
1357 policy);
1358
1359 /* verify the cpu speed can be set within this limit,
1360 which might be different to the first one */
1361 ret = cpufreq_driver->verify(policy);
1362 if (ret) {
1363 up_read(&cpufreq_notifier_rwsem);
1364 goto error_out;
1365 }
1366
1367 /* notification of the new policy */
1368 notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_NOTIFY,
1369 policy);
1370
1371 up_read(&cpufreq_notifier_rwsem);
1372
Dave Jones7d5e3502006-02-02 17:03:42 -05001373 data->min = policy->min;
1374 data->max = policy->max;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
1376 dprintk("new min and max freqs are %u - %u kHz\n", data->min, data->max);
1377
1378 if (cpufreq_driver->setpolicy) {
1379 data->policy = policy->policy;
1380 dprintk("setting range\n");
1381 ret = cpufreq_driver->setpolicy(policy);
1382 } else {
1383 if (policy->governor != data->governor) {
1384 /* save old, working values */
1385 struct cpufreq_governor *old_gov = data->governor;
1386
1387 dprintk("governor switch\n");
1388
1389 /* end old governor */
1390 if (data->governor)
1391 __cpufreq_governor(data, CPUFREQ_GOV_STOP);
1392
1393 /* start new governor */
1394 data->governor = policy->governor;
1395 if (__cpufreq_governor(data, CPUFREQ_GOV_START)) {
1396 /* new governor failed, so re-start old one */
1397 dprintk("starting governor %s failed\n", data->governor->name);
1398 if (old_gov) {
1399 data->governor = old_gov;
1400 __cpufreq_governor(data, CPUFREQ_GOV_START);
1401 }
1402 ret = -EINVAL;
1403 goto error_out;
1404 }
1405 /* might be a policy change, too, so fall through */
1406 }
1407 dprintk("governor: change or update limits\n");
1408 __cpufreq_governor(data, CPUFREQ_GOV_LIMITS);
1409 }
1410
Dave Jones7d5e3502006-02-02 17:03:42 -05001411error_out:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 cpufreq_debug_enable_ratelimit();
1413 return ret;
1414}
1415
1416/**
1417 * cpufreq_set_policy - set a new CPUFreq policy
1418 * @policy: policy to be set.
1419 *
1420 * Sets a new CPU frequency and voltage scaling policy.
1421 */
1422int cpufreq_set_policy(struct cpufreq_policy *policy)
1423{
1424 int ret = 0;
1425 struct cpufreq_policy *data;
1426
1427 if (!policy)
1428 return -EINVAL;
1429
1430 data = cpufreq_cpu_get(policy->cpu);
1431 if (!data)
1432 return -EINVAL;
1433
1434 /* lock this CPU */
Arjan van de Ven83933af2006-01-14 16:01:49 +01001435 mutex_lock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
1437 ret = __cpufreq_set_policy(data, policy);
1438 data->user_policy.min = data->min;
1439 data->user_policy.max = data->max;
1440 data->user_policy.policy = data->policy;
1441 data->user_policy.governor = data->governor;
1442
Arjan van de Ven83933af2006-01-14 16:01:49 +01001443 mutex_unlock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 cpufreq_cpu_put(data);
1445
1446 return ret;
1447}
1448EXPORT_SYMBOL(cpufreq_set_policy);
1449
1450
1451/**
1452 * cpufreq_update_policy - re-evaluate an existing cpufreq policy
1453 * @cpu: CPU which shall be re-evaluated
1454 *
1455 * Usefull for policy notifiers which have different necessities
1456 * at different times.
1457 */
1458int cpufreq_update_policy(unsigned int cpu)
1459{
1460 struct cpufreq_policy *data = cpufreq_cpu_get(cpu);
1461 struct cpufreq_policy policy;
1462 int ret = 0;
1463
1464 if (!data)
1465 return -ENODEV;
1466
Arjan van de Ven83933af2006-01-14 16:01:49 +01001467 mutex_lock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
1469 dprintk("updating policy for CPU %u\n", cpu);
Dave Jones7d5e3502006-02-02 17:03:42 -05001470 memcpy(&policy, data, sizeof(struct cpufreq_policy));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 policy.min = data->user_policy.min;
1472 policy.max = data->user_policy.max;
1473 policy.policy = data->user_policy.policy;
1474 policy.governor = data->user_policy.governor;
1475
Thomas Renninger0961dd02006-01-26 18:46:33 +01001476 /* BIOS might change freq behind our back
1477 -> ask driver for current freq and notify governors about a change */
1478 if (cpufreq_driver->get) {
1479 policy.cur = cpufreq_driver->get(cpu);
Thomas Renningera85f7bd2006-02-01 11:36:04 +01001480 if (!data->cur) {
1481 dprintk("Driver did not initialize current freq");
1482 data->cur = policy.cur;
1483 } else {
1484 if (data->cur != policy.cur)
1485 cpufreq_out_of_sync(cpu, data->cur, policy.cur);
1486 }
Thomas Renninger0961dd02006-01-26 18:46:33 +01001487 }
1488
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 ret = __cpufreq_set_policy(data, &policy);
1490
Arjan van de Ven83933af2006-01-14 16:01:49 +01001491 mutex_unlock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
1493 cpufreq_cpu_put(data);
1494 return ret;
1495}
1496EXPORT_SYMBOL(cpufreq_update_policy);
1497
Ashok Rajc32b6b82005-10-30 14:59:54 -08001498static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
1499 unsigned long action, void *hcpu)
1500{
1501 unsigned int cpu = (unsigned long)hcpu;
1502 struct cpufreq_policy *policy;
1503 struct sys_device *sys_dev;
1504
1505 sys_dev = get_cpu_sysdev(cpu);
1506
1507 if (sys_dev) {
1508 switch (action) {
1509 case CPU_ONLINE:
1510 cpufreq_add_dev(sys_dev);
1511 break;
1512 case CPU_DOWN_PREPARE:
1513 /*
1514 * We attempt to put this cpu in lowest frequency
1515 * possible before going down. This will permit
1516 * hardware-managed P-State to switch other related
1517 * threads to min or higher speeds if possible.
1518 */
1519 policy = cpufreq_cpu_data[cpu];
1520 if (policy) {
1521 cpufreq_driver_target(policy, policy->min,
1522 CPUFREQ_RELATION_H);
1523 }
1524 break;
1525 case CPU_DEAD:
1526 cpufreq_remove_dev(sys_dev);
1527 break;
1528 }
1529 }
1530 return NOTIFY_OK;
1531}
1532
1533static struct notifier_block cpufreq_cpu_notifier =
1534{
1535 .notifier_call = cpufreq_cpu_callback,
1536};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
1538/*********************************************************************
1539 * REGISTER / UNREGISTER CPUFREQ DRIVER *
1540 *********************************************************************/
1541
1542/**
1543 * cpufreq_register_driver - register a CPU Frequency driver
1544 * @driver_data: A struct cpufreq_driver containing the values#
1545 * submitted by the CPU Frequency driver.
1546 *
Dave Jones32ee8c32006-02-28 00:43:23 -05001547 * Registers a CPU Frequency driver to this core code. This code
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 * returns zero on success, -EBUSY when another driver got here first
Dave Jones32ee8c32006-02-28 00:43:23 -05001549 * (and isn't unregistered in the meantime).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 *
1551 */
1552int cpufreq_register_driver(struct cpufreq_driver *driver_data)
1553{
1554 unsigned long flags;
1555 int ret;
1556
1557 if (!driver_data || !driver_data->verify || !driver_data->init ||
1558 ((!driver_data->setpolicy) && (!driver_data->target)))
1559 return -EINVAL;
1560
1561 dprintk("trying to register driver %s\n", driver_data->name);
1562
1563 if (driver_data->setpolicy)
1564 driver_data->flags |= CPUFREQ_CONST_LOOPS;
1565
1566 spin_lock_irqsave(&cpufreq_driver_lock, flags);
1567 if (cpufreq_driver) {
1568 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1569 return -EBUSY;
1570 }
1571 cpufreq_driver = driver_data;
1572 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1573
1574 ret = sysdev_driver_register(&cpu_sysdev_class,&cpufreq_sysdev_driver);
1575
1576 if ((!ret) && !(cpufreq_driver->flags & CPUFREQ_STICKY)) {
1577 int i;
1578 ret = -ENODEV;
1579
1580 /* check for at least one working CPU */
1581 for (i=0; i<NR_CPUS; i++)
1582 if (cpufreq_cpu_data[i])
1583 ret = 0;
1584
1585 /* if all ->init() calls failed, unregister */
1586 if (ret) {
1587 dprintk("no CPU initialized for driver %s\n", driver_data->name);
1588 sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver);
1589
1590 spin_lock_irqsave(&cpufreq_driver_lock, flags);
1591 cpufreq_driver = NULL;
1592 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1593 }
1594 }
1595
1596 if (!ret) {
Ashok Rajc32b6b82005-10-30 14:59:54 -08001597 register_cpu_notifier(&cpufreq_cpu_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 dprintk("driver %s up and running\n", driver_data->name);
1599 cpufreq_debug_enable_ratelimit();
1600 }
1601
1602 return (ret);
1603}
1604EXPORT_SYMBOL_GPL(cpufreq_register_driver);
1605
1606
1607/**
1608 * cpufreq_unregister_driver - unregister the current CPUFreq driver
1609 *
Dave Jones32ee8c32006-02-28 00:43:23 -05001610 * Unregister the current CPUFreq driver. Only call this if you have
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 * the right to do so, i.e. if you have succeeded in initialising before!
1612 * Returns zero if successful, and -EINVAL if the cpufreq_driver is
1613 * currently not initialised.
1614 */
1615int cpufreq_unregister_driver(struct cpufreq_driver *driver)
1616{
1617 unsigned long flags;
1618
1619 cpufreq_debug_disable_ratelimit();
1620
1621 if (!cpufreq_driver || (driver != cpufreq_driver)) {
1622 cpufreq_debug_enable_ratelimit();
1623 return -EINVAL;
1624 }
1625
1626 dprintk("unregistering driver %s\n", driver->name);
1627
1628 sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver);
Ashok Rajc32b6b82005-10-30 14:59:54 -08001629 unregister_cpu_notifier(&cpufreq_cpu_notifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630
1631 spin_lock_irqsave(&cpufreq_driver_lock, flags);
1632 cpufreq_driver = NULL;
1633 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1634
1635 return 0;
1636}
1637EXPORT_SYMBOL_GPL(cpufreq_unregister_driver);