blob: 97e3f8eb49783dc7240cde86f597f0cb4e9b8adf [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 */
Rafael J. Wysocki3f241772011-08-08 23:43:29 +020016 GPD_STATE_WAIT_PARENT, /* PM domain's parent is being waited for */
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +020017 GPD_STATE_BUSY, /* Something is happening to the PM domain */
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +020018 GPD_STATE_REPEAT, /* Power off in progress, to be repeated */
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +020019 GPD_STATE_POWER_OFF, /* PM domain is off */
20};
Rafael J. Wysocki596ba342011-07-01 22:13:19 +020021
Rafael J. Wysockif7218892011-07-01 22:12:45 +020022struct dev_power_governor {
23 bool (*power_down_ok)(struct dev_pm_domain *domain);
24};
25
26struct generic_pm_domain {
27 struct dev_pm_domain domain; /* PM domain operations */
Rafael J. Wysocki5125bbf2011-07-13 12:31:52 +020028 struct list_head gpd_list_node; /* Node in the global PM domains list */
Rafael J. Wysockif7218892011-07-01 22:12:45 +020029 struct list_head sd_node; /* Node in the parent's subdomain list */
30 struct generic_pm_domain *parent; /* Parent PM domain */
31 struct list_head sd_list; /* List of dubdomains */
32 struct list_head dev_list; /* List of devices */
33 struct mutex lock;
34 struct dev_power_governor *gov;
35 struct work_struct power_off_work;
36 unsigned int in_progress; /* Number of devices being suspended now */
Rafael J. Wysockic4bb3162011-08-08 23:43:04 +020037 atomic_t sd_count; /* Number of subdomains with power "on" */
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +020038 enum gpd_status status; /* Current state of the domain */
39 wait_queue_head_t status_wait_queue;
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +020040 struct task_struct *poweroff_task; /* Powering off task */
41 unsigned int resume_count; /* Number of devices being resumed */
Rafael J. Wysocki596ba342011-07-01 22:13:19 +020042 unsigned int device_count; /* Number of devices */
43 unsigned int suspended_count; /* System suspend device counter */
44 unsigned int prepared_count; /* Suspend counter of prepared devices */
45 bool suspend_power_off; /* Power status before system suspend */
Rafael J. Wysockif7218892011-07-01 22:12:45 +020046 int (*power_off)(struct generic_pm_domain *domain);
47 int (*power_on)(struct generic_pm_domain *domain);
48 int (*start_device)(struct device *dev);
49 int (*stop_device)(struct device *dev);
Rafael J. Wysockid4f2d872011-07-01 22:13:29 +020050 bool (*active_wakeup)(struct device *dev);
Rafael J. Wysockif7218892011-07-01 22:12:45 +020051};
52
Rafael J. Wysocki596ba342011-07-01 22:13:19 +020053static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd)
54{
55 return container_of(pd, struct generic_pm_domain, domain);
56}
57
Rafael J. Wysockif7218892011-07-01 22:12:45 +020058struct dev_list_entry {
59 struct list_head node;
60 struct device *dev;
61 bool need_restore;
62};
63
64#ifdef CONFIG_PM_GENERIC_DOMAINS
65extern int pm_genpd_add_device(struct generic_pm_domain *genpd,
66 struct device *dev);
67extern int pm_genpd_remove_device(struct generic_pm_domain *genpd,
68 struct device *dev);
69extern int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
70 struct generic_pm_domain *new_subdomain);
71extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
72 struct generic_pm_domain *target);
73extern void pm_genpd_init(struct generic_pm_domain *genpd,
74 struct dev_power_governor *gov, bool is_off);
Magnus Damm18b4f3f2011-07-10 10:39:14 +020075extern int pm_genpd_poweron(struct generic_pm_domain *genpd);
Rafael J. Wysockif7218892011-07-01 22:12:45 +020076#else
77static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
78 struct device *dev)
79{
80 return -ENOSYS;
81}
82static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd,
83 struct device *dev)
84{
85 return -ENOSYS;
86}
87static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
88 struct generic_pm_domain *new_sd)
89{
90 return -ENOSYS;
91}
92static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
93 struct generic_pm_domain *target)
94{
95 return -ENOSYS;
96}
97static inline void pm_genpd_init(struct generic_pm_domain *genpd,
98 struct dev_power_governor *gov, bool is_off) {}
Magnus Damm18b4f3f2011-07-10 10:39:14 +020099static inline int pm_genpd_poweron(struct generic_pm_domain *genpd)
100{
101 return -ENOSYS;
102}
Rafael J. Wysocki17f2ae72011-08-14 13:34:31 +0200103#endif
104
105#ifdef CONFIG_PM_GENERIC_DOMAINS_RUNTIME
106extern void genpd_queue_power_off_work(struct generic_pm_domain *genpd);
107extern void pm_genpd_poweroff_unused(void);
108#else
Rafael J. Wysocki0bc5b2d2011-07-14 20:59:07 +0200109static inline void genpd_queue_power_off_work(struct generic_pm_domain *gpd) {}
Rafael J. Wysocki17f2ae72011-08-14 13:34:31 +0200110static inline void pm_genpd_poweroff_unused(void) {}
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200111#endif
112
113#endif /* _LINUX_PM_DOMAIN_H */