blob: 65633e5a2bc023ba277c3c9e5db167678c0f046a [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. Wysocki17877eb2011-08-08 23:43:50 +020016 GPD_STATE_WAIT_MASTER, /* PM domain's master 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. Wysocki5063ce12011-08-08 23:43:40 +020029 struct list_head master_links; /* Links with PM domain as a master */
30 struct list_head slave_links; /* Links with PM domain as a slave */
Rafael J. Wysockif7218892011-07-01 22:12:45 +020031 struct list_head dev_list; /* List of devices */
32 struct mutex lock;
33 struct dev_power_governor *gov;
34 struct work_struct power_off_work;
35 unsigned int in_progress; /* Number of devices being suspended now */
Rafael J. Wysockic4bb3162011-08-08 23:43:04 +020036 atomic_t sd_count; /* Number of subdomains with power "on" */
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +020037 enum gpd_status status; /* Current state of the domain */
38 wait_queue_head_t status_wait_queue;
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +020039 struct task_struct *poweroff_task; /* Powering off task */
40 unsigned int resume_count; /* Number of devices being resumed */
Rafael J. Wysocki596ba342011-07-01 22:13:19 +020041 unsigned int device_count; /* Number of devices */
42 unsigned int suspended_count; /* System suspend device counter */
43 unsigned int prepared_count; /* Suspend counter of prepared devices */
44 bool suspend_power_off; /* Power status before system suspend */
Rafael J. Wysocki0aa2a222011-08-25 15:37:04 +020045 bool dev_irq_safe; /* Device callbacks are IRQ-safe */
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. Wysocki5063ce12011-08-08 23:43:40 +020058struct gpd_link {
59 struct generic_pm_domain *master;
60 struct list_head master_node;
61 struct generic_pm_domain *slave;
62 struct list_head slave_node;
63};
64
Rafael J. Wysockicd0ea672011-09-26 20:22:02 +020065struct generic_pm_domain_data {
66 struct pm_domain_data base;
67 bool need_restore;
68};
69
70static inline struct generic_pm_domain_data *to_gpd_data(struct pm_domain_data *pdd)
71{
72 return container_of(pdd, struct generic_pm_domain_data, base);
73}
74
Rafael J. Wysockif7218892011-07-01 22:12:45 +020075#ifdef CONFIG_PM_GENERIC_DOMAINS
76extern int pm_genpd_add_device(struct generic_pm_domain *genpd,
77 struct device *dev);
78extern int pm_genpd_remove_device(struct generic_pm_domain *genpd,
79 struct device *dev);
80extern int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
81 struct generic_pm_domain *new_subdomain);
82extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
83 struct generic_pm_domain *target);
84extern void pm_genpd_init(struct generic_pm_domain *genpd,
85 struct dev_power_governor *gov, bool is_off);
Magnus Damm18b4f3f2011-07-10 10:39:14 +020086extern int pm_genpd_poweron(struct generic_pm_domain *genpd);
Rafael J. Wysockif7218892011-07-01 22:12:45 +020087#else
88static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
89 struct device *dev)
90{
91 return -ENOSYS;
92}
93static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd,
94 struct device *dev)
95{
96 return -ENOSYS;
97}
98static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
99 struct generic_pm_domain *new_sd)
100{
101 return -ENOSYS;
102}
103static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
104 struct generic_pm_domain *target)
105{
106 return -ENOSYS;
107}
108static inline void pm_genpd_init(struct generic_pm_domain *genpd,
109 struct dev_power_governor *gov, bool is_off) {}
Magnus Damm18b4f3f2011-07-10 10:39:14 +0200110static inline int pm_genpd_poweron(struct generic_pm_domain *genpd)
111{
112 return -ENOSYS;
113}
Rafael J. Wysocki17f2ae72011-08-14 13:34:31 +0200114#endif
115
116#ifdef CONFIG_PM_GENERIC_DOMAINS_RUNTIME
117extern void genpd_queue_power_off_work(struct generic_pm_domain *genpd);
118extern void pm_genpd_poweroff_unused(void);
119#else
Rafael J. Wysocki0bc5b2d2011-07-14 20:59:07 +0200120static inline void genpd_queue_power_off_work(struct generic_pm_domain *gpd) {}
Rafael J. Wysocki17f2ae72011-08-14 13:34:31 +0200121static inline void pm_genpd_poweroff_unused(void) {}
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200122#endif
123
124#endif /* _LINUX_PM_DOMAIN_H */