power.h 2.9 KB

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