nfc_wakelock.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * NFC Wakelock
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. */
  10. #ifndef _NFC_WAKELOCK_H
  11. #define _NFC_WAKELOCK_H
  12. #include <linux/ktime.h>
  13. #include <linux/device.h>
  14. #include <linux/version.h>
  15. #define wake_lock_init(a, b, c) nfc_wake_lock_init(a, c)
  16. #define wake_lock_destroy(a) nfc_wake_lock_destroy(a)
  17. #define wake_lock_timeout(a, b) nfc_wake_lock_timeout(a, b)
  18. #define wake_lock_active(a) nfc_wake_lock_active(a)
  19. #define wake_lock(a) nfc_wake_lock(a)
  20. #define wake_unlock(a) nfc_wake_unlock(a)
  21. struct nfc_wake_lock {
  22. struct wakeup_source *ws;
  23. };
  24. static inline void nfc_wake_lock_init(struct nfc_wake_lock *lock, const char *name)
  25. {
  26. #if CONFIG_SEC_NFC_WAKELOCK_METHOD == 2
  27. lock->ws = wakeup_source_register(NULL, name);
  28. #elif (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0)) || CONFIG_SEC_NFC_WAKELOCK_METHOD == 1
  29. wakeup_source_init(lock->ws, name); /* 4.19 R */
  30. if (!(lock->ws)) {
  31. lock->ws = wakeup_source_create(name); /* 4.19 Q */
  32. if (lock->ws)
  33. wakeup_source_add(lock->ws);
  34. }
  35. #else
  36. lock->ws = wakeup_source_register(NULL, name); /* 5.4 R */
  37. #endif
  38. }
  39. static inline void nfc_wake_lock_destroy(struct nfc_wake_lock *lock)
  40. {
  41. if (lock->ws)
  42. wakeup_source_unregister(lock->ws);
  43. }
  44. static inline void nfc_wake_lock(struct nfc_wake_lock *lock)
  45. {
  46. if (lock->ws)
  47. __pm_stay_awake(lock->ws);
  48. }
  49. static inline void nfc_wake_lock_timeout(struct nfc_wake_lock *lock, long timeout)
  50. {
  51. if (lock->ws)
  52. __pm_wakeup_event(lock->ws, jiffies_to_msecs(timeout));
  53. }
  54. static inline void nfc_wake_unlock(struct nfc_wake_lock *lock)
  55. {
  56. if (lock->ws)
  57. __pm_relax(lock->ws);
  58. }
  59. static inline int nfc_wake_lock_active(struct nfc_wake_lock *lock)
  60. {
  61. return lock->ws->active;
  62. }
  63. #endif