• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef _LINUX_WAKELOCK_H
17 #define _LINUX_WAKELOCK_H
18 
19 #include <linux/ktime.h>
20 #include <linux/device.h>
21 
22 /* A wake_lock prevents the system from entering suspend or other low power
23  * states when active. If the type is set to WAKE_LOCK_SUSPEND, the wake_lock
24  * prevents a full system suspend.
25  */
26 
27 enum {
28     WAKE_LOCK_SUSPEND, /* Prevent suspend */
29     WAKE_LOCK_TYPE_COUNT
30 };
31 
32 struct wake_lock {
33     struct wakeup_source ws;
34 };
35 
wake_lock_init(struct wake_lock * lock,int type,const char * name)36 static inline void wake_lock_init(struct wake_lock *lock, int type, const char *name)
37 {
38     struct wakeup_source *ws = &lock->ws;
39 
40     if (ws) {
41         memset(ws, 0, sizeof(*ws));
42         ws->name = name;
43     }
44     wakeup_source_add(ws);
45 }
46 
wake_lock_destroy(struct wake_lock * lock)47 static inline void wake_lock_destroy(struct wake_lock *lock)
48 {
49     struct wakeup_source *ws = &lock->ws;
50 
51     wakeup_source_remove(ws);
52     __pm_relax(ws);
53 }
54 
wake_lock(struct wake_lock * lock)55 static inline void wake_lock(struct wake_lock *lock)
56 {
57     __pm_stay_awake(&lock->ws);
58 }
59 
wake_lock_timeout(struct wake_lock * lock,long timeout)60 static inline void wake_lock_timeout(struct wake_lock *lock, long timeout)
61 {
62     __pm_wakeup_event(&lock->ws, jiffies_to_msecs(timeout));
63 }
64 
wake_unlock(struct wake_lock * lock)65 static inline void wake_unlock(struct wake_lock *lock)
66 {
67     __pm_relax(&lock->ws);
68 }
69 
wake_lock_active(struct wake_lock * lock)70 static inline int wake_lock_active(struct wake_lock *lock)
71 {
72     return lock->ws.active;
73 }
74 
75 #endif
76