blob: ed7aeff786b277d01b281a47c418eb5c988ea249 [file] [log] [blame]
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -07001/* -*- linux-c -*- ------------------------------------------------------- *
2 *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
H. Peter Anvincf06de72009-04-01 18:20:11 -07005 * Copyright 2009 Intel Corporation; author H. Peter Anvin
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -07006 *
7 * This file is part of the Linux kernel, and is made available under
8 * the terms of the GNU General Public License version 2.
9 *
10 * ----------------------------------------------------------------------- */
11
12/*
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070013 * Common all-VGA modes
14 */
15
16#include "boot.h"
17#include "video.h"
18
19static struct mode_info vga_modes[] = {
H. Peter Anvin1cac5002008-01-30 13:33:02 +010020 { VIDEO_80x25, 80, 25, 0 },
21 { VIDEO_8POINT, 80, 50, 0 },
22 { VIDEO_80x43, 80, 43, 0 },
23 { VIDEO_80x28, 80, 28, 0 },
24 { VIDEO_80x30, 80, 30, 0 },
25 { VIDEO_80x34, 80, 34, 0 },
26 { VIDEO_80x60, 80, 60, 0 },
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070027};
28
29static struct mode_info ega_modes[] = {
H. Peter Anvin1cac5002008-01-30 13:33:02 +010030 { VIDEO_80x25, 80, 25, 0 },
31 { VIDEO_8POINT, 80, 43, 0 },
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070032};
33
34static struct mode_info cga_modes[] = {
H. Peter Anvin1cac5002008-01-30 13:33:02 +010035 { VIDEO_80x25, 80, 25, 0 },
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070036};
37
Hannes Edera1a00b52008-11-23 19:37:09 +010038static __videocard video_vga;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070039
40/* Set basic 80x25 mode */
41static u8 vga_set_basic_mode(void)
42{
H. Peter Anvincf06de72009-04-01 18:20:11 -070043 struct biosregs ireg, oreg;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070044 u16 ax;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070045 u8 mode;
46
H. Peter Anvincf06de72009-04-01 18:20:11 -070047 initregs(&ireg);
48
H. Peter Anvin8e92dc72010-02-19 13:21:38 -080049 /* Query current mode */
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070050 ax = 0x0f00;
H. Peter Anvincf06de72009-04-01 18:20:11 -070051 intcall(0x10, &ireg, &oreg);
52 mode = oreg.al;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070053
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070054 if (mode != 3 && mode != 7)
55 mode = 3;
56
57 /* Set the mode */
H. Peter Anvincf06de72009-04-01 18:20:11 -070058 ireg.ax = mode; /* AH=0: set mode */
59 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070060 do_restore = 1;
61 return mode;
62}
63
64static void vga_set_8font(void)
65{
66 /* Set 8x8 font - 80x43 on EGA, 80x50 on VGA */
H. Peter Anvincf06de72009-04-01 18:20:11 -070067 struct biosregs ireg;
68
69 initregs(&ireg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070070
71 /* Set 8x8 font */
H. Peter Anvincf06de72009-04-01 18:20:11 -070072 ireg.ax = 0x1112;
73 /* ireg.bl = 0; */
74 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070075
76 /* Use alternate print screen */
H. Peter Anvincf06de72009-04-01 18:20:11 -070077 ireg.ax = 0x1200;
78 ireg.bl = 0x20;
79 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070080
81 /* Turn off cursor emulation */
H. Peter Anvincf06de72009-04-01 18:20:11 -070082 ireg.ax = 0x1201;
83 ireg.bl = 0x34;
84 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070085
86 /* Cursor is scan lines 6-7 */
H. Peter Anvincf06de72009-04-01 18:20:11 -070087 ireg.ax = 0x0100;
88 ireg.cx = 0x0607;
89 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070090}
91
92static void vga_set_14font(void)
93{
94 /* Set 9x14 font - 80x28 on VGA */
H. Peter Anvincf06de72009-04-01 18:20:11 -070095 struct biosregs ireg;
96
97 initregs(&ireg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070098
99 /* Set 9x14 font */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700100 ireg.ax = 0x1111;
101 /* ireg.bl = 0; */
102 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700103
104 /* Turn off cursor emulation */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700105 ireg.ax = 0x1201;
106 ireg.bl = 0x34;
107 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700108
109 /* Cursor is scan lines 11-12 */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700110 ireg.ax = 0x0100;
111 ireg.cx = 0x0b0c;
112 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700113}
114
115static void vga_set_80x43(void)
116{
117 /* Set 80x43 mode on VGA (not EGA) */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700118 struct biosregs ireg;
119
120 initregs(&ireg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700121
122 /* Set 350 scans */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700123 ireg.ax = 0x1201;
124 ireg.bl = 0x30;
125 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700126
127 /* Reset video mode */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700128 ireg.ax = 0x0003;
129 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700130
131 vga_set_8font();
132}
133
134/* I/O address of the VGA CRTC */
135u16 vga_crtc(void)
136{
137 return (inb(0x3cc) & 1) ? 0x3d4 : 0x3b4;
138}
139
H. Peter Anvin1e274a52009-04-07 10:59:25 -0700140static void vga_set_480_scanlines(void)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700141{
H. Peter Anvin5f641352009-03-18 16:54:05 -0700142 u16 crtc; /* CRTC base address */
143 u8 csel; /* CRTC miscellaneous output register */
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700144
145 crtc = vga_crtc();
146
147 out_idx(0x0c, crtc, 0x11); /* Vertical sync end, unlock CR0-7 */
148 out_idx(0x0b, crtc, 0x06); /* Vertical total */
H. Peter Anvin1e274a52009-04-07 10:59:25 -0700149 out_idx(0x3e, crtc, 0x07); /* Vertical overflow */
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700150 out_idx(0xea, crtc, 0x10); /* Vertical sync start */
H. Peter Anvin1e274a52009-04-07 10:59:25 -0700151 out_idx(0xdf, crtc, 0x12); /* Vertical display end */
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700152 out_idx(0xe7, crtc, 0x15); /* Vertical blank start */
153 out_idx(0x04, crtc, 0x16); /* Vertical blank end */
154 csel = inb(0x3cc);
155 csel &= 0x0d;
156 csel |= 0xe2;
H. Peter Anvin5f641352009-03-18 16:54:05 -0700157 outb(csel, 0x3c2);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700158}
159
H. Peter Anvin1e274a52009-04-07 10:59:25 -0700160static void vga_set_vertical_end(int lines)
161{
162 u16 crtc; /* CRTC base address */
163 u8 ovfw; /* CRTC overflow register */
164 int end = lines-1;
165
166 crtc = vga_crtc();
167
168 ovfw = 0x3c | ((end >> (8-1)) & 0x02) | ((end >> (9-6)) & 0x40);
169
170 out_idx(ovfw, crtc, 0x07); /* Vertical overflow */
171 out_idx(end, crtc, 0x12); /* Vertical display end */
172}
173
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700174static void vga_set_80x30(void)
175{
H. Peter Anvin1e274a52009-04-07 10:59:25 -0700176 vga_set_480_scanlines();
177 vga_set_vertical_end(30*16);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700178}
179
180static void vga_set_80x34(void)
181{
H. Peter Anvin1e274a52009-04-07 10:59:25 -0700182 vga_set_480_scanlines();
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700183 vga_set_14font();
H. Peter Anvin1e274a52009-04-07 10:59:25 -0700184 vga_set_vertical_end(34*14);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700185}
186
187static void vga_set_80x60(void)
188{
H. Peter Anvin1e274a52009-04-07 10:59:25 -0700189 vga_set_480_scanlines();
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700190 vga_set_8font();
H. Peter Anvin1e274a52009-04-07 10:59:25 -0700191 vga_set_vertical_end(60*8);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700192}
193
194static int vga_set_mode(struct mode_info *mode)
195{
196 /* Set the basic mode */
197 vga_set_basic_mode();
198
199 /* Override a possibly broken BIOS */
200 force_x = mode->x;
201 force_y = mode->y;
202
203 switch (mode->mode) {
204 case VIDEO_80x25:
205 break;
206 case VIDEO_8POINT:
207 vga_set_8font();
208 break;
209 case VIDEO_80x43:
210 vga_set_80x43();
211 break;
212 case VIDEO_80x28:
213 vga_set_14font();
214 break;
215 case VIDEO_80x30:
216 vga_set_80x30();
217 break;
218 case VIDEO_80x34:
219 vga_set_80x34();
220 break;
221 case VIDEO_80x60:
222 vga_set_80x60();
223 break;
224 }
225
226 return 0;
227}
228
229/*
230 * Note: this probe includes basic information required by all
231 * systems. It should be executed first, by making sure
232 * video-vga.c is listed first in the Makefile.
233 */
234static int vga_probe(void)
235{
236 static const char *card_name[] = {
237 "CGA/MDA/HGC", "EGA", "VGA"
238 };
239 static struct mode_info *mode_lists[] = {
240 cga_modes,
241 ega_modes,
242 vga_modes,
243 };
244 static int mode_count[] = {
245 sizeof(cga_modes)/sizeof(struct mode_info),
246 sizeof(ega_modes)/sizeof(struct mode_info),
247 sizeof(vga_modes)/sizeof(struct mode_info),
248 };
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700249
H. Peter Anvincf06de72009-04-01 18:20:11 -0700250 struct biosregs ireg, oreg;
251
252 initregs(&ireg);
253
254 ireg.ax = 0x1200;
255 ireg.bl = 0x10; /* Check EGA/VGA */
256 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700257
Pavel Macheke44b7b72008-04-10 23:28:10 +0200258#ifndef _WAKEUP
H. Peter Anvincf06de72009-04-01 18:20:11 -0700259 boot_params.screen_info.orig_video_ega_bx = oreg.bx;
Pavel Macheke44b7b72008-04-10 23:28:10 +0200260#endif
261
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700262 /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700263 if (oreg.bl != 0x10) {
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700264 /* EGA/VGA */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700265 ireg.ax = 0x1a00;
266 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700267
H. Peter Anvincf06de72009-04-01 18:20:11 -0700268 if (oreg.al == 0x1a) {
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700269 adapter = ADAPTER_VGA;
Pavel Macheke44b7b72008-04-10 23:28:10 +0200270#ifndef _WAKEUP
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700271 boot_params.screen_info.orig_video_isVGA = 1;
Pavel Macheke44b7b72008-04-10 23:28:10 +0200272#endif
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700273 } else {
274 adapter = ADAPTER_EGA;
275 }
276 } else {
277 adapter = ADAPTER_CGA;
278 }
279
280 video_vga.modes = mode_lists[adapter];
281 video_vga.card_name = card_name[adapter];
282 return mode_count[adapter];
283}
284
Hannes Edera1a00b52008-11-23 19:37:09 +0100285static __videocard video_vga = {
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700286 .card_name = "VGA",
287 .probe = vga_probe,
288 .set_mode = vga_set_mode,
289};