power.h 4.8 KB

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