power.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. struct wake_irq {
  19. struct device *dev;
  20. int irq;
  21. bool dedicated_irq:1;
  22. };
  23. extern void dev_pm_arm_wake_irq(struct wake_irq *wirq);
  24. extern void dev_pm_disarm_wake_irq(struct wake_irq *wirq);
  25. #ifdef CONFIG_PM_SLEEP
  26. extern int device_wakeup_attach_irq(struct device *dev,
  27. struct wake_irq *wakeirq);
  28. extern void device_wakeup_detach_irq(struct device *dev);
  29. extern void device_wakeup_arm_wake_irqs(void);
  30. extern void device_wakeup_disarm_wake_irqs(void);
  31. #else
  32. static inline int
  33. device_wakeup_attach_irq(struct device *dev,
  34. struct wake_irq *wakeirq)
  35. {
  36. return 0;
  37. }
  38. static inline void device_wakeup_detach_irq(struct device *dev)
  39. {
  40. }
  41. static inline void device_wakeup_arm_wake_irqs(void)
  42. {
  43. }
  44. static inline void device_wakeup_disarm_wake_irqs(void)
  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. #else /* CONFIG_PM */
  63. static inline void pm_runtime_early_init(struct device *dev)
  64. {
  65. device_pm_init_common(dev);
  66. }
  67. static inline void pm_runtime_init(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. static inline void rpm_sysfs_remove(struct device *dev) {}
  72. static inline int wakeup_sysfs_add(struct device *dev) { return 0; }
  73. static inline void wakeup_sysfs_remove(struct device *dev) {}
  74. static inline int pm_qos_sysfs_add(struct device *dev) { return 0; }
  75. static inline void pm_qos_sysfs_remove(struct device *dev) {}
  76. static inline void dev_pm_arm_wake_irq(struct wake_irq *wirq)
  77. {
  78. }
  79. static inline void dev_pm_disarm_wake_irq(struct wake_irq *wirq)
  80. {
  81. }
  82. #endif
  83. #ifdef CONFIG_PM_SLEEP
  84. /* kernel/power/main.c */
  85. extern int pm_async_enabled;
  86. /* drivers/base/power/main.c */
  87. extern struct list_head dpm_list; /* The active device list */
  88. static inline struct device *to_device(struct list_head *entry)
  89. {
  90. return container_of(entry, struct device, power.entry);
  91. }
  92. extern void device_pm_sleep_init(struct device *dev);
  93. extern void device_pm_add(struct device *);
  94. extern void device_pm_remove(struct device *);
  95. extern void device_pm_move_before(struct device *, struct device *);
  96. extern void device_pm_move_after(struct device *, struct device *);
  97. extern void device_pm_move_last(struct device *);
  98. #else /* !CONFIG_PM_SLEEP */
  99. static inline void device_pm_sleep_init(struct device *dev) {}
  100. static inline void device_pm_add(struct device *dev) {}
  101. static inline void device_pm_remove(struct device *dev)
  102. {
  103. pm_runtime_remove(dev);
  104. }
  105. static inline void device_pm_move_before(struct device *deva,
  106. struct device *devb) {}
  107. static inline void device_pm_move_after(struct device *deva,
  108. struct device *devb) {}
  109. static inline void device_pm_move_last(struct device *dev) {}
  110. #endif /* !CONFIG_PM_SLEEP */
  111. static inline void device_pm_init(struct device *dev)
  112. {
  113. device_pm_init_common(dev);
  114. device_pm_sleep_init(dev);
  115. pm_runtime_init(dev);
  116. }