Blame view

include/linux/pm_wakeup.h 6.11 KB
1a59d1b8e   Thomas Gleixner   treewide: Replace...
1
  /* SPDX-License-Identifier: GPL-2.0-or-later */
9a3df1f7d   Alan Stern   PM: Convert wakeu...
2
3
4
5
  /*
   *  pm_wakeup.h - Power management wakeup interface
   *
   *  Copyright (C) 2008 Alan Stern
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
6
   *  Copyright (C) 2010 Rafael J. Wysocki, Novell Inc.
9a3df1f7d   Alan Stern   PM: Convert wakeu...
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   Dmitry Torokhov   PM: pm_wakeup - s...
15
  #include <linux/types.h>
4990d4fe3   Tony Lindgren   PM / Wakeirq: Add...
16
  struct wake_irq;
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
17
18
  /**
   * struct wakeup_source - Representation of wakeup sources
2430d12c9   Alan Stern   PM: describe kern...
19
   *
4990d4fe3   Tony Lindgren   PM / Wakeirq: Add...
20
   * @name: Name of the wakeup source
c8377adfa   Tri Vo   PM / wakeup: Show...
21
   * @id: Wakeup source id
4990d4fe3   Tony Lindgren   PM / Wakeirq: Add...
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   Rafael J. Wysocki   PM / Wakeup: Intr...
27
28
   * @total_time: Total time this wakeup source has been active.
   * @max_time: Maximum time this wakeup source has been continuously active.
30e3ce6dc   Rafael J. Wysocki   PM / Sleep: Chang...
29
   * @last_time: Monotonic clock when the wakeup source's was touched last time.
55850945e   Rafael J. Wysocki   PM / Sleep: Add "...
30
   * @prevent_sleep_time: Total time this source has been preventing autosleep.
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
31
   * @event_count: Number of signaled wakeup events.
1258ca805   Chanwoo Choi   PM / Sleep: Fix c...
32
33
   * @active_count: Number of times the wakeup source was activated.
   * @relax_count: Number of times the wakeup source was deactivated.
30e3ce6dc   Rafael J. Wysocki   PM / Sleep: Chang...
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   Tri Vo   PM / wakeup: Show...
36
   * @dev: Struct device for sysfs statistics about the wakeup source.
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
37
   * @active: Status of the wakeup source.
e9bea8f98   Rafael J. Wysocki   PM: sleep: Update...
38
   * @autosleep_enabled: Autosleep is active, so update @prevent_sleep_time.
9a3df1f7d   Alan Stern   PM: Convert wakeu...
39
   */
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
40
  struct wakeup_source {
8671bbc1b   Rafael J. Wysocki   PM / Sleep: Add m...
41
  	const char 		*name;
c8377adfa   Tri Vo   PM / wakeup: Show...
42
  	int			id;
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
43
44
  	struct list_head	entry;
  	spinlock_t		lock;
4990d4fe3   Tony Lindgren   PM / Wakeirq: Add...
45
  	struct wake_irq		*wakeirq;
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
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   Rafael J. Wysocki   PM / Sleep: Add "...
51
52
  	ktime_t start_prevent_time;
  	ktime_t prevent_sleep_time;
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
53
54
55
  	unsigned long		event_count;
  	unsigned long		active_count;
  	unsigned long		relax_count;
30e3ce6dc   Rafael J. Wysocki   PM / Sleep: Chang...
56
57
  	unsigned long		expire_count;
  	unsigned long		wakeup_count;
c8377adfa   Tri Vo   PM / wakeup: Show...
58
  	struct device		*dev;
30e3ce6dc   Rafael J. Wysocki   PM / Sleep: Chang...
59
  	bool			active:1;
55850945e   Rafael J. Wysocki   PM / Sleep: Add "...
60
  	bool			autosleep_enabled:1;
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
61
  };
b4941adb2   Ran Wang   PM: wakeup: Add r...
62
63
64
65
  #define for_each_wakeup_source(ws) \
  	for ((ws) = wakeup_sources_walk_start();	\
  	     (ws);					\
  	     (ws) = wakeup_sources_walk_next((ws)))
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
66
67
68
69
70
  #ifdef CONFIG_PM_SLEEP
  
  /*
   * Changes to device_may_wakeup take effect on the next pm state change.
   */
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
71
72
73
74
  static inline bool device_can_wakeup(struct device *dev)
  {
  	return dev->power.can_wakeup;
  }
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
75
  static inline bool device_may_wakeup(struct device *dev)
9a3df1f7d   Alan Stern   PM: Convert wakeu...
76
  {
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
77
  	return dev->power.can_wakeup && !!dev->power.wakeup;
9a3df1f7d   Alan Stern   PM: Convert wakeu...
78
  }
cf04ce784   Ulf Hansson   PM / wakeup: Add ...
79
80
81
82
  static inline void device_set_wakeup_path(struct device *dev)
  {
  	dev->power.wakeup_path = true;
  }
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
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   Tri Vo   PM / wakeup: Show...
88
89
  extern struct wakeup_source *wakeup_source_register(struct device *dev,
  						    const char *name);
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
90
  extern void wakeup_source_unregister(struct wakeup_source *ws);
b4941adb2   Ran Wang   PM: wakeup: Add r...
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   Rafael J. Wysocki   PM / Wakeup: Intr...
95
96
  extern int device_wakeup_enable(struct device *dev);
  extern int device_wakeup_disable(struct device *dev);
