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.

180 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1994-1995 International Buisness Machines Corporation
  3. Copyright (c) 1994-1995 Microsoft Corporation
  4. Module Name:
  5. sdac.c
  6. Abstract:
  7. This module contains the code that initializes the S3 SDAC.
  8. Environment:
  9. Kernel mode
  10. Revision History:
  11. --*/
  12. #include "s3.h"
  13. #if defined(ALLOC_PRAGMA)
  14. #pragma alloc_text(PAGE,InitializeSDAC)
  15. #pragma alloc_text(PAGE,FindSDAC)
  16. #endif
  17. BOOLEAN
  18. InitializeSDAC( PHW_DEVICE_EXTENSION HwDeviceExtension )
  19. /*++
  20. Routine Description:
  21. Initializes the SDAC.
  22. Arguments:
  23. HwDeviceExtension - Supplies a pointer to the miniport's device extension.
  24. Return Value:
  25. Always TRUE
  26. --*/
  27. {
  28. SDAC_PLL_PARMS
  29. *SdacClk0;
  30. ULONG
  31. tablebase;
  32. UCHAR
  33. i,
  34. clk,
  35. dval,
  36. old55;
  37. tablebase = HwDeviceExtension->ActiveFrequencyEntry->Fixed.Clock;
  38. clk = (UCHAR) tablebase;
  39. tablebase = (tablebase < 8) ? 0 : ((tablebase - 2) / 6) * 6;
  40. SdacClk0 = &SdacTable[tablebase];
  41. clk -= (UCHAR) tablebase;
  42. clk |= 0x20;
  43. // set RS[2] with CR55[0];
  44. VideoPortWritePortUchar(CRT_ADDRESS_REG, 0x55);
  45. dval = VideoPortReadPortUchar(CRT_DATA_REG);
  46. old55 = dval;
  47. dval &= 0xfc;
  48. dval |= 0x01;
  49. VideoPortWritePortUchar(CRT_DATA_REG, dval);
  50. VideoPortReadPortUchar(CRT_DATA_REG);
  51. // Enhanced Command Register
  52. if( HwDeviceExtension->ActiveFrequencyEntry->BitsPerPel == 16 )
  53. VideoPortWritePortUchar(DAC_PIXEL_MASK_REG, 0x50);
  54. else
  55. VideoPortWritePortUchar(DAC_PIXEL_MASK_REG, 0x00);
  56. // Program CLK0 registers
  57. for( i = 2; i < 8; ++i ) // write registers f2 - f7 only
  58. {
  59. // make sure we don't run off the end of the table
  60. if( (ULONG_PTR) &SdacClk0[i] >= (ULONG_PTR) &SdacTable[SDAC_TABLE_SIZE] )
  61. break;
  62. if( SdacClk0[i].m || SdacClk0[i].n )
  63. {
  64. VideoPortWritePortUchar(DAC_ADDRESS_WRITE_PORT, i);
  65. VideoPortWritePortUchar(DAC_DATA_REG_PORT, SdacClk0[i].m);
  66. VideoPortWritePortUchar(DAC_DATA_REG_PORT, SdacClk0[i].n);
  67. }
  68. }
  69. // Program CLK1
  70. VideoPortWritePortUchar(DAC_ADDRESS_WRITE_PORT, 0x0a);
  71. VideoPortWritePortUchar(DAC_DATA_REG_PORT, 0x41);
  72. VideoPortWritePortUchar(DAC_DATA_REG_PORT, 0x26);
  73. // select CLK0 with the PLL control register
  74. VideoPortWritePortUchar(DAC_ADDRESS_WRITE_PORT, 0x0e);
  75. VideoPortWritePortUchar(DAC_DATA_REG_PORT, clk);
  76. // restore CR55
  77. VideoPortWritePortUchar(CRT_ADDRESS_REG, 0x55);
  78. VideoPortWritePortUchar(CRT_DATA_REG, old55);
  79. return( TRUE );
  80. }
  81. BOOLEAN
  82. FindSDAC( PHW_DEVICE_EXTENSION HwDeviceExtension )
  83. /*++
  84. Routine Description:
  85. Detects and S3 SDAC.
  86. Arguments:
  87. HwDeviceExtension - Supplies a pointer to the miniport's device extension.
  88. Return Value:
  89. TRUE if SDAC detected; FALSE if not.
  90. --*/
  91. {
  92. UCHAR
  93. regval,
  94. old55;
  95. // 4 consecutive reads of the SDAC's Pixel Mask Register cause
  96. // the next access to that register to be redirected to the
  97. // SDAC's Enhanced Command Register, additionally the 4th read
  98. // returns 0x70 to identify the SDAC
  99. // set CR55[0] to access the Pixel Mask Register
  100. VideoPortWritePortUchar( CRT_ADDRESS_REG, 0x55 );
  101. old55 = VideoPortReadPortUchar( CRT_DATA_REG );
  102. VideoPortWritePortUchar( CRT_DATA_REG, (UCHAR) (old55 & 0xfc) );
  103. // look for the SDAC's ID
  104. VideoPortWritePortUchar( DAC_PIXEL_MASK_REG, 0 );
  105. VideoPortWritePortUchar( DAC_PIXEL_MASK_REG, 0xff );
  106. VideoPortReadPortUchar( DAC_PIXEL_MASK_REG );
  107. VideoPortReadPortUchar( DAC_PIXEL_MASK_REG );
  108. VideoPortReadPortUchar( DAC_PIXEL_MASK_REG );
  109. regval = VideoPortReadPortUchar( DAC_PIXEL_MASK_REG );
  110. if( (regval & 0xf0) == 0x70 )
  111. {
  112. // clear the redirection
  113. VideoPortReadPortUchar( DAC_PIXEL_MASK_REG );
  114. return( TRUE );
  115. }
  116. // restore the contents of register 55
  117. VideoPortWritePortUchar( CRT_ADDRESS_REG, 0x55 );
  118. VideoPortWritePortUchar( CRT_DATA_REG, old55 );
  119. return( FALSE );
  120. }