Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 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 | |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 14 | enum gpd_status { |
| 15 | GPD_STATE_ACTIVE = 0, /* PM domain is active */ |
| 16 | GPD_STATE_BUSY, /* Something is happening to the PM domain */ |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 17 | GPD_STATE_REPEAT, /* Power off in progress, to be repeated */ |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 18 | GPD_STATE_POWER_OFF, /* PM domain is off */ |
| 19 | }; |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 20 | |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 21 | struct dev_power_governor { |
| 22 | bool (*power_down_ok)(struct dev_pm_domain *domain); |
| 23 | }; |
| 24 | |
| 25 | struct generic_pm_domain { |
| 26 | struct dev_pm_domain domain; /* PM domain operations */ |
Rafael J. Wysocki | 5125bbf | 2011-07-13 12:31:52 +0200 | [diff] [blame] | 27 | struct list_head gpd_list_node; /* Node in the global PM domains list */ |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 28 | struct list_head sd_node; /* Node in the parent's subdomain list */ |
| 29 | struct generic_pm_domain *parent; /* Parent PM domain */ |
| 30 | struct list_head sd_list; /* List of dubdomains */ |
| 31 | 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 */ |
| 36 | unsigned int sd_count; /* Number of subdomains with power "on" */ |
Rafael J. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 37 | enum gpd_status status; /* Current state of the domain */ |
| 38 | wait_queue_head_t status_wait_queue; |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame] | 39 | struct task_struct *poweroff_task; /* Powering off task */ |
| 40 | unsigned int resume_count; /* Number of devices being resumed */ |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 41 | 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. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 45 | int (*power_off)(struct generic_pm_domain *domain); |
| 46 | int (*power_on)(struct generic_pm_domain *domain); |
| 47 | int (*start_device)(struct device *dev); |
| 48 | int (*stop_device)(struct device *dev); |
Rafael J. Wysocki | d4f2d87 | 2011-07-01 22:13:29 +0200 | [diff] [blame] | 49 | bool (*active_wakeup)(struct device *dev); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 50 | }; |
| 51 | |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 52 | static inline struct generic_pm_domain *pd_to_genpd(struct dev_pm_domain *pd) |
| 53 | { |
| 54 | return container_of(pd, struct generic_pm_domain, domain); |
| 55 | } |
| 56 | |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 57 | struct dev_list_entry { |
| 58 | struct list_head node; |
| 59 | struct device *dev; |
| 60 | bool need_restore; |
| 61 | }; |
| 62 | |
| 63 | #ifdef CONFIG_PM_GENERIC_DOMAINS |
| 64 | extern int pm_genpd_add_device(struct generic_pm_domain *genpd, |
| 65 | struct device *dev); |
| 66 | extern int pm_genpd_remove_device(struct generic_pm_domain *genpd, |
| 67 | struct device *dev); |
| 68 | extern int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, |
| 69 | struct generic_pm_domain *new_subdomain); |
| 70 | extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, |
| 71 | struct generic_pm_domain *target); |
| 72 | extern void pm_genpd_init(struct generic_pm_domain *genpd, |
| 73 | struct dev_power_governor *gov, bool is_off); |
Magnus Damm | 18b4f3f | 2011-07-10 10:39:14 +0200 | [diff] [blame] | 74 | extern int pm_genpd_poweron(struct generic_pm_domain *genpd); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 75 | #else |
| 76 | static inline int pm_genpd_add_device(struct generic_pm_domain *genpd, |
| 77 | struct device *dev) |
| 78 | { |
| 79 | return -ENOSYS; |
| 80 | } |
| 81 | static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd, |
| 82 | struct device *dev) |
| 83 | { |
| 84 | return -ENOSYS; |
| 85 | } |
| 86 | static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, |
| 87 | struct generic_pm_domain *new_sd) |
| 88 | { |
| 89 | return -ENOSYS; |
| 90 | } |
| 91 | static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, |
| 92 | struct generic_pm_domain *target) |
| 93 | { |
| 94 | return -ENOSYS; |
| 95 | } |
| 96 | static inline void pm_genpd_init(struct generic_pm_domain *genpd, |
| 97 | struct dev_power_governor *gov, bool is_off) {} |
Magnus Damm | 18b4f3f | 2011-07-10 10:39:14 +0200 | [diff] [blame] | 98 | static inline int pm_genpd_poweron(struct generic_pm_domain *genpd) |
| 99 | { |
| 100 | return -ENOSYS; |
| 101 | } |
Rafael J. Wysocki | 17f2ae7 | 2011-08-14 13:34:31 +0200 | [diff] [blame^] | 102 | #endif |
| 103 | |
| 104 | #ifdef CONFIG_PM_GENERIC_DOMAINS_RUNTIME |
| 105 | extern void genpd_queue_power_off_work(struct generic_pm_domain *genpd); |
| 106 | extern void pm_genpd_poweroff_unused(void); |
| 107 | #else |
Rafael J. Wysocki | 0bc5b2d | 2011-07-14 20:59:07 +0200 | [diff] [blame] | 108 | static inline void genpd_queue_power_off_work(struct generic_pm_domain *gpd) {} |
Rafael J. Wysocki | 17f2ae7 | 2011-08-14 13:34:31 +0200 | [diff] [blame^] | 109 | static inline void pm_genpd_poweroff_unused(void) {} |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 110 | #endif |
| 111 | |
| 112 | #endif /* _LINUX_PM_DOMAIN_H */ |