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 */ |
| 19 | |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 20 | #ifdef CONFIG_PM_RUNTIME |
| 21 | |
| 22 | extern struct workqueue_struct *pm_wq; |
| 23 | |
| 24 | extern int pm_runtime_idle(struct device *dev); |
| 25 | extern int pm_runtime_suspend(struct device *dev); |
| 26 | extern int pm_runtime_resume(struct device *dev); |
| 27 | extern int pm_request_idle(struct device *dev); |
| 28 | extern int pm_schedule_suspend(struct device *dev, unsigned int delay); |
| 29 | extern int pm_request_resume(struct device *dev); |
Alan Stern | 3f9af05 | 2010-09-25 23:34:54 +0200 | [diff] [blame^] | 30 | extern int __pm_runtime_get(struct device *dev, int rpmflags); |
| 31 | extern int __pm_runtime_put(struct device *dev, int rpmflags); |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 32 | extern int __pm_runtime_set_status(struct device *dev, unsigned int status); |
| 33 | extern int pm_runtime_barrier(struct device *dev); |
| 34 | extern void pm_runtime_enable(struct device *dev); |
| 35 | extern void __pm_runtime_disable(struct device *dev, bool check_resume); |
Rafael J. Wysocki | 5382363 | 2010-01-23 22:02:51 +0100 | [diff] [blame] | 36 | extern void pm_runtime_allow(struct device *dev); |
| 37 | extern void pm_runtime_forbid(struct device *dev); |
Rafael J. Wysocki | 2f60ba7 | 2010-05-10 23:09:30 +0200 | [diff] [blame] | 38 | extern int pm_generic_runtime_idle(struct device *dev); |
| 39 | extern int pm_generic_runtime_suspend(struct device *dev); |
| 40 | extern int pm_generic_runtime_resume(struct device *dev); |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 41 | |
| 42 | static inline bool pm_children_suspended(struct device *dev) |
| 43 | { |
| 44 | return dev->power.ignore_children |
| 45 | || !atomic_read(&dev->power.child_count); |
| 46 | } |
| 47 | |
| 48 | static inline void pm_suspend_ignore_children(struct device *dev, bool enable) |
| 49 | { |
| 50 | dev->power.ignore_children = enable; |
| 51 | } |
| 52 | |
| 53 | static inline void pm_runtime_get_noresume(struct device *dev) |
| 54 | { |
| 55 | atomic_inc(&dev->power.usage_count); |
| 56 | } |
| 57 | |
| 58 | static inline void pm_runtime_put_noidle(struct device *dev) |
| 59 | { |
| 60 | atomic_add_unless(&dev->power.usage_count, -1, 0); |
| 61 | } |
| 62 | |
Rafael J. Wysocki | 7a1a8eb | 2009-12-03 21:19:18 +0100 | [diff] [blame] | 63 | static inline bool device_run_wake(struct device *dev) |
| 64 | { |
| 65 | return dev->power.run_wake; |
| 66 | } |
| 67 | |
| 68 | static inline void device_set_run_wake(struct device *dev, bool enable) |
| 69 | { |
| 70 | dev->power.run_wake = enable; |
| 71 | } |
| 72 | |
Rafael J. Wysocki | d690b2c | 2010-03-06 21:28:37 +0100 | [diff] [blame] | 73 | static inline bool pm_runtime_suspended(struct device *dev) |
| 74 | { |
| 75 | return dev->power.runtime_status == RPM_SUSPENDED; |
| 76 | } |
| 77 | |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 78 | #else /* !CONFIG_PM_RUNTIME */ |
| 79 | |
| 80 | static inline int pm_runtime_idle(struct device *dev) { return -ENOSYS; } |
| 81 | static inline int pm_runtime_suspend(struct device *dev) { return -ENOSYS; } |
| 82 | static inline int pm_runtime_resume(struct device *dev) { return 0; } |
| 83 | static inline int pm_request_idle(struct device *dev) { return -ENOSYS; } |
| 84 | static inline int pm_schedule_suspend(struct device *dev, unsigned int delay) |
| 85 | { |
| 86 | return -ENOSYS; |
| 87 | } |
| 88 | static inline int pm_request_resume(struct device *dev) { return 0; } |
Alan Stern | 3f9af05 | 2010-09-25 23:34:54 +0200 | [diff] [blame^] | 89 | static inline int __pm_runtime_get(struct device *dev, int rpmflags) |
| 90 | { return 1; } |
| 91 | static inline int __pm_runtime_put(struct device *dev, int rpmflags) |
| 92 | { return 0; } |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 93 | static inline int __pm_runtime_set_status(struct device *dev, |
| 94 | unsigned int status) { return 0; } |
| 95 | static inline int pm_runtime_barrier(struct device *dev) { return 0; } |
| 96 | static inline void pm_runtime_enable(struct device *dev) {} |
| 97 | static inline void __pm_runtime_disable(struct device *dev, bool c) {} |
Rafael J. Wysocki | 5382363 | 2010-01-23 22:02:51 +0100 | [diff] [blame] | 98 | static inline void pm_runtime_allow(struct device *dev) {} |
| 99 | static inline void pm_runtime_forbid(struct device *dev) {} |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 100 | |
| 101 | static inline bool pm_children_suspended(struct device *dev) { return false; } |
| 102 | static inline void pm_suspend_ignore_children(struct device *dev, bool en) {} |
| 103 | static inline void pm_runtime_get_noresume(struct device *dev) {} |
| 104 | static inline void pm_runtime_put_noidle(struct device *dev) {} |
Rafael J. Wysocki | 7a1a8eb | 2009-12-03 21:19:18 +0100 | [diff] [blame] | 105 | static inline bool device_run_wake(struct device *dev) { return false; } |
| 106 | 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] | 107 | static inline bool pm_runtime_suspended(struct device *dev) { return false; } |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 108 | |
Rafael J. Wysocki | 2f60ba7 | 2010-05-10 23:09:30 +0200 | [diff] [blame] | 109 | static inline int pm_generic_runtime_idle(struct device *dev) { return 0; } |
| 110 | static inline int pm_generic_runtime_suspend(struct device *dev) { return 0; } |
| 111 | static inline int pm_generic_runtime_resume(struct device *dev) { return 0; } |
| 112 | |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 113 | #endif /* !CONFIG_PM_RUNTIME */ |
| 114 | |
| 115 | static inline int pm_runtime_get(struct device *dev) |
| 116 | { |
Alan Stern | 3f9af05 | 2010-09-25 23:34:54 +0200 | [diff] [blame^] | 117 | return __pm_runtime_get(dev, RPM_ASYNC); |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | static inline int pm_runtime_get_sync(struct device *dev) |
| 121 | { |
Alan Stern | 3f9af05 | 2010-09-25 23:34:54 +0200 | [diff] [blame^] | 122 | return __pm_runtime_get(dev, 0); |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | static inline int pm_runtime_put(struct device *dev) |
| 126 | { |
Alan Stern | 3f9af05 | 2010-09-25 23:34:54 +0200 | [diff] [blame^] | 127 | return __pm_runtime_put(dev, RPM_ASYNC); |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | static inline int pm_runtime_put_sync(struct device *dev) |
| 131 | { |
Alan Stern | 3f9af05 | 2010-09-25 23:34:54 +0200 | [diff] [blame^] | 132 | return __pm_runtime_put(dev, 0); |
Rafael J. Wysocki | 5e928f7 | 2009-08-18 23:38:32 +0200 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | static inline int pm_runtime_set_active(struct device *dev) |
| 136 | { |
| 137 | return __pm_runtime_set_status(dev, RPM_ACTIVE); |
| 138 | } |
| 139 | |
| 140 | static inline void pm_runtime_set_suspended(struct device *dev) |
| 141 | { |
| 142 | __pm_runtime_set_status(dev, RPM_SUSPENDED); |
| 143 | } |
| 144 | |
| 145 | static inline void pm_runtime_disable(struct device *dev) |
| 146 | { |
| 147 | __pm_runtime_disable(dev, true); |
| 148 | } |
| 149 | |
| 150 | #endif |