Blame view
include/linux/pm_wakeup.h
6.11 KB
1a59d1b8e
|
1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
9a3df1f7d
|
2 3 4 5 |
/* * pm_wakeup.h - Power management wakeup interface * * Copyright (C) 2008 Alan Stern |
074037ec7
|
6 |
* Copyright (C) 2010 Rafael J. Wysocki, Novell Inc. |
9a3df1f7d
|
7 8 9 10 11 12 13 14 |
*/ #ifndef _LINUX_PM_WAKEUP_H #define _LINUX_PM_WAKEUP_H #ifndef _DEVICE_H_ # error "please don't include this file directly" #endif |
228c54ef7
|
15 |
#include <linux/types.h> |
4990d4fe3
|
16 |
struct wake_irq; |
074037ec7
|
17 18 |
/** * struct wakeup_source - Representation of wakeup sources |
2430d12c9
|
19 |
* |
4990d4fe3
|
20 |
* @name: Name of the wakeup source |
c8377adfa
|
21 |
* @id: Wakeup source id |
4990d4fe3
|
22 23 24 25 26 |
* @entry: Wakeup source list entry * @lock: Wakeup source lock * @wakeirq: Optional device specific wakeirq * @timer: Wakeup timer list * @timer_expires: Wakeup timer expiration |
074037ec7
|
27 28 |
* @total_time: Total time this wakeup source has been active. * @max_time: Maximum time this wakeup source has been continuously active. |
30e3ce6dc
|
29 |
* @last_time: Monotonic clock when the wakeup source's was touched last time. |
55850945e
|
30 |
* @prevent_sleep_time: Total time this source has been preventing autosleep. |
074037ec7
|
31 |
* @event_count: Number of signaled wakeup events. |
1258ca805
|
32 33 |
* @active_count: Number of times the wakeup source was activated. * @relax_count: Number of times the wakeup source was deactivated. |
30e3ce6dc
|
34 35 |
* @expire_count: Number of times the wakeup source's timeout has expired. * @wakeup_count: Number of times the wakeup source might abort suspend. |
c8377adfa
|
36 |
* @dev: Struct device for sysfs statistics about the wakeup source. |
074037ec7
|
37 |
* @active: Status of the wakeup source. |
e9bea8f98
|
38 |
* @autosleep_enabled: Autosleep is active, so update @prevent_sleep_time. |
9a3df1f7d
|
39 |
*/ |
074037ec7
|
40 |
struct wakeup_source { |
8671bbc1b
|
41 |
const char *name; |
c8377adfa
|
42 |
int id; |
074037ec7
|
43 44 |
struct list_head entry; spinlock_t lock; |
4990d4fe3
|
45 |
struct wake_irq *wakeirq; |
074037ec7
|
46 47 48 49 50 |
struct timer_list timer; unsigned long timer_expires; ktime_t total_time; ktime_t max_time; ktime_t last_time; |
55850945e
|
51 52 |
ktime_t start_prevent_time; ktime_t prevent_sleep_time; |
074037ec7
|
53 54 55 |
unsigned long event_count; unsigned long active_count; unsigned long relax_count; |
30e3ce6dc
|
56 57 |
unsigned long expire_count; unsigned long wakeup_count; |
c8377adfa
|
58 |
struct device *dev; |
30e3ce6dc
|
59 |
bool active:1; |
55850945e
|
60 |
bool autosleep_enabled:1; |
074037ec7
|
61 |
}; |
b4941adb2
|
62 63 64 65 |
#define for_each_wakeup_source(ws) \ for ((ws) = wakeup_sources_walk_start(); \ (ws); \ (ws) = wakeup_sources_walk_next((ws))) |
074037ec7
|
66 67 68 69 70 |
#ifdef CONFIG_PM_SLEEP /* * Changes to device_may_wakeup take effect on the next pm state change. */ |
074037ec7
|
71 72 73 74 |
static inline bool device_can_wakeup(struct device *dev) { return dev->power.can_wakeup; } |
074037ec7
|
75 |
static inline bool device_may_wakeup(struct device *dev) |
9a3df1f7d
|
76 |
{ |
074037ec7
|
77 |
return dev->power.can_wakeup && !!dev->power.wakeup; |
9a3df1f7d
|
78 |
} |
cf04ce784
|
79 80 81 82 |
static inline void device_set_wakeup_path(struct device *dev) { dev->power.wakeup_path = true; } |
074037ec7
|
83 84 85 86 87 |
/* drivers/base/power/wakeup.c */ extern struct wakeup_source *wakeup_source_create(const char *name); extern void wakeup_source_destroy(struct wakeup_source *ws); extern void wakeup_source_add(struct wakeup_source *ws); extern void wakeup_source_remove(struct wakeup_source *ws); |
c8377adfa
|
88 89 |
extern struct wakeup_source *wakeup_source_register(struct device *dev, const char *name); |
074037ec7
|
90 |
extern void wakeup_source_unregister(struct wakeup_source *ws); |
b4941adb2
|
91 92 93 94 |
extern int wakeup_sources_read_lock(void); extern void wakeup_sources_read_unlock(int idx); extern struct wakeup_source *wakeup_sources_walk_start(void); extern struct wakeup_source *wakeup_sources_walk_next(struct wakeup_source *ws); |
074037ec7
|
95 96 |
extern int device_wakeup_enable(struct device *dev); extern int device_wakeup_disable(struct device *dev); |
cb8f51bda
|
97 |
extern void device_set_wakeup_capable(struct device *dev, bool capable); |
074037ec7
|
98 99 100 101 102 103 |
extern int device_init_wakeup(struct device *dev, bool val); extern int device_set_wakeup_enable(struct device *dev, bool enable); extern void __pm_stay_awake(struct wakeup_source *ws); extern void pm_stay_awake(struct device *dev); extern void __pm_relax(struct wakeup_source *ws); extern void pm_relax(struct device *dev); |
8a537ece3
|
104 105 |
extern void pm_wakeup_ws_event(struct wakeup_source *ws, unsigned int msec, bool hard); extern void pm_wakeup_dev_event(struct device *dev, unsigned int msec, bool hard); |
074037ec7
|
106 107 |
#else /* !CONFIG_PM_SLEEP */ |
228c54ef7
|
108 |
static inline void device_set_wakeup_capable(struct device *dev, bool capable) |
eb9d0fe40
|
109 |
{ |
228c54ef7
|
110 |
dev->power.can_wakeup = capable; |
eb9d0fe40
|
111 |
} |
228c54ef7
|
112 |
static inline bool device_can_wakeup(struct device *dev) |
9a3df1f7d
|
113 114 115 |
{ return dev->power.can_wakeup; } |
074037ec7
|
116 |
static inline struct wakeup_source *wakeup_source_create(const char *name) |
9a3df1f7d
|
117 |
{ |
074037ec7
|
118 |
return NULL; |
9a3df1f7d
|
119 |
} |
074037ec7
|
120 121 122 |
static inline void wakeup_source_destroy(struct wakeup_source *ws) {} static inline void wakeup_source_add(struct wakeup_source *ws) {} |
9a3df1f7d
|
123 |
|
074037ec7
|
124 |
static inline void wakeup_source_remove(struct wakeup_source *ws) {} |
c8377adfa
|
125 126 |
static inline struct wakeup_source *wakeup_source_register(struct device *dev, const char *name) |
9a3df1f7d
|
127 |
{ |
074037ec7
|
128 |
return NULL; |
9a3df1f7d
|
129 |
} |
074037ec7
|
130 131 132 |
static inline void wakeup_source_unregister(struct wakeup_source *ws) {} static inline int device_wakeup_enable(struct device *dev) |
228c54ef7
|
133 |
{ |
805bdaec1
|
134 135 |
dev->power.should_wakeup = true; return 0; |
228c54ef7
|
136 |
} |
c300bd2fb
|
137 |
|
074037ec7
|
138 |
static inline int device_wakeup_disable(struct device *dev) |
9a3df1f7d
|
139 |
{ |
805bdaec1
|
140 |
dev->power.should_wakeup = false; |
074037ec7
|
141 |
return 0; |
9a3df1f7d
|
142 |
} |
805bdaec1
|
143 |
static inline int device_set_wakeup_enable(struct device *dev, bool enable) |
228c54ef7
|
144 |
{ |
805bdaec1
|
145 146 |
dev->power.should_wakeup = enable; return 0; |
228c54ef7
|
147 |
} |
805bdaec1
|
148 149 150 151 152 153 |
static inline int device_init_wakeup(struct device *dev, bool val) { device_set_wakeup_capable(dev, val); device_set_wakeup_enable(dev, val); return 0; } |
074037ec7
|
154 |
|
805bdaec1
|
155 |
static inline bool device_may_wakeup(struct device *dev) |
228c54ef7
|
156 |
{ |
805bdaec1
|
157 |
return dev->power.can_wakeup && dev->power.should_wakeup; |
228c54ef7
|
158 |
} |
9a3df1f7d
|
159 |
|
cf04ce784
|
160 |
static inline void device_set_wakeup_path(struct device *dev) {} |
074037ec7
|
161 162 163 164 165 166 167 |
static inline void __pm_stay_awake(struct wakeup_source *ws) {} static inline void pm_stay_awake(struct device *dev) {} static inline void __pm_relax(struct wakeup_source *ws) {} static inline void pm_relax(struct device *dev) {} |
8a537ece3
|
168 169 |
static inline void pm_wakeup_ws_event(struct wakeup_source *ws, unsigned int msec, bool hard) {} |
074037ec7
|
170 |
|
8a537ece3
|
171 172 |
static inline void pm_wakeup_dev_event(struct device *dev, unsigned int msec, bool hard) {} |
074037ec7
|
173 174 |
#endif /* !CONFIG_PM_SLEEP */ |
9a3df1f7d
|
175 |
|
8a537ece3
|
176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
static inline void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec) { return pm_wakeup_ws_event(ws, msec, false); } static inline void pm_wakeup_event(struct device *dev, unsigned int msec) { return pm_wakeup_dev_event(dev, msec, false); } static inline void pm_wakeup_hard_event(struct device *dev) { return pm_wakeup_dev_event(dev, 0, true); } |
9a3df1f7d
|
190 |
#endif /* _LINUX_PM_WAKEUP_H */ |