Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 1 | /* |
| 2 | * pm_runtime.h - Device run-time power management helper functions. |
| 3 | * |
| 4 | * Copyright (C) 2009 Rafael J. Wysocki <rjw@sisk.pl> |
| 5 | * |
| 6 | * This file is released under the GPLv2. |
| 7 | */ |
| 8 | |
| 9 | #ifndef _LINUX_PM_RUNTIME_H |
| 10 | #define _LINUX_PM_RUNTIME_H |
| 11 | |
| 12 | #include <linux/device.h> |
| 13 | #include <linux/pm.h> |
| 14 | |
Alan Stern | 3f9af05 | 2010-09-25 23:34:54 +0200 | [diff] [blame] | 15 | /* Runtime PM flag argument bits */ |
| 16 | #define RPM_ASYNC 0x01 /* Request is asynchronous */ |
| 17 | #define RPM_NOWAIT 0x02 /* Don't wait for concurrent |
| 18 | state change */ |
Alan Stern | 140a6c9 | 2010-09-25 23:35:07 +0200 | [diff] [blame^] | 19 | #define RPM_GET_PUT 0x04 /* Increment/decrement the |
| 20 | usage_count */ |
Alan Stern | 3f9af05 | 2010-09-25 23:34:54 +0200 | [diff] [blame] | 21 | |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 22 | #ifdef CONFIG_PM_RUNTIME |
| 23 | |
| 24 | extern struct workqueue_struct *pm_wq; |
| 25 | |
Alan Stern | 140a6c9 | 2010-09-25 23:35:07 +0200 | [diff] [blame^] | 26 | extern int __pm_runtime_idle(struct device *dev, int rpmflags); |
| 27 | extern int __pm_runtime_suspend(struct device *dev, int rpmflags); |
| 28 | extern int __pm_runtime_resume(struct device *dev, int rpmflags); |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 29 | extern int pm_schedule_suspend(struct device *dev, unsigned int delay); |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 30 | extern int __pm_runtime_set_status(struct device *dev, unsigned int status); |
| 31 | extern int pm_runtime_barrier(struct device *dev); |
| 32 | extern void pm_runtime_enable(struct device *dev); |
| 33 | extern void __pm_runtime_disable(struct device *dev, bool check_resume); |
Rafael J. Wysocki | 5382363 | 2010-01-23 22:02:51 +0100 | [diff] [blame] | 34 | extern void pm_runtime_allow(struct device *dev); |
| 35 | extern void pm_runtime_forbid(struct device *dev); |
Rafael J. Wysocki | 2f60ba7 | 2010-05-10 23:09:30 +0200 | [diff] [blame] | 36 | extern int pm_generic_runtime_idle(struct device *dev); |
| 37 | extern int pm_generic_runtime_suspend(struct device *dev); |
| 38 | extern int pm_generic_runtime_resume(struct device *dev); |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 39 | |
| 40 | static inline bool pm_children_suspended(struct device *dev) |
| 41 | { |
| 42 | return dev->power.ignore_children |
| 43 | || !atomic_read(&dev->power.child_count); |
| 44 | } |
| 45 | |
| 46 | static inline void pm_suspend_ignore_children(struct device *dev, bool enable) |
| 47 | { |
| 48 | dev->power.ignore_children = enable; |
| 49 | } |
| 50 | |
| 51 | static inline void pm_runtime_get_noresume(struct device *dev) |
| 52 | { |
| 53 | atomic_inc(&dev->power.usage_count); |
| 54 | } |
| 55 | |
| 56 | static inline void pm_runtime_put_noidle(struct device *dev) |
| 57 | { |
| 58 | atomic_add_unless(&dev->power.usage_count, -1, 0); |
| 59 | } |
| 60 | |
Rafael J. Wysocki | 7a1a8eb | 2009-12-03 21:19:18 +0100 | [diff] [blame] | 61 | static inline bool device_run_wake(struct device *dev) |
| 62 | { |
| 63 | return dev->power.run_wake; |
| 64 | } |
| 65 | |
| 66 | static inline void device_set_run_wake(struct device *dev, bool enable) |
| 67 | { |
| 68 | dev->power.run_wake = enable; |
| 69 | } |
| 70 | |
Rafael J. Wysocki | d690b2c | 2010-03-06 21:28:37 +0100 | [diff] [blame] | 71 | static inline bool pm_runtime_suspended(struct device *dev) |
| 72 | { |
| 73 | return dev->power.runtime_status == RPM_SUSPENDED; |
| 74 | } |
| 75 | |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 76 | #else /* !CONFIG_PM_RUNTIME */ |
| 77 | |
Alan Stern | 140a6c9 | 2010-09-25 23:35:07 +0200 | [diff] [blame^] | 78 | static inline int __pm_runtime_idle(struct device *dev, int rpmflags) |
| 79 | { |
| 80 | return -ENOSYS; |
| 81 | } |
| 82 | static inline int __pm_runtime_suspend(struct device *dev, int rpmflags) |
| 83 | { |
| 84 | return -ENOSYS; |
| 85 | } |
| 86 | static inline int __pm_runtime_resume(struct device *dev, int rpmflags) |
| 87 | { |
| 88 | return 1; |
| 89 | } |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 90 | static inline int pm_schedule_suspend(struct device *dev, unsigned int delay) |
| 91 | { |
| 92 | return -ENOSYS; |
| 93 | } |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 94 | static inline int __pm_runtime_set_status(struct device *dev, |
| 95 | unsigned int status) { return 0; } |
| 96 | static inline int pm_runtime_barrier(struct device *dev) { return 0; } |
| 97 | static inline void pm_runtime_enable(struct device *dev) {} |
| 98 | static inline void __pm_runtime_disable(struct device *dev, bool c) {} |
Rafael J. Wysocki | 5382363 | 2010-01-23 22:02:51 +0100 | [diff] [blame] | 99 | static inline void pm_runtime_allow(struct device *dev) {} |
| 100 | static inline void pm_runtime_forbid(struct device *dev) {} |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 101 | |
| 102 | static inline bool pm_children_suspended(struct device *dev) { return false; } |
| 103 | static inline void pm_suspend_ignore_children(struct device *dev, bool en) {} |
| 104 | static inline void pm_runtime_get_noresume(struct device *dev) {} |
| 105 | static inline void pm_runtime_put_noidle(struct device *dev) {} |
Rafael J. Wysocki | 7a1a8eb | 2009-12-03 21:19:18 +0100 | [diff] [blame] | 106 | static inline bool device_run_wake(struct device *dev) { return false; } |
| 107 | static inline void device_set_run_wake(struct device *dev, bool enable) {} |
Rafael J. Wysocki | d690b2c | 2010-03-06 21:28:37 +0100 | [diff] [blame] | 108 | static inline bool pm_runtime_suspended(struct device *dev) { return false; } |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 109 | |
Rafael J. Wysocki | 2f60ba7 | 2010-05-10 23:09:30 +0200 | [diff] [blame] | 110 | static inline int pm_generic_runtime_idle(struct device *dev) { return 0; } |
| 111 | static inline int pm_generic_runtime_suspend(struct device *dev) { return 0; } |
| 112 | static inline int pm_generic_runtime_resume(struct device *dev) { return 0; } |
| 113 | |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 114 | #endif /* !CONFIG_PM_RUNTIME */ |
| 115 | |
Alan Stern | 140a6c9 | 2010-09-25 23:35:07 +0200 | [diff] [blame^] | 116 | static inline int pm_runtime_idle(struct device *dev) |
| 117 | { |
| 118 | return __pm_runtime_idle(dev, 0); |
| 119 | } |
| 120 | |
| 121 | static inline int pm_runtime_suspend(struct device *dev) |
| 122 | { |
| 123 | return __pm_runtime_suspend(dev, 0); |
| 124 | } |
| 125 | |
| 126 | static inline int pm_runtime_resume(struct device *dev) |
| 127 | { |
| 128 | return __pm_runtime_resume(dev, 0); |
| 129 | } |
| 130 | |
| 131 | static inline int pm_request_idle(struct device *dev) |
| 132 | { |
| 133 | return __pm_runtime_idle(dev, RPM_ASYNC); |
| 134 | } |
| 135 | |
| 136 | static inline int pm_request_resume(struct device *dev) |
| 137 | { |
| 138 | return __pm_runtime_resume(dev, RPM_ASYNC); |
| 139 | } |
| 140 | |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 141 | static inline int pm_runtime_get(struct device *dev) |
| 142 | { |
Alan Stern | 140a6c9 | 2010-09-25 23:35:07 +0200 | [diff] [blame^] | 143 | return __pm_runtime_resume(dev, RPM_GET_PUT | RPM_ASYNC); |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | static inline int pm_runtime_get_sync(struct device *dev) |
| 147 | { |
Alan Stern | 140a6c9 | 2010-09-25 23:35:07 +0200 | [diff] [blame^] | 148 | return __pm_runtime_resume(dev, RPM_GET_PUT); |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static inline int pm_runtime_put(struct device *dev) |
| 152 | { |
Alan Stern | 140a6c9 | 2010-09-25 23:35:07 +0200 | [diff] [blame^] | 153 | return __pm_runtime_idle(dev, RPM_GET_PUT | RPM_ASYNC); |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | static inline int pm_runtime_put_sync(struct device *dev) |
| 157 | { |
Alan Stern | 140a6c9 | 2010-09-25 23:35:07 +0200 | [diff] [blame^] | 158 | return __pm_runtime_idle(dev, RPM_GET_PUT); |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | static inline int pm_runtime_set_active(struct device *dev) |
| 162 | { |
| 163 | return __pm_runtime_set_status(dev, RPM_ACTIVE); |
| 164 | } |
| 165 | |
| 166 | static inline void pm_runtime_set_suspended(struct device *dev) |
| 167 | { |
| 168 | __pm_runtime_set_status(dev, RPM_SUSPENDED); |
| 169 | } |
| 170 | |
| 171 | static inline void pm_runtime_disable(struct device *dev) |
| 172 | { |
| 173 | __pm_runtime_disable(dev, true); |
| 174 | } |
| 175 | |
| 176 | #endif |