[ARM] 3035/1: RISCOS compat code fix
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / cpufreq / cpufreq.c
blob109d62ccf6514fe5475154ed821c7cb6bbefcbdf
1 /*
2 * linux/drivers/cpufreq/cpufreq.c
4 * Copyright (C) 2001 Russell King
5 * (C) 2002 - 2003 Dominik Brodowski <linux@brodo.de>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
13 #include <linux/config.h>
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/notifier.h>
18 #include <linux/cpufreq.h>
19 #include <linux/delay.h>
20 #include <linux/interrupt.h>
21 #include <linux/spinlock.h>
22 #include <linux/device.h>
23 #include <linux/slab.h>
24 #include <linux/cpu.h>
25 #include <linux/completion.h>
27 #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_CORE, "cpufreq-core", msg)
29 /**
30 * The "cpufreq driver" - the arch- or hardware-dependend low
31 * level driver of CPUFreq support, and its spinlock. This lock
32 * also protects the cpufreq_cpu_data array.
34 static struct cpufreq_driver *cpufreq_driver;
35 static struct cpufreq_policy *cpufreq_cpu_data[NR_CPUS];
36 static DEFINE_SPINLOCK(cpufreq_driver_lock);
39 /* we keep a copy of all ->add'ed CPU's struct sys_device here;
40 * as it is only accessed in ->add and ->remove, no lock or reference
41 * count is necessary.
43 static struct sys_device *cpu_sys_devices[NR_CPUS];
46 /* internal prototypes */
47 static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event);
48 static void handle_update(void *data);
49 static inline void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci);
51 /**
52 * Two notifier lists: the "policy" list is involved in the
53 * validation process for a new CPU frequency policy; the
54 * "transition" list for kernel code that needs to handle
55 * changes to devices when the CPU clock speed changes.
56 * The mutex locks both lists.
58 static struct notifier_block *cpufreq_policy_notifier_list;
59 static struct notifier_block *cpufreq_transition_notifier_list;
60 static DECLARE_RWSEM (cpufreq_notifier_rwsem);
63 static LIST_HEAD(cpufreq_governor_list);
64 static DECLARE_MUTEX (cpufreq_governor_sem);
66 struct cpufreq_policy * cpufreq_cpu_get(unsigned int cpu)
68 struct cpufreq_policy *data;
69 unsigned long flags;
71 if (cpu >= NR_CPUS)
72 goto err_out;
74 /* get the cpufreq driver */
75 spin_lock_irqsave(&cpufreq_driver_lock, flags);
77 if (!cpufreq_driver)
78 goto err_out_unlock;
80 if (!try_module_get(cpufreq_driver->owner))
81 goto err_out_unlock;
84 /* get the CPU */
85 data = cpufreq_cpu_data[cpu];
87 if (!data)
88 goto err_out_put_module;
90 if (!kobject_get(&data->kobj))
91 goto err_out_put_module;
94 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
96 return data;
98 err_out_put_module:
99 module_put(cpufreq_driver->owner);
100 err_out_unlock:
101 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
102 err_out:
103 return NULL;
105 EXPORT_SYMBOL_GPL(cpufreq_cpu_get);
107 void cpufreq_cpu_put(struct cpufreq_policy *data)
109 kobject_put(&data->kobj);
110 module_put(cpufreq_driver->owner);
112 EXPORT_SYMBOL_GPL(cpufreq_cpu_put);
115 /*********************************************************************
116 * UNIFIED DEBUG HELPERS *
117 *********************************************************************/
118 #ifdef CONFIG_CPU_FREQ_DEBUG
120 /* what part(s) of the CPUfreq subsystem are debugged? */
121 static unsigned int debug;
123 /* is the debug output ratelimit'ed using printk_ratelimit? User can
124 * set or modify this value.
126 static unsigned int debug_ratelimit = 1;
128 /* is the printk_ratelimit'ing enabled? It's enabled after a successful
129 * loading of a cpufreq driver, temporarily disabled when a new policy
130 * is set, and disabled upon cpufreq driver removal
132 static unsigned int disable_ratelimit = 1;
133 static DEFINE_SPINLOCK(disable_ratelimit_lock);
135 static inline void cpufreq_debug_enable_ratelimit(void)
137 unsigned long flags;
139 spin_lock_irqsave(&disable_ratelimit_lock, flags);
140 if (disable_ratelimit)
141 disable_ratelimit--;
142 spin_unlock_irqrestore(&disable_ratelimit_lock, flags);
145 static inline void cpufreq_debug_disable_ratelimit(void)
147 unsigned long flags;
149 spin_lock_irqsave(&disable_ratelimit_lock, flags);
150 disable_ratelimit++;
151 spin_unlock_irqrestore(&disable_ratelimit_lock, flags);
154 void cpufreq_debug_printk(unsigned int type, const char *prefix, const char *fmt, ...)
156 char s[256];
157 va_list args;
158 unsigned int len;
159 unsigned long flags;
161 WARN_ON(!prefix);
162 if (type & debug) {
163 spin_lock_irqsave(&disable_ratelimit_lock, flags);
164 if (!disable_ratelimit && debug_ratelimit && !printk_ratelimit()) {
165 spin_unlock_irqrestore(&disable_ratelimit_lock, flags);
166 return;
168 spin_unlock_irqrestore(&disable_ratelimit_lock, flags);
170 len = snprintf(s, 256, KERN_DEBUG "%s: ", prefix);
172 va_start(args, fmt);
173 len += vsnprintf(&s[len], (256 - len), fmt, args);
174 va_end(args);
176 printk(s);
178 WARN_ON(len < 5);
181 EXPORT_SYMBOL(cpufreq_debug_printk);
184 module_param(debug, uint, 0644);
185 MODULE_PARM_DESC(debug, "CPUfreq debugging: add 1 to debug core, 2 to debug drivers, and 4 to debug governors.");
187 module_param(debug_ratelimit, uint, 0644);
188 MODULE_PARM_DESC(debug_ratelimit, "CPUfreq debugging: set to 0 to disable ratelimiting.");
190 #else /* !CONFIG_CPU_FREQ_DEBUG */
192 static inline void cpufreq_debug_enable_ratelimit(void) { return; }
193 static inline void cpufreq_debug_disable_ratelimit(void) { return; }
195 #endif /* CONFIG_CPU_FREQ_DEBUG */
198 /*********************************************************************
199 * EXTERNALLY AFFECTING FREQUENCY CHANGES *
200 *********************************************************************/
203 * adjust_jiffies - adjust the system "loops_per_jiffy"
205 * This function alters the system "loops_per_jiffy" for the clock
206 * speed change. Note that loops_per_jiffy cannot be updated on SMP
207 * systems as each CPU might be scaled differently. So, use the arch
208 * per-CPU loops_per_jiffy value wherever possible.
210 #ifndef CONFIG_SMP
211 static unsigned long l_p_j_ref;
212 static unsigned int l_p_j_ref_freq;
214 static inline void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci)
216 if (ci->flags & CPUFREQ_CONST_LOOPS)
217 return;
219 if (!l_p_j_ref_freq) {
220 l_p_j_ref = loops_per_jiffy;
221 l_p_j_ref_freq = ci->old;
222 dprintk("saving %lu as reference value for loops_per_jiffy; freq is %u kHz\n", l_p_j_ref, l_p_j_ref_freq);
224 if ((val == CPUFREQ_PRECHANGE && ci->old < ci->new) ||
225 (val == CPUFREQ_POSTCHANGE && ci->old > ci->new) ||
226 (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE)) {
227 loops_per_jiffy = cpufreq_scale(l_p_j_ref, l_p_j_ref_freq, ci->new);
228 dprintk("scaling loops_per_jiffy to %lu for frequency %u kHz\n", loops_per_jiffy, ci->new);
231 #else
232 static inline void adjust_jiffies(unsigned long val, struct cpufreq_freqs *ci) { return; }
233 #endif
237 * cpufreq_notify_transition - call notifier chain and adjust_jiffies on frequency transition
239 * This function calls the transition notifiers and the "adjust_jiffies" function. It is called
240 * twice on all CPU frequency changes that have external effects.
242 void cpufreq_notify_transition(struct cpufreq_freqs *freqs, unsigned int state)
244 BUG_ON(irqs_disabled());
246 freqs->flags = cpufreq_driver->flags;
247 dprintk("notification %u of frequency transition to %u kHz\n", state, freqs->new);
249 down_read(&cpufreq_notifier_rwsem);
250 switch (state) {
251 case CPUFREQ_PRECHANGE:
252 /* detect if the driver reported a value as "old frequency" which
253 * is not equal to what the cpufreq core thinks is "old frequency".
255 if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
256 if ((likely(cpufreq_cpu_data[freqs->cpu])) &&
257 (likely(cpufreq_cpu_data[freqs->cpu]->cpu == freqs->cpu)) &&
258 (likely(cpufreq_cpu_data[freqs->cpu]->cur)) &&
259 (unlikely(freqs->old != cpufreq_cpu_data[freqs->cpu]->cur)))
261 dprintk(KERN_WARNING "Warning: CPU frequency is %u, "
262 "cpufreq assumed %u kHz.\n", freqs->old, cpufreq_cpu_data[freqs->cpu]->cur);
263 freqs->old = cpufreq_cpu_data[freqs->cpu]->cur;
266 notifier_call_chain(&cpufreq_transition_notifier_list, CPUFREQ_PRECHANGE, freqs);
267 adjust_jiffies(CPUFREQ_PRECHANGE, freqs);
268 break;
269 case CPUFREQ_POSTCHANGE:
270 adjust_jiffies(CPUFREQ_POSTCHANGE, freqs);
271 notifier_call_chain(&cpufreq_transition_notifier_list, CPUFREQ_POSTCHANGE, freqs);
272 if ((likely(cpufreq_cpu_data[freqs->cpu])) &&
273 (likely(cpufreq_cpu_data[freqs->cpu]->cpu == freqs->cpu)))
274 cpufreq_cpu_data[freqs->cpu]->cur = freqs->new;
275 break;
277 up_read(&cpufreq_notifier_rwsem);
279 EXPORT_SYMBOL_GPL(cpufreq_notify_transition);
283 /*********************************************************************
284 * SYSFS INTERFACE *
285 *********************************************************************/
288 * cpufreq_parse_governor - parse a governor string
290 static int cpufreq_parse_governor (char *str_governor, unsigned int *policy,
291 struct cpufreq_governor **governor)
293 if (!cpufreq_driver)
294 return -EINVAL;
295 if (cpufreq_driver->setpolicy) {
296 if (!strnicmp(str_governor, "performance", CPUFREQ_NAME_LEN)) {
297 *policy = CPUFREQ_POLICY_PERFORMANCE;
298 return 0;
299 } else if (!strnicmp(str_governor, "powersave", CPUFREQ_NAME_LEN)) {
300 *policy = CPUFREQ_POLICY_POWERSAVE;
301 return 0;
303 return -EINVAL;
304 } else {
305 struct cpufreq_governor *t;
306 down(&cpufreq_governor_sem);
307 if (!cpufreq_driver || !cpufreq_driver->target)
308 goto out;
309 list_for_each_entry(t, &cpufreq_governor_list, governor_list) {
310 if (!strnicmp(str_governor,t->name,CPUFREQ_NAME_LEN)) {
311 *governor = t;
312 up(&cpufreq_governor_sem);
313 return 0;
316 out:
317 up(&cpufreq_governor_sem);
319 return -EINVAL;
321 EXPORT_SYMBOL_GPL(cpufreq_parse_governor);
324 /* drivers/base/cpu.c */
325 extern struct sysdev_class cpu_sysdev_class;
329 * cpufreq_per_cpu_attr_read() / show_##file_name() - print out cpufreq information
331 * Write out information from cpufreq_driver->policy[cpu]; object must be
332 * "unsigned int".
335 #define show_one(file_name, object) \
336 static ssize_t show_##file_name \
337 (struct cpufreq_policy * policy, char *buf) \
339 return sprintf (buf, "%u\n", policy->object); \
342 show_one(cpuinfo_min_freq, cpuinfo.min_freq);
343 show_one(cpuinfo_max_freq, cpuinfo.max_freq);
344 show_one(scaling_min_freq, min);
345 show_one(scaling_max_freq, max);
346 show_one(scaling_cur_freq, cur);
349 * cpufreq_per_cpu_attr_write() / store_##file_name() - sysfs write access
351 #define store_one(file_name, object) \
352 static ssize_t store_##file_name \
353 (struct cpufreq_policy * policy, const char *buf, size_t count) \
355 unsigned int ret = -EINVAL; \
356 struct cpufreq_policy new_policy; \
358 ret = cpufreq_get_policy(&new_policy, policy->cpu); \
359 if (ret) \
360 return -EINVAL; \
362 ret = sscanf (buf, "%u", &new_policy.object); \
363 if (ret != 1) \
364 return -EINVAL; \
366 ret = cpufreq_set_policy(&new_policy); \
368 return ret ? ret : count; \
371 store_one(scaling_min_freq,min);
372 store_one(scaling_max_freq,max);
375 * show_cpuinfo_cur_freq - current CPU frequency as detected by hardware
377 static ssize_t show_cpuinfo_cur_freq (struct cpufreq_policy * policy, char *buf)
379 unsigned int cur_freq = cpufreq_get(policy->cpu);
380 if (!cur_freq)
381 return sprintf(buf, "<unknown>");
382 return sprintf(buf, "%u\n", cur_freq);
387 * show_scaling_governor - show the current policy for the specified CPU
389 static ssize_t show_scaling_governor (struct cpufreq_policy * policy, char *buf)
391 if(policy->policy == CPUFREQ_POLICY_POWERSAVE)
392 return sprintf(buf, "powersave\n");
393 else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE)
394 return sprintf(buf, "performance\n");
395 else if (policy->governor)
396 return scnprintf(buf, CPUFREQ_NAME_LEN, "%s\n", policy->governor->name);
397 return -EINVAL;
402 * store_scaling_governor - store policy for the specified CPU
404 static ssize_t store_scaling_governor (struct cpufreq_policy * policy,
405 const char *buf, size_t count)
407 unsigned int ret = -EINVAL;
408 char str_governor[16];
409 struct cpufreq_policy new_policy;
411 ret = cpufreq_get_policy(&new_policy, policy->cpu);
412 if (ret)
413 return ret;
415 ret = sscanf (buf, "%15s", str_governor);
416 if (ret != 1)
417 return -EINVAL;
419 if (cpufreq_parse_governor(str_governor, &new_policy.policy, &new_policy.governor))
420 return -EINVAL;
422 ret = cpufreq_set_policy(&new_policy);
424 return ret ? ret : count;
428 * show_scaling_driver - show the cpufreq driver currently loaded
430 static ssize_t show_scaling_driver (struct cpufreq_policy * policy, char *buf)
432 return scnprintf(buf, CPUFREQ_NAME_LEN, "%s\n", cpufreq_driver->name);
436 * show_scaling_available_governors - show the available CPUfreq governors
438 static ssize_t show_scaling_available_governors (struct cpufreq_policy * policy,
439 char *buf)
441 ssize_t i = 0;
442 struct cpufreq_governor *t;
444 if (!cpufreq_driver->target) {
445 i += sprintf(buf, "performance powersave");
446 goto out;
449 list_for_each_entry(t, &cpufreq_governor_list, governor_list) {
450 if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char)) - (CPUFREQ_NAME_LEN + 2)))
451 goto out;
452 i += scnprintf(&buf[i], CPUFREQ_NAME_LEN, "%s ", t->name);
454 out:
455 i += sprintf(&buf[i], "\n");
456 return i;
459 * show_affected_cpus - show the CPUs affected by each transition
461 static ssize_t show_affected_cpus (struct cpufreq_policy * policy, char *buf)
463 ssize_t i = 0;
464 unsigned int cpu;
466 for_each_cpu_mask(cpu, policy->cpus) {
467 if (i)
468 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), " ");
469 i += scnprintf(&buf[i], (PAGE_SIZE - i - 2), "%u", cpu);
470 if (i >= (PAGE_SIZE - 5))
471 break;
473 i += sprintf(&buf[i], "\n");
474 return i;
478 #define define_one_ro(_name) \
479 static struct freq_attr _name = \
480 __ATTR(_name, 0444, show_##_name, NULL)
482 #define define_one_ro0400(_name) \
483 static struct freq_attr _name = \
484 __ATTR(_name, 0400, show_##_name, NULL)
486 #define define_one_rw(_name) \
487 static struct freq_attr _name = \
488 __ATTR(_name, 0644, show_##_name, store_##_name)
490 define_one_ro0400(cpuinfo_cur_freq);
491 define_one_ro(cpuinfo_min_freq);
492 define_one_ro(cpuinfo_max_freq);
493 define_one_ro(scaling_available_governors);
494 define_one_ro(scaling_driver);
495 define_one_ro(scaling_cur_freq);
496 define_one_ro(affected_cpus);
497 define_one_rw(scaling_min_freq);
498 define_one_rw(scaling_max_freq);
499 define_one_rw(scaling_governor);
501 static struct attribute * default_attrs[] = {
502 &cpuinfo_min_freq.attr,
503 &cpuinfo_max_freq.attr,
504 &scaling_min_freq.attr,
505 &scaling_max_freq.attr,
506 &affected_cpus.attr,
507 &scaling_governor.attr,
508 &scaling_driver.attr,
509 &scaling_available_governors.attr,
510 NULL
513 #define to_policy(k) container_of(k,struct cpufreq_policy,kobj)
514 #define to_attr(a) container_of(a,struct freq_attr,attr)
516 static ssize_t show(struct kobject * kobj, struct attribute * attr ,char * buf)
518 struct cpufreq_policy * policy = to_policy(kobj);
519 struct freq_attr * fattr = to_attr(attr);
520 ssize_t ret;
521 policy = cpufreq_cpu_get(policy->cpu);
522 if (!policy)
523 return -EINVAL;
524 ret = fattr->show ? fattr->show(policy,buf) : -EIO;
525 cpufreq_cpu_put(policy);
526 return ret;
529 static ssize_t store(struct kobject * kobj, struct attribute * attr,
530 const char * buf, size_t count)
532 struct cpufreq_policy * policy = to_policy(kobj);
533 struct freq_attr * fattr = to_attr(attr);
534 ssize_t ret;
535 policy = cpufreq_cpu_get(policy->cpu);
536 if (!policy)
537 return -EINVAL;
538 ret = fattr->store ? fattr->store(policy,buf,count) : -EIO;
539 cpufreq_cpu_put(policy);
540 return ret;
543 static void cpufreq_sysfs_release(struct kobject * kobj)
545 struct cpufreq_policy * policy = to_policy(kobj);
546 dprintk("last reference is dropped\n");
547 complete(&policy->kobj_unregister);
550 static struct sysfs_ops sysfs_ops = {
551 .show = show,
552 .store = store,
555 static struct kobj_type ktype_cpufreq = {
556 .sysfs_ops = &sysfs_ops,
557 .default_attrs = default_attrs,
558 .release = cpufreq_sysfs_release,
563 * cpufreq_add_dev - add a CPU device
565 * Adds the cpufreq interface for a CPU device.
567 static int cpufreq_add_dev (struct sys_device * sys_dev)
569 unsigned int cpu = sys_dev->id;
570 int ret = 0;
571 struct cpufreq_policy new_policy;
572 struct cpufreq_policy *policy;
573 struct freq_attr **drv_attr;
574 unsigned long flags;
575 unsigned int j;
577 cpufreq_debug_disable_ratelimit();
578 dprintk("adding CPU %u\n", cpu);
580 #ifdef CONFIG_SMP
581 /* check whether a different CPU already registered this
582 * CPU because it is in the same boat. */
583 policy = cpufreq_cpu_get(cpu);
584 if (unlikely(policy)) {
585 cpu_sys_devices[cpu] = sys_dev;
586 dprintk("CPU already managed, adding link\n");
587 sysfs_create_link(&sys_dev->kobj, &policy->kobj, "cpufreq");
588 cpufreq_debug_enable_ratelimit();
589 return 0;
591 #endif
593 if (!try_module_get(cpufreq_driver->owner)) {
594 ret = -EINVAL;
595 goto module_out;
598 policy = kmalloc(sizeof(struct cpufreq_policy), GFP_KERNEL);
599 if (!policy) {
600 ret = -ENOMEM;
601 goto nomem_out;
603 memset(policy, 0, sizeof(struct cpufreq_policy));
605 policy->cpu = cpu;
606 policy->cpus = cpumask_of_cpu(cpu);
608 init_MUTEX_LOCKED(&policy->lock);
609 init_completion(&policy->kobj_unregister);
610 INIT_WORK(&policy->update, handle_update, (void *)(long)cpu);
612 /* call driver. From then on the cpufreq must be able
613 * to accept all calls to ->verify and ->setpolicy for this CPU
615 ret = cpufreq_driver->init(policy);
616 if (ret) {
617 dprintk("initialization failed\n");
618 goto err_out;
621 memcpy(&new_policy, policy, sizeof(struct cpufreq_policy));
623 /* prepare interface data */
624 policy->kobj.parent = &sys_dev->kobj;
625 policy->kobj.ktype = &ktype_cpufreq;
626 strlcpy(policy->kobj.name, "cpufreq", KOBJ_NAME_LEN);
628 ret = kobject_register(&policy->kobj);
629 if (ret)
630 goto err_out_driver_exit;
632 /* set up files for this cpu device */
633 drv_attr = cpufreq_driver->attr;
634 while ((drv_attr) && (*drv_attr)) {
635 sysfs_create_file(&policy->kobj, &((*drv_attr)->attr));
636 drv_attr++;
638 if (cpufreq_driver->get)
639 sysfs_create_file(&policy->kobj, &cpuinfo_cur_freq.attr);
640 if (cpufreq_driver->target)
641 sysfs_create_file(&policy->kobj, &scaling_cur_freq.attr);
643 spin_lock_irqsave(&cpufreq_driver_lock, flags);
644 for_each_cpu_mask(j, policy->cpus)
645 cpufreq_cpu_data[j] = policy;
646 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
647 policy->governor = NULL; /* to assure that the starting sequence is
648 * run in cpufreq_set_policy */
649 up(&policy->lock);
651 /* set default policy */
653 ret = cpufreq_set_policy(&new_policy);
654 if (ret) {
655 dprintk("setting policy failed\n");
656 goto err_out_unregister;
659 module_put(cpufreq_driver->owner);
660 cpu_sys_devices[cpu] = sys_dev;
661 dprintk("initialization complete\n");
662 cpufreq_debug_enable_ratelimit();
664 return 0;
667 err_out_unregister:
668 spin_lock_irqsave(&cpufreq_driver_lock, flags);
669 for_each_cpu_mask(j, policy->cpus)
670 cpufreq_cpu_data[j] = NULL;
671 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
673 kobject_unregister(&policy->kobj);
674 wait_for_completion(&policy->kobj_unregister);
676 err_out_driver_exit:
677 if (cpufreq_driver->exit)
678 cpufreq_driver->exit(policy);
680 err_out:
681 kfree(policy);
683 nomem_out:
684 module_put(cpufreq_driver->owner);
685 module_out:
686 cpufreq_debug_enable_ratelimit();
687 return ret;
692 * cpufreq_remove_dev - remove a CPU device
694 * Removes the cpufreq interface for a CPU device.
696 static int cpufreq_remove_dev (struct sys_device * sys_dev)
698 unsigned int cpu = sys_dev->id;
699 unsigned long flags;
700 struct cpufreq_policy *data;
701 #ifdef CONFIG_SMP
702 unsigned int j;
703 #endif
705 cpufreq_debug_disable_ratelimit();
706 dprintk("unregistering CPU %u\n", cpu);
708 spin_lock_irqsave(&cpufreq_driver_lock, flags);
709 data = cpufreq_cpu_data[cpu];
711 if (!data) {
712 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
713 cpu_sys_devices[cpu] = NULL;
714 cpufreq_debug_enable_ratelimit();
715 return -EINVAL;
717 cpufreq_cpu_data[cpu] = NULL;
720 #ifdef CONFIG_SMP
721 /* if this isn't the CPU which is the parent of the kobj, we
722 * only need to unlink, put and exit
724 if (unlikely(cpu != data->cpu)) {
725 dprintk("removing link\n");
726 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
727 sysfs_remove_link(&sys_dev->kobj, "cpufreq");
728 cpu_sys_devices[cpu] = NULL;
729 cpufreq_cpu_put(data);
730 cpufreq_debug_enable_ratelimit();
731 return 0;
733 #endif
735 cpu_sys_devices[cpu] = NULL;
737 if (!kobject_get(&data->kobj)) {
738 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
739 cpufreq_debug_enable_ratelimit();
740 return -EFAULT;
743 #ifdef CONFIG_SMP
744 /* if we have other CPUs still registered, we need to unlink them,
745 * or else wait_for_completion below will lock up. Clean the
746 * cpufreq_cpu_data[] while holding the lock, and remove the sysfs
747 * links afterwards.
749 if (unlikely(cpus_weight(data->cpus) > 1)) {
750 for_each_cpu_mask(j, data->cpus) {
751 if (j == cpu)
752 continue;
753 cpufreq_cpu_data[j] = NULL;
757 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
759 if (unlikely(cpus_weight(data->cpus) > 1)) {
760 for_each_cpu_mask(j, data->cpus) {
761 if (j == cpu)
762 continue;
763 dprintk("removing link for cpu %u\n", j);
764 sysfs_remove_link(&cpu_sys_devices[j]->kobj, "cpufreq");
765 cpufreq_cpu_put(data);
768 #else
769 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
770 #endif
772 down(&data->lock);
773 if (cpufreq_driver->target)
774 __cpufreq_governor(data, CPUFREQ_GOV_STOP);
775 cpufreq_driver->target = NULL;
776 up(&data->lock);
778 kobject_unregister(&data->kobj);
780 kobject_put(&data->kobj);
782 /* we need to make sure that the underlying kobj is actually
783 * not referenced anymore by anybody before we proceed with
784 * unloading.
786 dprintk("waiting for dropping of refcount\n");
787 wait_for_completion(&data->kobj_unregister);
788 dprintk("wait complete\n");
790 if (cpufreq_driver->exit)
791 cpufreq_driver->exit(data);
793 kfree(data);
795 cpufreq_debug_enable_ratelimit();
797 return 0;
801 static void handle_update(void *data)
803 unsigned int cpu = (unsigned int)(long)data;
804 dprintk("handle_update for cpu %u called\n", cpu);
805 cpufreq_update_policy(cpu);
809 * cpufreq_out_of_sync - If actual and saved CPU frequency differs, we're in deep trouble.
810 * @cpu: cpu number
811 * @old_freq: CPU frequency the kernel thinks the CPU runs at
812 * @new_freq: CPU frequency the CPU actually runs at
814 * We adjust to current frequency first, and need to clean up later. So either call
815 * to cpufreq_update_policy() or schedule handle_update()).
817 static void cpufreq_out_of_sync(unsigned int cpu, unsigned int old_freq, unsigned int new_freq)
819 struct cpufreq_freqs freqs;
821 dprintk(KERN_WARNING "Warning: CPU frequency out of sync: cpufreq and timing "
822 "core thinks of %u, is %u kHz.\n", old_freq, new_freq);
824 freqs.cpu = cpu;
825 freqs.old = old_freq;
826 freqs.new = new_freq;
827 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
828 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
832 /**
833 * cpufreq_get - get the current CPU frequency (in kHz)
834 * @cpu: CPU number
836 * Get the CPU current (static) CPU frequency
838 unsigned int cpufreq_get(unsigned int cpu)
840 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
841 unsigned int ret = 0;
843 if (!policy)
844 return 0;
846 if (!cpufreq_driver->get)
847 goto out;
849 down(&policy->lock);
851 ret = cpufreq_driver->get(cpu);
853 if (ret && policy->cur && !(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS))
855 /* verify no discrepancy between actual and saved value exists */
856 if (unlikely(ret != policy->cur)) {
857 cpufreq_out_of_sync(cpu, policy->cur, ret);
858 schedule_work(&policy->update);
862 up(&policy->lock);
864 out:
865 cpufreq_cpu_put(policy);
867 return (ret);
869 EXPORT_SYMBOL(cpufreq_get);
873 * cpufreq_suspend - let the low level driver prepare for suspend
876 static int cpufreq_suspend(struct sys_device * sysdev, pm_message_t pmsg)
878 int cpu = sysdev->id;
879 unsigned int ret = 0;
880 unsigned int cur_freq = 0;
881 struct cpufreq_policy *cpu_policy;
883 dprintk("resuming cpu %u\n", cpu);
885 if (!cpu_online(cpu))
886 return 0;
888 /* we may be lax here as interrupts are off. Nonetheless
889 * we need to grab the correct cpu policy, as to check
890 * whether we really run on this CPU.
893 cpu_policy = cpufreq_cpu_get(cpu);
894 if (!cpu_policy)
895 return -EINVAL;
897 /* only handle each CPU group once */
898 if (unlikely(cpu_policy->cpu != cpu)) {
899 cpufreq_cpu_put(cpu_policy);
900 return 0;
903 if (cpufreq_driver->suspend) {
904 ret = cpufreq_driver->suspend(cpu_policy, pmsg);
905 if (ret) {
906 printk(KERN_ERR "cpufreq: suspend failed in ->suspend "
907 "step on CPU %u\n", cpu_policy->cpu);
908 cpufreq_cpu_put(cpu_policy);
909 return ret;
914 if (cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)
915 goto out;
917 if (cpufreq_driver->get)
918 cur_freq = cpufreq_driver->get(cpu_policy->cpu);
920 if (!cur_freq || !cpu_policy->cur) {
921 printk(KERN_ERR "cpufreq: suspend failed to assert current "
922 "frequency is what timing core thinks it is.\n");
923 goto out;
926 if (unlikely(cur_freq != cpu_policy->cur)) {
927 struct cpufreq_freqs freqs;
929 if (!(cpufreq_driver->flags & CPUFREQ_PM_NO_WARN))
930 dprintk(KERN_DEBUG "Warning: CPU frequency is %u, "
931 "cpufreq assumed %u kHz.\n",
932 cur_freq, cpu_policy->cur);
934 freqs.cpu = cpu;
935 freqs.old = cpu_policy->cur;
936 freqs.new = cur_freq;
938 notifier_call_chain(&cpufreq_transition_notifier_list,
939 CPUFREQ_SUSPENDCHANGE, &freqs);
940 adjust_jiffies(CPUFREQ_SUSPENDCHANGE, &freqs);
942 cpu_policy->cur = cur_freq;
945 out:
946 cpufreq_cpu_put(cpu_policy);
947 return 0;
951 * cpufreq_resume - restore proper CPU frequency handling after resume
953 * 1.) resume CPUfreq hardware support (cpufreq_driver->resume())
954 * 2.) if ->target and !CPUFREQ_CONST_LOOPS: verify we're in sync
955 * 3.) schedule call cpufreq_update_policy() ASAP as interrupts are
956 * restored.
958 static int cpufreq_resume(struct sys_device * sysdev)
960 int cpu = sysdev->id;
961 unsigned int ret = 0;
962 struct cpufreq_policy *cpu_policy;
964 dprintk("resuming cpu %u\n", cpu);
966 if (!cpu_online(cpu))
967 return 0;
969 /* we may be lax here as interrupts are off. Nonetheless
970 * we need to grab the correct cpu policy, as to check
971 * whether we really run on this CPU.
974 cpu_policy = cpufreq_cpu_get(cpu);
975 if (!cpu_policy)
976 return -EINVAL;
978 /* only handle each CPU group once */
979 if (unlikely(cpu_policy->cpu != cpu)) {
980 cpufreq_cpu_put(cpu_policy);
981 return 0;
984 if (cpufreq_driver->resume) {
985 ret = cpufreq_driver->resume(cpu_policy);
986 if (ret) {
987 printk(KERN_ERR "cpufreq: resume failed in ->resume "
988 "step on CPU %u\n", cpu_policy->cpu);
989 cpufreq_cpu_put(cpu_policy);
990 return ret;
994 if (!(cpufreq_driver->flags & CPUFREQ_CONST_LOOPS)) {
995 unsigned int cur_freq = 0;
997 if (cpufreq_driver->get)
998 cur_freq = cpufreq_driver->get(cpu_policy->cpu);
1000 if (!cur_freq || !cpu_policy->cur) {
1001 printk(KERN_ERR "cpufreq: resume failed to assert "
1002 "current frequency is what timing core "
1003 "thinks it is.\n");
1004 goto out;
1007 if (unlikely(cur_freq != cpu_policy->cur)) {
1008 struct cpufreq_freqs freqs;
1010 if (!(cpufreq_driver->flags & CPUFREQ_PM_NO_WARN))
1011 dprintk(KERN_WARNING "Warning: CPU frequency"
1012 "is %u, cpufreq assumed %u kHz.\n",
1013 cur_freq, cpu_policy->cur);
1015 freqs.cpu = cpu;
1016 freqs.old = cpu_policy->cur;
1017 freqs.new = cur_freq;
1019 notifier_call_chain(&cpufreq_transition_notifier_list,
1020 CPUFREQ_RESUMECHANGE, &freqs);
1021 adjust_jiffies(CPUFREQ_RESUMECHANGE, &freqs);
1023 cpu_policy->cur = cur_freq;
1027 out:
1028 schedule_work(&cpu_policy->update);
1029 cpufreq_cpu_put(cpu_policy);
1030 return ret;
1033 static struct sysdev_driver cpufreq_sysdev_driver = {
1034 .add = cpufreq_add_dev,
1035 .remove = cpufreq_remove_dev,
1036 .suspend = cpufreq_suspend,
1037 .resume = cpufreq_resume,
1041 /*********************************************************************
1042 * NOTIFIER LISTS INTERFACE *
1043 *********************************************************************/
1046 * cpufreq_register_notifier - register a driver with cpufreq
1047 * @nb: notifier function to register
1048 * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER
1050 * Add a driver to one of two lists: either a list of drivers that
1051 * are notified about clock rate changes (once before and once after
1052 * the transition), or a list of drivers that are notified about
1053 * changes in cpufreq policy.
1055 * This function may sleep, and has the same return conditions as
1056 * notifier_chain_register.
1058 int cpufreq_register_notifier(struct notifier_block *nb, unsigned int list)
1060 int ret;
1062 down_write(&cpufreq_notifier_rwsem);
1063 switch (list) {
1064 case CPUFREQ_TRANSITION_NOTIFIER:
1065 ret = notifier_chain_register(&cpufreq_transition_notifier_list, nb);
1066 break;
1067 case CPUFREQ_POLICY_NOTIFIER:
1068 ret = notifier_chain_register(&cpufreq_policy_notifier_list, nb);
1069 break;
1070 default:
1071 ret = -EINVAL;
1073 up_write(&cpufreq_notifier_rwsem);
1075 return ret;
1077 EXPORT_SYMBOL(cpufreq_register_notifier);
1081 * cpufreq_unregister_notifier - unregister a driver with cpufreq
1082 * @nb: notifier block to be unregistered
1083 * @list: CPUFREQ_TRANSITION_NOTIFIER or CPUFREQ_POLICY_NOTIFIER
1085 * Remove a driver from the CPU frequency notifier list.
1087 * This function may sleep, and has the same return conditions as
1088 * notifier_chain_unregister.
1090 int cpufreq_unregister_notifier(struct notifier_block *nb, unsigned int list)
1092 int ret;
1094 down_write(&cpufreq_notifier_rwsem);
1095 switch (list) {
1096 case CPUFREQ_TRANSITION_NOTIFIER:
1097 ret = notifier_chain_unregister(&cpufreq_transition_notifier_list, nb);
1098 break;
1099 case CPUFREQ_POLICY_NOTIFIER:
1100 ret = notifier_chain_unregister(&cpufreq_policy_notifier_list, nb);
1101 break;
1102 default:
1103 ret = -EINVAL;
1105 up_write(&cpufreq_notifier_rwsem);
1107 return ret;
1109 EXPORT_SYMBOL(cpufreq_unregister_notifier);
1112 /*********************************************************************
1113 * GOVERNORS *
1114 *********************************************************************/
1117 int __cpufreq_driver_target(struct cpufreq_policy *policy,
1118 unsigned int target_freq,
1119 unsigned int relation)
1121 int retval = -EINVAL;
1122 lock_cpu_hotplug();
1123 dprintk("target for CPU %u: %u kHz, relation %u\n", policy->cpu,
1124 target_freq, relation);
1125 if (cpu_online(policy->cpu) && cpufreq_driver->target)
1126 retval = cpufreq_driver->target(policy, target_freq, relation);
1127 unlock_cpu_hotplug();
1128 return retval;
1130 EXPORT_SYMBOL_GPL(__cpufreq_driver_target);
1133 int cpufreq_driver_target(struct cpufreq_policy *policy,
1134 unsigned int target_freq,
1135 unsigned int relation)
1137 int ret;
1139 policy = cpufreq_cpu_get(policy->cpu);
1140 if (!policy)
1141 return -EINVAL;
1143 down(&policy->lock);
1145 ret = __cpufreq_driver_target(policy, target_freq, relation);
1147 up(&policy->lock);
1149 cpufreq_cpu_put(policy);
1151 return ret;
1153 EXPORT_SYMBOL_GPL(cpufreq_driver_target);
1156 static int __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event)
1158 int ret;
1160 if (!try_module_get(policy->governor->owner))
1161 return -EINVAL;
1163 dprintk("__cpufreq_governor for CPU %u, event %u\n", policy->cpu, event);
1164 ret = policy->governor->governor(policy, event);
1166 /* we keep one module reference alive for each CPU governed by this CPU */
1167 if ((event != CPUFREQ_GOV_START) || ret)
1168 module_put(policy->governor->owner);
1169 if ((event == CPUFREQ_GOV_STOP) && !ret)
1170 module_put(policy->governor->owner);
1172 return ret;
1176 int cpufreq_governor(unsigned int cpu, unsigned int event)
1178 int ret = 0;
1179 struct cpufreq_policy *policy = cpufreq_cpu_get(cpu);
1181 if (!policy)
1182 return -EINVAL;
1184 down(&policy->lock);
1185 ret = __cpufreq_governor(policy, event);
1186 up(&policy->lock);
1188 cpufreq_cpu_put(policy);
1190 return ret;
1192 EXPORT_SYMBOL_GPL(cpufreq_governor);
1195 int cpufreq_register_governor(struct cpufreq_governor *governor)
1197 struct cpufreq_governor *t;
1199 if (!governor)
1200 return -EINVAL;
1202 down(&cpufreq_governor_sem);
1204 list_for_each_entry(t, &cpufreq_governor_list, governor_list) {
1205 if (!strnicmp(governor->name,t->name,CPUFREQ_NAME_LEN)) {
1206 up(&cpufreq_governor_sem);
1207 return -EBUSY;
1210 list_add(&governor->governor_list, &cpufreq_governor_list);
1212 up(&cpufreq_governor_sem);
1214 return 0;
1216 EXPORT_SYMBOL_GPL(cpufreq_register_governor);
1219 void cpufreq_unregister_governor(struct cpufreq_governor *governor)
1221 if (!governor)
1222 return;
1224 down(&cpufreq_governor_sem);
1225 list_del(&governor->governor_list);
1226 up(&cpufreq_governor_sem);
1227 return;
1229 EXPORT_SYMBOL_GPL(cpufreq_unregister_governor);
1233 /*********************************************************************
1234 * POLICY INTERFACE *
1235 *********************************************************************/
1238 * cpufreq_get_policy - get the current cpufreq_policy
1239 * @policy: struct cpufreq_policy into which the current cpufreq_policy is written
1241 * Reads the current cpufreq policy.
1243 int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu)
1245 struct cpufreq_policy *cpu_policy;
1246 if (!policy)
1247 return -EINVAL;
1249 cpu_policy = cpufreq_cpu_get(cpu);
1250 if (!cpu_policy)
1251 return -EINVAL;
1253 down(&cpu_policy->lock);
1254 memcpy(policy, cpu_policy, sizeof(struct cpufreq_policy));
1255 up(&cpu_policy->lock);
1257 cpufreq_cpu_put(cpu_policy);
1259 return 0;
1261 EXPORT_SYMBOL(cpufreq_get_policy);
1264 static int __cpufreq_set_policy(struct cpufreq_policy *data, struct cpufreq_policy *policy)
1266 int ret = 0;
1268 cpufreq_debug_disable_ratelimit();
1269 dprintk("setting new policy for CPU %u: %u - %u kHz\n", policy->cpu,
1270 policy->min, policy->max);
1272 memcpy(&policy->cpuinfo,
1273 &data->cpuinfo,
1274 sizeof(struct cpufreq_cpuinfo));
1276 /* verify the cpu speed can be set within this limit */
1277 ret = cpufreq_driver->verify(policy);
1278 if (ret)
1279 goto error_out;
1281 down_read(&cpufreq_notifier_rwsem);
1283 /* adjust if necessary - all reasons */
1284 notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_ADJUST,
1285 policy);
1287 /* adjust if necessary - hardware incompatibility*/
1288 notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_INCOMPATIBLE,
1289 policy);
1291 /* verify the cpu speed can be set within this limit,
1292 which might be different to the first one */
1293 ret = cpufreq_driver->verify(policy);
1294 if (ret) {
1295 up_read(&cpufreq_notifier_rwsem);
1296 goto error_out;
1299 /* notification of the new policy */
1300 notifier_call_chain(&cpufreq_policy_notifier_list, CPUFREQ_NOTIFY,
1301 policy);
1303 up_read(&cpufreq_notifier_rwsem);
1305 data->min = policy->min;
1306 data->max = policy->max;
1308 dprintk("new min and max freqs are %u - %u kHz\n", data->min, data->max);
1310 if (cpufreq_driver->setpolicy) {
1311 data->policy = policy->policy;
1312 dprintk("setting range\n");
1313 ret = cpufreq_driver->setpolicy(policy);
1314 } else {
1315 if (policy->governor != data->governor) {
1316 /* save old, working values */
1317 struct cpufreq_governor *old_gov = data->governor;
1319 dprintk("governor switch\n");
1321 /* end old governor */
1322 if (data->governor)
1323 __cpufreq_governor(data, CPUFREQ_GOV_STOP);
1325 /* start new governor */
1326 data->governor = policy->governor;
1327 if (__cpufreq_governor(data, CPUFREQ_GOV_START)) {
1328 /* new governor failed, so re-start old one */
1329 dprintk("starting governor %s failed\n", data->governor->name);
1330 if (old_gov) {
1331 data->governor = old_gov;
1332 __cpufreq_governor(data, CPUFREQ_GOV_START);
1334 ret = -EINVAL;
1335 goto error_out;
1337 /* might be a policy change, too, so fall through */
1339 dprintk("governor: change or update limits\n");
1340 __cpufreq_governor(data, CPUFREQ_GOV_LIMITS);
1343 error_out:
1344 cpufreq_debug_enable_ratelimit();
1345 return ret;
1349 * cpufreq_set_policy - set a new CPUFreq policy
1350 * @policy: policy to be set.
1352 * Sets a new CPU frequency and voltage scaling policy.
1354 int cpufreq_set_policy(struct cpufreq_policy *policy)
1356 int ret = 0;
1357 struct cpufreq_policy *data;
1359 if (!policy)
1360 return -EINVAL;
1362 data = cpufreq_cpu_get(policy->cpu);
1363 if (!data)
1364 return -EINVAL;
1366 /* lock this CPU */
1367 down(&data->lock);
1369 ret = __cpufreq_set_policy(data, policy);
1370 data->user_policy.min = data->min;
1371 data->user_policy.max = data->max;
1372 data->user_policy.policy = data->policy;
1373 data->user_policy.governor = data->governor;
1375 up(&data->lock);
1376 cpufreq_cpu_put(data);
1378 return ret;
1380 EXPORT_SYMBOL(cpufreq_set_policy);
1384 * cpufreq_update_policy - re-evaluate an existing cpufreq policy
1385 * @cpu: CPU which shall be re-evaluated
1387 * Usefull for policy notifiers which have different necessities
1388 * at different times.
1390 int cpufreq_update_policy(unsigned int cpu)
1392 struct cpufreq_policy *data = cpufreq_cpu_get(cpu);
1393 struct cpufreq_policy policy;
1394 int ret = 0;
1396 if (!data)
1397 return -ENODEV;
1399 down(&data->lock);
1401 dprintk("updating policy for CPU %u\n", cpu);
1402 memcpy(&policy,
1403 data,
1404 sizeof(struct cpufreq_policy));
1405 policy.min = data->user_policy.min;
1406 policy.max = data->user_policy.max;
1407 policy.policy = data->user_policy.policy;
1408 policy.governor = data->user_policy.governor;
1410 ret = __cpufreq_set_policy(data, &policy);
1412 up(&data->lock);
1414 cpufreq_cpu_put(data);
1415 return ret;
1417 EXPORT_SYMBOL(cpufreq_update_policy);
1420 /*********************************************************************
1421 * REGISTER / UNREGISTER CPUFREQ DRIVER *
1422 *********************************************************************/
1425 * cpufreq_register_driver - register a CPU Frequency driver
1426 * @driver_data: A struct cpufreq_driver containing the values#
1427 * submitted by the CPU Frequency driver.
1429 * Registers a CPU Frequency driver to this core code. This code
1430 * returns zero on success, -EBUSY when another driver got here first
1431 * (and isn't unregistered in the meantime).
1434 int cpufreq_register_driver(struct cpufreq_driver *driver_data)
1436 unsigned long flags;
1437 int ret;
1439 if (!driver_data || !driver_data->verify || !driver_data->init ||
1440 ((!driver_data->setpolicy) && (!driver_data->target)))
1441 return -EINVAL;
1443 dprintk("trying to register driver %s\n", driver_data->name);
1445 if (driver_data->setpolicy)
1446 driver_data->flags |= CPUFREQ_CONST_LOOPS;
1448 spin_lock_irqsave(&cpufreq_driver_lock, flags);
1449 if (cpufreq_driver) {
1450 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1451 return -EBUSY;
1453 cpufreq_driver = driver_data;
1454 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1456 ret = sysdev_driver_register(&cpu_sysdev_class,&cpufreq_sysdev_driver);
1458 if ((!ret) && !(cpufreq_driver->flags & CPUFREQ_STICKY)) {
1459 int i;
1460 ret = -ENODEV;
1462 /* check for at least one working CPU */
1463 for (i=0; i<NR_CPUS; i++)
1464 if (cpufreq_cpu_data[i])
1465 ret = 0;
1467 /* if all ->init() calls failed, unregister */
1468 if (ret) {
1469 dprintk("no CPU initialized for driver %s\n", driver_data->name);
1470 sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver);
1472 spin_lock_irqsave(&cpufreq_driver_lock, flags);
1473 cpufreq_driver = NULL;
1474 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1478 if (!ret) {
1479 dprintk("driver %s up and running\n", driver_data->name);
1480 cpufreq_debug_enable_ratelimit();
1483 return (ret);
1485 EXPORT_SYMBOL_GPL(cpufreq_register_driver);
1489 * cpufreq_unregister_driver - unregister the current CPUFreq driver
1491 * Unregister the current CPUFreq driver. Only call this if you have
1492 * the right to do so, i.e. if you have succeeded in initialising before!
1493 * Returns zero if successful, and -EINVAL if the cpufreq_driver is
1494 * currently not initialised.
1496 int cpufreq_unregister_driver(struct cpufreq_driver *driver)
1498 unsigned long flags;
1500 cpufreq_debug_disable_ratelimit();
1502 if (!cpufreq_driver || (driver != cpufreq_driver)) {
1503 cpufreq_debug_enable_ratelimit();
1504 return -EINVAL;
1507 dprintk("unregistering driver %s\n", driver->name);
1509 sysdev_driver_unregister(&cpu_sysdev_class, &cpufreq_sysdev_driver);
1511 spin_lock_irqsave(&cpufreq_driver_lock, flags);
1512 cpufreq_driver = NULL;
1513 spin_unlock_irqrestore(&cpufreq_driver_lock, flags);
1515 return 0;
1517 EXPORT_SYMBOL_GPL(cpufreq_unregister_driver);