video-vga.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /* -*- linux-c -*- ------------------------------------------------------- *
  2. *
  3. * Copyright (C) 1991, 1992 Linus Torvalds
  4. * Copyright 2007 rPath, Inc. - All Rights Reserved
  5. * Copyright 2009 Intel Corporation; author H. Peter Anvin
  6. *
  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. * Common all-VGA modes
  13. */
  14. #include "boot.h"
  15. #include "video.h"
  16. static struct mode_info vga_modes[] = {
  17. { VIDEO_80x25, 80, 25, 0 },
  18. { VIDEO_8POINT, 80, 50, 0 },
  19. { VIDEO_80x43, 80, 43, 0 },
  20. { VIDEO_80x28, 80, 28, 0 },
  21. { VIDEO_80x30, 80, 30, 0 },
  22. { VIDEO_80x34, 80, 34, 0 },
  23. { VIDEO_80x60, 80, 60, 0 },
  24. };
  25. static struct mode_info ega_modes[] = {
  26. { VIDEO_80x25, 80, 25, 0 },
  27. { VIDEO_8POINT, 80, 43, 0 },
  28. };
  29. static struct mode_info cga_modes[] = {
  30. { VIDEO_80x25, 80, 25, 0 },
  31. };
  32. static __videocard video_vga;
  33. /* Set basic 80x25 mode */
  34. static u8 vga_set_basic_mode(void)
  35. {
  36. struct biosregs ireg, oreg;
  37. u16 ax;
  38. u8 rows;
  39. u8 mode;
  40. initregs(&ireg);
  41. #ifdef CONFIG_VIDEO_400_HACK
  42. if (adapter >= ADAPTER_VGA) {
  43. ireg.ax = 0x1202;
  44. ireg.bx = 0x0030;
  45. intcall(0x10, &ireg, NULL);
  46. }
  47. #endif
  48. ax = 0x0f00;
  49. intcall(0x10, &ireg, &oreg);
  50. mode = oreg.al;
  51. set_fs(0);
  52. rows = rdfs8(0x484); /* rows minus one */
  53. #ifndef CONFIG_VIDEO_400_HACK
  54. if ((oreg.ax == 0x5003 || oreg.ax == 0x5007) &&
  55. (rows == 0 || rows == 24))
  56. return mode;
  57. #endif
  58. if (mode != 3 && mode != 7)
  59. mode = 3;
  60. /* Set the mode */
  61. ireg.ax = mode; /* AH=0: set mode */
  62. intcall(0x10, &ireg, NULL);
  63. do_restore = 1;
  64. return mode;
  65. }
  66. static void vga_set_8font(void)
  67. {
  68. /* Set 8x8 font - 80x43 on EGA, 80x50 on VGA */
  69. struct biosregs ireg;
  70. initregs(&ireg);
  71. /* Set 8x8 font */
  72. ireg.ax = 0x1112;
  73. /* ireg.bl = 0; */
  74. intcall(0x10, &ireg, NULL);
  75. /* Use alternate print screen */
  76. ireg.ax = 0x1200;
  77. ireg.bl = 0x20;
  78. intcall(0x10, &ireg, NULL);
  79. /* Turn off cursor emulation */
  80. ireg.ax = 0x1201;
  81. ireg.bl = 0x34;
  82. intcall(0x10, &ireg, NULL);
  83. /* Cursor is scan lines 6-7 */
  84. ireg.ax = 0x0100;
  85. ireg.cx = 0x0607;
  86. intcall(0x10, &ireg, NULL);
  87. }
  88. static void vga_set_14font(void)
  89. {
  90. /* Set 9x14 font - 80x28 on VGA */
  91. struct biosregs ireg;
  92. initregs(&ireg);
  93. /* Set 9x14 font */
  94. ireg.ax = 0x1111;
  95. /* ireg.bl = 0; */
  96. intcall(0x10, &ireg, NULL);
  97. /* Turn off cursor emulation */
  98. ireg.ax = 0x1201;
  99. ireg.bl = 0x34;
  100. intcall(0x10, &ireg, NULL);
  101. /* Cursor is scan lines 11-12 */
  102. ireg.ax = 0x0100;
  103. ireg.cx = 0x0b0c;
  104. intcall(0x10, &ireg, NULL);
  105. }
  106. static void vga_set_80x43(void)
  107. {
  108. /* Set 80x43 mode on VGA (not EGA) */
  109. struct biosregs ireg;
  110. initregs(&ireg);
  111. /* Set 350 scans */
  112. ireg.ax = 0x1201;
  113. ireg.bl = 0x30;
  114. intcall(0x10, &ireg, NULL);
  115. /* Reset video mode */
  116. ireg.ax = 0x0003;
  117. intcall(0x10, &ireg, NULL);
  118. vga_set_8font();
  119. }
  120. /* I/O address of the VGA CRTC */
  121. u16 vga_crtc(void)
  122. {
  123. return (inb(0x3cc) & 1) ? 0x3d4 : 0x3b4;
  124. }
  125. static void vga_set_480_scanlines(void)
  126. {
  127. u16 crtc; /* CRTC base address */
  128. u8 csel; /* CRTC miscellaneous output register */
  129. crtc = vga_crtc();
  130. out_idx(0x0c, crtc, 0x11); /* Vertical sync end, unlock CR0-7 */
  131. out_idx(0x0b, crtc, 0x06); /* Vertical total */
  132. out_idx(0x3e, crtc, 0x07); /* Vertical overflow */
  133. out_idx(0xea, crtc, 0x10); /* Vertical sync start */
  134. out_idx(0xdf, crtc, 0x12); /* Vertical display end */
  135. out_idx(0xe7, crtc, 0x15); /* Vertical blank start */
  136. out_idx(0x04, crtc, 0x16); /* Vertical blank end */
  137. csel = inb(0x3cc);
  138. csel &= 0x0d;
  139. csel |= 0xe2;
  140. outb(csel, 0x3c2);
  141. }
  142. static void vga_set_vertical_end(int lines)
  143. {
  144. u16 crtc; /* CRTC base address */
  145. u8 ovfw; /* CRTC overflow register */
  146. int end = lines-1;
  147. crtc = vga_crtc();
  148. ovfw = 0x3c | ((end >> (8-1)) & 0x02) | ((end >> (9-6)) & 0x40);
  149. out_idx(ovfw, crtc, 0x07); /* Vertical overflow */
  150. out_idx(end, crtc, 0x12); /* Vertical display end */
  151. }
  152. static void vga_set_80x30(void)
  153. {
  154. vga_set_480_scanlines();
  155. vga_set_vertical_end(30*16);
  156. }
  157. static void vga_set_80x34(void)
  158. {
  159. vga_set_480_scanlines();
  160. vga_set_14font();
  161. vga_set_vertical_end(34*14);
  162. }
  163. static void vga_set_80x60(void)
  164. {
  165. vga_set_480_scanlines();
  166. vga_set_8font();
  167. vga_set_vertical_end(60*8);
  168. }
  169. static int vga_set_mode(struct mode_info *mode)
  170. {
  171. /* Set the basic mode */
  172. vga_set_basic_mode();
  173. /* Override a possibly broken BIOS */
  174. force_x = mode->x;
  175. force_y = mode->y;
  176. switch (mode->mode) {
  177. case VIDEO_80x25:
  178. break;
  179. case VIDEO_8POINT:
  180. vga_set_8font();
  181. break;
  182. case VIDEO_80x43:
  183. vga_set_80x43();
  184. break;
  185. case VIDEO_80x28:
  186. vga_set_14font();
  187. break;
  188. case VIDEO_80x30:
  189. vga_set_80x30();
  190. break;
  191. case VIDEO_80x34:
  192. vga_set_80x34();
  193. break;
  194. case VIDEO_80x60:
  195. vga_set_80x60();
  196. break;
  197. }
  198. return 0;
  199. }
  200. /*
  201. * Note: this probe includes basic information required by all
  202. * systems. It should be executed first, by making sure
  203. * video-vga.c is listed first in the Makefile.
  204. */
  205. static int vga_probe(void)
  206. {
  207. static const char *card_name[] = {
  208. "CGA/MDA/HGC", "EGA", "VGA"
  209. };
  210. static struct mode_info *mode_lists[] = {
  211. cga_modes,
  212. ega_modes,
  213. vga_modes,
  214. };
  215. static int mode_count[] = {
  216. sizeof(cga_modes)/sizeof(struct mode_info),
  217. sizeof(ega_modes)/sizeof(struct mode_info),
  218. sizeof(vga_modes)/sizeof(struct mode_info),
  219. };
  220. struct biosregs ireg, oreg;
  221. initregs(&ireg);
  222. ireg.ax = 0x1200;
  223. ireg.bl = 0x10; /* Check EGA/VGA */
  224. intcall(0x10, &ireg, &oreg);
  225. #ifndef _WAKEUP
  226. boot_params.screen_info.orig_video_ega_bx = oreg.bx;
  227. #endif
  228. /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */
  229. if (oreg.bl != 0x10) {
  230. /* EGA/VGA */
  231. ireg.ax = 0x1a00;
  232. intcall(0x10, &ireg, &oreg);
  233. if (oreg.al == 0x1a) {
  234. adapter = ADAPTER_VGA;
  235. #ifndef _WAKEUP
  236. boot_params.screen_info.orig_video_isVGA = 1;
  237. #endif
  238. } else {
  239. adapter = ADAPTER_EGA;
  240. }
  241. } else {
  242. adapter = ADAPTER_CGA;
  243. }
  244. video_vga.modes = mode_lists[adapter];
  245. video_vga.card_name = card_name[adapter];
  246. return mode_count[adapter];
  247. }
  248. static __videocard video_vga = {
  249. .card_name = "VGA",
  250. .probe = vga_probe,
  251. .set_mode = vga_set_mode,
  252. };