Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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> |
Andres Salomon | b6f448e | 2008-04-28 02:15:03 -0700 | [diff] [blame] | 10 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include "power.h" |
| 12 | |
Rafael J. Wysocki | 46cd2f3 | 2006-02-07 12:58:50 -0800 | [diff] [blame] | 13 | #if defined(CONFIG_VT) && defined(CONFIG_VT_CONSOLE) |
| 14 | #define SUSPEND_CONSOLE (MAX_NR_CONSOLES-1) |
| 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | static int orig_fgconsole, orig_kmsg; |
Andres Salomon | b6f448e | 2008-04-28 02:15:03 -0700 | [diff] [blame] | 17 | static int disable_vt_switch; |
| 18 | |
| 19 | /* |
| 20 | * Normally during a suspend, we allocate a new console and switch to it. |
| 21 | * When we resume, we switch back to the original console. This switch |
| 22 | * can be slow, so on systems where the framebuffer can handle restoration |
| 23 | * of video registers anyways, there's little point in doing the console |
| 24 | * switch. This function allows you to disable it by passing it '0'. |
| 25 | */ |
| 26 | void pm_set_vt_switch(int do_switch) |
| 27 | { |
| 28 | acquire_console_sem(); |
| 29 | disable_vt_switch = !do_switch; |
| 30 | release_console_sem(); |
| 31 | } |
| 32 | EXPORT_SYMBOL(pm_set_vt_switch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | |
| 34 | int pm_prepare_console(void) |
| 35 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | acquire_console_sem(); |
| 37 | |
Andres Salomon | b6f448e | 2008-04-28 02:15:03 -0700 | [diff] [blame] | 38 | if (disable_vt_switch) { |
| 39 | release_console_sem(); |
| 40 | return 0; |
| 41 | } |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | orig_fgconsole = fg_console; |
| 44 | |
| 45 | if (vc_allocate(SUSPEND_CONSOLE)) { |
| 46 | /* we can't have a free VC for now. Too bad, |
| 47 | * we don't want to mess the screen for now. */ |
| 48 | release_console_sem(); |
| 49 | return 1; |
| 50 | } |
| 51 | |
Andrew Johnson | b257bc0 | 2007-03-16 13:38:24 -0800 | [diff] [blame] | 52 | if (set_console(SUSPEND_CONSOLE)) { |
| 53 | /* |
| 54 | * We're unable to switch to the SUSPEND_CONSOLE. |
| 55 | * Let the calling function know so it can decide |
| 56 | * what to do. |
| 57 | */ |
| 58 | release_console_sem(); |
| 59 | return 1; |
| 60 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | release_console_sem(); |
| 62 | |
| 63 | if (vt_waitactive(SUSPEND_CONSOLE)) { |
| 64 | pr_debug("Suspend: Can't switch VCs."); |
| 65 | return 1; |
| 66 | } |
| 67 | orig_kmsg = kmsg_redirect; |
| 68 | kmsg_redirect = SUSPEND_CONSOLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | void pm_restore_console(void) |
| 73 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | acquire_console_sem(); |
Andres Salomon | b6f448e | 2008-04-28 02:15:03 -0700 | [diff] [blame] | 75 | if (disable_vt_switch) { |
| 76 | release_console_sem(); |
| 77 | return; |
| 78 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | set_console(orig_fgconsole); |
| 80 | release_console_sem(); |
Arve Hjønnevåg | b090f9f | 2009-02-14 02:06:17 +0100 | [diff] [blame] | 81 | |
| 82 | if (vt_waitactive(orig_fgconsole)) { |
| 83 | pr_debug("Resume: Can't switch VCs."); |
| 84 | return; |
| 85 | } |
| 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | kmsg_redirect = orig_kmsg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
Rafael J. Wysocki | f7b8988 | 2006-02-01 03:05:21 -0800 | [diff] [blame] | 89 | #endif |