Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2357 lines
77 KiB

  1. /************************************************************************/
  2. /* */
  3. /* MODES_M.C */
  4. /* */
  5. /* (c) 1991,1992, 1993 ATI Technologies Incorporated. */
  6. /************************************************************************/
  7. /********************** PolyTron RCS Utilities
  8. $Revision: 1.18 $
  9. $Date: 10 Apr 1996 17:00:44 $
  10. $Author: RWolff $
  11. $Log: S:/source/wnt/ms11/miniport/archive/modes_m.c_v $
  12. *
  13. * Rev 1.18 10 Apr 1996 17:00:44 RWolff
  14. * Microsoft-originated change.
  15. *
  16. * Rev 1.17 23 Jan 1996 11:46:36 RWolff
  17. * Eliminated level 3 warnings.
  18. *
  19. * Rev 1.16 08 Feb 1995 13:54:38 RWOLFF
  20. * Updated FIFO depth entries to correspond to more recent table.
  21. *
  22. * Rev 1.15 20 Jan 1995 16:23:04 RWOLFF
  23. * Optimized video FIFO depth for the installed RAM size and selected
  24. * resolution, pixel depth, and refresh rate. This gives a slight performance
  25. * improvement on low-res, low-depth, low frequency modes while eliminating
  26. * noise on high-res, high-depth, high frequency modes.
  27. *
  28. * Rev 1.14 23 Dec 1994 10:47:24 ASHANMUG
  29. * ALPHA/Chrontel-DAC
  30. *
  31. * Rev 1.13 18 Nov 1994 11:40:54 RWOLFF
  32. * Added support for STG1702/1703 in native mode, as opposed to being
  33. * strapped into STG1700 emulation.
  34. *
  35. * Rev 1.12 19 Aug 1994 17:11:26 RWOLFF
  36. * Added support for SC15026 DAC and non-standard pixel clock
  37. * generators, removed dead code.
  38. *
  39. * Rev 1.11 09 Aug 1994 11:53:58 RWOLFF
  40. * Shifting of colours when setting up palette is now done in
  41. * display driver.
  42. *
  43. * Rev 1.10 06 Jul 1994 16:23:58 RWOLFF
  44. * Fix for screen doubling when warm booting from ATI driver to 8514/A
  45. * driver on Mach 32.
  46. *
  47. * Rev 1.9 30 Jun 1994 18:10:44 RWOLFF
  48. * Andre Vachon's change: don't clear screen on switch into text mode.
  49. * The HAL will do it, and we aren't allowed to do the memory mapping
  50. * needed to clear the screen.
  51. *
  52. * Rev 1.8 20 May 1994 14:00:40 RWOLFF
  53. * Ajith's change: clears the screen on shutdown.
  54. *
  55. * Rev 1.7 18 May 1994 17:01:18 RWOLFF
  56. * Fixed colour scramble in 16 and 24BPP on IBM ValuePoint (AT&T 49[123]
  57. * DAC), got rid of debug print statements and commented-out code.
  58. *
  59. * Rev 1.6 31 Mar 1994 15:07:00 RWOLFF
  60. * Added debugging code.
  61. *
  62. * Rev 1.5 16 Mar 1994 15:28:02 RWOLFF
  63. * Now determines DAC type using q_DAC_type field of query structure,
  64. * rather than raw value from CONFIG_STATUS_1. This allows different
  65. * DAC types reporting the same value to be distinguished.
  66. *
  67. * Rev 1.4 14 Mar 1994 16:28:10 RWOLFF
  68. * Routines used by ATIMPResetHw() are no longer swappable, SetTextMode_m()
  69. * returns after toggling passthrough on Mach 8.
  70. *
  71. * Rev 1.3 10 Feb 1994 16:02:34 RWOLFF
  72. * Fixed out-of-sync problem in 640x480 16BPP 60Hz.
  73. *
  74. * Rev 1.2 08 Feb 1994 19:00:22 RWOLFF
  75. * Fixed pixel delay for Brooktree 48x DACs. This corrects flickering pixels
  76. * at 8BPP and unstable colours at 16 and 24 BPP.
  77. *
  78. * Rev 1.1 07 Feb 1994 14:09:02 RWOLFF
  79. * Added alloc_text() pragmas to allow miniport to be swapped out when
  80. * not needed.
  81. *
  82. * Rev 1.0 31 Jan 1994 11:11:36 RWOLFF
  83. * Initial revision.
  84. *
  85. * Rev 1.10 24 Jan 1994 18:05:36 RWOLFF
  86. * Now expects mode tables for 16 and 24 BPP on BT48x and AT&T 49[123] DACs
  87. * to already contain modified pixel clock and other fields, rather than
  88. * increasing pixel clock frequency when setting the video mode.
  89. *
  90. * Rev 1.9 14 Jan 1994 15:22:36 RWOLFF
  91. * Added routine to switch into 80x25 16 colour text mode without using BIOS.
  92. *
  93. * Rev 1.8 15 Dec 1993 15:27:32 RWOLFF
  94. * Added support for SC15021 DAC.
  95. *
  96. * Rev 1.7 30 Nov 1993 18:18:40 RWOLFF
  97. * Added support for AT&T 498 DAC, 32BPP on STG1700 DAC.
  98. *
  99. * Rev 1.6 10 Nov 1993 19:24:28 RWOLFF
  100. * Re-enabled MUX handling of 1280x1024 8BPP as special case of InitTi_8_m(),
  101. * fix for dark DOS full-screen on TI DAC cards.
  102. *
  103. * Rev 1.5 05 Nov 1993 13:26:14 RWOLFF
  104. * Added support for STG1700 DAC.
  105. *
  106. * Rev 1.4 15 Oct 1993 18:13:18 RWOLFF
  107. * Fix for memory-mapped scrambled screen.
  108. *
  109. * Rev 1.3 08 Oct 1993 15:18:08 RWOLFF
  110. * No longer includes VIDFIND.H.
  111. *
  112. * Rev 1.2 08 Oct 1993 11:11:04 RWOLFF
  113. * Added "_m" to function names to identify them as being specific to the
  114. * 8514/A-compatible family of ATI accelerators.
  115. *
  116. * Rev 1.1 24 Sep 1993 18:15:08 RWOLFF
  117. * Added support for AT&T 49x DACs.
  118. *
  119. * Rev 1.1 24 Sep 1993 11:47:14 RWOLFF
  120. * Added support for AT&T 49x DACs.
  121. *
  122. * Rev 1.0 03 Sep 1993 14:23:48 RWOLFF
  123. * Initial revision.
  124. Rev 1.0 16 Aug 1993 13:29:28 Robert_Wolff
  125. Initial revision.
  126. Rev 1.18 06 Jul 1993 15:49:46 RWOLFF
  127. Removed mach32_split_fixup special handling (for non-production hardware),
  128. added support for AT&T 491 and ATI 68860 DACs. Unable to obtain appropriate
  129. hardware to test the DAC-related changes, must still add routine to
  130. distinguish AT&T 491 from Brooktree 48x when setting q_dac_type.
  131. Rev 1.17 07 Jun 1993 11:43:42 BRADES
  132. Rev 6 split transfer fixup.
  133. Rev 1.15 18 May 1993 14:06:04 RWOLFF
  134. Calls to wait_for_idle() no longer pass in hardware device extension,
  135. since it's a global variable.
  136. Rev 1.14 27 Apr 1993 20:16:28 BRADES
  137. do not use IO register+1 since now from Linear address table.
  138. Rev 1.13 21 Apr 1993 17:25:22 RWOLFF
  139. Now uses AMACH.H instead of 68800.H/68801.H.
  140. Rev 1.12 14 Apr 1993 18:22:26 RWOLFF
  141. High-colour initialization now supports Bt481 DAC.
  142. Rev 1.11 08 Apr 1993 16:50:48 RWOLFF
  143. Revision level as checked in at Microsoft.
  144. Rev 1.10 15 Mar 1993 22:19:28 BRADES
  145. use m_screen_pitch for the # pixels per display line.
  146. Rev 1.9 08 Mar 1993 19:29:30 BRADES
  147. submit to MS NT
  148. Rev 1.6 06 Jan 1993 10:59:20 Robert_Wolff
  149. ROM BIOS area C0000-DFFFF is now mapped as a single block,
  150. added type casts to eliminate compile warnings.
  151. Rev 1.5 04 Jan 1993 14:42:18 Robert_Wolff
  152. Added card type as a parameter to setmode(). This is done because the
  153. Mach 32 requires GE_PITCH and CRT_PITCH to be set to the horizontal
  154. resolution divided by 8, while the Mach 8 requires them to be set
  155. to the smallest multiple of 128 which is not less than the horizontal
  156. resolution, divided by 8. This difference is only significant for
  157. 800x600, since 640x480, 1024x768, and 1280x1024 all have horizontal
  158. resolutions which are already multiples of 128 pixels.
  159. Rev 1.4 09 Dec 1992 10:31:52 Robert_Wolff
  160. Made setmode() compatible with Mach 8 cards in 800x600 mode, Get_clk_src()
  161. will now compile properly under both MS-DOS and Windows NT.
  162. Rev 1.3 27 Nov 1992 15:18:58 STEPHEN
  163. No change.
  164. Rev 1.2 17 Nov 1992 14:09:24 GRACE
  165. program the palette here instead of in a68_init.asm
  166. Rev 1.1 12 Nov 1992 09:29:04 GRACE
  167. removed all the excess baggage carried over from the video program.
  168. Rev 1.0 05 Nov 1992 14:02:22 Robert_Wolff
  169. Initial revision.
  170. End of PolyTron RCS section *****************/
  171. #ifdef DOC
  172. MODES_M.C - Functions to switch the 8514/A-compatible family of
  173. ATI Graphics Accelerator adapters into ALL supported modes
  174. Note: Different DACs have a different use for the DAC registers
  175. in IO space 2EA-2ED. The DAC_MASK, DAC_R_INDEX may be misleading.
  176. OTHER FILES
  177. #endif
  178. #include <stdio.h>
  179. #include <stdlib.h>
  180. #include <string.h>
  181. #include "miniport.h"
  182. #include "ntddvdeo.h"
  183. #include "video.h"
  184. #include "stdtyp.h"
  185. #include "amach.h"
  186. #include "amach1.h"
  187. #include "atimp.h"
  188. #include "detect_m.h"
  189. #define INCLUDE_MODES_M
  190. #include "modes_m.h"
  191. #include "services.h"
  192. #include "setup_m.h"
  193. #define NUM_ROM_BASE_RANGES 2
  194. #if DBG
  195. #if defined(i386) || defined(_X86_)
  196. #define INT _asm int 3;
  197. #else
  198. #define INT DbgBreakPoint();
  199. #endif
  200. #else
  201. #define INT
  202. #endif
  203. static void InitTIMux_m(int config,ULONG_PTR rom_address);
  204. static BYTE GetClkSrc_m(ULONG *rom_address);
  205. static void SetBlankAdj_m(BYTE adjust);
  206. static void Init68860_m(WORD ext_ge_config);
  207. static void InitSTG1700_m(WORD ext_ge_config, BOOL DoublePixel);
  208. static void InitSTG1702_m(WORD ext_ge_config, BOOL DoublePixel);
  209. static void InitATT498_m(WORD ext_ge_config, BOOL DoublePixel);
  210. static void InitSC15021_m(WORD ext_ge_config, BOOL DoublePixel);
  211. static void InitSC15026_m(WORD ext_ge_config);
  212. static void ReadDac4(void);
  213. /*
  214. * Allow miniport to be swapped out when not needed.
  215. *
  216. * SetTextMode_m() and Passth8514_m() are called by ATIMPResetHw(),
  217. * which must be in nonpageable memory.
  218. */
  219. #if defined (ALLOC_PRAGMA)
  220. #pragma alloc_text(PAGE_M, setmode_m)
  221. #pragma alloc_text(PAGE_M, InitTIMux_m)
  222. #pragma alloc_text(PAGE_M, GetClkSrc_m)
  223. #pragma alloc_text(PAGE_M, SetBlankAdj_m)
  224. #pragma alloc_text(PAGE_M, InitTi_8_m)
  225. #pragma alloc_text(PAGE_M, InitTi_16_m)
  226. #pragma alloc_text(PAGE_M, InitTi_24_m)
  227. #pragma alloc_text(PAGE_M, Init68860_m)
  228. #pragma alloc_text(PAGE_M, InitSTG1700_m)
  229. #pragma alloc_text(PAGE_M, InitSTG1702_m)
  230. #pragma alloc_text(PAGE_M, InitATT498_m)
  231. #pragma alloc_text(PAGE_M, InitSC15021_m)
  232. #pragma alloc_text(PAGE_M, InitSC15026_m)
  233. #pragma alloc_text(PAGE_M, ReadDac4)
  234. #pragma alloc_text(PAGE_M, UninitTiDac_m)
  235. #pragma alloc_text(PAGE_M, SetPalette_m)
  236. #endif
  237. /*
  238. * void Passth8514_m(status)
  239. *
  240. * int status; Desired source for display
  241. *
  242. * Turn passthrough off (accelerator mode) if status is SHOW_ACCEL,
  243. * or on (vga passthrough) if status is SHOW_VGA.
  244. *
  245. * Note that this routine is specific to ATI graphics accelerators.
  246. * Generic 8514/A routine should also include setting up CRT parameters
  247. * to ensure that the DAC gets a reasonable clock rate.
  248. */
  249. void Passth8514_m(int status)
  250. {
  251. OUTP(DISP_CNTL,0x53); /* disable CRT controller */
  252. if (status == SHOW_ACCEL)
  253. {
  254. OUTPW(ADVFUNC_CNTL,0x7);
  255. OUTPW(CLOCK_SEL,(WORD)(INPW(CLOCK_SEL)|1)); /* slow down the clock rate */
  256. }
  257. else
  258. {
  259. OUTPW(ADVFUNC_CNTL,0x6);
  260. OUTPW(CLOCK_SEL,(WORD)(INPW(CLOCK_SEL)&0xfffe)); /* speed up the clock rate */
  261. }
  262. OUTP(DISP_CNTL,0x33); /* enable CRT controller */
  263. return;
  264. } /* Passth8514_m() */
  265. /*
  266. * void setmode_m(crttable, rom_address, CardType);
  267. *
  268. * struct st_mode_table *crttable; CRT parameters for desired mode
  269. * ULONG_PTR rom_address; Location of ROM BIOS (virtual address)
  270. * ULONG CardType; Type of ATI accelerator
  271. *
  272. * Initialize the CRT controller in the 8514/A-compatible
  273. * family of ATI accelerators.
  274. */
  275. void setmode_m (struct st_mode_table *crttable, ULONG_PTR rom_address, ULONG CardType)
  276. {
  277. BYTE clock;
  278. WORD overscan;
  279. BYTE low,high;
  280. WORD ClockSelect; /* Value to write to CLOCK_SEL register */
  281. struct query_structure *QueryPtr; /* Query information for the card */
  282. ULONG BaseClock; /* Pixel rate not adjusted for DAC type and pixel depth */
  283. /*
  284. * Get a formatted pointer into the query section of HwDeviceExtension.
  285. * The CardInfo[] field is an unformatted buffer.
  286. */
  287. QueryPtr = (struct query_structure *) (phwDeviceExtension->CardInfo);
  288. ClockSelect = (crttable->m_clock_select & CLOCK_SEL_STRIP) | GetShiftedSelector(crttable->ClockFreq);
  289. WaitForIdle_m();
  290. OUTP(SHADOW_SET, 2); /* unlock shadows */
  291. DEC_DELAY
  292. DEC_DELAY
  293. OUTP(SHADOW_CTL, 0);
  294. DEC_DELAY
  295. OUTP(SHADOW_SET, 1);
  296. DEC_DELAY
  297. OUTP(SHADOW_CTL, 0);
  298. DEC_DELAY
  299. OUTP(SHADOW_SET, 0);
  300. DEC_DELAY
  301. /* disable CRT controller */
  302. OUTP(DISP_CNTL,0x53);
  303. delay(10);
  304. OUTP(CLOCK_SEL, (UCHAR)(ClockSelect | 0x01 )); /* Disable passthrough */
  305. DEC_DELAY
  306. OUTP(V_SYNC_WID, crttable->m_v_sync_wid);
  307. DEC_DELAY
  308. OUTPW(V_SYNC_STRT, crttable->m_v_sync_strt);
  309. DEC_DELAY
  310. OUTPW(V_DISP, crttable->m_v_disp);
  311. DEC_DELAY
  312. OUTPW(V_TOTAL, crttable->m_v_total);
  313. DEC_DELAY
  314. OUTP(H_SYNC_WID, crttable->m_h_sync_wid);
  315. DEC_DELAY
  316. OUTP(H_SYNC_STRT, crttable->m_h_sync_strt);
  317. DEC_DELAY
  318. OUTP(H_DISP, crttable->m_h_disp);
  319. DEC_DELAY
  320. OUTP(H_TOTAL, crttable->m_h_total);
  321. DEC_DELAY
  322. OUTP(GE_PITCH, (UCHAR) (crttable->m_screen_pitch >> 3));
  323. DEC_DELAY
  324. OUTP(CRT_PITCH, (UCHAR) (crttable->m_screen_pitch >> 3));
  325. delay(10);
  326. OUTP(DISP_CNTL, crttable->m_disp_cntl);
  327. delay(10);
  328. /*
  329. * Set up the Video FIFO depth. This field is used only on DRAM cards.
  330. * Since the required FIFO depth depends on 4 values (memory size,
  331. * pixel depth, resolution, and refresh rate) which are not enumerated
  332. * types, implementing the selection as an array indexed by these
  333. * values would require a very large, very sparse array.
  334. *
  335. * Select DRAM cards by excluding all known VRAM types rather than
  336. * by including all known DRAM types because only 7 of the 8 possible
  337. * memory types are defined. If the eighth type is VRAM and we include
  338. * it because it's not in the exclusion list, the value we assign will
  339. * be ignored. If it's DRAM and we exclude it because it's not in the
  340. * inclusion list, we will have problems.
  341. */
  342. if ((QueryPtr->q_memory_type != VMEM_VRAM_256Kx4_SER512) &&
  343. (QueryPtr->q_memory_type != VMEM_VRAM_256Kx4_SER256) &&
  344. (QueryPtr->q_memory_type != VMEM_VRAM_256Kx4_SPLIT512) &&
  345. (QueryPtr->q_memory_type != VMEM_VRAM_256Kx16_SPLIT256))
  346. {
  347. /*
  348. * We can't switch on the refresh rate because if we're setting
  349. * the mode from the installed mode table rather than one of the
  350. * "canned" tables, the refresh rate field will hold a reserved
  351. * value rather than the true rate. Instead, use the pixel rate,
  352. * which varies with refresh rate. We can't simply use the pixel
  353. * clock frequency, since it will have been boosted for certain
  354. * DAC and pixel depth combinations. Instead, we must undo this
  355. * boost in order to get the pixel rate.
  356. */
  357. switch (crttable->m_pixel_depth)
  358. {
  359. case 24:
  360. if ((QueryPtr->q_DAC_type == DAC_BT48x) ||
  361. (QueryPtr->q_DAC_type == DAC_SC15026) ||
  362. (QueryPtr->q_DAC_type == DAC_ATT491))
  363. {
  364. BaseClock = crttable->ClockFreq / 3;
  365. }
  366. else if ((QueryPtr->q_DAC_type == DAC_SC15021) ||
  367. (QueryPtr->q_DAC_type == DAC_STG1702) ||
  368. (QueryPtr->q_DAC_type == DAC_STG1703))
  369. {
  370. BaseClock = crttable->ClockFreq * 2;
  371. BaseClock /= 3;
  372. }
  373. else if ((QueryPtr->q_DAC_type == DAC_STG1700) ||
  374. (QueryPtr->q_DAC_type == DAC_ATT498))
  375. {
  376. BaseClock = crttable->ClockFreq / 2;
  377. }
  378. else
  379. {
  380. BaseClock = crttable->ClockFreq;
  381. }
  382. break;
  383. case 16:
  384. if ((QueryPtr->q_DAC_type == DAC_BT48x) ||
  385. (QueryPtr->q_DAC_type == DAC_SC15026) ||
  386. (QueryPtr->q_DAC_type == DAC_ATT491))
  387. {
  388. BaseClock = crttable->ClockFreq / 2;
  389. }
  390. else
  391. {
  392. BaseClock = crttable->ClockFreq;
  393. }
  394. break;
  395. case 8:
  396. default:
  397. BaseClock = crttable->ClockFreq;
  398. break;
  399. }
  400. /*
  401. * 1M cards include Mach 8 combo cards which report the total
  402. * (accelerator plus VGA) memory in q_memory_size. Since the
  403. * maximum VGA memory on these cards is 512k, none of them will
  404. * report 2M. If we were to look for 1M cards, we'd also have to
  405. * check for 1.25M and 1.5M cards in order to catch the combos.
  406. *
  407. * Some threshold values of BaseClock are chosen to catch both
  408. * straight-through (DAC displays 1 pixel per clock) and adjusted
  409. * (DAC needs more than 1 clock per pixel) cases, and so do not
  410. * correspond to the pixel clock frequency for any mode.
  411. */
  412. if (QueryPtr->q_memory_size == VRAM_2mb)
  413. {
  414. switch (crttable->m_pixel_depth)
  415. {
  416. case 24:
  417. /*
  418. * Only 640x480 and 800x600 suported.
  419. */
  420. if (crttable->m_x_size == 640)
  421. {
  422. if (BaseClock < 30000000L) /* 60Hz */
  423. clock = 0x08;
  424. else /* 72Hz */
  425. clock = 0x0A;
  426. }
  427. else /* 800x600 */
  428. {
  429. if (BaseClock <= 32500000) /* 89Hz interlaced */
  430. clock = 0x0A;
  431. else if (BaseClock <= 36000000) /* 95Hz interlaced and 56Hz */
  432. clock = 0x0C;
  433. else if (BaseClock <= 40000000) /* 60Hz */
  434. clock = 0x0D;
  435. else /* 70Hz and 72Hz */
  436. clock = 0x0E;
  437. }
  438. break;
  439. case 16:
  440. /*
  441. * All resolutions except 1280x1024 supported.
  442. */
  443. if (crttable->m_x_size == 640)
  444. {
  445. if (BaseClock < 30000000L) /* 60Hz */
  446. clock = 0x04;
  447. else /* 72Hz */
  448. clock = 0x05;
  449. }
  450. else if (crttable->m_x_size == 800)
  451. {
  452. if (BaseClock <= 40000000) /* 89Hz and 95Hz interlaced, 56Hz, and 60Hz */
  453. clock = 0x05;
  454. else if (BaseClock <= 46000000) /* 70Hz */
  455. clock = 0x07;
  456. else /* 72Hz */
  457. clock = 0x08;
  458. }
  459. else /* 1024x768 */
  460. {
  461. if (BaseClock < 45000000) /* 87Hz interlaced */
  462. {
  463. clock = 0x07;
  464. }
  465. else if (BaseClock < 70000000) /* 60Hz */
  466. {
  467. clock = 0x0B;
  468. }
  469. else /* 66Hz, 70Hz, and 72Hz */
  470. {
  471. clock = 0x0D;
  472. }
  473. }
  474. break;
  475. case 8:
  476. default: /* If 4BPP is implemented, it will be treated like 8BPP */
  477. if (crttable->m_x_size == 640)
  478. {
  479. /*
  480. * Both available refresh rates use the same value
  481. */
  482. clock = 0x02;
  483. }
  484. else if (crttable->m_x_size == 800)
  485. {
  486. if (BaseClock <= 46000000) /* 89Hz and 95Hz interlaced, 56Hz, 60Hz, and 70Hz */
  487. clock = 0x02;
  488. else /* 72Hz */
  489. clock = 0x04;
  490. }
  491. else if (crttable->m_x_size == 1024)
  492. {
  493. if (BaseClock < 45000000) /* 87Hz interlaced */
  494. {
  495. clock = 0x03;
  496. }
  497. else if (BaseClock < 70000000) /* 60Hz */
  498. {
  499. clock = 0x05;
  500. }
  501. else /* 66Hz, 70Hz, and 72Hz */
  502. {
  503. clock = 0x06;
  504. }
  505. }
  506. else /* 1280x1024 */
  507. {
  508. if (BaseClock < 100000000) /* both interlaced modes */
  509. clock = 0x07;
  510. else /* 60Hz - only DRAM noninterlaced mode */
  511. clock = 0x0A;
  512. }
  513. break;
  514. }
  515. }
  516. else /* 1M cards */
  517. {
  518. switch (crttable->m_pixel_depth)
  519. {
  520. case 24:
  521. /*
  522. * Only 640x480 fits in 1M. Both 60Hz and 72Hz
  523. * use the same FIFO depth.
  524. */
  525. clock = 0x0E;
  526. break;
  527. case 16:
  528. /*
  529. * Only 640x480 and 800x600 suported.
  530. */
  531. if (crttable->m_x_size == 640)
  532. {
  533. if (BaseClock < 30000000L) /* 60Hz */
  534. clock = 0x08;
  535. else /* 72Hz */
  536. clock = 0x0A;
  537. }
  538. else /* 800x600 */
  539. {
  540. if (BaseClock <= 32500000) /* 89Hz interlaced */
  541. clock = 0x0A;
  542. else /* 95Hz interlaced and 56Hz, higher rates not supported in 1M */
  543. clock = 0x0C;
  544. }
  545. break;
  546. case 8:
  547. default: /* If 4BPP is implemented, it will be treated like 8BPP */
  548. if (crttable->m_x_size == 640)
  549. {
  550. if (BaseClock < 30000000L) /* 60Hz */
  551. clock = 0x04;
  552. else /* 72Hz */
  553. clock = 0x05;
  554. }
  555. else if (crttable->m_x_size == 800)
  556. {
  557. if (BaseClock <= 32500000) /* 89Hz interlaced */
  558. clock = 0x05;
  559. else if (BaseClock <= 40000000) /* 95Hz interlaced, 56Hz, and 60Hz */
  560. clock = 0x06;
  561. else if (BaseClock <= 46000000) /* 70Hz */
  562. clock = 0x07;
  563. else /* 72Hz */
  564. clock = 0x08;
  565. }
  566. else if (crttable->m_x_size == 1024)
  567. {
  568. if (BaseClock < 45000000) /* 87Hz interlaced */
  569. {
  570. clock = 0x07;
  571. }
  572. else /* 60Hz, 66Hz, 70Hz, and 72Hz */
  573. {
  574. clock = 0x08;
  575. }
  576. }
  577. else /* 1280x1024 */
  578. {
  579. /*
  580. * Only interlaced modes supported in 1M (4BPP only),
  581. * both use the same FIFO depth.
  582. */
  583. clock = 0x03;
  584. }
  585. break;
  586. }
  587. }
  588. WaitForIdle_m();
  589. OUTPW (CLOCK_SEL, (WORD)((clock << 8) | (ClockSelect & 0x00FF) | 0x01));
  590. DEC_DELAY
  591. }
  592. overscan=crttable->m_h_overscan;
  593. low=(BYTE)(overscan&0xff);
  594. high=(BYTE)(overscan>>8);
  595. high=high>>4;
  596. low=low&0xf;
  597. if (high>=low)
  598. high=low;
  599. else
  600. low=high;
  601. high=high<<4;
  602. low=low|high;
  603. WaitForIdle_m();
  604. OUTPW(HORZ_OVERSCAN,(WORD)(low & 0x00FF));
  605. DEC_DELAY
  606. overscan=crttable->m_v_overscan;
  607. low=(BYTE)(overscan&0xff);
  608. high=(BYTE)(overscan>>8);
  609. if (high>=low)
  610. high=low;
  611. else
  612. low=high;
  613. high <<= 8;
  614. overscan=(WORD)high + (WORD)low;
  615. OUTPW(VERT_OVERSCAN,overscan);
  616. DEC_DELAY
  617. return;
  618. } /* setmode_m() */
  619. /*
  620. * void InitTIMux_m(config, rom_address);
  621. *
  622. * int config; Default EXT_GE_CONFIG (should be 0x10A or 0x11A)
  623. * ULONG_PTR rom_address; Virtual address of start of ROM BIOS
  624. *
  625. * Put TI DAC into MUX mode for 1280x1024 non-interlaced displays.
  626. */
  627. void InitTIMux_m(int config,ULONG_PTR rom_address)
  628. {
  629. struct query_structure *QueryPtr; /* Query information for the card */
  630. WORD reg;
  631. WORD temp;
  632. /*
  633. * Get a formatted pointer into the query section of HwDeviceExtension.
  634. * The CardInfo[] field is an unformatted buffer.
  635. */
  636. QueryPtr = (struct query_structure *) (phwDeviceExtension->CardInfo);
  637. if (QueryPtr->q_DAC_type == DAC_TI34075)
  638. {
  639. reg=INPW(CLOCK_SEL);
  640. temp = (reg & CLOCK_SEL_STRIP) | GetShiftedSelector(50000000L);
  641. OUTPW(CLOCK_SEL,temp);
  642. OUTPW(EXT_GE_CONFIG,0x201a); /* Set EXT_DAC_ADDR field */
  643. OUTP(DAC_MASK,9); /* OUTPut clock is SCLK/2 and VCLK/2 */
  644. OUTP(DAC_R_INDEX,0x1d); /* set MUX control to 8/16 */
  645. /* INPut clock source is CLK3 or CLK1 (most current release) */
  646. OUTP(DAC_DATA,GetClkSrc_m((ULONG *) rom_address));
  647. /* reset EXT_DAC_ADDR, put DAC in 6 bit mode, engine in 8 bit mode, enable MUX mode */
  648. OUTPW(EXT_GE_CONFIG,(WORD)config);
  649. SetBlankAdj_m(1); /* set BLANK_ADJUST=1, PIXEL_DELAY=0 */
  650. OUTPW (CLOCK_SEL,reg);
  651. }
  652. return;
  653. } /* InitTIMux_m() */
  654. /*
  655. * BYTE GetClkSrc_m(rom_address);
  656. *
  657. * ULONG *rom_address; Virtual address of start of ROM BIOS
  658. *
  659. * Get INPUT_CLOCK_SEL value for TI DACs
  660. *
  661. * Returns:
  662. * Input clock source
  663. */
  664. BYTE GetClkSrc_m(ULONG *rom_address)
  665. {
  666. WORD *rom;
  667. BYTE *crom;
  668. BYTE clock_sel=0;
  669. int i;
  670. rom= (PUSHORT)*rom_address++;
  671. if (rom && VideoPortReadRegisterUshort ((PUSHORT)rom)==VIDEO_ROM_ID)
  672. {
  673. crom=(BYTE *)rom;
  674. clock_sel=VideoPortReadRegisterUchar (&crom[0x47]);
  675. i=NUM_ROM_BASE_RANGES;
  676. }
  677. if (clock_sel==0)
  678. clock_sel=1;
  679. return(clock_sel);
  680. } /* GetClkSrc_m() */
  681. /*
  682. * void SetBlankAdj_m(adjust);
  683. *
  684. * BYTE adjust; Desired blank adjust (bits 0-1)
  685. * and pixel delay (bits 2-3) values
  686. *
  687. * Sets the blank adjust and pixel delay values.
  688. */
  689. void SetBlankAdj_m(BYTE adjust)
  690. {
  691. WORD misc;
  692. misc = INPW(R_MISC_CNTL) & 0xF0FF | (adjust << 8);
  693. OUTPW (MISC_CNTL,misc);
  694. return;
  695. } /* SetBlankAdj_m() */
  696. /*
  697. * void InitTi_8_m(ext_ge_config);
  698. *
  699. * WORD ext_ge_config; Desired EXT_GE_CONFIG value (should be 0x1a)
  700. *
  701. * Initialize DAC for standard 8 bit per pixel mode.
  702. */
  703. void InitTi_8_m(WORD ext_ge_config)
  704. {
  705. struct query_structure *QueryPtr; /* Query information for the card */
  706. WORD ClockSelect; /* Value from CLOCK_SEL register */
  707. struct st_mode_table *CrtTable; /* Pointer to current mode table */
  708. /*
  709. * Get a formatted pointer into the query section of HwDeviceExtension,
  710. * and another pointer to the current mode table. The CardInfo[] field
  711. * is an unformatted buffer.
  712. */
  713. QueryPtr = (struct query_structure *) (phwDeviceExtension->CardInfo);
  714. CrtTable = (struct st_mode_table *)QueryPtr;
  715. ((struct query_structure *)CrtTable)++;
  716. CrtTable += phwDeviceExtension->ModeIndex;
  717. switch(QueryPtr->q_DAC_type)
  718. {
  719. case DAC_ATT491: /* At 8 BPP, Brooktree 48x and AT&T 20C491 */
  720. case DAC_BT48x: /* are set up the same way */
  721. OUTPW(EXT_GE_CONFIG,0x101a); /* Set EXT_DAC_ADDR */
  722. OUTP (DAC_MASK,0);
  723. SetBlankAdj_m(0x0C); /* set BLANK_ADJUST=0, PIXEL_DELAY=3 */
  724. break;
  725. case DAC_STG1700:
  726. /*
  727. * If we are running 1280x1024 noninterlaced, cut the
  728. * clock frequency in half, set the MUX bit in
  729. * ext_ge_config, and tell InitSTG1700_m() to use the
  730. * 8BPP double pixel mode.
  731. *
  732. * All 1280x1024 noninterlaced modes use a pixel clock
  733. * frequency of 110 MHz or higher, with the clock
  734. * frequency divided by 1.
  735. */
  736. ClockSelect = INPW(CLOCK_SEL);
  737. if ((QueryPtr->q_desire_x == 1280) &&
  738. ((CrtTable->m_clock_select & CLOCK_SEL_MUX) ||
  739. (CrtTable->ClockFreq >= 110000000)))
  740. {
  741. if (CrtTable->ClockFreq >= 110000000)
  742. {
  743. ClockSelect &= CLOCK_SEL_STRIP;
  744. ClockSelect |= GetShiftedSelector((CrtTable->ClockFreq) / 2);
  745. OUTPW(CLOCK_SEL, ClockSelect);
  746. }
  747. ext_ge_config |= 0x0100;
  748. InitSTG1700_m(ext_ge_config, TRUE);
  749. }
  750. else
  751. {
  752. InitSTG1700_m(ext_ge_config, FALSE);
  753. }
  754. break;
  755. case DAC_STG1702:
  756. case DAC_STG1703:
  757. /*
  758. * If we are running 1280x1024 noninterlaced, cut the
  759. * clock frequency in half, set the MUX bit in
  760. * ext_ge_config, and tell InitSTG1702_m() to use the
  761. * 8BPP double pixel mode.
  762. *
  763. * All 1280x1024 noninterlaced modes use a pixel clock
  764. * frequency of 110 MHz or higher, with the clock
  765. * frequency divided by 1.
  766. */
  767. ClockSelect = INPW(CLOCK_SEL);
  768. if ((QueryPtr->q_desire_x == 1280) &&
  769. ((CrtTable->m_clock_select & CLOCK_SEL_MUX) ||
  770. (CrtTable->ClockFreq >= 110000000)))
  771. {
  772. if (CrtTable->ClockFreq >= 110000000)
  773. {
  774. ClockSelect &= CLOCK_SEL_STRIP;
  775. ClockSelect |= GetShiftedSelector((CrtTable->ClockFreq) / 2);
  776. OUTPW(CLOCK_SEL, ClockSelect);
  777. }
  778. ext_ge_config |= 0x0100;
  779. InitSTG1702_m(ext_ge_config, TRUE);
  780. }
  781. else
  782. {
  783. InitSTG1702_m(ext_ge_config, FALSE);
  784. }
  785. break;
  786. case DAC_ATT498:
  787. /*
  788. * If we are running 1280x1024 noninterlaced, cut the
  789. * clock frequency in half, set the MUX bit in
  790. * ext_ge_config, and tell InitATT498_m() to use the
  791. * 8BPP double pixel mode.
  792. *
  793. * All 1280x1024 noninterlaced modes use a pixel clock
  794. * frequency of 110 MHz or higher, with the clock
  795. * frequency divided by 1.
  796. */
  797. ClockSelect = INPW(CLOCK_SEL);
  798. if ((QueryPtr->q_desire_x == 1280) &&
  799. ((CrtTable->m_clock_select & CLOCK_SEL_MUX) ||
  800. (CrtTable->ClockFreq >= 110000000)))
  801. {
  802. if (CrtTable->ClockFreq >= 110000000)
  803. {
  804. ClockSelect &= CLOCK_SEL_STRIP;
  805. ClockSelect |= GetShiftedSelector((CrtTable->ClockFreq) / 2);
  806. OUTPW(CLOCK_SEL, ClockSelect);
  807. }
  808. ext_ge_config |= 0x0100;
  809. InitATT498_m(ext_ge_config, TRUE);
  810. }
  811. else
  812. {
  813. InitATT498_m(ext_ge_config, FALSE);
  814. }
  815. break;
  816. case DAC_SC15021:
  817. /*
  818. * If we are running 1280x1024 noninterlaced, cut the
  819. * clock frequency in half, set the MUX bit in
  820. * ext_ge_config, and tell InitSC15021_m() to use the
  821. * 8BPP double pixel mode.
  822. *
  823. * All 1280x1024 noninterlaced modes use a pixel clock
  824. * frequency of 110 MHz or higher, with the clock
  825. * frequency divided by 1.
  826. */
  827. ClockSelect = INPW(CLOCK_SEL);
  828. if ((QueryPtr->q_desire_x == 1280) &&
  829. ((CrtTable->m_clock_select & CLOCK_SEL_MUX) ||
  830. (CrtTable->ClockFreq >= 110000000)))
  831. {
  832. /*
  833. * NOTE: The only SC15021 card available for testing
  834. * (93/12/07) is a DRAM card. Since 1280x1024
  835. * noninterlaced is only available on VRAM cards,
  836. * it has not been tested.
  837. */
  838. if (CrtTable->ClockFreq >= 110000000)
  839. {
  840. ClockSelect &= CLOCK_SEL_STRIP;
  841. ClockSelect |= GetShiftedSelector((CrtTable->ClockFreq) / 2);
  842. OUTPW(CLOCK_SEL, ClockSelect);
  843. }
  844. ext_ge_config |= 0x0100;
  845. InitSC15021_m(ext_ge_config, TRUE);
  846. }
  847. else
  848. {
  849. InitSC15021_m(ext_ge_config, FALSE);
  850. }
  851. break;
  852. case DAC_SC15026:
  853. InitSC15026_m(ext_ge_config);
  854. break;
  855. case DAC_TI34075:
  856. /*
  857. * Handle 1280x1024 through the MUX.
  858. */
  859. if (QueryPtr->q_desire_x == 1280)
  860. {
  861. InitTIMux_m(0x11a, (ULONG_PTR) &(phwDeviceExtension->RomBaseRange));
  862. return;
  863. }
  864. else
  865. {
  866. OUTPW(EXT_GE_CONFIG,0x201a); /* Set EXT_DAC_ADDR field */
  867. DEC_DELAY
  868. OUTP (DAC_DATA,0); /* Input clock source is CLK0 */
  869. DEC_DELAY
  870. OUTP (DAC_MASK,0); /* Output clock is SCLK/1 and VCLK/1 */
  871. DEC_DELAY
  872. OUTP (DAC_R_INDEX,0x2d); /* set MUX control to 8/8 */
  873. DEC_DELAY
  874. SetBlankAdj_m(0xc); /* set pixel delay to 3 */
  875. DEC_DELAY
  876. OUTPW(HORZ_OVERSCAN,1); /* set horizontal skew */
  877. DEC_DELAY
  878. break;
  879. }
  880. case DAC_ATI_68860:
  881. Init68860_m(ext_ge_config);
  882. break;
  883. }
  884. //
  885. // reset EXT_DAC_ADDR, put DAC in 6 bit mode
  886. //
  887. OUTPW(EXT_GE_CONFIG,ext_ge_config);
  888. DEC_DELAY
  889. OUTP (DAC_MASK,0xff); /* enable DAC_MASK */
  890. DEC_DELAY
  891. return;
  892. } /* InitTi_8_m() */
  893. /*
  894. * void InitTi_16_m(ext_ge_config, rom_address);
  895. *
  896. * WORD ext_ge_config; Desired EXT_GE_CONFIG value (should be 0x2a, 0x6a, 0xaa, or 0xea)
  897. * ULONG_PTR rom_address; Virtual address of start of ROM BIOS
  898. *
  899. * Initialize DAC for 16 bit per pixel mode.
  900. */
  901. void InitTi_16_m(WORD ext_ge_config, ULONG_PTR rom_address)
  902. {
  903. WORD ReadExtGeConfig;
  904. BYTE dummy;
  905. struct query_structure *QueryPtr; /* Query information for the card */
  906. /*
  907. * Get a formatted pointer into the query section of HwDeviceExtension.
  908. * The CardInfo[] field is an unformatted buffer.
  909. */
  910. QueryPtr = (struct query_structure *) (phwDeviceExtension->CardInfo);
  911. switch(QueryPtr->q_DAC_type)
  912. {
  913. case DAC_TI34075:
  914. /* TLC34075 initialization */
  915. /* disable overlay feature */
  916. OUTP (DAC_MASK,0);
  917. DEC_DELAY
  918. /* set BLANK_ADJUST=1, PIXEL_DELAY=0 */
  919. SetBlankAdj_m(1);
  920. /* Set EXT_DAC_ADDR field */
  921. OUTPW(EXT_GE_CONFIG,0x201a);
  922. DEC_DELAY
  923. /* get INPut clock source */
  924. OUTP (DAC_DATA, GetClkSrc_m((ULONG *) rom_address));
  925. DEC_DELAY
  926. /*
  927. * Re-write the I/O vs. memory mapped flag (bit 5 of
  928. * LOCAL_CONTROL set). If this is not done, and memory
  929. * mapped registers are being used, the EXT_GE_CONFIG
  930. * value won't be interpreted properly.
  931. *
  932. * If this is done at the beginning of the
  933. * IOCTL_VIDEO_SET_CURRENT_MODE packet, rather than
  934. * just before setting EXT_GE_CONFIG for each DAC type,
  935. * it has no effect.
  936. */
  937. OUTPW(LOCAL_CONTROL, INPW(LOCAL_CONTROL));
  938. /* OUTPut clock source is SCLK/1 and VCLK/1 */
  939. /* -- for modes which require PCLK/2, set VCLK/2 */
  940. if ( INPW(CLOCK_SEL) & 0xc0 )
  941. {
  942. DEC_DELAY
  943. OUTPW (CLOCK_SEL, (WORD)(INPW(CLOCK_SEL) & 0xff3f));
  944. DEC_DELAY
  945. if ( (INPW(R_H_DISP) & 0x00FF) == 0x4f ) // H_DISP = 640?
  946. {
  947. /* exception case: 640x480 60 Hz needs longer blank adjust (2) */
  948. DEC_DELAY
  949. SetBlankAdj_m(2);
  950. }
  951. OUTP (DAC_MASK,8);
  952. DEC_DELAY
  953. }
  954. else{
  955. DEC_DELAY
  956. OUTP (DAC_MASK,0);
  957. DEC_DELAY
  958. }
  959. OUTP (DAC_R_INDEX,0xd); /* set MUX control to 24/32 */
  960. DEC_DELAY
  961. /* reset EXT_DAC_ADDR, put DAC in 8 bit mode, engine in 555 mode */
  962. OUTPW (EXT_GE_CONFIG, (WORD)(ext_ge_config | 0x4000));
  963. DEC_DELAY
  964. break;
  965. case DAC_BT48x: /* Brooktree Bt481 initialization */
  966. /*
  967. * Re-write the I/O vs. memory mapped flag (bit 5 of
  968. * LOCAL_CONTROL set). If this is not done, and memory
  969. * mapped registers are being used, the clock select
  970. * value won't be interpreted properly.
  971. */
  972. OUTPW(LOCAL_CONTROL, INPW(LOCAL_CONTROL));
  973. ReadExtGeConfig = INPW(R_EXT_GE_CONFIG) & 0x000f;
  974. ReadExtGeConfig |= (ext_ge_config & 0x0ff0);
  975. OUTPW(EXT_GE_CONFIG, (WORD)(ReadExtGeConfig | 0x1000));
  976. /*
  977. * See Bt481/Bt482 Product Description p.5 top of col. 2
  978. */
  979. dummy = INP(DAC_MASK);
  980. dummy = INP(DAC_MASK);
  981. dummy = INP(DAC_MASK);
  982. dummy = INP(DAC_MASK);
  983. /*
  984. * Determine 555 or 565
  985. */
  986. if (ext_ge_config & 0x0c0)
  987. OUTP(DAC_MASK, 0x0e0); /* 565 */
  988. else
  989. OUTP(DAC_MASK, 0x0a0); /* 555 */
  990. OUTPW(EXT_GE_CONFIG, ReadExtGeConfig);
  991. SetBlankAdj_m(0x0C); /* set BLANK_ADJUST=0, PIXEL_DELAY=3 */
  992. break;
  993. /*
  994. * ATT20C491 initialization. At 16BPP, this DAC is subtly
  995. * different from the Brooktree 48x.
  996. */
  997. case DAC_ATT491:
  998. OUTP (DAC_MASK,0);
  999. SetBlankAdj_m(0x0C); /* BLANK_ADJUST=0, PIXEL_DELAY=3 */
  1000. OUTPW(EXT_GE_CONFIG,0x101a); /* set EXT_DAC_ADDR */
  1001. /*
  1002. * Windows NT miniport currently only supports 565 in 16BPP.
  1003. * The test for the mode may need to be changed once all
  1004. * orderings are supported.
  1005. */
  1006. if (ext_ge_config &0x0c0)
  1007. OUTP (DAC_MASK,0xc0); // 565, 8 bit
  1008. else
  1009. OUTP (DAC_MASK,0xa0); // 555, 8 bit UNTESTED MODE
  1010. OUTPW(EXT_GE_CONFIG,ext_ge_config);
  1011. break;
  1012. case DAC_STG1700:
  1013. InitSTG1700_m(ext_ge_config, FALSE);
  1014. break;
  1015. case DAC_STG1702:
  1016. case DAC_STG1703:
  1017. InitSTG1702_m(ext_ge_config, FALSE);
  1018. break;
  1019. case DAC_ATT498:
  1020. InitATT498_m(ext_ge_config, FALSE);
  1021. break;
  1022. case DAC_SC15021:
  1023. InitSC15021_m(ext_ge_config, FALSE);
  1024. break;
  1025. case DAC_SC15026:
  1026. InitSC15026_m(ext_ge_config);
  1027. break;
  1028. case DAC_ATI_68860:
  1029. SetBlankAdj_m(0x0C); /* BLANK_ADJUST=0, PIXEL_DELAY=3 */
  1030. Init68860_m(ext_ge_config);
  1031. OUTPW(EXT_GE_CONFIG,ext_ge_config);
  1032. break;
  1033. default:
  1034. OUTPW(EXT_GE_CONFIG,ext_ge_config);
  1035. /* set pixel delay (3) for non-TI_DACs */
  1036. SetBlankAdj_m(0xc);
  1037. break;
  1038. }
  1039. return;
  1040. } /* InitTi_16_m() */
  1041. /*
  1042. * void InitTi_24_m(ext_ge_config, rom_address);
  1043. *
  1044. * WORD ext_ge_config; Desired EXT_GE_CONFIG value (should be 0x3a | 24_BIT_OPTIONS)
  1045. * ULONG_PTR rom_address; Virtual address of start of ROM BIOS
  1046. *
  1047. * Initialize DAC for 24 bit per pixel mode, 3 bytes, RGB.
  1048. */
  1049. void InitTi_24_m(WORD ext_ge_config, ULONG_PTR rom_address)
  1050. {
  1051. WORD clock_sel;
  1052. BYTE dummy;
  1053. WORD ReadExtGeConfig;
  1054. struct query_structure *QueryPtr; /* Query information for the card */
  1055. /*
  1056. * Get a formatted pointer into the query section of HwDeviceExtension.
  1057. * The CardInfo[] field is an unformatted buffer.
  1058. */
  1059. QueryPtr = (struct query_structure *) (phwDeviceExtension->CardInfo);
  1060. /*
  1061. * Set 8-bit DAC operation.
  1062. */
  1063. ext_ge_config |= 0x4000;
  1064. switch(QueryPtr->q_DAC_type)
  1065. {
  1066. case DAC_TI34075: /* TLC34075 initialization */
  1067. SetBlankAdj_m(1); /* BLANK_ADJ=1, PIXEL_DELAY=0 */
  1068. DEC_DELAY
  1069. OUTPW(EXT_GE_CONFIG,0x201a); /* Set EXT_DAC_ADDR field */
  1070. DEC_DELAY
  1071. OUTP (DAC_DATA, GetClkSrc_m((ULONG *) rom_address));
  1072. DEC_DELAY
  1073. /* OUTPut clock source is SCLK/1 and VCLK/1 */
  1074. /* -- for modes which require PCLK/2, set VCLK/2 */
  1075. clock_sel= INPW(CLOCK_SEL);
  1076. DEC_DELAY
  1077. /*
  1078. * If clock select is currently divided by 2, divide by 1.
  1079. */
  1080. if (clock_sel & 0xc0)
  1081. {
  1082. clock_sel &= 0xff3f;
  1083. /*
  1084. * 640x480 60Hz needs longer blank adjust (2). Other
  1085. * refresh rates at 640x400 don't need this, but they
  1086. * use a divide-by-1 clock so they don't reach this point.
  1087. */
  1088. if (INP(R_H_DISP) == 0x4f)
  1089. {
  1090. /* exception case: 640x480 60 Hz needs longer blank adjust (2) */
  1091. DEC_DELAY
  1092. SetBlankAdj_m(2);
  1093. }
  1094. DEC_DELAY
  1095. OUTP (DAC_MASK,8);
  1096. DEC_DELAY
  1097. }
  1098. else{
  1099. OUTP (DAC_MASK,0);
  1100. DEC_DELAY
  1101. }
  1102. OUTP(DAC_R_INDEX,0xd); /* set MUX control to 24/32 */
  1103. DEC_DELAY
  1104. /*
  1105. * Re-write the I/O vs. memory mapped flag (bit 5 of
  1106. * LOCAL_CONTROL set). If this is not done, and memory
  1107. * mapped registers are being used, the clock select
  1108. * value won't be interpreted properly.
  1109. *
  1110. * If this is done at the beginning of the
  1111. * IOCTL_VIDEO_SET_CURRENT_MODE packet, rather than
  1112. * just before setting EXT_GE_CONFIG for each DAC type,
  1113. * it has no effect.
  1114. */
  1115. OUTPW(LOCAL_CONTROL, INPW(LOCAL_CONTROL));
  1116. DEC_DELAY
  1117. /* reset EXT_DAC_ADDR, put DAC in 8 bit mode, engine in 555 mode */
  1118. OUTPW (EXT_GE_CONFIG, (WORD)(ext_ge_config | 0x4000));
  1119. DEC_DELAY
  1120. OUTPW(CLOCK_SEL,clock_sel);
  1121. DEC_DELAY
  1122. OUTP (DAC_MASK,0); /* disable overlay feature */
  1123. DEC_DELAY
  1124. break;
  1125. case DAC_BT48x: /* Brooktree Bt481 initialization */
  1126. /*
  1127. * This code is still experimental.
  1128. */
  1129. /*
  1130. * Re-write the I/O vs. memory mapped flag (bit 5 of
  1131. * LOCAL_CONTROL set). If this is not done, and memory
  1132. * mapped registers are being used, the clock select
  1133. * value won't be interpreted properly.
  1134. */
  1135. OUTPW(LOCAL_CONTROL, INPW(LOCAL_CONTROL));
  1136. ReadExtGeConfig = INPW(R_EXT_GE_CONFIG) & 0x000f;
  1137. ReadExtGeConfig |= (ext_ge_config & 0x0ff0);
  1138. OUTPW(EXT_GE_CONFIG, (WORD)(ReadExtGeConfig | 0x1000));
  1139. /*
  1140. * See Bt481/Bt482 Product Description p.5 top of col. 2
  1141. */
  1142. dummy = INP(DAC_MASK);
  1143. dummy = INP(DAC_MASK);
  1144. dummy = INP(DAC_MASK);
  1145. dummy = INP(DAC_MASK);
  1146. OUTP(DAC_MASK, 0x0f0); /* 8:8:8 single-edge clock */
  1147. OUTPW(EXT_GE_CONFIG, ReadExtGeConfig);
  1148. SetBlankAdj_m(0x0C); /* set BLANK_ADJUST=0, PIXEL_DELAY=3 */
  1149. break;
  1150. case DAC_ATT491: /* ATT20C491 initialization */
  1151. OUTP(DAC_MASK,0);
  1152. SetBlankAdj_m(0x0C); /* set BLANK_ADJUST=0, PIXEL_DELAY=3 */
  1153. /* set EXT_DAC_ADDR field */
  1154. OUTPW(EXT_GE_CONFIG,0x101a);
  1155. /* set 24bpp bypass mode */
  1156. OUTP(DAC_MASK,0xe2);
  1157. /*
  1158. * Re-write the I/O vs. memory mapped flag (bit 5 of
  1159. * LOCAL_CONTROL set). If this is not done, and memory
  1160. * mapped registers are being used, the clock select
  1161. * value won't be interpreted properly.
  1162. */
  1163. OUTPW(LOCAL_CONTROL, INPW(LOCAL_CONTROL));
  1164. OUTPW(EXT_GE_CONFIG,ext_ge_config);
  1165. break;
  1166. case DAC_STG1700:
  1167. InitSTG1700_m(ext_ge_config, FALSE);
  1168. break;
  1169. case DAC_STG1702:
  1170. case DAC_STG1703:
  1171. InitSTG1702_m(ext_ge_config, FALSE);
  1172. break;
  1173. case DAC_ATT498:
  1174. InitATT498_m(ext_ge_config, FALSE);
  1175. break;
  1176. case DAC_SC15021:
  1177. InitSC15021_m(ext_ge_config, FALSE);
  1178. break;
  1179. case DAC_SC15026:
  1180. InitSC15026_m(ext_ge_config);
  1181. break;
  1182. case DAC_ATI_68860:
  1183. Init68860_m(ext_ge_config);
  1184. /* Intentional fallthrough */
  1185. default:
  1186. OUTPW(EXT_GE_CONFIG,ext_ge_config);
  1187. break;
  1188. }
  1189. return;
  1190. } /* InitTi_24_m() */
  1191. /*
  1192. * void Init68860_m(ext_ge_config);
  1193. *
  1194. * WORD ext_ge_config; Value to be written to EXT_GE_CONFIG register
  1195. *
  1196. * Initialize the ATI 68860 DAC.
  1197. */
  1198. void Init68860_m(WORD ext_ge_config)
  1199. {
  1200. struct query_structure *QueryPtr; /* Query information for the card */
  1201. unsigned char GMRValue; /* Value to put into Graphics Mode Register */
  1202. /*
  1203. * Get a formatted pointer into the query section of HwDeviceExtension.
  1204. * The CardInfo[] field is an unformatted buffer.
  1205. */
  1206. QueryPtr = (struct query_structure *) (phwDeviceExtension->CardInfo);
  1207. OUTPW(EXT_GE_CONFIG, (WORD)(ext_ge_config | 0x3000)); /* 6 bit DAC, DAC_EXT_ADDR = 3 */
  1208. /*
  1209. * Initialize Device Setup Register A. Select 6-bit DAC operation,
  1210. * normal power mode, PIXA bus width=64, disable overscan, and
  1211. * no delay PIXA latching. Enable both SOB0 and SOB1 on cards
  1212. * with more than 512k, 512k cards enable only SOB0.
  1213. */
  1214. if (QueryPtr->q_memory_size == VRAM_512k)
  1215. OUTP(DAC_W_INDEX, 0x2D);
  1216. else
  1217. OUTP(DAC_W_INDEX, 0x6D);
  1218. OUTPW(EXT_GE_CONFIG, (WORD)(ext_ge_config | 0x2000)); /* 6 bit DAC, DAC_EXT_ADDR = 2 */
  1219. /*
  1220. * Initialize Clock Selection Register. Select activate SCLK, enable
  1221. * SCLK output, CLK1 as dot clock, VCLK=CLK1/4, no delay PIXB latch.
  1222. */
  1223. OUTP(DAC_MASK, 0x1D);
  1224. /*
  1225. * Initialize Display Control Register. Enable CMPA output, enable POSW,
  1226. * 0 IRE blanking pedestal, disabe sync onto Red, Green, and Blue DACs.
  1227. */
  1228. OUTP(DAC_W_INDEX, 0x02);
  1229. /*
  1230. * Get the Graphics Mode Register value corresponding to the desired
  1231. * colour depth and RGB ordering, then write it.
  1232. */
  1233. switch (ext_ge_config & 0x06F0)
  1234. {
  1235. case 0x0000: /* 4 BPP */
  1236. GMRValue = 0x01;
  1237. break;
  1238. case 0x0020: /* 16 BPP 555 */
  1239. GMRValue = 0x20;
  1240. break;
  1241. case 0x0060: /* 16 BPP 565 */
  1242. GMRValue = 0x21;
  1243. break;
  1244. case 0x00A0: /* 16 BPP 655 */
  1245. GMRValue = 0x22;
  1246. break;
  1247. case 0x00E0: /* 16 BPP 664 */
  1248. GMRValue = 0x23;
  1249. break;
  1250. case 0x0030: /* 24 BPP RBG */
  1251. GMRValue = 0x40;
  1252. break;
  1253. case 0x0430: /* 24 BPP BGR */
  1254. GMRValue = 0x41;
  1255. break;
  1256. case 0x0230: /* 32 BPP RBGa */
  1257. GMRValue = 0x60;
  1258. break;
  1259. case 0x0630: /* 32 BPP aBGR */
  1260. GMRValue = 0x61;
  1261. break;
  1262. default: /* 8 BPP */
  1263. GMRValue = 0x03;
  1264. break;
  1265. }
  1266. OUTP(DAC_R_INDEX, GMRValue);
  1267. return;
  1268. } /* end Init68860_m() */
  1269. /***************************************************************************
  1270. *
  1271. * void InitSTG1700_m(ext_ge_config, DoublePixel);
  1272. *
  1273. * WORD ext_ge_config; Value to be written to EXT_GE_CONFIG register
  1274. * BOOL DoublePixel; Whether or not to use 8BPP double pixel mode
  1275. *
  1276. * DESCRIPTION:
  1277. * Initializes the STG1700 DAC to the desired colour depth.
  1278. *
  1279. * GLOBALS CHANGED:
  1280. * none
  1281. *
  1282. * CALLED BY:
  1283. * InitTi_<depth>_m(), UninitTiDac_m()
  1284. *
  1285. * AUTHOR:
  1286. * Robert Wolff
  1287. *
  1288. * CHANGE HISTORY:
  1289. *
  1290. * TEST HISTORY:
  1291. *
  1292. ***************************************************************************/
  1293. void InitSTG1700_m(WORD ext_ge_config, BOOL DoublePixel)
  1294. {
  1295. unsigned char PixModeSelect; /* Value to write to DAC Pixel Mode Select registers */
  1296. unsigned char Dummy; /* Scratch variable */
  1297. /*
  1298. * Get the value to be written to the DAC's Pixel Mode Select registers.
  1299. */
  1300. switch (ext_ge_config & 0x06F0)
  1301. {
  1302. case (PIX_WIDTH_16BPP | ORDER_16BPP_555):
  1303. PixModeSelect = 0x02;
  1304. break;
  1305. case (PIX_WIDTH_16BPP | ORDER_16BPP_565):
  1306. PixModeSelect = 0x03;
  1307. break;
  1308. case (PIX_WIDTH_24BPP | ORDER_24BPP_RGB):
  1309. case (PIX_WIDTH_24BPP | ORDER_24BPP_RGBx):
  1310. PixModeSelect = 0x04;
  1311. break;
  1312. default: /* 4 and 8 BPP */
  1313. if (DoublePixel == TRUE)
  1314. PixModeSelect = 0x05;
  1315. else
  1316. PixModeSelect = 0x00;
  1317. break;
  1318. }
  1319. /*
  1320. * Enable extended register/pixel mode.
  1321. */
  1322. ReadDac4();
  1323. OUTP(DAC_MASK, 0x18);
  1324. /*
  1325. * Skip over the Pixel Command register, then write to indexed
  1326. * registers 3 and 4 (Primrary and Secondary Pixel Mode Select
  1327. * registers). Registers auto-increment when written.
  1328. */
  1329. ReadDac4();
  1330. Dummy = INP(DAC_MASK);
  1331. OUTP(DAC_MASK, 0x03); /* Index low */
  1332. OUTP(DAC_MASK, 0x00); /* Index high */
  1333. OUTP(DAC_MASK, PixModeSelect); /* Primrary pixel mode select */
  1334. OUTP(DAC_MASK, PixModeSelect); /* Secondary pixel mode select */
  1335. /*
  1336. * In 8BPP double pixel mode, we must also set the PLL control
  1337. * register. Since this mode is only used for 1280x1024 noninterlaced,
  1338. * which always has a pixel clock frequency greater than 64 MHz,
  1339. * the setting for this register is a constant.
  1340. */
  1341. if (DoublePixel == TRUE)
  1342. OUTP(DAC_MASK, 0x02); /* Input is 32 to 67.5 MHz, output 64 to 135 MHz */
  1343. OUTPW(EXT_GE_CONFIG, ext_ge_config);
  1344. Dummy = INP(DAC_W_INDEX); /* Clear counter */
  1345. return;
  1346. } /* end InitSTG1700_m() */
  1347. /***************************************************************************
  1348. *
  1349. * void InitSTG1702_m(ext_ge_config, DoublePixel);
  1350. *
  1351. * WORD ext_ge_config; Value to be written to EXT_GE_CONFIG register
  1352. * BOOL DoublePixel; Whether or not to use 8BPP double pixel mode
  1353. *
  1354. * DESCRIPTION:
  1355. * Initializes the STG1702/1703 DAC to the desired colour depth.
  1356. *
  1357. * GLOBALS CHANGED:
  1358. * none
  1359. *
  1360. * CALLED BY:
  1361. * InitTi_<depth>_m(), UninitTiDac_m()
  1362. *
  1363. * AUTHOR:
  1364. * Robert Wolff
  1365. *
  1366. * CHANGE HISTORY:
  1367. *
  1368. * TEST HISTORY:
  1369. *
  1370. ***************************************************************************/
  1371. void InitSTG1702_m(WORD ext_ge_config, BOOL DoublePixel)
  1372. {
  1373. unsigned char PixModeSelect; /* Value to write to DAC Pixel Mode Select registers */
  1374. unsigned char Dummy; /* Scratch variable */
  1375. /*
  1376. * Get the value to be written to the DAC's Pixel Mode Select registers.
  1377. */
  1378. switch (ext_ge_config & 0x06F0)
  1379. {
  1380. case (PIX_WIDTH_16BPP | ORDER_16BPP_555):
  1381. PixModeSelect = 0x02;
  1382. break;
  1383. case (PIX_WIDTH_16BPP | ORDER_16BPP_565):
  1384. PixModeSelect = 0x03;
  1385. break;
  1386. case (PIX_WIDTH_24BPP | ORDER_24BPP_RGB):
  1387. case (PIX_WIDTH_24BPP | ORDER_24BPP_RGBx):
  1388. /*
  1389. * Use double 24BPP direct colour. In this mode,
  1390. * two pixels are passed as
  1391. * RRRRRRRRGGGGGGGG BBBBBBBBrrrrrrrr ggggggggbbbbbbbb
  1392. * rather than
  1393. * RRRRRRRRGGGGGGGG BBBBBBBBxxxxxxxx rrrrrrrrgggggggg bbbbbbbbxxxxxxxx
  1394. */
  1395. PixModeSelect = 0x09;
  1396. break;
  1397. default: /* 4 and 8 BPP */
  1398. if (DoublePixel == TRUE)
  1399. PixModeSelect = 0x05;
  1400. else
  1401. PixModeSelect = 0x00;
  1402. break;
  1403. }
  1404. /*
  1405. * Enable extended register/pixel mode.
  1406. */
  1407. ReadDac4();
  1408. OUTP(DAC_MASK, 0x18);
  1409. /*
  1410. * Skip over the Pixel Command register, then write to indexed
  1411. * registers 3 and 4 (Primrary and Secondary Pixel Mode Select
  1412. * registers). Registers auto-increment when written.
  1413. */
  1414. ReadDac4();
  1415. Dummy = INP(DAC_MASK);
  1416. OUTP(DAC_MASK, 0x03); /* Index low */
  1417. OUTP(DAC_MASK, 0x00); /* Index high */
  1418. OUTP(DAC_MASK, PixModeSelect); /* Primrary pixel mode select */
  1419. OUTP(DAC_MASK, PixModeSelect); /* Secondary pixel mode select */
  1420. /*
  1421. * In 8BPP double pixel mode, we must also set the PLL control
  1422. * register. Since this mode is only used for 1280x1024 noninterlaced,
  1423. * which always has a pixel clock frequency greater than 64 MHz,
  1424. * the setting for this register is a constant.
  1425. */
  1426. if (DoublePixel == TRUE)
  1427. OUTP(DAC_MASK, 0x02); /* Input is 32 to 67.5 MHz, output 64 to 135 MHz */
  1428. OUTPW(EXT_GE_CONFIG, ext_ge_config);
  1429. Dummy = INP(DAC_W_INDEX); /* Clear counter */
  1430. return;
  1431. } /* end InitSTG1702_m() */
  1432. /***************************************************************************
  1433. *
  1434. * void InitATT498_m(ext_ge_config, DoublePixel);
  1435. *
  1436. * WORD ext_ge_config; Value to be written to EXT_GE_CONFIG register
  1437. * BOOL DoublePixel; Whether or not to use 8BPP double pixel mode
  1438. *
  1439. * DESCRIPTION:
  1440. * Initializes the AT&T 498 DAC to the desired colour depth.
  1441. *
  1442. * GLOBALS CHANGED:
  1443. * none
  1444. *
  1445. * CALLED BY:
  1446. * InitTi_<depth>_m(), UninitTiDac_m()
  1447. *
  1448. * AUTHOR:
  1449. * Robert Wolff
  1450. *
  1451. * CHANGE HISTORY:
  1452. *
  1453. * TEST HISTORY:
  1454. *
  1455. ***************************************************************************/
  1456. void InitATT498_m(WORD ext_ge_config, BOOL DoublePixel)
  1457. {
  1458. unsigned char PixModeSelect; /* Value to write to DAC Pixel Mode Select registers */
  1459. unsigned char Dummy; /* Scratch variable */
  1460. /*
  1461. * Get the value to be written to the DAC's Pixel Mode Select registers.
  1462. */
  1463. switch (ext_ge_config & 0x06F0)
  1464. {
  1465. case (PIX_WIDTH_16BPP | ORDER_16BPP_555):
  1466. PixModeSelect = 0x17;
  1467. break;
  1468. case (PIX_WIDTH_16BPP | ORDER_16BPP_565):
  1469. PixModeSelect = 0x37;
  1470. break;
  1471. case (PIX_WIDTH_24BPP | ORDER_24BPP_RGB):
  1472. case (PIX_WIDTH_24BPP | ORDER_24BPP_RGBx):
  1473. PixModeSelect = 0x57;
  1474. break;
  1475. default: /* 4 and 8 BPP */
  1476. if (DoublePixel == TRUE)
  1477. PixModeSelect = 0x25;
  1478. else
  1479. PixModeSelect = 0x05;
  1480. break;
  1481. }
  1482. /*
  1483. * Get to the "hidden" Control Register 0, then fill it with
  1484. * the appropriate pixel mode select value.
  1485. */
  1486. ReadDac4();
  1487. OUTP(DAC_MASK, PixModeSelect);
  1488. OUTPW(EXT_GE_CONFIG, ext_ge_config);
  1489. Dummy = INP(DAC_W_INDEX); /* Clear counter */
  1490. return;
  1491. } /* end InitATT498_m() */
  1492. /***************************************************************************
  1493. *
  1494. * void InitSC15021_m(ext_ge_config, DoublePixel);
  1495. *
  1496. * WORD ext_ge_config; Value to be written to EXT_GE_CONFIG register
  1497. * BOOL DoublePixel; Whether or not to use 8BPP double pixel mode
  1498. *
  1499. * DESCRIPTION:
  1500. * Initializes the Sierra 15021 DAC to the desired colour depth.
  1501. *
  1502. * GLOBALS CHANGED:
  1503. * none
  1504. *
  1505. * CALLED BY:
  1506. * InitTi_<depth>_m(), UninitTiDac_m()
  1507. *
  1508. * AUTHOR:
  1509. * Robert Wolff
  1510. *
  1511. * CHANGE HISTORY:
  1512. *
  1513. * TEST HISTORY:
  1514. *
  1515. ***************************************************************************/
  1516. void InitSC15021_m(WORD ext_ge_config, BOOL DoublePixel)
  1517. {
  1518. unsigned char Repack; /* Value to write to Repack register */
  1519. unsigned char ColourMode; /* Colour mode to write to Command register */
  1520. /*
  1521. * Get the values to be written to the DAC's Repack (external to
  1522. * internal data translation) and Command registers.
  1523. */
  1524. switch (ext_ge_config & 0x06F0)
  1525. {
  1526. case (PIX_WIDTH_16BPP | ORDER_16BPP_555):
  1527. Repack = 0x08;
  1528. ColourMode = 0x80;
  1529. break;
  1530. case (PIX_WIDTH_16BPP | ORDER_16BPP_565):
  1531. Repack = 0x08;
  1532. ColourMode = 0xC0;
  1533. break;
  1534. case (PIX_WIDTH_24BPP | ORDER_24BPP_RGB):
  1535. case (PIX_WIDTH_24BPP | ORDER_24BPP_RGBx):
  1536. Repack = 0x05;
  1537. ColourMode = 0x40;
  1538. break;
  1539. default: /* 4 and 8 BPP */
  1540. if (DoublePixel == TRUE)
  1541. Repack = 0x04;
  1542. else
  1543. Repack = 0x00;
  1544. ColourMode = 0x00;
  1545. break;
  1546. }
  1547. OUTPW(EXT_GE_CONFIG, ext_ge_config);
  1548. /*
  1549. * Get to the "hidden" Command register and set Extended
  1550. * Register Programming Flag.
  1551. */
  1552. ReadDac4();
  1553. OUTP(DAC_MASK, 0x10);
  1554. /*
  1555. * Write to the Extended Index register so the Extended Data
  1556. * register points to the Repack register.
  1557. */
  1558. OUTP(DAC_R_INDEX, 0x10);
  1559. /*
  1560. * Write out the values for the Repack and Command registers.
  1561. * Clearing bit 4 of the Command register (all our ColourMode
  1562. * values have this bit clear) will clear the Extended Register
  1563. * Programming flag.
  1564. */
  1565. OUTP(DAC_W_INDEX, Repack);
  1566. OUTP(DAC_MASK, ColourMode);
  1567. OUTPW(EXT_GE_CONFIG, ext_ge_config);
  1568. return;
  1569. } /* end InitSC15021_m() */
  1570. /***************************************************************************
  1571. *
  1572. * void InitSC15026_m(ext_ge_config);
  1573. *
  1574. * WORD ext_ge_config; Value to be written to EXT_GE_CONFIG register
  1575. *
  1576. * DESCRIPTION:
  1577. * Initializes the Sierra 15026 DAC to the desired colour depth.
  1578. *
  1579. * GLOBALS CHANGED:
  1580. * none
  1581. *
  1582. * CALLED BY:
  1583. * InitTi_<depth>_m(), UninitTiDac_m()
  1584. *
  1585. * AUTHOR:
  1586. * Robert Wolff
  1587. *
  1588. * CHANGE HISTORY:
  1589. *
  1590. * TEST HISTORY:
  1591. *
  1592. ***************************************************************************/
  1593. void InitSC15026_m(WORD ext_ge_config)
  1594. {
  1595. unsigned char ColourMode; /* Colour mode to write to Command register */
  1596. /*
  1597. * Get the values to be written to the DAC's Repack (external to
  1598. * internal data translation) and Command registers.
  1599. */
  1600. switch (ext_ge_config & 0x06F0)
  1601. {
  1602. case (PIX_WIDTH_16BPP | ORDER_16BPP_555):
  1603. ColourMode = 0xA0;
  1604. break;
  1605. case (PIX_WIDTH_16BPP | ORDER_16BPP_565):
  1606. ColourMode = 0xE0;
  1607. break;
  1608. case (PIX_WIDTH_24BPP | ORDER_24BPP_RGB):
  1609. case (PIX_WIDTH_24BPP | ORDER_24BPP_RGBx):
  1610. ColourMode = 0x60;
  1611. break;
  1612. default: /* 4 and 8 BPP */
  1613. ColourMode = 0x00;
  1614. break;
  1615. }
  1616. OUTPW(EXT_GE_CONFIG, ext_ge_config);
  1617. /*
  1618. * Get to the "hidden" Command register and set Extended
  1619. * Register Programming Flag.
  1620. */
  1621. ReadDac4();
  1622. OUTP(DAC_MASK, 0x10);
  1623. /*
  1624. * Write to the Extended Index register so the Extended Data
  1625. * register points to the Repack register.
  1626. */
  1627. OUTP(DAC_R_INDEX, 0x10);
  1628. /*
  1629. * Write out the values for the Repack and Command registers.
  1630. * Clearing bit 4 of the Command register (all our ColourMode
  1631. * values have this bit clear) will clear the Extended Register
  1632. * Programming flag. All of our supported pixel depths use
  1633. * a Repack value of zero.
  1634. */
  1635. OUTP(DAC_W_INDEX, 0);
  1636. OUTP(DAC_MASK, ColourMode);
  1637. OUTPW(EXT_GE_CONFIG, ext_ge_config);
  1638. return;
  1639. } /* end InitSC15026_m() */
  1640. /***************************************************************************
  1641. *
  1642. * void ReadDac4(void);
  1643. *
  1644. * DESCRIPTION:
  1645. * Gain access to the extended registers on STG1700 and similar DACs.
  1646. * These registers are hidden behind the pixel mask register. To access
  1647. * them, read the DAC_W_INDEX register once, then the DAC_MASK register
  1648. * four times. The next access to the DAC_MASK register will then be
  1649. * to the Pixel Command register. If access to another extended register
  1650. * is desired, each additional read from DAC_MASK will skip to the
  1651. * next extended register.
  1652. *
  1653. * GLOBALS CHANGED:
  1654. * none
  1655. *
  1656. * CALLED BY:
  1657. * Init<DAC type>_m()
  1658. *
  1659. * AUTHOR:
  1660. * Robert Wolff
  1661. *
  1662. * CHANGE HISTORY:
  1663. *
  1664. * TEST HISTORY:
  1665. *
  1666. ***************************************************************************/
  1667. void ReadDac4(void)
  1668. {
  1669. UCHAR Dummy; /* Scratch variable */
  1670. Dummy = INP(DAC_W_INDEX);
  1671. Dummy = INP(DAC_MASK);
  1672. Dummy = INP(DAC_MASK);
  1673. Dummy = INP(DAC_MASK);
  1674. Dummy = INP(DAC_MASK);
  1675. return;
  1676. } /* end ReadDac4() */
  1677. /*
  1678. * void UninitTiDac_m(void);
  1679. *
  1680. * Prepare DAC for 8514/A compatible mode on
  1681. * 8514/A-compatible ATI accelerators.
  1682. */
  1683. void UninitTiDac_m (void)
  1684. {
  1685. struct query_structure *QueryPtr; /* Query information for the card */
  1686. /*
  1687. * Get a formatted pointer into the query section of HwDeviceExtension.
  1688. * The CardInfo[] field is an unformatted buffer.
  1689. */
  1690. QueryPtr = (struct query_structure *) (phwDeviceExtension->CardInfo);
  1691. Passth8514_m(SHOW_ACCEL); // can only program DAC in 8514 mode
  1692. switch (QueryPtr->q_DAC_type)
  1693. {
  1694. case DAC_TI34075:
  1695. OUTPW (EXT_GE_CONFIG,0x201a); /* set EXT_DAC_ADDR field */
  1696. DEC_DELAY
  1697. OUTP (DAC_DATA,0); /* Input clock source is CLK0 */
  1698. DEC_DELAY
  1699. OUTP (DAC_MASK,0); /* Output clock is SCLK/1 and VCLK/1 */
  1700. DEC_DELAY
  1701. OUTP (DAC_R_INDEX,0x2d); /* set MUX CONTROL TO 8/16 */
  1702. DEC_DELAY
  1703. /* set default 8bpp pixel delay and blank adjust */
  1704. OUTPW (LOCAL_CONTROL,(WORD)(INPW(LOCAL_CONTROL) | 8)); // TI_DAC_BLANK_ADJUST is always on
  1705. DEC_DELAY
  1706. SetBlankAdj_m(0xc);
  1707. DEC_DELAY
  1708. OUTPW(HORZ_OVERSCAN,1); /* set horizontal skew */
  1709. DEC_DELAY
  1710. break;
  1711. case DAC_STG1700:
  1712. InitSTG1700_m(PIX_WIDTH_8BPP | 0x000A, FALSE);
  1713. break;
  1714. case DAC_STG1702:
  1715. case DAC_STG1703:
  1716. InitSTG1702_m(PIX_WIDTH_8BPP | 0x000A, FALSE);
  1717. break;
  1718. case DAC_ATT498:
  1719. InitATT498_m(PIX_WIDTH_8BPP | 0x000A, FALSE);
  1720. break;
  1721. case DAC_SC15021:
  1722. InitSC15021_m(PIX_WIDTH_8BPP | 0x000A, FALSE);
  1723. break;
  1724. case DAC_SC15026:
  1725. InitSC15026_m(PIX_WIDTH_8BPP | 0x000A);
  1726. break;
  1727. case DAC_ATT491:
  1728. case DAC_BT48x:
  1729. OUTPW (EXT_GE_CONFIG,0x101a);
  1730. OUTP (DAC_MASK,0);
  1731. /* Intentional fallthrough */
  1732. default:
  1733. SetBlankAdj_m(0); /* PIXEL_DELAY=0 */
  1734. OUTPW(HORZ_OVERSCAN,0); /* set horizontal skew */
  1735. break;
  1736. }
  1737. // reset EXT_DAC_ADDR, put DAC in 6 bit mode, engine in 8 bit mode
  1738. OUTPW(EXT_GE_CONFIG,0x1a);
  1739. DEC_DELAY
  1740. Passth8514_m(SHOW_VGA);
  1741. return;
  1742. } /* UninitTiDac_m() */
  1743. /***************************************************************************
  1744. *
  1745. * void SetPalette_m(lpPalette, StartIndex, Count);
  1746. *
  1747. * PPALETTEENTRY lpPalette; Colour values to plug into palette
  1748. * USHORT StartIndex; First palette entry to set
  1749. * USHORT Count; Number of palette entries to set
  1750. *
  1751. * DESCRIPTION:
  1752. * Set the desired number of palette entries to the specified colours,
  1753. * starting at the specified index. Colour values are stored in
  1754. * doublewords, in the order (low byte to high byte) RGBx.
  1755. *
  1756. * GLOBALS CHANGED:
  1757. * none
  1758. *
  1759. * CALLED BY:
  1760. * SetCurrentMode_m() and IOCTL_VIDEO_SET_COLOR_REGISTERS packet
  1761. * of ATIMPStartIO()
  1762. *
  1763. * AUTHOR:
  1764. * unknown
  1765. *
  1766. * CHANGE HISTORY:
  1767. *
  1768. * TEST HISTORY:
  1769. *
  1770. ***************************************************************************/
  1771. void SetPalette_m(PULONG lpPalette, USHORT StartIndex, USHORT Count)
  1772. {
  1773. int i;
  1774. BYTE *pPal=(BYTE *)lpPalette;
  1775. OUTP(DAC_W_INDEX,(BYTE)StartIndex); // load DAC_W_INDEX with StartIndex
  1776. for (i=0; i<Count; i++) // this is number of colours to update
  1777. {
  1778. OUTP(DAC_DATA, *pPal++); // red
  1779. OUTP(DAC_DATA, *pPal++); // green
  1780. OUTP(DAC_DATA, *pPal++); // blue
  1781. pPal++;
  1782. }
  1783. return;
  1784. } /* SetPalette_m() */
  1785. /**************************************************************************
  1786. *
  1787. * void SetTextMode_m(void);
  1788. *
  1789. * DESCRIPTION:
  1790. * Switch into 80x25 16 colour text mode using register writes rather
  1791. * than BIOS calls. This allows systems with no video BIOS (e.g. DEC
  1792. * ALPHA) to return to a text screen when shutting down and rebooting.
  1793. *
  1794. * GLOBALS CHANGED:
  1795. * none
  1796. *
  1797. * CALLED BY:
  1798. * ATIMPStartIO(), packet IOCTL_VIDEO_RESET_DEVICE
  1799. *
  1800. * AUTHOR:
  1801. * Robert Wolff
  1802. *
  1803. * CHANGE HISTORY:
  1804. *
  1805. * TEST HISTORY:
  1806. *
  1807. **************************************************************************/
  1808. void SetTextMode_m(void)
  1809. {
  1810. short LoopCount; /* Loop counter */
  1811. BYTE Scratch; /* Temporary variable */
  1812. BYTE Seq02; /* Saved value of Sequencer register 2 */
  1813. BYTE Seq04; /* Saved value of Sequencer register 4 */
  1814. BYTE Gra05; /* Saved value of Graphics register 5 */
  1815. BYTE Gra06; /* Saved value of Graphics register 6 */
  1816. WORD ExtGeConfig; /* Saved contents of EXT_GE_CONFIG register */
  1817. WORD MiscOptions; /* Saved contents of MISC_OPTIONS register */
  1818. WORD Column; /* Current byte of font data being dealt with */
  1819. WORD ScreenColumn; /* Screen column corresponding to current byte of font data */
  1820. WORD Row; /* Current character being dealt with */
  1821. /*
  1822. * Let the VGA drive the screen. Mach 8 cards have separate VGA and
  1823. * accelerator controllers, so no further action needs to be taken
  1824. * once this is done. Mach 32 cards need to be put into VGA text mode.
  1825. */
  1826. Passth8514_m(SHOW_VGA);
  1827. if (phwDeviceExtension->ModelNumber != MACH32_ULTRA)
  1828. return;
  1829. /*
  1830. * Stop the sequencer to change memory timing
  1831. * and memory organization
  1832. */
  1833. OUTPW(HI_SEQ_ADDR, 0x00 | (0x01 << 8));
  1834. for (LoopCount = 1; LoopCount <= S_LEN; ++LoopCount)
  1835. OUTPW(HI_SEQ_ADDR, (WORD)(LoopCount | (StdTextCRTC_m[S_PARM + LoopCount - 1] << 8)));
  1836. /*
  1837. * Program the extended VGAWonder registers
  1838. */
  1839. for (LoopCount = 0; ExtTextCRTC_m[LoopCount] != 0; LoopCount += 3)
  1840. {
  1841. OUTP(reg1CE, ExtTextCRTC_m[LoopCount]);
  1842. Scratch = (INP(reg1CF) & ExtTextCRTC_m[LoopCount + 1]) | ExtTextCRTC_m[LoopCount + 2];
  1843. OUTPW(reg1CE, (WORD)(ExtTextCRTC_m[LoopCount] | (Scratch << 8)));
  1844. }
  1845. LioOutp(regVGA_END_BREAK_PORT, StdTextCRTC_m[MIS_PARM], GENMO_OFFSET);
  1846. /*
  1847. * Restart the sequencer after the memory changes
  1848. */
  1849. OUTPW(HI_SEQ_ADDR, 0x00 | (0x03 << 8));
  1850. /*
  1851. * Program the CRTC controller
  1852. */
  1853. LioOutpw(regVGA_END_BREAK_PORT, 0x11 | (0x00 << 8), CRTX_COLOUR_OFFSET);
  1854. for (LoopCount = 0; LoopCount < C_LEN; ++LoopCount)
  1855. LioOutpw(regVGA_END_BREAK_PORT, (WORD)(LoopCount | (StdTextCRTC_m[C_PARM + LoopCount] << 8)), CRTX_COLOUR_OFFSET);
  1856. /*
  1857. * Program the Attribute controller (internal palette)
  1858. */
  1859. Scratch = LioInp(regVGA_END_BREAK_PORT, GENS1_COLOUR_OFFSET);
  1860. for (LoopCount = 0; LoopCount < A_LEN; LoopCount++)
  1861. {
  1862. OUTP(regVGA_END_BREAK_PORT, (BYTE)LoopCount);
  1863. OUTP(regVGA_END_BREAK_PORT, StdTextCRTC_m[A_PARM + LoopCount]);
  1864. }
  1865. OUTP(regVGA_END_BREAK_PORT, 0x14);
  1866. OUTP(regVGA_END_BREAK_PORT, 0x00);
  1867. /*
  1868. * Program the graphics controller
  1869. */
  1870. for (LoopCount = 0; LoopCount < G_LEN; ++LoopCount)
  1871. OUTPW(reg3CE, (WORD)(LoopCount | (StdTextCRTC_m[G_PARM + LoopCount] << 8)));
  1872. /*
  1873. * Program the DAC (external palette)
  1874. */
  1875. for (LoopCount = 0; LoopCount < 0x10; ++LoopCount)
  1876. {
  1877. LioOutp(regVGA_END_BREAK_PORT, StdTextCRTC_m[A_PARM + LoopCount], DAC_W_INDEX_OFFSET);
  1878. LioOutp(regVGA_END_BREAK_PORT, TextDAC_m[LoopCount * 3], DAC_DATA_OFFSET);
  1879. LioOutp(regVGA_END_BREAK_PORT, TextDAC_m[LoopCount * 3 + 1], DAC_DATA_OFFSET);
  1880. LioOutp(regVGA_END_BREAK_PORT, TextDAC_m[LoopCount * 3 + 2], DAC_DATA_OFFSET);
  1881. }
  1882. /*
  1883. * Turn on the display
  1884. */
  1885. Scratch = LioInp(regVGA_END_BREAK_PORT, GENS1_COLOUR_OFFSET);
  1886. OUTP(regVGA_END_BREAK_PORT, 0x20);
  1887. /*
  1888. * No need to clear the screen.
  1889. * First, the driver should not call Map Frame while the machine is
  1890. * bug checking !!!
  1891. * Second, it is not necessary to clear the screen since the HAL will
  1892. * do it.
  1893. */
  1894. /*
  1895. * Initialize the 8x16 font. Start by saving the registers which
  1896. * are changed during font initialization.
  1897. */
  1898. OUTP(SEQ_IND, 0x02);
  1899. Seq02 = INP(SEQ_DATA);
  1900. OUTP(SEQ_IND, 4);
  1901. Seq04 = INP(SEQ_DATA);
  1902. OUTP(reg3CE, 5);
  1903. Gra05 = INP_HBLW(reg3CE);
  1904. OUTP(reg3CE, 6);
  1905. Gra06 = INP_HBLW(reg3CE);
  1906. /*
  1907. * Set up to allow font loading
  1908. */
  1909. OUTPW(reg3CE, 0x0005);
  1910. OUTPW(reg3CE, 0x0406);
  1911. OUTPW(HI_SEQ_ADDR, 0x0402);
  1912. OUTPW(HI_SEQ_ADDR, 0x0704);
  1913. /*
  1914. * Load our font data into video memory. This would normally be
  1915. * done through the VGA aperture, but some machines (including
  1916. * the DEC ALPHA) are unable to use the VGA aperture. Since
  1917. * this routine is needed to re-initialize the VGA text screen
  1918. * on non-80x86 machines (which can't use the BIOS), and some
  1919. * of these are unable to use the VGA aperture, we need an
  1920. * alternate method of loading the font data.
  1921. *
  1922. * The font data occupies byte 2 (zero-based) of each doubleword
  1923. * for the first 8192 doublewords of video memory, in the pattern
  1924. * 16 bytes of character data followed by 16 zero bytes. To load
  1925. * the font data using the graphics engine, set it to 8BPP at a
  1926. * screen pitch of 128 pixels (32 doublewords per line). In the
  1927. * first 16 font data columns, use a host to screen blit to copy
  1928. * the font data. For the last 16 font data columns (constant data
  1929. * of zero), do a paint blit with colour zero. This will yield
  1930. * one character of font data per line. Since we have already
  1931. * switched to display via the VGA, this will not affect the
  1932. * on-screen image.
  1933. *
  1934. * Note that this is only possible on a Mach 32 with the VGA enabled.
  1935. */
  1936. /*
  1937. * Initialize the drawing engine to 8BPP with a pitch of 128. Don't
  1938. * set up the CRT, since we are only trying to fill in the appropriate
  1939. * bytes of video memory, and the results of our drawing are not
  1940. * intended to be seen.
  1941. */
  1942. ExtGeConfig = INPW(R_EXT_GE_CONFIG);
  1943. MiscOptions = INPW(MISC_OPTIONS);
  1944. OUTPW(MISC_OPTIONS, (WORD)(MiscOptions | 0x0002)); /* 8 bit host data I/O */
  1945. OUTPW(EXT_GE_CONFIG, (WORD)(PIX_WIDTH_8BPP | 0x000A));
  1946. OUTPW(GE_PITCH, (128 >> 3));
  1947. OUTPW(GE_OFFSET_HI, 0);
  1948. OUTPW(GE_OFFSET_LO, 0);
  1949. /*
  1950. * We must now do our 32 rectangular blits, each 1 pixel wide by
  1951. * 256 pixels high. These start at column 2 (zero-based), and are
  1952. * done every 4 columns.
  1953. */
  1954. for(Column = 0; Column <= 31; Column++)
  1955. {
  1956. ScreenColumn = (Column * 4) + 2;
  1957. /*
  1958. * If this is one of the first 16 columns, we need to do a
  1959. * host-to-screen blit.
  1960. */
  1961. if (Column <= 15)
  1962. {
  1963. WaitForIdle_m();
  1964. OUTPW(DP_CONFIG, (WORD)(FG_COLOR_SRC_HOST | BG_COLOR_SRC_BG | EXT_MONO_SRC_ONE | DRAW | READ_WRITE));
  1965. OUTPW(CUR_X, ScreenColumn);
  1966. OUTPW(CUR_Y, 0);
  1967. OUTPW(DEST_X_START, ScreenColumn);
  1968. OUTPW(DEST_X_END, (WORD)(ScreenColumn + 1));
  1969. OUTPW(DEST_Y_END, 256);
  1970. /*
  1971. * The nth column contains the nth byte of character bitmap
  1972. * data for each of the 256 characters. There are 16 bytes
  1973. * of bitmap data per character, so the nth byte of data for
  1974. * character x (n and x both zero-based) is at offset
  1975. * (x * 16) + n.
  1976. */
  1977. for (Row = 0; Row < 256; Row++)
  1978. {
  1979. OUTP_HBLW(PIX_TRANS, FontData_m[(Row * 16) + Column]);
  1980. }
  1981. }
  1982. else
  1983. {
  1984. /*
  1985. * This is one of the "padding" zero bytes which must be
  1986. * added to each character in the font to bring it up
  1987. * to 32 bytes of data per character.
  1988. */
  1989. WaitForIdle_m();
  1990. OUTPW(DP_CONFIG, (WORD)(FG_COLOR_SRC_FG | DRAW | READ_WRITE));
  1991. OUTPW(ALU_FG_FN, MIX_FN_PAINT);
  1992. OUTPW(FRGD_COLOR, 0);
  1993. OUTPW(CUR_X, ScreenColumn);
  1994. OUTPW(CUR_Y, 0);
  1995. OUTPW(DEST_X_START, ScreenColumn);
  1996. OUTPW(DEST_X_END, (WORD)(ScreenColumn + 1));
  1997. OUTPW(DEST_Y_END, 256);
  1998. }
  1999. }
  2000. /*
  2001. * Restore the graphics engine registers we changed.
  2002. */
  2003. OUTPW(EXT_GE_CONFIG, ExtGeConfig);
  2004. OUTPW(MISC_OPTIONS, MiscOptions);
  2005. /*
  2006. * Restore the registers we changed to load the font.
  2007. */
  2008. OUTPW(reg3CE, (WORD) ((Gra06 << 8) | 6));
  2009. OUTPW(reg3CE, (WORD) ((Gra05 << 8) | 5));
  2010. OUTPW(HI_SEQ_ADDR, (WORD) ((Seq04 << 8) | 4));
  2011. OUTPW(HI_SEQ_ADDR, (WORD) ((Seq02 << 8) | 2));
  2012. /*
  2013. * Set up the engine and CRT pitches for 1024x768, to avoid screen
  2014. * doubling when warm-booting from our driver to the 8514/A driver.
  2015. * This is only necessary on the Mach 32 (Mach 8 never reaches this
  2016. * point in the code) because on the Mach 8, writing to ADVFUNC_CNTL
  2017. * (done as part of Passth8514_m()) sets both registers up for
  2018. * 1024x768.
  2019. */
  2020. OUTPW(GE_PITCH, 128);
  2021. OUTPW(CRT_PITCH, 128);
  2022. return;
  2023. } /* SetTextMode_m() */
  2024. /***************************** end of MODES_M.C **********************/