pm_domain.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * pm_domain.h - Definitions and headers related to device power domains.
  3. *
  4. * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Renesas Electronics Corp.
  5. *
  6. * This file is released under the GPLv2.
  7. */
  8. #ifndef _LINUX_PM_DOMAIN_H
  9. #define _LINUX_PM_DOMAIN_H
  10. #include <linux/device.h>
  11. enum gpd_status {
  12. GPD_STATE_ACTIVE = 0, /* PM domain is active */
  13. GPD_STATE_BUSY, /* Something is happening to the PM domain */
  14. GPD_STATE_REPEAT, /* Power off in progress, to be repeated */
  15. GPD_STATE_POWER_OFF, /* PM domain is off */
  16. };
  17. struct dev_power_governor {
  18. bool (*power_down_ok)(struct dev_pm_domain *domain);
  19. };
  20. struct generic_pm_domain {
  21. struct dev_pm_domain domain; /* PM domain operations */
  22. struct list_head gpd_list_node; /* Node in the global PM domains list */
  23. struct list_head sd_node; /* Node in the parent's subdomain list */
  24. struct generic_pm_domain *parent; /* Parent PM domain */
  25. struct list_head sd_list; /* List of dubdomains */
  26. struct list_head dev_list; /* List of devices */
  27. struct mutex lock;
  28. struct dev_power_governor *gov;
  29. struct work_struct power_off_work;
  30. unsigned int in_progress; /* Number of devices being suspended now */
  31. unsigned int sd_count; /* Number of subdomains with power "on" */
  32. enum gpd_status status; /* Current state of the domain */
  33. wait_queue_head_t status_wait_queue;
  34. struct task_struct *poweroff_task; /* Powering off task */
  35. unsigned int resume_count; /* Number of devices being resumed */
  36. unsigned int device_count; /* Number of devices */
  37. unsigned int suspended_count; /* System suspend device counter */
  38. unsigned int prepared_count; /* Suspend counter of prepared devices */
  39. bool suspend_power_off; /* Power status before system suspend */
  40. int (*power_off)(struct generic_pm_domain *domain);
  41. int (*power_on)(struct generic_pm_domain *domain);
  42. int (*start_device)(struct device *dev);
  43. int (*stop_device)(struct device *dev);
  44. bool (*active_wakeup)(struct device *dev);
  45. };
  46. static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd)
  47. {
  48. return container_of(pd, struct generic_pm_domain, domain);
  49. }
  50. struct dev_list_entry {
  51. struct list_head node;
  52. struct device *dev;
  53. bool need_restore;
  54. };
  55. #ifdef CONFIG_PM_GENERIC_DOMAINS
  56. extern int pm_genpd_add_device(struct generic_pm_domain *genpd,
  57. struct device *dev);
  58. extern int pm_genpd_remove_device(struct generic_pm_domain *genpd,
  59. struct device *dev);
  60. extern int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
  61. struct generic_pm_domain *new_subdomain);
  62. extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
  63. struct generic_pm_domain *target);
  64. extern void pm_genpd_init(struct generic_pm_domain *genpd,
  65. struct dev_power_governor *gov, bool is_off);
  66. extern int pm_genpd_poweron(struct generic_pm_domain *genpd);
  67. #else
  68. static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
  69. struct device *dev)
  70. {
  71. return -ENOSYS;
  72. }
  73. static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd,
  74. struct device *dev)
  75. {
  76. return -ENOSYS;
  77. }
  78. static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
  79. struct generic_pm_domain *new_sd)
  80. {
  81. return -ENOSYS;
  82. }
  83. static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
  84. struct generic_pm_domain *target)
  85. {
  86. return -ENOSYS;
  87. }
  88. static inline void pm_genpd_init(struct generic_pm_domain *genpd,
  89. struct dev_power_governor *gov, bool is_off) {}
  90. static inline int pm_genpd_poweron(struct generic_pm_domain *genpd)
  91. {
  92. return -ENOSYS;
  93. }
  94. #endif
  95. #ifdef CONFIG_PM_GENERIC_DOMAINS_RUNTIME
  96. extern void genpd_queue_power_off_work(struct generic_pm_domain *genpd);
  97. extern void pm_genpd_poweroff_unused(void);
  98. #else
  99. static inline void genpd_queue_power_off_work(struct generic_pm_domain *gpd) {}
  100. static inline void pm_genpd_poweroff_unused(void) {}
  101. #endif
  102. #endif /* _LINUX_PM_DOMAIN_H */