hwmon: (it87) Expose the PWM/temperature mappings
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / x86 / boot / video-vga.c
blobed7aeff786b277d01b281a47c418eb5c988ea249
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
16 #include "boot.h"
17 #include "video.h"
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;
44 u16 ax;
45 u8 mode;
47 initregs(&ireg);
49 /* Query current mode */
50 ax = 0x0f00;
51 intcall(0x10, &ireg, &oreg);
52 mode = oreg.al;
54 if (mode != 3 && mode != 7)
55 mode = 3;
57 /* Set the mode */
58 ireg.ax = mode; /* AH=0: set mode */
59 intcall(0x10, &ireg, NULL);
60 do_restore = 1;
61 return mode;
64 static void vga_set_8font(void)
66 /* Set 8x8 font - 80x43 on EGA, 80x50 on VGA */
67 struct biosregs ireg;
69 initregs(&ireg);
71 /* Set 8x8 font */
72 ireg.ax = 0x1112;
73 /* ireg.bl = 0; */
74 intcall(0x10, &ireg, NULL);
76 /* Use alternate print screen */
77 ireg.ax = 0x1200;
78 ireg.bl = 0x20;
79 intcall(0x10, &ireg, NULL);
81 /* Turn off cursor emulation */
82 ireg.ax = 0x1201;
83 ireg.bl = 0x34;
84 intcall(0x10, &ireg, NULL);
86 /* Cursor is scan lines 6-7 */
87 ireg.ax = 0x0100;
88 ireg.cx = 0x0607;
89 intcall(0x10, &ireg, NULL);
92 static void vga_set_14font(void)
94 /* Set 9x14 font - 80x28 on VGA */
95 struct biosregs ireg;
97 initregs(&ireg);
99 /* Set 9x14 font */
100 ireg.ax = 0x1111;
101 /* ireg.bl = 0; */
102 intcall(0x10, &ireg, NULL);
104 /* Turn off cursor emulation */
105 ireg.ax = 0x1201;
106 ireg.bl = 0x34;
107 intcall(0x10, &ireg, NULL);
109 /* Cursor is scan lines 11-12 */
110 ireg.ax = 0x0100;
111 ireg.cx = 0x0b0c;
112 intcall(0x10, &ireg, NULL);
115 static void vga_set_80x43(void)
117 /* Set 80x43 mode on VGA (not EGA) */
118 struct biosregs ireg;
120 initregs(&ireg);
122 /* Set 350 scans */
123 ireg.ax = 0x1201;
124 ireg.bl = 0x30;
125 intcall(0x10, &ireg, NULL);
127 /* Reset video mode */
128 ireg.ax = 0x0003;
129 intcall(0x10, &ireg, NULL);
131 vga_set_8font();
134 /* I/O address of the VGA CRTC */
135 u16 vga_crtc(void)
137 return (inb(0x3cc) & 1) ? 0x3d4 : 0x3b4;
140 static void vga_set_480_scanlines(void)
142 u16 crtc; /* CRTC base address */
143 u8 csel; /* CRTC miscellaneous output register */
145 crtc = vga_crtc();
147 out_idx(0x0c, crtc, 0x11); /* Vertical sync end, unlock CR0-7 */
148 out_idx(0x0b, crtc, 0x06); /* Vertical total */
149 out_idx(0x3e, crtc, 0x07); /* Vertical overflow */
150 out_idx(0xea, crtc, 0x10); /* Vertical sync start */
151 out_idx(0xdf, crtc, 0x12); /* Vertical display end */
152 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;
157 outb(csel, 0x3c2);
160 static void vga_set_vertical_end(int lines)
162 u16 crtc; /* CRTC base address */
163 u8 ovfw; /* CRTC overflow register */
164 int end = lines-1;
166 crtc = vga_crtc();
168 ovfw = 0x3c | ((end >> (8-1)) & 0x02) | ((end >> (9-6)) & 0x40);
170 out_idx(ovfw, crtc, 0x07); /* Vertical overflow */
171 out_idx(end, crtc, 0x12); /* Vertical display end */
174 static void vga_set_80x30(void)
176 vga_set_480_scanlines();
177 vga_set_vertical_end(30*16);
180 static void vga_set_80x34(void)
182 vga_set_480_scanlines();
183 vga_set_14font();
184 vga_set_vertical_end(34*14);
187 static void vga_set_80x60(void)
189 vga_set_480_scanlines();
190 vga_set_8font();
191 vga_set_vertical_end(60*8);
194 static int vga_set_mode(struct mode_info *mode)
196 /* Set the basic mode */
197 vga_set_basic_mode();
199 /* Override a possibly broken BIOS */
200 force_x = mode->x;
201 force_y = mode->y;
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;
226 return 0;
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.
234 static int vga_probe(void)
236 static const char *card_name[] = {
237 "CGA/MDA/HGC", "EGA", "VGA"
239 static struct mode_info *mode_lists[] = {
240 cga_modes,
241 ega_modes,
242 vga_modes,
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),
250 struct biosregs ireg, oreg;
252 initregs(&ireg);
254 ireg.ax = 0x1200;
255 ireg.bl = 0x10; /* Check EGA/VGA */
256 intcall(0x10, &ireg, &oreg);
258 #ifndef _WAKEUP
259 boot_params.screen_info.orig_video_ega_bx = oreg.bx;
260 #endif
262 /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */
263 if (oreg.bl != 0x10) {
264 /* EGA/VGA */
265 ireg.ax = 0x1a00;
266 intcall(0x10, &ireg, &oreg);
268 if (oreg.al == 0x1a) {
269 adapter = ADAPTER_VGA;
270 #ifndef _WAKEUP
271 boot_params.screen_info.orig_video_isVGA = 1;
272 #endif
273 } else {
274 adapter = ADAPTER_EGA;
276 } else {
277 adapter = ADAPTER_CGA;
280 video_vga.modes = mode_lists[adapter];
281 video_vga.card_name = card_name[adapter];
282 return mode_count[adapter];
285 static __videocard video_vga = {
286 .card_name = "VGA",
287 .probe = vga_probe,
288 .set_mode = vga_set_mode,