]>
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); | |
b02c999a | 29 | bool (*stop_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); | |
ecf00475 RW |
35 | int (*save_state)(struct device *dev); |
36 | int (*restore_state)(struct device *dev); | |
d5e4cbfe RW |
37 | bool (*active_wakeup)(struct device *dev); |
38 | }; | |
39 | ||
f721889f RW |
40 | struct generic_pm_domain { |
41 | struct dev_pm_domain domain; /* PM domain operations */ | |
5125bbf3 | 42 | struct list_head gpd_list_node; /* Node in the global PM domains list */ |
5063ce15 RW |
43 | struct list_head master_links; /* Links with PM domain as a master */ |
44 | struct list_head slave_links; /* Links with PM domain as a slave */ | |
f721889f RW |
45 | struct list_head dev_list; /* List of devices */ |
46 | struct mutex lock; | |
47 | struct dev_power_governor *gov; | |
48 | struct work_struct power_off_work; | |
d07e9c17 | 49 | const char *name; |
c4bb3160 | 50 | atomic_t sd_count; /* Number of subdomains with power "on" */ |
17b75eca | 51 | enum gpd_status status; /* Current state of the domain */ |
596ba34b RW |
52 | unsigned int device_count; /* Number of devices */ |
53 | unsigned int suspended_count; /* System suspend device counter */ | |
54 | unsigned int prepared_count; /* Suspend counter of prepared devices */ | |
55 | bool suspend_power_off; /* Power status before system suspend */ | |
f721889f | 56 | int (*power_off)(struct generic_pm_domain *domain); |
221e9b58 | 57 | s64 power_off_latency_ns; |
f721889f | 58 | int (*power_on)(struct generic_pm_domain *domain); |
221e9b58 | 59 | s64 power_on_latency_ns; |
d5e4cbfe | 60 | struct gpd_dev_ops dev_ops; |
221e9b58 | 61 | s64 max_off_time_ns; /* Maximum allowed "suspended" time. */ |
6ff7bb0d RW |
62 | bool max_off_time_changed; |
63 | bool cached_power_down_ok; | |
c16561e8 UH |
64 | int (*attach_dev)(struct generic_pm_domain *domain, |
65 | struct device *dev); | |
66 | void (*detach_dev)(struct generic_pm_domain *domain, | |
67 | struct device *dev); | |
c11f6f5b | 68 | unsigned int flags; /* Bit field of configs for genpd */ |
f721889f RW |
69 | }; |
70 | ||
596ba34b RW |
71 | static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd) |
72 | { | |
73 | return container_of(pd, struct generic_pm_domain, domain); | |
74 | } | |
75 | ||
5063ce15 RW |
76 | struct gpd_link { |
77 | struct generic_pm_domain *master; | |
78 | struct list_head master_node; | |
79 | struct generic_pm_domain *slave; | |
80 | struct list_head slave_node; | |
81 | }; | |
82 | ||
b02c999a | 83 | struct gpd_timing_data { |
2b1d88cd UH |
84 | s64 suspend_latency_ns; |
85 | s64 resume_latency_ns; | |
a5bef810 | 86 | s64 effective_constraint_ns; |
6ff7bb0d RW |
87 | bool constraint_changed; |
88 | bool cached_stop_ok; | |
b02c999a RW |
89 | }; |
90 | ||
00e7c295 UH |
91 | struct pm_domain_data { |
92 | struct list_head list_node; | |
93 | struct device *dev; | |
94 | }; | |
95 | ||
cd0ea672 RW |
96 | struct generic_pm_domain_data { |
97 | struct pm_domain_data base; | |
b02c999a | 98 | struct gpd_timing_data td; |
6ff7bb0d | 99 | struct notifier_block nb; |
cd0ea672 RW |
100 | }; |
101 | ||
9b4f617b | 102 | #ifdef CONFIG_PM_GENERIC_DOMAINS |
cd0ea672 RW |
103 | static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd) |
104 | { | |
105 | return container_of(pdd, struct generic_pm_domain_data, base); | |
106 | } | |
107 | ||
d5e4cbfe RW |
108 | static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev) |
109 | { | |
110 | return to_gpd_data(dev->power.subsys_data->domain_data); | |
111 | } | |
112 | ||
446d999c | 113 | extern struct generic_pm_domain *pm_genpd_lookup_dev(struct device *dev); |
b02c999a RW |
114 | extern int __pm_genpd_add_device(struct generic_pm_domain *genpd, |
115 | struct device *dev, | |
116 | struct gpd_timing_data *td); | |
117 | ||
f721889f RW |
118 | extern int pm_genpd_remove_device(struct generic_pm_domain *genpd, |
119 | struct device *dev); | |
120 | extern int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, | |
121 | struct generic_pm_domain *new_subdomain); | |
122 | extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, | |
123 | struct generic_pm_domain *target); | |
124 | extern void pm_genpd_init(struct generic_pm_domain *genpd, | |
125 | struct dev_power_governor *gov, bool is_off); | |
b02c999a | 126 | |
ae3c511c | 127 | extern struct dev_power_governor simple_qos_governor; |
925b44a2 | 128 | extern struct dev_power_governor pm_domain_always_on_gov; |
f721889f | 129 | #else |
b02c999a | 130 | |
b642631d MD |
131 | static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev) |
132 | { | |
133 | return ERR_PTR(-ENOSYS); | |
134 | } | |
446d999c | 135 | static inline struct generic_pm_domain *pm_genpd_lookup_dev(struct device *dev) |
b02c999a | 136 | { |
446d999c | 137 | return NULL; |
b02c999a RW |
138 | } |
139 | static inline int __pm_genpd_add_device(struct generic_pm_domain *genpd, | |
140 | struct device *dev, | |
141 | struct gpd_timing_data *td) | |
142 | { | |
143 | return -ENOSYS; | |
144 | } | |
f721889f RW |
145 | static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd, |
146 | struct device *dev) | |
147 | { | |
148 | return -ENOSYS; | |
149 | } | |
150 | static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, | |
151 | struct generic_pm_domain *new_sd) | |
152 | { | |
153 | return -ENOSYS; | |
154 | } | |
155 | static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, | |
156 | struct generic_pm_domain *target) | |
157 | { | |
158 | return -ENOSYS; | |
159 | } | |
b642631d MD |
160 | static inline void pm_genpd_init(struct generic_pm_domain *genpd, |
161 | struct dev_power_governor *gov, bool is_off) | |
b02c999a RW |
162 | { |
163 | } | |
17f2ae7f RW |
164 | #endif |
165 | ||
b5abb085 RW |
166 | static inline int pm_genpd_add_device(struct generic_pm_domain *genpd, |
167 | struct device *dev) | |
168 | { | |
169 | return __pm_genpd_add_device(genpd, dev, NULL); | |
170 | } | |
171 | ||
77f827de | 172 | #ifdef CONFIG_PM_GENERIC_DOMAINS_SLEEP |
d47e6464 UH |
173 | extern void pm_genpd_syscore_poweroff(struct device *dev); |
174 | extern void pm_genpd_syscore_poweron(struct device *dev); | |
77f827de | 175 | #else |
d47e6464 UH |
176 | static inline void pm_genpd_syscore_poweroff(struct device *dev) {} |
177 | static inline void pm_genpd_syscore_poweron(struct device *dev) {} | |
77f827de RW |
178 | #endif |
179 | ||
aa42240a TF |
180 | /* OF PM domain providers */ |
181 | struct of_device_id; | |
182 | ||
183 | struct genpd_onecell_data { | |
184 | struct generic_pm_domain **domains; | |
185 | unsigned int num_domains; | |
186 | }; | |
187 | ||
188 | typedef struct generic_pm_domain *(*genpd_xlate_t)(struct of_phandle_args *args, | |
189 | void *data); | |
190 | ||
191 | #ifdef CONFIG_PM_GENERIC_DOMAINS_OF | |
192 | int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate, | |
193 | void *data); | |
194 | void of_genpd_del_provider(struct device_node *np); | |
7496fcbe ADK |
195 | struct generic_pm_domain *of_genpd_get_from_provider( |
196 | struct of_phandle_args *genpdspec); | |
aa42240a TF |
197 | |
198 | struct generic_pm_domain *__of_genpd_xlate_simple( | |
199 | struct of_phandle_args *genpdspec, | |
200 | void *data); | |
201 | struct generic_pm_domain *__of_genpd_xlate_onecell( | |
202 | struct of_phandle_args *genpdspec, | |
203 | void *data); | |
204 | ||
205 | int genpd_dev_pm_attach(struct device *dev); | |
206 | #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */ | |
207 | static inline int __of_genpd_add_provider(struct device_node *np, | |
208 | genpd_xlate_t xlate, void *data) | |
209 | { | |
210 | return 0; | |
211 | } | |
212 | static inline void of_genpd_del_provider(struct device_node *np) {} | |
213 | ||
7496fcbe ADK |
214 | static inline struct generic_pm_domain *of_genpd_get_from_provider( |
215 | struct of_phandle_args *genpdspec) | |
216 | { | |
217 | return NULL; | |
218 | } | |
219 | ||
aa42240a TF |
220 | #define __of_genpd_xlate_simple NULL |
221 | #define __of_genpd_xlate_onecell NULL | |
222 | ||
223 | static inline int genpd_dev_pm_attach(struct device *dev) | |
224 | { | |
225 | return -ENODEV; | |
226 | } | |
227 | #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */ | |
228 | ||
229 | static inline int of_genpd_add_provider_simple(struct device_node *np, | |
230 | struct generic_pm_domain *genpd) | |
231 | { | |
232 | return __of_genpd_add_provider(np, __of_genpd_xlate_simple, genpd); | |
233 | } | |
234 | static inline int of_genpd_add_provider_onecell(struct device_node *np, | |
235 | struct genpd_onecell_data *data) | |
236 | { | |
237 | return __of_genpd_add_provider(np, __of_genpd_xlate_onecell, data); | |
238 | } | |
239 | ||
f48c767c UH |
240 | #ifdef CONFIG_PM |
241 | extern int dev_pm_domain_attach(struct device *dev, bool power_on); | |
242 | extern void dev_pm_domain_detach(struct device *dev, bool power_off); | |
989561de | 243 | extern void dev_pm_domain_set(struct device *dev, struct dev_pm_domain *pd); |
f48c767c UH |
244 | #else |
245 | static inline int dev_pm_domain_attach(struct device *dev, bool power_on) | |
246 | { | |
247 | return -ENODEV; | |
248 | } | |
249 | static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {} | |
989561de TV |
250 | static inline void dev_pm_domain_set(struct device *dev, |
251 | struct dev_pm_domain *pd) {} | |
f48c767c UH |
252 | #endif |
253 | ||
f721889f | 254 | #endif /* _LINUX_PM_DOMAIN_H */ |