consoleearlysuspend.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* 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. #include <linux/console.h>
  16. #include <linux/earlysuspend.h>
  17. #include <linux/kbd_kern.h>
  18. #include <linux/module.h>
  19. #include <linux/vt_kern.h>
  20. #include <linux/wait.h>
  21. #define EARLY_SUSPEND_CONSOLE (MAX_NR_CONSOLES-1)
  22. static int orig_fgconsole;
  23. static void console_early_suspend(struct early_suspend *h)
  24. {
  25. acquire_console_sem();
  26. orig_fgconsole = fg_console;
  27. if (vc_allocate(EARLY_SUSPEND_CONSOLE))
  28. goto err;
  29. if (set_console(EARLY_SUSPEND_CONSOLE))
  30. goto err;
  31. release_console_sem();
  32. if (vt_waitactive(EARLY_SUSPEND_CONSOLE + 1))
  33. pr_warning("console_early_suspend: Can't switch VCs.\n");
  34. return;
  35. err:
  36. pr_warning("console_early_suspend: Can't set console\n");
  37. release_console_sem();
  38. }
  39. static void console_late_resume(struct early_suspend *h)
  40. {
  41. int ret;
  42. acquire_console_sem();
  43. ret = set_console(orig_fgconsole);
  44. release_console_sem();
  45. if (ret) {
  46. pr_warning("console_late_resume: Can't set console.\n");
  47. return;
  48. }
  49. if (vt_waitactive(orig_fgconsole + 1))
  50. pr_warning("console_late_resume: Can't switch VCs.\n");
  51. }
  52. static struct early_suspend console_early_suspend_desc = {
  53. .level = EARLY_SUSPEND_LEVEL_STOP_DRAWING,
  54. .suspend = console_early_suspend,
  55. .resume = console_late_resume,
  56. };
  57. static int __init console_early_suspend_init(void)
  58. {
  59. register_early_suspend(&console_early_suspend_desc);
  60. return 0;
  61. }
  62. static void __exit console_early_suspend_exit(void)
  63. {
  64. unregister_early_suspend(&console_early_suspend_desc);
  65. }
  66. module_init(console_early_suspend_init);
  67. module_exit(console_early_suspend_exit);