• 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,
37 				  const char *name)
38 {
39 	struct wakeup_source *ws = &lock->ws;
40 
41 	if (ws) {
42 		memset(ws, 0, sizeof(*ws));
43 		ws->name = name;
44 	}
45 	wakeup_source_add(ws);
46 }
47 
wake_lock_destroy(struct wake_lock * lock)48 static inline void wake_lock_destroy(struct wake_lock *lock)
49 {
50 	struct wakeup_source *ws = &lock->ws;
51 
52 	wakeup_source_remove(ws);
53 	__pm_relax(ws);
54 }
55 
wake_lock(struct wake_lock * lock)56 static inline void wake_lock(struct wake_lock *lock)
57 {
58 	__pm_stay_awake(&lock->ws);
59 }
60 
wake_lock_timeout(struct wake_lock * lock,long timeout)61 static inline void wake_lock_timeout(struct wake_lock *lock, long timeout)
62 {
63 	__pm_wakeup_event(&lock->ws, jiffies_to_msecs(timeout));
64 }
65 
wake_unlock(struct wake_lock * lock)66 static inline void wake_unlock(struct wake_lock *lock)
67 {
68 	__pm_relax(&lock->ws);
69 }
70 
wake_lock_active(struct wake_lock * lock)71 static inline int wake_lock_active(struct wake_lock *lock)
72 {
73 	return lock->ws.active;
74 }
75 
76 #endif
77