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 */
23 GPD_STATE_ACTIVE = 0, /* PM domain is active */
24 GPD_STATE_POWER_OFF, /* PM domain is off */
27 struct dev_power_governor {
28 bool (*power_down_ok)(struct dev_pm_domain *domain);
29 bool (*stop_ok)(struct device *dev);
33 int (*start)(struct device *dev);
34 int (*stop)(struct device *dev);
35 int (*save_state)(struct device *dev);
36 int (*restore_state)(struct device *dev);
37 bool (*active_wakeup)(struct device *dev);
40 struct generic_pm_domain {
41 struct dev_pm_domain domain; /* PM domain operations */
42 struct list_head gpd_list_node; /* Node in the global PM domains list */
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 */
45 struct list_head dev_list; /* List of devices */
47 struct dev_power_governor *gov;
48 struct work_struct power_off_work;
50 unsigned int in_progress; /* Number of devices being suspended now */
51 atomic_t sd_count; /* Number of subdomains with power "on" */
52 enum gpd_status status; /* Current state of the domain */
53 unsigned int device_count; /* Number of devices */
54 unsigned int suspended_count; /* System suspend device counter */
55 unsigned int prepared_count; /* Suspend counter of prepared devices */
56 bool suspend_power_off; /* Power status before system suspend */
57 int (*power_off)(struct generic_pm_domain *domain);
58 s64 power_off_latency_ns;
59 int (*power_on)(struct generic_pm_domain *domain);
60 s64 power_on_latency_ns;
61 struct gpd_dev_ops dev_ops;
62 s64 max_off_time_ns; /* Maximum allowed "suspended" time. */
63 bool max_off_time_changed;
64 bool cached_power_down_ok;
65 int (*attach_dev)(struct generic_pm_domain *domain,
67 void (*detach_dev)(struct generic_pm_domain *domain,
69 unsigned int flags; /* Bit field of configs for genpd */
72 static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd)
74 return container_of(pd, struct generic_pm_domain, domain);
78 struct generic_pm_domain *master;
79 struct list_head master_node;
80 struct generic_pm_domain *slave;
81 struct list_head slave_node;
84 struct gpd_timing_data {
87 s64 save_state_latency_ns;
88 s64 restore_state_latency_ns;
89 s64 effective_constraint_ns;
90 bool constraint_changed;
94 struct pm_domain_data {
95 struct list_head list_node;
99 struct generic_pm_domain_data {
100 struct pm_domain_data base;
101 struct gpd_timing_data td;
102 struct notifier_block nb;
105 #ifdef CONFIG_PM_GENERIC_DOMAINS
106 static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd)
108 return container_of(pdd, struct generic_pm_domain_data, base);
111 static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
113 return to_gpd_data(dev->power.subsys_data->domain_data);
116 extern struct generic_pm_domain *pm_genpd_lookup_dev(struct device *dev);
117 extern int __pm_genpd_add_device(struct generic_pm_domain *genpd,
119 struct gpd_timing_data *td);
121 extern int pm_genpd_remove_device(struct generic_pm_domain *genpd,
123 extern int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
124 struct generic_pm_domain *new_subdomain);
125 extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
126 struct generic_pm_domain *target);
127 extern void pm_genpd_init(struct generic_pm_domain *genpd,
128 struct dev_power_governor *gov, bool is_off);
130 extern int pm_genpd_poweron(struct generic_pm_domain *genpd);
131 extern void pm_genpd_poweroff_unused(void);
133 extern struct dev_power_governor simple_qos_governor;
134 extern struct dev_power_governor pm_domain_always_on_gov;
137 static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
139 return ERR_PTR(-ENOSYS);
141 static inline struct generic_pm_domain *pm_genpd_lookup_dev(struct device *dev)
145 static inline int __pm_genpd_add_device(struct generic_pm_domain *genpd,
147 struct gpd_timing_data *td)
151 static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd,
156 static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
157 struct generic_pm_domain *new_sd)
161 static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
162 struct generic_pm_domain *target)
166 static inline void pm_genpd_init(struct generic_pm_domain *genpd,
167 struct dev_power_governor *gov, bool is_off)
170 static inline int pm_genpd_poweron(struct generic_pm_domain *genpd)
174 static inline void pm_genpd_poweroff_unused(void) {}
177 static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
180 return __pm_genpd_add_device(genpd, dev, NULL);
183 #ifdef CONFIG_PM_GENERIC_DOMAINS_SLEEP
184 extern void pm_genpd_syscore_poweroff(struct device *dev);
185 extern void pm_genpd_syscore_poweron(struct device *dev);
187 static inline void pm_genpd_syscore_poweroff(struct device *dev) {}
188 static inline void pm_genpd_syscore_poweron(struct device *dev) {}
191 /* OF PM domain providers */
194 struct genpd_onecell_data {
195 struct generic_pm_domain **domains;
196 unsigned int num_domains;
199 typedef struct generic_pm_domain *(*genpd_xlate_t)(struct of_phandle_args *args,
202 #ifdef CONFIG_PM_GENERIC_DOMAINS_OF
203 int __of_genpd_add_provider(struct device_node *np, genpd_xlate_t xlate,
205 void of_genpd_del_provider(struct device_node *np);
206 struct generic_pm_domain *of_genpd_get_from_provider(
207 struct of_phandle_args *genpdspec);
209 struct generic_pm_domain *__of_genpd_xlate_simple(
210 struct of_phandle_args *genpdspec,
212 struct generic_pm_domain *__of_genpd_xlate_onecell(
213 struct of_phandle_args *genpdspec,
216 int genpd_dev_pm_attach(struct device *dev);
217 #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
218 static inline int __of_genpd_add_provider(struct device_node *np,
219 genpd_xlate_t xlate, void *data)
223 static inline void of_genpd_del_provider(struct device_node *np) {}
225 static inline struct generic_pm_domain *of_genpd_get_from_provider(
226 struct of_phandle_args *genpdspec)
231 #define __of_genpd_xlate_simple NULL
232 #define __of_genpd_xlate_onecell NULL
234 static inline int genpd_dev_pm_attach(struct device *dev)
238 #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
240 static inline int of_genpd_add_provider_simple(struct device_node *np,
241 struct generic_pm_domain *genpd)
243 return __of_genpd_add_provider(np, __of_genpd_xlate_simple, genpd);
245 static inline int of_genpd_add_provider_onecell(struct device_node *np,
246 struct genpd_onecell_data *data)
248 return __of_genpd_add_provider(np, __of_genpd_xlate_onecell, data);
252 extern int dev_pm_domain_attach(struct device *dev, bool power_on);
253 extern void dev_pm_domain_detach(struct device *dev, bool power_off);
255 static inline int dev_pm_domain_attach(struct device *dev, bool power_on)
259 static inline void dev_pm_domain_detach(struct device *dev, bool power_off) {}
262 #endif /* _LINUX_PM_DOMAIN_H */