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 */
22 #define GENPD_MAX_NUM_STATES 8 /* Number of possible low power states */
25 GPD_STATE_ACTIVE
= 0, /* PM domain is active */
26 GPD_STATE_POWER_OFF
, /* PM domain is off */
29 struct dev_power_governor
{
30 bool (*power_down_ok
)(struct dev_pm_domain
*domain
);
31 bool (*stop_ok
)(struct device
*dev
);
35 int (*start
)(struct device
*dev
);
36 int (*stop
)(struct device
*dev
);
37 int (*save_state
)(struct device
*dev
);
38 int (*restore_state
)(struct device
*dev
);
39 bool (*active_wakeup
)(struct device
*dev
);
42 struct genpd_power_state
{
43 s64 power_off_latency_ns
;
44 s64 power_on_latency_ns
;
47 struct generic_pm_domain
{
48 struct dev_pm_domain domain
; /* PM domain operations */
49 struct list_head gpd_list_node
; /* Node in the global PM domains list */
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 */
52 struct list_head dev_list
; /* List of devices */
54 struct dev_power_governor
*gov
;
55 struct work_struct power_off_work
;
57 atomic_t sd_count
; /* Number of subdomains with power "on" */
58 enum gpd_status status
; /* Current state of the domain */
59 unsigned int device_count
; /* Number of devices */
60 unsigned int suspended_count
; /* System suspend device counter */
61 unsigned int prepared_count
; /* Suspend counter of prepared devices */
62 bool suspend_power_off
; /* Power status before system suspend */
63 int (*power_off
)(struct generic_pm_domain
*domain
);
64 int (*power_on
)(struct generic_pm_domain
*domain
);
65 struct gpd_dev_ops dev_ops
;
66 s64 max_off_time_ns
; /* Maximum allowed "suspended" time. */
67 bool max_off_time_changed
;
68 bool cached_power_down_ok
;
69 int (*attach_dev
)(struct generic_pm_domain
*domain
,
71 void (*detach_dev
)(struct generic_pm_domain
*domain
,
73 unsigned int flags
; /* Bit field of configs for genpd */
74 struct genpd_power_state states
[GENPD_MAX_NUM_STATES
];
75 unsigned int state_count
; /* number of states */
76 unsigned int state_idx
; /* state that genpd will go to when off */
80 static inline struct generic_pm_domain
*pd_to_genpd(struct dev_pm_domain
*pd
)
82 return container_of(pd
, struct generic_pm_domain
, domain
);
86 struct generic_pm_domain
*master
;
87 struct list_head master_node
;
88 struct generic_pm_domain
*slave
;
89 struct list_head slave_node
;
92 struct gpd_timing_data
{
93 s64 suspend_latency_ns
;
94 s64 resume_latency_ns
;
95 s64 effective_constraint_ns
;
96 bool constraint_changed
;
100 struct pm_domain_data
{
101 struct list_head list_node
;
105 struct generic_pm_domain_data
{
106 struct pm_domain_data base
;
107 struct gpd_timing_data td
;
108 struct notifier_block nb
;
111 #ifdef CONFIG_PM_GENERIC_DOMAINS
112 static inline struct generic_pm_domain_data
*to_gpd_data(struct pm_domain_data
*pdd
)
114 return container_of(pdd
, struct generic_pm_domain_data
, base
);
117 static inline struct generic_pm_domain_data
*dev_gpd_data(struct device
*dev
)
119 return to_gpd_data(dev
->power
.subsys_data
->domain_data
);
122 extern struct generic_pm_domain
*pm_genpd_lookup_dev(struct device
*dev
);
123 extern int __pm_genpd_add_device(struct generic_pm_domain
*genpd
,
125 struct gpd_timing_data
*td
);
127 extern int pm_genpd_remove_device(struct generic_pm_domain
*genpd
,
129 extern int pm_genpd_add_subdomain(struct generic_pm_domain
*genpd
,
130 struct generic_pm_domain
*new_subdomain
);
131 extern int pm_genpd_remove_subdomain(struct generic_pm_domain
*genpd
,
132 struct generic_pm_domain
*target
);
133 extern void pm_genpd_init(struct generic_pm_domain
*genpd
,
134 struct dev_power_governor
*gov
, bool is_off
);
136 extern struct dev_power_governor simple_qos_governor
;
137 extern struct dev_power_governor pm_domain_always_on_gov
;
140 static inline struct generic_pm_domain_data
*dev_gpd_data(struct device
*dev
)
142 return ERR_PTR(-ENOSYS
);
144 static inline struct generic_pm_domain
*pm_genpd_lookup_dev(struct device
*dev
)
148 static inline int __pm_genpd_add_device(struct generic_pm_domain
*genpd
,
150 struct gpd_timing_data
*td
)
154 static inline int pm_genpd_remove_device(struct generic_pm_domain
*genpd
,
159 static inline int pm_genpd_add_subdomain(struct generic_pm_domain
*genpd
,
160 struct generic_pm_domain
*new_sd
)
164 static inline int pm_genpd_remove_subdomain(struct generic_pm_domain
*genpd
,
165 struct generic_pm_domain
*target
)
169 static inline void pm_genpd_init(struct generic_pm_domain
*genpd
,
170 struct dev_power_governor
*gov
, bool is_off
)
175 static inline int pm_genpd_add_device(struct generic_pm_domain
*genpd
,
178 return __pm_genpd_add_device(genpd
, dev
, NULL
);
181 #ifdef CONFIG_PM_GENERIC_DOMAINS_SLEEP
182 extern void pm_genpd_syscore_poweroff(struct device
*dev
);
183 extern void pm_genpd_syscore_poweron(struct device
*dev
);
185 static inline void pm_genpd_syscore_poweroff(struct device
*dev
) {}
186 static inline void pm_genpd_syscore_poweron(struct device
*dev
) {}
189 /* OF PM domain providers */
192 struct genpd_onecell_data
{
193 struct generic_pm_domain
**domains
;
194 unsigned int num_domains
;
197 typedef struct generic_pm_domain
*(*genpd_xlate_t
)(struct of_phandle_args
*args
,
200 #ifdef CONFIG_PM_GENERIC_DOMAINS_OF
201 int __of_genpd_add_provider(struct device_node
*np
, genpd_xlate_t xlate
,
203 void of_genpd_del_provider(struct device_node
*np
);
204 struct generic_pm_domain
*of_genpd_get_from_provider(
205 struct of_phandle_args
*genpdspec
);
207 struct generic_pm_domain
*__of_genpd_xlate_simple(
208 struct of_phandle_args
*genpdspec
,
210 struct generic_pm_domain
*__of_genpd_xlate_onecell(
211 struct of_phandle_args
*genpdspec
,
214 int genpd_dev_pm_attach(struct device
*dev
);
215 #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
216 static inline int __of_genpd_add_provider(struct device_node
*np
,
217 genpd_xlate_t xlate
, void *data
)
221 static inline void of_genpd_del_provider(struct device_node
*np
) {}
223 static inline struct generic_pm_domain
*of_genpd_get_from_provider(
224 struct of_phandle_args
*genpdspec
)
229 #define __of_genpd_xlate_simple NULL
230 #define __of_genpd_xlate_onecell NULL
232 static inline int genpd_dev_pm_attach(struct device
*dev
)
236 #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
238 static inline int of_genpd_add_provider_simple(struct device_node
*np
,
239 struct generic_pm_domain
*genpd
)
241 return __of_genpd_add_provider(np
, __of_genpd_xlate_simple
, genpd
);
243 static inline int of_genpd_add_provider_onecell(struct device_node
*np
,
244 struct genpd_onecell_data
*data
)
246 return __of_genpd_add_provider(np
, __of_genpd_xlate_onecell
, data
);
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
);
254 static inline int dev_pm_domain_attach(struct device
*dev
, bool power_on
)
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
) {}
263 #endif /* _LINUX_PM_DOMAIN_H */