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 | { |
Arve Hjønnevåg | c8bb315 | 2008-10-15 17:52:20 -0700 | [diff] [blame] | 28 | orig_fgconsole = fg_console; |
| 29 | if (vc_allocate(EARLY_SUSPEND_CONSOLE)) |
| 30 | goto err; |
| 31 | if (set_console(EARLY_SUSPEND_CONSOLE)) |
| 32 | goto err; |
Arve Hjønnevåg | c8bb315 | 2008-10-15 17:52:20 -0700 | [diff] [blame] | 33 | |
Arve Hjønnevåg | b28a6a1 | 2009-12-14 22:14:52 -0800 | [diff] [blame] | 34 | if (vt_waitactive(EARLY_SUSPEND_CONSOLE + 1)) |
Arve Hjønnevåg | c8bb315 | 2008-10-15 17:52:20 -0700 | [diff] [blame] | 35 | pr_warning("console_early_suspend: Can't switch VCs.\n"); |
| 36 | return; |
| 37 | err: |
| 38 | pr_warning("console_early_suspend: Can't set console\n"); |
Arve Hjønnevåg | c8bb315 | 2008-10-15 17:52:20 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | static void console_late_resume(struct early_suspend *h) |
| 42 | { |
| 43 | int ret; |
Arve Hjønnevåg | c8bb315 | 2008-10-15 17:52:20 -0700 | [diff] [blame] | 44 | ret = set_console(orig_fgconsole); |
Arve Hjønnevåg | c8bb315 | 2008-10-15 17:52:20 -0700 | [diff] [blame] | 45 | if (ret) { |
| 46 | pr_warning("console_late_resume: Can't set console.\n"); |
| 47 | return; |
| 48 | } |
| 49 | |
Arve Hjønnevåg | b28a6a1 | 2009-12-14 22:14:52 -0800 | [diff] [blame] | 50 | if (vt_waitactive(orig_fgconsole + 1)) |
Arve Hjønnevåg | c8bb315 | 2008-10-15 17:52:20 -0700 | [diff] [blame] | 51 | pr_warning("console_late_resume: Can't switch VCs.\n"); |
| 52 | } |
| 53 | |
| 54 | static struct early_suspend console_early_suspend_desc = { |
| 55 | .level = EARLY_SUSPEND_LEVEL_STOP_DRAWING, |
| 56 | .suspend = console_early_suspend, |
| 57 | .resume = console_late_resume, |
| 58 | }; |
| 59 | |
| 60 | static int __init console_early_suspend_init(void) |
| 61 | { |
| 62 | register_early_suspend(&console_early_suspend_desc); |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | static void __exit console_early_suspend_exit(void) |
| 67 | { |
| 68 | unregister_early_suspend(&console_early_suspend_desc); |
| 69 | } |
| 70 | |
| 71 | module_init(console_early_suspend_init); |
| 72 | module_exit(console_early_suspend_exit); |
| 73 | |