2 * pm_domain.h - Definitions and headers related to device power domains.
4 * Copyright (C) 2011 Rafael J. Wysocki <rjw@sisk.pl>, Renesas Electronics Corp.
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>
19 /* Defines used for the flags field in the struct generic_pm_domain */
20 #define GENPD_FLAG_PM_CLK (1U << 0) /* PM domain uses PM clk */
22 #define GENPD_MAX_NUM_STATES 8 /* Number of possible low power states */
25 GPD_STATE_ACTIVE = 0, /* PM domain is active */
26 GPD_STATE_POWER_OFF, /* PM domain is off */
29 struct dev_power_governor {
30 bool (*power_down_ok)(struct dev_pm_domain *domain);
31 bool (*suspend_ok)(struct device *dev);
35 int (*start)(struct device *dev);
36 int (*stop)(struct device *dev);
37 bool (*active_wakeup)(struct device *dev);
40 struct genpd_power_state {
41 s64 power_off_latency_ns;
42 s64 power_on_latency_ns;
45 struct generic_pm_domain {
46 struct dev_pm_domain domain; /* PM domain operations */
47 struct list_head gpd_list_node; /* Node in the global PM domains list */
48 struct list_head master_links; /* Links with PM domain as a master */
49 struct list_head slave_links; /* Links with PM domain as a slave */
50 struct list_head dev_list; /* List of devices */
52 struct dev_power_governor *gov;
53 struct work_struct power_off_work;
55 atomic_t sd_count; /* Number of subdomains with power "on" */
56 enum gpd_status status; /* Current state of the domain */
57 unsigned int device_count; /* Number of devices */
58 unsigned int suspended_count; /* System suspend device counter */
59 unsigned int prepared_count; /* Suspend counter of prepared devices */
60 int (*power_off)(struct generic_pm_domain *domain);
61 int (*power_on)(struct generic_pm_domain *domain);
62 struct gpd_dev_ops dev_ops;
63 s64 max_off_time_ns; /* Maximum allowed "suspended" time. */
64 bool max_off_time_changed;
65 bool cached_power_down_ok;
66 int (*attach_dev)(struct generic_pm_domain *domain,
68 void (*detach_dev)(struct generic_pm_domain *domain,
70 unsigned int flags; /* Bit field of configs for genpd */
71 struct genpd_power_state states[GENPD_MAX_NUM_STATES];
72 unsigned int state_count; /* number of states */
73 unsigned int state_idx; /* state that genpd will go to when off */
77 static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd)
79 return container_of(pd, struct generic_pm_domain, domain);
83 struct generic_pm_domain *master;
84 struct list_head master_node;
85 struct generic_pm_domain *slave;
86 struct list_head slave_node;
89 struct gpd_timing_data {
90 s64 suspend_latency_ns;
91 s64 resume_latency_ns;
92 s64 effective_constraint_ns;
93 bool constraint_changed;
94 bool cached_suspend_ok;
97 struct pm_domain_data {
98 struct list_head list_node;
102 struct generic_pm_domain_data {
103 struct pm_domain_data base;
104 struct gpd_timing_data td;
105 struct notifier_block nb;
108 #ifdef CONFIG_PM_GENERIC_DOMAINS
109 static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd)
111 return container_of(pdd, struct generic_pm_domain_data, base);
114 static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
116 return to_gpd_data(dev->power.subsys_data->domain_data);
119 extern int __pm_genpd_add_device(struct generic_pm_domain *genpd,
121 struct gpd_timing_data *td);
123 extern int pm_genpd_remove_device(struct generic_pm_domain *genpd,
125 extern int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
126 struct generic_pm_domain *new_subdomain);
127 extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
128 struct generic_pm_domain *target);
129 extern int pm_genpd_init(struct generic_pm_domain *genpd,
130 struct dev_power_governor *gov, bool is_off);
132 extern struct dev_power_governor simple_qos_governor;
133 extern struct dev_power_governor pm_domain_always_on_gov;
136 static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
138 return ERR_PTR(-ENOSYS);
140 static inline int __pm_genpd_add_device(struct generic_pm_domain *genpd,
142 struct gpd_timing_data *td)
146 static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd,
151 static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
152 struct generic_pm_domain *new_sd)
156 static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
157 struct generic_pm_domain *target)
161 static inline int pm_genpd_init(struct generic_pm_domain *genpd,
162 struct dev_power_governor *gov, bool is_off)
168 static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
171 return __pm_genpd_add_device(genpd, dev, NULL);
174 #ifdef CONFIG_PM_GENERIC_DOMAINS_SLEEP
175 extern void pm_genpd_syscore_poweroff(struct device *dev);
176 extern void pm_genpd_syscore_poweron(struct device *dev);
178 static inline void pm_genpd_syscore_poweroff(struct device *dev) {}
179 static inline void pm_genpd_syscore_poweron(struct device *dev) {}
182 /* OF PM domain providers */
185 struct genpd_onecell_data {
186 struct generic_pm_domain **domains;
187 unsigned int num_domains;
190 typedef struct generic_pm_domain *(*genpd_xlate_t)(struct of_phandle_args *args,
193 #ifdef CONFIG_PM_GENERIC_DOMAINS_OF
194 int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
196 void of_genpd_del_provider(struct device_node *np);
197 struct generic_pm_domain *__of_genpd_xlate_simple(
198 struct of_phandle_args *genpdspec,
200 struct generic_pm_domain *__of_genpd_xlate_onecell(
201 struct of_phandle_args *genpdspec,
203 extern int of_genpd_add_device(struct of_phandle_args *args,
205 extern int of_genpd_add_subdomain(struct of_phandle_args *parent,
206 struct of_phandle_args *new_subdomain);
208 int genpd_dev_pm_attach(struct device *dev);
209 #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
210 static inline int __of_genpd_add_provider(struct device_node *np,
211 genpd_xlate_t xlate, void *data)
215 static inline void of_genpd_del_provider(struct device_node *np) {}
217 #define __of_genpd_xlate_simple NULL
218 #define __of_genpd_xlate_onecell NULL
220 static inline int of_genpd_add_device(struct of_phandle_args *args,
226 static inline int of_genpd_add_subdomain(struct of_phandle_args *parent,
227 struct of_phandle_args *new_subdomain)
232 static inline int genpd_dev_pm_attach(struct device *dev)
236 #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
238 static inline int of_genpd_add_provider_simple(struct device_node *np,
239 struct generic_pm_domain *genpd)
241 return __of_genpd_add_provider(np, __of_genpd_xlate_simple, genpd);
243 static inline int of_genpd_add_provider_onecell(struct device_node *np,
244 struct genpd_onecell_data *data)
246 return __of_genpd_add_provider(np, __of_genpd_xlate_onecell, data);
250 extern int dev_pm_domain_attach(struct device *dev, bool power_on);
251 extern void dev_pm_domain_detach(struct device *dev, bool power_off);
252 extern void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd);
254 static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
258 static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {}
259 static inline void dev_pm_domain_set(struct device *dev,
260 struct dev_pm_domain *pd) {}
263 #endif /* _LINUX_PM_DOMAIN_H */