]>
Commit | Line | Data |
---|---|---|
f721889f RW |
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 | ||
9 | #ifndef _LINUX_PM_DOMAIN_H | |
10 | #define _LINUX_PM_DOMAIN_H | |
11 | ||
12 | #include <linux/device.h> | |
313162d0 PG |
13 | #include <linux/mutex.h> |
14 | #include <linux/pm.h> | |
4f042cda | 15 | #include <linux/err.h> |
c8aa130b | 16 | #include <linux/of.h> |
6ff7bb0d | 17 | #include <linux/notifier.h> |
d716f479 | 18 | #include <linux/spinlock.h> |
f721889f | 19 | |
c11f6f5b | 20 | /* Defines used for the flags field in the struct generic_pm_domain */ |
95a20ef6 GU |
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 */ | |
c11f6f5b | 25 | |
17b75eca RW |
26 | enum gpd_status { |
27 | GPD_STATE_ACTIVE = 0, /* PM domain is active */ | |
17b75eca RW |
28 | GPD_STATE_POWER_OFF, /* PM domain is off */ |
29 | }; | |
596ba34b | 30 | |
f721889f RW |
31 | struct dev_power_governor { |
32 | bool (*power_down_ok)(struct dev_pm_domain *domain); | |
9df3921e | 33 | bool (*suspend_ok)(struct device *dev); |
f721889f RW |
34 | }; |
35 | ||
d5e4cbfe RW |
36 | struct gpd_dev_ops { |
37 | int (*start)(struct device *dev); | |
38 | int (*stop)(struct device *dev); | |
d5e4cbfe RW |
39 | }; |
40 | ||
fc5cbf0c AH |
41 | struct genpd_power_state { |
42 | s64 power_off_latency_ns; | |
43 | s64 power_on_latency_ns; | |
405f7226 | 44 | s64 residency_ns; |
0c9b694a | 45 | struct fwnode_handle *fwnode; |
afece3ab | 46 | ktime_t idle_time; |
fc5cbf0c AH |
47 | }; |
48 | ||
35241d12 | 49 | struct genpd_lock_ops; |
6e41766a | 50 | struct dev_pm_opp; |
35241d12 | 51 | |
f721889f | 52 | struct generic_pm_domain { |
401ea157 | 53 | struct device dev; |
f721889f | 54 | struct dev_pm_domain domain; /* PM domain operations */ |
5125bbf3 | 55 | struct list_head gpd_list_node; /* Node in the global PM domains list */ |
5063ce15 RW |
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 */ | |
f721889f | 58 | struct list_head dev_list; /* List of devices */ |
f721889f RW |
59 | struct dev_power_governor *gov; |
60 | struct work_struct power_off_work; | |
de0aa06d JH |
61 | struct fwnode_handle *provider; /* Identity of the domain provider */ |
62 | bool has_provider; | |
d07e9c17 | 63 | const char *name; |
c4bb3160 | 64 | atomic_t sd_count; /* Number of subdomains with power "on" */ |
17b75eca | 65 | enum gpd_status status; /* Current state of the domain */ |
596ba34b RW |
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 */ | |
42f6284a | 69 | unsigned int performance_state; /* Aggregated max performance state */ |
f721889f RW |
70 | int (*power_off)(struct generic_pm_domain *domain); |
71 | int (*power_on)(struct generic_pm_domain *domain); | |
6e41766a VK |
72 | unsigned int (*opp_to_performance_state)(struct generic_pm_domain *genpd, |
73 | struct dev_pm_opp *opp); | |
42f6284a VK |
74 | int (*set_performance_state)(struct generic_pm_domain *genpd, |
75 | unsigned int state); | |
d5e4cbfe | 76 | struct gpd_dev_ops dev_ops; |
221e9b58 | 77 | s64 max_off_time_ns; /* Maximum allowed "suspended" time. */ |
6ff7bb0d RW |
78 | bool max_off_time_changed; |
79 | bool cached_power_down_ok; | |
c16561e8 UH |
80 | int (*attach_dev)(struct generic_pm_domain *domain, |
81 | struct device *dev); | |
82 | void (*detach_dev)(struct generic_pm_domain *domain, | |
83 | struct device *dev); | |
c11f6f5b | 84 | unsigned int flags; /* Bit field of configs for genpd */ |
59d65b73 | 85 | struct genpd_power_state *states; |
fc5cbf0c AH |
86 | unsigned int state_count; /* number of states */ |
87 | unsigned int state_idx; /* state that genpd will go to when off */ | |
59d65b73 | 88 | void *free; /* Free the state that was allocated for default */ |
afece3ab TG |
89 | ktime_t on_time; |
90 | ktime_t accounting_time; | |
35241d12 | 91 | const struct genpd_lock_ops *lock_ops; |
d716f479 LI |
92 | union { |
93 | struct mutex mlock; | |
94 | struct { | |
95 | spinlock_t slock; | |
96 | unsigned long lock_flags; | |
97 | }; | |
98 | }; | |
fc5cbf0c | 99 | |
f721889f RW |
100 | }; |
101 | ||
596ba34b RW |
102 | static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd) |
103 | { | |
104 | return container_of(pd, struct generic_pm_domain, domain); | |
105 | } | |
106 | ||
5063ce15 RW |
107 | struct gpd_link { |
108 | struct generic_pm_domain *master; | |
109 | struct list_head master_node; | |
110 | struct generic_pm_domain *slave; | |
111 | struct list_head slave_node; | |
112 | }; | |
113 | ||
b02c999a | 114 | struct gpd_timing_data { |
2b1d88cd UH |
115 | s64 suspend_latency_ns; |
116 | s64 resume_latency_ns; | |
a5bef810 | 117 | s64 effective_constraint_ns; |
6ff7bb0d | 118 | bool constraint_changed; |
9df3921e | 119 | bool cached_suspend_ok; |
b02c999a RW |
120 | }; |
121 | ||
00e7c295 UH |
122 | struct pm_domain_data { |
123 | struct list_head list_node; | |
124 | struct device *dev; | |
125 | }; | |
126 | ||
cd0ea672 RW |
127 | struct generic_pm_domain_data { |
128 | struct pm_domain_data base; | |
b02c999a | 129 | struct gpd_timing_data td; |
6ff7bb0d | 130 | struct notifier_block nb; |
42f6284a | 131 | unsigned int performance_state; |
a5ea7a0f | 132 | void *data; |
cd0ea672 RW |
133 | }; |
134 | ||
9b4f617b | 135 | #ifdef CONFIG_PM_GENERIC_DOMAINS |
cd0ea672 RW |
136 | static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd) |
137 | { | |
138 | return container_of(pdd, struct generic_pm_domain_data, base); | |
139 | } | |
140 | ||
d5e4cbfe RW |
141 | static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev) |
142 | { | |
143 | return to_gpd_data(dev->power.subsys_data->domain_data); | |
144 | } | |
145 | ||
1a7a6707 | 146 | int pm_genpd_add_device(struct generic_pm_domain *genpd, struct device *dev); |
924f4486 | 147 | int pm_genpd_remove_device(struct device *dev); |
781b9d6b UH |
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); | |
b02c999a | 156 | |
ae3c511c | 157 | extern struct dev_power_governor simple_qos_governor; |
925b44a2 | 158 | extern struct dev_power_governor pm_domain_always_on_gov; |
f721889f | 159 | #else |
b02c999a | 160 | |
b642631d MD |
161 | static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev) |
162 | { | |
163 | return ERR_PTR(-ENOSYS); | |
164 | } | |
1a7a6707 UH |
165 | static inline int pm_genpd_add_device(struct generic_pm_domain *genpd, |
166 | struct device *dev) | |
b02c999a RW |
167 | { |
168 | return -ENOSYS; | |
169 | } | |
924f4486 | 170 | static inline int pm_genpd_remove_device(struct device *dev) |
f721889f RW |
171 | { |
172 | return -ENOSYS; | |
173 | } | |
174 | static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, | |
175 | struct generic_pm_domain *new_sd) | |
176 | { | |
177 | return -ENOSYS; | |
178 | } | |
179 | static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, | |
180 | struct generic_pm_domain *target) | |
181 | { | |
182 | return -ENOSYS; | |
183 | } | |
7eb231c3 UH |
184 | static inline int pm_genpd_init(struct generic_pm_domain *genpd, |
185 | struct dev_power_governor *gov, bool is_off) | |
b02c999a | 186 | { |
7eb231c3 | 187 | return -ENOSYS; |
b02c999a | 188 | } |
3fe57710 JH |
189 | static inline int pm_genpd_remove(struct generic_pm_domain *genpd) |
190 | { | |
191 | return -ENOTSUPP; | |
192 | } | |
16d0bf18 | 193 | |
42f6284a VK |
194 | static inline int dev_pm_genpd_set_performance_state(struct device *dev, |
195 | unsigned int state) | |
196 | { | |
197 | return -ENOTSUPP; | |
198 | } | |
199 | ||
16d0bf18 GU |
200 | #define simple_qos_governor (*(struct dev_power_governor *)(NULL)) |
201 | #define pm_domain_always_on_gov (*(struct dev_power_governor *)(NULL)) | |
17f2ae7f RW |
202 | #endif |
203 | ||
77f827de | 204 | #ifdef CONFIG_PM_GENERIC_DOMAINS_SLEEP |
781b9d6b UH |
205 | void pm_genpd_syscore_poweroff(struct device *dev); |
206 | void pm_genpd_syscore_poweron(struct device *dev); | |
77f827de | 207 | #else |
d47e6464 UH |
208 | static inline void pm_genpd_syscore_poweroff(struct device *dev) {} |
209 | static inline void pm_genpd_syscore_poweron(struct device *dev) {} | |
77f827de RW |
210 | #endif |
211 | ||
aa42240a TF |
212 | /* OF PM domain providers */ |
213 | struct of_device_id; | |
214 | ||
40845524 TR |
215 | typedef struct generic_pm_domain *(*genpd_xlate_t)(struct of_phandle_args *args, |
216 | void *data); | |
217 | ||
aa42240a TF |
218 | struct genpd_onecell_data { |
219 | struct generic_pm_domain **domains; | |
220 | unsigned int num_domains; | |
40845524 | 221 | genpd_xlate_t xlate; |
aa42240a TF |
222 | }; |
223 | ||
aa42240a | 224 | #ifdef CONFIG_PM_GENERIC_DOMAINS_OF |
892ebdcc JH |
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); | |
aa42240a | 229 | void of_genpd_del_provider(struct device_node *np); |
781b9d6b UH |
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, | |
6e41766a | 237 | struct device_node *opp_node); |
aa42240a TF |
238 | |
239 | int genpd_dev_pm_attach(struct device *dev); | |
3c095f32 UH |
240 | struct device *genpd_dev_pm_attach_by_id(struct device *dev, |
241 | unsigned int index); | |
aa42240a | 242 | #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */ |
892ebdcc JH |
243 | static inline int of_genpd_add_provider_simple(struct device_node *np, |
244 | struct generic_pm_domain *genpd) | |
aa42240a | 245 | { |
892ebdcc JH |
246 | return -ENOTSUPP; |
247 | } | |
248 | ||
249 | static inline int of_genpd_add_provider_onecell(struct device_node *np, | |
250 | struct genpd_onecell_data *data) | |
251 | { | |
252 | return -ENOTSUPP; | |
aa42240a | 253 | } |
aa42240a | 254 | |
892ebdcc | 255 | static inline void of_genpd_del_provider(struct device_node *np) {} |
aa42240a | 256 | |
ec69572b JH |
257 | static inline int of_genpd_add_device(struct of_phandle_args *args, |
258 | struct device *dev) | |
259 | { | |
260 | return -ENODEV; | |
261 | } | |
262 | ||
263 | static inline int of_genpd_add_subdomain(struct of_phandle_args *parent, | |
264 | struct of_phandle_args *new_subdomain) | |
265 | { | |
266 | return -ENODEV; | |
267 | } | |
268 | ||
30f60428 LI |
269 | static inline int of_genpd_parse_idle_states(struct device_node *dn, |
270 | struct genpd_power_state **states, int *n) | |
271 | { | |
272 | return -ENODEV; | |
273 | } | |
274 | ||
6e41766a VK |
275 | static inline unsigned int |
276 | of_genpd_opp_to_performance_state(struct device *dev, | |
277 | struct device_node *opp_node) | |
278 | { | |
279 | return -ENODEV; | |
280 | } | |
281 | ||
aa42240a TF |
282 | static inline int genpd_dev_pm_attach(struct device *dev) |
283 | { | |
919b7308 | 284 | return 0; |
aa42240a | 285 | } |
17926551 | 286 | |
3c095f32 UH |
287 | static inline struct device *genpd_dev_pm_attach_by_id(struct device *dev, |
288 | unsigned int index) | |
289 | { | |
290 | return NULL; | |
291 | } | |
292 | ||
17926551 JH |
293 | static inline |
294 | struct generic_pm_domain *of_genpd_remove_last(struct device_node *np) | |
295 | { | |
296 | return ERR_PTR(-ENOTSUPP); | |
297 | } | |
aa42240a TF |
298 | #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */ |
299 | ||
f48c767c | 300 | #ifdef CONFIG_PM |
781b9d6b UH |
301 | int dev_pm_domain_attach(struct device *dev, bool power_on); |
302 | void dev_pm_domain_detach(struct device *dev, bool power_off); | |
303 | void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd); | |
f48c767c UH |
304 | #else |
305 | static inline int dev_pm_domain_attach(struct device *dev, bool power_on) | |
306 | { | |
919b7308 | 307 | return 0; |
f48c767c UH |
308 | } |
309 | static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {} | |
989561de TV |
310 | static inline void dev_pm_domain_set(struct device *dev, |
311 | struct dev_pm_domain *pd) {} | |
f48c767c UH |
312 | #endif |
313 | ||
f721889f | 314 | #endif /* _LINUX_PM_DOMAIN_H */ |