PM / Domains: Don't expose generic_pm_domain structure to clients
[cascardo/linux.git] / include / linux / pm_domain.h
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>
13 #include <linux/mutex.h>
14 #include <linux/pm.h>
15 #include <linux/err.h>
16 #include <linux/of.h>
17 #include <linux/notifier.h>
18
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
22 #define GENPD_MAX_NUM_STATES    8 /* Number of possible low power states */
23
24 enum gpd_status {
25         GPD_STATE_ACTIVE = 0,   /* PM domain is active */
26         GPD_STATE_POWER_OFF,    /* PM domain is off */
27 };
28
29 struct dev_power_governor {
30         bool (*power_down_ok)(struct dev_pm_domain *domain);
31         bool (*suspend_ok)(struct device *dev);
32 };
33
34 struct gpd_dev_ops {
35         int (*start)(struct device *dev);
36         int (*stop)(struct device *dev);
37         bool (*active_wakeup)(struct device *dev);
38 };
39
40 struct genpd_power_state {
41         s64 power_off_latency_ns;
42         s64 power_on_latency_ns;
43 };
44
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 */
51         struct mutex lock;
52         struct dev_power_governor *gov;
53         struct work_struct power_off_work;
54         const char *name;
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,
67                           struct device *dev);
68         void (*detach_dev)(struct generic_pm_domain *domain,
69                            struct device *dev);
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 */
74
75 };
76
77 static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd)
78 {
79         return container_of(pd, struct generic_pm_domain, domain);
80 }
81
82 struct gpd_link {
83         struct generic_pm_domain *master;
84         struct list_head master_node;
85         struct generic_pm_domain *slave;
86         struct list_head slave_node;
87 };
88
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;
95 };
96
97 struct pm_domain_data {
98         struct list_head list_node;
99         struct device *dev;
100 };
101
102 struct generic_pm_domain_data {
103         struct pm_domain_data base;
104         struct gpd_timing_data td;
105         struct notifier_block nb;
106 };
107
108 #ifdef CONFIG_PM_GENERIC_DOMAINS
109 static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd)
110 {
111         return container_of(pdd, struct generic_pm_domain_data, base);
112 }
113
114 static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
115 {
116         return to_gpd_data(dev->power.subsys_data->domain_data);
117 }
118
119 extern int __pm_genpd_add_device(struct generic_pm_domain *genpd,
120                                  struct device *dev,
121                                  struct gpd_timing_data *td);
122
123 extern int pm_genpd_remove_device(struct generic_pm_domain *genpd,
124                                   struct device *dev);
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);
131
132 extern struct dev_power_governor simple_qos_governor;
133 extern struct dev_power_governor pm_domain_always_on_gov;
134 #else
135
136 static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
137 {
138         return ERR_PTR(-ENOSYS);
139 }
140 static inline int __pm_genpd_add_device(struct generic_pm_domain *genpd,
141                                         struct device *dev,
142                                         struct gpd_timing_data *td)
143 {
144         return -ENOSYS;
145 }
146 static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd,
147                                          struct device *dev)
148 {
149         return -ENOSYS;
150 }
151 static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
152                                          struct generic_pm_domain *new_sd)
153 {
154         return -ENOSYS;
155 }
156 static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
157                                             struct generic_pm_domain *target)
158 {
159         return -ENOSYS;
160 }
161 static inline int pm_genpd_init(struct generic_pm_domain *genpd,
162                                 struct dev_power_governor *gov, bool is_off)
163 {
164         return -ENOSYS;
165 }
166 #endif
167
168 static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
169                                       struct device *dev)
170 {
171         return __pm_genpd_add_device(genpd, dev, NULL);
172 }
173
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);
177 #else
178 static inline void pm_genpd_syscore_poweroff(struct device *dev) {}
179 static inline void pm_genpd_syscore_poweron(struct device *dev) {}
180 #endif
181
182 /* OF PM domain providers */
183 struct of_device_id;
184
185 struct genpd_onecell_data {
186         struct generic_pm_domain **domains;
187         unsigned int num_domains;
188 };
189
190 typedef struct generic_pm_domain *(*genpd_xlate_t)(struct of_phandle_args *args,
191                                                 void *data);
192
193 #ifdef CONFIG_PM_GENERIC_DOMAINS_OF
194 int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
195                         void *data);
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,
199                                         void *data);
200 struct generic_pm_domain *__of_genpd_xlate_onecell(
201                                         struct of_phandle_args *genpdspec,
202                                         void *data);
203 extern int of_genpd_add_device(struct of_phandle_args *args,
204                                struct device *dev);
205 extern int of_genpd_add_subdomain(struct of_phandle_args *parent,
206                                   struct of_phandle_args *new_subdomain);
207
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)
212 {
213         return 0;
214 }
215 static inline void of_genpd_del_provider(struct device_node *np) {}
216
217 #define __of_genpd_xlate_simple         NULL
218 #define __of_genpd_xlate_onecell        NULL
219
220 static inline int of_genpd_add_device(struct of_phandle_args *args,
221                                       struct device *dev)
222 {
223         return -ENODEV;
224 }
225
226 static inline int of_genpd_add_subdomain(struct of_phandle_args *parent,
227                                          struct of_phandle_args *new_subdomain)
228 {
229         return -ENODEV;
230 }
231
232 static inline int genpd_dev_pm_attach(struct device *dev)
233 {
234         return -ENODEV;
235 }
236 #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
237
238 static inline int of_genpd_add_provider_simple(struct device_node *np,
239                                         struct generic_pm_domain *genpd)
240 {
241         return __of_genpd_add_provider(np, __of_genpd_xlate_simple, genpd);
242 }
243 static inline int of_genpd_add_provider_onecell(struct device_node *np,
244                                         struct genpd_onecell_data *data)
245 {
246         return __of_genpd_add_provider(np, __of_genpd_xlate_onecell, data);
247 }
248
249 #ifdef CONFIG_PM
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);
253 #else
254 static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
255 {
256         return -ENODEV;
257 }
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) {}
261 #endif
262
263 #endif /* _LINUX_PM_DOMAIN_H */