power.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.power_state = PMSG_INVALID;
  7. dev->power.early_init = true;
  8. }
  9. }
  10. #ifdef CONFIG_PM_RUNTIME
  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. #else /* !CONFIG_PM_RUNTIME */
  19. static inline void pm_runtime_early_init(struct device *dev)
  20. {
  21. device_pm_init_common(dev);
  22. }
  23. static inline void pm_runtime_init(struct device *dev) {}
  24. static inline void pm_runtime_remove(struct device *dev) {}
  25. #endif /* !CONFIG_PM_RUNTIME */
  26. #ifdef CONFIG_PM_SLEEP
  27. /* kernel/power/main.c */
  28. extern int pm_async_enabled;
  29. /* drivers/base/power/main.c */
  30. extern struct list_head dpm_list; /* The active device list */
  31. static inline struct device *to_device(struct list_head *entry)
  32. {
  33. return container_of(entry, struct device, power.entry);
  34. }
  35. extern void device_pm_sleep_init(struct device *dev);
  36. extern void device_pm_add(struct device *);
  37. extern void device_pm_remove(struct device *);
  38. extern void device_pm_move_before(struct device *, struct device *);
  39. extern void device_pm_move_after(struct device *, struct device *);
  40. extern void device_pm_move_last(struct device *);
  41. #else /* !CONFIG_PM_SLEEP */
  42. static inline void device_pm_sleep_init(struct device *dev) {}
  43. static inline void device_pm_add(struct device *dev)
  44. {
  45. dev_pm_qos_constraints_init(dev);
  46. }
  47. static inline void device_pm_remove(struct device *dev)
  48. {
  49. dev_pm_qos_constraints_destroy(dev);
  50. pm_runtime_remove(dev);
  51. }
  52. static inline void device_pm_move_before(struct device *deva,
  53. struct device *devb) {}
  54. static inline void device_pm_move_after(struct device *deva,
  55. struct device *devb) {}
  56. static inline void device_pm_move_last(struct device *dev) {}
  57. #endif /* !CONFIG_PM_SLEEP */
  58. static inline void device_pm_init(struct device *dev)
  59. {
  60. device_pm_init_common(dev);
  61. device_pm_sleep_init(dev);
  62. pm_runtime_init(dev);
  63. }
  64. #ifdef CONFIG_PM
  65. /*
  66. * sysfs.c
  67. */
  68. extern int dpm_sysfs_add(struct device *dev);
  69. extern void dpm_sysfs_remove(struct device *dev);
  70. extern void rpm_sysfs_remove(struct device *dev);
  71. extern int wakeup_sysfs_add(struct device *dev);
  72. extern void wakeup_sysfs_remove(struct device *dev);
  73. extern int pm_qos_sysfs_add_latency(struct device *dev);
  74. extern void pm_qos_sysfs_remove_latency(struct device *dev);
  75. extern int pm_qos_sysfs_add_flags(struct device *dev);
  76. extern void pm_qos_sysfs_remove_flags(struct device *dev);
  77. #else /* CONFIG_PM */
  78. static inline int dpm_sysfs_add(struct device *dev) { return 0; }
  79. static inline void dpm_sysfs_remove(struct device *dev) {}
  80. static inline void rpm_sysfs_remove(struct device *dev) {}
  81. static inline int wakeup_sysfs_add(struct device *dev) { return 0; }
  82. static inline void wakeup_sysfs_remove(struct device *dev) {}
  83. static inline int pm_qos_sysfs_add(struct device *dev) { return 0; }
  84. static inline void pm_qos_sysfs_remove(struct device *dev) {}
  85. #endif