dummycon.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * linux/drivers/video/dummycon.c -- A dummy console driver
  3. *
  4. * To be used if there's no other console driver (e.g. for plain VGA text)
  5. * available, usually until fbcon takes console over.
  6. */
  7. #include <linux/types.h>
  8. #include <linux/kdev_t.h>
  9. #include <linux/console.h>
  10. #include <linux/vt_kern.h>
  11. #include <linux/screen_info.h>
  12. #include <linux/init.h>
  13. #include <linux/module.h>
  14. /*
  15. * Dummy console driver
  16. */
  17. #if defined(__arm__)
  18. #define DUMMY_COLUMNS screen_info.orig_video_cols
  19. #define DUMMY_ROWS screen_info.orig_video_lines
  20. #else
  21. /* set by Kconfig. Use 80x25 for 640x480 and 160x64 for 1280x1024 */
  22. #define DUMMY_COLUMNS CONFIG_DUMMY_CONSOLE_COLUMNS
  23. #define DUMMY_ROWS CONFIG_DUMMY_CONSOLE_ROWS
  24. #endif
  25. #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
  26. /* These are both protected by the console_lock */
  27. static RAW_NOTIFIER_HEAD(dummycon_output_nh);
  28. static bool dummycon_putc_called;
  29. void dummycon_register_output_notifier(struct notifier_block *nb)
  30. {
  31. raw_notifier_chain_register(&dummycon_output_nh, nb);
  32. if (dummycon_putc_called)
  33. nb->notifier_call(nb, 0, NULL);
  34. }
  35. void dummycon_unregister_output_notifier(struct notifier_block *nb)
  36. {
  37. raw_notifier_chain_unregister(&dummycon_output_nh, nb);
  38. }
  39. static void dummycon_putc(struct vc_data *vc, int c, int ypos, int xpos)
  40. {
  41. dummycon_putc_called = true;
  42. raw_notifier_call_chain(&dummycon_output_nh, 0, NULL);
  43. }
  44. static void dummycon_putcs(struct vc_data *vc, const unsigned short *s,
  45. int count, int ypos, int xpos)
  46. {
  47. int i;
  48. if (!dummycon_putc_called) {
  49. /* Ignore erases */
  50. for (i = 0 ; i < count; i++) {
  51. if (s[i] != vc->vc_video_erase_char)
  52. break;
  53. }
  54. if (i == count)
  55. return;
  56. dummycon_putc_called = true;
  57. }
  58. raw_notifier_call_chain(&dummycon_output_nh, 0, NULL);
  59. }
  60. static int dummycon_blank(struct vc_data *vc, int blank, int mode_switch)
  61. {
  62. /* Redraw, so that we get putc(s) for output done while blanked */
  63. return 1;
  64. }
  65. #else
  66. static void dummycon_putc(struct vc_data *vc, int c, int ypos, int xpos) { }
  67. static void dummycon_putcs(struct vc_data *vc, const unsigned short *s,
  68. int count, int ypos, int xpos) { }
  69. static int dummycon_blank(struct vc_data *vc, int blank, int mode_switch)
  70. {
  71. return 0;
  72. }
  73. #endif
  74. static const char *dummycon_startup(void)
  75. {
  76. return "dummy device";
  77. }
  78. static void dummycon_init(struct vc_data *vc, int init)
  79. {
  80. vc->vc_can_do_color = 1;
  81. if (init) {
  82. vc->vc_cols = DUMMY_COLUMNS;
  83. vc->vc_rows = DUMMY_ROWS;
  84. } else
  85. vc_resize(vc, DUMMY_COLUMNS, DUMMY_ROWS);
  86. }
  87. static void dummycon_deinit(struct vc_data *vc) { }
  88. static void dummycon_clear(struct vc_data *vc, int sy, int sx, int height,
  89. int width) { }
  90. static void dummycon_cursor(struct vc_data *vc, int mode) { }
  91. static bool dummycon_scroll(struct vc_data *vc, unsigned int top,
  92. unsigned int bottom, enum con_scroll dir,
  93. unsigned int lines)
  94. {
  95. return false;
  96. }
  97. static int dummycon_switch(struct vc_data *vc)
  98. {
  99. return 0;
  100. }
  101. static int dummycon_font_set(struct vc_data *vc, struct console_font *font,
  102. unsigned int flags)
  103. {
  104. return 0;
  105. }
  106. static int dummycon_font_default(struct vc_data *vc,
  107. struct console_font *font, char *name)
  108. {
  109. return 0;
  110. }
  111. static int dummycon_font_copy(struct vc_data *vc, int con)
  112. {
  113. return 0;
  114. }
  115. /*
  116. * The console `switch' structure for the dummy console
  117. *
  118. * Most of the operations are dummies.
  119. */
  120. const struct consw dummy_con = {
  121. .owner = THIS_MODULE,
  122. .con_startup = dummycon_startup,
  123. .con_init = dummycon_init,
  124. .con_deinit = dummycon_deinit,
  125. .con_clear = dummycon_clear,
  126. .con_putc = dummycon_putc,
  127. .con_putcs = dummycon_putcs,
  128. .con_cursor = dummycon_cursor,
  129. .con_scroll = dummycon_scroll,
  130. .con_switch = dummycon_switch,
  131. .con_blank = dummycon_blank,
  132. .con_font_set = dummycon_font_set,
  133. .con_font_default = dummycon_font_default,
  134. .con_font_copy = dummycon_font_copy,
  135. };
  136. EXPORT_SYMBOL_GPL(dummy_con);