Blame view

include/linux/pm_wakeup.h 5.92 KB
9a3df1f7d   Alan Stern   PM: Convert wakeu...
1
2
3
4
  /*
   *  pm_wakeup.h - Power management wakeup interface
   *
   *  Copyright (C) 2008 Alan Stern
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
5
   *  Copyright (C) 2010 Rafael J. Wysocki, Novell Inc.
9a3df1f7d   Alan Stern   PM: Convert wakeu...
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
   *
   *  This program is free software; you can redistribute it and/or modify
   *  it under the terms of the GNU General Public License as published by
   *  the Free Software Foundation; either version 2 of the License, or
   *  (at your option) any later version.
   *
   *  This program is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU General Public License for more details.
   *
   *  You should have received a copy of the GNU General Public License
   *  along with this program; if not, write to the Free Software
   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
  
  #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...
28
  #include <linux/types.h>
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
29
30
  /**
   * struct wakeup_source - Representation of wakeup sources
2430d12c9   Alan Stern   PM: describe kern...
31
   *
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
32
33
   * @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...
34
   * @last_time: Monotonic clock when the wakeup source's was touched last time.
55850945e   Rafael J. Wysocki   PM / Sleep: Add "...
35
   * @prevent_sleep_time: Total time this source has been preventing autosleep.
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
36
   * @event_count: Number of signaled wakeup events.
1258ca805   Chanwoo Choi   PM / Sleep: Fix c...
37
38
   * @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...
39
40
   * @expire_count: Number of times the wakeup source's timeout has expired.
   * @wakeup_count: Number of times the wakeup source might abort suspend.
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
41
   * @active: Status of the wakeup source.
30e3ce6dc   Rafael J. Wysocki   PM / Sleep: Chang...
42
   * @has_timeout: The wakeup source has been activated with a timeout.
9a3df1f7d   Alan Stern   PM: Convert wakeu...
43
   */
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
44
  struct wakeup_source {
8671bbc1b   Rafael J. Wysocki   PM / Sleep: Add m...
45
  	const char 		*name;
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
46
47
48
49
50
51
52
  	struct list_head	entry;
  	spinlock_t		lock;
  	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 "...
53
54
  	ktime_t start_prevent_time;
  	ktime_t prevent_sleep_time;
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
55
56
57
  	unsigned long		event_count;
  	unsigned long		active_count;
  	unsigned long		relax_count;
30e3ce6dc   Rafael J. Wysocki   PM / Sleep: Chang...
58
59
60
  	unsigned long		expire_count;
  	unsigned long		wakeup_count;
  	bool			active:1;
55850945e   Rafael J. Wysocki   PM / Sleep: Add "...
61
  	bool			autosleep_enabled:1;
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
62
63
64
65
66
67
68
  };
  
  #ifdef CONFIG_PM_SLEEP
  
  /*
   * Changes to device_may_wakeup take effect on the next pm state change.
   */
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
69
70
71
72
  static inline bool device_can_wakeup(struct device *dev)
  {
  	return dev->power.can_wakeup;
  }
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
73
  static inline bool device_may_wakeup(struct device *dev)
9a3df1f7d   Alan Stern   PM: Convert wakeu...
74
  {
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
75
  	return dev->power.can_wakeup && !!dev->power.wakeup;
9a3df1f7d   Alan Stern   PM: Convert wakeu...
76
  }
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
77
  /* drivers/base/power/wakeup.c */
8671bbc1b   Rafael J. Wysocki   PM / Sleep: Add m...
78
  extern void wakeup_source_prepare(struct wakeup_source *ws, const char *name);
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
79
  extern struct wakeup_source *wakeup_source_create(const char *name);
