power.h 4.4 KB

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