Merge branch 'linus' of git://git.kernel.org/pub/scm/linux/kernel/git/herbert/crypto-2.6
[linux-2.6-block.git] / include / linux / pm_wakeup.h
CommitLineData
1a59d1b8 1/* SPDX-License-Identifier: GPL-2.0-or-later */
9a3df1f7
AS
2/*
3 * pm_wakeup.h - Power management wakeup interface
4 *
5 * Copyright (C) 2008 Alan Stern
074037ec 6 * Copyright (C) 2010 Rafael J. Wysocki, Novell Inc.
9a3df1f7
AS
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
228c54ef
DT
16#include <linux/types.h>
17
4990d4fe
TL
18struct wake_irq;
19
074037ec
RW
20/**
21 * struct wakeup_source - Representation of wakeup sources
2430d12c 22 *
4990d4fe
TL
23 * @name: Name of the wakeup source
24 * @entry: Wakeup source list entry
25 * @lock: Wakeup source lock
26 * @wakeirq: Optional device specific wakeirq
27 * @timer: Wakeup timer list
28 * @timer_expires: Wakeup timer expiration
074037ec
RW
29 * @total_time: Total time this wakeup source has been active.
30 * @max_time: Maximum time this wakeup source has been continuously active.
30e3ce6d 31 * @last_time: Monotonic clock when the wakeup source's was touched last time.
55850945 32 * @prevent_sleep_time: Total time this source has been preventing autosleep.
074037ec 33 * @event_count: Number of signaled wakeup events.
1258ca80
CC
34 * @active_count: Number of times the wakeup source was activated.
35 * @relax_count: Number of times the wakeup source was deactivated.
30e3ce6d
RW
36 * @expire_count: Number of times the wakeup source's timeout has expired.
37 * @wakeup_count: Number of times the wakeup source might abort suspend.
074037ec 38 * @active: Status of the wakeup source.
e9bea8f9 39 * @autosleep_enabled: Autosleep is active, so update @prevent_sleep_time.
9a3df1f7 40 */
074037ec 41struct wakeup_source {
8671bbc1 42 const char *name;
074037ec
RW
43 struct list_head entry;
44 spinlock_t lock;
4990d4fe 45 struct wake_irq *wakeirq;
074037ec
RW
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;
55850945
RW
51 ktime_t start_prevent_time;
52 ktime_t prevent_sleep_time;
074037ec
RW
53 unsigned long event_count;
54 unsigned long active_count;
55 unsigned long relax_count;
30e3ce6d
RW
56 unsigned long expire_count;
57 unsigned long wakeup_count;
58 bool active:1;
55850945 59 bool autosleep_enabled:1;
074037ec
RW
60};
61
62#ifdef CONFIG_PM_SLEEP
63
64/*
65 * Changes to device_may_wakeup take effect on the next pm state change.
66 */
67
074037ec
RW
68static inline bool device_can_wakeup(struct device *dev)
69{
70 return dev->power.can_wakeup;
71}
72
074037ec 73static inline bool device_may_wakeup(struct device *dev)
9a3df1f7 74{
074037ec 75 return dev->power.can_wakeup && !!dev->power.wakeup;
9a3df1f7
AS
76}
77
cf04ce78
UH
78static inline void device_set_wakeup_path(struct device *dev)
79{
80 dev->power.wakeup_path = true;
81}
82
074037ec 83/* drivers/base/power/wakeup.c */
8671bbc1 84extern void wakeup_source_prepare(struct wakeup_source *ws, const char *name);
074037ec
RW
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);
cb8f51bd 93extern void device_set_wakeup_capable(struct device *dev, bool capable);
074037ec
RW
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);
8a537ece
RW
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);
074037ec
RW
102
103#else /* !CONFIG_PM_SLEEP */
104
228c54ef 105static inline void device_set_wakeup_capable(struct device *dev, bool capable)
eb9d0fe4 106{
228c54ef 107 dev->power.can_wakeup = capable;
eb9d0fe4
RW
108}
109
228c54ef 110static inline bool device_can_wakeup(struct device *dev)
9a3df1f7
AS
111{
112 return dev->power.can_wakeup;
113}
114
8671bbc1
RW
115static inline void wakeup_source_prepare(struct wakeup_source *ws,
116 const char *name) {}
117
074037ec 118static inline struct wakeup_source *wakeup_source_create(const char *name)
9a3df1f7 119{
074037ec 120 return NULL;
9a3df1f7
AS
121}
122
074037ec
RW
123static inline void wakeup_source_destroy(struct wakeup_source *ws) {}
124
125static inline void wakeup_source_add(struct wakeup_source *ws) {}
9a3df1f7 126
074037ec
RW
127static inline void wakeup_source_remove(struct wakeup_source *ws) {}
128
129static inline struct wakeup_source *wakeup_source_register(const char *name)
9a3df1f7 130{
074037ec 131 return NULL;
9a3df1f7
AS
132}
133
074037ec
RW
134static inline void wakeup_source_unregister(struct wakeup_source *ws) {}
135
136static inline int device_wakeup_enable(struct device *dev)
228c54ef 137{
805bdaec
RW
138 dev->power.should_wakeup = true;
139 return 0;
228c54ef 140}
c300bd2f 141
074037ec 142static inline int device_wakeup_disable(struct device *dev)
9a3df1f7 143{
805bdaec 144 dev->power.should_wakeup = false;
074037ec 145 return 0;
9a3df1f7
AS
146}
147
805bdaec 148static inline int device_set_wakeup_enable(struct device *dev, bool enable)
228c54ef 149{
805bdaec
RW
150 dev->power.should_wakeup = enable;
151 return 0;
228c54ef
DT
152}
153
805bdaec
RW
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}
074037ec 160
805bdaec 161static inline bool device_may_wakeup(struct device *dev)
228c54ef 162{
805bdaec 163 return dev->power.can_wakeup && dev->power.should_wakeup;
228c54ef 164}
9a3df1f7 165
cf04ce78
UH
166static inline void device_set_wakeup_path(struct device *dev) {}
167
074037ec
RW
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
8a537ece
RW
176static inline void pm_wakeup_ws_event(struct wakeup_source *ws,
177 unsigned int msec, bool hard) {}
074037ec 178
8a537ece
RW
179static inline void pm_wakeup_dev_event(struct device *dev, unsigned int msec,
180 bool hard) {}
074037ec
RW
181
182#endif /* !CONFIG_PM_SLEEP */
9a3df1f7 183
8671bbc1
RW
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
8a537ece
RW
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
9a3df1f7 206#endif /* _LINUX_PM_WAKEUP_H */