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>
18 #include <linux/spinlock.h>
21 * Flags to control the behaviour of a genpd.
23 * These flags may be set in the struct generic_pm_domain's flags field by a
24 * genpd backend driver. The flags must be set before it calls pm_genpd_init(),
25 * which initializes a genpd.
27 * GENPD_FLAG_PM_CLK: Instructs genpd to use the PM clk framework,
28 * while powering on/off attached devices.
30 * GENPD_FLAG_IRQ_SAFE: This informs genpd that its backend callbacks,
31 * ->power_on|off(), doesn't sleep. Hence, these
32 * can be invoked from within atomic context, which
33 * enables genpd to power on/off the PM domain,
34 * even when pm_runtime_is_irq_safe() returns true,
35 * for any of its attached devices. Note that, a
36 * genpd having this flag set, requires its
37 * masterdomains to also have it set.
39 * GENPD_FLAG_ALWAYS_ON: Instructs genpd to always keep the PM domain
42 * GENPD_FLAG_ACTIVE_WAKEUP: Instructs genpd to keep the PM domain powered
43 * on, in case any of its attached devices is used
44 * in the wakeup path to serve system wakeups.
46 #define GENPD_FLAG_PM_CLK (1U << 0)
47 #define GENPD_FLAG_IRQ_SAFE (1U << 1)
48 #define GENPD_FLAG_ALWAYS_ON (1U << 2)
49 #define GENPD_FLAG_ACTIVE_WAKEUP (1U << 3)
52 GPD_STATE_ACTIVE
= 0, /* PM domain is active */
53 GPD_STATE_POWER_OFF
, /* PM domain is off */
56 struct dev_power_governor
{
57 bool (*power_down_ok
)(struct dev_pm_domain
*domain
);
58 bool (*suspend_ok
)(struct device
*dev
);
62 int (*start
)(struct device
*dev
);
63 int (*stop
)(struct device
*dev
);
66 struct genpd_power_state
{
67 s64 power_off_latency_ns
;
68 s64 power_on_latency_ns
;
70 struct fwnode_handle
*fwnode
;
74 struct genpd_lock_ops
;
77 struct generic_pm_domain
{
79 struct dev_pm_domain domain
; /* PM domain operations */
80 struct list_head gpd_list_node
; /* Node in the global PM domains list */
81 struct list_head master_links
; /* Links with PM domain as a master */
82 struct list_head slave_links
; /* Links with PM domain as a slave */
83 struct list_head dev_list
; /* List of devices */
84 struct dev_power_governor
*gov
;
85 struct work_struct power_off_work
;
86 struct fwnode_handle
*provider
; /* Identity of the domain provider */
89 atomic_t sd_count
; /* Number of subdomains with power "on" */
90 enum gpd_status status
; /* Current state of the domain */
91 unsigned int device_count
; /* Number of devices */
92 unsigned int suspended_count
; /* System suspend device counter */
93 unsigned int prepared_count
; /* Suspend counter of prepared devices */
94 unsigned int performance_state
; /* Aggregated max performance state */
95 int (*power_off
)(struct generic_pm_domain
*domain
);
96 int (*power_on
)(struct generic_pm_domain
*domain
);
97 unsigned int (*opp_to_performance_state
)(struct generic_pm_domain
*genpd
,
98 struct dev_pm_opp
*opp
);
99 int (*set_performance_state
)(struct generic_pm_domain
*genpd
,
101 struct gpd_dev_ops dev_ops
;
102 s64 max_off_time_ns
; /* Maximum allowed "suspended" time. */
103 bool max_off_time_changed
;
104 bool cached_power_down_ok
;
105 int (*attach_dev
)(struct generic_pm_domain
*domain
,
107 void (*detach_dev
)(struct generic_pm_domain
*domain
,
109 unsigned int flags
; /* Bit field of configs for genpd */
110 struct genpd_power_state
*states
;
111 unsigned int state_count
; /* number of states */
112 unsigned int state_idx
; /* state that genpd will go to when off */
113 void *free
; /* Free the state that was allocated for default */
115 ktime_t accounting_time
;
116 const struct genpd_lock_ops
*lock_ops
;
121 unsigned long lock_flags
;
127 static inline struct generic_pm_domain
*pd_to_genpd(struct dev_pm_domain
*pd
)
129 return container_of(pd
, struct generic_pm_domain
, domain
);
133 struct generic_pm_domain
*master
;
134 struct list_head master_node
;
135 struct generic_pm_domain
*slave
;
136 struct list_head slave_node
;
139 struct gpd_timing_data
{
140 s64 suspend_latency_ns
;
141 s64 resume_latency_ns
;
142 s64 effective_constraint_ns
;
143 bool constraint_changed
;
144 bool cached_suspend_ok
;
147 struct pm_domain_data
{
148 struct list_head list_node
;
152 struct generic_pm_domain_data
{
153 struct pm_domain_data base
;
154 struct gpd_timing_data td
;
155 struct notifier_block nb
;
156 unsigned int performance_state
;
160 #ifdef CONFIG_PM_GENERIC_DOMAINS
161 static inline struct generic_pm_domain_data
*to_gpd_data(struct pm_domain_data
*pdd
)
163 return container_of(pdd
, struct generic_pm_domain_data
, base
);
166 static inline struct generic_pm_domain_data
*dev_gpd_data(struct device
*dev
)
168 return to_gpd_data(dev
->power
.subsys_data
->domain_data
);
171 int pm_genpd_add_device(struct generic_pm_domain
*genpd
, struct device
*dev
);
172 int pm_genpd_remove_device(struct device
*dev
);
173 int pm_genpd_add_subdomain(struct generic_pm_domain
*genpd
,
174 struct generic_pm_domain
*new_subdomain
);
175 int pm_genpd_remove_subdomain(struct generic_pm_domain
*genpd
,
176 struct generic_pm_domain
*target
);
177 int pm_genpd_init(struct generic_pm_domain
*genpd
,
178 struct dev_power_governor
*gov
, bool is_off
);
179 int pm_genpd_remove(struct generic_pm_domain
*genpd
);
180 int dev_pm_genpd_set_performance_state(struct device
*dev
, unsigned int state
);
182 extern struct dev_power_governor simple_qos_governor
;
183 extern struct dev_power_governor pm_domain_always_on_gov
;
186 static inline struct generic_pm_domain_data
*dev_gpd_data(struct device
*dev
)
188 return ERR_PTR(-ENOSYS
);
190 static inline int pm_genpd_add_device(struct generic_pm_domain
*genpd
,
195 static inline int pm_genpd_remove_device(struct device
*dev
)
199 static inline int pm_genpd_add_subdomain(struct generic_pm_domain
*genpd
,
200 struct generic_pm_domain
*new_sd
)
204 static inline int pm_genpd_remove_subdomain(struct generic_pm_domain
*genpd
,
205 struct generic_pm_domain
*target
)
209 static inline int pm_genpd_init(struct generic_pm_domain
*genpd
,
210 struct dev_power_governor
*gov
, bool is_off
)
214 static inline int pm_genpd_remove(struct generic_pm_domain
*genpd
)
219 static inline int dev_pm_genpd_set_performance_state(struct device
*dev
,
225 #define simple_qos_governor (*(struct dev_power_governor *)(NULL))
226 #define pm_domain_always_on_gov (*(struct dev_power_governor *)(NULL))
229 #ifdef CONFIG_PM_GENERIC_DOMAINS_SLEEP
230 void pm_genpd_syscore_poweroff(struct device
*dev
);
231 void pm_genpd_syscore_poweron(struct device
*dev
);
233 static inline void pm_genpd_syscore_poweroff(struct device
*dev
) {}
234 static inline void pm_genpd_syscore_poweron(struct device
*dev
) {}
237 /* OF PM domain providers */
240 typedef struct generic_pm_domain
*(*genpd_xlate_t
)(struct of_phandle_args
*args
,
243 struct genpd_onecell_data
{
244 struct generic_pm_domain
**domains
;
245 unsigned int num_domains
;
249 #ifdef CONFIG_PM_GENERIC_DOMAINS_OF
250 int of_genpd_add_provider_simple(struct device_node
*np
,
251 struct generic_pm_domain
*genpd
);
252 int of_genpd_add_provider_onecell(struct device_node
*np
,
253 struct genpd_onecell_data
*data
);
254 void of_genpd_del_provider(struct device_node
*np
);
255 int of_genpd_add_device(struct of_phandle_args
*args
, struct device
*dev
);
256 int of_genpd_add_subdomain(struct of_phandle_args
*parent
,
257 struct of_phandle_args
*new_subdomain
);
258 struct generic_pm_domain
*of_genpd_remove_last(struct device_node
*np
);
259 int of_genpd_parse_idle_states(struct device_node
*dn
,
260 struct genpd_power_state
**states
, int *n
);
261 unsigned int of_genpd_opp_to_performance_state(struct device
*dev
,
262 struct device_node
*np
);
264 int genpd_dev_pm_attach(struct device
*dev
);
265 struct device
*genpd_dev_pm_attach_by_id(struct device
*dev
,
267 struct device
*genpd_dev_pm_attach_by_name(struct device
*dev
,
269 #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
270 static inline int of_genpd_add_provider_simple(struct device_node
*np
,
271 struct generic_pm_domain
*genpd
)
276 static inline int of_genpd_add_provider_onecell(struct device_node
*np
,
277 struct genpd_onecell_data
*data
)
282 static inline void of_genpd_del_provider(struct device_node
*np
) {}
284 static inline int of_genpd_add_device(struct of_phandle_args
*args
,
290 static inline int of_genpd_add_subdomain(struct of_phandle_args
*parent
,
291 struct of_phandle_args
*new_subdomain
)
296 static inline int of_genpd_parse_idle_states(struct device_node
*dn
,
297 struct genpd_power_state
**states
, int *n
)
302 static inline unsigned int
303 of_genpd_opp_to_performance_state(struct device
*dev
,
304 struct device_node
*np
)
309 static inline int genpd_dev_pm_attach(struct device
*dev
)
314 static inline struct device
*genpd_dev_pm_attach_by_id(struct device
*dev
,
320 static inline struct device
*genpd_dev_pm_attach_by_name(struct device
*dev
,
327 struct generic_pm_domain
*of_genpd_remove_last(struct device_node
*np
)
329 return ERR_PTR(-ENOTSUPP
);
331 #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
334 int dev_pm_domain_attach(struct device
*dev
, bool power_on
);
335 struct device
*dev_pm_domain_attach_by_id(struct device
*dev
,
337 struct device
*dev_pm_domain_attach_by_name(struct device
*dev
,
339 void dev_pm_domain_detach(struct device
*dev
, bool power_off
);
340 void dev_pm_domain_set(struct device
*dev
, struct dev_pm_domain
*pd
);
342 static inline int dev_pm_domain_attach(struct device
*dev
, bool power_on
)
346 static inline struct device
*dev_pm_domain_attach_by_id(struct device
*dev
,
351 static inline struct device
*dev_pm_domain_attach_by_name(struct device
*dev
,
356 static inline void dev_pm_domain_detach(struct device
*dev
, bool power_off
) {}
357 static inline void dev_pm_domain_set(struct device
*dev
,
358 struct dev_pm_domain
*pd
) {}
361 #endif /* _LINUX_PM_DOMAIN_H */