1 /* include/linux/wakelock.h
3 * Copyright (C) 2007-2012 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/ktime.h>
20 #include <linux/device.h>
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.
28 WAKE_LOCK_SUSPEND, /* Prevent suspend */
33 struct wakeup_source ws;
36 static inline void wake_lock_init(struct wake_lock *lock, int type,
39 wakeup_source_init(&lock->ws, name);
42 static inline void wake_lock_destroy(struct wake_lock *lock)
44 wakeup_source_trash(&lock->ws);
47 static inline void wake_lock(struct wake_lock *lock)
49 __pm_stay_awake(&lock->ws);
52 static inline void wake_lock_timeout(struct wake_lock *lock, long timeout)
54 __pm_wakeup_event(&lock->ws, jiffies_to_msecs(timeout));
57 static inline void wake_unlock(struct wake_lock *lock)
59 __pm_relax(&lock->ws);
62 static inline int wake_lock_active(struct wake_lock *lock)
64 return lock->ws.active;