1
2
3
4
5
6
7
8
9#ifndef _LINUX_PM_WAKEUP_H
10#define _LINUX_PM_WAKEUP_H
11
12#ifndef _DEVICE_H_
13# error "please don't include this file directly"
14#endif
15
16#include <linux/types.h>
17
18struct wake_irq;
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41struct wakeup_source {
42 const char *name;
43 struct list_head entry;
44 spinlock_t lock;
45 struct wake_irq *wakeirq;
46 struct timer_list timer;
47 unsigned long timer_expires;
48 ktime_t total_time;
49 ktime_t max_time;
50 ktime_t last_time;
51 ktime_t start_prevent_time;
52 ktime_t prevent_sleep_time;
53 unsigned long event_count;
54 unsigned long active_count;
55 unsigned long relax_count;
56 unsigned long expire_count;
57 unsigned long wakeup_count;
58 bool active:1;
59 bool autosleep_enabled:1;
60};
61
62#ifdef CONFIG_PM_SLEEP
63
64
65
66
67
68static inline bool device_can_wakeup(struct device *dev)
69{
70 return dev->power.can_wakeup;
71}
72
73static inline bool device_may_wakeup(struct device *dev)
74{
75 return dev->power.can_wakeup && !!dev->power.wakeup;
76}
77
78static inline void device_set_wakeup_path(struct device *dev)
79{
80 dev->power.wakeup_path = true;
81}
82
83
84extern void wakeup_source_prepare(struct wakeup_source *ws, const char *name);
85extern struct wakeup_source *wakeup_source_create(const char *name);
86extern void wakeup_source_destroy(struct wakeup_source *ws);
87extern void wakeup_source_add(struct wakeup_source *ws);
88extern void wakeup_source_remove(struct wakeup_source *ws);
89extern struct wakeup_source *wakeup_source_register(const char *name);
90extern void wakeup_source_unregister(struct wakeup_source *ws);
91extern int device_wakeup_enable(struct device *dev);
92extern int device_wakeup_disable(struct device *dev);
93extern void device_set_wakeup_capable(struct device *dev, bool capable);
94extern int device_init_wakeup(struct device *dev, bool val);
95extern int device_set_wakeup_enable(struct device *dev, bool enable);
96extern void __pm_stay_awake(struct wakeup_source *ws);
97extern void pm_stay_awake(struct device *dev);
98extern void __pm_relax(struct wakeup_source *ws);
99extern void pm_relax(struct device *dev);
100extern void pm_wakeup_ws_event(struct wakeup_source *ws, unsigned int msec, bool hard);
101extern void pm_wakeup_dev_event(struct device *dev, unsigned int msec, bool hard);
102
103#else
104
105static inline void device_set_wakeup_capable(struct device *dev, bool capable)
106{
107 dev->power.can_wakeup = capable;
108}
109
110static inline bool device_can_wakeup(struct device *dev)
111{
112 return dev->power.can_wakeup;
113}
114
115static inline void wakeup_source_prepare(struct wakeup_source *ws,
116 const char *name) {}
117
118static inline struct wakeup_source *wakeup_source_create(const char *name)
119{
120 return NULL;
121}
122
123static inline void wakeup_source_destroy(struct wakeup_source *ws) {}
124
125static inline void wakeup_source_add(struct wakeup_source *ws) {}
126
127static inline void wakeup_source_remove(struct wakeup_source *ws) {}
128
129static inline struct wakeup_source *wakeup_source_register(const char *name)
130{
131 return NULL;
132}
133
134static inline void wakeup_source_unregister(struct wakeup_source *ws) {}
135
136static inline int device_wakeup_enable(struct device *dev)
137{
138 dev->power.should_wakeup = true;
139 return 0;
140}
141
142static inline int device_wakeup_disable(struct device *dev)
143{
144 dev->power.should_wakeup = false;
145 return 0;
146}
147
148static inline int device_set_wakeup_enable(struct device *dev, bool enable)
149{
150 dev->power.should_wakeup = enable;
151 return 0;
152}
153
154static inline int device_init_wakeup(struct device *dev, bool val)
155{
156 device_set_wakeup_capable(dev, val);
157 device_set_wakeup_enable(dev, val);
158 return 0;
159}
160
161static inline bool device_may_wakeup(struct device *dev)
162{
163 return dev->power.can_wakeup && dev->power.should_wakeup;
164}
165
166static inline void device_set_wakeup_path(struct device *dev) {}
167
168static inline void __pm_stay_awake(struct wakeup_source *ws) {}
169
170static inline void pm_stay_awake(struct device *dev) {}
171
172static inline void __pm_relax(struct wakeup_source *ws) {}
173
174static inline void pm_relax(struct device *dev) {}
175
176static inline void pm_wakeup_ws_event(struct wakeup_source *ws,
177 unsigned int msec, bool hard) {}
178
179static inline void pm_wakeup_dev_event(struct device *dev, unsigned int msec,
180 bool hard) {}
181
182#endif
183
184static inline void wakeup_source_init(struct wakeup_source *ws,
185 const char *name)
186{
187 wakeup_source_prepare(ws, name);
188 wakeup_source_add(ws);
189}
190
191static inline void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec)
192{
193 return pm_wakeup_ws_event(ws, msec, false);
194}
195
196static inline void pm_wakeup_event(struct device *dev, unsigned int msec)
197{
198 return pm_wakeup_dev_event(dev, msec, false);
199}
200
201static inline void pm_wakeup_hard_event(struct device *dev)
202{
203 return pm_wakeup_dev_event(dev, 0, true);
204}
205
206#endif
207