blob: 8ca52f7c357e861318a5806b0d1784462c38ad94 [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
Alan Stern3f9af052010-09-25 23:34:54 +020015/* 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 Stern140a6c92010-09-25 23:35:07 +020019#define RPM_GET_PUT 0x04 /* Increment/decrement the
20 usage_count */
Alan Stern3f9af052010-09-25 23:34:54 +020021
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020022#ifdef CONFIG_PM_RUNTIME
23
24extern struct workqueue_struct *pm_wq;
25
Alan Stern140a6c92010-09-25 23:35:07 +020026extern int __pm_runtime_idle(struct device *dev, int rpmflags);
27extern int __pm_runtime_suspend(struct device *dev, int rpmflags);
28extern int __pm_runtime_resume(struct device *dev, int rpmflags);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020029extern int pm_schedule_suspend(struct device *dev, unsigned int delay);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020030extern int __pm_runtime_set_status(struct device *dev, unsigned int status);
31extern int pm_runtime_barrier(struct device *dev);
32extern void pm_runtime_enable(struct device *dev);
33extern void __pm_runtime_disable(struct device *dev, bool check_resume);
Rafael J. Wysocki53823632010-01-23 22:02:51 +010034extern void pm_runtime_allow(struct device *dev);
35extern void pm_runtime_forbid(struct device *dev);
Rafael J. Wysocki2f60ba72010-05-10 23:09:30 +020036extern int pm_generic_runtime_idle(struct device *dev);
37extern int pm_generic_runtime_suspend(struct device *dev);
38extern int pm_generic_runtime_resume(struct device *dev);
Alan Stern7490e442010-09-25 23:35:15 +020039extern void pm_runtime_no_callbacks(struct device *dev);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020040
41static inline bool pm_children_suspended(struct device *dev)
42{
43 return dev->power.ignore_children
44 || !atomic_read(&dev->power.child_count);
45}
46
47static inline void pm_suspend_ignore_children(struct device *dev, bool enable)
48{
49 dev->power.ignore_children = enable;
50}
51
52static inline void pm_runtime_get_noresume(struct device *dev)
53{
54 atomic_inc(&dev->power.usage_count);
55}
56
57static inline void pm_runtime_put_noidle(struct device *dev)
58{
59 atomic_add_unless(&dev->power.usage_count, -1, 0);
60}
61
Rafael J. Wysocki7a1a8eb2009-12-03 21:19:18 +010062static inline bool device_run_wake(struct device *dev)
63{
64 return dev->power.run_wake;
65}
66
67static inline void device_set_run_wake(struct device *dev, bool enable)
68{
69 dev->power.run_wake = enable;
70}
71
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010072static inline bool pm_runtime_suspended(struct device *dev)
73{
74 return dev->power.runtime_status == RPM_SUSPENDED;
75}
76
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020077#else /* !CONFIG_PM_RUNTIME */
78
Alan Stern140a6c92010-09-25 23:35:07 +020079static inline int __pm_runtime_idle(struct device *dev, int rpmflags)
80{
81 return -ENOSYS;
82}
83static inline int __pm_runtime_suspend(struct device *dev, int rpmflags)
84{
85 return -ENOSYS;
86}
87static inline int __pm_runtime_resume(struct device *dev, int rpmflags)
88{
89 return 1;
90}
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020091static inline int pm_schedule_suspend(struct device *dev, unsigned int delay)
92{
93 return -ENOSYS;
94}
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020095static inline int __pm_runtime_set_status(struct device *dev,
96 unsigned int status) { return 0; }
97static inline int pm_runtime_barrier(struct device *dev) { return 0; }
98static inline void pm_runtime_enable(struct device *dev) {}
99static inline void __pm_runtime_disable(struct device *dev, bool c) {}
Rafael J. Wysocki53823632010-01-23 22:02:51 +0100100static inline void pm_runtime_allow(struct device *dev) {}
101static inline void pm_runtime_forbid(struct device *dev) {}
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200102
103static inline bool pm_children_suspended(struct device *dev) { return false; }
104static inline void pm_suspend_ignore_children(struct device *dev, bool en) {}
105static inline void pm_runtime_get_noresume(struct device *dev) {}
106static inline void pm_runtime_put_noidle(struct device *dev) {}
Rafael J. Wysocki7a1a8eb2009-12-03 21:19:18 +0100107static inline bool device_run_wake(struct device *dev) { return false; }
108static inline void device_set_run_wake(struct device *dev, bool enable) {}
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100109static inline bool pm_runtime_suspended(struct device *dev) { return false; }
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200110
Rafael J. Wysocki2f60ba72010-05-10 23:09:30 +0200111static inline int pm_generic_runtime_idle(struct device *dev) { return 0; }
112static inline int pm_generic_runtime_suspend(struct device *dev) { return 0; }
113static inline int pm_generic_runtime_resume(struct device *dev) { return 0; }
Alan Stern7490e442010-09-25 23:35:15 +0200114static inline void pm_runtime_no_callbacks(struct device *dev) {}
Rafael J. Wysocki2f60ba72010-05-10 23:09:30 +0200115
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200116#endif /* !CONFIG_PM_RUNTIME */
117
Alan Stern140a6c92010-09-25 23:35:07 +0200118static inline int pm_runtime_idle(struct device *dev)
119{
120 return __pm_runtime_idle(dev, 0);
121}
122
123static inline int pm_runtime_suspend(struct device *dev)
124{
125 return __pm_runtime_suspend(dev, 0);
126}
127
128static inline int pm_runtime_resume(struct device *dev)
129{
130 return __pm_runtime_resume(dev, 0);
131}
132
133static inline int pm_request_idle(struct device *dev)
134{
135 return __pm_runtime_idle(dev, RPM_ASYNC);
136}
137
138static inline int pm_request_resume(struct device *dev)
139{
140 return __pm_runtime_resume(dev, RPM_ASYNC);
141}
142
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200143static inline int pm_runtime_get(struct device *dev)
144{
Alan Stern140a6c92010-09-25 23:35:07 +0200145 return __pm_runtime_resume(dev, RPM_GET_PUT | RPM_ASYNC);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200146}
147
148static inline int pm_runtime_get_sync(struct device *dev)
149{
Alan Stern140a6c92010-09-25 23:35:07 +0200150 return __pm_runtime_resume(dev, RPM_GET_PUT);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200151}
152
153static inline int pm_runtime_put(struct device *dev)
154{
Alan Stern140a6c92010-09-25 23:35:07 +0200155 return __pm_runtime_idle(dev, RPM_GET_PUT | RPM_ASYNC);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200156}
157
158static inline int pm_runtime_put_sync(struct device *dev)
159{
Alan Stern140a6c92010-09-25 23:35:07 +0200160 return __pm_runtime_idle(dev, RPM_GET_PUT);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200161}
162
163static inline int pm_runtime_set_active(struct device *dev)
164{
165 return __pm_runtime_set_status(dev, RPM_ACTIVE);
166}
167
168static inline void pm_runtime_set_suspended(struct device *dev)
169{
170 __pm_runtime_set_status(dev, RPM_SUSPENDED);
171}
172
173static inline void pm_runtime_disable(struct device *dev)
174{
175 __pm_runtime_disable(dev, true);
176}
177
178#endif