wakelock.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* include/linux/wakelock.h
  2. *
  3. * Copyright (C) 2007-2012 Google, Inc.
  4. *
  5. * This software is licensed under the terms of the GNU General Public
  6. * License version 2, as published by the Free Software Foundation, and
  7. * may be copied, distributed, and modified under those terms.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. */
  15. #ifndef _LINUX_WAKELOCK_H
  16. #define _LINUX_WAKELOCK_H
  17. #include <linux/ktime.h>
  18. #include <linux/device.h>
  19. /* A wake_lock prevents the system from entering suspend or other low power
  20. * states when active. If the type is set to WAKE_LOCK_SUSPEND, the wake_lock
  21. * prevents a full system suspend.
  22. */
  23. enum {
  24. WAKE_LOCK_SUSPEND, /* Prevent suspend */
  25. WAKE_LOCK_TYPE_COUNT
  26. };
  27. struct wake_lock {
  28. struct wakeup_source ws;
  29. };
  30. static inline void wake_lock_init(struct wake_lock *lock, int type,
  31. const char *name)
  32. {
  33. wakeup_source_init(&lock->ws, name);
  34. }
  35. static inline void wake_lock_destroy(struct wake_lock *lock)
  36. {
  37. wakeup_source_trash(&lock->ws);
  38. }
  39. static inline void wake_lock(struct wake_lock *lock)
  40. {
  41. __pm_stay_awake(&lock->ws);
  42. }
  43. static inline void wake_lock_timeout(struct wake_lock *lock, long timeout)
  44. {
  45. __pm_wakeup_event(&lock->ws, jiffies_to_msecs(timeout));
  46. }
  47. static inline void wake_unlock(struct wake_lock *lock)
  48. {
  49. __pm_relax(&lock->ws);
  50. }
  51. static inline int wake_lock_active(struct wake_lock *lock)
  52. {
  53. return lock->ws.active;
  54. }
  55. #endif