2 * pm_domain.h - Definitions and headers related to device power domains.
6 * This file is released under the GPLv2.
9 #ifndef _LINUX_PM_DOMAIN_H
10 #define _LINUX_PM_DOMAIN_H
12 #include <linux/device.h>
13 #include <linux/mutex.h>
15 #include <linux/err.h>
17 #include <linux/notifier.h>
18 #include <linux/spinlock.h>
20 /* Defines used for the flags field in the struct generic_pm_domain */
21 #define GENPD_FLAG_PM_CLK (1U << 0) /* PM domain uses PM clk */
22 #define GENPD_FLAG_IRQ_SAFE (1U << 1) /* PM domain operates in atomic */
23 #define GENPD_FLAG_ALWAYS_ON (1U << 2) /* PM domain is always powered on */
24 #define GENPD_FLAG_ACTIVE_WAKEUP (1U << 3) /* Keep devices active if wakeup */
27 GPD_STATE_ACTIVE = 0, /* PM domain is active */
28 GPD_STATE_POWER_OFF, /* PM domain is off */
31 struct dev_power_governor {
32 bool (*power_down_ok)(struct dev_pm_domain *domain);
33 bool (*suspend_ok)(struct device *dev);
37 int (*start)(struct device *dev);
38 int (*stop)(struct device *dev);
41 struct genpd_power_state {
42 s64 power_off_latency_ns;
43 s64 power_on_latency_ns;
45 struct fwnode_handle *fwnode;
49 struct genpd_lock_ops;
52 struct generic_pm_domain {
54 struct dev_pm_domain domain; /* PM domain operations */
55 struct list_head gpd_list_node; /* Node in the global PM domains list */
56 struct list_head master_links; /* Links with PM domain as a master */
57 struct list_head slave_links; /* Links with PM domain as a slave */
58 struct list_head dev_list; /* List of devices */
59 struct dev_power_governor *gov;
60 struct work_struct power_off_work;
61 struct fwnode_handle *provider; /* Identity of the domain provider */
64 atomic_t sd_count; /* Number of subdomains with power "on" */
65 enum gpd_status status; /* Current state of the domain */
66 unsigned int device_count; /* Number of devices */
67 unsigned int suspended_count; /* System suspend device counter */
68 unsigned int prepared_count; /* Suspend counter of prepared devices */
69 unsigned int performance_state; /* Aggregated max performance state */
70 int (*power_off)(struct generic_pm_domain *domain);
71 int (*power_on)(struct generic_pm_domain *domain);
72 unsigned int (*opp_to_performance_state)(struct generic_pm_domain *genpd,
73 struct dev_pm_opp *opp);
74 int (*set_performance_state)(struct generic_pm_domain *genpd,
76 struct gpd_dev_ops dev_ops;
77 s64 max_off_time_ns; /* Maximum allowed "suspended" time. */
78 bool max_off_time_changed;
79 bool cached_power_down_ok;
80 int (*attach_dev)(struct generic_pm_domain *domain,
82 void (*detach_dev)(struct generic_pm_domain *domain,
84 unsigned int flags; /* Bit field of configs for genpd */
85 struct genpd_power_state *states;
86 unsigned int state_count; /* number of states */
87 unsigned int state_idx; /* state that genpd will go to when off */
88 void *free; /* Free the state that was allocated for default */
90 ktime_t accounting_time;
91 const struct genpd_lock_ops *lock_ops;
96 unsigned long lock_flags;
102 static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd)
104 return container_of(pd, struct generic_pm_domain, domain);
108 struct generic_pm_domain *master;
109 struct list_head master_node;
110 struct generic_pm_domain *slave;
111 struct list_head slave_node;
114 struct gpd_timing_data {
115 s64 suspend_latency_ns;
116 s64 resume_latency_ns;
117 s64 effective_constraint_ns;
118 bool constraint_changed;
119 bool cached_suspend_ok;
122 struct pm_domain_data {
123 struct list_head list_node;
127 struct generic_pm_domain_data {
128 struct pm_domain_data base;
129 struct gpd_timing_data td;
130 struct notifier_block nb;
131 unsigned int performance_state;
135 #ifdef CONFIG_PM_GENERIC_DOMAINS
136 static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd)
138 return container_of(pdd, struct generic_pm_domain_data, base);
141 static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
143 return to_gpd_data(dev->power.subsys_data->domain_data);
146 int pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev);
147 int pm_genpd_remove_device(struct device *dev);
148 int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
149 struct generic_pm_domain *new_subdomain);
150 int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
151 struct generic_pm_domain *target);
152 int pm_genpd_init(struct generic_pm_domain *genpd,
153 struct dev_power_governor *gov, bool is_off);
154 int pm_genpd_remove(struct generic_pm_domain *genpd);
155 int dev_pm_genpd_set_performance_state(struct device *dev, unsigned int state);
157 extern struct dev_power_governor simple_qos_governor;
158 extern struct dev_power_governor pm_domain_always_on_gov;
161 static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
163 return ERR_PTR(-ENOSYS);
165 static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
170 static inline int pm_genpd_remove_device(struct device *dev)
174 static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
175 struct generic_pm_domain *new_sd)
179 static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
180 struct generic_pm_domain *target)
184 static inline int pm_genpd_init(struct generic_pm_domain *genpd,
185 struct dev_power_governor *gov, bool is_off)
189 static inline int pm_genpd_remove(struct generic_pm_domain *genpd)
194 static inline int dev_pm_genpd_set_performance_state(struct device *dev,
200 #define simple_qos_governor (*(struct dev_power_governor *)(NULL))
201 #define pm_domain_always_on_gov (*(struct dev_power_governor *)(NULL))
204 #ifdef CONFIG_PM_GENERIC_DOMAINS_SLEEP
205 void pm_genpd_syscore_poweroff(struct device *dev);
206 void pm_genpd_syscore_poweron(struct device *dev);
208 static inline void pm_genpd_syscore_poweroff(struct device *dev) {}
209 static inline void pm_genpd_syscore_poweron(struct device *dev) {}
212 /* OF PM domain providers */
215 typedef struct generic_pm_domain *(*genpd_xlate_t)(struct of_phandle_args *args,
218 struct genpd_onecell_data {
219 struct generic_pm_domain **domains;
220 unsigned int num_domains;
224 #ifdef CONFIG_PM_GENERIC_DOMAINS_OF
225 int of_genpd_add_provider_simple(struct device_node *np,
226 struct generic_pm_domain *genpd);
227 int of_genpd_add_provider_onecell(struct device_node *np,
228 struct genpd_onecell_data *data);
229 void of_genpd_del_provider(struct device_node *np);
230 int of_genpd_add_device(struct of_phandle_args *args, struct device *dev);
231 int of_genpd_add_subdomain(struct of_phandle_args *parent,
232 struct of_phandle_args *new_subdomain);
233 struct generic_pm_domain *of_genpd_remove_last(struct device_node *np);
234 int of_genpd_parse_idle_states(struct device_node *dn,
235 struct genpd_power_state **states, int *n);
236 unsigned int of_genpd_opp_to_performance_state(struct device *dev,
237 struct device_node *np);
239 int genpd_dev_pm_attach(struct device *dev);
240 struct device *genpd_dev_pm_attach_by_id(struct device *dev,
242 #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
243 static inline int of_genpd_add_provider_simple(struct device_node *np,
244 struct generic_pm_domain *genpd)
249 static inline int of_genpd_add_provider_onecell(struct device_node *np,
250 struct genpd_onecell_data *data)
255 static inline void of_genpd_del_provider(struct device_node *np) {}
257 static inline int of_genpd_add_device(struct of_phandle_args *args,
263 static inline int of_genpd_add_subdomain(struct of_phandle_args *parent,
264 struct of_phandle_args *new_subdomain)
269 static inline int of_genpd_parse_idle_states(struct device_node *dn,
270 struct genpd_power_state **states, int *n)
275 static inline unsigned int
276 of_genpd_opp_to_performance_state(struct device *dev,
277 struct device_node *np)
282 static inline int genpd_dev_pm_attach(struct device *dev)
287 static inline struct device *genpd_dev_pm_attach_by_id(struct device *dev,
294 struct generic_pm_domain *of_genpd_remove_last(struct device_node *np)
296 return ERR_PTR(-ENOTSUPP);
298 #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
301 int dev_pm_domain_attach(struct device *dev, bool power_on);
302 struct device *dev_pm_domain_attach_by_id(struct device *dev,
304 void dev_pm_domain_detach(struct device *dev, bool power_off);
305 void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd);
307 static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
311 static inline struct device *dev_pm_domain_attach_by_id(struct device *dev,
316 static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {}
317 static inline void dev_pm_domain_set(struct device *dev,
318 struct dev_pm_domain *pd) {}
321 #endif /* _LINUX_PM_DOMAIN_H */