power.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. const char *name;
  29. };
  30. extern void dev_pm_arm_wake_irq(struct wake_irq *wirq);
  31. extern void dev_pm_disarm_wake_irq(struct wake_irq *wirq);
  32. extern void dev_pm_enable_wake_irq_check(struct device *dev,
  33. bool can_change_status);
  34. extern void dev_pm_disable_wake_irq_check(struct device *dev);
  35. #ifdef CONFIG_PM_SLEEP
  36. extern void device_wakeup_attach_irq(struct device *dev, 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 void device_wakeup_attach_irq(struct device *dev,
  42. struct wake_irq *wakeirq) {}
  43. static inline void device_wakeup_detach_irq(struct device *dev)
  44. {
  45. }
  46. #endif /* CONFIG_PM_SLEEP */
  47. /*
  48. * sysfs.c
  49. */
  50. extern int dpm_sysfs_add(struct device *dev);
  51. extern void dpm_sysfs_remove(struct device *dev);
  52. extern void rpm_sysfs_remove(struct device *dev);
  53. extern int wakeup_sysfs_add(struct device *dev);
  54. extern void wakeup_sysfs_remove(struct device *dev);
  55. extern int pm_qos_sysfs_add_resume_latency(struct device *dev);
  56. extern void pm_qos_sysfs_remove_resume_latency(struct device *dev);
  57. extern int pm_qos_sysfs_add_flags(struct device *dev);
  58. extern void pm_qos_sysfs_remove_flags(struct device *dev);
  59. extern int pm_qos_sysfs_add_latency_tolerance(struct device *dev);
  60. extern void pm_qos_sysfs_remove_latency_tolerance(struct device *dev);
  61. #else /* CONFIG_PM */
  62. static inline void pm_runtime_early_init(struct device *dev)
  63. {
  64. device_pm_init_common(dev);
  65. }
  66. static inline void pm_runtime_init(struct device *dev) {}
  67. static inline void pm_runtime_reinit(struct device *dev) {}
  68. static inline void pm_runtime_remove(struct device *dev) {}
  69. static inline int dpm_sysfs_add(struct device *dev) { return 0; }
  70. static inline void dpm_sysfs_remove(struct device *dev) {}
  71. #endif
  72. #ifdef CONFIG_PM_SLEEP
  73. /* kernel/power/main.c */
  74. extern int pm_async_enabled;
  75. /* drivers/base/power/main.c */
  76. extern struct list_head dpm_list; /* The active device list */
  77. static inline struct device *to_device(struct list_head *entry)
  78. {
  79. return container_of(entry, struct device, power.entry);
  80. }
  81. extern void device_pm_sleep_init(struct device *dev);
  82. extern void device_pm_add(struct device *);
  83. extern void device_pm_remove(struct device *);
  84. extern void device_pm_move_before(struct device *, struct device *);
  85. extern void device_pm_move_after(struct device *, struct device *);
  86. extern void device_pm_move_last(struct device *);
  87. extern void device_pm_check_callbacks(struct device *dev);
  88. static inline bool device_pm_initialized(struct device *dev)
  89. {
  90. return dev->power.in_dpm_list;
  91. }
  92. #else /* !CONFIG_PM_SLEEP */
  93. static inline void device_pm_sleep_init(struct device *dev) {}
  94. static inline void device_pm_add(struct device *dev) {}
  95. static inline void device_pm_remove(struct device *dev)
  96. {
  97. pm_runtime_remove(dev);
  98. }
  99. static inline void device_pm_move_before(struct device *deva,
  100. struct device *devb) {}
  101. static inline void device_pm_move_after(struct device *deva,
  102. struct device *devb) {}
  103. static inline void device_pm_move_last(struct device *dev) {}
  104. static inline void device_pm_check_callbacks(struct device *dev) {}
  105. static inline bool device_pm_initialized(struct device *dev)
  106. {
  107. return device_is_registered(dev);
  108. }
  109. #endif /* !CONFIG_PM_SLEEP */
  110. static inline void device_pm_init(struct device *dev)
  111. {
  112. device_pm_init_common(dev);
  113. device_pm_sleep_init(dev);
  114. pm_runtime_init(dev);
  115. }