]>
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> |
f721889f | 18 | |
c11f6f5b UH |
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 */ | |
21 | ||
17b75eca RW |
22 | enum gpd_status { |
23 | GPD_STATE_ACTIVE = 0, /* PM domain is active */ | |
17b75eca RW |
24 | GPD_STATE_POWER_OFF, /* PM domain is off */ |
25 | }; | |
596ba34b | 26 | |
f721889f RW |
27 | struct dev_power_governor { |
28 | bool (*power_down_ok)(struct dev_pm_domain *domain); | |
9df3921e | 29 | bool (*suspend_ok)(struct device *dev); |
f721889f RW |
30 | }; |
31 | ||
d5e4cbfe RW |
32 | struct gpd_dev_ops { |
33 | int (*start)(struct device *dev); | |
34 | int (*stop)(struct device *dev); | |
35 | bool (*active_wakeup)(struct device *dev); | |
36 | }; | |
37 | ||
fc5cbf0c AH |
38 | struct genpd_power_state { |
39 | s64 power_off_latency_ns; | |
40 | s64 power_on_latency_ns; | |
405f7226 | 41 | s64 residency_ns; |
0c9b694a | 42 | struct fwnode_handle *fwnode; |
fc5cbf0c AH |
43 | }; |
44 | ||
35241d12 LI |
45 | struct genpd_lock_ops; |
46 | ||
f721889f RW |
47 | struct generic_pm_domain { |
48 | struct dev_pm_domain domain; /* PM domain operations */ | |
5125bbf3 | 49 | struct list_head gpd_list_node; /* Node in the global PM domains list */ |
5063ce15 RW |
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 */ | |
f721889f | 52 | struct list_head dev_list; /* List of devices */ |
f721889f RW |
53 | struct dev_power_governor *gov; |
54 | struct work_struct power_off_work; | |
de0aa06d JH |
55 | struct fwnode_handle *provider; /* Identity of the domain provider */ |
56 | bool has_provider; | |
d07e9c17 | 57 | const char *name; |
c4bb3160 | 58 | atomic_t sd_count; /* Number of subdomains with power "on" */ |
17b75eca | 59 | enum gpd_status status; /* Current state of the domain */ |
596ba34b RW |
60 | unsigned int device_count; /* Number of devices */ |
61 | unsigned int suspended_count; /* System suspend device counter */ | |
62 | unsigned int prepared_count; /* Suspend counter of prepared devices */ | |
f721889f RW |
63 | int (*power_off)(struct generic_pm_domain *domain); |
64 | int (*power_on)(struct generic_pm_domain *domain); | |
d5e4cbfe | 65 | struct gpd_dev_ops dev_ops; |
221e9b58 | 66 | s64 max_off_time_ns; /* Maximum allowed "suspended" time. */ |
6ff7bb0d RW |
67 | bool max_off_time_changed; |
68 | bool cached_power_down_ok; | |
c16561e8 UH |
69 | int (*attach_dev)(struct generic_pm_domain *domain, |
70 | struct device *dev); | |
71 | void (*detach_dev)(struct generic_pm_domain *domain, | |
72 | struct device *dev); | |
c11f6f5b | 73 | unsigned int flags; /* Bit field of configs for genpd */ |
59d65b73 | 74 | struct genpd_power_state *states; |
fc5cbf0c AH |
75 | unsigned int state_count; /* number of states */ |
76 | unsigned int state_idx; /* state that genpd will go to when off */ | |
59d65b73 | 77 | void *free; /* Free the state that was allocated for default */ |
35241d12 LI |
78 | const struct genpd_lock_ops *lock_ops; |
79 | struct mutex mlock; | |
fc5cbf0c | 80 | |
f721889f RW |
81 | }; |
82 | ||
596ba34b RW |
83 | static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd) |
84 | { | |
85 | return container_of(pd, struct generic_pm_domain, domain); | |
86 | } | |
87 | ||
5063ce15 RW |
88 | struct gpd_link { |
89 | struct generic_pm_domain *master; | |
90 | struct list_head master_node; | |
91 | struct generic_pm_domain *slave; | |
92 | struct list_head slave_node; | |
93 | }; | |
94 | ||
b02c999a | 95 | struct gpd_timing_data { |
2b1d88cd UH |
96 | s64 suspend_latency_ns; |
97 | s64 resume_latency_ns; | |
a5bef810 | 98 | s64 effective_constraint_ns; |
6ff7bb0d | 99 | bool constraint_changed; |
9df3921e | 100 | bool cached_suspend_ok; |
b02c999a RW |
101 | }; |
102 | ||
00e7c295 UH |
103 | struct pm_domain_data { |
104 | struct list_head list_node; | |
105 | struct device *dev; | |
106 | }; | |
107 | ||
cd0ea672 RW |
108 | struct generic_pm_domain_data { |
109 | struct pm_domain_data base; | |
b02c999a | 110 | struct gpd_timing_data td; |
6ff7bb0d | 111 | struct notifier_block nb; |
cd0ea672 RW |
112 | }; |
113 | ||
9b4f617b | 114 | #ifdef CONFIG_PM_GENERIC_DOMAINS |
cd0ea672 RW |
115 | static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd) |
116 | { | |
117 | return container_of(pdd, struct generic_pm_domain_data, base); | |
118 | } | |
119 | ||
d5e4cbfe RW |
120 | static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev) |
121 | { | |
122 | return to_gpd_data(dev->power.subsys_data->domain_data); | |
123 | } | |
124 | ||
b02c999a RW |
125 | extern int __pm_genpd_add_device(struct generic_pm_domain *genpd, |
126 | struct device *dev, | |
127 | struct gpd_timing_data *td); | |
128 | ||
f721889f RW |
129 | extern int pm_genpd_remove_device(struct generic_pm_domain *genpd, |
130 | struct device *dev); | |
131 | extern int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, | |
132 | struct generic_pm_domain *new_subdomain); | |
133 | extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, | |
134 | struct generic_pm_domain *target); | |
7eb231c3 UH |
135 | extern int pm_genpd_init(struct generic_pm_domain *genpd, |
136 | struct dev_power_governor *gov, bool is_off); | |
3fe57710 | 137 | extern int pm_genpd_remove(struct generic_pm_domain *genpd); |
b02c999a | 138 | |
ae3c511c | 139 | extern struct dev_power_governor simple_qos_governor; |
925b44a2 | 140 | extern struct dev_power_governor pm_domain_always_on_gov; |
f721889f | 141 | #else |
b02c999a | 142 | |
b642631d MD |
143 | static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev) |
144 | { | |
145 | return ERR_PTR(-ENOSYS); | |
146 | } | |
b02c999a RW |
147 | static inline int __pm_genpd_add_device(struct generic_pm_domain *genpd, |
148 | struct device *dev, | |
149 | struct gpd_timing_data *td) | |
150 | { | |
151 | return -ENOSYS; | |
152 | } | |
f721889f RW |
153 | static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd, |
154 | struct device *dev) | |
155 | { | |
156 | return -ENOSYS; | |
157 | } | |
158 | static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, | |
159 | struct generic_pm_domain *new_sd) | |
160 | { | |
161 | return -ENOSYS; | |
162 | } | |
163 | static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, | |
164 | struct generic_pm_domain *target) | |
165 | { | |
166 | return -ENOSYS; | |
167 | } | |
7eb231c3 UH |
168 | static inline int pm_genpd_init(struct generic_pm_domain *genpd, |
169 | struct dev_power_governor *gov, bool is_off) | |
b02c999a | 170 | { |
7eb231c3 | 171 | return -ENOSYS; |
b02c999a | 172 | } |
3fe57710 JH |
173 | static inline int pm_genpd_remove(struct generic_pm_domain *genpd) |
174 | { | |
175 | return -ENOTSUPP; | |
176 | } | |
17f2ae7f RW |
177 | #endif |
178 | ||
b5abb085 RW |
179 | static inline int pm_genpd_add_device(struct generic_pm_domain *genpd, |
180 | struct device *dev) | |
181 | { | |
182 | return __pm_genpd_add_device(genpd, dev, NULL); | |
183 | } | |
184 | ||
77f827de | 185 | #ifdef CONFIG_PM_GENERIC_DOMAINS_SLEEP |
d47e6464 UH |
186 | extern void pm_genpd_syscore_poweroff(struct device *dev); |
187 | extern void pm_genpd_syscore_poweron(struct device *dev); | |
77f827de | 188 | #else |
d47e6464 UH |
189 | static inline void pm_genpd_syscore_poweroff(struct device *dev) {} |
190 | static inline void pm_genpd_syscore_poweron(struct device *dev) {} | |
77f827de RW |
191 | #endif |
192 | ||
aa42240a TF |
193 | /* OF PM domain providers */ |
194 | struct of_device_id; | |
195 | ||
196 | struct genpd_onecell_data { | |
197 | struct generic_pm_domain **domains; | |
198 | unsigned int num_domains; | |
199 | }; | |
200 | ||
aa42240a | 201 | #ifdef CONFIG_PM_GENERIC_DOMAINS_OF |
892ebdcc JH |
202 | int of_genpd_add_provider_simple(struct device_node *np, |
203 | struct generic_pm_domain *genpd); | |
204 | int of_genpd_add_provider_onecell(struct device_node *np, | |
205 | struct genpd_onecell_data *data); | |
aa42240a | 206 | void of_genpd_del_provider(struct device_node *np); |
ec69572b JH |
207 | extern int of_genpd_add_device(struct of_phandle_args *args, |
208 | struct device *dev); | |
209 | extern int of_genpd_add_subdomain(struct of_phandle_args *parent, | |
210 | struct of_phandle_args *new_subdomain); | |
17926551 | 211 | extern struct generic_pm_domain *of_genpd_remove_last(struct device_node *np); |
30f60428 LI |
212 | extern int of_genpd_parse_idle_states(struct device_node *dn, |
213 | struct genpd_power_state **states, int *n); | |
aa42240a TF |
214 | |
215 | int genpd_dev_pm_attach(struct device *dev); | |
216 | #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */ | |
892ebdcc JH |
217 | static inline int of_genpd_add_provider_simple(struct device_node *np, |
218 | struct generic_pm_domain *genpd) | |
aa42240a | 219 | { |
892ebdcc JH |
220 | return -ENOTSUPP; |
221 | } | |
222 | ||
223 | static inline int of_genpd_add_provider_onecell(struct device_node *np, | |
224 | struct genpd_onecell_data *data) | |
225 | { | |
226 | return -ENOTSUPP; | |
aa42240a | 227 | } |
aa42240a | 228 | |
892ebdcc | 229 | static inline void of_genpd_del_provider(struct device_node *np) {} |
aa42240a | 230 | |
ec69572b JH |
231 | static inline int of_genpd_add_device(struct of_phandle_args *args, |
232 | struct device *dev) | |
233 | { | |
234 | return -ENODEV; | |
235 | } | |
236 | ||
237 | static inline int of_genpd_add_subdomain(struct of_phandle_args *parent, | |
238 | struct of_phandle_args *new_subdomain) | |
239 | { | |
240 | return -ENODEV; | |
241 | } | |
242 | ||
30f60428 LI |
243 | static inline int of_genpd_parse_idle_states(struct device_node *dn, |
244 | struct genpd_power_state **states, int *n) | |
245 | { | |
246 | return -ENODEV; | |
247 | } | |
248 | ||
aa42240a TF |
249 | static inline int genpd_dev_pm_attach(struct device *dev) |
250 | { | |
251 | return -ENODEV; | |
252 | } | |
17926551 JH |
253 | |
254 | static inline | |
255 | struct generic_pm_domain *of_genpd_remove_last(struct device_node *np) | |
256 | { | |
257 | return ERR_PTR(-ENOTSUPP); | |
258 | } | |
aa42240a TF |
259 | #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */ |
260 | ||
f48c767c UH |
261 | #ifdef CONFIG_PM |
262 | extern int dev_pm_domain_attach(struct device *dev, bool power_on); | |
263 | extern void dev_pm_domain_detach(struct device *dev, bool power_off); | |
989561de | 264 | extern void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd); |
f48c767c UH |
265 | #else |
266 | static inline int dev_pm_domain_attach(struct device *dev, bool power_on) | |
267 | { | |
268 | return -ENODEV; | |
269 | } | |
270 | static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {} | |
989561de TV |
271 | static inline void dev_pm_domain_set(struct device *dev, |
272 | struct dev_pm_domain *pd) {} | |
f48c767c UH |
273 | #endif |
274 | ||
f721889f | 275 | #endif /* _LINUX_PM_DOMAIN_H */ |