pm_wakeup.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. /**
  28. * struct wakeup_source - Representation of wakeup sources
  29. *
  30. * @total_time: Total time this wakeup source has been active.
  31. * @max_time: Maximum time this wakeup source has been continuously active.
  32. * @last_time: Monotonic clock when the wakeup source's was touched last time.
  33. * @prevent_sleep_time: Total time this source has been preventing autosleep.
  34. * @event_count: Number of signaled wakeup events.
  35. * @active_count: Number of times the wakeup sorce was activated.
  36. * @relax_count: Number of times the wakeup sorce was deactivated.
  37. * @expire_count: Number of times the wakeup source's timeout has expired.
  38. * @wakeup_count: Number of times the wakeup source might abort suspend.
  39. * @active: Status of the wakeup source.
  40. * @has_timeout: The wakeup source has been activated with a timeout.
  41. */
  42. struct wakeup_source {
  43. const char *name;
  44. struct list_head entry;
  45. spinlock_t lock;
  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. #ifdef CONFIG_PM_SLEEP
  62. /*
  63. * Changes to device_may_wakeup take effect on the next pm state change.
  64. */
  65. static inline bool device_can_wakeup(struct device *dev)
  66. {
  67. return dev->power.can_wakeup;
  68. }
  69. static inline bool device_may_wakeup(struct device *dev)
  70. {
  71. return dev->power.can_wakeup && !!dev->power.wakeup;
  72. }
  73. /* drivers/base/power/wakeup.c */
  74. extern void wakeup_source_prepare(struct wakeup_source *ws, const char *name);
  75. extern struct wakeup_source *wakeup_source_create(const char *name);
  76. extern void wakeup_source_drop(struct wakeup_source *ws);
  77. extern void wakeup_source_destroy(struct wakeup_source *ws);
  78. extern void wakeup_source_add(struct wakeup_source *ws);
  79. extern void wakeup_source_remove(struct wakeup_source *ws);
  80. extern struct wakeup_source *wakeup_source_register(const char *name);
  81. extern void wakeup_source_unregister(struct wakeup_source *ws);
  82. extern int device_wakeup_enable(struct device *dev);
  83. extern int device_wakeup_disable(struct device *dev);
  84. extern void device_set_wakeup_capable(struct device *dev, bool capable);
  85. extern int device_init_wakeup(struct device *dev, bool val);
  86. extern int device_set_wakeup_enable(struct device *dev, bool enable);
  87. extern void __pm_stay_awake(struct wakeup_source *ws);
  88. extern void pm_stay_awake(struct device *dev);
  89. extern void __pm_relax(struct wakeup_source *ws);
  90. extern void pm_relax(struct device *dev);
  91. extern void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec);
  92. extern void pm_wakeup_event(struct device *dev, unsigned int msec);
  93. #else /* !CONFIG_PM_SLEEP */
  94. static inline void device_set_wakeup_capable(struct device *dev, bool capable)
  95. {
  96. dev->power.can_wakeup = capable;
  97. }
  98. static inline bool device_can_wakeup(struct device *dev)
  99. {
  100. return dev->power.can_wakeup;
  101. }
  102. static inline void wakeup_source_prepare(struct wakeup_source *ws,
  103. const char *name) {}
  104. static inline struct wakeup_source *wakeup_source_create(const char *name)
  105. {
  106. return NULL;
  107. }
  108. static inline void wakeup_source_drop(struct wakeup_source *ws) {}
  109. static inline void wakeup_source_destroy(struct wakeup_source *ws) {}
  110. static inline void wakeup_source_add(struct wakeup_source *ws) {}
  111. static inline void wakeup_source_remove(struct wakeup_source *ws) {}
  112. static inline struct wakeup_source *wakeup_source_register(const char *name)
  113. {
  114. return NULL;
  115. }
  116. static inline void wakeup_source_unregister(struct wakeup_source *ws) {}
  117. static inline int device_wakeup_enable(struct device *dev)
  118. {
  119. dev->power.should_wakeup = true;
  120. return 0;
  121. }
  122. static inline int device_wakeup_disable(struct device *dev)
  123. {
  124. dev->power.should_wakeup = false;
  125. return 0;
  126. }
  127. static inline int device_set_wakeup_enable(struct device *dev, bool enable)
  128. {
  129. dev->power.should_wakeup = enable;
  130. return 0;
  131. }
  132. static inline int device_init_wakeup(struct device *dev, bool val)
  133. {
  134. device_set_wakeup_capable(dev, val);
  135. device_set_wakeup_enable(dev, val);
  136. return 0;
  137. }
  138. static inline bool device_may_wakeup(struct device *dev)
  139. {
  140. return dev->power.can_wakeup && dev->power.should_wakeup;
  141. }
  142. static inline void __pm_stay_awake(struct wakeup_source *ws) {}
  143. static inline void pm_stay_awake(struct device *dev) {}
  144. static inline void __pm_relax(struct wakeup_source *ws) {}
  145. static inline void pm_relax(struct device *dev) {}
  146. static inline void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec) {}
  147. static inline void pm_wakeup_event(struct device *dev, unsigned int msec) {}
  148. #endif /* !CONFIG_PM_SLEEP */
  149. static inline void wakeup_source_init(struct wakeup_source *ws,
  150. const char *name)
  151. {
  152. wakeup_source_prepare(ws, name);
  153. wakeup_source_add(ws);
  154. }
  155. static inline void wakeup_source_trash(struct wakeup_source *ws)
  156. {
  157. wakeup_source_remove(ws);
  158. wakeup_source_drop(ws);
  159. }
  160. #endif /* _LINUX_PM_WAKEUP_H */