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.

282 lines
9.2 KiB

  1. //---------------------------------------------------------------------------
  2. /*++
  3. Copyright (c) 1994 Cirrus Logic, Inc.
  4. Module Name:
  5. sr754x.c
  6. Abstract:
  7. This module performs the save/restore operations specific to the
  8. CL-GD754x chipset (aka Nordic).
  9. Environment:
  10. kernel mode only
  11. Notes:
  12. Revision History:
  13. 13Oct94 mrh Initial version
  14. --*/
  15. //---------------------------------------------------------------------------
  16. #include "dderror.h"
  17. #include "devioctl.h"
  18. #include "miniport.h"
  19. #include "ntddvdeo.h"
  20. #include "video.h"
  21. #include "cirrus.h"
  22. #include "sr754x.h"
  23. #if defined(ALLOC_PRAGMA)
  24. #pragma alloc_text(PAGE,NordicSaveRegs)
  25. #pragma alloc_text(PAGE,NordicRestoreRegs)
  26. #endif
  27. VP_STATUS NordicSaveRegs(
  28. PHW_DEVICE_EXTENSION HwDeviceExtension,
  29. PUSHORT pNordicSaveArea
  30. )
  31. {
  32. UCHAR i;
  33. UCHAR PortVal, Save2C, Save2D;
  34. PUCHAR CRTCAddressPort, CRTCDataPort;
  35. PUSHORT pSaveBuf;
  36. UCHAR vShadowIndex[CL754x_NUM_VSHADOW] = {0x06,0x07,0x10,0x11,0x15,0x16};
  37. UCHAR zShadowIndex[CL754x_NUM_ZSHADOW] = {0,2,3,4,5};
  38. UCHAR yShadowIndex[CL754x_NUM_YSHADOW] = {0,2,3,4,5};
  39. UCHAR xShadowIndex[CL754x_NUM_XSHADOW] = {2,3,4,5,6,7,8,9,0x0B,0x0C,0x0D,0x0E};
  40. //
  41. // Determine where the CRTC registers are addressed (color or mono).
  42. //
  43. CRTCAddressPort = HwDeviceExtension->IOAddress;
  44. CRTCDataPort = HwDeviceExtension->IOAddress;
  45. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  46. MISC_OUTPUT_REG_READ_PORT) & 0x01)
  47. {
  48. CRTCAddressPort += CRTC_ADDRESS_PORT_COLOR;
  49. CRTCDataPort += CRTC_DATA_PORT_COLOR;
  50. }
  51. else
  52. {
  53. CRTCAddressPort += CRTC_ADDRESS_PORT_MONO;
  54. CRTCDataPort += CRTC_DATA_PORT_MONO;
  55. }
  56. VideoPortWritePortUchar(CRTCAddressPort, IND_CR2D);
  57. Save2D = (VideoPortReadPortUchar(CRTCDataPort));
  58. VideoPortWritePortUchar(CRTCAddressPort, IND_CR2C);
  59. Save2C = (VideoPortReadPortUchar(CRTCDataPort));
  60. pSaveBuf = pNordicSaveArea;
  61. //Initialize the control registers to access shadowed vertical regs:
  62. // CR2C[3] = {0} Allows access to Vert regs (CR6,CR7,CR10,CR11,CR15,CR16)
  63. // CR2D[7] = {0} Blocks access to LCD timing regs (R2X-REX)
  64. //
  65. VideoPortWritePortUshort((PUSHORT)CRTCAddressPort,
  66. (USHORT)(((Save2C & ~0x08) << 8) | IND_CR2C));
  67. VideoPortWritePortUshort((PUSHORT)CRTCAddressPort,
  68. (USHORT)(((Save2D & ~0x80) << 8) | IND_CR2D));
  69. for (i = 0; i < CL754x_NUM_VSHADOW; i++)
  70. {
  71. VideoPortWritePortUchar (CRTCAddressPort, vShadowIndex[i]);
  72. *pSaveBuf++ = (USHORT)((VideoPortReadPortUchar (CRTCDataPort)) << 8) |
  73. vShadowIndex[i];
  74. }
  75. for (i = CL754x_CRTC_EXT_START; i <= CL754x_CRTC_EXT_END; i++)
  76. {
  77. VideoPortWritePortUchar (CRTCAddressPort, i);
  78. *pSaveBuf++ = (USHORT)((VideoPortReadPortUchar (CRTCDataPort)) << 8) | i;
  79. }
  80. for (i = CL754x_HRZ_TIME_START; i <= CL754x_HRZ_TIME_END; i++)
  81. {
  82. VideoPortWritePortUchar (CRTCAddressPort, i);
  83. *pSaveBuf++ = (USHORT)((VideoPortReadPortUchar (CRTCDataPort)) << 8) | i;
  84. }
  85. // Set CR2D [7] to {0} and CR2C[5,4] to {1,0}
  86. // These values provide access to Y shadow registers
  87. //
  88. VideoPortWritePortUshort((PUSHORT)CRTCAddressPort,
  89. (USHORT)(((Save2D & ~0x80) << 8) | IND_CR2D));
  90. PortVal = Save2C & ~0x30; // We'll use PortVal again below
  91. VideoPortWritePortUshort((PUSHORT)CRTCAddressPort,
  92. (USHORT)(((PortVal | 0x20) << 8) | IND_CR2C));
  93. for (i = 0; i < CL754x_NUM_YSHADOW; i++)
  94. {
  95. VideoPortWritePortUchar (CRTCAddressPort, yShadowIndex[i]);
  96. *pSaveBuf++ = (USHORT)((VideoPortReadPortUchar (CRTCDataPort)) << 8) |
  97. yShadowIndex[i];
  98. }
  99. // Set CR2C[5,4] to {1,1}
  100. // This will provide access to Z shadow registers
  101. //
  102. VideoPortWritePortUshort((PUSHORT)CRTCAddressPort,
  103. (USHORT)(((PortVal | 0x30) << 8 )| IND_CR2C));
  104. for (i = 0; i < CL754x_NUM_ZSHADOW; i++)
  105. {
  106. VideoPortWritePortUchar (CRTCAddressPort, zShadowIndex[i]);
  107. *pSaveBuf++ = (USHORT)((VideoPortReadPortUchar (CRTCDataPort)) << 8) |
  108. zShadowIndex[i];
  109. }
  110. // Set CR2C[5,4] to {0,0} and CR2D[7] to {1}
  111. // This will provide access to X shadow registers
  112. //
  113. VideoPortWritePortUshort((PUSHORT)CRTCAddressPort, // PortVal=Save2C & ~0x30
  114. (USHORT)((PortVal << 8) | IND_CR2C));
  115. VideoPortWritePortUshort((PUSHORT)CRTCAddressPort,
  116. (USHORT)(((Save2D | 0x80) << 8) | IND_CR2D));
  117. for (i = 0; i < CL754x_NUM_XSHADOW; i++)
  118. {
  119. VideoPortWritePortUchar (CRTCAddressPort, xShadowIndex[i]);
  120. *pSaveBuf++ = ((VideoPortReadPortUchar (CRTCDataPort)) << 8) |
  121. xShadowIndex[i];
  122. }
  123. //Restore the original values for CR2C and CR2D
  124. //
  125. VideoPortWritePortUshort((PUSHORT)CRTCAddressPort,
  126. (USHORT)((Save2D << 8) | IND_CR2D));
  127. VideoPortWritePortUshort((PUSHORT)CRTCAddressPort,
  128. (USHORT)((Save2C << 8) | IND_CR2C));
  129. return NO_ERROR;
  130. }
  131. VP_STATUS NordicRestoreRegs(
  132. PHW_DEVICE_EXTENSION HwDeviceExtension,
  133. PUSHORT pNordicSaveArea
  134. )
  135. {
  136. ULONG i;
  137. UCHAR PortVal, Save2C, Save2D;
  138. PUSHORT pSaveBuf;
  139. PUCHAR CRTCAddressPort, CRTCDataPort;
  140. //
  141. // Determine where the CRTC registers are addressed (color or mono).
  142. //
  143. CRTCAddressPort = HwDeviceExtension->IOAddress;
  144. CRTCDataPort = HwDeviceExtension->IOAddress;
  145. if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
  146. MISC_OUTPUT_REG_READ_PORT) & 0x01)
  147. {
  148. CRTCAddressPort += CRTC_ADDRESS_PORT_COLOR;
  149. CRTCDataPort += CRTC_DATA_PORT_COLOR;
  150. }
  151. else
  152. {
  153. CRTCAddressPort += CRTC_ADDRESS_PORT_MONO;
  154. CRTCDataPort += CRTC_DATA_PORT_MONO;
  155. }
  156. //Initialize the control registers to access shadowed vertical regs
  157. // CR11[7] = {0} Allows access to CR0-7
  158. // CR2C[3] = {0} Allows access to Vertical regs (CR6,CR7,CR10,CR11,CR15,CR16
  159. // CR2D[7] = {0} Blocks access to LCD timing regs (R2X-REX)
  160. //
  161. VideoPortWritePortUchar(CRTCAddressPort, IND_CRTC_PROTECT);
  162. VideoPortWritePortUchar(CRTCDataPort,
  163. (UCHAR) (VideoPortReadPortUchar(CRTCDataPort) & ~0x80));
  164. VideoPortWritePortUchar(CRTCAddressPort, IND_CR2C);
  165. VideoPortWritePortUchar(CRTCDataPort,
  166. (UCHAR) (VideoPortReadPortUchar(CRTCDataPort) & ~0x08));
  167. VideoPortWritePortUchar(CRTCAddressPort, IND_CR2D);
  168. VideoPortWritePortUchar(CRTCDataPort,
  169. (UCHAR) (VideoPortReadPortUchar(CRTCDataPort) & ~0x80));
  170. pSaveBuf = pNordicSaveArea;
  171. for (i = 0; i < CL754x_NUM_VSHADOW; i++)
  172. {
  173. VideoPortWritePortUshort((PUSHORT)CRTCAddressPort, (*pSaveBuf++));
  174. }
  175. // Make sure we didn't lock CR0-CR7
  176. //
  177. VideoPortWritePortUchar(CRTCAddressPort, IND_CRTC_PROTECT);
  178. VideoPortWritePortUchar(CRTCDataPort,
  179. (UCHAR) (VideoPortReadPortUchar(CRTCDataPort) & ~0x80));
  180. for (i=0; i < (CL754x_NUM_CRTC_EXT_PORTS + CL754x_NUM_HRZ_TIME_PORTS); i++)
  181. {
  182. VideoPortWritePortUshort((PUSHORT)CRTCAddressPort, (*pSaveBuf++));
  183. }
  184. // Set CR2D [7] to {0} and CR2C[5,4] to {1,0}; save current contents
  185. // These values provide access to Y shadow registers
  186. //
  187. VideoPortWritePortUchar(CRTCAddressPort, IND_CR2D);
  188. Save2D = (VideoPortReadPortUchar(CRTCDataPort));
  189. VideoPortWritePortUchar(CRTCDataPort, (UCHAR)(Save2D & ~0x80));
  190. VideoPortWritePortUchar(CRTCAddressPort, IND_CR2C);
  191. PortVal = Save2C = (VideoPortReadPortUchar(CRTCDataPort));
  192. PortVal &= ~0x30;
  193. PortVal |= 0x20;
  194. VideoPortWritePortUchar(CRTCDataPort, PortVal);
  195. for (i = 0; i < CL754x_NUM_YSHADOW; i++)
  196. {
  197. VideoPortWritePortUshort((PUSHORT)CRTCAddressPort, (*pSaveBuf++));
  198. }
  199. // Set CR2C[5,4] to {1,1}
  200. // This will provide access to Z shadow registers
  201. //
  202. VideoPortWritePortUshort((PUSHORT)CRTCAddressPort,
  203. (USHORT)(((PortVal | 0x30) << 8) | IND_CR2C) );
  204. for (i = 0; i < CL754x_NUM_ZSHADOW; i++)
  205. {
  206. VideoPortWritePortUshort((PUSHORT)CRTCAddressPort, (*pSaveBuf++));
  207. }
  208. // Set CR2C[5,4] to {0,0} and CR2D[7] to {1}
  209. // This will provide access to X shadow registers
  210. //
  211. VideoPortWritePortUshort((PUSHORT)CRTCAddressPort,
  212. (USHORT)(((PortVal & ~0x30) << 8) | IND_CR2C) );
  213. VideoPortWritePortUshort((PUSHORT)CRTCAddressPort,
  214. (USHORT)(((Save2D | 0x80) << 8) | IND_CR2D) );
  215. for (i = 0; i < CL754x_NUM_XSHADOW; i++)
  216. {
  217. VideoPortWritePortUshort((PUSHORT)CRTCAddressPort, (*pSaveBuf++));
  218. }
  219. // Reset the Blitter, in case it's busy
  220. //
  221. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  222. GRAPH_ADDRESS_PORT), 0x0430);
  223. VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
  224. GRAPH_ADDRESS_PORT), 0x0030);
  225. VideoPortWritePortUshort((PUSHORT) CRTCAddressPort,
  226. (USHORT)((Save2C << 8) | IND_CR2C));
  227. VideoPortWritePortUshort((PUSHORT) CRTCAddressPort,
  228. (USHORT)((Save2D << 8) | IND_CR2D));
  229. return NO_ERROR;
  230. }