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 */ |
| 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. Wysocki | 17b75ec | 2011-07-12 00:39:29 +0200 | [diff] [blame] | 36 | enum gpd_status status; /* Current state of the domain */ |
| 37 | wait_queue_head_t status_wait_queue; |
Rafael J. Wysocki | c6d22b3 | 2011-07-12 00:39:36 +0200 | [diff] [blame^] | 38 | struct task_struct *poweroff_task; /* Powering off task */ |
| 39 | unsigned int resume_count; /* Number of devices being resumed */ |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 40 | 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. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 44 | 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. Wysocki | d4f2d87 | 2011-07-01 22:13:29 +0200 | [diff] [blame] | 48 | bool (*active_wakeup)(struct device *dev); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 49 | }; |
| 50 | |
Rafael J. Wysocki | 596ba34 | 2011-07-01 22:13:19 +0200 | [diff] [blame] | 51 | static 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. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 56 | struct dev_list_entry { |
| 57 | struct list_head node; |
| 58 | struct device *dev; |
| 59 | bool need_restore; |
| 60 | }; |
| 61 | |
| 62 | #ifdef CONFIG_PM_GENERIC_DOMAINS |
| 63 | extern int pm_genpd_add_device(struct generic_pm_domain *genpd, |
| 64 | struct device *dev); |
| 65 | extern int pm_genpd_remove_device(struct generic_pm_domain *genpd, |
| 66 | struct device *dev); |
| 67 | extern int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, |
| 68 | struct generic_pm_domain *new_subdomain); |
| 69 | extern int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, |
| 70 | struct generic_pm_domain *target); |
| 71 | extern void pm_genpd_init(struct generic_pm_domain *genpd, |
| 72 | struct dev_power_governor *gov, bool is_off); |
Magnus Damm | 18b4f3f | 2011-07-10 10:39:14 +0200 | [diff] [blame] | 73 | extern int pm_genpd_poweron(struct generic_pm_domain *genpd); |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 74 | #else |
| 75 | static inline int pm_genpd_add_device(struct generic_pm_domain *genpd, |
| 76 | struct device *dev) |
| 77 | { |
| 78 | return -ENOSYS; |
| 79 | } |
| 80 | static inline int pm_genpd_remove_device(struct generic_pm_domain *genpd, |
| 81 | struct device *dev) |
| 82 | { |
| 83 | return -ENOSYS; |
| 84 | } |
| 85 | static inline int pm_genpd_add_subdomain(struct generic_pm_domain *genpd, |
| 86 | struct generic_pm_domain *new_sd) |
| 87 | { |
| 88 | return -ENOSYS; |
| 89 | } |
| 90 | static inline int pm_genpd_remove_subdomain(struct generic_pm_domain *genpd, |
| 91 | struct generic_pm_domain *target) |
| 92 | { |
| 93 | return -ENOSYS; |
| 94 | } |
| 95 | static inline void pm_genpd_init(struct generic_pm_domain *genpd, |
| 96 | struct dev_power_governor *gov, bool is_off) {} |
Magnus Damm | 18b4f3f | 2011-07-10 10:39:14 +0200 | [diff] [blame] | 97 | static inline int pm_genpd_poweron(struct generic_pm_domain *genpd) |
| 98 | { |
| 99 | return -ENOSYS; |
| 100 | } |
Rafael J. Wysocki | f721889 | 2011-07-01 22:12:45 +0200 | [diff] [blame] | 101 | #endif |
| 102 | |
| 103 | #endif /* _LINUX_PM_DOMAIN_H */ |