blob: 6e81888c62225f99217ab356dd0f3c46a3a45715 [file] [log] [blame]
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +02001/*
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
15#ifdef CONFIG_PM_RUNTIME
16
17extern struct workqueue_struct *pm_wq;
18
19extern int pm_runtime_idle(struct device *dev);
20extern int pm_runtime_suspend(struct device *dev);
21extern int pm_runtime_resume(struct device *dev);
22extern int pm_request_idle(struct device *dev);
23extern int pm_schedule_suspend(struct device *dev, unsigned int delay);
24extern int pm_request_resume(struct device *dev);
25extern int __pm_runtime_get(struct device *dev, bool sync);
26extern int __pm_runtime_put(struct device *dev, bool sync);
27extern int __pm_runtime_set_status(struct device *dev, unsigned int status);
28extern int pm_runtime_barrier(struct device *dev);
29extern void pm_runtime_enable(struct device *dev);
30extern void __pm_runtime_disable(struct device *dev, bool check_resume);
Rafael J. Wysocki53823632010-01-23 22:02:51 +010031extern void pm_runtime_allow(struct device *dev);
32extern void pm_runtime_forbid(struct device *dev);
Rafael J. Wysocki2f60ba72010-05-10 23:09:30 +020033extern int pm_generic_runtime_idle(struct device *dev);
34extern int pm_generic_runtime_suspend(struct device *dev);
35extern int pm_generic_runtime_resume(struct device *dev);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020036
37static inline bool pm_children_suspended(struct device *dev)
38{
39 return dev->power.ignore_children
40 || !atomic_read(&dev->power.child_count);
41}
42
43static inline void pm_suspend_ignore_children(struct device *dev, bool enable)
44{
45 dev->power.ignore_children = enable;
46}
47
48static inline void pm_runtime_get_noresume(struct device *dev)
49{
50 atomic_inc(&dev->power.usage_count);
51}
52
53static inline void pm_runtime_put_noidle(struct device *dev)
54{
55 atomic_add_unless(&dev->power.usage_count, -1, 0);
56}
57
Rafael J. Wysocki7a1a8eb2009-12-03 21:19:18 +010058static inline bool device_run_wake(struct device *dev)
59{
60 return dev->power.run_wake;
61}
62
63static inline void device_set_run_wake(struct device *dev, bool enable)
64{
65 dev->power.run_wake = enable;
66}
67
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010068static inline bool pm_runtime_suspended(struct device *dev)
69{
70 return dev->power.runtime_status == RPM_SUSPENDED;
71}
72
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020073#else /* !CONFIG_PM_RUNTIME */
74
75static inline int pm_runtime_idle(struct device *dev) { return -ENOSYS; }
76static inline int pm_runtime_suspend(struct device *dev) { return -ENOSYS; }
77static inline int pm_runtime_resume(struct device *dev) { return 0; }
78static inline int pm_request_idle(struct device *dev) { return -ENOSYS; }
79static inline int pm_schedule_suspend(struct device *dev, unsigned int delay)
80{
81 return -ENOSYS;
82}
83static inline int pm_request_resume(struct device *dev) { return 0; }
84static inline int __pm_runtime_get(struct device *dev, bool sync) { return 1; }
85static inline int __pm_runtime_put(struct device *dev, bool sync) { return 0; }
86static inline int __pm_runtime_set_status(struct device *dev,
87 unsigned int status) { return 0; }
88static inline int pm_runtime_barrier(struct device *dev) { return 0; }
89static inline void pm_runtime_enable(struct device *dev) {}
90static inline void __pm_runtime_disable(struct device *dev, bool c) {}
Rafael J. Wysocki53823632010-01-23 22:02:51 +010091static inline void pm_runtime_allow(struct device *dev) {}
92static inline void pm_runtime_forbid(struct device *dev) {}
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020093
94static inline bool pm_children_suspended(struct device *dev) { return false; }
95static inline void pm_suspend_ignore_children(struct device *dev, bool en) {}
96static inline void pm_runtime_get_noresume(struct device *dev) {}
97static inline void pm_runtime_put_noidle(struct device *dev) {}
Rafael J. Wysocki7a1a8eb2009-12-03 21:19:18 +010098static inline bool device_run_wake(struct device *dev) { return false; }
99static inline void device_set_run_wake(struct device *dev, bool enable) {}
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100100static inline bool pm_runtime_suspended(struct device *dev) { return false; }
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200101
Rafael J. Wysocki2f60ba72010-05-10 23:09:30 +0200102static inline int pm_generic_runtime_idle(struct device *dev) { return 0; }
103static inline int pm_generic_runtime_suspend(struct device *dev) { return 0; }
104static inline int pm_generic_runtime_resume(struct device *dev) { return 0; }
105
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200106#endif /* !CONFIG_PM_RUNTIME */
107
108static inline int pm_runtime_get(struct device *dev)
109{
110 return __pm_runtime_get(dev, false);
111}
112
113static inline int pm_runtime_get_sync(struct device *dev)
114{
115 return __pm_runtime_get(dev, true);
116}
117
118static inline int pm_runtime_put(struct device *dev)
119{
120 return __pm_runtime_put(dev, false);
121}
122
123static inline int pm_runtime_put_sync(struct device *dev)
124{
125 return __pm_runtime_put(dev, true);
126}
127
128static inline int pm_runtime_set_active(struct device *dev)
129{
130 return __pm_runtime_set_status(dev, RPM_ACTIVE);
131}
132
133static inline void pm_runtime_set_suspended(struct device *dev)
134{
135 __pm_runtime_set_status(dev, RPM_SUSPENDED);
136}
137
138static inline void pm_runtime_disable(struct device *dev)
139{
140 __pm_runtime_disable(dev, true);
141}
142
143#endif