at v5.2 6.0 kB view raw
1/* SPDX-License-Identifier: GPL-2.0-or-later */ 2/* 3 * pm_wakeup.h - Power management wakeup interface 4 * 5 * Copyright (C) 2008 Alan Stern 6 * Copyright (C) 2010 Rafael J. Wysocki, Novell Inc. 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 * struct wakeup_source - Representation of wakeup sources 22 * 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 * @has_timeout: The wakeup source has been activated with a timeout. 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 * Changes to device_may_wakeup take effect on the next pm state change. 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/* drivers/base/power/wakeup.c */ 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 /* !CONFIG_PM_SLEEP */ 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 /* !CONFIG_PM_SLEEP */ 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 /* _LINUX_PM_WAKEUP_H */