xref: /linux/drivers/cpuidle/driver.c (revision bcefe12eff5dca6fdfa94ed85e5bee66380d5cd9)
1 /*
2  * driver.c - driver support
3  *
4  * (C) 2006-2007 Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
5  *               Shaohua Li <shaohua.li@intel.com>
6  *               Adam Belay <abelay@novell.com>
7  *
8  * This code is licenced under the GPL.
9  */
10 
11 #include <linux/mutex.h>
12 #include <linux/module.h>
13 #include <linux/cpuidle.h>
14 
15 #include "cpuidle.h"
16 
17 struct cpuidle_driver *cpuidle_curr_driver;
18 DEFINE_SPINLOCK(cpuidle_driver_lock);
19 
20 /**
21  * cpuidle_register_driver - registers a driver
22  * @drv: the driver
23  */
24 int cpuidle_register_driver(struct cpuidle_driver *drv)
25 {
26 	if (!drv)
27 		return -EINVAL;
28 
29 	spin_lock(&cpuidle_driver_lock);
30 	if (cpuidle_curr_driver) {
31 		spin_unlock(&cpuidle_driver_lock);
32 		return -EBUSY;
33 	}
34 	cpuidle_curr_driver = drv;
35 	spin_unlock(&cpuidle_driver_lock);
36 
37 	return 0;
38 }
39 
40 EXPORT_SYMBOL_GPL(cpuidle_register_driver);
41 
42 /**
43  * cpuidle_unregister_driver - unregisters a driver
44  * @drv: the driver
45  */
46 void cpuidle_unregister_driver(struct cpuidle_driver *drv)
47 {
48 	if (!drv)
49 		return;
50 
51 	spin_lock(&cpuidle_driver_lock);
52 	cpuidle_curr_driver = NULL;
53 	spin_unlock(&cpuidle_driver_lock);
54 }
55 
56 EXPORT_SYMBOL_GPL(cpuidle_unregister_driver);
57