pm_domain.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. extern void pm_genpd_poweroff_unused(void);
  68. extern void genpd_queue_power_off_work(struct generic_pm_domain *genpd);
  69. #else
  70. static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
  71. struct device *dev)
  72. {
  73. return -ENOSYS;
  74. }
  75. static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd,
  76. struct device *dev)
  77. {
  78. return -ENOSYS;
  79. }
  80. static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
  81. struct generic_pm_domain *new_sd)
  82. {
  83. return -ENOSYS;
  84. }
  85. static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
  86. struct generic_pm_domain *target)
  87. {
  88. return -ENOSYS;
  89. }
  90. static inline void pm_genpd_init(struct generic_pm_domain *genpd,
  91. struct dev_power_governor *gov, bool is_off) {}
  92. static inline int pm_genpd_poweron(struct generic_pm_domain *genpd)
  93. {
  94. return -ENOSYS;
  95. }
  96. static inline void pm_genpd_poweroff_unused(void) {}
  97. static inline void genpd_queue_power_off_work(struct generic_pm_domain *gpd) {}
  98. #endif
  99. #endif /* _LINUX_PM_DOMAIN_H */