blob: 623786d4415950b08c8fb6f3461bfb8c86c152b2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/power/process.c - Functions for saving/restoring console.
3 *
4 * Originally from swsusp.
5 */
6
7#include <linux/vt_kern.h>
8#include <linux/kbd_kern.h>
9#include <linux/console.h>
10#include "power.h"
11
Rafael J. Wysocki46cd2f32006-02-07 12:58:50 -080012#if defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE)
13#define SUSPEND_CONSOLE (MAX_NR_CONSOLES-1)
14
Linus Torvalds1da177e2005-04-16 15:20:36 -070015static int orig_fgconsole, orig_kmsg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17int pm_prepare_console(void)
18{
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 acquire_console_sem();
20
21 orig_fgconsole = fg_console;
22
23 if (vc_allocate(SUSPEND_CONSOLE)) {
24 /* we can't have a free VC for now. Too bad,
25 * we don't want to mess the screen for now. */
26 release_console_sem();
27 return 1;
28 }
29
30 set_console(SUSPEND_CONSOLE);
31 release_console_sem();
32
33 if (vt_waitactive(SUSPEND_CONSOLE)) {
34 pr_debug("Suspend: Can't switch VCs.");
35 return 1;
36 }
37 orig_kmsg = kmsg_redirect;
38 kmsg_redirect = SUSPEND_CONSOLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 return 0;
40}
41
42void pm_restore_console(void)
43{
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 acquire_console_sem();
45 set_console(orig_fgconsole);
46 release_console_sem();
47 kmsg_redirect = orig_kmsg;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 return;
49}
Rafael J. Wysockif7b89882006-02-01 03:05:21 -080050#endif