Arve Hjønnevåg | e9911f4 | 2012-03-16 17:44:42 -0700 | [diff] [blame] | 1 | /* include/linux/wakelock.h |
| 2 | * |
Arve Hjønnevåg | 90cce09 | 2012-03-16 17:44:42 -0700 | [diff] [blame] | 3 | * Copyright (C) 2007-2012 Google, Inc. |
Arve Hjønnevåg | e9911f4 | 2012-03-16 17:44:42 -0700 | [diff] [blame] | 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/ktime.h> |
Arve Hjønnevåg | 90cce09 | 2012-03-16 17:44:42 -0700 | [diff] [blame] | 20 | #include <linux/device.h> |
Arve Hjønnevåg | e9911f4 | 2012-03-16 17:44:42 -0700 | [diff] [blame] | 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 |
Arve Hjønnevåg | 90cce09 | 2012-03-16 17:44:42 -0700 | [diff] [blame] | 24 | * prevents a full system suspend. |
Arve Hjønnevåg | e9911f4 | 2012-03-16 17:44:42 -0700 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | enum { |
| 28 | WAKE_LOCK_SUSPEND, /* Prevent suspend */ |
| 29 | WAKE_LOCK_TYPE_COUNT |
| 30 | }; |
| 31 | |
| 32 | struct wake_lock { |
Arve Hjønnevåg | 90cce09 | 2012-03-16 17:44:42 -0700 | [diff] [blame] | 33 | struct wakeup_source ws; |
Arve Hjønnevåg | e9911f4 | 2012-03-16 17:44:42 -0700 | [diff] [blame] | 34 | }; |
| 35 | |
| 36 | static inline void wake_lock_init(struct wake_lock *lock, int type, |
Arve Hjønnevåg | 90cce09 | 2012-03-16 17:44:42 -0700 | [diff] [blame] | 37 | const char *name) |
| 38 | { |
| 39 | wakeup_source_init(&lock->ws, name); |
| 40 | } |
Arve Hjønnevåg | e9911f4 | 2012-03-16 17:44:42 -0700 | [diff] [blame] | 41 | |
Arve Hjønnevåg | 90cce09 | 2012-03-16 17:44:42 -0700 | [diff] [blame] | 42 | static inline void wake_lock_destroy(struct wake_lock *lock) |
| 43 | { |
| 44 | wakeup_source_trash(&lock->ws); |
| 45 | } |
| 46 | |
| 47 | static inline void wake_lock(struct wake_lock *lock) |
| 48 | { |
| 49 | __pm_stay_awake(&lock->ws); |
| 50 | } |
| 51 | |
| 52 | static inline void wake_lock_timeout(struct wake_lock *lock, long timeout) |
| 53 | { |
| 54 | __pm_wakeup_event(&lock->ws, jiffies_to_msecs(timeout)); |
| 55 | } |
| 56 | |
| 57 | static inline void wake_unlock(struct wake_lock *lock) |
| 58 | { |
| 59 | __pm_relax(&lock->ws); |
| 60 | } |
| 61 | |
| 62 | static inline int wake_lock_active(struct wake_lock *lock) |
| 63 | { |
| 64 | return lock->ws.active; |
| 65 | } |
Arve Hjønnevåg | e9911f4 | 2012-03-16 17:44:42 -0700 | [diff] [blame] | 66 | |
| 67 | #endif |