pm_wakeup.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 activated last time.
  33. * @event_count: Number of signaled wakeup events.
  34. * @active_count: Number of times the wakeup sorce was activated.
  35. * @relax_count: Number of times the wakeup sorce was deactivated.
  36. * @hit_count: Number of times the wakeup sorce might abort system suspend.
  37. * @active: Status of the wakeup source.
  38. */
  39. struct wakeup_source {
  40. const char *name;
  41. struct list_head entry;
  42. spinlock_t lock;
  43. struct timer_list timer;
  44. unsigned long timer_expires;
  45. ktime_t total_time;
  46. ktime_t max_time;
  47. ktime_t last_time;
  48. unsigned long event_count;
  49. unsigned long active_count;
  50. unsigned long relax_count;
  51. unsigned long hit_count;
  52. unsigned int active:1;
  53. };
  54. #ifdef CONFIG_PM_SLEEP
  55. /*
  56. * Changes to device_may_wakeup take effect on the next pm state change.
  57. */
  58. static inline bool device_can_wakeup(struct device *dev)
  59. {
  60. return dev->power.can_wakeup;
  61. }
  62. static inline bool device_may_wakeup(struct device *dev)
  63. {
  64. return dev->power.can_wakeup && !!dev->power.wakeup;
  65. }
  66. /* drivers/base/power/wakeup.c */
  67. extern void wakeup_source_prepare(struct wakeup_source *ws, const char *name);
  68. extern struct wakeup_source *wakeup_source_create(const char *name);
  69. extern void wakeup_source_drop(struct wakeup_source *ws);
  70. extern void wakeup_source_destroy(struct wakeup_source *ws);
  71. extern void wakeup_source_add(struct wakeup_source *ws);
  72. extern void wakeup_source_remove(struct wakeup_source *ws);
  73. extern struct wakeup_source *wakeup_source_register(const char *name);
  74. extern void wakeup_source_unregister(struct wakeup_source *ws);
  75. extern int device_wakeup_enable(struct device *dev);
  76. extern int device_wakeup_disable(struct device *dev);
  77. extern void device_set_wakeup_capable(struct device *dev, bool capable);
  78. extern int device_init_wakeup(struct device *dev, bool val);
  79. extern int device_set_wakeup_enable(struct device *dev, bool enable);
  80. extern void __pm_stay_awake(struct wakeup_source *ws);
  81. extern void pm_stay_awake(struct device *dev);
  82. extern void __pm_relax(struct wakeup_source *ws);
  83. extern void pm_relax(struct device *dev);
  84. extern void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec);
  85. extern void pm_wakeup_event(struct device *dev, unsigned int msec);
  86. #else /* !CONFIG_PM_SLEEP */
  87. static inline void device_set_wakeup_capable(struct device *dev, bool capable)
  88. {
  89. dev->power.can_wakeup = capable;
  90. }
  91. static inline bool device_can_wakeup(struct device *dev)
  92. {
  93. return dev->power.can_wakeup;
  94. }
  95. static inline void wakeup_source_prepare(struct wakeup_source *ws,
  96. const char *name) {}
  97. static inline struct wakeup_source *wakeup_source_create(const char *name)
  98. {
  99. return NULL;
  100. }
  101. static inline void wakeup_source_drop(struct wakeup_source *ws) {}
  102. static inline void wakeup_source_destroy(struct wakeup_source *ws) {}
  103. static inline void wakeup_source_add(struct wakeup_source *ws) {}
  104. static inline void wakeup_source_remove(struct wakeup_source *ws) {}
  105. static inline struct wakeup_source *wakeup_source_register(const char *name)
  106. {
  107. return NULL;
  108. }
  109. static inline void wakeup_source_unregister(struct wakeup_source *ws) {}
  110. static inline int device_wakeup_enable(struct device *dev)
  111. {
  112. dev->power.should_wakeup = true;
  113. return 0;
  114. }
  115. static inline int device_wakeup_disable(struct device *dev)
  116. {
  117. dev->power.should_wakeup = false;
  118. return 0;
  119. }
  120. static inline int device_set_wakeup_enable(struct device *dev, bool enable)
  121. {
  122. dev->power.should_wakeup = enable;
  123. return 0;
  124. }
  125. static inline int device_init_wakeup(struct device *dev, bool val)
  126. {
  127. device_set_wakeup_capable(dev, val);
  128. device_set_wakeup_enable(dev, val);
  129. return 0;
  130. }
  131. static inline bool device_may_wakeup(struct device *dev)
  132. {
  133. return dev->power.can_wakeup && dev->power.should_wakeup;
  134. }
  135. static inline void __pm_stay_awake(struct wakeup_source *ws) {}
  136. static inline void pm_stay_awake(struct device *dev) {}
  137. static inline void __pm_relax(struct wakeup_source *ws) {}
  138. static inline void pm_relax(struct device *dev) {}
  139. static inline void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec) {}
  140. static inline void pm_wakeup_event(struct device *dev, unsigned int msec) {}
  141. #endif /* !CONFIG_PM_SLEEP */
  142. static inline void wakeup_source_init(struct wakeup_source *ws,
  143. const char *name)
  144. {
  145. wakeup_source_prepare(ws, name);
  146. wakeup_source_add(ws);
  147. }
  148. static inline void wakeup_source_trash(struct wakeup_source *ws)
  149. {
  150. wakeup_source_remove(ws);
  151. wakeup_source_drop(ws);
  152. }
  153. #endif /* _LINUX_PM_WAKEUP_H */