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.

282 lines
6.5 KiB

  1. //
  2. // Module: DDC50.C
  3. // Date: Jun 29, 1997
  4. //
  5. // Copyright (c) 1997 by ATI Technologies Inc.
  6. //
  7. /********************** PolyTron RCS Utilities
  8. $Revision: 1.1 $
  9. $Date: 30 Jun 1997 11:36:28 $
  10. $Author: MACIESOW $
  11. $Log: V:\source\wnt\ms11\miniport\archive\ddc50.c_v $
  12. *
  13. * Rev 1.1 30 Jun 1997 11:36:28 MACIESOW
  14. * Initial revision.
  15. End of PolyTron RCS section *****************/
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <errno.h>
  20. #include <math.h>
  21. #include "dderror.h"
  22. #include "miniport.h"
  23. #include "ntddvdeo.h"
  24. #include "video.h" /* for VP_STATUS definition */
  25. #include "stdtyp.h"
  26. #include "amachcx.h"
  27. #include "amach1.h"
  28. #include "atimp.h"
  29. #include "atint.h"
  30. #include "cvtvdif.h"
  31. #include "cvtvga.h"
  32. #include "dynainit.h"
  33. #include "dynatime.h"
  34. #include "services.h"
  35. #include "vdptocrt.h"
  36. #define INCLUDE_CVTDDC
  37. #include "cvtddc.h"
  38. #if (TARGET_BUILD >= 500)
  39. VOID WriteClockLineDAC(PHW_DEVICE_EXTENSION phwDeviceExtension, UCHAR ucData);
  40. VOID WriteDataLineDAC(PHW_DEVICE_EXTENSION phwDeviceExtension, UCHAR ucData);
  41. BOOLEAN ReadClockLineDAC(PHW_DEVICE_EXTENSION phwDeviceExtension);
  42. BOOLEAN ReadDataLineDAC(PHW_DEVICE_EXTENSION phwDeviceExtension);
  43. VOID WaitForVsyncActiveDAC(PHW_DEVICE_EXTENSION HwDeviceExtension);
  44. VOID WriteClockLineGP(PHW_DEVICE_EXTENSION phwDeviceExtension, UCHAR ucData);
  45. VOID WriteDataLineGP(PHW_DEVICE_EXTENSION phwDeviceExtension, UCHAR ucData);
  46. BOOLEAN ReadClockLineGP(PHW_DEVICE_EXTENSION phwDeviceExtension);
  47. BOOLEAN ReadDataLineGP(PHW_DEVICE_EXTENSION phwDeviceExtension);
  48. VOID WaitForVsyncActiveGP(PHW_DEVICE_EXTENSION HwDeviceExtension);
  49. /****************************************************************
  50. ; DDC register
  51. ;
  52. ; High Byte, High Word
  53. ;
  54. ; ... 5 4 3 2 1 0 SCW = CLK Write
  55. ; --------|---|---|---|---|---|---| SDW = DATA Write
  56. ; ...|SCW|SDW| |SCR|SDR| | SCR = CLK Read
  57. ; --------------------------------- SDR = DATA Read
  58. ;
  59. ;****************************************************************/
  60. VOID WriteClockLineDAC(PHW_DEVICE_EXTENSION phwDeviceExtension, UCHAR ucData)
  61. {
  62. UCHAR Scratch;
  63. //
  64. // Value is inverted.
  65. //
  66. ucData = (ucData + 1) & 0x01;
  67. //
  68. // Write to the SCL line.
  69. //
  70. Scratch = (INP_HBHW(DAC_CNTL) & 0xE8) | (ucData << 5);
  71. OUTP_HBHW(DAC_CNTL, Scratch);
  72. }
  73. VOID WriteDataLineDAC(PHW_DEVICE_EXTENSION phwDeviceExtension, UCHAR ucData)
  74. {
  75. UCHAR Scratch;
  76. //
  77. // Value is inverted.
  78. //
  79. ucData = (ucData + 1) & 0x01;
  80. //
  81. // Write to the SDA line.
  82. //
  83. Scratch = (INP_HBHW(DAC_CNTL) & 0xD8) | (ucData << 4);
  84. OUTP_HBHW(DAC_CNTL, Scratch);
  85. }
  86. BOOLEAN ReadClockLineDAC(PHW_DEVICE_EXTENSION phwDeviceExtension)
  87. {
  88. return ((INP_HBHW(DAC_CNTL) & 0x04) >> 2);
  89. }
  90. BOOLEAN ReadDataLineDAC(PHW_DEVICE_EXTENSION phwDeviceExtension)
  91. {
  92. return ((INP_HBHW(DAC_CNTL) & 0x02) >> 1);
  93. }
  94. VOID WaitForVsyncActiveDAC(PHW_DEVICE_EXTENSION HwDeviceExtension)
  95. {
  96. //
  97. // BUGBUG
  98. //
  99. delay(30);
  100. }
  101. /****************************************************************
  102. ; DDC register
  103. ;
  104. ; High Byte, Low Word
  105. ;
  106. ; ... 5 4 3 2 1 0
  107. ; --------|---|---|---|---|---|---|
  108. ; ...|SCR|SDR| | | | | SCR = CLK Read
  109. ; --------------------------------- SDR = DATA Read
  110. ;
  111. ; High Byte, High Word
  112. ;
  113. ; ... 5 4 3 2 1 0 SCW = CLK Write
  114. ; --------|---|---|---|---|---|---| SDW = DATA Write
  115. ; ...|SCW|SDW| | | | |
  116. ; ---------------------------------
  117. ;
  118. ;****************************************************************/
  119. VOID WriteClockLineGP(PHW_DEVICE_EXTENSION phwDeviceExtension, UCHAR ucData)
  120. {
  121. UCHAR Scratch;
  122. //
  123. // Value is inverted.
  124. //
  125. ucData = (ucData + 1) & 0x01;
  126. //
  127. // Write to the SCL line.
  128. //
  129. Scratch = (INP_HBHW(GP_IO) & 0xDF) | (ucData << 5);
  130. OUTP_HBHW(GP_IO, Scratch);
  131. }
  132. VOID WriteDataLineGP(PHW_DEVICE_EXTENSION phwDeviceExtension, UCHAR ucData)
  133. {
  134. UCHAR Scratch;
  135. //
  136. // Value is inverted.
  137. //
  138. ucData = (ucData + 1) & 0x01;
  139. //
  140. // Write to the SDA line.
  141. //
  142. Scratch = (INP_HBHW(GP_IO) & 0xEF) | (ucData << 4);
  143. OUTP_HBHW(GP_IO, Scratch);
  144. }
  145. BOOLEAN ReadClockLineGP(PHW_DEVICE_EXTENSION phwDeviceExtension)
  146. {
  147. return ((INP_HBLW(GP_IO) & 0x20) >> 5);
  148. }
  149. BOOLEAN ReadDataLineGP(PHW_DEVICE_EXTENSION phwDeviceExtension)
  150. {
  151. return ((INP_HBLW(GP_IO) & 0x10) >> 4);
  152. }
  153. VOID WaitForVsyncActiveGP(PHW_DEVICE_EXTENSION HwDeviceExtension)
  154. {
  155. //
  156. // BUGBUG
  157. //
  158. delay(30);
  159. }
  160. BOOLEAN
  161. DDC2Query50(
  162. PHW_DEVICE_EXTENSION phwDeviceExtension,
  163. PUCHAR QueryBuffer,
  164. ULONG BufferSize)
  165. //
  166. // DESCRIPTION:
  167. // Reads the basic EDID structure from the monitor using DDC2.
  168. //
  169. // PARAMETERS:
  170. // phwDeviceExtension Points to per-adapter device extension.
  171. // QueryBuffer Buffer where information will be stored.
  172. // BufferSize Size of the buffer to fill.
  173. //
  174. // RETURN VALUE:
  175. // Whether the call succeeded or not.
  176. //
  177. {
  178. struct query_structure * Query;
  179. I2C_FNC_TABLE i2c;
  180. ULONG Checksum;
  181. ULONG i;
  182. //
  183. // Get a formatted pointer into the query section of HW_DEVICE_EXTENSION.
  184. //
  185. Query = (struct query_structure *)phwDeviceExtension->CardInfo;
  186. //
  187. // Determine which class of hardware we are dealing with, since
  188. // different cards use different registers to control the SCL
  189. // and SDA lines. Don't worry about cards which don't support
  190. // DDC2, since the check for DDC support will have rejected
  191. // any of these cards so we won't reach this point in the code.
  192. //
  193. {
  194. i2c.WriteClockLine = WriteClockLineDAC;
  195. i2c.WriteDataLine = WriteDataLineDAC;
  196. i2c.ReadClockLine = ReadClockLineDAC;
  197. i2c.ReadDataLine = ReadDataLineDAC;
  198. i2c.WaitVsync = WaitForVsyncActiveDAC;
  199. VideoDebugPrint((DEBUG_NORMAL, "DAC DDC control"));
  200. }
  201. i2c.Size = sizeof(I2C_FNC_TABLE);
  202. if (!VideoPortDDCMonitorHelper(phwDeviceExtension,
  203. &i2c,
  204. QueryBuffer,
  205. BufferSize))
  206. {
  207. VideoDebugPrint((DEBUG_NORMAL, "DDC Query Failed\n"));
  208. return FALSE;
  209. }
  210. return TRUE;
  211. }
  212. #endif