pm_domain.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. };
  107. #ifdef CONFIG_PM_GENERIC_DOMAINS
  108. static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd)
  109. {
  110. return container_of(pdd, struct generic_pm_domain_data, base);
  111. }
  112. static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
  113. {
  114. return to_gpd_data(dev->power.subsys_data->domain_data);
  115. }
  116. extern struct dev_power_governor simple_qos_governor;
  117. extern struct generic_pm_domain *dev_to_genpd(struct device *dev);
  118. extern int __pm_genpd_add_device(struct generic_pm_domain *genpd,
  119. struct device *dev,
  120. struct gpd_timing_data *td);
  121. extern int __pm_genpd_of_add_device(struct device_node *genpd_node,
  122. struct device *dev,
  123. struct gpd_timing_data *td);
  124. extern int __pm_genpd_name_add_device(const char *domain_name,
  125. struct device *dev,
  126. struct gpd_timing_data *td);
  127. extern int pm_genpd_remove_device(struct generic_pm_domain *genpd,
  128. struct device *dev);
  129. extern void pm_genpd_dev_need_restore(struct device *dev, bool val);
  130. extern int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
  131. struct generic_pm_domain *new_subdomain);
  132. extern int pm_genpd_add_subdomain_names(const char *master_name,
  133. const char *subdomain_name);
  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 int genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state);
  141. extern int genpd_detach_cpuidle(struct generic_pm_domain *genpd);
  142. extern void pm_genpd_init(struct generic_pm_domain *genpd,
  143. struct dev_power_governor *gov, bool is_off);
  144. extern int pm_genpd_poweron(struct generic_pm_domain *genpd);
  145. extern int pm_genpd_name_poweron(const char *domain_name);
  146. extern bool default_stop_ok(struct device *dev);
  147. extern struct dev_power_governor pm_domain_always_on_gov;
  148. #else
  149. static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
  150. {
  151. return ERR_PTR(-ENOSYS);
  152. }
  153. static inline struct generic_pm_domain *dev_to_genpd(struct device *dev)
  154. {
  155. return ERR_PTR(-ENOSYS);
  156. }
  157. static inline int __pm_genpd_add_device(struct generic_pm_domain *genpd,
  158. struct device *dev,
  159. struct gpd_timing_data *td)
  160. {
  161. return -ENOSYS;
  162. }
  163. static inline int __pm_genpd_of_add_device(struct device_node *genpd_node,
  164. struct device *dev,
  165. struct gpd_timing_data *td)
  166. {
  167. return -ENOSYS;
  168. }
  169. static inline int __pm_genpd_name_add_device(const char *domain_name,
  170. struct device *dev,
  171. struct gpd_timing_data *td)
  172. {
  173. return -ENOSYS;
  174. }
  175. static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd,
  176. struct device *dev)
  177. {
  178. return -ENOSYS;
  179. }
  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_add_subdomain_names(const char *master_name,
  187. const char *subdomain_name)
  188. {
  189. return -ENOSYS;
  190. }
  191. static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
  192. struct generic_pm_domain *target)
  193. {
  194. return -ENOSYS;
  195. }
  196. static inline int pm_genpd_add_callbacks(struct device *dev,
  197. struct gpd_dev_ops *ops,
  198. struct gpd_timing_data *td)
  199. {
  200. return -ENOSYS;
  201. }
  202. static inline int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
  203. {
  204. return -ENOSYS;
  205. }
  206. static inline int genpd_attach_cpuidle(struct generic_pm_domain *genpd, int st)
  207. {
  208. return -ENOSYS;
  209. }
  210. static inline int genpd_detach_cpuidle(struct generic_pm_domain *genpd)
  211. {
  212. return -ENOSYS;
  213. }
  214. static inline void pm_genpd_init(struct generic_pm_domain *genpd,
  215. struct dev_power_governor *gov, bool is_off)
  216. {
  217. }
  218. static inline int pm_genpd_poweron(struct generic_pm_domain *genpd)
  219. {
  220. return -ENOSYS;
  221. }
  222. static inline int pm_genpd_name_poweron(const char *domain_name)
  223. {
  224. return -ENOSYS;
  225. }
  226. static inline bool default_stop_ok(struct device *dev)
  227. {
  228. return false;
  229. }
  230. #define simple_qos_governor NULL
  231. #define pm_domain_always_on_gov NULL
  232. #endif
  233. static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
  234. struct device *dev)
  235. {
  236. return __pm_genpd_add_device(genpd, dev, NULL);
  237. }
  238. static inline int pm_genpd_of_add_device(struct device_node *genpd_node,
  239. struct device *dev)
  240. {
  241. return __pm_genpd_of_add_device(genpd_node, dev, NULL);
  242. }
  243. static inline int pm_genpd_name_add_device(const char *domain_name,
  244. struct device *dev)
  245. {
  246. return __pm_genpd_name_add_device(domain_name, dev, NULL);
  247. }
  248. static inline int pm_genpd_remove_callbacks(struct device *dev)
  249. {
  250. return __pm_genpd_remove_callbacks(dev, true);
  251. }
  252. #ifdef CONFIG_PM_GENERIC_DOMAINS_RUNTIME
  253. extern void genpd_queue_power_off_work(struct generic_pm_domain *genpd);
  254. extern void pm_genpd_poweroff_unused(void);
  255. #else
  256. static inline void genpd_queue_power_off_work(struct generic_pm_domain *gpd) {}
  257. static inline void pm_genpd_poweroff_unused(void) {}
  258. #endif
  259. #ifdef CONFIG_PM_GENERIC_DOMAINS_SLEEP
  260. extern void pm_genpd_syscore_switch(struct device *dev, bool suspend);
  261. #else
  262. static inline void pm_genpd_syscore_switch(struct device *dev, bool suspend) {}
  263. #endif
  264. static inline void pm_genpd_syscore_poweroff(struct device *dev)
  265. {
  266. pm_genpd_syscore_switch(dev, true);
  267. }
  268. static inline void pm_genpd_syscore_poweron(struct device *dev)
  269. {
  270. pm_genpd_syscore_switch(dev, false);
  271. }
  272. #endif /* _LINUX_PM_DOMAIN_H */