blob: 5b2d0f348ac6290f9997d07419c1a74730b51eb2 [file] [log] [blame]
Arve Hjønnevåge9911f42012-03-16 17:44:42 -07001/* include/linux/wakelock.h
2 *
Arve Hjønnevågec811422008-09-26 22:10:56 -07003 * Copyright (C) 2007-2008 Google, Inc.
Arve Hjønnevåge9911f42012-03-16 17:44:42 -07004 *
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
Arve Hjønnevågec811422008-09-26 22:10:56 -070019#include <linux/list.h>
Arve Hjønnevåge9911f42012-03-16 17:44:42 -070020#include <linux/ktime.h>
Arve Hjønnevåge9911f42012-03-16 17:44:42 -070021
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
Arve Hjønnevågec811422008-09-26 22:10:56 -070024 * prevents a full system suspend. If the type is WAKE_LOCK_IDLE, low power
25 * states that cause large interrupt latencies or that disable a set of
26 * interrupts will not entered from idle until the wake_locks are released.
Arve Hjønnevåge9911f42012-03-16 17:44:42 -070027 */
28
29enum {
30 WAKE_LOCK_SUSPEND, /* Prevent suspend */
31 WAKE_LOCK_TYPE_COUNT
32};
33
34struct wake_lock {
Steve Mucklef132c6c2012-06-06 18:30:57 -070035#ifdef CONFIG_HAS_WAKELOCK
Arve Hjønnevågec811422008-09-26 22:10:56 -070036 struct list_head link;
37 int flags;
38 const char *name;
39 unsigned long expires;
40#ifdef CONFIG_WAKELOCK_STAT
41 struct {
42 int count;
43 int expire_count;
44 int wakeup_count;
45 ktime_t total_time;
46 ktime_t prevent_suspend_time;
47 ktime_t max_time;
48 ktime_t last_time;
49 } stat;
50#endif
Steve Mucklef132c6c2012-06-06 18:30:57 -070051#endif
Arve Hjønnevåge9911f42012-03-16 17:44:42 -070052};
53
Arve Hjønnevågec811422008-09-26 22:10:56 -070054#ifdef CONFIG_HAS_WAKELOCK
55
56void wake_lock_init(struct wake_lock *lock, int type, const char *name);
57void wake_lock_destroy(struct wake_lock *lock);
58void wake_lock(struct wake_lock *lock);
59void wake_lock_timeout(struct wake_lock *lock, long timeout);
60void wake_unlock(struct wake_lock *lock);
61
62/* wake_lock_active returns a non-zero value if the wake_lock is currently
63 * locked. If the wake_lock has a timeout, it does not check the timeout
64 * but if the timeout had aready been checked it will return 0.
65 */
66int wake_lock_active(struct wake_lock *lock);
67
68/* has_wake_lock returns 0 if no wake locks of the specified type are active,
69 * and non-zero if one or more wake locks are held. Specifically it returns
70 * -1 if one or more wake locks with no timeout are active or the
71 * number of jiffies until all active wake locks time out.
72 */
73long has_wake_lock(int type);
74
75#else
76
Arve Hjønnevåge9911f42012-03-16 17:44:42 -070077static inline void wake_lock_init(struct wake_lock *lock, int type,
Arve Hjønnevågec811422008-09-26 22:10:56 -070078 const char *name) {}
79static inline void wake_lock_destroy(struct wake_lock *lock) {}
80static inline void wake_lock(struct wake_lock *lock) {}
81static inline void wake_lock_timeout(struct wake_lock *lock, long timeout) {}
82static inline void wake_unlock(struct wake_lock *lock) {}
Arve Hjønnevåge9911f42012-03-16 17:44:42 -070083
Arve Hjønnevågec811422008-09-26 22:10:56 -070084static inline int wake_lock_active(struct wake_lock *lock) { return 0; }
85static inline long has_wake_lock(int type) { return 0; }
Arve Hjønnevåge9911f42012-03-16 17:44:42 -070086
87#endif
Arve Hjønnevågec811422008-09-26 22:10:56 -070088
89#endif
90