blob: 819caa1f200879887c3726de406cbf664a771960 [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;
45 u8 rows;
46 u8 mode;
47
H. Peter Anvincf06de72009-04-01 18:20:11 -070048 initregs(&ireg);
49
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
54 set_fs(0);
55 rows = rdfs8(0x484); /* rows minus one */
56
H. Peter Anvincf06de72009-04-01 18:20:11 -070057 if ((oreg.ax == 0x5003 || oreg.ax == 0x5007) &&
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070058 (rows == 0 || rows == 24))
59 return mode;
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070060
61 if (mode != 3 && mode != 7)
62 mode = 3;
63
64 /* Set the mode */
H. Peter Anvincf06de72009-04-01 18:20:11 -070065 ireg.ax = mode; /* AH=0: set mode */
66 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070067 do_restore = 1;
68 return mode;
69}
70
71static void vga_set_8font(void)
72{
73 /* Set 8x8 font - 80x43 on EGA, 80x50 on VGA */
H. Peter Anvincf06de72009-04-01 18:20:11 -070074 struct biosregs ireg;
75
76 initregs(&ireg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070077
78 /* Set 8x8 font */
H. Peter Anvincf06de72009-04-01 18:20:11 -070079 ireg.ax = 0x1112;
80 /* ireg.bl = 0; */
81 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070082
83 /* Use alternate print screen */
H. Peter Anvincf06de72009-04-01 18:20:11 -070084 ireg.ax = 0x1200;
85 ireg.bl = 0x20;
86 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070087
88 /* Turn off cursor emulation */
H. Peter Anvincf06de72009-04-01 18:20:11 -070089 ireg.ax = 0x1201;
90 ireg.bl = 0x34;
91 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070092
93 /* Cursor is scan lines 6-7 */
H. Peter Anvincf06de72009-04-01 18:20:11 -070094 ireg.ax = 0x0100;
95 ireg.cx = 0x0607;
96 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -070097}
98
99static void vga_set_14font(void)
100{
101 /* Set 9x14 font - 80x28 on VGA */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700102 struct biosregs ireg;
103
104 initregs(&ireg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700105
106 /* Set 9x14 font */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700107 ireg.ax = 0x1111;
108 /* ireg.bl = 0; */
109 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700110
111 /* Turn off cursor emulation */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700112 ireg.ax = 0x1201;
113 ireg.bl = 0x34;
114 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700115
116 /* Cursor is scan lines 11-12 */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700117 ireg.ax = 0x0100;
118 ireg.cx = 0x0b0c;
119 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700120}
121
122static void vga_set_80x43(void)
123{
124 /* Set 80x43 mode on VGA (not EGA) */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700125 struct biosregs ireg;
126
127 initregs(&ireg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700128
129 /* Set 350 scans */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700130 ireg.ax = 0x1201;
131 ireg.bl = 0x30;
132 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700133
134 /* Reset video mode */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700135 ireg.ax = 0x0003;
136 intcall(0x10, &ireg, NULL);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700137
138 vga_set_8font();
139}
140
141/* I/O address of the VGA CRTC */
142u16 vga_crtc(void)
143{
144 return (inb(0x3cc) & 1) ? 0x3d4 : 0x3b4;
145}
146
H. Peter Anvin1e274a52009-04-07 10:59:25 -0700147static void vga_set_480_scanlines(void)
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700148{
H. Peter Anvin5f641352009-03-18 16:54:05 -0700149 u16 crtc; /* CRTC base address */
150 u8 csel; /* CRTC miscellaneous output register */
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700151
152 crtc = vga_crtc();
153
154 out_idx(0x0c, crtc, 0x11); /* Vertical sync end, unlock CR0-7 */
155 out_idx(0x0b, crtc, 0x06); /* Vertical total */
H. Peter Anvin1e274a52009-04-07 10:59:25 -0700156 out_idx(0x3e, crtc, 0x07); /* Vertical overflow */
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700157 out_idx(0xea, crtc, 0x10); /* Vertical sync start */
H. Peter Anvin1e274a52009-04-07 10:59:25 -0700158 out_idx(0xdf, crtc, 0x12); /* Vertical display end */
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700159 out_idx(0xe7, crtc, 0x15); /* Vertical blank start */
160 out_idx(0x04, crtc, 0x16); /* Vertical blank end */
161 csel = inb(0x3cc);
162 csel &= 0x0d;
163 csel |= 0xe2;
H. Peter Anvin5f641352009-03-18 16:54:05 -0700164 outb(csel, 0x3c2);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700165}
166
H. Peter Anvin1e274a52009-04-07 10:59:25 -0700167static void vga_set_vertical_end(int lines)
168{
169 u16 crtc; /* CRTC base address */
170 u8 ovfw; /* CRTC overflow register */
171 int end = lines-1;
172
173 crtc = vga_crtc();
174
175 ovfw = 0x3c | ((end >> (8-1)) & 0x02) | ((end >> (9-6)) & 0x40);
176
177 out_idx(ovfw, crtc, 0x07); /* Vertical overflow */
178 out_idx(end, crtc, 0x12); /* Vertical display end */
179}
180
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700181static void vga_set_80x30(void)
182{
H. Peter Anvin1e274a52009-04-07 10:59:25 -0700183 vga_set_480_scanlines();
184 vga_set_vertical_end(30*16);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700185}
186
187static void vga_set_80x34(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_14font();
H. Peter Anvin1e274a52009-04-07 10:59:25 -0700191 vga_set_vertical_end(34*14);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700192}
193
194static void vga_set_80x60(void)
195{
H. Peter Anvin1e274a52009-04-07 10:59:25 -0700196 vga_set_480_scanlines();
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700197 vga_set_8font();
H. Peter Anvin1e274a52009-04-07 10:59:25 -0700198 vga_set_vertical_end(60*8);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700199}
200
201static int vga_set_mode(struct mode_info *mode)
202{
203 /* Set the basic mode */
204 vga_set_basic_mode();
205
206 /* Override a possibly broken BIOS */
207 force_x = mode->x;
208 force_y = mode->y;
209
210 switch (mode->mode) {
211 case VIDEO_80x25:
212 break;
213 case VIDEO_8POINT:
214 vga_set_8font();
215 break;
216 case VIDEO_80x43:
217 vga_set_80x43();
218 break;
219 case VIDEO_80x28:
220 vga_set_14font();
221 break;
222 case VIDEO_80x30:
223 vga_set_80x30();
224 break;
225 case VIDEO_80x34:
226 vga_set_80x34();
227 break;
228 case VIDEO_80x60:
229 vga_set_80x60();
230 break;
231 }
232
233 return 0;
234}
235
236/*
237 * Note: this probe includes basic information required by all
238 * systems. It should be executed first, by making sure
239 * video-vga.c is listed first in the Makefile.
240 */
241static int vga_probe(void)
242{
243 static const char *card_name[] = {
244 "CGA/MDA/HGC", "EGA", "VGA"
245 };
246 static struct mode_info *mode_lists[] = {
247 cga_modes,
248 ega_modes,
249 vga_modes,
250 };
251 static int mode_count[] = {
252 sizeof(cga_modes)/sizeof(struct mode_info),
253 sizeof(ega_modes)/sizeof(struct mode_info),
254 sizeof(vga_modes)/sizeof(struct mode_info),
255 };
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700256
H. Peter Anvincf06de72009-04-01 18:20:11 -0700257 struct biosregs ireg, oreg;
258
259 initregs(&ireg);
260
261 ireg.ax = 0x1200;
262 ireg.bl = 0x10; /* Check EGA/VGA */
263 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700264
Pavel Macheke44b7b72008-04-10 23:28:10 +0200265#ifndef _WAKEUP
H. Peter Anvincf06de72009-04-01 18:20:11 -0700266 boot_params.screen_info.orig_video_ega_bx = oreg.bx;
Pavel Macheke44b7b72008-04-10 23:28:10 +0200267#endif
268
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700269 /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700270 if (oreg.bl != 0x10) {
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700271 /* EGA/VGA */
H. Peter Anvincf06de72009-04-01 18:20:11 -0700272 ireg.ax = 0x1a00;
273 intcall(0x10, &ireg, &oreg);
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700274
H. Peter Anvincf06de72009-04-01 18:20:11 -0700275 if (oreg.al == 0x1a) {
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700276 adapter = ADAPTER_VGA;
Pavel Macheke44b7b72008-04-10 23:28:10 +0200277#ifndef _WAKEUP
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700278 boot_params.screen_info.orig_video_isVGA = 1;
Pavel Macheke44b7b72008-04-10 23:28:10 +0200279#endif
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700280 } else {
281 adapter = ADAPTER_EGA;
282 }
283 } else {
284 adapter = ADAPTER_CGA;
285 }
286
287 video_vga.modes = mode_lists[adapter];
288 video_vga.card_name = card_name[adapter];
289 return mode_count[adapter];
290}
291
Hannes Edera1a00b52008-11-23 19:37:09 +0100292static __videocard video_vga = {
H. Peter Anvin5e8ddcbe2007-07-11 12:18:52 -0700293 .card_name = "VGA",
294 .probe = vga_probe,
295 .set_mode = vga_set_mode,
296};