PM / Domains: Make it possible to use per-device domain callbacks
[linux-2.6.git] / include / linux / pm_domain.h
1 /*
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>
13
14 enum gpd_status {
15         GPD_STATE_ACTIVE = 0,   /* PM domain is active */
16         GPD_STATE_WAIT_MASTER,  /* PM domain's master is being waited for */
17         GPD_STATE_BUSY,         /* Something is happening to the PM domain */
18         GPD_STATE_REPEAT,       /* Power off in progress, to be repeated */
19         GPD_STATE_POWER_OFF,    /* PM domain is off */
20 };
21
22 struct dev_power_governor {
23         bool (*power_down_ok)(struct dev_pm_domain *domain);
24 };
25
26 struct gpd_dev_ops {
27         int (*start)(struct device *dev);
28         int (*stop)(struct device *dev);
29         bool (*active_wakeup)(struct device *dev);
30 };
31
32 struct generic_pm_domain {
33         struct dev_pm_domain domain;    /* PM domain operations */
34         struct list_head gpd_list_node; /* Node in the global PM domains list */
35         struct list_head master_links;  /* Links with PM domain as a master */
36         struct list_head slave_links;   /* Links with PM domain as a slave */
37         struct list_head dev_list;      /* List of devices */
38         struct mutex lock;
39         struct dev_power_governor *gov;
40         struct work_struct power_off_work;
41         unsigned int in_progress;       /* Number of devices being suspended now */
42         atomic_t sd_count;      /* Number of subdomains with power "on" */
43         enum gpd_status status; /* Current state of the domain */
44         wait_queue_head_t status_wait_queue;
45         struct task_struct *poweroff_task;      /* Powering off task */
46         unsigned int resume_count;      /* Number of devices being resumed */
47         unsigned int device_count;      /* Number of devices */
48         unsigned int suspended_count;   /* System suspend device counter */
49         unsigned int prepared_count;    /* Suspend counter of prepared devices */
50         bool suspend_power_off; /* Power status before system suspend */
51         bool dev_irq_safe;      /* Device callbacks are IRQ-safe */
52         int (*power_off)(struct generic_pm_domain *domain);
53         int (*power_on)(struct generic_pm_domain *domain);
54         struct gpd_dev_ops dev_ops;
55 };
56
57 static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd)
58 {
59         return container_of(pd, struct generic_pm_domain, domain);
60 }
61
62 struct gpd_link {
63         struct generic_pm_domain *master;
64         struct list_head master_node;
65         struct generic_pm_domain *slave;
66         struct list_head slave_node;
67 };
68
69 struct generic_pm_domain_data {
70         struct pm_domain_data base;
71         struct gpd_dev_ops ops;
72         bool need_restore;
73 };
74
75 static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd)
76 {
77         return container_of(pdd, struct generic_pm_domain_data, base);
78 }
79
80 #ifdef CONFIG_PM_GENERIC_DOMAINS
81 static inline struct generic_pm_domain_data *dev_gpd_data(struct device *dev)
82 {
83         return to_gpd_data(dev->power.subsys_data->domain_data);
84 }
85
86 extern int pm_genpd_add_device(struct generic_pm_domain *genpd,
87                                struct device *dev);
88 extern int pm_genpd_remove_device(struct generic_pm_domain *genpd,
89                                   struct device *dev);
90 extern int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
91                                   struct generic_pm_domain *new_subdomain);
92 extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
93                                      struct generic_pm_domain *target);
94 extern int pm_genpd_add_callbacks(struct device *dev, struct gpd_dev_ops *ops);
95 extern int pm_genpd_remove_callbacks(struct device *dev);
96 extern void pm_genpd_init(struct generic_pm_domain *genpd,
97                           struct dev_power_governor *gov, bool is_off);
98 extern int pm_genpd_poweron(struct generic_pm_domain *genpd);
99 #else
100 static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
101                                       struct device *dev)
102 {
103         return -ENOSYS;
104 }
105 static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd,
106                                          struct device *dev)
107 {
108         return -ENOSYS;
109 }
110 static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
111                                          struct generic_pm_domain *new_sd)
112 {
113         return -ENOSYS;
114 }
115 static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
116                                             struct generic_pm_domain *target)
117 {
118         return -ENOSYS;
119 }
120 static inline int pm_genpd_add_callbacks(struct device *dev,
121                                          struct gpd_dev_ops *ops)
122 {
123         return -ENOSYS;
124 }
125 static inline int pm_genpd_remove_callbacks(struct device *dev)
126 {
127         return -ENOSYS;
128 }
129 static inline void pm_genpd_init(struct generic_pm_domain *genpd,
130                                  struct dev_power_governor *gov, bool is_off) {}
131 static inline int pm_genpd_poweron(struct generic_pm_domain *genpd)
132 {
133         return -ENOSYS;
134 }
135 #endif
136
137 #ifdef CONFIG_PM_GENERIC_DOMAINS_RUNTIME
138 extern void genpd_queue_power_off_work(struct generic_pm_domain *genpd);
139 extern void pm_genpd_poweroff_unused(void);
140 #else
141 static inline void genpd_queue_power_off_work(struct generic_pm_domain *gpd) {}
142 static inline void pm_genpd_poweroff_unused(void) {}
143 #endif
144
145 #endif /* _LINUX_PM_DOMAIN_H */