1 From 0083b2afe89dea4a06bfd967b164318ad0bccd11 Mon Sep 17 00:00:00 2001
2 From: =?utf-8?q?Arve=20Hj=C3=B8nnev=C3=A5g?= <arve@android.com>
3 Date: Wed, 15 Oct 2008 17:52:20 -0700
4 Subject: [PATCH 071/134] PM: earlysuspend: Add console switch when user requested sleep state changes.
6 Content-Type: text/plain; charset=utf-8
7 Content-Transfer-Encoding: 8bit
9 Signed-off-by: Arve Hjønnevåg <arve@android.com>
11 kernel/power/Kconfig | 17 ++++++++
12 kernel/power/Makefile | 1 +
13 kernel/power/consoleearlysuspend.c | 78 ++++++++++++++++++++++++++++++++++++
14 3 files changed, 96 insertions(+), 0 deletions(-)
15 create mode 100644 kernel/power/consoleearlysuspend.c
17 --- a/kernel/power/Kconfig
18 +++ b/kernel/power/Kconfig
19 @@ -157,6 +157,23 @@ config EARLYSUSPEND
20 Call early suspend handlers when the user requested sleep state
24 + prompt "User-space screen access"
25 + default CONSOLE_EARLYSUSPEND
26 + depends on HAS_EARLYSUSPEND
28 + config NO_USER_SPACE_SCREEN_ACCESS_CONTROL
31 + config CONSOLE_EARLYSUSPEND
32 + bool "Console switch on early-suspend"
33 + depends on HAS_EARLYSUSPEND && VT
35 + Register early suspend handler to perform a console switch to
36 + when user-space should stop drawing to the screen and a switch
37 + back when it should resume.
41 bool "Hibernation (aka 'suspend to disk')"
42 depends on PM && SWAP && ARCH_HIBERNATION_POSSIBLE
43 --- a/kernel/power/Makefile
44 +++ b/kernel/power/Makefile
45 @@ -9,6 +9,7 @@ obj-$(CONFIG_FREEZER) += process.o
46 obj-$(CONFIG_WAKELOCK) += wakelock.o
47 obj-$(CONFIG_USER_WAKELOCK) += userwakelock.o
48 obj-$(CONFIG_EARLYSUSPEND) += earlysuspend.o
49 +obj-$(CONFIG_CONSOLE_EARLYSUSPEND) += consoleearlysuspend.o
50 obj-$(CONFIG_HIBERNATION) += swsusp.o disk.o snapshot.o swap.o user.o
52 obj-$(CONFIG_MAGIC_SYSRQ) += poweroff.o
54 +++ b/kernel/power/consoleearlysuspend.c
56 +/* kernel/power/consoleearlysuspend.c
58 + * Copyright (C) 2005-2008 Google, Inc.
60 + * This software is licensed under the terms of the GNU General Public
61 + * License version 2, as published by the Free Software Foundation, and
62 + * may be copied, distributed, and modified under those terms.
64 + * This program is distributed in the hope that it will be useful,
65 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
66 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67 + * GNU General Public License for more details.
71 +#include <linux/console.h>
72 +#include <linux/earlysuspend.h>
73 +#include <linux/kbd_kern.h>
74 +#include <linux/module.h>
75 +#include <linux/vt_kern.h>
76 +#include <linux/wait.h>
78 +#define EARLY_SUSPEND_CONSOLE (MAX_NR_CONSOLES-1)
80 +static int orig_fgconsole;
81 +static void console_early_suspend(struct early_suspend *h)
83 + acquire_console_sem();
84 + orig_fgconsole = fg_console;
85 + if (vc_allocate(EARLY_SUSPEND_CONSOLE))
87 + if (set_console(EARLY_SUSPEND_CONSOLE))
89 + release_console_sem();
91 + if (vt_waitactive(EARLY_SUSPEND_CONSOLE))
92 + pr_warning("console_early_suspend: Can't switch VCs.\n");
95 + pr_warning("console_early_suspend: Can't set console\n");
96 + release_console_sem();
99 +static void console_late_resume(struct early_suspend *h)
102 + acquire_console_sem();
103 + ret = set_console(orig_fgconsole);
104 + release_console_sem();
106 + pr_warning("console_late_resume: Can't set console.\n");
110 + if (vt_waitactive(orig_fgconsole))
111 + pr_warning("console_late_resume: Can't switch VCs.\n");
114 +static struct early_suspend console_early_suspend_desc = {
115 + .level = EARLY_SUSPEND_LEVEL_STOP_DRAWING,
116 + .suspend = console_early_suspend,
117 + .resume = console_late_resume,
120 +static int __init console_early_suspend_init(void)
122 + register_early_suspend(&console_early_suspend_desc);
126 +static void __exit console_early_suspend_exit(void)
128 + unregister_early_suspend(&console_early_suspend_desc);
131 +module_init(console_early_suspend_init);
132 +module_exit(console_early_suspend_exit);