power.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #else /* CONFIG_PM */
  61. static inline void pm_runtime_early_init(struct device *dev)
  62. {
  63. device_pm_init_common(dev);
  64. }
  65. static inline void pm_runtime_init(struct device *dev) {}
  66. static inline void pm_runtime_remove(struct device *dev) {}
  67. static inline int dpm_sysfs_add(struct device *dev) { return 0; }
  68. static inline void dpm_sysfs_remove(struct device *dev) {}
  69. static inline void rpm_sysfs_remove(struct device *dev) {}
  70. static inline int wakeup_sysfs_add(struct device *dev) { return 0; }
  71. static inline void wakeup_sysfs_remove(struct device *dev) {}
  72. static inline int pm_qos_sysfs_add(struct device *dev) { return 0; }
  73. static inline void pm_qos_sysfs_remove(struct device *dev) {}
  74. static inline void dev_pm_arm_wake_irq(struct wake_irq *wirq)
  75. {
  76. }
  77. static inline void dev_pm_disarm_wake_irq(struct wake_irq *wirq)
  78. {
  79. }
  80. #endif
  81. #ifdef CONFIG_PM_SLEEP
  82. /* kernel/power/main.c */
  83. extern int pm_async_enabled;
  84. /* drivers/base/power/main.c */
  85. extern struct list_head dpm_list; /* The active device list */
  86. static inline struct device *to_device(struct list_head *entry)
  87. {
  88. return container_of(entry, struct device, power.entry);
  89. }
  90. extern void device_pm_sleep_init(struct device *dev);
  91. extern void device_pm_add(struct device *);
  92. extern void device_pm_remove(struct device *);
  93. extern void device_pm_move_before(struct device *, struct device *);
  94. extern void device_pm_move_after(struct device *, struct device *);
  95. extern void device_pm_move_last(struct device *);
  96. #else /* !CONFIG_PM_SLEEP */
  97. static inline void device_pm_sleep_init(struct device *dev) {}
  98. static inline void device_pm_add(struct device *dev) {}
  99. static inline void device_pm_remove(struct device *dev)
  100. {
  101. pm_runtime_remove(dev);
  102. }
  103. static inline void device_pm_move_before(struct device *deva,
  104. struct device *devb) {}
  105. static inline void device_pm_move_after(struct device *deva,
  106. struct device *devb) {}
  107. static inline void device_pm_move_last(struct device *dev) {}
  108. #endif /* !CONFIG_PM_SLEEP */
  109. static inline void device_pm_init(struct device *dev)
  110. {
  111. device_pm_init_common(dev);
  112. device_pm_sleep_init(dev);
  113. pm_runtime_init(dev);
  114. }