pm_runtime.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * pm_runtime.h - Device run-time power management helper functions.
  3. *
  4. * Copyright (C) 2009 Rafael J. Wysocki <rjw@sisk.pl>
  5. *
  6. * This file is released under the GPLv2.
  7. */
  8. #ifndef _LINUX_PM_RUNTIME_H
  9. #define _LINUX_PM_RUNTIME_H
  10. #include <linux/device.h>
  11. #include <linux/pm.h>
  12. #ifdef CONFIG_PM_RUNTIME
  13. extern struct workqueue_struct *pm_wq;
  14. extern int pm_runtime_idle(struct device *dev);
  15. extern int pm_runtime_suspend(struct device *dev);
  16. extern int pm_runtime_resume(struct device *dev);
  17. extern int pm_request_idle(struct device *dev);
  18. extern int pm_schedule_suspend(struct device *dev, unsigned int delay);
  19. extern int pm_request_resume(struct device *dev);
  20. extern int __pm_runtime_get(struct device *dev, bool sync);
  21. extern int __pm_runtime_put(struct device *dev, bool sync);
  22. extern int __pm_runtime_set_status(struct device *dev, unsigned int status);
  23. extern int pm_runtime_barrier(struct device *dev);
  24. extern void pm_runtime_enable(struct device *dev);
  25. extern void __pm_runtime_disable(struct device *dev, bool check_resume);
  26. static inline bool pm_children_suspended(struct device *dev)
  27. {
  28. return dev->power.ignore_children
  29. || !atomic_read(&dev->power.child_count);
  30. }
  31. static inline void pm_suspend_ignore_children(struct device *dev, bool enable)
  32. {
  33. dev->power.ignore_children = enable;
  34. }
  35. static inline void pm_runtime_get_noresume(struct device *dev)
  36. {
  37. atomic_inc(&dev->power.usage_count);
  38. }
  39. static inline void pm_runtime_put_noidle(struct device *dev)
  40. {
  41. atomic_add_unless(&dev->power.usage_count, -1, 0);
  42. }
  43. #else /* !CONFIG_PM_RUNTIME */
  44. static inline int pm_runtime_idle(struct device *dev) { return -ENOSYS; }
  45. static inline int pm_runtime_suspend(struct device *dev) { return -ENOSYS; }
  46. static inline int pm_runtime_resume(struct device *dev) { return 0; }
  47. static inline int pm_request_idle(struct device *dev) { return -ENOSYS; }
  48. static inline int pm_schedule_suspend(struct device *dev, unsigned int delay)
  49. {
  50. return -ENOSYS;
  51. }
  52. static inline int pm_request_resume(struct device *dev) { return 0; }
  53. static inline int __pm_runtime_get(struct device *dev, bool sync) { return 1; }
  54. static inline int __pm_runtime_put(struct device *dev, bool sync) { return 0; }
  55. static inline int __pm_runtime_set_status(struct device *dev,
  56. unsigned int status) { return 0; }
  57. static inline int pm_runtime_barrier(struct device *dev) { return 0; }
  58. static inline void pm_runtime_enable(struct device *dev) {}
  59. static inline void __pm_runtime_disable(struct device *dev, bool c) {}
  60. static inline bool pm_children_suspended(struct device *dev) { return false; }
  61. static inline void pm_suspend_ignore_children(struct device *dev, bool en) {}
  62. static inline void pm_runtime_get_noresume(struct device *dev) {}
  63. static inline void pm_runtime_put_noidle(struct device *dev) {}
  64. #endif /* !CONFIG_PM_RUNTIME */
  65. static inline int pm_runtime_get(struct device *dev)
  66. {
  67. return __pm_runtime_get(dev, false);
  68. }
  69. static inline int pm_runtime_get_sync(struct device *dev)
  70. {
  71. return __pm_runtime_get(dev, true);
  72. }
  73. static inline int pm_runtime_put(struct device *dev)
  74. {
  75. return __pm_runtime_put(dev, false);
  76. }
  77. static inline int pm_runtime_put_sync(struct device *dev)
  78. {
  79. return __pm_runtime_put(dev, true);
  80. }
  81. static inline int pm_runtime_set_active(struct device *dev)
  82. {
  83. return __pm_runtime_set_status(dev, RPM_ACTIVE);
  84. }
  85. static inline void pm_runtime_set_suspended(struct device *dev)
  86. {
  87. __pm_runtime_set_status(dev, RPM_SUSPENDED);
  88. }
  89. static inline void pm_runtime_disable(struct device *dev)
  90. {
  91. __pm_runtime_disable(dev, true);
  92. }
  93. #endif