blob: feb80af4cc1b5cb1e78b3dd9e21e02db37d5b6b0 [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 */
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +020017 GPD_STATE_REPEAT, /* Power off in progress, to be repeated */
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +020018 GPD_STATE_POWER_OFF, /* PM domain is off */
19};
Rafael J. Wysocki596ba342011-07-01 22:13:19 +020020
Rafael J. Wysockif7218892011-07-01 22:12:45 +020021struct dev_power_governor {
22 bool (*power_down_ok)(struct dev_pm_domain *domain);
23};
24
25struct generic_pm_domain {
26 struct dev_pm_domain domain; /* PM domain operations */
27 struct list_head sd_node; /* Node in the parent's subdomain list */
28 struct generic_pm_domain *parent; /* Parent PM domain */
29 struct list_head sd_list; /* List of dubdomains */
30 struct list_head dev_list; /* List of devices */
31 struct mutex lock;
32 struct dev_power_governor *gov;
33 struct work_struct power_off_work;
34 unsigned int in_progress; /* Number of devices being suspended now */
35 unsigned int sd_count; /* Number of subdomains with power "on" */
Rafael J. Wysocki17b75ec2011-07-12 00:39:29 +020036 enum gpd_status status; /* Current state of the domain */
37 wait_queue_head_t status_wait_queue;
Rafael J. Wysockic6d22b32011-07-12 00:39:36 +020038 struct task_struct *poweroff_task; /* Powering off task */
39 unsigned int resume_count; /* Number of devices being resumed */
Rafael J. Wysocki596ba342011-07-01 22:13:19 +020040 unsigned int device_count; /* Number of devices */
41 unsigned int suspended_count; /* System suspend device counter */
42 unsigned int prepared_count; /* Suspend counter of prepared devices */
43 bool suspend_power_off; /* Power status before system suspend */
Rafael J. Wysockif7218892011-07-01 22:12:45 +020044 int (*power_off)(struct generic_pm_domain *domain);
45 int (*power_on)(struct generic_pm_domain *domain);
46 int (*start_device)(struct device *dev);
47 int (*stop_device)(struct device *dev);
Rafael J. Wysockid4f2d872011-07-01 22:13:29 +020048 bool (*active_wakeup)(struct device *dev);
Rafael J. Wysockif7218892011-07-01 22:12:45 +020049};
50
Rafael J. Wysocki596ba342011-07-01 22:13:19 +020051static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd)
52{
53 return container_of(pd, struct generic_pm_domain, domain);
54}
55
Rafael J. Wysockif7218892011-07-01 22:12:45 +020056struct dev_list_entry {
57 struct list_head node;
58 struct device *dev;
59 bool need_restore;
60};
61
62#ifdef CONFIG_PM_GENERIC_DOMAINS
63extern int pm_genpd_add_device(struct generic_pm_domain *genpd,
64 struct device *dev);
65extern int pm_genpd_remove_device(struct generic_pm_domain *genpd,
66 struct device *dev);
67extern int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
68 struct generic_pm_domain *new_subdomain);
69extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
70 struct generic_pm_domain *target);
71extern void pm_genpd_init(struct generic_pm_domain *genpd,
72 struct dev_power_governor *gov, bool is_off);
Magnus Damm18b4f3f2011-07-10 10:39:14 +020073extern int pm_genpd_poweron(struct generic_pm_domain *genpd);
Rafael J. Wysockif7218892011-07-01 22:12:45 +020074#else
75static inline int pm_genpd_add_device(struct generic_pm_domain *genpd,
76 struct device *dev)
77{
78 return -ENOSYS;
79}
80static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd,
81 struct device *dev)
82{
83 return -ENOSYS;
84}
85static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd,
86 struct generic_pm_domain *new_sd)
87{
88 return -ENOSYS;
89}
90static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd,
91 struct generic_pm_domain *target)
92{
93 return -ENOSYS;
94}
95static inline void pm_genpd_init(struct generic_pm_domain *genpd,
96 struct dev_power_governor *gov, bool is_off) {}
Magnus Damm18b4f3f2011-07-10 10:39:14 +020097static inline int pm_genpd_poweron(struct generic_pm_domain *genpd)
98{
99 return -ENOSYS;
100}
Rafael J. Wysockif7218892011-07-01 22:12:45 +0200101#endif
102
103#endif /* _LINUX_PM_DOMAIN_H */