blob: 5869d87fffaccf89c332913872326a81555f0b50 [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);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020039
40static inline bool pm_children_suspended(struct device *dev)
41{
42 return dev->power.ignore_children
43 || !atomic_read(&dev->power.child_count);
44}
45
46static inline void pm_suspend_ignore_children(struct device *dev, bool enable)
47{
48 dev->power.ignore_children = enable;
49}
50
51static inline void pm_runtime_get_noresume(struct device *dev)
52{
53 atomic_inc(&dev->power.usage_count);
54}
55
56static inline void pm_runtime_put_noidle(struct device *dev)
57{
58 atomic_add_unless(&dev->power.usage_count, -1, 0);
59}
60
Rafael J. Wysocki7a1a8eb2009-12-03 21:19:18 +010061static inline bool device_run_wake(struct device *dev)
62{
63 return dev->power.run_wake;
64}
65
66static inline void device_set_run_wake(struct device *dev, bool enable)
67{
68 dev->power.run_wake = enable;
69}
70
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010071static inline bool pm_runtime_suspended(struct device *dev)
72{
73 return dev->power.runtime_status == RPM_SUSPENDED;
74}
75
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020076#else /* !CONFIG_PM_RUNTIME */
77
Alan Stern140a6c92010-09-25 23:35:07 +020078static inline int __pm_runtime_idle(struct device *dev, int rpmflags)
79{
80 return -ENOSYS;
81}
82static inline int __pm_runtime_suspend(struct device *dev, int rpmflags)
83{
84 return -ENOSYS;
85}
86static inline int __pm_runtime_resume(struct device *dev, int rpmflags)
87{
88 return 1;
89}
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020090static inline int pm_schedule_suspend(struct device *dev, unsigned int delay)
91{
92 return -ENOSYS;
93}
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020094static inline int __pm_runtime_set_status(struct device *dev,
95 unsigned int status) { return 0; }
96static inline int pm_runtime_barrier(struct device *dev) { return 0; }
97static inline void pm_runtime_enable(struct device *dev) {}
98static inline void __pm_runtime_disable(struct device *dev, bool c) {}
Rafael J. Wysocki53823632010-01-23 22:02:51 +010099static inline void pm_runtime_allow(struct device *dev) {}
100static inline void pm_runtime_forbid(struct device *dev) {}
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200101
102static inline bool pm_children_suspended(struct device *dev) { return false; }
103static inline void pm_suspend_ignore_children(struct device *dev, bool en) {}
104static inline void pm_runtime_get_noresume(struct device *dev) {}
105static inline void pm_runtime_put_noidle(struct device *dev) {}
Rafael J. Wysocki7a1a8eb2009-12-03 21:19:18 +0100106static inline bool device_run_wake(struct device *dev) { return false; }
107static inline void device_set_run_wake(struct device *dev, bool enable) {}
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100108static inline bool pm_runtime_suspended(struct device *dev) { return false; }
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200109
Rafael J. Wysocki2f60ba72010-05-10 23:09:30 +0200110static inline int pm_generic_runtime_idle(struct device *dev) { return 0; }
111static inline int pm_generic_runtime_suspend(struct device *dev) { return 0; }
112static inline int pm_generic_runtime_resume(struct device *dev) { return 0; }
113
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200114#endif /* !CONFIG_PM_RUNTIME */
115
Alan Stern140a6c92010-09-25 23:35:07 +0200116static inline int pm_runtime_idle(struct device *dev)
117{
118 return __pm_runtime_idle(dev, 0);
119}
120
121static inline int pm_runtime_suspend(struct device *dev)
122{
123 return __pm_runtime_suspend(dev, 0);
124}
125
126static inline int pm_runtime_resume(struct device *dev)
127{
128 return __pm_runtime_resume(dev, 0);
129}
130
131static inline int pm_request_idle(struct device *dev)
132{
133 return __pm_runtime_idle(dev, RPM_ASYNC);
134}
135
136static inline int pm_request_resume(struct device *dev)
137{
138 return __pm_runtime_resume(dev, RPM_ASYNC);
139}
140
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200141static inline int pm_runtime_get(struct device *dev)
142{
Alan Stern140a6c92010-09-25 23:35:07 +0200143 return __pm_runtime_resume(dev, RPM_GET_PUT | RPM_ASYNC);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200144}
145
146static inline int pm_runtime_get_sync(struct device *dev)
147{
Alan Stern140a6c92010-09-25 23:35:07 +0200148 return __pm_runtime_resume(dev, RPM_GET_PUT);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200149}
150
151static inline int pm_runtime_put(struct device *dev)
152{
Alan Stern140a6c92010-09-25 23:35:07 +0200153 return __pm_runtime_idle(dev, RPM_GET_PUT | RPM_ASYNC);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200154}
155
156static inline int pm_runtime_put_sync(struct device *dev)
157{
Alan Stern140a6c92010-09-25 23:35:07 +0200158 return __pm_runtime_idle(dev, RPM_GET_PUT);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200159}
160
161static inline int pm_runtime_set_active(struct device *dev)
162{
163 return __pm_runtime_set_status(dev, RPM_ACTIVE);
164}
165
166static inline void pm_runtime_set_suspended(struct device *dev)
167{
168 __pm_runtime_set_status(dev, RPM_SUSPENDED);
169}
170
171static inline void pm_runtime_disable(struct device *dev)
172{
173 __pm_runtime_disable(dev, true);
174}
175
176#endif