driver.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. #include <linux/mutex.h>
  11. #include <linux/module.h>
  12. #include <linux/cpuidle.h>
  13. #include "cpuidle.h"
  14. static struct cpuidle_driver *cpuidle_curr_driver;
  15. DEFINE_SPINLOCK(cpuidle_driver_lock);
  16. /**
  17. * cpuidle_register_driver - registers a driver
  18. * @drv: the driver
  19. */
  20. int cpuidle_register_driver(struct cpuidle_driver *drv)
  21. {
  22. if (!drv)
  23. return -EINVAL;
  24. spin_lock(&cpuidle_driver_lock);
  25. if (cpuidle_curr_driver) {
  26. spin_unlock(&cpuidle_driver_lock);
  27. return -EBUSY;
  28. }
  29. cpuidle_curr_driver = drv;
  30. spin_unlock(&cpuidle_driver_lock);
  31. return 0;
  32. }
  33. EXPORT_SYMBOL_GPL(cpuidle_register_driver);
  34. /**
  35. * cpuidle_get_driver - return the current driver
  36. */
  37. struct cpuidle_driver *cpuidle_get_driver(void)
  38. {
  39. return cpuidle_curr_driver;
  40. }
  41. EXPORT_SYMBOL_GPL(cpuidle_get_driver);
  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 != cpuidle_curr_driver) {
  49. WARN(1, "invalid cpuidle_unregister_driver(%s)\n",
  50. drv->name);
  51. return;
  52. }
  53. spin_lock(&cpuidle_driver_lock);
  54. cpuidle_curr_driver = NULL;
  55. spin_unlock(&cpuidle_driver_lock);
  56. }
  57. EXPORT_SYMBOL_GPL(cpuidle_unregister_driver);