Source code of Windows XP (NT5)
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.

766 lines
13 KiB

  1. /*++
  2. Copyright (c) 1993, 1994 Weitek Corporation
  3. Module Name:
  4. bt485.c
  5. Abstract:
  6. This module contains code specific to the Bt485 DAC on P9x0x adapters.
  7. Environment:
  8. Kernel mode
  9. Revision History may be found at the end of this file.
  10. --*/
  11. #include "p9.h"
  12. #include "p9gbl.h"
  13. #include "p9000.h"
  14. #include "bt485.h"
  15. #include "p91regs.h"
  16. #include "p91dac.h"
  17. #define PIX_PORT_15 0x30
  18. //
  19. // DAC specific static data.
  20. //
  21. UCHAR
  22. ReadDAC(
  23. PHW_DEVICE_EXTENSION HwDeviceExtension,
  24. ULONG ulIndex
  25. );
  26. VOID
  27. WriteDAC(
  28. PHW_DEVICE_EXTENSION HwDeviceExtension,
  29. ULONG ulIndex,
  30. UCHAR ucValue
  31. );
  32. VOID
  33. P91Bt485SetPalette(
  34. PHW_DEVICE_EXTENSION HwDeviceExtension,
  35. ULONG *pPal,
  36. ULONG StartIndex,
  37. ULONG Count
  38. );
  39. VOID
  40. P91Bt485SetPointerPos(
  41. PHW_DEVICE_EXTENSION HwDeviceExtension,
  42. ULONG ptlX,
  43. ULONG ptlY
  44. );
  45. VOID
  46. P91Bt485SetPointerShape(
  47. PHW_DEVICE_EXTENSION HwDeviceExtension,
  48. PUCHAR pHWCursorShape
  49. );
  50. VOID
  51. P91Bt485PointerOn(
  52. PHW_DEVICE_EXTENSION HwDeviceExtension
  53. );
  54. VOID
  55. P91Bt485PointerOff(
  56. PHW_DEVICE_EXTENSION HwDeviceExtension
  57. );
  58. VOID
  59. P91Bt485ClearPalette(
  60. PHW_DEVICE_EXTENSION HwDeviceExtension
  61. );
  62. BOOLEAN
  63. P91Bt485SetMode(
  64. PHW_DEVICE_EXTENSION HwDeviceExtension
  65. );
  66. VOID
  67. P91Bt485RestoreMode(
  68. PHW_DEVICE_EXTENSION HwDeviceExtension
  69. );
  70. VOID
  71. P91Bt485SetClkDoubler(
  72. PHW_DEVICE_EXTENSION HwDeviceExtension
  73. );
  74. VOID
  75. P91Bt485ClrClkDoubler(
  76. PHW_DEVICE_EXTENSION HwDeviceExtension
  77. );
  78. //
  79. // Define the DAC support routines structure for the Bt485 DAC.
  80. //
  81. DAC P91Bt485 = {
  82. DAC_ID_BT485,
  83. NUM_DAC_REGS,
  84. P91Bt485SetMode,
  85. P91Bt485RestoreMode,
  86. P91Bt485SetPalette,
  87. P91Bt485ClearPalette,
  88. P91Bt485PointerOn,
  89. P91Bt485PointerOff,
  90. P91Bt485SetPointerPos,
  91. P91Bt485SetPointerShape,
  92. CLK_MAX_FREQ,
  93. P91Bt485SetClkDoubler,
  94. P91Bt485ClrClkDoubler,
  95. DAC_ID_BT485,
  96. 32,
  97. FALSE,
  98. FALSE,
  99. FALSE
  100. };
  101. //
  102. // Power 9100 Bt485 DAC register definitions. See comments in
  103. // VLGetBaseAddrP91().
  104. //
  105. ULONG P91_Bt485_DAC_Regs[] =
  106. {
  107. P9100_RAMWRITE,
  108. P9100_PALETDATA,
  109. P9100_PIXELMASK,
  110. P9100_RAMREAD,
  111. P9100_COLORWRITE,
  112. P9100_COLORDATA,
  113. P9100_COMREG0,
  114. P9100_COLORREAD,
  115. P9100_COMREG1,
  116. P9100_COMREG2,
  117. P9100_COMREG3,
  118. P9100_CURSORDATA,
  119. P9100_CURSORX0,
  120. P9100_CURSORX1,
  121. P9100_CURSORY0,
  122. P9100_CURSORY1
  123. };
  124. VOID
  125. P91Bt485SetPalette(
  126. PHW_DEVICE_EXTENSION HwDeviceExtension,
  127. ULONG *pPal,
  128. ULONG StartIndex,
  129. ULONG Count
  130. )
  131. /*++
  132. Routine Description:
  133. Sets the Device palette
  134. Arguments:
  135. HwDeviceExtension - Pointer to the miniport driver's device extension.
  136. pPal - Pointer to the array of pallete entries.
  137. StartIndex - Specifies the first pallete entry provided in pPal.
  138. Count - Number of palette entries in pPal
  139. Return Value:
  140. None.
  141. --*/
  142. {
  143. UCHAR *pBytePal;
  144. PAL_WR_ADDR((UCHAR) StartIndex);
  145. pBytePal = (PUCHAR) pPal;
  146. //
  147. // Load the palette with RGB values. The input palette has 4 bytes
  148. // per entry, the last of which is ignored.
  149. //
  150. while (Count--)
  151. {
  152. PAL_WR_DATA(*pBytePal++);
  153. PAL_WR_DATA(*pBytePal++);
  154. PAL_WR_DATA(*pBytePal++);
  155. pBytePal++;
  156. }
  157. }
  158. VOID
  159. P91Bt485SetPointerPos(
  160. PHW_DEVICE_EXTENSION HwDeviceExtension,
  161. ULONG ptlX,
  162. ULONG ptlY
  163. )
  164. /*++
  165. Routine Description:
  166. Move Hardware Pointer.
  167. Arguments:
  168. HwDeviceExtension - Pointer to the miniport driver's device extension.
  169. ptlX, ptlY - Requested X,Y position for the pointer.
  170. Return Value:
  171. TRUE
  172. --*/
  173. {
  174. //
  175. // Strip off the invalid bits and update the cursor position regs.
  176. //
  177. WR_CURS_POS_X(((ptlX + CURSOR_WIDTH) & 0xFFF));
  178. WR_CURS_POS_Y(((ptlY + CURSOR_HEIGHT) & 0xFFF));
  179. return;
  180. }
  181. VOID
  182. P91Bt485SetPointerShape(
  183. PHW_DEVICE_EXTENSION HwDeviceExtension,
  184. PUCHAR pHWCursorShape
  185. )
  186. /*++
  187. Routine Description:
  188. Sets the hardware cursor shape.
  189. Arguments:
  190. HwDeviceExtension - Pointer to the miniport driver's device extension.
  191. pHWCursorShape - Pointer to the cursor bitmap.
  192. Return Value:
  193. None.
  194. --*/
  195. {
  196. ULONG iCount;
  197. //
  198. // The # of bytes of cursor bitmap data to send *= 2 for and/xor mask
  199. // *= 8 for 8bit/byte
  200. // *= 2 for 2 loops
  201. //
  202. ULONG iLoop = (CURSOR_WIDTH * CURSOR_HEIGHT * 2) / (8 * 2);
  203. //
  204. // AND mask will be loaded to plane 1.
  205. //
  206. PAL_WR_ADDR(0x80);
  207. iCount = iLoop;
  208. WAIT_FOR_RETRACE();
  209. while (iCount--)
  210. {
  211. WR_CURS_DATA(*pHWCursorShape++);
  212. }
  213. //
  214. // XOR mask will be loaded to plane 0.
  215. //
  216. PAL_WR_ADDR(0x00);
  217. iCount = iLoop;
  218. WAIT_FOR_RETRACE();
  219. while (iCount--)
  220. {
  221. WR_CURS_DATA(*pHWCursorShape++);
  222. }
  223. return;
  224. }
  225. VOID
  226. P91Bt485PointerOn(
  227. PHW_DEVICE_EXTENSION HwDeviceExtension
  228. )
  229. /*++
  230. Routine Description:
  231. Turn on the hardware cursor.
  232. Arguments:
  233. HwDeviceExtension - Pointer to the miniport driver's device extension.
  234. Return Value:
  235. None.
  236. --*/
  237. {
  238. //
  239. // Turn the cursor on only if it was disabled.
  240. //
  241. if (!CURS_IS_ON())
  242. {
  243. WAIT_FOR_RETRACE();
  244. CURS_ON();
  245. }
  246. return;
  247. }
  248. VOID
  249. P91Bt485PointerOff(
  250. PHW_DEVICE_EXTENSION HwDeviceExtension
  251. )
  252. /*++
  253. Routine Description:
  254. Turn off the hardware cursor.
  255. Arguments:
  256. HwDeviceExtension - Pointer to the miniport driver's device extension.
  257. Return Value:
  258. None.
  259. --*/
  260. {
  261. //
  262. // Turn the cursor off only if it was enabled.
  263. //
  264. if (CURS_IS_ON())
  265. {
  266. WAIT_FOR_RETRACE();
  267. CURS_OFF();
  268. }
  269. return;
  270. }
  271. VOID
  272. P91Bt485ClearPalette(
  273. PHW_DEVICE_EXTENSION HwDeviceExtension
  274. )
  275. /*++
  276. Routine Description:
  277. Clears the palette to all 0's
  278. Arguments:
  279. HwDeviceExtension - Pointer to the miniport driver's device extension.
  280. Return Value:
  281. None.
  282. --*/
  283. {
  284. int Count;
  285. //
  286. // Calculate the number of palette entries. It is assumed that the
  287. // caller has already determined that the current mode makes use
  288. // of the palette,
  289. //
  290. Count = 1 << HwDeviceExtension->usBitsPixel;
  291. //
  292. // Fill the palette with RGB values of 0.
  293. //
  294. while (Count--)
  295. {
  296. PAL_WR_DATA(0);
  297. PAL_WR_DATA(0);
  298. PAL_WR_DATA(0);
  299. }
  300. return;
  301. }
  302. BOOLEAN
  303. P91Bt485SetMode(
  304. PHW_DEVICE_EXTENSION HwDeviceExtension
  305. )
  306. /*++
  307. Routine Description:
  308. Initializes the DAC for the current mode.
  309. Arguments:
  310. HwDeviceExtension - Pointer to the miniport driver's device extension.
  311. Return Value:
  312. None.
  313. --*/
  314. {
  315. UCHAR ucCurState;
  316. //
  317. // Enable 8bit dacs, allow access to Command Register 3.
  318. //
  319. //
  320. // Enable accesses to CMD_REG_3. For the Power 9100, to access command
  321. // register 3, you must have CR07 TRUE and you must load a one into
  322. // the address register.
  323. //
  324. if (IS_DEV_P9100)
  325. P9_WR_REG(P9100_RAMWRITE, 0x01);
  326. WriteDAC(HwDeviceExtension, CMD_REG_0, ENB_CMD_REG_3 | MODE_8_BIT);
  327. //
  328. // Set the DAC Pixel port value for the current bit depth.
  329. // Note: The BT485 does not support 24bpp mode.
  330. //
  331. switch (HwDeviceExtension->usBitsPixel)
  332. {
  333. case 8:
  334. WriteDAC(HwDeviceExtension, CMD_REG_1, PIX_PORT_8);
  335. break;
  336. case 16: // This is really 555, not 565...
  337. WriteDAC(HwDeviceExtension, CMD_REG_1, PIX_PORT_15);
  338. break;
  339. case 32:
  340. WriteDAC(HwDeviceExtension, CMD_REG_1, PIX_PORT_32);
  341. break;
  342. default:
  343. //
  344. // Oops..invalid BPP value. Use 8BPP value for now.
  345. //
  346. WriteDAC(HwDeviceExtension, CMD_REG_1, PIX_PORT_8);
  347. break;
  348. };
  349. //
  350. // Select P9x00 video clock, disable cursor
  351. //
  352. WriteDAC(HwDeviceExtension, CMD_REG_2,
  353. (PORTSEL_MSKD | PCLK1_SEL) & DIS_CURS);
  354. //
  355. // Select 32x32x2 cursor mode, and clock doubler mode if neccessary.
  356. //
  357. RD_CMD_REG_3(ucCurState);
  358. if (HwDeviceExtension->VideoData.dotfreq1 >
  359. HwDeviceExtension->Dac.ulMaxClkFreq)
  360. {
  361. //
  362. // Enable the DAC clock doubler mode.
  363. //
  364. HwDeviceExtension->Dac.DACSetClkDblMode(HwDeviceExtension);
  365. }
  366. else
  367. {
  368. //
  369. // Disable the DAC clock doubler mode.
  370. //
  371. HwDeviceExtension->Dac.DACClrClkDblMode(HwDeviceExtension);
  372. }
  373. //
  374. // Set the pixel read mask.
  375. //
  376. WriteDAC(HwDeviceExtension, PIXEL_MSK_REG, 0xff);
  377. //
  378. // Set cursor colors 1 and 2.
  379. //
  380. WriteDAC(HwDeviceExtension, CURS_CLR_ADDR, 1);
  381. WriteDAC(HwDeviceExtension, CURS_CLR_DATA, 0x00);
  382. WriteDAC(HwDeviceExtension, CURS_CLR_DATA, 0x00);
  383. WriteDAC(HwDeviceExtension, CURS_CLR_DATA, 0x00);
  384. WriteDAC(HwDeviceExtension, CURS_CLR_DATA, 0xFF);
  385. WriteDAC(HwDeviceExtension, CURS_CLR_DATA, 0xFF);
  386. WriteDAC(HwDeviceExtension, CURS_CLR_DATA, 0xFF);
  387. return(TRUE);
  388. }
  389. VOID
  390. P91Bt485RestoreMode(
  391. PHW_DEVICE_EXTENSION HwDeviceExtension
  392. )
  393. /*++
  394. routine description:
  395. Restore the DAC to its pristine state.
  396. arguments:
  397. hwdeviceextension - pointer to the miniport driver's device extension.
  398. return value:
  399. --*/
  400. {
  401. UCHAR ucCurState;
  402. VideoDebugPrint((1, "P91Bt485RestoreMode----------\n"));
  403. //
  404. // Enable accesses to CMD_REG_3. For the Power 9100, to access command
  405. // register 3, you must have CR07 TRUE and you must load a one into
  406. // the address register.
  407. //
  408. if (IS_DEV_P9100)
  409. {
  410. P9_WR_REG(P9100_RAMWRITE, 0x01);
  411. WriteDAC(HwDeviceExtension, CMD_REG_0, ENB_CMD_REG_3);
  412. WR_CMD_REG_3(0x00);
  413. WriteDAC(HwDeviceExtension, CMD_REG_0, 0x00);
  414. WriteDAC(HwDeviceExtension, CMD_REG_1, 0x00);
  415. WriteDAC(HwDeviceExtension, CMD_REG_2, 0x00);
  416. return;
  417. }
  418. WriteDAC(HwDeviceExtension, CMD_REG_0, ENB_CMD_REG_3);
  419. //
  420. // Set pixel port for 8bit pixels.
  421. //
  422. WriteDAC(HwDeviceExtension, CMD_REG_1, PIX_PORT_8);
  423. //
  424. // Select VGA video clock, disable cursor.
  425. //
  426. WriteDAC(HwDeviceExtension, (ULONG) CMD_REG_2,
  427. (UCHAR)(ReadDAC(HwDeviceExtension, (ULONG) CMD_REG_2) & DIS_CURS));
  428. //
  429. // Select 32x32 cursor, clear clock doubler bit.
  430. //
  431. RD_CMD_REG_3(ucCurState);
  432. WR_CMD_REG_3(ucCurState & (~DAC_CLK_2X & CUR_MODE_32));
  433. //
  434. // Set pixel read mask.
  435. //
  436. WriteDAC(HwDeviceExtension, PIXEL_MSK_REG, 0xff);
  437. return;
  438. }
  439. VOID
  440. P91Bt485SetClkDoubler(
  441. PHW_DEVICE_EXTENSION HwDeviceExtension
  442. )
  443. /*++
  444. routine description:
  445. Enable the DAC's internal clock doubler.
  446. arguments:
  447. hwdeviceextension - pointer to the miniport driver's device extension.
  448. return value:
  449. --*/
  450. {
  451. UCHAR ucCurState;
  452. VideoDebugPrint((1, "P91Bt485SetClkDoubler----------\n"));
  453. RD_CMD_REG_3(ucCurState);
  454. WR_CMD_REG_3(ucCurState | DAC_CLK_2X);
  455. return;
  456. }
  457. VOID
  458. P91Bt485ClrClkDoubler(
  459. PHW_DEVICE_EXTENSION HwDeviceExtension
  460. )
  461. /*++
  462. routine description:
  463. Disable the DAC's internal clock doubler.
  464. arguments:
  465. hwdeviceextension - pointer to the miniport driver's device extension.
  466. return value:
  467. --*/
  468. {
  469. UCHAR ucCurState;
  470. VideoDebugPrint((1, "P91Bt485ClrClkDoubler----------\n"));
  471. RD_CMD_REG_3(ucCurState);
  472. WR_CMD_REG_3(ucCurState & ~DAC_CLK_2X);
  473. return;
  474. }
  475. UCHAR
  476. ReadDAC(
  477. PHW_DEVICE_EXTENSION HwDeviceExtension,
  478. ULONG ulIndex
  479. )
  480. /*++
  481. routine description:
  482. Read a value from the specified index from the DAC.
  483. arguments:
  484. hwdeviceextension - pointer to the miniport driver's device extension,
  485. ulIndex - index register.
  486. return value:
  487. Value.
  488. --*/
  489. {
  490. if (IS_DEV_P9100)
  491. {
  492. #if 0
  493. return((UCHAR) P9_RD_REG(ulIndex));
  494. #else
  495. return( (UCHAR) (VideoPortReadRegisterUlong(
  496. (PULONG)((PUCHAR) HwDeviceExtension->Coproc + (ulIndex - 2)) ) >> 16) );
  497. #endif
  498. }
  499. else
  500. {
  501. return(VideoPortReadPortUchar((PUCHAR)(ULONG_PTR)ulIndex));
  502. }
  503. } // End of ReadDAC()
  504. VOID
  505. WriteDAC(
  506. PHW_DEVICE_EXTENSION HwDeviceExtension,
  507. ULONG ulIndex,
  508. UCHAR ucValue
  509. )
  510. /*++
  511. routine description:
  512. Write the specified value to the specified index to the DAC.
  513. arguments:
  514. hwdeviceextension - pointer to the miniport driver's device extension,
  515. ulIndex - index register,
  516. ucValue - value to write.
  517. return value:
  518. None.
  519. --*/
  520. {
  521. if (IS_DEV_P9100)
  522. {
  523. #if 0
  524. P9_WR_REG(ulIndex, ucValue);
  525. #endif
  526. VideoPortWriteRegisterUlong(
  527. (PULONG)((PUCHAR)HwDeviceExtension->Coproc + (ulIndex - 2)),
  528. (((ULONG) ucValue) << 16) );
  529. }
  530. else
  531. {
  532. VideoPortWritePortUchar((PUCHAR)(ULONG_PTR)ulIndex, ucValue);
  533. }
  534. return;
  535. } // End of WriteDAC()