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.

156 lines
4.6 KiB

  1. /******************************************************************************
  2. *
  3. * ******************************************
  4. * * Copyright (c) 1997, Cirrus Logic, Inc. *
  5. * * All Rights Reserved *
  6. * ******************************************
  7. *
  8. * PROJECT: Laguna I (CL-GD546x) -
  9. *
  10. * FILE: clddc2b.c
  11. *
  12. * AUTHOR: Benny Ng
  13. *
  14. * DESCRIPTION:
  15. * This module checks for a DDC monitor, and returns the
  16. * established Timings value from the EDID if found.
  17. *
  18. ****************************************************************************
  19. ****************************************************************************/
  20. /*----------------------------- INCLUDES ----------------------------------*/
  21. #include "cirrus.h"
  22. #define VOLATILE volatile
  23. #define I2COUT_PORT 0x280
  24. #define I2CIN_PORT 0x281
  25. #define OFF 0
  26. #define ON 1
  27. /*-------------------------------------------------------------------------*/
  28. unsigned char InMemb(PHW_DEVICE_EXTENSION HwDeviceExtension, int offset)
  29. {
  30. #undef LAGUNA_REGS
  31. #define LAGUNA_REGS HwDeviceExtension->RegisterAddress
  32. VOLATILE unsigned char *pByte = (unsigned char *)(LAGUNA_REGS + offset);
  33. return *pByte;
  34. }
  35. unsigned char OutMemb(PHW_DEVICE_EXTENSION HwDeviceExtension,
  36. int offset,
  37. unsigned char value)
  38. {
  39. #undef LAGUNA_REGS
  40. #define LAGUNA_REGS HwDeviceExtension->RegisterAddress
  41. VOLATILE unsigned char *pByte = (unsigned char *)(LAGUNA_REGS + offset);
  42. *pByte = value;
  43. return *pByte;
  44. }
  45. // NOTE: HwDeviceExtension->I2Cflavor determines whether to invert the
  46. // output clock and data lines and is set in GetDDCInformation below
  47. /*-------------------------------------------------------------------------*/
  48. VOID WriteClockLine (PHW_DEVICE_EXTENSION HwDeviceExtension, UCHAR data)
  49. {
  50. UCHAR ReadSEQDATA;
  51. ReadSEQDATA = InMemb(HwDeviceExtension, I2COUT_PORT);
  52. ReadSEQDATA = (ReadSEQDATA & 0x7F) | ((data^HwDeviceExtension->I2Cflavor) << 7);
  53. OutMemb(HwDeviceExtension, I2COUT_PORT, ReadSEQDATA);
  54. }
  55. /*-------------------------------------------------------------------------*/
  56. VOID WriteDataLine (PHW_DEVICE_EXTENSION HwDeviceExtension, UCHAR data)
  57. {
  58. UCHAR ReadSEQDATA;
  59. ReadSEQDATA = InMemb(HwDeviceExtension, I2COUT_PORT);
  60. ReadSEQDATA &= 0xFE;
  61. ReadSEQDATA |= (data^HwDeviceExtension->I2Cflavor) & 1;
  62. OutMemb(HwDeviceExtension, I2COUT_PORT, ReadSEQDATA);
  63. }
  64. /*-------------------------------------------------------------------------*/
  65. BOOLEAN ReadClockLine (PHW_DEVICE_EXTENSION HwDeviceExtension)
  66. {
  67. UCHAR ReadSEQDATA;
  68. ReadSEQDATA = InMemb(HwDeviceExtension, I2CIN_PORT);
  69. return (ReadSEQDATA >> 7);
  70. }
  71. /*-------------------------------------------------------------------------*/
  72. BOOLEAN ReadDataLine (PHW_DEVICE_EXTENSION HwDeviceExtension)
  73. {
  74. return (InMemb(HwDeviceExtension, I2CIN_PORT) & 1);
  75. }
  76. /*-------------------------------------------------------------------------*/
  77. VOID WaitVSync (PHW_DEVICE_EXTENSION HwDeviceExtension)
  78. {
  79. // not used
  80. }
  81. // callbacks for VideoPortDDCMonitorHelper
  82. I2C_FNC_TABLE I2CFunctions =
  83. {
  84. sizeof(struct _I2C_FNC_TABLE ),
  85. WriteClockLine,
  86. WriteDataLine,
  87. ReadClockLine,
  88. ReadDataLine,
  89. WaitVSync,
  90. NULL
  91. };
  92. BOOLEAN GetDDCInformation(
  93. PHW_DEVICE_EXTENSION HwDeviceExtension,
  94. PVOID QueryBuffer,
  95. ULONG BufferSize
  96. )
  97. {
  98. // Some cards invert the output clock and data bits.
  99. // (It's probably all 5465's but since I'm not sure so I will try
  100. // reading the DDC info first without inverting the output then with
  101. // instead of assuming it by chip type)
  102. HwDeviceExtension->I2Cflavor=0; // start non inverted
  103. if (!VideoPortDDCMonitorHelper (HwDeviceExtension,
  104. &I2CFunctions,
  105. QueryBuffer,
  106. BufferSize)
  107. )
  108. {
  109. HwDeviceExtension->I2Cflavor=0xff; // else try inverted
  110. if (!VideoPortDDCMonitorHelper (HwDeviceExtension,
  111. &I2CFunctions,
  112. QueryBuffer,
  113. BufferSize)
  114. )
  115. return FALSE;
  116. }
  117. VideoPortMoveMemory(HwDeviceExtension->EDIDBuffer,
  118. QueryBuffer,
  119. sizeof(HwDeviceExtension->EDIDBuffer));
  120. return TRUE;
  121. }