blob: 44087044910ff3b13aa72810ad741423de6f1960 [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);
31
32static inline bool pm_children_suspended(struct device *dev)
33{
34 return dev->power.ignore_children
35 || !atomic_read(&dev->power.child_count);
36}
37
38static inline void pm_suspend_ignore_children(struct device *dev, bool enable)
39{
40 dev->power.ignore_children = enable;
41}
42
43static inline void pm_runtime_get_noresume(struct device *dev)
44{
45 atomic_inc(&dev->power.usage_count);
46}
47
48static inline void pm_runtime_put_noidle(struct device *dev)
49{
50 atomic_add_unless(&dev->power.usage_count, -1, 0);
51}
52
53#else /* !CONFIG_PM_RUNTIME */
54
55static inline int pm_runtime_idle(struct device *dev) { return -ENOSYS; }
56static inline int pm_runtime_suspend(struct device *dev) { return -ENOSYS; }
57static inline int pm_runtime_resume(struct device *dev) { return 0; }
58static inline int pm_request_idle(struct device *dev) { return -ENOSYS; }
59static inline int pm_schedule_suspend(struct device *dev, unsigned int delay)
60{
61 return -ENOSYS;
62}
63static inline int pm_request_resume(struct device *dev) { return 0; }
64static inline int __pm_runtime_get(struct device *dev, bool sync) { return 1; }
65static inline int __pm_runtime_put(struct device *dev, bool sync) { return 0; }
66static inline int __pm_runtime_set_status(struct device *dev,
67 unsigned int status) { return 0; }
68static inline int pm_runtime_barrier(struct device *dev) { return 0; }
69static inline void pm_runtime_enable(struct device *dev) {}
70static inline void __pm_runtime_disable(struct device *dev, bool c) {}
71
72static inline bool pm_children_suspended(struct device *dev) { return false; }
73static inline void pm_suspend_ignore_children(struct device *dev, bool en) {}
74static inline void pm_runtime_get_noresume(struct device *dev) {}
75static inline void pm_runtime_put_noidle(struct device *dev) {}
76
77#endif /* !CONFIG_PM_RUNTIME */
78
79static inline int pm_runtime_get(struct device *dev)
80{
81 return __pm_runtime_get(dev, false);
82}
83
84static inline int pm_runtime_get_sync(struct device *dev)
85{
86 return __pm_runtime_get(dev, true);
87}
88
89static inline int pm_runtime_put(struct device *dev)
90{
91 return __pm_runtime_put(dev, false);
92}
93
94static inline int pm_runtime_put_sync(struct device *dev)
95{
96 return __pm_runtime_put(dev, true);
97}
98
99static inline int pm_runtime_set_active(struct device *dev)
100{
101 return __pm_runtime_set_status(dev, RPM_ACTIVE);
102}
103
104static inline void pm_runtime_set_suspended(struct device *dev)
105{
106 __pm_runtime_set_status(dev, RPM_SUSPENDED);
107}
108
109static inline void pm_runtime_disable(struct device *dev)
110{
111 __pm_runtime_disable(dev, true);
112}
113
114#endif