video-vga.c 5.7 KB

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