Branch data Line data Source code
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 : :
36 : : static inline void wake_lock_init(struct wake_lock *lock, int type,
37 : : const char *name)
38 : : {
39 : 0 : wakeup_source_init(&lock->ws, name);
40 : : }
41 : :
42 : : static inline void wake_lock_destroy(struct wake_lock *lock)
43 : : {
44 : 0 : wakeup_source_trash(&lock->ws);
45 : : }
46 : :
47 : : static inline void wake_lock(struct wake_lock *lock)
48 : : {
49 : 32934 : __pm_stay_awake(&lock->ws);
50 : : }
51 : :
52 : : static inline void wake_lock_timeout(struct wake_lock *lock, long timeout)
53 : : {
54 : 0 : __pm_wakeup_event(&lock->ws, jiffies_to_msecs(timeout));
55 : : }
56 : :
57 : : static inline void wake_unlock(struct wake_lock *lock)
58 : : {
59 : 32934 : __pm_relax(&lock->ws);
60 : : }
61 : :
62 : : static inline int wake_lock_active(struct wake_lock *lock)
63 : : {
64 : : return lock->ws.active;
65 : : }
66 : :
67 : : #endif
|