pm_wakeup.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. 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 void device_set_wakeup_capable(struct device *dev, bool capable)
  59. {
  60. dev->power.can_wakeup = capable;
  61. }
  62. static inline bool device_can_wakeup(struct device *dev)
  63. {
  64. return dev->power.can_wakeup;
  65. }
  66. static inline bool device_may_wakeup(struct device *dev)
  67. {
  68. return dev->power.can_wakeup && !!dev->power.wakeup;
  69. }
  70. /* drivers/base/power/wakeup.c */
  71. extern struct wakeup_source *wakeup_source_create(const char *name);
  72. extern void wakeup_source_destroy(struct wakeup_source *ws);
  73. extern void wakeup_source_add(struct wakeup_source *ws);
  74. extern void wakeup_source_remove(struct wakeup_source *ws);
  75. extern struct wakeup_source *wakeup_source_register(const char *name);
  76. extern void wakeup_source_unregister(struct wakeup_source *ws);
  77. extern int device_wakeup_enable(struct device *dev);
  78. extern int device_wakeup_disable(struct device *dev);
  79. extern int device_init_wakeup(struct device *dev, bool val);
  80. extern int device_set_wakeup_enable(struct device *dev, bool enable);
  81. extern void __pm_stay_awake(struct wakeup_source *ws);
  82. extern void pm_stay_awake(struct device *dev);
  83. extern void __pm_relax(struct wakeup_source *ws);
  84. extern void pm_relax(struct device *dev);
  85. extern void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec);
  86. extern void pm_wakeup_event(struct device *dev, unsigned int msec);
  87. #else /* !CONFIG_PM_SLEEP */
  88. static inline void device_set_wakeup_capable(struct device *dev, bool capable)
  89. {
  90. dev->power.can_wakeup = capable;
  91. }
  92. static inline bool device_can_wakeup(struct device *dev)
  93. {
  94. return dev->power.can_wakeup;
  95. }
  96. static inline bool device_may_wakeup(struct device *dev)
  97. {
  98. return false;
  99. }
  100. static inline struct wakeup_source *wakeup_source_create(const char *name)
  101. {
  102. return NULL;
  103. }
  104. static inline void wakeup_source_destroy(struct wakeup_source *ws) {}
  105. static inline void wakeup_source_add(struct wakeup_source *ws) {}
  106. static inline void wakeup_source_remove(struct wakeup_source *ws) {}
  107. static inline struct wakeup_source *wakeup_source_register(const char *name)
  108. {
  109. return NULL;
  110. }
  111. static inline void wakeup_source_unregister(struct wakeup_source *ws) {}
  112. static inline int device_wakeup_enable(struct device *dev)
  113. {
  114. return -EINVAL;
  115. }
  116. static inline int device_wakeup_disable(struct device *dev)
  117. {
  118. return 0;
  119. }
  120. static inline int device_init_wakeup(struct device *dev, bool val)
  121. {
  122. dev->power.can_wakeup = val;
  123. return val ? -EINVAL : 0;
  124. }
  125. static inline int device_set_wakeup_enable(struct device *dev, bool enable)
  126. {
  127. return -EINVAL;
  128. }
  129. static inline void __pm_stay_awake(struct wakeup_source *ws) {}
  130. static inline void pm_stay_awake(struct device *dev) {}
  131. static inline void __pm_relax(struct wakeup_source *ws) {}
  132. static inline void pm_relax(struct device *dev) {}
  133. static inline void __pm_wakeup_event(struct wakeup_source *ws, unsigned int msec) {}
  134. static inline void pm_wakeup_event(struct device *dev, unsigned int msec) {}
  135. #endif /* !CONFIG_PM_SLEEP */
  136. #endif /* _LINUX_PM_WAKEUP_H */