blob: aedf4aad31c32b4174318bb96107d90be869e277 [file] [log] [blame]
Arve Hjønnevågc8bb3152008-10-15 17:52:20 -07001/* 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
25static int orig_fgconsole;
26static void console_early_suspend(struct early_suspend *h)
27{
Arve Hjønnevågc8bb3152008-10-15 17:52:20 -070028 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ågc8bb3152008-10-15 17:52:20 -070033
Arve Hjønnevågb28a6a12009-12-14 22:14:52 -080034 if (vt_waitactive(EARLY_SUSPEND_CONSOLE + 1))
Arve Hjønnevågc8bb3152008-10-15 17:52:20 -070035 pr_warning("console_early_suspend: Can't switch VCs.\n");
36 return;
37err:
38 pr_warning("console_early_suspend: Can't set console\n");
Arve Hjønnevågc8bb3152008-10-15 17:52:20 -070039}
40
41static void console_late_resume(struct early_suspend *h)
42{
43 int ret;
Arve Hjønnevågc8bb3152008-10-15 17:52:20 -070044 ret = set_console(orig_fgconsole);
Arve Hjønnevågc8bb3152008-10-15 17:52:20 -070045 if (ret) {
46 pr_warning("console_late_resume: Can't set console.\n");
47 return;
48 }
49
Arve Hjønnevågb28a6a12009-12-14 22:14:52 -080050 if (vt_waitactive(orig_fgconsole + 1))
Arve Hjønnevågc8bb3152008-10-15 17:52:20 -070051 pr_warning("console_late_resume: Can't switch VCs.\n");
52}
53
54static 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
60static int __init console_early_suspend_init(void)
61{
62 register_early_suspend(&console_early_suspend_desc);
63 return 0;
64}
65
66static void __exit console_early_suspend_exit(void)
67{
68 unregister_early_suspend(&console_early_suspend_desc);
69}
70
71module_init(console_early_suspend_init);
72module_exit(console_early_suspend_exit);
73