1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * pm_wakeup.h - Power management wakeup interface
5 * Copyright (C) 2008 Alan Stern
6 * Copyright (C) 2010 Rafael J. Wysocki, Novell Inc.
9 #ifndef _LINUX_PM_WAKEUP_H
10 #define _LINUX_PM_WAKEUP_H
13 # error "please don't include this file directly"
16 #include <linux/types.h>
21 * struct wakeup_source - Representation of wakeup sources
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
29 * @total_time: Total time this wakeup source has been active.
30 * @max_time: Maximum time this wakeup source has been continuously active.
31 * @last_time: Monotonic clock when the wakeup source's was touched last time.
32 * @prevent_sleep_time: Total time this source has been preventing autosleep.
33 * @event_count: Number of signaled wakeup events.
34 * @active_count: Number of times the wakeup source was activated.
35 * @relax_count: Number of times the wakeup source was deactivated.
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.
38 * @active: Status of the wakeup source.
39 * @autosleep_enabled: Autosleep is active, so update @prevent_sleep_time.
41 struct wakeup_source
{
43 struct list_head entry
;
45 struct wake_irq
*wakeirq
;
46 struct timer_list timer
;
47 unsigned long timer_expires
;
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
;
59 bool autosleep_enabled
:1;
62 #ifdef CONFIG_PM_SLEEP
65 * Changes to device_may_wakeup take effect on the next pm state change.
68 static inline bool device_can_wakeup(struct device
*dev
)
70 return dev
->power
.can_wakeup
;
73 static inline bool device_may_wakeup(struct device
*dev
)
75 return dev
->power
.can_wakeup
&& !!dev
->power
.wakeup
;
78 static inline void device_set_wakeup_path(struct device
*dev
)
80 dev
->power
.wakeup_path
= true;
83 /* drivers/base/power/wakeup.c */
84 extern void wakeup_source_prepare(struct wakeup_source
*ws
, const char *name
);
85 extern struct wakeup_source
*wakeup_source_create(const char *name
);
86 extern void wakeup_source_destroy(struct wakeup_source
*ws
);
87 extern void wakeup_source_add(struct wakeup_source
*ws
);
88 extern void wakeup_source_remove(struct wakeup_source
*ws
);
89 extern struct wakeup_source
*wakeup_source_register(const char *name
);
90 extern void wakeup_source_unregister(struct wakeup_source
*ws
);
91 extern int device_wakeup_enable(struct device
*dev
);
92 extern int device_wakeup_disable(struct device
*dev
);
93 extern void device_set_wakeup_capable(struct device
*dev
, bool capable
);
94 extern int device_init_wakeup(struct device
*dev
, bool val
);
95 extern int device_set_wakeup_enable(struct device
*dev
, bool enable
);
96 extern void __pm_stay_awake(struct wakeup_source
*ws
);
97 extern void pm_stay_awake(struct device
*dev
);
98 extern void __pm_relax(struct wakeup_source
*ws
);
99 extern void pm_relax(struct device
*dev
);
100 extern void pm_wakeup_ws_event(struct wakeup_source
*ws
, unsigned int msec
, bool hard
);
101 extern void pm_wakeup_dev_event(struct device
*dev
, unsigned int msec
, bool hard
);
103 #else /* !CONFIG_PM_SLEEP */
105 static inline void device_set_wakeup_capable(struct device
*dev
, bool capable
)
107 dev
->power
.can_wakeup
= capable
;
110 static inline bool device_can_wakeup(struct device
*dev
)
112 return dev
->power
.can_wakeup
;
115 static inline void wakeup_source_prepare(struct wakeup_source
*ws
,
118 static inline struct wakeup_source
*wakeup_source_create(const char *name
)
123 static inline void wakeup_source_destroy(struct wakeup_source
*ws
) {}
125 static inline void wakeup_source_add(struct wakeup_source
*ws
) {}
127 static inline void wakeup_source_remove(struct wakeup_source
*ws
) {}
129 static inline struct wakeup_source
*wakeup_source_register(const char *name
)
134 static inline void wakeup_source_unregister(struct wakeup_source
*ws
) {}
136 static inline int device_wakeup_enable(struct device
*dev
)
138 dev
->power
.should_wakeup
= true;
142 static inline int device_wakeup_disable(struct device
*dev
)
144 dev
->power
.should_wakeup
= false;
148 static inline int device_set_wakeup_enable(struct device
*dev
, bool enable
)
150 dev
->power
.should_wakeup
= enable
;
154 static inline int device_init_wakeup(struct device
*dev
, bool val
)
156 device_set_wakeup_capable(dev
, val
);
157 device_set_wakeup_enable(dev
, val
);
161 static inline bool device_may_wakeup(struct device
*dev
)
163 return dev
->power
.can_wakeup
&& dev
->power
.should_wakeup
;
166 static inline void device_set_wakeup_path(struct device
*dev
) {}
168 static inline void __pm_stay_awake(struct wakeup_source
*ws
) {}
170 static inline void pm_stay_awake(struct device
*dev
) {}
172 static inline void __pm_relax(struct wakeup_source
*ws
) {}
174 static inline void pm_relax(struct device
*dev
) {}
176 static inline void pm_wakeup_ws_event(struct wakeup_source
*ws
,
177 unsigned int msec
, bool hard
) {}
179 static inline void pm_wakeup_dev_event(struct device
*dev
, unsigned int msec
,
182 #endif /* !CONFIG_PM_SLEEP */
184 static inline void wakeup_source_init(struct wakeup_source
*ws
,
187 wakeup_source_prepare(ws
, name
);
188 wakeup_source_add(ws
);
191 static inline void __pm_wakeup_event(struct wakeup_source
*ws
, unsigned int msec
)
193 return pm_wakeup_ws_event(ws
, msec
, false);
196 static inline void pm_wakeup_event(struct device
*dev
, unsigned int msec
)
198 return pm_wakeup_dev_event(dev
, msec
, false);
201 static inline void pm_wakeup_hard_event(struct device
*dev
)
203 return pm_wakeup_dev_event(dev
, 0, true);
206 #endif /* _LINUX_PM_WAKEUP_H */