Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 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 | |
Len Brown | 752138d | 2010-05-22 16:57:26 -0400 | [diff] [blame^] | 17 | static struct cpuidle_driver *cpuidle_curr_driver; |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 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 | /** |
Len Brown | 752138d | 2010-05-22 16:57:26 -0400 | [diff] [blame^] | 43 | * cpuidle_get_driver - return the current driver |
| 44 | */ |
| 45 | struct cpuidle_driver *cpuidle_get_driver(void) |
| 46 | { |
| 47 | return cpuidle_curr_driver; |
| 48 | } |
| 49 | EXPORT_SYMBOL_GPL(cpuidle_get_driver); |
| 50 | |
| 51 | /** |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 52 | * cpuidle_unregister_driver - unregisters a driver |
| 53 | * @drv: the driver |
| 54 | */ |
| 55 | void cpuidle_unregister_driver(struct cpuidle_driver *drv) |
| 56 | { |
Len Brown | c0d64cb | 2010-05-22 16:34:10 -0400 | [diff] [blame] | 57 | if (drv != cpuidle_curr_driver) { |
| 58 | WARN(1, "invalid cpuidle_unregister_driver(%s)\n", |
| 59 | drv->name); |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 60 | return; |
Len Brown | c0d64cb | 2010-05-22 16:34:10 -0400 | [diff] [blame] | 61 | } |
Len Brown | 4f86d3a | 2007-10-03 18:58:00 -0400 | [diff] [blame] | 62 | |
| 63 | spin_lock(&cpuidle_driver_lock); |
| 64 | cpuidle_curr_driver = NULL; |
| 65 | spin_unlock(&cpuidle_driver_lock); |
| 66 | } |
| 67 | |
| 68 | EXPORT_SYMBOL_GPL(cpuidle_unregister_driver); |