pm_domain.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. #include <linux/mutex.h>
  12. #include <linux/pm.h>
  13. #include <linux/err.h>
  14. #include <linux/of.h>
  15. #include <linux/notifier.h>
  16. enum gpd_status {
  17. GPD_STATE_ACTIVE = 0, /* PM domain is active */
  18. GPD_STATE_WAIT_MASTER, /* PM domain's master is being waited for */
  19. GPD_STATE_BUSY, /* Something is happening to the PM domain */
  20. GPD_STATE_REPEAT, /* Power off in progress, to be repeated */
  21. GPD_STATE_POWER_OFF, /* PM domain is off */
  22. };
  23. struct dev_power_governor {
  24. bool (*power_down_ok)(struct dev_pm_domain *domain);
  25. bool (*stop_ok)(struct device *dev);
  26. };
  27. struct gpd_dev_ops {
  28. int (*start)(struct device *dev);
  29. int (*stop)(struct device *dev);
  30. int (*save_state)(struct device *dev);
  31. int (*restore_state)(struct device *dev);
  32. int (*suspend)(struct device *dev);
  33. int (*suspend_late)(struct device *dev);
  34. int (*resume_early)(struct device *dev);
  35. int (*resume)(struct device *dev);
  36. int (*freeze)(struct device *dev);
  37. int (*freeze_late)(struct device *dev);
  38. int (*thaw_early)(struct device *dev);
  39. int (*thaw)(struct device *dev);
  40. bool (*active_wakeup)(struct device *dev);
  41. };
  42. struct generic_pm_domain {
  43. struct dev_pm_domain domain; /* PM domain operations */
  44. struct list_head gpd_list_node; /* Node in the global PM domains list */
  45. struct list_head master_links; /* Links with PM domain as a master */
  46. struct list_head slave_links; /* Links with PM domain as a slave */
  47. struct list_head dev_list; /* List of devices */
  48. struct mutex lock;
  49. struct dev_power_governor *gov;
  50. struct work_struct power_off_work;
  51. char *name;
  52. unsigned int in_progress; /* Number of devices being suspended now */
  53. atomic_t sd_count; /* Number of subdomains with power "on" */
  54. enum gpd_status status; /* Current state of the domain */
  55. wait_queue_head_t status_wait_queue;
  56. struct task_struct *poweroff_task; /* Powering off task */
  57. unsigned int resume_count; /* Number of devices being resumed */
  58. unsigned int device_count; /* Number of devices */
  59. unsigned int suspended_count; /* System suspend device counter */
  60. unsigned int prepared_count; /* Suspend counter of prepared devices */
  61. bool suspend_power_off; /* Power status before system suspend */
  62. bool dev_irq_safe; /* Device callbacks are IRQ-safe */
  63. int (*power_off)(struct generic_pm_domain *domain);
  64. s64 power_off_latency_ns;
  65. int (*power_on)(struct generic_pm_domain *domain);
  66. s64 power_on_latency_ns;
  67. struct gpd_dev_ops dev_ops;
  68. s64 max_off_time_ns; /* Maximum allowed "suspended" time. */
  69. bool max_off_time_changed;
  70. bool cached_power_down_ok;
  71. struct device_node *of_node; /* Node in device tree */
  72. };
  73. static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd)
  74. {
  75. return container_of(pd, struct generic_pm_domain, domain);
  76. }
  77. struct gpd_link {
  78. struct generic_pm_domain *master;
  79. struct list_head master_node;
  80. struct generic_pm_domain *slave;
  81. struct list_head slave_node;
  82. };
  83. struct gpd_timing_data {
  84. s64 stop_latency_ns;
  85. s64 start_latency_ns;
  86. s64 save_state_latency_ns;
  87. s64 restore_state_latency_ns;
  88. s64 effective_constraint_ns;
  89. bool constraint_changed;
  90. bool cached_stop_ok;
  91. };
  92. struct generic_pm_domain_data {
  93. struct pm_domain_data base;
  94. struct gpd_dev_ops ops;
  95. struct gpd_timing_data td;
  96. struct notifier_block nb;
  97. struct mutex lock;
  98. bool need_restore;
  99. bool always_on;
  100. };
  101. #ifdef CONFIG_PM_GENERIC_DOMAINS
  102. static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd)
  103. {
  104. return container_of(pdd, struct generic_pm_domain_data, base);
  105. }
  106. static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
  107. {
  108. return to_gpd_data(dev->power.subsys_data->domain_data);
  109. }
  110. extern struct dev_power_governor simple_qos_governor;
  111. extern struct generic_pm_domain *dev_to_genpd(struct device *dev);
  112. extern int __pm_genpd_add_device(struct generic_pm_domain *genpd,
  113. struct device *dev,
  114. struct gpd_timing_data *td);
  115. extern int __pm_genpd_of_add_device(struct device_node *genpd_node,
  116. struct device *dev,
  117. struct gpd_timing_data *td);
  118. static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
  119. struct device *dev)
  120. {
  121. return __pm_genpd_add_device(genpd, dev, NULL);
  122. }
  123. static inline int pm_genpd_of_add_device(struct device_node *genpd_node,
  124. struct device *dev)
  125. {
  126. return __pm_genpd_of_add_device(genpd_node, dev, NULL);
  127. }
  128. extern int pm_genpd_remove_device(struct generic_pm_domain *genpd,
  129. struct device *dev);
  130. extern void pm_genpd_dev_always_on(struct device *dev, bool val);
  131. extern void pm_genpd_dev_need_restore(struct device *dev, bool val);
  132. extern int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
  133. struct generic_pm_domain *new_subdomain);
  134. extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
  135. struct generic_pm_domain *target);
  136. extern int pm_genpd_add_callbacks(struct device *dev,
  137. struct gpd_dev_ops *ops,
  138. struct gpd_timing_data *td);
  139. extern int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td);
  140. extern void pm_genpd_init(struct generic_pm_domain *genpd,
  141. struct dev_power_governor *gov, bool is_off);
  142. extern int pm_genpd_poweron(struct generic_pm_domain *genpd);
  143. extern bool default_stop_ok(struct device *dev);
  144. extern struct dev_power_governor pm_domain_always_on_gov;
  145. #else
  146. static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
  147. {
  148. return ERR_PTR(-ENOSYS);
  149. }
  150. static inline struct generic_pm_domain *dev_to_genpd(struct device *dev)
  151. {
  152. return ERR_PTR(-ENOSYS);
  153. }
  154. static inline int __pm_genpd_add_device(struct generic_pm_domain *genpd,
  155. struct device *dev,
  156. struct gpd_timing_data *td)
  157. {
  158. return -ENOSYS;
  159. }
  160. static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
  161. struct device *dev)
  162. {
  163. return -ENOSYS;
  164. }
  165. static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd,
  166. struct device *dev)
  167. {
  168. return -ENOSYS;
  169. }
  170. static inline void pm_genpd_dev_always_on(struct device *dev, bool val) {}
  171. static inline void pm_genpd_dev_need_restore(struct device *dev, bool val) {}
  172. static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
  173. struct generic_pm_domain *new_sd)
  174. {
  175. return -ENOSYS;
  176. }
  177. static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
  178. struct generic_pm_domain *target)
  179. {
  180. return -ENOSYS;
  181. }
  182. static inline int pm_genpd_add_callbacks(struct device *dev,
  183. struct gpd_dev_ops *ops,
  184. struct gpd_timing_data *td)
  185. {
  186. return -ENOSYS;
  187. }
  188. static inline int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
  189. {
  190. return -ENOSYS;
  191. }
  192. static inline void pm_genpd_init(struct generic_pm_domain *genpd,
  193. struct dev_power_governor *gov, bool is_off)
  194. {
  195. }
  196. static inline int pm_genpd_poweron(struct generic_pm_domain *genpd)
  197. {
  198. return -ENOSYS;
  199. }
  200. static inline bool default_stop_ok(struct device *dev)
  201. {
  202. return false;
  203. }
  204. #define simple_qos_governor NULL
  205. #define pm_domain_always_on_gov NULL
  206. #endif
  207. static inline int pm_genpd_remove_callbacks(struct device *dev)
  208. {
  209. return __pm_genpd_remove_callbacks(dev, true);
  210. }
  211. #ifdef CONFIG_PM_GENERIC_DOMAINS_RUNTIME
  212. extern void genpd_queue_power_off_work(struct generic_pm_domain *genpd);
  213. extern void pm_genpd_poweroff_unused(void);
  214. #else
  215. static inline void genpd_queue_power_off_work(struct generic_pm_domain *gpd) {}
  216. static inline void pm_genpd_poweroff_unused(void) {}
  217. #endif
  218. #endif /* _LINUX_PM_DOMAIN_H */