power.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #include <linux/pm_qos.h>
  2. static inline void device_pm_init_common(struct device *dev)
  3. {
  4. if (!dev->power.early_init) {
  5. spin_lock_init(&dev->power.lock);
  6. dev->power.qos = NULL;
  7. dev->power.early_init = true;
  8. }
  9. }
  10. #ifdef CONFIG_PM
  11. static inline void pm_runtime_early_init(struct device *dev)
  12. {
  13. dev->power.disable_depth = 1;
  14. device_pm_init_common(dev);
  15. }
  16. extern void pm_runtime_init(struct device *dev);
  17. extern void pm_runtime_reinit(struct device *dev);
  18. extern void pm_runtime_remove(struct device *dev);
  19. #define WAKE_IRQ_DEDICATED_ALLOCATED BIT(0)
  20. #define WAKE_IRQ_DEDICATED_MANAGED BIT(1)
  21. #define WAKE_IRQ_DEDICATED_MASK (WAKE_IRQ_DEDICATED_ALLOCATED | \
  22. WAKE_IRQ_DEDICATED_MANAGED)
  23. struct wake_irq {
  24. struct device *dev;
  25. unsigned int status;
  26. int irq;
  27. };
  28. extern void dev_pm_arm_wake_irq(struct wake_irq *wirq);
  29. extern void dev_pm_disarm_wake_irq(struct wake_irq *wirq);
  30. extern void dev_pm_enable_wake_irq_check(struct device *dev,
  31. bool can_change_status);
  32. extern void dev_pm_disable_wake_irq_check(struct device *dev);
  33. #ifdef CONFIG_PM_SLEEP
  34. extern int device_wakeup_attach_irq(struct device *dev,
  35. struct wake_irq *wakeirq);
  36. extern void device_wakeup_detach_irq(struct device *dev);
  37. extern void device_wakeup_arm_wake_irqs(void);
  38. extern void device_wakeup_disarm_wake_irqs(void);
  39. #else
  40. static inline int
  41. device_wakeup_attach_irq(struct device *dev,
  42. struct wake_irq *wakeirq)
  43. {
  44. return 0;
  45. }
  46. static inline void device_wakeup_detach_irq(struct device *dev)
  47. {
  48. }
  49. static inline void device_wakeup_arm_wake_irqs(void)
  50. {
  51. }
  52. static inline void device_wakeup_disarm_wake_irqs(void)
  53. {
  54. }
  55. #endif /* CONFIG_PM_SLEEP */
  56. /*
  57. * sysfs.c
  58. */
  59. extern int dpm_sysfs_add(struct device *dev);
  60. extern void dpm_sysfs_remove(struct device *dev);
  61. extern void rpm_sysfs_remove(struct device *dev);
  62. extern int wakeup_sysfs_add(struct device *dev);
  63. extern void wakeup_sysfs_remove(struct device *dev);
  64. extern int pm_qos_sysfs_add_resume_latency(struct device *dev);
  65. extern void pm_qos_sysfs_remove_resume_latency(struct device *dev);
  66. extern int pm_qos_sysfs_add_flags(struct device *dev);
  67. extern void pm_qos_sysfs_remove_flags(struct device *dev);
  68. extern int pm_qos_sysfs_add_latency_tolerance(struct device *dev);
  69. extern void pm_qos_sysfs_remove_latency_tolerance(struct device *dev);
  70. #else /* CONFIG_PM */
  71. static inline void pm_runtime_early_init(struct device *dev)
  72. {
  73. device_pm_init_common(dev);
  74. }
  75. static inline void pm_runtime_init(struct device *dev) {}
  76. static inline void pm_runtime_reinit(struct device *dev) {}
  77. static inline void pm_runtime_remove(struct device *dev) {}
  78. static inline int dpm_sysfs_add(struct device *dev) { return 0; }
  79. static inline void dpm_sysfs_remove(struct device *dev) {}
  80. static inline void rpm_sysfs_remove(struct device *dev) {}
  81. static inline int wakeup_sysfs_add(struct device *dev) { return 0; }
  82. static inline void wakeup_sysfs_remove(struct device *dev) {}
  83. static inline int pm_qos_sysfs_add(struct device *dev) { return 0; }
  84. static inline void pm_qos_sysfs_remove(struct device *dev) {}
  85. static inline void dev_pm_arm_wake_irq(struct wake_irq *wirq)
  86. {
  87. }
  88. static inline void dev_pm_disarm_wake_irq(struct wake_irq *wirq)
  89. {
  90. }
  91. static inline void dev_pm_enable_wake_irq_check(struct device *dev,
  92. bool can_change_status)
  93. {
  94. }
  95. static inline void dev_pm_disable_wake_irq_check(struct device *dev)
  96. {
  97. }
  98. #endif
  99. #ifdef CONFIG_PM_SLEEP
  100. /* kernel/power/main.c */
  101. extern int pm_async_enabled;
  102. /* drivers/base/power/main.c */
  103. extern struct list_head dpm_list; /* The active device list */
  104. static inline struct device *to_device(struct list_head *entry)
  105. {
  106. return container_of(entry, struct device, power.entry);
  107. }
  108. extern void device_pm_sleep_init(struct device *dev);
  109. extern void device_pm_add(struct device *);
  110. extern void device_pm_remove(struct device *);
  111. extern void device_pm_move_before(struct device *, struct device *);
  112. extern void device_pm_move_after(struct device *, struct device *);
  113. extern void device_pm_move_last(struct device *);
  114. extern void device_pm_check_callbacks(struct device *dev);
  115. #else /* !CONFIG_PM_SLEEP */
  116. static inline void device_pm_sleep_init(struct device *dev) {}
  117. static inline void device_pm_add(struct device *dev) {}
  118. static inline void device_pm_remove(struct device *dev)
  119. {
  120. pm_runtime_remove(dev);
  121. }
  122. static inline void device_pm_move_before(struct device *deva,
  123. struct device *devb) {}
  124. static inline void device_pm_move_after(struct device *deva,
  125. struct device *devb) {}
  126. static inline void device_pm_move_last(struct device *dev) {}
  127. static inline void device_pm_check_callbacks(struct device *dev) {}
  128. #endif /* !CONFIG_PM_SLEEP */
  129. static inline void device_pm_init(struct device *dev)
  130. {
  131. device_pm_init_common(dev);
  132. device_pm_sleep_init(dev);
  133. pm_runtime_init(dev);
  134. }