1 /* kernel/power/consoleearlysuspend.c
3 * Copyright (C) 2005-2008 Google, Inc.
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.
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.
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>
23 #define EARLY_SUSPEND_CONSOLE (MAX_NR_CONSOLES-1)
25 static int orig_fgconsole
;
26 static void console_early_suspend(struct early_suspend
*h
)
28 acquire_console_sem();
29 orig_fgconsole
= fg_console
;
30 if (vc_allocate(EARLY_SUSPEND_CONSOLE
))
32 if (set_console(EARLY_SUSPEND_CONSOLE
))
34 release_console_sem();
36 if (vt_waitactive(EARLY_SUSPEND_CONSOLE
+ 1))
37 pr_warning("console_early_suspend: Can't switch VCs.\n");
40 pr_warning("console_early_suspend: Can't set console\n");
41 release_console_sem();
44 static void console_late_resume(struct early_suspend
*h
)
47 acquire_console_sem();
48 ret
= set_console(orig_fgconsole
);
49 release_console_sem();
51 pr_warning("console_late_resume: Can't set console.\n");
55 if (vt_waitactive(orig_fgconsole
+ 1))
56 pr_warning("console_late_resume: Can't switch VCs.\n");
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
,
65 static int __init
console_early_suspend_init(void)
67 register_early_suspend(&console_early_suspend_desc
);
71 static void __exit
console_early_suspend_exit(void)
73 unregister_early_suspend(&console_early_suspend_desc
);
76 module_init(console_early_suspend_init
);
77 module_exit(console_early_suspend_exit
);