cb8f51bda   Rafael J. Wysocki   PM: Do not create...
97
  extern void device_set_wakeup_capable(struct device *dev, bool capable);
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
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   Rafael J. Wysocki   PM / wakeup: Inte...
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   Rafael J. Wysocki   PM / Wakeup: Intr...
106
107
  
  #else /* !CONFIG_PM_SLEEP */
228c54ef7   Dmitry Torokhov   PM: pm_wakeup - s...
108
  static inline void device_set_wakeup_capable(struct device *dev, bool capable)
eb9d0fe40   Rafael J. Wysocki   PCI ACPI: Rework ...
109
  {
228c54ef7   Dmitry Torokhov   PM: pm_wakeup - s...
110
  	dev->power.can_wakeup = capable;
eb9d0fe40   Rafael J. Wysocki   PCI ACPI: Rework ...
111
  }
228c54ef7   Dmitry Torokhov   PM: pm_wakeup - s...
112
  static inline bool device_can_wakeup(struct device *dev)
9a3df1f7d   Alan Stern   PM: Convert wakeu...
113
114
115
  {
  	return dev->power.can_wakeup;
  }
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
116
  static inline struct wakeup_source *wakeup_source_create(const char *name)
9a3df1f7d   Alan Stern   PM: Convert wakeu...
117
  {
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
118
  	return NULL;
9a3df1f7d   Alan Stern   PM: Convert wakeu...
119
  }
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
120
121
122
  static inline void wakeup_source_destroy(struct wakeup_source *ws) {}
  
  static inline void wakeup_source_add(struct wakeup_source *ws) {}
9a3df1f7d   Alan Stern   PM: Convert wakeu...
123

074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
124
  static inline void wakeup_source_remove(struct wakeup_source *ws) {}
c8377adfa   Tri Vo   PM / wakeup: Show...
125
126
  static inline struct wakeup_source *wakeup_source_register(struct device *dev,
  							   const char *name)
9a3df1f7d   Alan Stern   PM: Convert wakeu...
127
  {
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
128
  	return NULL;
9a3df1f7d   Alan Stern   PM: Convert wakeu...
129
  }
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
130
131
132
  static inline void wakeup_source_unregister(struct wakeup_source *ws) {}
  
  static inline int device_wakeup_enable(struct device *dev)
228c54ef7   Dmitry Torokhov   PM: pm_wakeup - s...
133
  {
805bdaec1   Rafael J. Wysocki   PM: Make ACPI wak...
134
135
  	dev->power.should_wakeup = true;
  	return 0;
228c54ef7   Dmitry Torokhov   PM: pm_wakeup - s...
136
  }
c300bd2fb   Stephen Rothwell   PCI: include linu...
137

074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
138
  static inline int device_wakeup_disable(struct device *dev)
9a3df1f7d   Alan Stern   PM: Convert wakeu...
139
  {
805bdaec1   Rafael J. Wysocki   PM: Make ACPI wak...
140
  	dev->power.should_wakeup = false;
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
141
  	return 0;
9a3df1f7d   Alan Stern   PM: Convert wakeu...
142
  }
805bdaec1   Rafael J. Wysocki   PM: Make ACPI wak...
143
  static inline int device_set_wakeup_enable(struct device *dev, bool enable)
228c54ef7   Dmitry Torokhov   PM: pm_wakeup - s...
144
  {
805bdaec1   Rafael J. Wysocki   PM: Make ACPI wak...
145
146
  	dev->power.should_wakeup = enable;
  	return 0;
228c54ef7   Dmitry Torokhov   PM: pm_wakeup - s...
147
  }
805bdaec1   Rafael J. Wysocki   PM: Make ACPI wak...
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   Rafael J. Wysocki   PM / Wakeup: Intr...
154

805bdaec1   Rafael J. Wysocki   PM: Make ACPI wak...
155
  static inline bool device_may_wakeup(struct device *dev)
228c54ef7   Dmitry Torokhov   PM: pm_wakeup - s...
156
  {
805bdaec1   Rafael J. Wysocki   PM: Make ACPI wak...
157
  	return dev->power.can_wakeup && dev->power.should_wakeup;
228c54ef7   Dmitry Torokhov   PM: pm_wakeup - s...
158
  }
9a3df1f7d   Alan Stern   PM: Convert wakeu...
159

cf04ce784   Ulf Hansson   PM / wakeup: Add ...
160
  static inline void device_set_wakeup_path(struct device *dev) {}
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
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   Rafael J. Wysocki   PM / wakeup: Inte...
168
169
  static inline void pm_wakeup_ws_event(struct wakeup_source *ws,
  				      unsigned int msec, bool hard) {}
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
170

8a537ece3   Rafael J. Wysocki   PM / wakeup: Inte...
171
172
  static inline void pm_wakeup_dev_event(struct device *dev, unsigned int msec,
  				       bool hard) {}
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
173
174
  
  #endif /* !CONFIG_PM_SLEEP */
9a3df1f7d   Alan Stern   PM: Convert wakeu...
175

8a537ece3   Rafael J. Wysocki   PM / wakeup: Inte...
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   Alan Stern   PM: Convert wakeu...
190
  #endif /* _LINUX_PM_WAKEUP_H */