blob: c71457cb8a7905ffb6c83defbed886eddf0a062f [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>
13
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +020014enum gpd_status {
15 GPD_STATE_ACTIVE = 0, /* PM domain is active */
16 GPD_STATE_BUSY, /* Something is happening to the PM domain */
17 GPD_STATE_POWER_OFF, /* PM domain is off */
18};
Rafael J. Wysocki596ba342011-07-01 22:13:19 +020019
Rafael J. Wysockif7218892011-07-01 22:12:45 +020020struct dev_power_governor {
21 bool (*power_down_ok)(struct dev_pm_domain *domain);
22};
23
24struct generic_pm_domain {
25 struct dev_pm_domain domain; /* PM domain operations */
26 struct list_head sd_node; /* Node in the parent's subdomain list */
27 struct generic_pm_domain *parent; /* Parent PM domain */
28 struct list_head sd_list; /* List of dubdomains */
29 struct list_head dev_list; /* List of devices */
30 struct mutex lock;
31 struct dev_power_governor *gov;
32 struct work_struct power_off_work;
33 unsigned int in_progress; /* Number of devices being suspended now */
34 unsigned int sd_count; /* Number of subdomains with power "on" */
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +020035 enum gpd_status status; /* Current state of the domain */
36 wait_queue_head_t status_wait_queue;
Rafael J. Wysocki596ba342011-07-01 22:13:19 +020037 unsigned int device_count; /* Number of devices */
38 unsigned int suspended_count; /* System suspend device counter */
39 unsigned int prepared_count; /* Suspend counter of prepared devices */
40 bool suspend_power_off; /* Power status before system suspend */
Rafael J. Wysockif7218892011-07-01 22:12:45 +020041 int (*power_off)(struct generic_pm_domain *domain);
42 int (*power_on)(struct generic_pm_domain *domain);
43 int (*start_device)(struct device *dev);
44 int (*stop_device)(struct device *dev);
Rafael J. Wysockid4f2d872011-07-01 22:13:29 +020045 bool (*active_wakeup)(struct device *dev);
Rafael J. Wysockif7218892011-07-01 22:12:45 +020046};
47
Rafael J. Wysocki596ba342011-07-01 22:13:19 +020048static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd)
49{
50 return container_of(pd, struct generic_pm_domain, domain);
51}
52
Rafael J. Wysockif7218892011-07-01 22:12:45 +020053struct dev_list_entry {
54 struct list_head node;
55 struct device *dev;
56 bool need_restore;
57};
58
59#ifdef CONFIG_PM_GENERIC_DOMAINS
60extern int pm_genpd_add_device(struct generic_pm_domain *genpd,
61 struct device *dev);
62extern int pm_genpd_remove_device(struct generic_pm_domain *genpd,
63 struct device *dev);
64extern int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
65 struct generic_pm_domain *new_subdomain);
66extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
67 struct generic_pm_domain *target);
68extern void pm_genpd_init(struct generic_pm_domain *genpd,
69 struct dev_power_governor *gov, bool is_off);
Magnus Damm18b4f3f2011-07-10 10:39:14 +020070extern int pm_genpd_poweron(struct generic_pm_domain *genpd);
Rafael J. Wysockif7218892011-07-01 22:12:45 +020071#else
72static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
73 struct device *dev)
74{
75 return -ENOSYS;
76}
77static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd,
78 struct device *dev)
79{
80 return -ENOSYS;
81}
82static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
83 struct generic_pm_domain *new_sd)
84{
85 return -ENOSYS;
86}
87static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
88 struct generic_pm_domain *target)
89{
90 return -ENOSYS;
91}
92static inline void pm_genpd_init(struct generic_pm_domain *genpd,
93 struct dev_power_governor *gov, bool is_off) {}
Magnus Damm18b4f3f2011-07-10 10:39:14 +020094static inline int pm_genpd_poweron(struct generic_pm_domain *genpd)
95{
96 return -ENOSYS;
97}
Rafael J. Wysockif7218892011-07-01 22:12:45 +020098#endif
99
100#endif /* _LINUX_PM_DOMAIN_H */