power.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. extern u64 pm_runtime_active_time(struct device *dev);
  21. #define WAKE_IRQ_DEDICATED_ALLOCATED BIT(0)
  22. #define WAKE_IRQ_DEDICATED_MANAGED BIT(1)
  23. #define WAKE_IRQ_DEDICATED_REVERSE BIT(2)
  24. #define WAKE_IRQ_DEDICATED_MASK (WAKE_IRQ_DEDICATED_ALLOCATED | \
  25. WAKE_IRQ_DEDICATED_MANAGED | \
  26. WAKE_IRQ_DEDICATED_REVERSE)
  27. #define WAKE_IRQ_DEDICATED_ENABLED BIT(3)
  28. struct wake_irq {
  29. struct device *dev;
  30. unsigned int status;
  31. int irq;
  32. const char *name;
  33. };
  34. extern void dev_pm_arm_wake_irq(struct wake_irq *wirq);
  35. extern void dev_pm_disarm_wake_irq(struct wake_irq *wirq);
  36. extern void dev_pm_enable_wake_irq_check(struct device *dev,
  37. bool can_change_status);
  38. extern void dev_pm_disable_wake_irq_check(struct device *dev, bool cond_disable);
  39. extern void dev_pm_enable_wake_irq_complete(struct device *dev);
  40. #ifdef CONFIG_PM_SLEEP
  41. extern void device_wakeup_attach_irq(struct device *dev, struct wake_irq *wakeirq);
  42. extern void device_wakeup_detach_irq(struct device *dev);
  43. extern void device_wakeup_arm_wake_irqs(void);
  44. extern void device_wakeup_disarm_wake_irqs(void);
  45. #else
  46. static inline void device_wakeup_attach_irq(struct device *dev,
  47. struct wake_irq *wakeirq) {}
  48. static inline void device_wakeup_detach_irq(struct device *dev)
  49. {
  50. }
  51. #endif /* CONFIG_PM_SLEEP */
  52. /*
  53. * sysfs.c
  54. */
  55. extern int dpm_sysfs_add(struct device *dev);
  56. extern void dpm_sysfs_remove(struct device *dev);
  57. extern void rpm_sysfs_remove(struct device *dev);
  58. extern int wakeup_sysfs_add(struct device *dev);
  59. extern void wakeup_sysfs_remove(struct device *dev);
  60. extern int pm_qos_sysfs_add_resume_latency(struct device *dev);
  61. extern void pm_qos_sysfs_remove_resume_latency(struct device *dev);
  62. extern int pm_qos_sysfs_add_flags(struct device *dev);
  63. extern void pm_qos_sysfs_remove_flags(struct device *dev);
  64. extern int pm_qos_sysfs_add_latency_tolerance(struct device *dev);
  65. extern void pm_qos_sysfs_remove_latency_tolerance(struct device *dev);
  66. extern int dpm_sysfs_change_owner(struct device *dev, kuid_t kuid, kgid_t kgid);
  67. #else /* CONFIG_PM */
  68. static inline void pm_runtime_early_init(struct device *dev)
  69. {
  70. device_pm_init_common(dev);
  71. }
  72. static inline void pm_runtime_init(struct device *dev) {}
  73. static inline void pm_runtime_reinit(struct device *dev) {}
  74. static inline void pm_runtime_remove(struct device *dev) {}
  75. static inline int dpm_sysfs_add(struct device *dev) { return 0; }
  76. static inline void dpm_sysfs_remove(struct device *dev) {}
  77. static inline int dpm_sysfs_change_owner(struct device *dev, kuid_t kuid,
  78. kgid_t kgid) { return 0; }
  79. #endif
  80. #ifdef CONFIG_PM_SLEEP
  81. /* kernel/power/main.c */
  82. extern int pm_async_enabled;
  83. /* drivers/base/power/main.c */
  84. extern struct list_head dpm_list; /* The active device list */
  85. static inline struct device *to_device(struct list_head *entry)
  86. {
  87. return container_of(entry, struct device, power.entry);
  88. }
  89. extern void device_pm_sleep_init(struct device *dev);
  90. extern void device_pm_add(struct device *);
  91. extern void device_pm_remove(struct device *);
  92. extern void device_pm_move_before(struct device *, struct device *);
  93. extern void device_pm_move_after(struct device *, struct device *);
  94. extern void device_pm_move_last(struct device *);
  95. extern void device_pm_check_callbacks(struct device *dev);
  96. static inline bool device_pm_initialized(struct device *dev)
  97. {
  98. return dev->power.in_dpm_list;
  99. }
  100. /* drivers/base/power/wakeup_stats.c */
  101. extern int wakeup_source_sysfs_add(struct device *parent,
  102. struct wakeup_source *ws);
  103. extern void wakeup_source_sysfs_remove(struct wakeup_source *ws);
  104. extern int pm_wakeup_source_sysfs_add(struct device *parent);
  105. #else /* !CONFIG_PM_SLEEP */
  106. static inline void device_pm_sleep_init(struct device *dev) {}
  107. static inline void device_pm_add(struct device *dev) {}
  108. static inline void device_pm_remove(struct device *dev)
  109. {
  110. pm_runtime_remove(dev);
  111. }
  112. static inline void device_pm_move_before(struct device *deva,
  113. struct device *devb) {}
  114. static inline void device_pm_move_after(struct device *deva,
  115. struct device *devb) {}
  116. static inline void device_pm_move_last(struct device *dev) {}
  117. static inline void device_pm_check_callbacks(struct device *dev) {}
  118. static inline bool device_pm_initialized(struct device *dev)
  119. {
  120. return device_is_registered(dev);
  121. }
  122. static inline int pm_wakeup_source_sysfs_add(struct device *parent)
  123. {
  124. return 0;
  125. }
  126. #endif /* !CONFIG_PM_SLEEP */
  127. static inline void device_pm_init(struct device *dev)
  128. {
  129. device_pm_init_common(dev);
  130. device_pm_sleep_init(dev);
  131. pm_runtime_init(dev);
  132. }