1 // SPDX-License-Identifier: GPL-2.0-only
2 /* -*- linux-c -*- ------------------------------------------------------- *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 * Copyright 2007 rPath, Inc. - All Rights Reserved
6 * Copyright 2009 Intel Corporation; author H. Peter Anvin
8 * ----------------------------------------------------------------------- */
11 * Common all-VGA modes
17 static struct mode_info vga_modes[] = {
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 },
27 static struct mode_info ega_modes[] = {
28 { VIDEO_80x25, 80, 25, 0 },
29 { VIDEO_8POINT, 80, 43, 0 },
32 static struct mode_info cga_modes[] = {
33 { VIDEO_80x25, 80, 25, 0 },
36 static __videocard video_vga;
38 /* Set basic 80x25 mode */
39 static u8 vga_set_basic_mode(void)
41 struct biosregs ireg, oreg;
46 /* Query current mode */
48 intcall(0x10, &ireg, &oreg);
51 if (mode != 3 && mode != 7)
55 ireg.ax = mode; /* AH=0: set mode */
56 intcall(0x10, &ireg, NULL);
61 static void vga_set_8font(void)
63 /* Set 8x8 font - 80x43 on EGA, 80x50 on VGA */
71 intcall(0x10, &ireg, NULL);
73 /* Use alternate print screen */
76 intcall(0x10, &ireg, NULL);
78 /* Turn off cursor emulation */
81 intcall(0x10, &ireg, NULL);
83 /* Cursor is scan lines 6-7 */
86 intcall(0x10, &ireg, NULL);
89 static void vga_set_14font(void)
91 /* Set 9x14 font - 80x28 on VGA */
99 intcall(0x10, &ireg, NULL);
101 /* Turn off cursor emulation */
104 intcall(0x10, &ireg, NULL);
106 /* Cursor is scan lines 11-12 */
109 intcall(0x10, &ireg, NULL);
112 static void vga_set_80x43(void)
114 /* Set 80x43 mode on VGA (not EGA) */
115 struct biosregs ireg;
122 intcall(0x10, &ireg, NULL);
124 /* Reset video mode */
126 intcall(0x10, &ireg, NULL);
131 /* I/O address of the VGA CRTC */
134 return (inb(0x3cc) & 1) ? 0x3d4 : 0x3b4;
137 static void vga_set_480_scanlines(void)
139 u16 crtc; /* CRTC base address */
140 u8 csel; /* CRTC miscellaneous output register */
144 out_idx(0x0c, crtc, 0x11); /* Vertical sync end, unlock CR0-7 */
145 out_idx(0x0b, crtc, 0x06); /* Vertical total */
146 out_idx(0x3e, crtc, 0x07); /* Vertical overflow */
147 out_idx(0xea, crtc, 0x10); /* Vertical sync start */
148 out_idx(0xdf, crtc, 0x12); /* Vertical display end */
149 out_idx(0xe7, crtc, 0x15); /* Vertical blank start */
150 out_idx(0x04, crtc, 0x16); /* Vertical blank end */
157 static void vga_set_vertical_end(int lines)
159 u16 crtc; /* CRTC base address */
160 u8 ovfw; /* CRTC overflow register */
165 ovfw = 0x3c | ((end >> (8-1)) & 0x02) | ((end >> (9-6)) & 0x40);
167 out_idx(ovfw, crtc, 0x07); /* Vertical overflow */
168 out_idx(end, crtc, 0x12); /* Vertical display end */
171 static void vga_set_80x30(void)
173 vga_set_480_scanlines();
174 vga_set_vertical_end(30*16);
177 static void vga_set_80x34(void)
179 vga_set_480_scanlines();
181 vga_set_vertical_end(34*14);
184 static void vga_set_80x60(void)
186 vga_set_480_scanlines();
188 vga_set_vertical_end(60*8);
191 static int vga_set_mode(struct mode_info *mode)
193 /* Set the basic mode */
194 vga_set_basic_mode();
196 /* Override a possibly broken BIOS */
200 switch (mode->mode) {
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.
231 static int vga_probe(void)
233 static const char *card_name[] = {
234 "CGA/MDA/HGC", "EGA", "VGA"
236 static struct mode_info *mode_lists[] = {
241 static int mode_count[] = {
242 ARRAY_SIZE(cga_modes),
243 ARRAY_SIZE(ega_modes),
244 ARRAY_SIZE(vga_modes),
247 struct biosregs ireg, oreg;
252 ireg.bl = 0x10; /* Check EGA/VGA */
253 intcall(0x10, &ireg, &oreg);
256 boot_params.screen_info.orig_video_ega_bx = oreg.bx;
259 /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */
260 if (oreg.bl != 0x10) {
263 intcall(0x10, &ireg, &oreg);
265 if (oreg.al == 0x1a) {
266 adapter = ADAPTER_VGA;
268 boot_params.screen_info.orig_video_isVGA = 1;
271 adapter = ADAPTER_EGA;
274 adapter = ADAPTER_CGA;
277 video_vga.modes = mode_lists[adapter];
278 video_vga.card_name = card_name[adapter];
279 return mode_count[adapter];
282 static __videocard video_vga = {
285 .set_mode = vga_set_mode,