blob: fb809b9048919eb54e246043fb4747e32e9216d4 [file] [log] [blame]
Rafael J. Wysockif7218892011-07-01 22:12:45 +02001/*
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>
Guennadi Liakhovetski4f042cd2011-12-01 00:05:31 +010013#include <linux/err.h>
Rafael J. Wysockif7218892011-07-01 22:12:45 +020014
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +020015enum gpd_status {
16 GPD_STATE_ACTIVE = 0, /* PM domain is active */
Rafael J. Wysocki17877eb2011-08-08 23:43:50 +020017 GPD_STATE_WAIT_MASTER, /* PM domain's master is being waited for */
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +020018 GPD_STATE_BUSY, /* Something is happening to the PM domain */
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +020019 GPD_STATE_REPEAT, /* Power off in progress, to be repeated */
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +020020 GPD_STATE_POWER_OFF, /* PM domain is off */
21};
Rafael J. Wysocki596ba342011-07-01 22:13:19 +020022
Rafael J. Wysockif7218892011-07-01 22:12:45 +020023struct dev_power_governor {
24 bool (*power_down_ok)(struct dev_pm_domain *domain);
Rafael J. Wysockib02c9992011-12-01 00:02:05 +010025 bool (*stop_ok)(struct device *dev);
Rafael J. Wysockif7218892011-07-01 22:12:45 +020026};
27
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +010028struct gpd_dev_ops {
29 int (*start)(struct device *dev);
30 int (*stop)(struct device *dev);
Rafael J. Wysockiecf00472011-11-27 13:11:44 +010031 int (*save_state)(struct device *dev);
32 int (*restore_state)(struct device *dev);
Rafael J. Wysockid23b9b02011-11-27 13:11:51 +010033 int (*suspend)(struct device *dev);
34 int (*suspend_late)(struct device *dev);
35 int (*resume_early)(struct device *dev);
36 int (*resume)(struct device *dev);
37 int (*freeze)(struct device *dev);
38 int (*freeze_late)(struct device *dev);
39 int (*thaw_early)(struct device *dev);
40 int (*thaw)(struct device *dev);
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +010041 bool (*active_wakeup)(struct device *dev);
42};
43
Rafael J. Wysockif7218892011-07-01 22:12:45 +020044struct generic_pm_domain {
45 struct dev_pm_domain domain; /* PM domain operations */
Rafael J. Wysocki5125bbf2011-07-13 12:31:52 +020046 struct list_head gpd_list_node; /* Node in the global PM domains list */
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +020047 struct list_head master_links; /* Links with PM domain as a master */
48 struct list_head slave_links; /* Links with PM domain as a slave */
Rafael J. Wysockif7218892011-07-01 22:12:45 +020049 struct list_head dev_list; /* List of devices */
50 struct mutex lock;
51 struct dev_power_governor *gov;
52 struct work_struct power_off_work;
Rafael J. Wysockie84b2c22011-12-06 22:19:54 +010053 char *name;
Rafael J. Wysockif7218892011-07-01 22:12:45 +020054 unsigned int in_progress; /* Number of devices being suspended now */
Rafael J. Wysockic4bb3162011-08-08 23:43:04 +020055 atomic_t sd_count; /* Number of subdomains with power "on" */
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +020056 enum gpd_status status; /* Current state of the domain */
57 wait_queue_head_t status_wait_queue;
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +020058 struct task_struct *poweroff_task; /* Powering off task */
59 unsigned int resume_count; /* Number of devices being resumed */
Rafael J. Wysocki596ba342011-07-01 22:13:19 +020060 unsigned int device_count; /* Number of devices */
61 unsigned int suspended_count; /* System suspend device counter */
62 unsigned int prepared_count; /* Suspend counter of prepared devices */
63 bool suspend_power_off; /* Power status before system suspend */
Rafael J. Wysocki0aa2a222011-08-25 15:37:04 +020064 bool dev_irq_safe; /* Device callbacks are IRQ-safe */
Rafael J. Wysockif7218892011-07-01 22:12:45 +020065 int (*power_off)(struct generic_pm_domain *domain);
Rafael J. Wysocki221e9b52011-12-01 00:02:10 +010066 s64 power_off_latency_ns;
Rafael J. Wysockif7218892011-07-01 22:12:45 +020067 int (*power_on)(struct generic_pm_domain *domain);
Rafael J. Wysocki221e9b52011-12-01 00:02:10 +010068 s64 power_on_latency_ns;
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +010069 struct gpd_dev_ops dev_ops;
Rafael J. Wysocki221e9b52011-12-01 00:02:10 +010070 s64 break_even_ns; /* Power break even for the entire domain. */
71 s64 max_off_time_ns; /* Maximum allowed "suspended" time. */
72 ktime_t power_off_time;
Rafael J. Wysockif7218892011-07-01 22:12:45 +020073};
74
Rafael J. Wysocki596ba342011-07-01 22:13:19 +020075static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd)
76{
77 return container_of(pd, struct generic_pm_domain, domain);
78}
79
Rafael J. Wysocki5063ce12011-08-08 23:43:40 +020080struct gpd_link {
81 struct generic_pm_domain *master;
82 struct list_head master_node;
83 struct generic_pm_domain *slave;
84 struct list_head slave_node;
85};
86
Rafael J. Wysockib02c9992011-12-01 00:02:05 +010087struct gpd_timing_data {
88 s64 stop_latency_ns;
89 s64 start_latency_ns;
Rafael J. Wysocki221e9b52011-12-01 00:02:10 +010090 s64 save_state_latency_ns;
91 s64 restore_state_latency_ns;
Rafael J. Wysockib02c9992011-12-01 00:02:05 +010092 s64 break_even_ns;
93};
94
Rafael J. Wysockicd0ea672011-09-26 20:22:02 +020095struct generic_pm_domain_data {
96 struct pm_domain_data base;
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +010097 struct gpd_dev_ops ops;
Rafael J. Wysockib02c9992011-12-01 00:02:05 +010098 struct gpd_timing_data td;
Rafael J. Wysockicd0ea672011-09-26 20:22:02 +020099 bool need_restore;
100};
101
102static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd)
103{
104 return container_of(pdd, struct generic_pm_domain_data, base);
105}
106
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200107#ifdef CONFIG_PM_GENERIC_DOMAINS
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100108static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
109{
110 return to_gpd_data(dev->power.subsys_data->domain_data);
111}
112
Rafael J. Wysockib02c9992011-12-01 00:02:05 +0100113extern struct dev_power_governor simple_qos_governor;
114
115extern struct generic_pm_domain *dev_to_genpd(struct device *dev);
116extern int __pm_genpd_add_device(struct generic_pm_domain *genpd,
117 struct device *dev,
118 struct gpd_timing_data *td);
119
120static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
121 struct device *dev)
122{
123 return __pm_genpd_add_device(genpd, dev, NULL);
124}
125
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200126extern int pm_genpd_remove_device(struct generic_pm_domain *genpd,
127 struct device *dev);
128extern int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
129 struct generic_pm_domain *new_subdomain);
130extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
131 struct generic_pm_domain *target);
Rafael J. Wysockib02c9992011-12-01 00:02:05 +0100132extern int pm_genpd_add_callbacks(struct device *dev,
133 struct gpd_dev_ops *ops,
134 struct gpd_timing_data *td);
135extern int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td);
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200136extern void pm_genpd_init(struct generic_pm_domain *genpd,
137 struct dev_power_governor *gov, bool is_off);
Rafael J. Wysockib02c9992011-12-01 00:02:05 +0100138
Magnus Damm18b4f3f2011-07-10 10:39:14 +0200139extern int pm_genpd_poweron(struct generic_pm_domain *genpd);
Rafael J. Wysockib02c9992011-12-01 00:02:05 +0100140
141extern bool default_stop_ok(struct device *dev);
142
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200143#else
Rafael J. Wysockib02c9992011-12-01 00:02:05 +0100144
145static inline struct generic_pm_domain *dev_to_genpd(struct device *dev)
146{
147 return ERR_PTR(-ENOSYS);
148}
149static inline int __pm_genpd_add_device(struct generic_pm_domain *genpd,
150 struct device *dev,
151 struct gpd_timing_data *td)
152{
153 return -ENOSYS;
154}
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200155static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
156 struct device *dev)
157{
158 return -ENOSYS;
159}
160static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd,
161 struct device *dev)
162{
163 return -ENOSYS;
164}
165static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
166 struct generic_pm_domain *new_sd)
167{
168 return -ENOSYS;
169}
170static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
171 struct generic_pm_domain *target)
172{
173 return -ENOSYS;
174}
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100175static inline int pm_genpd_add_callbacks(struct device *dev,
Rafael J. Wysockib02c9992011-12-01 00:02:05 +0100176 struct gpd_dev_ops *ops,
177 struct gpd_timing_data *td)
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100178{
179 return -ENOSYS;
180}
Rafael J. Wysockib02c9992011-12-01 00:02:05 +0100181static inline int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
Rafael J. Wysockid5e4cbf2011-11-27 13:11:36 +0100182{
183 return -ENOSYS;
184}
Rafael J. Wysockib02c9992011-12-01 00:02:05 +0100185static inline void pm_genpd_init(struct generic_pm_domain *genpd, bool is_off)
186{
187}
Magnus Damm18b4f3f2011-07-10 10:39:14 +0200188static inline int pm_genpd_poweron(struct generic_pm_domain *genpd)
189{
190 return -ENOSYS;
191}
Rafael J. Wysockib02c9992011-12-01 00:02:05 +0100192static inline bool default_stop_ok(struct device *dev)
193{
194 return false;
195}
Rafael J. Wysocki17f2ae72011-08-14 13:34:31 +0200196#endif
197
Rafael J. Wysockib02c9992011-12-01 00:02:05 +0100198static inline int pm_genpd_remove_callbacks(struct device *dev)
199{
200 return __pm_genpd_remove_callbacks(dev, true);
201}
202
Rafael J. Wysocki17f2ae72011-08-14 13:34:31 +0200203#ifdef CONFIG_PM_GENERIC_DOMAINS_RUNTIME
204extern void genpd_queue_power_off_work(struct generic_pm_domain *genpd);
205extern void pm_genpd_poweroff_unused(void);
206#else
Rafael J. Wysocki0bc5b2d2011-07-14 20:59:07 +0200207static inline void genpd_queue_power_off_work(struct generic_pm_domain *gpd) {}
Rafael J. Wysocki17f2ae72011-08-14 13:34:31 +0200208static inline void pm_genpd_poweroff_unused(void) {}
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200209#endif
210
211#endif /* _LINUX_PM_DOMAIN_H */