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