pm_domain.h 8.0 KB

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