1 /* include/linux/wakelock.h
3 * Copyright (C) 2007-2008 Google, Inc.
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.
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.
16 #ifndef _LINUX_WAKELOCK_H
17 #define _LINUX_WAKELOCK_H
19 #include <linux/list.h>
20 #include <linux/ktime.h>
21 #ifdef CONFIG_PM_AUTOSLEEP
22 #include <linux/device.h>
25 /* A wake_lock prevents the system from entering suspend or other low power
26 * states when active. If the type is set to WAKE_LOCK_SUSPEND, the wake_lock
27 * prevents a full system suspend. If the type is WAKE_LOCK_IDLE, low power
28 * states that cause large interrupt latencies or that disable a set of
29 * interrupts will not entered from idle until the wake_locks are released.
33 WAKE_LOCK_SUSPEND, /* Prevent suspend */
34 WAKE_LOCK_IDLE, /* Prevent low power idle */
39 #ifdef CONFIG_HAS_WAKELOCK
40 struct list_head link;
43 unsigned long expires;
44 #ifdef CONFIG_WAKELOCK_STAT
50 ktime_t prevent_suspend_time;
56 struct wakeup_source ws;
60 #ifdef CONFIG_HAS_WAKELOCK
62 void wake_lock_init(struct wake_lock *lock, int type, const char *name);
63 void wake_lock_destroy(struct wake_lock *lock);
64 void wake_lock(struct wake_lock *lock);
65 void wake_lock_timeout(struct wake_lock *lock, long timeout);
66 void wake_unlock(struct wake_lock *lock);
68 /* wake_lock_active returns a non-zero value if the wake_lock is currently
69 * locked. If the wake_lock has a timeout, it does not check the timeout
70 * but if the timeout had aready been checked it will return 0.
72 int wake_lock_active(struct wake_lock *lock);
74 /* has_wake_lock returns 0 if no wake locks of the specified type are active,
75 * and non-zero if one or more wake locks are held. Specifically it returns
76 * -1 if one or more wake locks with no timeout are active or the
77 * number of jiffies until all active wake locks time out.
79 long has_wake_lock(int type);
83 #ifdef CONFIG_PM_AUTOSLEEP
84 static inline void wake_lock_init(struct wake_lock *lock, int type,
87 wakeup_source_init(&lock->ws, name);
90 static inline void wake_lock_destroy(struct wake_lock *lock)
92 wakeup_source_trash(&lock->ws);
95 static inline void wake_lock(struct wake_lock *lock)
97 __pm_stay_awake(&lock->ws);
100 static inline void wake_lock_timeout(struct wake_lock *lock, long timeout)
102 __pm_wakeup_event(&lock->ws, jiffies_to_msecs(timeout));
105 static inline void wake_unlock(struct wake_lock *lock)
107 __pm_relax(&lock->ws);
110 static inline int wake_lock_active(struct wake_lock *lock)
112 return lock->ws.active;
115 static inline void wake_lock_init(struct wake_lock *lock, int type,
117 static inline void wake_lock_destroy(struct wake_lock *lock) {}
118 static inline void wake_lock(struct wake_lock *lock) {}
119 static inline void wake_lock_timeout(struct wake_lock *lock, long timeout) {}
120 static inline void wake_unlock(struct wake_lock *lock) {}
122 static inline int wake_lock_active(struct wake_lock *lock) { return 0; }
124 static inline long has_wake_lock(int type) { return 0; }