Arve Hjønnevåg | c8bb315 | 2008-10-15 17:52:20 -0700 | [diff] [blame^] | 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)) |
| 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)) |
| 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 | |