1 /* -*- linux-c -*- ------------------------------------------------------- *
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright 2007 rPath, Inc. - All Rights Reserved
5 * Copyright 2009 Intel Corporation; author H. Peter Anvin
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.
10 * ----------------------------------------------------------------------- */
13 * Common all-VGA modes
19 static struct mode_info vga_modes
[] = {
20 { 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 },
29 static struct mode_info ega_modes
[] = {
30 { VIDEO_80x25
, 80, 25, 0 },
31 { VIDEO_8POINT
, 80, 43, 0 },
34 static struct mode_info cga_modes
[] = {
35 { VIDEO_80x25
, 80, 25, 0 },
38 static __videocard video_vga
;
40 /* Set basic 80x25 mode */
41 static u8
vga_set_basic_mode(void)
43 struct biosregs ireg
, oreg
;
50 #ifdef CONFIG_VIDEO_400_HACK
51 if (adapter
>= ADAPTER_VGA
) {
54 intcall(0x10, &ireg
, NULL
);
59 intcall(0x10, &ireg
, &oreg
);
63 rows
= rdfs8(0x484); /* rows minus one */
65 #ifndef CONFIG_VIDEO_400_HACK
66 if ((oreg
.ax
== 0x5003 || oreg
.ax
== 0x5007) &&
67 (rows
== 0 || rows
== 24))
71 if (mode
!= 3 && mode
!= 7)
75 ireg
.ax
= mode
; /* AH=0: set mode */
76 intcall(0x10, &ireg
, NULL
);
81 static void vga_set_8font(void)
83 /* Set 8x8 font - 80x43 on EGA, 80x50 on VGA */
91 intcall(0x10, &ireg
, NULL
);
93 /* Use alternate print screen */
96 intcall(0x10, &ireg
, NULL
);
98 /* Turn off cursor emulation */
101 intcall(0x10, &ireg
, NULL
);
103 /* Cursor is scan lines 6-7 */
106 intcall(0x10, &ireg
, NULL
);
109 static void vga_set_14font(void)
111 /* Set 9x14 font - 80x28 on VGA */
112 struct biosregs ireg
;
119 intcall(0x10, &ireg
, NULL
);
121 /* Turn off cursor emulation */
124 intcall(0x10, &ireg
, NULL
);
126 /* Cursor is scan lines 11-12 */
129 intcall(0x10, &ireg
, NULL
);
132 static void vga_set_80x43(void)
134 /* Set 80x43 mode on VGA (not EGA) */
135 struct biosregs ireg
;
142 intcall(0x10, &ireg
, NULL
);
144 /* Reset video mode */
146 intcall(0x10, &ireg
, NULL
);
151 /* I/O address of the VGA CRTC */
154 return (inb(0x3cc) & 1) ? 0x3d4 : 0x3b4;
157 static void vga_set_480_scanlines(void)
159 u16 crtc
; /* CRTC base address */
160 u8 csel
; /* CRTC miscellaneous output register */
164 out_idx(0x0c, crtc
, 0x11); /* Vertical sync end, unlock CR0-7 */
165 out_idx(0x0b, crtc
, 0x06); /* Vertical total */
166 out_idx(0x3e, crtc
, 0x07); /* Vertical overflow */
167 out_idx(0xea, crtc
, 0x10); /* Vertical sync start */
168 out_idx(0xdf, crtc
, 0x12); /* Vertical display end */
169 out_idx(0xe7, crtc
, 0x15); /* Vertical blank start */
170 out_idx(0x04, crtc
, 0x16); /* Vertical blank end */
177 static void vga_set_vertical_end(int lines
)
179 u16 crtc
; /* CRTC base address */
180 u8 ovfw
; /* CRTC overflow register */
185 ovfw
= 0x3c | ((end
>> (8-1)) & 0x02) | ((end
>> (9-6)) & 0x40);
187 out_idx(ovfw
, crtc
, 0x07); /* Vertical overflow */
188 out_idx(end
, crtc
, 0x12); /* Vertical display end */
191 static void vga_set_80x30(void)
193 vga_set_480_scanlines();
194 vga_set_vertical_end(30*16);
197 static void vga_set_80x34(void)
199 vga_set_480_scanlines();
201 vga_set_vertical_end(34*14);
204 static void vga_set_80x60(void)
206 vga_set_480_scanlines();
208 vga_set_vertical_end(60*8);
211 static int vga_set_mode(struct mode_info
*mode
)
213 /* Set the basic mode */
214 vga_set_basic_mode();
216 /* Override a possibly broken BIOS */
220 switch (mode
->mode
) {
247 * Note: this probe includes basic information required by all
248 * systems. It should be executed first, by making sure
249 * video-vga.c is listed first in the Makefile.
251 static int vga_probe(void)
253 static const char *card_name
[] = {
254 "CGA/MDA/HGC", "EGA", "VGA"
256 static struct mode_info
*mode_lists
[] = {
261 static int mode_count
[] = {
262 sizeof(cga_modes
)/sizeof(struct mode_info
),
263 sizeof(ega_modes
)/sizeof(struct mode_info
),
264 sizeof(vga_modes
)/sizeof(struct mode_info
),
267 struct biosregs ireg
, oreg
;
272 ireg
.bl
= 0x10; /* Check EGA/VGA */
273 intcall(0x10, &ireg
, &oreg
);
276 boot_params
.screen_info
.orig_video_ega_bx
= oreg
.bx
;
279 /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */
280 if (oreg
.bl
!= 0x10) {
283 intcall(0x10, &ireg
, &oreg
);
285 if (oreg
.al
== 0x1a) {
286 adapter
= ADAPTER_VGA
;
288 boot_params
.screen_info
.orig_video_isVGA
= 1;
291 adapter
= ADAPTER_EGA
;
294 adapter
= ADAPTER_CGA
;
297 video_vga
.modes
= mode_lists
[adapter
];
298 video_vga
.card_name
= card_name
[adapter
];
299 return mode_count
[adapter
];
302 static __videocard video_vga
= {
305 .set_mode
= vga_set_mode
,