Commit | Line | Data |
---|---|---|
97873a3d | 1 | // SPDX-License-Identifier: GPL-2.0-only |
5e8ddcbe PA |
2 | /* -*- linux-c -*- ------------------------------------------------------- * |
3 | * | |
4 | * Copyright (C) 1991, 1992 Linus Torvalds | |
5 | * Copyright 2007 rPath, Inc. - All Rights Reserved | |
cf06de7b | 6 | * Copyright 2009 Intel Corporation; author H. Peter Anvin |
5e8ddcbe | 7 | * |
5e8ddcbe PA |
8 | * ----------------------------------------------------------------------- */ |
9 | ||
10 | /* | |
5e8ddcbe PA |
11 | * Common all-VGA modes |
12 | */ | |
13 | ||
14 | #include "boot.h" | |
15 | #include "video.h" | |
16 | ||
17 | static struct mode_info vga_modes[] = { | |
1cac5004 PA |
18 | { VIDEO_80x25, 80, 25, 0 }, |
19 | { VIDEO_8POINT, 80, 50, 0 }, | |
20 | { VIDEO_80x43, 80, 43, 0 }, | |
21 | { VIDEO_80x28, 80, 28, 0 }, | |
22 | { VIDEO_80x30, 80, 30, 0 }, | |
23 | { VIDEO_80x34, 80, 34, 0 }, | |
24 | { VIDEO_80x60, 80, 60, 0 }, | |
5e8ddcbe PA |
25 | }; |
26 | ||
27 | static struct mode_info ega_modes[] = { | |
1cac5004 PA |
28 | { VIDEO_80x25, 80, 25, 0 }, |
29 | { VIDEO_8POINT, 80, 43, 0 }, | |
5e8ddcbe PA |
30 | }; |
31 | ||
32 | static struct mode_info cga_modes[] = { | |
1cac5004 | 33 | { VIDEO_80x25, 80, 25, 0 }, |
5e8ddcbe PA |
34 | }; |
35 | ||
a1a00b58 | 36 | static __videocard video_vga; |
5e8ddcbe PA |
37 | |
38 | /* Set basic 80x25 mode */ | |
39 | static u8 vga_set_basic_mode(void) | |
40 | { | |
cf06de7b | 41 | struct biosregs ireg, oreg; |
5e8ddcbe PA |
42 | u8 mode; |
43 | ||
cf06de7b PA |
44 | initregs(&ireg); |
45 | ||
8e92dc76 | 46 | /* Query current mode */ |
cf3bdc29 | 47 | ireg.ax = 0x0f00; |
cf06de7b PA |
48 | intcall(0x10, &ireg, &oreg); |
49 | mode = oreg.al; | |
5e8ddcbe | 50 | |
5e8ddcbe PA |
51 | if (mode != 3 && mode != 7) |
52 | mode = 3; | |
53 | ||
54 | /* Set the mode */ | |
cf06de7b PA |
55 | ireg.ax = mode; /* AH=0: set mode */ |
56 | intcall(0x10, &ireg, NULL); | |
5e8ddcbe PA |
57 | do_restore = 1; |
58 | return mode; | |
59 | } | |
60 | ||
61 | static void vga_set_8font(void) | |
62 | { | |
63 | /* Set 8x8 font - 80x43 on EGA, 80x50 on VGA */ | |
cf06de7b PA |
64 | struct biosregs ireg; |
65 | ||
66 | initregs(&ireg); | |
5e8ddcbe PA |
67 | |
68 | /* Set 8x8 font */ | |
cf06de7b PA |
69 | ireg.ax = 0x1112; |
70 | /* ireg.bl = 0; */ | |
71 | intcall(0x10, &ireg, NULL); | |
5e8ddcbe PA |
72 | |
73 | /* Use alternate print screen */ | |
cf06de7b PA |
74 | ireg.ax = 0x1200; |
75 | ireg.bl = 0x20; | |
76 | intcall(0x10, &ireg, NULL); | |
5e8ddcbe PA |
77 | |
78 | /* Turn off cursor emulation */ | |
cf06de7b PA |
79 | ireg.ax = 0x1201; |
80 | ireg.bl = 0x34; | |
81 | intcall(0x10, &ireg, NULL); | |
5e8ddcbe PA |
82 | |
83 | /* Cursor is scan lines 6-7 */ | |
cf06de7b PA |
84 | ireg.ax = 0x0100; |
85 | ireg.cx = 0x0607; | |
86 | intcall(0x10, &ireg, NULL); | |
5e8ddcbe PA |
87 | } |
88 | ||
89 | static void vga_set_14font(void) | |
90 | { | |
91 | /* Set 9x14 font - 80x28 on VGA */ | |
cf06de7b PA |
92 | struct biosregs ireg; |
93 | ||
94 | initregs(&ireg); | |
5e8ddcbe PA |
95 | |
96 | /* Set 9x14 font */ | |
cf06de7b PA |
97 | ireg.ax = 0x1111; |
98 | /* ireg.bl = 0; */ | |
99 | intcall(0x10, &ireg, NULL); | |
5e8ddcbe PA |
100 | |
101 | /* Turn off cursor emulation */ | |
cf06de7b PA |
102 | ireg.ax = 0x1201; |
103 | ireg.bl = 0x34; | |
104 | intcall(0x10, &ireg, NULL); | |
5e8ddcbe PA |
105 | |
106 | /* Cursor is scan lines 11-12 */ | |
cf06de7b PA |
107 | ireg.ax = 0x0100; |
108 | ireg.cx = 0x0b0c; | |
109 | intcall(0x10, &ireg, NULL); | |
5e8ddcbe PA |
110 | } |
111 | ||
112 | static void vga_set_80x43(void) | |
113 | { | |
114 | /* Set 80x43 mode on VGA (not EGA) */ | |
cf06de7b PA |
115 | struct biosregs ireg; |
116 | ||
117 | initregs(&ireg); | |
5e8ddcbe PA |
118 | |
119 | /* Set 350 scans */ | |
cf06de7b PA |
120 | ireg.ax = 0x1201; |
121 | ireg.bl = 0x30; | |
122 | intcall(0x10, &ireg, NULL); | |
5e8ddcbe PA |
123 | |
124 | /* Reset video mode */ | |
cf06de7b PA |
125 | ireg.ax = 0x0003; |
126 | intcall(0x10, &ireg, NULL); | |
5e8ddcbe PA |
127 | |
128 | vga_set_8font(); | |
129 | } | |
130 | ||
131 | /* I/O address of the VGA CRTC */ | |
132 | u16 vga_crtc(void) | |
133 | { | |
134 | return (inb(0x3cc) & 1) ? 0x3d4 : 0x3b4; | |
135 | } | |
136 | ||
1e274a58 | 137 | static void vga_set_480_scanlines(void) |
5e8ddcbe | 138 | { |
5f641356 PA |
139 | u16 crtc; /* CRTC base address */ |
140 | u8 csel; /* CRTC miscellaneous output register */ | |
5e8ddcbe PA |
141 | |
142 | crtc = vga_crtc(); | |
143 | ||
144 | out_idx(0x0c, crtc, 0x11); /* Vertical sync end, unlock CR0-7 */ | |
145 | out_idx(0x0b, crtc, 0x06); /* Vertical total */ | |
1e274a58 | 146 | out_idx(0x3e, crtc, 0x07); /* Vertical overflow */ |
5e8ddcbe | 147 | out_idx(0xea, crtc, 0x10); /* Vertical sync start */ |
1e274a58 | 148 | out_idx(0xdf, crtc, 0x12); /* Vertical display end */ |
5e8ddcbe PA |
149 | out_idx(0xe7, crtc, 0x15); /* Vertical blank start */ |
150 | out_idx(0x04, crtc, 0x16); /* Vertical blank end */ | |
151 | csel = inb(0x3cc); | |
152 | csel &= 0x0d; | |
153 | csel |= 0xe2; | |
5f641356 | 154 | outb(csel, 0x3c2); |
5e8ddcbe PA |
155 | } |
156 | ||
1e274a58 PA |
157 | static void vga_set_vertical_end(int lines) |
158 | { | |
159 | u16 crtc; /* CRTC base address */ | |
160 | u8 ovfw; /* CRTC overflow register */ | |
161 | int end = lines-1; | |
162 | ||
163 | crtc = vga_crtc(); | |
164 | ||
165 | ovfw = 0x3c | ((end >> (8-1)) & 0x02) | ((end >> (9-6)) & 0x40); | |
166 | ||
167 | out_idx(ovfw, crtc, 0x07); /* Vertical overflow */ | |
168 | out_idx(end, crtc, 0x12); /* Vertical display end */ | |
169 | } | |
170 | ||
5e8ddcbe PA |
171 | static void vga_set_80x30(void) |
172 | { | |
1e274a58 PA |
173 | vga_set_480_scanlines(); |
174 | vga_set_vertical_end(30*16); | |
5e8ddcbe PA |
175 | } |
176 | ||
177 | static void vga_set_80x34(void) | |
178 | { | |
1e274a58 | 179 | vga_set_480_scanlines(); |
5e8ddcbe | 180 | vga_set_14font(); |
1e274a58 | 181 | vga_set_vertical_end(34*14); |
5e8ddcbe PA |
182 | } |
183 | ||
184 | static void vga_set_80x60(void) | |
185 | { | |
1e274a58 | 186 | vga_set_480_scanlines(); |
5e8ddcbe | 187 | vga_set_8font(); |
1e274a58 | 188 | vga_set_vertical_end(60*8); |
5e8ddcbe PA |
189 | } |
190 | ||
191 | static int vga_set_mode(struct mode_info *mode) | |
192 | { | |
193 | /* Set the basic mode */ | |
194 | vga_set_basic_mode(); | |
195 | ||
196 | /* Override a possibly broken BIOS */ | |
197 | force_x = mode->x; | |
198 | force_y = mode->y; | |
199 | ||
200 | switch (mode->mode) { | |
201 | case VIDEO_80x25: | |
202 | break; | |
203 | case VIDEO_8POINT: | |
204 | vga_set_8font(); | |
205 | break; | |
206 | case VIDEO_80x43: | |
207 | vga_set_80x43(); | |
208 | break; | |
209 | case VIDEO_80x28: | |
210 | vga_set_14font(); | |
211 | break; | |
212 | case VIDEO_80x30: | |
213 | vga_set_80x30(); | |
214 | break; | |
215 | case VIDEO_80x34: | |
216 | vga_set_80x34(); | |
217 | break; | |
218 | case VIDEO_80x60: | |
219 | vga_set_80x60(); | |
220 | break; | |
221 | } | |
222 | ||
223 | return 0; | |
224 | } | |
225 | ||
226 | /* | |
227 | * Note: this probe includes basic information required by all | |
228 | * systems. It should be executed first, by making sure | |
229 | * video-vga.c is listed first in the Makefile. | |
230 | */ | |
231 | static int vga_probe(void) | |
232 | { | |
233 | static const char *card_name[] = { | |
234 | "CGA/MDA/HGC", "EGA", "VGA" | |
235 | }; | |
236 | static struct mode_info *mode_lists[] = { | |
237 | cga_modes, | |
238 | ega_modes, | |
239 | vga_modes, | |
240 | }; | |
241 | static int mode_count[] = { | |
0cfe5b5f JL |
242 | ARRAY_SIZE(cga_modes), |
243 | ARRAY_SIZE(ega_modes), | |
244 | ARRAY_SIZE(vga_modes), | |
5e8ddcbe | 245 | }; |
5e8ddcbe | 246 | |
cf06de7b PA |
247 | struct biosregs ireg, oreg; |
248 | ||
249 | initregs(&ireg); | |
250 | ||
251 | ireg.ax = 0x1200; | |
252 | ireg.bl = 0x10; /* Check EGA/VGA */ | |
253 | intcall(0x10, &ireg, &oreg); | |
5e8ddcbe | 254 | |
e44b7b75 | 255 | #ifndef _WAKEUP |
cf06de7b | 256 | boot_params.screen_info.orig_video_ega_bx = oreg.bx; |
e44b7b75 PM |
257 | #endif |
258 | ||
5e8ddcbe | 259 | /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */ |
cf06de7b | 260 | if (oreg.bl != 0x10) { |
5e8ddcbe | 261 | /* EGA/VGA */ |
cf06de7b PA |
262 | ireg.ax = 0x1a00; |
263 | intcall(0x10, &ireg, &oreg); | |
5e8ddcbe | 264 | |
cf06de7b | 265 | if (oreg.al == 0x1a) { |
5e8ddcbe | 266 | adapter = ADAPTER_VGA; |
e44b7b75 | 267 | #ifndef _WAKEUP |
5e8ddcbe | 268 | boot_params.screen_info.orig_video_isVGA = 1; |
e44b7b75 | 269 | #endif |
5e8ddcbe PA |
270 | } else { |
271 | adapter = ADAPTER_EGA; | |
272 | } | |
273 | } else { | |
274 | adapter = ADAPTER_CGA; | |
275 | } | |
276 | ||
277 | video_vga.modes = mode_lists[adapter]; | |
278 | video_vga.card_name = card_name[adapter]; | |
279 | return mode_count[adapter]; | |
280 | } | |
281 | ||
a1a00b58 | 282 | static __videocard video_vga = { |
5e8ddcbe PA |
283 | .card_name = "VGA", |
284 | .probe = vga_probe, | |
285 | .set_mode = vga_set_mode, | |
286 | }; |