blob: 3f7e3cedd133b4ef66965351efb34351374b4af8 [file] [log] [blame]
Len Brown4f86d3a2007-10-03 18:58:00 -04001/*
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 Brown752138d2010-05-22 16:57:26 -040017static struct cpuidle_driver *cpuidle_curr_driver;
Len Brown4f86d3a2007-10-03 18:58:00 -040018DEFINE_SPINLOCK(cpuidle_driver_lock);
19
20/**
21 * cpuidle_register_driver - registers a driver
22 * @drv: the driver
23 */
24int cpuidle_register_driver(struct cpuidle_driver *drv)
25{
26 if (!drv)
27 return -EINVAL;
28
Len Brown62027ae2011-04-01 18:13:10 -040029 if (cpuidle_disabled())
30 return -ENODEV;
31
Len Brown4f86d3a2007-10-03 18:58:00 -040032 spin_lock(&cpuidle_driver_lock);
33 if (cpuidle_curr_driver) {
34 spin_unlock(&cpuidle_driver_lock);
35 return -EBUSY;
36 }
37 cpuidle_curr_driver = drv;
38 spin_unlock(&cpuidle_driver_lock);
39
40 return 0;
41}
42
43EXPORT_SYMBOL_GPL(cpuidle_register_driver);
44
45/**
Len Brown752138d2010-05-22 16:57:26 -040046 * cpuidle_get_driver - return the current driver
47 */
48struct cpuidle_driver *cpuidle_get_driver(void)
49{
50 return cpuidle_curr_driver;
51}
52EXPORT_SYMBOL_GPL(cpuidle_get_driver);
53
54/**
Len Brown4f86d3a2007-10-03 18:58:00 -040055 * cpuidle_unregister_driver - unregisters a driver
56 * @drv: the driver
57 */
58void cpuidle_unregister_driver(struct cpuidle_driver *drv)
59{
Len Brownc0d64cb2010-05-22 16:34:10 -040060 if (drv != cpuidle_curr_driver) {
61 WARN(1, "invalid cpuidle_unregister_driver(%s)\n",
62 drv->name);
Len Brown4f86d3a2007-10-03 18:58:00 -040063 return;
Len Brownc0d64cb2010-05-22 16:34:10 -040064 }
Len Brown4f86d3a2007-10-03 18:58:00 -040065
66 spin_lock(&cpuidle_driver_lock);
67 cpuidle_curr_driver = NULL;
68 spin_unlock(&cpuidle_driver_lock);
69}
70
71EXPORT_SYMBOL_GPL(cpuidle_unregister_driver);