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 (*suspend_ok
)(struct device
*dev
);
35 int (*start
)(struct device
*dev
);
36 int (*stop
)(struct device
*dev
);
37 bool (*active_wakeup
)(struct device
*dev
);
40 struct genpd_power_state
{
41 s64 power_off_latency_ns
;
42 s64 power_on_latency_ns
;
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 */
52 struct dev_power_governor
*gov
;
53 struct work_struct power_off_work
;
54 struct fwnode_handle
*provider
; /* Identity of the domain provider */
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 int (*power_off
)(struct generic_pm_domain
*domain
);
63 int (*power_on
)(struct generic_pm_domain
*domain
);
64 struct gpd_dev_ops dev_ops
;
65 s64 max_off_time_ns
; /* Maximum allowed "suspended" time. */
66 bool max_off_time_changed
;
67 bool cached_power_down_ok
;
68 int (*attach_dev
)(struct generic_pm_domain
*domain
,
70 void (*detach_dev
)(struct generic_pm_domain
*domain
,
72 unsigned int flags
; /* Bit field of configs for genpd */
73 struct genpd_power_state states
[GENPD_MAX_NUM_STATES
];
74 unsigned int state_count
; /* number of states */
75 unsigned int state_idx
; /* state that genpd will go to when off */
79 static inline struct generic_pm_domain
*pd_to_genpd(struct dev_pm_domain
*pd
)
81 return container_of(pd
, struct generic_pm_domain
, domain
);
85 struct generic_pm_domain
*master
;
86 struct list_head master_node
;
87 struct generic_pm_domain
*slave
;
88 struct list_head slave_node
;
91 struct gpd_timing_data
{
92 s64 suspend_latency_ns
;
93 s64 resume_latency_ns
;
94 s64 effective_constraint_ns
;
95 bool constraint_changed
;
96 bool cached_suspend_ok
;
99 struct pm_domain_data
{
100 struct list_head list_node
;
104 struct generic_pm_domain_data
{
105 struct pm_domain_data base
;
106 struct gpd_timing_data td
;
107 struct notifier_block nb
;
110 #ifdef CONFIG_PM_GENERIC_DOMAINS
111 static inline struct generic_pm_domain_data
*to_gpd_data(struct pm_domain_data
*pdd
)
113 return container_of(pdd
, struct generic_pm_domain_data
, base
);
116 static inline struct generic_pm_domain_data
*dev_gpd_data(struct device
*dev
)
118 return to_gpd_data(dev
->power
.subsys_data
->domain_data
);
121 extern int __pm_genpd_add_device(struct generic_pm_domain
*genpd
,
123 struct gpd_timing_data
*td
);
125 extern int pm_genpd_remove_device(struct generic_pm_domain
*genpd
,
127 extern int pm_genpd_add_subdomain(struct generic_pm_domain
*genpd
,
128 struct generic_pm_domain
*new_subdomain
);
129 extern int pm_genpd_remove_subdomain(struct generic_pm_domain
*genpd
,
130 struct generic_pm_domain
*target
);
131 extern int pm_genpd_init(struct generic_pm_domain
*genpd
,
132 struct dev_power_governor
*gov
, bool is_off
);
133 extern int pm_genpd_remove(struct generic_pm_domain
*genpd
);
135 extern struct dev_power_governor simple_qos_governor
;
136 extern struct dev_power_governor pm_domain_always_on_gov
;
139 static inline struct generic_pm_domain_data
*dev_gpd_data(struct device
*dev
)
141 return ERR_PTR(-ENOSYS
);
143 static inline int __pm_genpd_add_device(struct generic_pm_domain
*genpd
,
145 struct gpd_timing_data
*td
)
149 static inline int pm_genpd_remove_device(struct generic_pm_domain
*genpd
,
154 static inline int pm_genpd_add_subdomain(struct generic_pm_domain
*genpd
,
155 struct generic_pm_domain
*new_sd
)
159 static inline int pm_genpd_remove_subdomain(struct generic_pm_domain
*genpd
,
160 struct generic_pm_domain
*target
)
164 static inline int pm_genpd_init(struct generic_pm_domain
*genpd
,
165 struct dev_power_governor
*gov
, bool is_off
)
169 static inline int pm_genpd_remove(struct generic_pm_domain
*genpd
)
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 #ifdef CONFIG_PM_GENERIC_DOMAINS_OF
198 int of_genpd_add_provider_simple(struct device_node
*np
,
199 struct generic_pm_domain
*genpd
);
200 int of_genpd_add_provider_onecell(struct device_node
*np
,
201 struct genpd_onecell_data
*data
);
202 void of_genpd_del_provider(struct device_node
*np
);
203 extern int of_genpd_add_device(struct of_phandle_args
*args
,
205 extern int of_genpd_add_subdomain(struct of_phandle_args
*parent
,
206 struct of_phandle_args
*new_subdomain
);
207 extern struct generic_pm_domain
*of_genpd_remove_last(struct device_node
*np
);
209 int genpd_dev_pm_attach(struct device
*dev
);
210 #else /* !CONFIG_PM_GENERIC_DOMAINS_OF */
211 static inline int of_genpd_add_provider_simple(struct device_node
*np
,
212 struct generic_pm_domain
*genpd
)
217 static inline int of_genpd_add_provider_onecell(struct device_node
*np
,
218 struct genpd_onecell_data
*data
)
223 static inline void of_genpd_del_provider(struct device_node
*np
) {}
225 static inline int of_genpd_add_device(struct of_phandle_args
*args
,
231 static inline int of_genpd_add_subdomain(struct of_phandle_args
*parent
,
232 struct of_phandle_args
*new_subdomain
)
237 static inline int genpd_dev_pm_attach(struct device
*dev
)
243 struct generic_pm_domain
*of_genpd_remove_last(struct device_node
*np
)
245 return ERR_PTR(-ENOTSUPP
);
247 #endif /* CONFIG_PM_GENERIC_DOMAINS_OF */
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 */