2 * pm_runtime.h - Device run-time power management helper functions.
6 * This file is released under the GPLv2.
9 #ifndef _LINUX_PM_RUNTIME_H
10 #define _LINUX_PM_RUNTIME_H
12 #include <linux/device.h>
15 #ifdef CONFIG_PM_RUNTIME
17 extern struct workqueue_struct *pm_wq;
19 extern int pm_runtime_idle(struct device *dev);
20 extern int pm_runtime_suspend(struct device *dev);
21 extern int pm_runtime_resume(struct device *dev);
22 extern int pm_request_idle(struct device *dev);
23 extern int pm_schedule_suspend(struct device *dev, unsigned int delay);
24 extern int pm_request_resume(struct device *dev);
25 extern int __pm_runtime_get(struct device *dev, bool sync);
26 extern int __pm_runtime_put(struct device *dev, bool sync);
27 extern int __pm_runtime_set_status(struct device *dev, unsigned int status);
28 extern int pm_runtime_barrier(struct device *dev);
29 extern void pm_runtime_enable(struct device *dev);
30 extern void __pm_runtime_disable(struct device *dev, bool check_resume);
31 extern void pm_runtime_allow(struct device *dev);
32 extern void pm_runtime_forbid(struct device *dev);
34 static inline bool pm_children_suspended(struct device *dev)
36 return dev->power.ignore_children
37 || !atomic_read(&dev->power.child_count);
40 static inline void pm_suspend_ignore_children(struct device *dev, bool enable)
42 dev->power.ignore_children = enable;
45 static inline void pm_runtime_get_noresume(struct device *dev)
47 atomic_inc(&dev->power.usage_count);
50 static inline void pm_runtime_put_noidle(struct device *dev)
52 atomic_add_unless(&dev->power.usage_count, -1, 0);
55 static inline bool device_run_wake(struct device *dev)
57 return dev->power.run_wake;
60 static inline void device_set_run_wake(struct device *dev, bool enable)
62 dev->power.run_wake = enable;
65 #else /* !CONFIG_PM_RUNTIME */
67 static inline int pm_runtime_idle(struct device *dev) { return -ENOSYS; }
68 static inline int pm_runtime_suspend(struct device *dev) { return -ENOSYS; }
69 static inline int pm_runtime_resume(struct device *dev) { return 0; }
70 static inline int pm_request_idle(struct device *dev) { return -ENOSYS; }
71 static inline int pm_schedule_suspend(struct device *dev, unsigned int delay)
75 static inline int pm_request_resume(struct device *dev) { return 0; }
76 static inline int __pm_runtime_get(struct device *dev, bool sync) { return 1; }
77 static inline int __pm_runtime_put(struct device *dev, bool sync) { return 0; }
78 static inline int __pm_runtime_set_status(struct device *dev,
79 unsigned int status) { return 0; }
80 static inline int pm_runtime_barrier(struct device *dev) { return 0; }
81 static inline void pm_runtime_enable(struct device *dev) {}
82 static inline void __pm_runtime_disable(struct device *dev, bool c) {}
83 static inline void pm_runtime_allow(struct device *dev) {}
84 static inline void pm_runtime_forbid(struct device *dev) {}
86 static inline bool pm_children_suspended(struct device *dev) { return false; }
87 static inline void pm_suspend_ignore_children(struct device *dev, bool en) {}
88 static inline void pm_runtime_get_noresume(struct device *dev) {}
89 static inline void pm_runtime_put_noidle(struct device *dev) {}
90 static inline bool device_run_wake(struct device *dev) { return false; }
91 static inline void device_set_run_wake(struct device *dev, bool enable) {}
93 #endif /* !CONFIG_PM_RUNTIME */
95 static inline int pm_runtime_get(struct device *dev)
97 return __pm_runtime_get(dev, false);
100 static inline int pm_runtime_get_sync(struct device *dev)
102 return __pm_runtime_get(dev, true);
105 static inline int pm_runtime_put(struct device *dev)
107 return __pm_runtime_put(dev, false);
110 static inline int pm_runtime_put_sync(struct device *dev)
112 return __pm_runtime_put(dev, true);
115 static inline int pm_runtime_set_active(struct device *dev)
117 return __pm_runtime_set_status(dev, RPM_ACTIVE);
120 static inline void pm_runtime_set_suspended(struct device *dev)
122 __pm_runtime_set_status(dev, RPM_SUSPENDED);
125 static inline void pm_runtime_disable(struct device *dev)
127 __pm_runtime_disable(dev, true);