diff options
Diffstat (limited to 'kernel/power')
| -rw-r--r-- | kernel/power/consoleearlysuspend.c | 78 | ||||
| -rw-r--r-- | kernel/power/earlysuspend.c | 187 | ||||
| -rw-r--r-- | kernel/power/fbearlysuspend.c | 153 | ||||
| -rw-r--r-- | kernel/power/suspend_time.c | 111 | ||||
| -rw-r--r-- | kernel/power/userwakelock.c | 219 |
5 files changed, 748 insertions, 0 deletions
diff --git a/kernel/power/consoleearlysuspend.c b/kernel/power/consoleearlysuspend.c new file mode 100644 index 00000000000..a3edcb26738 --- /dev/null +++ b/kernel/power/consoleearlysuspend.c | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | /* kernel/power/consoleearlysuspend.c | ||
| 2 | * | ||
| 3 | * Copyright (C) 2005-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 | #include <linux/console.h> | ||
| 17 | #include <linux/earlysuspend.h> | ||
| 18 | #include <linux/kbd_kern.h> | ||
| 19 | #include <linux/module.h> | ||
| 20 | #include <linux/vt_kern.h> | ||
| 21 | #include <linux/wait.h> | ||
| 22 | |||
| 23 | #define EARLY_SUSPEND_CONSOLE (MAX_NR_CONSOLES-1) | ||
| 24 | |||
| 25 | static int orig_fgconsole; | ||
| 26 | static void console_early_suspend(struct early_suspend *h) | ||
| 27 | { | ||
| 28 | acquire_console_sem(); | ||
| 29 | orig_fgconsole = fg_console; | ||
| 30 | if (vc_allocate(EARLY_SUSPEND_CONSOLE)) | ||
| 31 | goto err; | ||
| 32 | if (set_console(EARLY_SUSPEND_CONSOLE)) | ||
| 33 | goto err; | ||
| 34 | release_console_sem(); | ||
| 35 | |||
| 36 | if (vt_waitactive(EARLY_SUSPEND_CONSOLE + 1)) | ||
| 37 | pr_warning("console_early_suspend: Can't switch VCs.\n"); | ||
| 38 | return; | ||
| 39 | err: | ||
| 40 | pr_warning("console_early_suspend: Can't set console\n"); | ||
| 41 | release_console_sem(); | ||
| 42 | } | ||
| 43 | |||
| 44 | static void console_late_resume(struct early_suspend *h) | ||
| 45 | { | ||
| 46 | int ret; | ||
| 47 | acquire_console_sem(); | ||
| 48 | ret = set_console(orig_fgconsole); | ||
| 49 | release_console_sem(); | ||
| 50 | if (ret) { | ||
| 51 | pr_warning("console_late_resume: Can't set console.\n"); | ||
| 52 | return; | ||
| 53 | } | ||
| 54 | |||
| 55 | if (vt_waitactive(orig_fgconsole + 1)) | ||
| 56 | pr_warning("console_late_resume: Can't switch VCs.\n"); | ||
| 57 | } | ||
| 58 | |||
| 59 | static struct early_suspend console_early_suspend_desc = { | ||
| 60 | .level = EARLY_SUSPEND_LEVEL_STOP_DRAWING, | ||
| 61 | .suspend = console_early_suspend, | ||
| 62 | .resume = console_late_resume, | ||
| 63 | }; | ||
| 64 | |||
| 65 | static int __init console_early_suspend_init(void) | ||
| 66 | { | ||
| 67 | register_early_suspend(&console_early_suspend_desc); | ||
| 68 | return 0; | ||
| 69 | } | ||
| 70 | |||
| 71 | static void __exit console_early_suspend_exit(void) | ||
| 72 | { | ||
| 73 | unregister_early_suspend(&console_early_suspend_desc); | ||
| 74 | } | ||
| 75 | |||
| 76 | module_init(console_early_suspend_init); | ||
| 77 | module_exit(console_early_suspend_exit); | ||
| 78 | |||
diff --git a/kernel/power/earlysuspend.c b/kernel/power/earlysuspend.c new file mode 100644 index 00000000000..b15f02eba45 --- /dev/null +++ b/kernel/power/earlysuspend.c | |||
| @@ -0,0 +1,187 @@ | |||
| 1 | /* kernel/power/earlysuspend.c | ||
| 2 | * | ||
| 3 | * Copyright (C) 2005-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 | #include <linux/earlysuspend.h> | ||
| 17 | #include <linux/module.h> | ||
| 18 | #include <linux/mutex.h> | ||
| 19 | #include <linux/rtc.h> | ||
| 20 | #include <linux/syscalls.h> /* sys_sync */ | ||
| 21 | #include <linux/wakelock.h> | ||
| 22 | #include <linux/workqueue.h> | ||
| 23 | |||
| 24 | #include "power.h" | ||
| 25 | |||
| 26 | enum { | ||
| 27 | DEBUG_USER_STATE = 1U << 0, | ||
| 28 | DEBUG_SUSPEND = 1U << 2, | ||
| 29 | DEBUG_VERBOSE = 1U << 3, | ||
| 30 | }; | ||
| 31 | static int debug_mask = DEBUG_USER_STATE; | ||
| 32 | module_param_named(debug_mask, debug_mask, int, S_IRUGO | S_IWUSR | S_IWGRP); | ||
| 33 | |||
| 34 | static DEFINE_MUTEX(early_suspend_lock); | ||
| 35 | static LIST_HEAD(early_suspend_handlers); | ||
| 36 | static void early_suspend(struct work_struct *work); | ||
| 37 | static void late_resume(struct work_struct *work); | ||
| 38 | static DECLARE_WORK(early_suspend_work, early_suspend); | ||
| 39 | static DECLARE_WORK(late_resume_work, late_resume); | ||
| 40 | static DEFINE_SPINLOCK(state_lock); | ||
| 41 | enum { | ||
| 42 | SUSPEND_REQUESTED = 0x1, | ||
| 43 | SUSPENDED = 0x2, | ||
| 44 | SUSPEND_REQUESTED_AND_SUSPENDED = SUSPEND_REQUESTED | SUSPENDED, | ||
| 45 | }; | ||
| 46 | static int state; | ||
| 47 | |||
| 48 | void register_early_suspend(struct early_suspend *handler) | ||
| 49 | { | ||
| 50 | struct list_head *pos; | ||
| 51 | |||
| 52 | mutex_lock(&early_suspend_lock); | ||
| 53 | list_for_each(pos, &early_suspend_handlers) { | ||
| 54 | struct early_suspend *e; | ||
| 55 | e = list_entry(pos, struct early_suspend, link); | ||
| 56 | if (e->level > handler->level) | ||
| 57 | break; | ||
| 58 | } | ||
| 59 | list_add_tail(&handler->link, pos); | ||
| 60 | if ((state & SUSPENDED) && handler->suspend) | ||
| 61 | handler->suspend(handler); | ||
| 62 | mutex_unlock(&early_suspend_lock); | ||
| 63 | } | ||
| 64 | EXPORT_SYMBOL(register_early_suspend); | ||
| 65 | |||
| 66 | void unregister_early_suspend(struct early_suspend *handler) | ||
| 67 | { | ||
| 68 | mutex_lock(&early_suspend_lock); | ||
| 69 | list_del(&handler->link); | ||
| 70 | mutex_unlock(&early_suspend_lock); | ||
| 71 | } | ||
| 72 | EXPORT_SYMBOL(unregister_early_suspend); | ||
| 73 | |||
| 74 | static void early_suspend(struct work_struct *work) | ||
| 75 | { | ||
| 76 | struct early_suspend *pos; | ||
| 77 | unsigned long irqflags; | ||
| 78 | int abort = 0; | ||
| 79 | |||
| 80 | mutex_lock(&early_suspend_lock); | ||
| 81 | spin_lock_irqsave(&state_lock, irqflags); | ||
| 82 | if (state == SUSPEND_REQUESTED) | ||
| 83 | state |= SUSPENDED; | ||
| 84 | else | ||
| 85 | abort = 1; | ||
| 86 | spin_unlock_irqrestore(&state_lock, irqflags); | ||
| 87 | |||
| 88 | if (abort) { | ||
| 89 | if (debug_mask & DEBUG_SUSPEND) | ||
| 90 | pr_info("early_suspend: abort, state %d\n", state); | ||
| 91 | mutex_unlock(&early_suspend_lock); | ||
| 92 | goto abort; | ||
| 93 | } | ||
| 94 | |||
| 95 | if (debug_mask & DEBUG_SUSPEND) | ||
| 96 | pr_info("early_suspend: call handlers\n"); | ||
| 97 | list_for_each_entry(pos, &early_suspend_handlers, link) { | ||
| 98 | if (pos->suspend != NULL) { | ||
| 99 | if (debug_mask & DEBUG_VERBOSE) | ||
| 100 | pr_info("early_suspend: calling %pf\n", pos->suspend); | ||
| 101 | pos->suspend(pos); | ||
| 102 | } | ||
| 103 | } | ||
| 104 | mutex_unlock(&early_suspend_lock); | ||
| 105 | |||
| 106 | if (debug_mask & DEBUG_SUSPEND) | ||
| 107 | pr_info("early_suspend: sync\n"); | ||
| 108 | |||
| 109 | sys_sync(); | ||
| 110 | abort: | ||
| 111 | spin_lock_irqsave(&state_lock, irqflags); | ||
| 112 | if (state == SUSPEND_REQUESTED_AND_SUSPENDED) | ||
| 113 | wake_unlock(&main_wake_lock); | ||
| 114 | spin_unlock_irqrestore(&state_lock, irqflags); | ||
| 115 | } | ||
| 116 | |||
| 117 | static void late_resume(struct work_struct *work) | ||
| 118 | { | ||
| 119 | struct early_suspend *pos; | ||
| 120 | unsigned long irqflags; | ||
| 121 | int abort = 0; | ||
| 122 | |||
| 123 | mutex_lock(&early_suspend_lock); | ||
| 124 | spin_lock_irqsave(&state_lock, irqflags); | ||
| 125 | if (state == SUSPENDED) | ||
| 126 | state &= ~SUSPENDED; | ||
| 127 | else | ||
| 128 | abort = 1; | ||
| 129 | spin_unlock_irqrestore(&state_lock, irqflags); | ||
| 130 | |||
| 131 | if (abort) { | ||
| 132 | if (debug_mask & DEBUG_SUSPEND) | ||
| 133 | pr_info("late_resume: abort, state %d\n", state); | ||
| 134 | goto abort; | ||
