blob: c030cac59aac43373234ea5d98c1ac06aebf33fb [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 */
19
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020020#ifdef CONFIG_PM_RUNTIME
21
22extern struct workqueue_struct *pm_wq;
23
24extern int pm_runtime_idle(struct device *dev);
25extern int pm_runtime_suspend(struct device *dev);
26extern int pm_runtime_resume(struct device *dev);
27extern int pm_request_idle(struct device *dev);
28extern int pm_schedule_suspend(struct device *dev, unsigned int delay);
29extern int pm_request_resume(struct device *dev);
Alan Stern3f9af052010-09-25 23:34:54 +020030extern int __pm_runtime_get(struct device *dev, int rpmflags);
31extern int __pm_runtime_put(struct device *dev, int rpmflags);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020032extern int __pm_runtime_set_status(struct device *dev, unsigned int status);
33extern int pm_runtime_barrier(struct device *dev);
34extern void pm_runtime_enable(struct device *dev);
35extern void __pm_runtime_disable(struct device *dev, bool check_resume);
Rafael J. Wysocki53823632010-01-23 22:02:51 +010036extern void pm_runtime_allow(struct device *dev);
37extern void pm_runtime_forbid(struct device *dev);
Rafael J. Wysocki2f60ba72010-05-10 23:09:30 +020038extern int pm_generic_runtime_idle(struct device *dev);
39extern int pm_generic_runtime_suspend(struct device *dev);
40extern int pm_generic_runtime_resume(struct device *dev);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020041
42static inline bool pm_children_suspended(struct device *dev)
43{
44 return dev->power.ignore_children
45 || !atomic_read(&dev->power.child_count);
46}
47
48static inline void pm_suspend_ignore_children(struct device *dev, bool enable)
49{
50 dev->power.ignore_children = enable;
51}
52
53static inline void pm_runtime_get_noresume(struct device *dev)
54{
55 atomic_inc(&dev->power.usage_count);
56}
57
58static inline void pm_runtime_put_noidle(struct device *dev)
59{
60 atomic_add_unless(&dev->power.usage_count, -1, 0);
61}
62
Rafael J. Wysocki7a1a8eb2009-12-03 21:19:18 +010063static inline bool device_run_wake(struct device *dev)
64{
65 return dev->power.run_wake;
66}
67
68static inline void device_set_run_wake(struct device *dev, bool enable)
69{
70 dev->power.run_wake = enable;
71}
72
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +010073static inline bool pm_runtime_suspended(struct device *dev)
74{
75 return dev->power.runtime_status == RPM_SUSPENDED;
76}
77
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020078#else /* !CONFIG_PM_RUNTIME */
79
80static inline int pm_runtime_idle(struct device *dev) { return -ENOSYS; }
81static inline int pm_runtime_suspend(struct device *dev) { return -ENOSYS; }
82static inline int pm_runtime_resume(struct device *dev) { return 0; }
83static inline int pm_request_idle(struct device *dev) { return -ENOSYS; }
84static inline int pm_schedule_suspend(struct device *dev, unsigned int delay)
85{
86 return -ENOSYS;
87}
88static inline int pm_request_resume(struct device *dev) { return 0; }
Alan Stern3f9af052010-09-25 23:34:54 +020089static inline int __pm_runtime_get(struct device *dev, int rpmflags)
90 { return 1; }
91static inline int __pm_runtime_put(struct device *dev, int rpmflags)
92 { return 0; }
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +020093static inline int __pm_runtime_set_status(struct device *dev,
94 unsigned int status) { return 0; }
95static inline int pm_runtime_barrier(struct device *dev) { return 0; }
96static inline void pm_runtime_enable(struct device *dev) {}
97static inline void __pm_runtime_disable(struct device *dev, bool c) {}
Rafael J. Wysocki53823632010-01-23 22:02:51 +010098static inline void pm_runtime_allow(struct device *dev) {}
99static inline void pm_runtime_forbid(struct device *dev) {}
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200100
101static inline bool pm_children_suspended(struct device *dev) { return false; }
102static inline void pm_suspend_ignore_children(struct device *dev, bool en) {}
103static inline void pm_runtime_get_noresume(struct device *dev) {}
104static inline void pm_runtime_put_noidle(struct device *dev) {}
Rafael J. Wysocki7a1a8eb2009-12-03 21:19:18 +0100105static inline bool device_run_wake(struct device *dev) { return false; }
106static inline void device_set_run_wake(struct device *dev, bool enable) {}
Rafael J. Wysockid690b2c2010-03-06 21:28:37 +0100107static inline bool pm_runtime_suspended(struct device *dev) { return false; }
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200108
Rafael J. Wysocki2f60ba72010-05-10 23:09:30 +0200109static inline int pm_generic_runtime_idle(struct device *dev) { return 0; }
110static inline int pm_generic_runtime_suspend(struct device *dev) { return 0; }
111static inline int pm_generic_runtime_resume(struct device *dev) { return 0; }
112
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200113#endif /* !CONFIG_PM_RUNTIME */
114
115static inline int pm_runtime_get(struct device *dev)
116{
Alan Stern3f9af052010-09-25 23:34:54 +0200117 return __pm_runtime_get(dev, RPM_ASYNC);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200118}
119
120static inline int pm_runtime_get_sync(struct device *dev)
121{
Alan Stern3f9af052010-09-25 23:34:54 +0200122 return __pm_runtime_get(dev, 0);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200123}
124
125static inline int pm_runtime_put(struct device *dev)
126{
Alan Stern3f9af052010-09-25 23:34:54 +0200127 return __pm_runtime_put(dev, RPM_ASYNC);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200128}
129
130static inline int pm_runtime_put_sync(struct device *dev)
131{
Alan Stern3f9af052010-09-25 23:34:54 +0200132 return __pm_runtime_put(dev, 0);
Rafael J. Wysocki5e928f72009-08-18 23:38:32 +0200133}
134
135static inline int pm_runtime_set_active(struct device *dev)
136{
137 return __pm_runtime_set_status(dev, RPM_ACTIVE);
138}
139
140static inline void pm_runtime_set_suspended(struct device *dev)
141{
142 __pm_runtime_set_status(dev, RPM_SUSPENDED);
143}
144
145static inline void pm_runtime_disable(struct device *dev)
146{
147 __pm_runtime_disable(dev, true);
148}
149
150#endif