blob: 024b913a8de28b48db182f6ac0f2f58c8929e2db [file] [log] [blame]
Arve Hjønnevågec811422008-09-26 22:10:56 -07001/* include/linux/wakelock.h
2 *
3 * Copyright (C) 2007-2008 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/list.h>
20#include <linux/ktime.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. 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.
27 */
28
29enum {
30 WAKE_LOCK_SUSPEND, /* Prevent suspend */
31 WAKE_LOCK_IDLE, /* Prevent low power idle */
32 WAKE_LOCK_TYPE_COUNT
33};
34
35struct wake_lock {
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
Arve Hjønnevågec811422008-09-26 22:10:56 -070051};
52
53#ifdef CONFIG_HAS_WAKELOCK
54
55void wake_lock_init(struct wake_lock *lock, int type, const char *name);
56void wake_lock_destroy(struct wake_lock *lock);
57void wake_lock(struct wake_lock *lock);
58void wake_lock_timeout(struct wake_lock *lock, long timeout);
59void wake_unlock(struct wake_lock *lock);
60
61/* wake_lock_active returns a non-zero value if the wake_lock is currently
62 * locked. If the wake_lock has a timeout, it does not check the timeout
63 * but if the timeout had aready been checked it will return 0.
64 */
65int wake_lock_active(struct wake_lock *lock);
66
67/* has_wake_lock returns 0 if no wake locks of the specified type are active,
68 * and non-zero if one or more wake locks are held. Specifically it returns
69 * -1 if one or more wake locks with no timeout are active or the
70 * number of jiffies until all active wake locks time out.
71 */
72long has_wake_lock(int type);
73
74#else
75
76static inline void wake_lock_init(struct wake_lock *lock, int type,
77 const char *name) {}
78static inline void wake_lock_destroy(struct wake_lock *lock) {}
79static inline void wake_lock(struct wake_lock *lock) {}
80static inline void wake_lock_timeout(struct wake_lock *lock, long timeout) {}
81static inline void wake_unlock(struct wake_lock *lock) {}
82
83static inline int wake_lock_active(struct wake_lock *lock) { return 0; }
84static inline long has_wake_lock(int type) { return 0; }
85
86#endif
87
88#endif
89