8671bbc1b   Rafael J. Wysocki   PM / Sleep: Add m...
80
  extern void wakeup_source_drop(struct wakeup_source *ws);
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
81
82
83
84
85
86
87
  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);
  extern struct wakeup_source *wakeup_source_register(const char *name);
  extern void wakeup_source_unregister(struct wakeup_source *ws);
  extern int device_wakeup_enable(struct device *dev);
  extern int device_wakeup_disable(struct device *dev);
cb8f51bda   Rafael J. Wysocki   PM: Do not create...
88
  extern void device_set_wakeup_capable(struct device *dev, bool capable);
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
89
90
91
92
93
94
95
96
97
98
  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);
  extern void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec);
  extern void pm_wakeup_event(struct device *dev, unsigned int msec);
  
  #else /* !CONFIG_PM_SLEEP */
228c54ef7   Dmitry Torokhov   PM: pm_wakeup - s...
99
  static inline void device_set_wakeup_capable(struct device *dev, bool capable)
eb9d0fe40   Rafael J. Wysocki   PCI ACPI: Rework ...
100
  {
228c54ef7   Dmitry Torokhov   PM: pm_wakeup - s...
101
  	dev->power.can_wakeup = capable;
eb9d0fe40   Rafael J. Wysocki   PCI ACPI: Rework ...
102
  }
228c54ef7   Dmitry Torokhov   PM: pm_wakeup - s...
103
  static inline bool device_can_wakeup(struct device *dev)
9a3df1f7d   Alan Stern   PM: Convert wakeu...
104
105
106
  {
  	return dev->power.can_wakeup;
  }
8671bbc1b   Rafael J. Wysocki   PM / Sleep: Add m...
107
108
  static inline void wakeup_source_prepare(struct wakeup_source *ws,
  					 const char *name) {}
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
109
  static inline struct wakeup_source *wakeup_source_create(const char *name)
9a3df1f7d   Alan Stern   PM: Convert wakeu...
110
  {
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
111
  	return NULL;
9a3df1f7d   Alan Stern   PM: Convert wakeu...
112
  }
8671bbc1b   Rafael J. Wysocki   PM / Sleep: Add m...
113
  static inline void wakeup_source_drop(struct wakeup_source *ws) {}
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
114
115
116
  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...
117

074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
118
119
120
  static inline void wakeup_source_remove(struct wakeup_source *ws) {}
  
  static inline struct wakeup_source *wakeup_source_register(const char *name)
9a3df1f7d   Alan Stern   PM: Convert wakeu...
121
  {
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
122
  	return NULL;
9a3df1f7d   Alan Stern   PM: Convert wakeu...
123
  }
074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
124
125
126
  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...
127
  {
805bdaec1   Rafael J. Wysocki   PM: Make ACPI wak...
128
129
  	dev->power.should_wakeup = true;
  	return 0;
228c54ef7   Dmitry Torokhov   PM: pm_wakeup - s...
130
  }
c300bd2fb   Stephen Rothwell   PCI: include linu...
131

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

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

074037ec7   Rafael J. Wysocki   PM / Wakeup: Intr...
154
155
156
157
158
159
160
161
162
163
164
165
166
  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) {}
  
  static inline void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec) {}
  
  static inline void pm_wakeup_event(struct device *dev, unsigned int msec) {}
  
  #endif /* !CONFIG_PM_SLEEP */
9a3df1f7d   Alan Stern   PM: Convert wakeu...
167

8671bbc1b   Rafael J. Wysocki   PM / Sleep: Add m...
168
169
170
171
172
173
174
175
176
177
178
179
  static inline void wakeup_source_init(struct wakeup_source *ws,
  				      const char *name)
  {
  	wakeup_source_prepare(ws, name);
  	wakeup_source_add(ws);
  }
  
  static inline void wakeup_source_trash(struct wakeup_source *ws)
  {
  	wakeup_source_remove(ws);
  	wakeup_source_drop(ws);
  }
9a3df1f7d   Alan Stern   PM: Convert wakeu...
180
  #endif /* _LINUX_PM_WAKEUP_H */