power.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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_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. static inline void device_pm_remove(struct device *dev)
  45. {
  46. pm_runtime_remove(dev);
  47. }
  48. static inline void device_pm_move_before(struct device *deva,
  49. struct device *devb) {}
  50. static inline void device_pm_move_after(struct device *deva,
  51. struct device *devb) {}
  52. static inline void device_pm_move_last(struct device *dev) {}
  53. #endif /* !CONFIG_PM_SLEEP */
  54. static inline void device_pm_init(struct device *dev)
  55. {
  56. device_pm_init_common(dev);
  57. device_pm_sleep_init(dev);
  58. pm_runtime_init(dev);
  59. }
  60. #ifdef CONFIG_PM
  61. /*
  62. * sysfs.c
  63. */
  64. extern int dpm_sysfs_add(struct device *dev);
  65. extern void dpm_sysfs_remove(struct device *dev);
  66. extern void rpm_sysfs_remove(struct device *dev);
  67. extern int wakeup_sysfs_add(struct device *dev);
  68. extern void wakeup_sysfs_remove(struct device *dev);
  69. extern int pm_qos_sysfs_add_latency(struct device *dev);
  70. extern void pm_qos_sysfs_remove_latency(struct device *dev);
  71. extern int pm_qos_sysfs_add_flags(struct device *dev);
  72. extern void pm_qos_sysfs_remove_flags(struct device *dev);
  73. #else /* CONFIG_PM */
  74. static inline int dpm_sysfs_add(struct device *dev) { return 0; }
  75. static inline void dpm_sysfs_remove(struct device *dev) {}
  76. static inline void rpm_sysfs_remove(struct device *dev) {}
  77. static inline int wakeup_sysfs_add(struct device *dev) { return 0; }
  78. static inline void wakeup_sysfs_remove(struct device *dev) {}
  79. static inline int pm_qos_sysfs_add(struct device *dev) { return 0; }
  80. static inline void pm_qos_sysfs_remove(struct device *dev) {}
  81. #endif