Add linux-next specific files for 20110831
[linux-2.6/next.git] / drivers / cpuidle / driver.c
blob3f7e3cedd133b4ef66965351efb34351374b4af8
1 /*
2 * driver.c - driver support
4 * (C) 2006-2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
5 * Shaohua Li <shaohua.li@intel.com>
6 * Adam Belay <abelay@novell.com>
8 * This code is licenced under the GPL.
9 */
11 #include <linux/mutex.h>
12 #include <linux/module.h>
13 #include <linux/cpuidle.h>
15 #include "cpuidle.h"
17 static struct cpuidle_driver *cpuidle_curr_driver;
18 DEFINE_SPINLOCK(cpuidle_driver_lock);
20 /**
21 * cpuidle_register_driver - registers a driver
22 * @drv: the driver
24 int cpuidle_register_driver(struct cpuidle_driver *drv)
26 if (!drv)
27 return -EINVAL;
29 if (cpuidle_disabled())
30 return -ENODEV;
32 spin_lock(&cpuidle_driver_lock);
33 if (cpuidle_curr_driver) {
34 spin_unlock(&cpuidle_driver_lock);
35 return -EBUSY;
37 cpuidle_curr_driver = drv;
38 spin_unlock(&cpuidle_driver_lock);
40 return 0;
43 EXPORT_SYMBOL_GPL(cpuidle_register_driver);
45 /**
46 * cpuidle_get_driver - return the current driver
48 struct cpuidle_driver *cpuidle_get_driver(void)
50 return cpuidle_curr_driver;
52 EXPORT_SYMBOL_GPL(cpuidle_get_driver);
54 /**
55 * cpuidle_unregister_driver - unregisters a driver
56 * @drv: the driver
58 void cpuidle_unregister_driver(struct cpuidle_driver *drv)
60 if (drv != cpuidle_curr_driver) {
61 WARN(1, "invalid cpuidle_unregister_driver(%s)\n",
62 drv->name);
63 return;
66 spin_lock(&cpuidle_driver_lock);
67 cpuidle_curr_driver = NULL;
68 spin_unlock(&cpuidle_driver_lock);
71 EXPORT_SYMBOL_GPL(cpuidle_unregister_driver);