power.h 4.9 KB

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