1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/video/dummycon.c -- A dummy console driver
5 * To be used if there's no other console driver (e.g. for plain VGA text)
6 * available, usually until fbcon takes console over.
9 #include <linux/types.h>
10 #include <linux/kdev_t.h>
11 #include <linux/console.h>
12 #include <linux/vt_kern.h>
13 #include <linux/screen_info.h>
14 #include <linux/init.h>
15 #include <linux/module.h>
18 * Dummy console driver
22 #define DUMMY_COLUMNS screen_info.orig_video_cols
23 #define DUMMY_ROWS screen_info.orig_video_lines
25 /* set by Kconfig. Use 80x25 for 640x480 and 160x64 for 1280x1024 */
26 #define DUMMY_COLUMNS CONFIG_DUMMY_CONSOLE_COLUMNS
27 #define DUMMY_ROWS CONFIG_DUMMY_CONSOLE_ROWS
30 #ifdef CONFIG_FRAMEBUFFER_CONSOLE_DEFERRED_TAKEOVER
31 /* These are both protected by the console_lock */
32 static RAW_NOTIFIER_HEAD(dummycon_output_nh
);
33 static bool dummycon_putc_called
;
35 void dummycon_register_output_notifier(struct notifier_block
*nb
)
37 WARN_CONSOLE_UNLOCKED();
39 raw_notifier_chain_register(&dummycon_output_nh
, nb
);
41 if (dummycon_putc_called
)
42 nb
->notifier_call(nb
, 0, NULL
);
45 void dummycon_unregister_output_notifier(struct notifier_block
*nb
)
47 WARN_CONSOLE_UNLOCKED();
49 raw_notifier_chain_unregister(&dummycon_output_nh
, nb
);
52 static void dummycon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
)
54 WARN_CONSOLE_UNLOCKED();
56 dummycon_putc_called
= true;
57 raw_notifier_call_chain(&dummycon_output_nh
, 0, NULL
);
60 static void dummycon_putcs(struct vc_data
*vc
, const unsigned short *s
,
61 int count
, int ypos
, int xpos
)
65 if (!dummycon_putc_called
) {
67 for (i
= 0 ; i
< count
; i
++) {
68 if (s
[i
] != vc
->vc_video_erase_char
)
74 dummycon_putc_called
= true;
77 raw_notifier_call_chain(&dummycon_output_nh
, 0, NULL
);
80 static int dummycon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
82 /* Redraw, so that we get putc(s) for output done while blanked */
86 static void dummycon_putc(struct vc_data
*vc
, int c
, int ypos
, int xpos
) { }
87 static void dummycon_putcs(struct vc_data
*vc
, const unsigned short *s
,
88 int count
, int ypos
, int xpos
) { }
89 static int dummycon_blank(struct vc_data
*vc
, int blank
, int mode_switch
)
95 static const char *dummycon_startup(void)
97 return "dummy device";
100 static void dummycon_init(struct vc_data
*vc
, int init
)
102 vc
->vc_can_do_color
= 1;
104 vc
->vc_cols
= DUMMY_COLUMNS
;
105 vc
->vc_rows
= DUMMY_ROWS
;
107 vc_resize(vc
, DUMMY_COLUMNS
, DUMMY_ROWS
);
110 static void dummycon_deinit(struct vc_data
*vc
) { }
111 static void dummycon_clear(struct vc_data
*vc
, int sy
, int sx
, int height
,
113 static void dummycon_cursor(struct vc_data
*vc
, int mode
) { }
115 static bool dummycon_scroll(struct vc_data
*vc
, unsigned int top
,
116 unsigned int bottom
, enum con_scroll dir
,
122 static int dummycon_switch(struct vc_data
*vc
)
127 static int dummycon_font_set(struct vc_data
*vc
, struct console_font
*font
,
133 static int dummycon_font_default(struct vc_data
*vc
,
134 struct console_font
*font
, char *name
)
139 static int dummycon_font_copy(struct vc_data
*vc
, int con
)
145 * The console `switch' structure for the dummy console
147 * Most of the operations are dummies.
150 const struct consw dummy_con
= {
151 .owner
= THIS_MODULE
,
152 .con_startup
= dummycon_startup
,
153 .con_init
= dummycon_init
,
154 .con_deinit
= dummycon_deinit
,
155 .con_clear
= dummycon_clear
,
156 .con_putc
= dummycon_putc
,
157 .con_putcs
= dummycon_putcs
,
158 .con_cursor
= dummycon_cursor
,
159 .con_scroll
= dummycon_scroll
,
160 .con_switch
= dummycon_switch
,
161 .con_blank
= dummycon_blank
,
162 .con_font_set
= dummycon_font_set
,
163 .con_font_default
= dummycon_font_default
,
164 .con_font_copy
= dummycon_font_copy
,
166 EXPORT_SYMBOL_GPL(dummy_con
);