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.
11 #include <linux/mutex.h>
12 #include <linux/module.h>
13 #include <linux/cpuidle.h>
17 static struct cpuidle_driver
*cpuidle_curr_driver
;
18 DEFINE_SPINLOCK(cpuidle_driver_lock
);
20 static void __cpuidle_register_driver(struct cpuidle_driver
*drv
)
24 * cpuidle driver should set the drv->power_specified bit
25 * before registering if the driver provides
26 * power_usage numbers.
28 * If power_specified is not set,
29 * we fill in power_usage with decreasing values as the
30 * cpuidle code has an implicit assumption that state Cn
31 * uses less power than C(n-1).
33 * With CONFIG_ARCH_HAS_CPU_RELAX, C0 is already assigned
34 * an power value of -1. So we use -2, -3, etc, for other
37 if (!drv
->power_specified
) {
38 for (i
= CPUIDLE_DRIVER_STATE_START
; i
< drv
->state_count
; i
++)
39 drv
->states
[i
].power_usage
= -1 - i
;
45 * cpuidle_register_driver - registers a driver
48 int cpuidle_register_driver(struct cpuidle_driver
*drv
)
50 if (!drv
|| !drv
->state_count
)
53 if (cpuidle_disabled())
56 spin_lock(&cpuidle_driver_lock
);
57 if (cpuidle_curr_driver
) {
58 spin_unlock(&cpuidle_driver_lock
);
61 __cpuidle_register_driver(drv
);
62 cpuidle_curr_driver
= drv
;
63 spin_unlock(&cpuidle_driver_lock
);
68 EXPORT_SYMBOL_GPL(cpuidle_register_driver
);
71 * cpuidle_get_driver - return the current driver
73 struct cpuidle_driver
*cpuidle_get_driver(void)
75 return cpuidle_curr_driver
;
77 EXPORT_SYMBOL_GPL(cpuidle_get_driver
);
80 * cpuidle_unregister_driver - unregisters a driver
83 void cpuidle_unregister_driver(struct cpuidle_driver
*drv
)
85 if (drv
!= cpuidle_curr_driver
) {
86 WARN(1, "invalid cpuidle_unregister_driver(%s)\n",
91 spin_lock(&cpuidle_driver_lock
);
92 cpuidle_curr_driver
= NULL
;
93 spin_unlock(&cpuidle_driver_lock
);
96 EXPORT_SYMBOL_GPL(cpuidle_unregister_driver
);