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