Arve Hjønnevåg | ec81142 | 2008-09-26 22:10:56 -0700 | [diff] [blame] | 1 | /* 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 | |
| 29 | enum { |
| 30 | WAKE_LOCK_SUSPEND, /* Prevent suspend */ |
| 31 | WAKE_LOCK_IDLE, /* Prevent low power idle */ |
| 32 | WAKE_LOCK_TYPE_COUNT |
| 33 | }; |
| 34 | |
| 35 | struct wake_lock { |
| 36 | #ifdef CONFIG_HAS_WAKELOCK |
| 37 | struct list_head link; |
| 38 | int flags; |
| 39 | const char *name; |
| 40 | unsigned long expires; |
| 41 | #ifdef CONFIG_WAKELOCK_STAT |
| 42 | struct { |
| 43 | int count; |
| 44 | int expire_count; |
| 45 | int wakeup_count; |
| 46 | ktime_t total_time; |
| 47 | ktime_t prevent_suspend_time; |
| 48 | ktime_t max_time; |
| 49 | ktime_t last_time; |
| 50 | } stat; |
| 51 | #endif |
| 52 | #endif |
| 53 | }; |
| 54 | |
| 55 | #ifdef CONFIG_HAS_WAKELOCK |
| 56 | |
| 57 | void wake_lock_init(struct wake_lock *lock, int type, const char *name); |
| 58 | void wake_lock_destroy(struct wake_lock *lock); |
| 59 | void wake_lock(struct wake_lock *lock); |
| 60 | void wake_lock_timeout(struct wake_lock *lock, long timeout); |
| 61 | void wake_unlock(struct wake_lock *lock); |
| 62 | |
| 63 | /* wake_lock_active returns a non-zero value if the wake_lock is currently |
| 64 | * locked. If the wake_lock has a timeout, it does not check the timeout |
| 65 | * but if the timeout had aready been checked it will return 0. |
| 66 | */ |
| 67 | int wake_lock_active(struct wake_lock *lock); |
| 68 | |
| 69 | /* has_wake_lock returns 0 if no wake locks of the specified type are active, |
| 70 | * and non-zero if one or more wake locks are held. Specifically it returns |
| 71 | * -1 if one or more wake locks with no timeout are active or the |
| 72 | * number of jiffies until all active wake locks time out. |
| 73 | */ |
| 74 | long has_wake_lock(int type); |
| 75 | |
| 76 | #else |
| 77 | |
| 78 | static inline void wake_lock_init(struct wake_lock *lock, int type, |
| 79 | const char *name) {} |
| 80 | static inline void wake_lock_destroy(struct wake_lock *lock) {} |
| 81 | static inline void wake_lock(struct wake_lock *lock) {} |
| 82 | static inline void wake_lock_timeout(struct wake_lock *lock, long timeout) {} |
| 83 | static inline void wake_unlock(struct wake_lock *lock) {} |
| 84 | |
| 85 | static inline int wake_lock_active(struct wake_lock *lock) { return 0; } |
| 86 | static inline long has_wake_lock(int type) { return 0; } |
| 87 | |
| 88 | #endif |
| 89 | |
| 90 | #endif |
| 91 | |