Rafael J. Wysocki | 1a9a915 | 2011-09-29 22:29:44 +0200 | [diff] [blame] | 1 | #include <linux/pm_qos.h> |
| 2 | |
Rafael J. Wysocki | e91c11b | 2012-08-06 01:44:28 +0200 | [diff] [blame] | 3 | static inline void device_pm_init_common(struct device *dev) |
| 4 | { |
Rafael J. Wysocki | bed2b42 | 2012-08-06 01:45:11 +0200 | [diff] [blame] | 5 | if (!dev->power.early_init) { |
| 6 | spin_lock_init(&dev->power.lock); |
Rafael J. Wysocki | 37530f2 | 2013-03-04 14:22:57 +0100 | [diff] [blame] | 7 | dev->power.qos = NULL; |
Rafael J. Wysocki | bed2b42 | 2012-08-06 01:45:11 +0200 | [diff] [blame] | 8 | dev->power.early_init = true; |
| 9 | } |
Rafael J. Wysocki | e91c11b | 2012-08-06 01:44:28 +0200 | [diff] [blame] | 10 | } |
| 11 | |
Rafael J. Wysocki | d30d819 | 2014-11-27 22:38:05 +0100 | [diff] [blame] | 12 | #ifdef CONFIG_PM |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 13 | |
Rafael J. Wysocki | bed2b42 | 2012-08-06 01:45:11 +0200 | [diff] [blame] | 14 | static inline void pm_runtime_early_init(struct device *dev) |
| 15 | { |
| 16 | dev->power.disable_depth = 1; |
| 17 | device_pm_init_common(dev); |
| 18 | } |
| 19 | |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 20 | extern void pm_runtime_init(struct device *dev); |
Ulf Hansson | 5de85b9d | 2015-11-18 11:48:39 +0100 | [diff] [blame^] | 21 | extern void pm_runtime_reinit(struct device *dev); |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 22 | extern void pm_runtime_remove(struct device *dev); |
| 23 | |
Tony Lindgren | 4990d4f | 2015-05-18 15:40:29 -0700 | [diff] [blame] | 24 | struct wake_irq { |
| 25 | struct device *dev; |
| 26 | int irq; |
| 27 | bool dedicated_irq:1; |
| 28 | }; |
| 29 | |
| 30 | extern void dev_pm_arm_wake_irq(struct wake_irq *wirq); |
| 31 | extern void dev_pm_disarm_wake_irq(struct wake_irq *wirq); |
| 32 | |
| 33 | #ifdef CONFIG_PM_SLEEP |
| 34 | |
| 35 | extern int device_wakeup_attach_irq(struct device *dev, |
| 36 | struct wake_irq *wakeirq); |
| 37 | extern void device_wakeup_detach_irq(struct device *dev); |
| 38 | extern void device_wakeup_arm_wake_irqs(void); |
| 39 | extern void device_wakeup_disarm_wake_irqs(void); |
| 40 | |
| 41 | #else |
| 42 | |
| 43 | static inline int |
| 44 | device_wakeup_attach_irq(struct device *dev, |
| 45 | struct wake_irq *wakeirq) |
| 46 | { |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | static inline void device_wakeup_detach_irq(struct device *dev) |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | static inline void device_wakeup_arm_wake_irqs(void) |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | static inline void device_wakeup_disarm_wake_irqs(void) |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | #endif /* CONFIG_PM_SLEEP */ |
| 63 | |
Rafael J. Wysocki | d30d819 | 2014-11-27 22:38:05 +0100 | [diff] [blame] | 64 | /* |
| 65 | * sysfs.c |
| 66 | */ |
| 67 | |
| 68 | extern int dpm_sysfs_add(struct device *dev); |
| 69 | extern void dpm_sysfs_remove(struct device *dev); |
| 70 | extern void rpm_sysfs_remove(struct device *dev); |
| 71 | extern int wakeup_sysfs_add(struct device *dev); |
| 72 | extern void wakeup_sysfs_remove(struct device *dev); |
| 73 | extern int pm_qos_sysfs_add_resume_latency(struct device *dev); |
| 74 | extern void pm_qos_sysfs_remove_resume_latency(struct device *dev); |
| 75 | extern int pm_qos_sysfs_add_flags(struct device *dev); |
| 76 | extern void pm_qos_sysfs_remove_flags(struct device *dev); |
Mika Westerberg | 13b2c4a | 2015-07-27 18:03:56 +0300 | [diff] [blame] | 77 | extern int pm_qos_sysfs_add_latency_tolerance(struct device *dev); |
| 78 | extern void pm_qos_sysfs_remove_latency_tolerance(struct device *dev); |
Rafael J. Wysocki | d30d819 | 2014-11-27 22:38:05 +0100 | [diff] [blame] | 79 | |
| 80 | #else /* CONFIG_PM */ |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 81 | |
Rafael J. Wysocki | bed2b42 | 2012-08-06 01:45:11 +0200 | [diff] [blame] | 82 | static inline void pm_runtime_early_init(struct device *dev) |
| 83 | { |
| 84 | device_pm_init_common(dev); |
| 85 | } |
| 86 | |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 87 | static inline void pm_runtime_init(struct device *dev) {} |
Ulf Hansson | 5de85b9d | 2015-11-18 11:48:39 +0100 | [diff] [blame^] | 88 | static inline void pm_runtime_reinit(struct device *dev) {} |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 89 | static inline void pm_runtime_remove(struct device *dev) {} |
| 90 | |
Rafael J. Wysocki | d30d819 | 2014-11-27 22:38:05 +0100 | [diff] [blame] | 91 | static inline int dpm_sysfs_add(struct device *dev) { return 0; } |
| 92 | static inline void dpm_sysfs_remove(struct device *dev) {} |
| 93 | static inline void rpm_sysfs_remove(struct device *dev) {} |
| 94 | static inline int wakeup_sysfs_add(struct device *dev) { return 0; } |
| 95 | static inline void wakeup_sysfs_remove(struct device *dev) {} |
| 96 | static inline int pm_qos_sysfs_add(struct device *dev) { return 0; } |
| 97 | static inline void pm_qos_sysfs_remove(struct device *dev) {} |
| 98 | |
Tony Lindgren | 4990d4f | 2015-05-18 15:40:29 -0700 | [diff] [blame] | 99 | static inline void dev_pm_arm_wake_irq(struct wake_irq *wirq) |
| 100 | { |
| 101 | } |
| 102 | |
| 103 | static inline void dev_pm_disarm_wake_irq(struct wake_irq *wirq) |
| 104 | { |
| 105 | } |
| 106 | |
Rafael J. Wysocki | d30d819 | 2014-11-27 22:38:05 +0100 | [diff] [blame] | 107 | #endif |
Alan Stern | 3b98aea | 2008-08-07 13:06:12 -0400 | [diff] [blame] | 108 | |
Rafael J. Wysocki | 296699d | 2007-07-29 23:27:18 +0200 | [diff] [blame] | 109 | #ifdef CONFIG_PM_SLEEP |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Rafael J. Wysocki | 0e06b4a | 2010-01-23 22:25:15 +0100 | [diff] [blame] | 111 | /* kernel/power/main.c */ |
| 112 | extern int pm_async_enabled; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | |
Rafael J. Wysocki | 0e06b4a | 2010-01-23 22:25:15 +0100 | [diff] [blame] | 114 | /* drivers/base/power/main.c */ |
Rafael J. Wysocki | 1eede07 | 2008-05-20 23:00:01 +0200 | [diff] [blame] | 115 | extern struct list_head dpm_list; /* The active device list */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Daniel Drake | dec13c1 | 2007-11-21 14:55:18 -0800 | [diff] [blame] | 117 | static inline struct device *to_device(struct list_head *entry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
Alan Stern | cd59abf | 2007-09-21 15:36:56 -0400 | [diff] [blame] | 119 | return container_of(entry, struct device, power.entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | |
Rafael J. Wysocki | e91c11b | 2012-08-06 01:44:28 +0200 | [diff] [blame] | 122 | extern void device_pm_sleep_init(struct device *dev); |
Alan Stern | 3b98aea | 2008-08-07 13:06:12 -0400 | [diff] [blame] | 123 | extern void device_pm_add(struct device *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | extern void device_pm_remove(struct device *); |
Cornelia Huck | ffa6a70 | 2009-03-04 12:44:00 +0100 | [diff] [blame] | 125 | extern void device_pm_move_before(struct device *, struct device *); |
| 126 | extern void device_pm_move_after(struct device *, struct device *); |
| 127 | extern void device_pm_move_last(struct device *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 129 | #else /* !CONFIG_PM_SLEEP */ |
| 130 | |
Rafael J. Wysocki | e91c11b | 2012-08-06 01:44:28 +0200 | [diff] [blame] | 131 | static inline void device_pm_sleep_init(struct device *dev) {} |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 132 | |
Rafael J. Wysocki | 37530f2 | 2013-03-04 14:22:57 +0100 | [diff] [blame] | 133 | static inline void device_pm_add(struct device *dev) {} |
Rafael J. Wysocki | 1a9a915 | 2011-09-29 22:29:44 +0200 | [diff] [blame] | 134 | |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 135 | static inline void device_pm_remove(struct device *dev) |
| 136 | { |
| 137 | pm_runtime_remove(dev); |
| 138 | } |
Daniel Drake | dec13c1 | 2007-11-21 14:55:18 -0800 | [diff] [blame] | 139 | |
Cornelia Huck | ffa6a70 | 2009-03-04 12:44:00 +0100 | [diff] [blame] | 140 | static inline void device_pm_move_before(struct device *deva, |
| 141 | struct device *devb) {} |
| 142 | static inline void device_pm_move_after(struct device *deva, |
| 143 | struct device *devb) {} |
| 144 | static inline void device_pm_move_last(struct device *dev) {} |
Rafael J. Wysocki | 775b64d | 2008-01-12 20:40:46 +0100 | [diff] [blame] | 145 | |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 146 | #endif /* !CONFIG_PM_SLEEP */ |
Daniel Drake | dec13c1 | 2007-11-21 14:55:18 -0800 | [diff] [blame] | 147 | |
Rafael J. Wysocki | e91c11b | 2012-08-06 01:44:28 +0200 | [diff] [blame] | 148 | static inline void device_pm_init(struct device *dev) |
| 149 | { |
| 150 | device_pm_init_common(dev); |
| 151 | device_pm_sleep_init(dev); |
| 152 | pm_runtime_init(dev); |
| 153 | } |