pm_domain.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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_WAIT_MASTER, /* PM domain's master is being waited for */
  14. GPD_STATE_BUSY, /* Something is happening to the PM domain */
  15. GPD_STATE_REPEAT, /* Power off in progress, to be repeated */
  16. GPD_STATE_POWER_OFF, /* PM domain is off */
  17. };
  18. struct dev_power_governor {
  19. bool (*power_down_ok)(struct dev_pm_domain *domain);
  20. };
  21. struct gpd_dev_ops {
  22. int (*start)(struct device *dev);
  23. int (*stop)(struct device *dev);
  24. int (*save_state)(struct device *dev);
  25. int (*restore_state)(struct device *dev);
  26. int (*suspend)(struct device *dev);
  27. int (*suspend_late)(struct device *dev);
  28. int (*resume_early)(struct device *dev);
  29. int (*resume)(struct device *dev);
  30. int (*freeze)(struct device *dev);
  31. int (*freeze_late)(struct device *dev);
  32. int (*thaw_early)(struct device *dev);
  33. int (*thaw)(struct device *dev);
  34. bool (*active_wakeup)(struct device *dev);
  35. };
  36. struct generic_pm_domain {
  37. struct dev_pm_domain domain; /* PM domain operations */
  38. struct list_head gpd_list_node; /* Node in the global PM domains list */
  39. struct list_head master_links; /* Links with PM domain as a master */
  40. struct list_head slave_links; /* Links with PM domain as a slave */
  41. struct list_head dev_list; /* List of devices */
  42. struct mutex lock;
  43. struct dev_power_governor *gov;
  44. struct work_struct power_off_work;
  45. unsigned int in_progress; /* Number of devices being suspended now */
  46. atomic_t sd_count; /* Number of subdomains with power "on" */
  47. enum gpd_status status; /* Current state of the domain */
  48. wait_queue_head_t status_wait_queue;
  49. struct task_struct *poweroff_task; /* Powering off task */
  50. unsigned int resume_count; /* Number of devices being resumed */
  51. unsigned int device_count; /* Number of devices */
  52. unsigned int suspended_count; /* System suspend device counter */
  53. unsigned int prepared_count; /* Suspend counter of prepared devices */
  54. bool suspend_power_off; /* Power status before system suspend */
  55. bool dev_irq_safe; /* Device callbacks are IRQ-safe */
  56. int (*power_off)(struct generic_pm_domain *domain);
  57. int (*power_on)(struct generic_pm_domain *domain);
  58. struct gpd_dev_ops dev_ops;
  59. };
  60. static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd)
  61. {
  62. return container_of(pd, struct generic_pm_domain, domain);
  63. }
  64. struct gpd_link {
  65. struct generic_pm_domain *master;
  66. struct list_head master_node;
  67. struct generic_pm_domain *slave;
  68. struct list_head slave_node;
  69. };
  70. struct generic_pm_domain_data {
  71. struct pm_domain_data base;
  72. struct gpd_dev_ops ops;
  73. bool need_restore;
  74. };
  75. static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd)
  76. {
  77. return container_of(pdd, struct generic_pm_domain_data, base);
  78. }
  79. #ifdef CONFIG_PM_GENERIC_DOMAINS
  80. static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
  81. {
  82. return to_gpd_data(dev->power.subsys_data->domain_data);
  83. }
  84. extern int pm_genpd_add_device(struct generic_pm_domain *genpd,
  85. struct device *dev);
  86. extern int pm_genpd_remove_device(struct generic_pm_domain *genpd,
  87. struct device *dev);
  88. extern int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
  89. struct generic_pm_domain *new_subdomain);
  90. extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
  91. struct generic_pm_domain *target);
  92. extern int pm_genpd_add_callbacks(struct device *dev, struct gpd_dev_ops *ops);
  93. extern int pm_genpd_remove_callbacks(struct device *dev);
  94. extern void pm_genpd_init(struct generic_pm_domain *genpd,
  95. struct dev_power_governor *gov, bool is_off);
  96. extern int pm_genpd_poweron(struct generic_pm_domain *genpd);
  97. #else
  98. static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
  99. struct device *dev)
  100. {
  101. return -ENOSYS;
  102. }
  103. static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd,
  104. struct device *dev)
  105. {
  106. return -ENOSYS;
  107. }
  108. static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
  109. struct generic_pm_domain *new_sd)
  110. {
  111. return -ENOSYS;
  112. }
  113. static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
  114. struct generic_pm_domain *target)
  115. {
  116. return -ENOSYS;
  117. }
  118. static inline int pm_genpd_add_callbacks(struct device *dev,
  119. struct gpd_dev_ops *ops)
  120. {
  121. return -ENOSYS;
  122. }
  123. static inline int pm_genpd_remove_callbacks(struct device *dev)
  124. {
  125. return -ENOSYS;
  126. }
  127. static inline void pm_genpd_init(struct generic_pm_domain *genpd,
  128. struct dev_power_governor *gov, bool is_off) {}
  129. static inline int pm_genpd_poweron(struct generic_pm_domain *genpd)
  130. {
  131. return -ENOSYS;
  132. }
  133. #endif
  134. #ifdef CONFIG_PM_GENERIC_DOMAINS_RUNTIME
  135. extern void genpd_queue_power_off_work(struct generic_pm_domain *genpd);
  136. extern void pm_genpd_poweroff_unused(void);
  137. #else
  138. static inline void genpd_queue_power_off_work(struct generic_pm_domain *gpd) {}
  139. static inline void pm_genpd_poweroff_unused(void) {}
  140. #endif
  141. #endif /* _LINUX_PM_DOMAIN_H */