pm_wakeup.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * pm_wakeup.h - Power management wakeup interface
  3. *
  4. * Copyright (C) 2008 Alan Stern
  5. * Copyright (C) 2010 Rafael J. Wysocki, Novell Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #ifndef _LINUX_PM_WAKEUP_H
  22. #define _LINUX_PM_WAKEUP_H
  23. #ifndef _DEVICE_H_
  24. # error "please don't include this file directly"
  25. #endif
  26. #include <linux/types.h>
  27. struct wake_irq;
  28. /**
  29. * struct wakeup_source - Representation of wakeup sources
  30. *
  31. * @name: Name of the wakeup source
  32. * @entry: Wakeup source list entry
  33. * @lock: Wakeup source lock
  34. * @wakeirq: Optional device specific wakeirq
  35. * @timer: Wakeup timer list
  36. * @timer_expires: Wakeup timer expiration
  37. * @total_time: Total time this wakeup source has been active.
  38. * @max_time: Maximum time this wakeup source has been continuously active.
  39. * @last_time: Monotonic clock when the wakeup source's was touched last time.
  40. * @prevent_sleep_time: Total time this source has been preventing autosleep.
  41. * @event_count: Number of signaled wakeup events.
  42. * @active_count: Number of times the wakeup source was activated.
  43. * @relax_count: Number of times the wakeup source was deactivated.
  44. * @expire_count: Number of times the wakeup source's timeout has expired.
  45. * @wakeup_count: Number of times the wakeup source might abort suspend.
  46. * @active: Status of the wakeup source.
  47. * @has_timeout: The wakeup source has been activated with a timeout.
  48. */
  49. struct wakeup_source {
  50. const char *name;
  51. struct list_head entry;
  52. spinlock_t lock;
  53. struct wake_irq *wakeirq;
  54. struct timer_list timer;
  55. unsigned long timer_expires;
  56. ktime_t total_time;
  57. ktime_t max_time;
  58. ktime_t last_time;
  59. ktime_t start_prevent_time;
  60. ktime_t prevent_sleep_time;
  61. unsigned long event_count;
  62. unsigned long active_count;
  63. unsigned long relax_count;
  64. unsigned long expire_count;
  65. unsigned long wakeup_count;
  66. bool active:1;
  67. bool autosleep_enabled:1;
  68. };
  69. #ifdef CONFIG_PM_SLEEP
  70. /*
  71. * Changes to device_may_wakeup take effect on the next pm state change.
  72. */
  73. static inline bool device_can_wakeup(struct device *dev)
  74. {
  75. return dev->power.can_wakeup;
  76. }
  77. static inline bool device_may_wakeup(struct device *dev)
  78. {
  79. return dev->power.can_wakeup && !!dev->power.wakeup;
  80. }
  81. /* drivers/base/power/wakeup.c */
  82. extern void wakeup_source_prepare(struct wakeup_source *ws, const char *name);
  83. extern struct wakeup_source *wakeup_source_create(const char *name);
  84. extern void wakeup_source_drop(struct wakeup_source *ws);
  85. extern void wakeup_source_destroy(struct wakeup_source *ws);
  86. extern void wakeup_source_add(struct wakeup_source *ws);
  87. extern void wakeup_source_remove(struct wakeup_source *ws);
  88. extern struct wakeup_source *wakeup_source_register(const char *name);
  89. extern void wakeup_source_unregister(struct wakeup_source *ws);
  90. extern int device_wakeup_enable(struct device *dev);
  91. extern int device_wakeup_disable(struct device *dev);
  92. extern void device_set_wakeup_capable(struct device *dev, bool capable);
  93. extern int device_init_wakeup(struct device *dev, bool val);
  94. extern int device_set_wakeup_enable(struct device *dev, bool enable);
  95. extern void __pm_stay_awake(struct wakeup_source *ws);
  96. extern void pm_stay_awake(struct device *dev);
  97. extern void __pm_relax(struct wakeup_source *ws);
  98. extern void pm_relax(struct device *dev);
  99. extern void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec);
  100. extern void pm_wakeup_event(struct device *dev, unsigned int msec);
  101. #else /* !CONFIG_PM_SLEEP */
  102. static inline void device_set_wakeup_capable(struct device *dev, bool capable)
  103. {
  104. dev->power.can_wakeup = capable;
  105. }
  106. static inline bool device_can_wakeup(struct device *dev)
  107. {
  108. return dev->power.can_wakeup;
  109. }
  110. static inline void wakeup_source_prepare(struct wakeup_source *ws,
  111. const char *name) {}
  112. static inline struct wakeup_source *wakeup_source_create(const char *name)
  113. {
  114. return NULL;
  115. }
  116. static inline void wakeup_source_drop(struct wakeup_source *ws) {}
  117. static inline void wakeup_source_destroy(struct wakeup_source *ws) {}
  118. static inline void wakeup_source_add(struct wakeup_source *ws) {}
  119. static inline void wakeup_source_remove(struct wakeup_source *ws) {}
  120. static inline struct wakeup_source *wakeup_source_register(const char *name)
  121. {
  122. return NULL;
  123. }
  124. static inline void wakeup_source_unregister(struct wakeup_source *ws) {}
  125. static inline int device_wakeup_enable(struct device *dev)
  126. {
  127. dev->power.should_wakeup = true;
  128. return 0;
  129. }
  130. static inline int device_wakeup_disable(struct device *dev)
  131. {
  132. dev->power.should_wakeup = false;
  133. return 0;
  134. }
  135. static inline int device_set_wakeup_enable(struct device *dev, bool enable)
  136. {
  137. dev->power.should_wakeup = enable;
  138. return 0;
  139. }
  140. static inline int device_init_wakeup(struct device *dev, bool val)
  141. {
  142. device_set_wakeup_capable(dev, val);
  143. device_set_wakeup_enable(dev, val);
  144. return 0;
  145. }
  146. static inline bool device_may_wakeup(struct device *dev)
  147. {
  148. return dev->power.can_wakeup && dev->power.should_wakeup;
  149. }
  150. static inline void __pm_stay_awake(struct wakeup_source *ws) {}
  151. static inline void pm_stay_awake(struct device *dev) {}
  152. static inline void __pm_relax(struct wakeup_source *ws) {}
  153. static inline void pm_relax(struct device *dev) {}
  154. static inline void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec) {}
  155. static inline void pm_wakeup_event(struct device *dev, unsigned int msec) {}
  156. #endif /* !CONFIG_PM_SLEEP */
  157. static inline void wakeup_source_init(struct wakeup_source *ws,
  158. const char *name)
  159. {
  160. wakeup_source_prepare(ws, name);
  161. wakeup_source_add(ws);
  162. }
  163. static inline void wakeup_source_trash(struct wakeup_source *ws)
  164. {
  165. wakeup_source_remove(ws);
  166. wakeup_source_drop(ws);
  167. }
  168. #endif /* _LINUX_PM_WAKEUP_H */