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.

1519 lines
48 KiB

  1. /*/****************************************************************************
  2. * name: vidfile.c
  3. *
  4. * description: Calculate video parameters
  5. *
  6. * designed: Gilles-Marie Perron
  7. * last modified: $Author: ctoutant $, $Date: 94/10/24 11:08:23 $
  8. *
  9. * version: $Id: vidfile.c 1.44 94/10/24 11:08:23 ctoutant Exp Locker: ctoutant $
  10. *
  11. * parameters: -
  12. * modifies: -
  13. * calls: -
  14. * returns: -
  15. ******************************************************************************/
  16. #include "switches.h"
  17. #include "bind.h"
  18. #include "mtxpci.h" /* pciBoardInfo, PCI_FLAG_ATHENA_REV1 */
  19. #ifdef WINDOWS_NT
  20. bool loadVidPar(dword Zoom, HwModeData *HwMode, HwModeData *DisplayMode);
  21. void calculCrtcParam(void);
  22. byte detectPatchWithGal(void);
  23. void GetMGAConfiguration(volatile byte _Far *, dword*, dword*, dword*);
  24. #if defined(ALLOC_PRAGMA)
  25. #pragma alloc_text(PAGE,loadVidPar)
  26. #pragma alloc_text(PAGE,calculCrtcParam)
  27. #pragma alloc_text(PAGE,detectPatchWithGal)
  28. #endif
  29. //#if defined(ALLOC_PRAGMA)
  30. // #pragma data_seg("PAGE")
  31. //#endif
  32. #endif
  33. #ifndef WINDOWS_NT
  34. #include <stdio.h>
  35. #include <string.h>
  36. #include <stdlib.h>
  37. #endif
  38. #include "bind.h"
  39. #include "defbind.h"
  40. #ifndef __DDK_SRC__
  41. #include "sxci.h"
  42. #endif
  43. #include "mgai_c.h"
  44. #include "mgai.h"
  45. #include "mga.h"
  46. #include "vidfile.h"
  47. #if ((!defined (WINDOWS_NT)) || (USE_DDC_CODE))
  48. /*********** DDC CODE ****************/
  49. #include "edid.h"
  50. /*********** DDC CODE ****************/
  51. #endif
  52. #define VCLK_DIVISOR 8
  53. vid vidtab [29] = {{"Pixel_clk", 75000}, /* 0 */
  54. {"H_Front_porch", 24},
  55. {"H_sync", 136},
  56. {"H_back_porch", 144},
  57. {"H_Overscan", 16},
  58. {"H_Visible", 1024}, /* 5 */
  59. {"V_front_porch", 3},
  60. {"V_sync", 6},
  61. {"V_back_porch", 29},
  62. {"V_Overscan", 2},
  63. {"V_visible", 768}, /* 10 */
  64. {"P_width", 8},
  65. {"Overscan_Enable", 0},
  66. {"Interlace_mode_Enable", 0},
  67. {"Start_add_Frame_Buffer", 0},
  68. {"Zoom_factor_x", 1}, /* 15 */
  69. {"Zoom_factor_y", 1},
  70. {"Virtuel_VIDEO_pitch", 1024},
  71. {"ALW", 1},
  72. {"H_blanking_Skew", 0},
  73. {"H_retrace_end_Skew", 0}, /* 20 */
  74. {"Cursor_end_Skew", 0},
  75. {"Cursor_Enable", 0},
  76. {"CRTC_test_Enable", 0},
  77. {"V_IRQ_Enable", 0},
  78. {"Select_5_Refresh_Cycle", 0}, /* 25 */
  79. {"CRTC_reg_0_7_Protect", 0},
  80. {"Hsync_pol", 0},
  81. {"Vsync_pol", 0}
  82. };
  83. ResParamSet ResParam[100] = {
  84. { 640, 480, 8, 75, 31200, 640, 32, 64, 96, 0, 480, 1, 3, 16, 0, 0, 0, 0, 0 }, { 640, 480, 8, 75, 31200, 640, 32, 64, 96, 0, 480, 1, 3, 16, 0, 0, 0, 0, 0 },
  85. { 640, 480, 16, 75, 31200, 640, 32, 64, 96, 0, 480, 1, 3, 16, 0, 0, 0, 0, 0 },
  86. { 640, 480, 24, 75, 31200, 640, 32, 64, 96, 0, 480, 1, 3, 16, 0, 0, 0, 0, 0 },
  87. { 640, 480, 32, 75, 31200, 640, 32, 64, 96, 0, 480, 1, 3, 16, 0, 0, 0, 0, 0 },
  88. { 640, 480, 8, 72, 31500, 640, 32, 32, 128, 0, 480, 9, 3, 28, 0, 0, 0, 0, 0 },
  89. { 640, 480, 16, 72, 31500, 640, 32, 32, 128, 0, 480, 9, 3, 28, 0, 0, 0, 0, 0 },
  90. { 640, 480, 24, 72, 31500, 640, 32, 32, 128, 0, 480, 9, 3, 28, 0, 0, 0, 0, 0 },
  91. { 640, 480, 32, 72, 31500, 640, 32, 32, 128, 0, 480, 9, 3, 28, 0, 0, 0, 0, 0 },
  92. { 640, 480, 8, 60, 25175, 640, 32, 96, 32, 0, 480, 8, 5, 32, 0, 0, 0, 0, 0 },
  93. { 640, 480, 16, 60, 25175, 640, 32, 96, 32, 0, 480, 8, 5, 32, 0, 0, 0, 0, 0 },
  94. { 640, 480, 24, 60, 25175, 640, 32, 96, 32, 0, 480, 8, 5, 32, 0, 0, 0, 0, 0 },
  95. { 640, 480, 32, 60, 25175, 640, 32, 96, 32, 0, 480, 8, 5, 32, 0, 0, 0, 0, 0 },
  96. { 800, 600, 8, 75, 49500, 800, 32, 64, 160, 1, 600, 1, 3, 21, 0, 0, 0, 1, 1 },
  97. { 800, 600, 16, 75, 49500, 800, 32, 64, 160, 1, 600, 1, 3, 21, 0, 0, 0, 1, 1 },
  98. { 800, 600, 24, 75, 49500, 800, 32, 64, 160, 1, 600, 1, 3, 21, 0, 0, 0, 1, 1 },
  99. { 800, 600, 32, 75, 49500, 800, 32, 64, 160, 1, 600, 1, 3, 21, 0, 0, 0, 1, 1 },
  100. { 800, 600, 8, 72, 51500, 800, 64, 128, 96, 0, 600, 33, 6, 19, 0, 0, 0, 1, 1 },
  101. { 800, 600, 16, 72, 51500, 800, 64, 128, 96, 0, 600, 33, 6, 19, 0, 0, 0, 1, 1 },
  102. { 800, 600, 24, 72, 51500, 800, 64, 128, 96, 0, 600, 33, 6, 19, 0, 0, 0, 1, 1 },
  103. { 800, 600, 32, 72, 51500, 800, 64, 128, 96, 0, 600, 33, 6, 19, 0, 0, 0, 1, 1 },
  104. { 800, 600, 8, 60, 40500, 800, 32, 128, 128, 0, 600, 2, 4, 14, 0, 0, 0, 1, 1 },
  105. { 800, 600, 16, 60, 40500, 800, 32, 128, 128, 0, 600, 2, 4, 14, 0, 0, 0, 1, 1 },
  106. { 800, 600, 24, 60, 40500, 800, 32, 128, 128, 0, 600, 2, 4, 14, 0, 0, 0, 1, 1 },
  107. { 800, 600, 32, 60, 40500, 800, 32, 128, 128, 0, 600, 2, 4, 14, 0, 0, 0, 1, 1 },
  108. { 800, 600, 8, 56, 37800, 800, 32, 128, 128, 0, 600, 2, 4, 14, 0, 0, 0, 1, 1 },
  109. { 800, 600, 16, 56, 37800, 800, 32, 128, 128, 0, 600, 2, 4, 14, 0, 0, 0, 1, 1 },
  110. { 800, 600, 24, 56, 37800, 800, 32, 128, 128, 0, 600, 2, 4, 14, 0, 0, 0, 1, 1 },
  111. { 800, 600, 32, 56, 37800, 800, 32, 128, 128, 0, 600, 2, 4, 14, 0, 0, 0, 1, 1 },
  112. { 1024, 768, 8, 43, 44900, 1024, 32, 128, 64, 0, 384, 1, 4, 21, 0, 0, 1, 1, 1 },
  113. { 1024, 768, 16, 43, 44900, 1024, 32, 128, 64, 0, 384, 1, 4, 21, 0, 0, 1, 1, 1 },
  114. { 1024, 768, 24, 43, 44900, 1024, 32, 128, 64, 0, 384, 1, 4, 21, 0, 0, 1, 1, 1 },
  115. { 1024, 768, 32, 43, 44900, 1024, 32, 128, 64, 0, 384, 1, 4, 21, 0, 0, 1, 1, 1 },
  116. { 1024, 768, 8, 75, 78750, 1024, 32, 96, 160, 1, 768, 1, 3, 28, 0, 0, 0, 1, 1 },
  117. { 1024, 768, 16, 75, 78750, 1024, 32, 96, 160, 1, 768, 1, 3, 28, 0, 0, 0, 1, 1 },
  118. { 1024, 768, 24, 75, 78750, 1024, 32, 96, 160, 1, 768, 1, 3, 28, 0, 0, 0, 1, 1 },
  119. { 1024, 768, 32, 75, 78750, 1024, 32, 96, 160, 1, 768, 1, 3, 28, 0, 0, 0, 1, 1 },
  120. { 1024, 768, 8, 70, 75000, 1024, 32, 128, 160, 0, 768, 3, 6, 21, 0, 0, 0, 0, 0 },
  121. { 1024, 768, 16, 70, 75000, 1024, 32, 128, 160, 0, 768, 3, 6, 21, 0, 0, 0, 0, 0 },
  122. { 1024, 768, 24, 70, 75000, 1024, 32, 128, 160, 0, 768, 3, 6, 21, 0, 0, 0, 0, 0 },
  123. { 1024, 768, 32, 70, 75000, 1024, 32, 128, 160, 0, 768, 3, 6, 21, 0, 0, 0, 0, 0 },
  124. { 1024, 768, 8, 60, 65000, 1024, 32, 128, 160, 0, 768, 3, 6, 29, 0, 0, 0, 0, 0 },
  125. { 1024, 768, 16, 60, 65000, 1024, 32, 128, 160, 0, 768, 3, 6, 29, 0, 0, 0, 0, 0 },
  126. { 1024, 768, 24, 60, 65000, 1024, 32, 128, 160, 0, 768, 3, 6, 29, 0, 0, 0, 0, 0 },
  127. { 1024, 768, 32, 60, 65000, 1024, 32, 128, 160, 0, 768, 3, 6, 29, 0, 0, 0, 0, 0 },
  128. { 1152, 882, 8, 75, 111350, 1152, 32, 224, 224, 0, 882, 2, 10, 16, 0, 0, 0, 0, 0 },
  129. { 1152, 882, 16, 75, 111350, 1152, 32, 224, 224, 0, 882, 2, 10, 16, 0, 0, 0, 0, 0 },
  130. { 1152, 882, 24, 75, 111350, 1152, 32, 224, 224, 0, 882, 2, 10, 16, 0, 0, 0, 0, 0 },
  131. { 1152, 882, 32, 75, 111350, 1152, 32, 224, 224, 0, 882, 2, 10, 16, 0, 0, 0, 0, 0 },
  132. { 1152, 882, 8, 72, 97000, 1152, 97, 128, 95, 0, 882, 4, 8, 20, 0, 0, 0, 0, 0 },
  133. { 1152, 882, 16, 72, 97000, 1152, 97, 128, 95, 0, 882, 4, 8, 20, 0, 0, 0, 0, 0 },
  134. { 1152, 882, 24, 72, 97000, 1152, 97, 128, 95, 0, 882, 4, 8, 20, 0, 0, 0, 0, 0 },
  135. { 1152, 882, 32, 72, 95000, 1152, 64, 128, 68, 0, 882, 28, 8, 39, 0, 0, 0, 0, 0 },
  136. { 1152, 882, 8, 60, 80500, 1152, 32, 128, 160, 0, 882, 4, 8, 16, 0, 0, 0, 0, 0 },
  137. { 1152, 882, 16, 60, 80500, 1152, 32, 128, 160, 0, 882, 4, 8, 16, 0, 0, 0, 0, 0 },
  138. { 1152, 882, 24, 60, 80500, 1152, 32, 128, 160, 0, 882, 4, 8, 16, 0, 0, 0, 0, 0 },
  139. { 1152, 882, 32, 60, 80500, 1152, 32, 128, 160, 0, 882, 4, 8, 16, 0, 0, 0, 0, 0 },
  140. { 1280, 1024, 8, 75, 135600, 1280, 32, 128, 256, 1, 1024, 2, 3, 37, 0, 0, 0, 1, 1 },
  141. { 1280, 1024, 16, 75, 135600, 1280, 32, 128, 256, 1, 1024, 2, 3, 37, 0, 0, 0, 1, 1 },
  142. { 1280, 1024, 24, 75, 135600, 1280, 32, 128, 256, 1, 1024, 2, 3, 37, 0, 0, 0, 1, 1 },
  143. { 1280, 1024, 32, 75, 135600, 1280, 32, 128, 256, 1, 1024, 2, 3, 37, 0, 0, 0, 1, 1 },
  144. { 1280, 1024, 8, 72, 135000, 1280, 64, 128, 288, 0, 1024, 6, 6, 30, 0, 0, 0, 0, 0 }, { 1280, 1024, 8, 72, 135000, 1280, 64, 128, 288, 0, 1024, 6, 6, 30, 0, 0, 0, 0, 0 },
  145. { 1280, 1024, 16, 72, 135000, 1280, 64, 128, 288, 0, 1024, 6, 6, 30, 0, 0, 0, 0, 0 },
  146. { 1280, 1024, 24, 72, 135000, 1280, 64, 128, 288, 0, 1024, 6, 6, 30, 0, 0, 0, 0, 0 },
  147. { 1280, 1024, 32, 72, 135000, 1280, 64, 128, 288, 0, 1024, 6, 6, 30, 0, 0, 0, 0, 0 },
  148. { 1280, 1024, 8, 60, 110000, 1280, 32, 128, 288, 0, 1024, 3, 3, 26, 0, 0, 0, 0, 0 },
  149. { 1280, 1024, 16, 60, 110000, 1280, 32, 128, 288, 0, 1024, 3, 3, 26, 0, 0, 0, 0, 0 },
  150. { 1280, 1024, 24, 60, 110000, 1280, 32, 128, 288, 0, 1024, 3, 3, 26, 0, 0, 0, 0, 0 },
  151. { 1280, 1024, 32, 60, 110000, 1280, 32, 128, 288, 0, 1024, 3, 3, 26, 0, 0, 0, 0, 0 },
  152. { 1600, 1200, 8, 72, 185400, 1600, 32, 128, 320, 0, 1200, 4, 18, 16, 0, 0, 0, 0, 0 },
  153. { 1600, 1200, 16, 72, 185400, 1600, 32, 128, 320, 0, 1200, 4, 18, 16, 0, 0, 0, 0, 0 },
  154. { 1600, 1200, 24, 72, 185400, 1600, 32, 128, 320, 0, 1200, 4, 18, 16, 0, 0, 0, 0, 0 },
  155. { 1600, 1200, 32, 72, 185400, 1600, 32, 128, 320, 0, 1200, 4, 18, 16, 0, 0, 0, 0, 0 },
  156. { 1600, 1200, 8, 60, 156000, 1600, 32, 160, 256, 0, 1200, 10, 8, 48, 0, 0, 0, 0, 0 },
  157. { 1600, 1200, 16, 60, 156000, 1600, 32, 160, 256, 0, 1200, 10, 8, 48, 0, 0, 0, 0, 0 },
  158. { 1600, 1200, 24, 60, 156000, 1600, 32, 160, 256, 0, 1200, 10, 8, 48, 0, 0, 0, 0, 0 },
  159. { 1600, 1200, 32, 60, 156000, 1600, 32, 160, 256, 0, 1200, 10, 8, 48, 0, 0, 0, 0, 0 },
  160. {(word)-1}
  161. };
  162. extern volatile byte _Far* pMgaBaseAddr;
  163. dword crtcTab[NB_CRTC_PARAM];
  164. extern byte iBoard;
  165. extern HwData Hw[NB_BOARD_MAX];
  166. extern char DefaultVidset[];
  167. extern dword ProductMGA[NB_BOARD_MAX];
  168. /* Prototype */
  169. byte detectPatchWithGal(void);
  170. extern char *selectMgaInfoBoard(void);
  171. /****************** definition of exit tab *********************************/
  172. /* */
  173. /*********************** value of registers ********************************/
  174. /* */
  175. /* crtctab[0]= horizontal total */
  176. /* crtctab[1]= horizontal display end */
  177. /* crtctab[2]= horizontal blanking start */
  178. /* crtctab[3]= horizontal blanking end */
  179. /* crtctab[4]= horizontal retrace start */
  180. /* crtctab[5]= horizontal retrace end */
  181. /* crtctab[6]= vertical total */
  182. /* crtctab[7]= overflow */
  183. /* crtctab[8]= preset row scan */
  184. /* crtctab[9]= maximum scanline */
  185. /* crtctab[10]=cursor start */
  186. /* crtctab[11]=cursor end */
  187. /* crtctab[12]=start adrress high */
  188. /* crrctab[13]=start address low */
  189. /* crtctab[14]=cursor position high */
  190. /* crtctab[15]=cursor position low */
  191. /* crtctab[16]=vertical retrace start */
  192. /* crtctab[17]=vertical retrace end */
  193. /* crtctab[18]=vertical display enable end */
  194. /* crtctab[19]=offset */
  195. /* crtctab[20]=underline location */
  196. /* crtctab[21]=vertical blanking start */
  197. /* crtctab[22]=vertical blanking end */
  198. /* crtctab[23]=mode control */
  199. /* crtctab[24]=line compare */
  200. /* crtctab[25]=cpu page select */
  201. /* crtctab[26]=crtc extended address register */
  202. /* crtctab[27]=32k video ram page select register */
  203. /* crtctab[28]=interlace support register */
  204. /* crtctab[29]=automatic line wrap */
  205. /* crtctab[30]=pixel clock */
  206. /* crtctab[31]=video delay */
  207. /* crtctab[32]=Hsync polarite */
  208. /* crtctab[33]=sync delay of dub_ctl register */
  209. /* */
  210. /***************************************************************************/
  211. /************************************************************************/
  212. /*/
  213. * Name: loadVidPar()
  214. *
  215. * synopsis:
  216. *
  217. * bugs:
  218. * designed:
  219. * reviewed:
  220. * last modified:
  221. *
  222. * parameters: (char *vidFile);
  223. * uses:
  224. *
  225. * calls: calculCrtcParam();
  226. *
  227. * returns: mtxOK
  228. * mtxFAIL
  229. *************************************************************************/
  230. bool loadVidPar(dword Zoom, HwModeData *HwMode, HwModeData *DisplayMode)
  231. {
  232. general_info *genInfo;
  233. Vidparm *vidParm;
  234. word TmpRes, ZoomIndex, ZoomVal;
  235. Vidset *pVidset = (Vidset *)0;
  236. word NbVidParam, i;
  237. ZoomVal = (word)(Zoom & 0x0000ffff);
  238. #if ((!defined (WINDOWS_NT)) || (USE_DDC_CODE))
  239. /*********** DDC CODE ****************/
  240. if ( SupportDDC )
  241. {
  242. /*** Find video parameters with the highest refresh rate (see vesavid.h) ***/
  243. pVidset = NULL;
  244. for (i=0; VesaParam[i].DispWidth != (word)-1 ; i++)
  245. {
  246. if( VesaParam[i].DispWidth == DisplayMode->DispWidth && VesaParam[i].Support )
  247. {
  248. pVidset = &(VesaParam[i].VideoSet);
  249. break;
  250. }
  251. }
  252. if( pVidset == NULL )
  253. return(mtxFAIL);
  254. }
  255. /*********** DDC CODE ****************/
  256. else
  257. #endif
  258. {
  259. if (Zoom & 0xff000000)
  260. {
  261. pVidset = NULL;
  262. for (i=0; ResParam[i].DispWidth != (word)-1 ; i++)
  263. {
  264. if ((ResParam[i].DispWidth == DisplayMode->DispWidth) &&
  265. (ResParam[i].PixDepth == DisplayMode->PixWidth) &&
  266. (ResParam[i].RefreshRate == (word)((Zoom >> 24) & 0x000000ff)))
  267. {
  268. pVidset = &(ResParam[i].VideoSet);
  269. break;
  270. }
  271. }
  272. if (pVidset == NULL)
  273. return(mtxFAIL);
  274. }
  275. else
  276. {
  277. switch(Zoom & 0xff)
  278. {
  279. case 2: ZoomIndex = 1; break;
  280. case 4: ZoomIndex = 2; break;
  281. default: ZoomIndex = 0; break;
  282. }
  283. /*** According to Board#, Resolution and PixWidth: Determine pVidset ***/
  284. /* ChT if no paramters for this card then default parameters */
  285. if ( !(genInfo = (general_info *)selectMgaInfoBoard()) ||
  286. (genInfo->NumVidparm < 0)
  287. )
  288. {
  289. #ifdef PRINT
  290. printf("No info for this board in mga.inf file\n");
  291. printf("Please run Setup\n");
  292. #endif
  293. vidParm = (Vidparm *)( DefaultVidset + sizeof(header) + sizeof(general_info));
  294. NbVidParam = ( (general_info *)( DefaultVidset + sizeof(header)))->NumVidparm;
  295. }
  296. else
  297. {
  298. vidParm = (Vidparm *)( (char *)genInfo + sizeof(general_info));
  299. NbVidParam = genInfo->NumVidparm;
  300. }
  301. /* Determine TmpRes for compatibility with spec mga.inf */
  302. switch (DisplayMode->DispWidth)
  303. {
  304. case 640:
  305. if (DisplayMode->DispType & 0x02)
  306. TmpRes = RESNTSC;
  307. else
  308. TmpRes = RES640;
  309. break;
  310. case 768:
  311. TmpRes = RESPAL;
  312. break;
  313. case 800:
  314. TmpRes = RES800;
  315. break;
  316. case 1024:
  317. TmpRes = RES1024;
  318. break;
  319. case 1152:
  320. TmpRes = RES1152;
  321. break;
  322. case 1280:
  323. TmpRes = RES1280;
  324. break;
  325. case 1600:
  326. TmpRes = RES1600;
  327. break;
  328. }
  329. for (i=0; i<NbVidParam; i++)
  330. {
  331. if ( vidParm[i].Resolution == TmpRes &&
  332. vidParm[i].PixWidth == (DisplayMode->PixWidth == 24 ? 32:DisplayMode->PixWidth)
  333. )
  334. {
  335. pVidset = &(vidParm[i].VidsetPar[ZoomIndex]);
  336. break;
  337. }
  338. }
  339. if (!pVidset)
  340. {
  341. #ifdef PRINT
  342. printf("Video parameter not found in mga.inf");
  343. #endif
  344. return mtxFAIL;
  345. }
  346. /*** If there is no video parameter in file mga.inf for zoomming > 1
  347. (the first item = -1) then we keep video parameters for zoom = 1 ***/
  348. if ((pVidset->PixClock == (long)-1) && (ZoomVal > 1))
  349. pVidset = &(vidParm[i].VidsetPar[0]);
  350. }
  351. } /* else - Support DDC */
  352. /*** Transfer video parametres towards array vidtab[] ***/
  353. if (ZoomVal == 0) {
  354. VideoDebugPrint ((0, "Division by zero (ZoomVal == 0) may occur!!"));
  355. }
  356. else
  357. vidtab[0].valeur = (unsigned long)pVidset->PixClock / ZoomVal;
  358. vidtab[1].valeur = (unsigned long)pVidset->HFPorch;
  359. vidtab[2].valeur = (unsigned long)pVidset->HSync;
  360. vidtab[3].valeur = (unsigned long)pVidset->HBPorch;
  361. vidtab[4].valeur = (unsigned long)pVidset->HOvscan;
  362. vidtab[5].valeur = (unsigned long)pVidset->HDisp;
  363. vidtab[6].valeur = (unsigned long)pVidset->VFPorch;
  364. vidtab[7].valeur = (unsigned long)pVidset->VSync;
  365. vidtab[8].valeur = (unsigned long)pVidset->VBPorch;
  366. vidtab[9].valeur = (unsigned long)pVidset->VOvscan;
  367. vidtab[10].valeur = (unsigned long)pVidset->VDisp;
  368. vidtab[11].valeur = DisplayMode->PixWidth;
  369. vidtab[12].valeur = (unsigned long)pVidset->OvscanEnable;
  370. vidtab[13].valeur = (unsigned long)pVidset->InterlaceEnable;
  371. vidtab[14].valeur = Hw[iBoard].YDstOrg; /* Start address */
  372. /* PACK PIXEL, CRTC en 32 bit et TITAN en 8 bits
  373. donc, YDstOrg transfome en byte
  374. */
  375. if (DisplayMode->PixWidth == 24)
  376. vidtab[14].valeur >>= 2;
  377. vidtab[15].valeur = ZoomVal; /* Zoom factor X */
  378. vidtab[16].valeur = ZoomVal; /* Zoom factor Y */
  379. vidtab[17].valeur = HwMode->FbPitch; /* Virtual video pitch */
  380. if ( (DisplayMode->FbPitch != HwMode->FbPitch) || (ZoomVal > 1) ||
  381. (DisplayMode->DispType & 0x01) ||
  382. (ProductMGA[iBoard] == MGA_PCI_4M) )
  383. vidtab[18].valeur = 0; /* ALW Non-Automatic Line Wrap */
  384. else
  385. vidtab[18].valeur = 1;
  386. if( detectPatchWithGal() )
  387. vidtab[18].valeur = 0; /* ALW Non-Automatic Line Wrap */
  388. vidtab[27].valeur = (unsigned long)pVidset->HsyncPol;
  389. vidtab[28].valeur = (unsigned long)pVidset->VsyncPol;
  390. return(mtxOK);
  391. }
  392. /************************************************************************/
  393. /* */
  394. /* Translate the CTRC value in MGA registers value... */
  395. /* */
  396. /************************************************************************/
  397. void calculCrtcParam(void)
  398. {
  399. /*declarations-------------------------------------------------------------*/
  400. unsigned long bs, be;
  401. unsigned long h_front_p,hbskew,hretskew,h_sync,h_back_p,h_over;
  402. unsigned long h_vis,h_total,v_vis,v_over,v_front_p,v_sync,v_back_p,vert_t;
  403. unsigned long start_add_f,virt_vid_p,v_blank;
  404. unsigned char v_blank_e,rline_c,cpu_p,page_s,alw,p_width;
  405. unsigned long mux_rate,ldclk_en_dotclk;
  406. int over_e,hsync_pol,div_1024,int_m;
  407. int vclkhtotal,vclkhvis,vclkhsync,vclkhover,vclkhbackp,vclkhblank,vclkhfrontp;
  408. int x_zoom,y_zoom;
  409. int Cur_e,Crtc_tst_e,cur_e_sk,e_v_int,sel_5ref,crtc_reg_prt,i;
  410. long rep_ge,nb_vclk_hfront_p,nb_vclk_hblank,delai,delai2,delai3,delai4;
  411. /* long gclk; */
  412. long vclk_divisor,pixel_clk;
  413. int flagDelay3=0,flagDelay4=0;
  414. long delayTab[4]={5000,11000,24000,28000}; /* for the value of delays */
  415. long delayTab_A[6]={3000, 4000, 5000,11000,24000,28000}; /* for the value of delays */
  416. /* of register crtc_ctrl of the titan */
  417. /* structure for horizontal blanking end register -------------------------*/
  418. union{
  419. struct {unsigned char pos :5;
  420. unsigned char skew:2;
  421. unsigned char res :1;
  422. }f;
  423. unsigned char all;
  424. } hor_blk_e;
  425. /* structure for horizontal retrace end register----------------------------*/
  426. union{
  427. struct {unsigned char pos :5;
  428. unsigned char skew:2;
  429. unsigned char res :1;
  430. }f;
  431. unsigned char all;
  432. } hor_ret;
  433. /* structure for the calculation of the horizontal blank end position-------*/
  434. /* since the last bit goes in the horizontal retrace end register ----------*/
  435. union{
  436. struct {unsigned char horz_blank_e :5;
  437. unsigned char horz_ret :1;
  438. unsigned char unused :2;
  439. }f;
  440. unsigned char all;
  441. } hor_blk_a;
  442. /* structure for the calculation of the vertical total since the first 7 bit go----*/
  443. /* in the vertical total register and 8 and 9 go in the overflow register-*/
  444. union{
  445. struct {unsigned long vert_t0_7 :8;
  446. unsigned long vert_t8 :1;
  447. unsigned long vert_t9 :1;
  448. unsigned long unused :22;
  449. }f;
  450. unsigned long all;
  451. } v_total;
  452. /* structure for the overflow register--------------------------------------*/
  453. union{
  454. struct {unsigned char r0 :1;
  455. unsigned char r1 :1;
  456. unsigned char r2 :1;
  457. unsigned char r3 :1;
  458. unsigned char r4 :1;
  459. unsigned char r5 :1;
  460. unsigned char r6 :1;
  461. unsigned char r7 :1;
  462. }f;
  463. unsigned char all;
  464. } r_overf;
  465. /* structure for the maximum scan line register-----------------------------*/
  466. union{
  467. struct {unsigned char maxsl :5;
  468. unsigned char v_blank_9 :1;
  469. unsigned char line_c :1;
  470. unsigned char line_doub_e :1;
  471. }f;
  472. unsigned char all;
  473. } r_maxscanl;
  474. /* structure for the cursor start register----------------------------------*/
  475. union{
  476. struct {unsigned char curstart :5;
  477. unsigned char cur_e :1;
  478. unsigned char res :1;
  479. unsigned char crtc_tst_e :1;
  480. }f;
  481. unsigned char all;
  482. } r_cursor_s;
  483. /* structure for the cursor end register------------------------------------*/
  484. union{
  485. struct {unsigned char curend :5;
  486. unsigned char cur_sk :2;
  487. unsigned char res :1;
  488. }f;
  489. unsigned char all;
  490. } r_cursor_e;
  491. /* structure for the calculation of the vertical retrace start register------*/
  492. /* the 7 least significant bits go in the register and the other 2 */
  493. /* go in the overflow register */
  494. union{
  495. struct {unsigned long bit0_7 :8;
  496. unsigned long bit8 :1;
  497. unsigned long bit9 :1;
  498. }f;
  499. unsigned long all;
  500. } rvert_ret_s;
  501. /* structure for the vertical retrace end register -------------------------*/
  502. union{
  503. struct {unsigned char bit0_3 :4;
  504. unsigned char cl :1;
  505. unsigned char e_vi :1;
  506. unsigned char sel_5ref :1;
  507. unsigned char reg_prot :1;
  508. }f;
  509. unsigned char all;
  510. } rvert_ret_e;
  511. /* structure for the calculation of the vertical display enable end---------*/
  512. union{
  513. struct {unsigned long bit0_7 :8;
  514. unsigned long bit8 :1;
  515. unsigned long bit9 :1;
  516. }f;
  517. unsigned long all;
  518. } v_disp_e;
  519. /* structure for the calculation of the vertical blanking start-------------*/
  520. union{
  521. struct {unsigned long bit0_7 :8;
  522. unsigned long bit8 :1;
  523. unsigned long bit9 :1;
  524. }f;
  525. unsigned long all;
  526. } v_blank_s;
  527. /* structure of the mode control register ----------------------------------*/
  528. union{
  529. struct {unsigned char r0 :1;
  530. unsigned char r1 :1;
  531. unsigned char r2 :1;
  532. unsigned char r3 :1;
  533. unsigned char r4 :1;
  534. unsigned char r5 :1;
  535. unsigned char r6 :1;
  536. unsigned char r7 :1;
  537. }f;
  538. unsigned char all;
  539. } r_mode;
  540. /* structure of the crtc extended add register------------------------*/
  541. union{
  542. struct {unsigned char crtcadd :2;
  543. unsigned char crtccur :2;
  544. unsigned char crtc_add_e :1;
  545. unsigned char aux_cl :1;
  546. unsigned char dip_sw_e :1;
  547. unsigned char irq_e :1;
  548. }f;
  549. unsigned char all;
  550. } r_crtc_ext;
  551. /*structure of the interlace support register--------------------------*/
  552. union{
  553. struct {unsigned char crtcadd :4;
  554. unsigned char seq_vid :1;
  555. unsigned char port :1;
  556. unsigned char m_int :1;
  557. unsigned char hr_16 :1;
  558. }f;
  559. unsigned char all;
  560. } r_int_s;
  561. /* gclk=25.0e-9; */
  562. vclk_divisor=VCLK_DIVISOR;
  563. /* variable defined for the entry table-------------------------------- */
  564. pixel_clk =vidtab[0].valeur * 1000;
  565. h_front_p =vidtab[1].valeur;
  566. h_sync =vidtab[2].valeur;
  567. h_back_p =vidtab[3].valeur;
  568. h_over =vidtab[4].valeur;
  569. h_vis =vidtab[5].valeur;
  570. v_front_p =vidtab[6].valeur;
  571. v_sync =vidtab[7].valeur;
  572. v_back_p =vidtab[8].valeur;
  573. v_over =vidtab[9].valeur;
  574. v_vis =vidtab[10].valeur;
  575. p_width =(unsigned char)vidtab[11].valeur;
  576. over_e =vidtab[12].valeur;
  577. int_m =vidtab[13].valeur;
  578. start_add_f =vidtab[14].valeur;
  579. x_zoom =vidtab[15].valeur;
  580. y_zoom =vidtab[16].valeur;
  581. virt_vid_p =vidtab[17].valeur;
  582. alw =(unsigned char)vidtab[18].valeur;
  583. hbskew =vidtab[19].valeur;
  584. hretskew =vidtab[20].valeur;
  585. cur_e_sk =vidtab[21].valeur;
  586. Cur_e =vidtab[22].valeur;
  587. Crtc_tst_e =vidtab[23].valeur;
  588. e_v_int =vidtab[24].valeur;
  589. sel_5ref =vidtab[25].valeur;
  590. crtc_reg_prt =vidtab[26].valeur;
  591. hsync_pol =vidtab[27].valeur;
  592. if (p_width == 24) /* Pack Pixel */
  593. {
  594. h_front_p = (h_front_p * 3 ) >> 2;
  595. h_sync = (h_sync * 3 ) >> 2;
  596. h_back_p = (h_back_p * 3 ) >> 2;
  597. h_over = (h_over * 3 ) >> 2;
  598. h_vis = (h_vis * 3 ) >> 2;
  599. if ( (h_front_p % 32) ) h_front_p += 32 - (h_front_p % 32);
  600. if ( (h_sync % 32) ) h_sync += 32 - (h_sync % 32);
  601. if ( (h_back_p % 32) ) h_back_p += 32 - (h_back_p % 32);
  602. }
  603. /*----------------calculation of reg htotal --------------------------------*/
  604. h_total=h_vis+h_front_p+h_sync+h_back_p;
  605. #ifdef NO_FLOAT
  606. vclkhtotal= (((h_total/VCLK_DIVISOR)*10)+5)/10;
  607. #else
  608. vclkhtotal=h_total/VCLK_DIVISOR+0.5;
  609. #endif
  610. crtcTab[0]=(vclkhtotal/x_zoom)-5;
  611. /* in pack pixel, the number of LCLKs in the total horizontal line
  612. (active + blanked) must be a multiple of the number of LCLKs
  613. per pixel group.
  614. */
  615. if ((p_width == 24) && ((crtcTab[0]+5) % 3 )) /* Pack Pixel */
  616. {
  617. vclkhtotal += (3 - ((crtcTab[0]+5) % 3)) * x_zoom;
  618. crtcTab[0] += 3 - ((crtcTab[0]+5) % 3);
  619. }
  620. /* PACK PIXEL, temporary PATCH */
  621. /*----------------calculation of the horizontal display enable end reg -----*/
  622. #ifdef NO_FLOAT
  623. vclkhvis=(((h_vis/VCLK_DIVISOR)*10)+5)/10;
  624. #else
  625. vclkhvis=h_vis/VCLK_DIVISOR+0.5;
  626. #endif
  627. crtcTab[1]=(vclkhvis/x_zoom)-1;
  628. /*----------------calculation of the horizontal blanking start register-----*/
  629. if(detectPatchWithGal() == 0)
  630. {
  631. if (h_over>0)
  632. {
  633. if (h_over<(VCLK_DIVISOR/2))
  634. vclkhover=1*over_e;
  635. else
  636. #ifdef NO_FLOAT
  637. vclkhover=((((h_over/VCLK_DIVISOR)*10)+5)/10)*over_e;
  638. #else
  639. vclkhover=(h_over/VCLK_DIVISOR+0.5)*over_e;
  640. #endif
  641. }
  642. else
  643. vclkhover=0;
  644. /* Create overscan to bypass a problem in the bank switch */
  645. /* with old revision of TVP3026 */
  646. crtcTab[2]=((vclkhvis+vclkhover)/x_zoom)-1;
  647. }
  648. else
  649. {
  650. crtcTab[2] = crtcTab[1] - 1; /* See DAT #??? */
  651. vclkhover=0;
  652. }
  653. /*-----------calculation of horizontal blanking end register----------------*/
  654. #ifdef NO_FLOAT
  655. vclkhfrontp=(((h_front_p/VCLK_DIVISOR)*10)+5)/10;
  656. vclkhsync=(((h_sync/VCLK_DIVISOR)*10)+5)/10;
  657. vclkhbackp=(((h_back_p/VCLK_DIVISOR)*10)+5)/10;
  658. #else
  659. vclkhfrontp=h_front_p/VCLK_DIVISOR+0.5;
  660. vclkhsync=h_sync/VCLK_DIVISOR+0.5;
  661. vclkhbackp=h_back_p/VCLK_DIVISOR+0.5;
  662. #endif
  663. vclkhblank=vclkhfrontp+vclkhbackp+vclkhsync-(2*vclkhover*over_e);
  664. hor_blk_a.all=((vclkhvis+vclkhover+vclkhblank)/x_zoom)-2;
  665. bs = crtcTab[2];
  666. be = hor_blk_a.all + 1;
  667. if (!((0x40 > bs) & (0x40 < be) ||
  668. (0x80 > bs) & (0x80 < be) ||
  669. (0xc0 > bs) & (0xc0 < be)))
  670. hor_blk_a.all = 0;
  671. if (detectPatchWithGal() == 0)
  672. hor_blk_e.f.pos=hor_blk_a.f.horz_blank_e;
  673. else
  674. hor_blk_e.f.pos=(vclkhtotal/x_zoom)-2;
  675. hor_blk_e.f.skew=(unsigned char)hbskew;
  676. hor_blk_e.f.res=0;
  677. crtcTab[3]=hor_blk_e.all;
  678. /*----------calculation of the horizontal retrace start register----------*/
  679. crtcTab[4]=((vclkhvis+vclkhfrontp)/x_zoom)-1;
  680. /*---------------calculation of the horizontal retrace end register---------*/
  681. hor_ret.f.pos=((vclkhvis+vclkhfrontp+vclkhsync)/x_zoom)-1;
  682. hor_ret.f.skew=(unsigned char)hretskew;
  683. hor_ret.f.res=hor_blk_a.f.horz_ret;
  684. if(detectPatchWithGal() == 0)
  685. hor_ret.f.res=hor_blk_a.f.horz_ret;
  686. else
  687. hor_ret.f.res=(unsigned char)(crtcTab[0]+3) >> 5;
  688. crtcTab[5]=hor_ret.all;
  689. /*--------------calculation of the vertical total register ----------------*/
  690. vert_t=v_vis+v_front_p+v_sync+v_back_p;
  691. div_1024=(vert_t>1023) ? 2 : 1;
  692. v_total.all=vert_t/div_1024-2;
  693. crtcTab[6]=v_total.f.vert_t0_7;
  694. /*------------- preset row scan register -----------------------------------*/
  695. crtcTab[8]=0;
  696. /*----------------calculation of the cursor start register------------------*/
  697. r_cursor_s.f.curstart=0;
  698. r_cursor_s.f.cur_e=~Cur_e;
  699. r_cursor_s.f.res=0;
  700. r_cursor_s.f.crtc_tst_e=(byte)Crtc_tst_e;
  701. crtcTab[10]=r_cursor_s.all;
  702. /*----------------calculation of the cursor end register -------------------*/
  703. r_cursor_e.f.curend=0;
  704. r_cursor_e.f.cur_sk=(byte)cur_e_sk;
  705. r_cursor_e.f.res=0;
  706. crtcTab[11]=r_cursor_e.all;
  707. /*----------------calculation of the add start add high register -----------*/
  708. start_add_f = start_add_f / 8;
  709. crtcTab[12]=start_add_f/256;
  710. /*-----------------calculation of the add start add low register -----------*/
  711. crtcTab[13]=start_add_f;
  712. /*----------------- cursor position high register --------------------------*/
  713. crtcTab[14]=0;
  714. /*----------------- cursor position low register ---------------------------*/
  715. crtcTab[15]=0;
  716. /*------------------calculation of the vertical retrace start register------*/
  717. rvert_ret_s.all=((v_vis+v_front_p)/div_1024)-1;
  718. crtcTab[16]=rvert_ret_s.f.bit0_7;
  719. /*-------------- calculation of the vertical retrace end register ----------*/
  720. rvert_ret_e.f.bit0_3=(unsigned char)(v_vis+v_front_p+v_sync)/div_1024-1;
  721. rvert_ret_e.f.cl=1;
  722. rvert_ret_e.f.e_vi=(byte)e_v_int;
  723. rvert_ret_e.f.sel_5ref=(byte)sel_5ref;
  724. rvert_ret_e.f.reg_prot=(byte)crtc_reg_prt;
  725. crtcTab[17]=rvert_ret_e.all;
  726. /*--------------calculation of the vertical display enable register --------*/
  727. v_disp_e.all=v_vis/div_1024-1;
  728. crtcTab[18]=v_disp_e.f.bit0_7;
  729. /*--------------calculation of the offset register -------------------------*/
  730. crtcTab[19]=((virt_vid_p/VCLK_DIVISOR)+(virt_vid_p*int_m/VCLK_DIVISOR))/2;
  731. if (p_width == 24) /* Pack Pixel */
  732. crtcTab[19] = (crtcTab[19] * 3) >> 2;
  733. /*------------------ under line location register --------------------------*/
  734. crtcTab[20]=0;
  735. /*-----------calculation of the vertical blanking start register ----------*/
  736. v_blank_s.all=(v_vis+(v_over*over_e))/div_1024-1;
  737. crtcTab[21]=v_blank_s.f.bit0_7;
  738. /*-----------calculation of the vertical blanking end register ------------*/
  739. v_blank=v_back_p+v_sync+v_front_p-(2*v_over*over_e);
  740. v_blank_e=(unsigned char)(
  741. (v_vis+(v_over*over_e)+v_blank-((v_over*over_e>0) ? 0 : 1))/div_1024-1);
  742. crtcTab[22]=v_blank_e;
  743. /*-------------- mode control register -------------------------------------*/
  744. r_mode.f.r0=0;
  745. r_mode.f.r1=0;
  746. r_mode.f.r2=div_1024==2 ? 1 : 0 ;
  747. r_mode.f.r3=0;
  748. r_mode.f.r4=0;
  749. r_mode.f.r5=0;
  750. r_mode.f.r6=1;
  751. r_mode.f.r7=1;
  752. crtcTab[23]=r_mode.all;
  753. /*----------- line compare register ----------------------------------------*/
  754. #ifdef WINDOWS_NT
  755. rline_c=0xFF;
  756. #else
  757. rline_c=-1;
  758. #endif
  759. crtcTab[24]=rline_c;
  760. /*-----------calculation of the maximum scan line register -----------------*/
  761. r_maxscanl.f.maxsl=(y_zoom==1) ? 0 : y_zoom-1;
  762. r_maxscanl.f.v_blank_9=(unsigned char)v_blank_s.f.bit9;
  763. r_maxscanl.f.line_c=1;
  764. r_maxscanl.f.line_doub_e=0;
  765. crtcTab[9]=r_maxscanl.all;
  766. /*-------------- overflow register -----------------------------------------*/
  767. r_overf.f.r0=(unsigned char)v_total.f.vert_t8;
  768. r_overf.f.r1=(unsigned char)v_disp_e.f.bit8;
  769. r_overf.f.r2=(unsigned char)rvert_ret_s.f.bit8;
  770. r_overf.f.r3=(unsigned char)v_blank_s.f.bit8;
  771. r_overf.f.r4=1;
  772. r_overf.f.r5=(unsigned char)v_total.f.vert_t9;
  773. r_overf.f.r6=(unsigned char)v_disp_e.f.bit9;
  774. r_overf.f.r7=(unsigned char)rvert_ret_s.f.bit9;
  775. crtcTab[7]=r_overf.all;
  776. /*------------ cpu page select register ------------------------------------*/
  777. cpu_p=0;
  778. crtcTab[25]=cpu_p;
  779. /*------------ crtc extended address register ------------------------------*/
  780. r_crtc_ext.f.crtcadd=0;
  781. r_crtc_ext.f.crtccur=0;
  782. r_crtc_ext.f.crtc_add_e=1;
  783. r_crtc_ext.f.aux_cl=0;
  784. r_crtc_ext.f.dip_sw_e=0;
  785. r_crtc_ext.f.irq_e=1;
  786. crtcTab[26]=r_crtc_ext.all;
  787. /*------------ 32k video ram page select register -----------------*/
  788. page_s=0;
  789. crtcTab[27]=page_s;
  790. /*----------- interlace support register--------------------------*/
  791. r_int_s.f.crtcadd=0;
  792. r_int_s.f.seq_vid=0;
  793. r_int_s.f.port=0;
  794. r_int_s.f.m_int=(byte)int_m;
  795. r_int_s.f.hr_16=0;
  796. crtcTab[28]=r_int_s.all;
  797. /*------------other arguments entered in the table------------------------*/
  798. crtcTab[29]=alw;
  799. crtcTab[30]=pixel_clk;
  800. crtcTab[32]=hsync_pol;
  801. /*************************************************************************/
  802. /* */
  803. /* calculation of video delay for the crtc_ctrl register */
  804. /* */
  805. /*************************************************************************/
  806. rep_ge=(37*25*(pixel_clk/1000000)) / vclk_divisor;
  807. nb_vclk_hfront_p= (h_front_p*1000) / (vclk_divisor * x_zoom);
  808. nb_vclk_hblank=( ((h_front_p+h_sync+h_back_p)*1000) / (VCLK_DIVISOR) / x_zoom);
  809. delai=nb_vclk_hfront_p-1000;
  810. delai2=rep_ge-625;
  811. delai3=nb_vclk_hblank-rep_ge-2000;
  812. delai4=((nb_vclk_hblank+1000)/2)-3000;
  813. /*** BEN ajout ***/
  814. crtcTab[31]=0x00;
  815. if ( (Hw[iBoard].ProductRev >> 4) == 0 ) /* TITAN */
  816. {
  817. for (i=0;i<4;i++)
  818. {
  819. if (delayTab[i]>=delai)
  820. {
  821. if (delayTab[i]>=delai2)
  822. {
  823. if (delayTab[i]<=delai3)
  824. {
  825. /*** The fourth was temporarily eliminated ***/
  826. /* if (delayTab[i]<=delai4) */
  827. /* { */
  828. if (delayTab[i]==28000)
  829. {
  830. crtcTab[31]=0x03;
  831. break;
  832. }
  833. else if (delayTab[i]==24000)
  834. {
  835. crtcTab[31]=0x02;
  836. break;
  837. }
  838. else if (delayTab[i]==11000)
  839. {
  840. crtcTab[31]=0x01;
  841. break;
  842. }
  843. else
  844. {
  845. crtcTab[31]=0x00;
  846. break;
  847. }
  848. /* } */
  849. }
  850. }
  851. }
  852. }
  853. }
  854. else /* 2 video delay add for atlas and I suppose,for newest */
  855. { /* variation of titan they have the same video delay */
  856. for (i=0;i<6;i++)
  857. {
  858. if (delayTab_A[i]>=delai)
  859. {
  860. if (delayTab_A[i]>=delai2)
  861. {
  862. if (delayTab_A[i]<=delai3)
  863. {
  864. if (delayTab_A[i]==28000)
  865. {
  866. crtcTab[31]=0x3;
  867. break;
  868. }
  869. else if (delayTab_A[i]==24000)
  870. {
  871. crtcTab[31]=0x2;
  872. break;
  873. }
  874. else if (delayTab_A[i]==11000)
  875. {
  876. crtcTab[31]=0x1;
  877. break;
  878. }
  879. else if (delayTab_A[i]==5000)
  880. {
  881. crtcTab[31]=0x0;
  882. break;
  883. }
  884. else if (delayTab_A[i]==4000)
  885. {
  886. crtcTab[31]=0x5;
  887. flagDelay4=1;
  888. break;
  889. }
  890. else if (delayTab_A[i]==3000)
  891. {
  892. crtcTab[31]=0x4;
  893. flagDelay3=1;
  894. continue;
  895. }
  896. }
  897. }
  898. }
  899. }
  900. }
  901. if ( flagDelay3 && flagDelay4 )
  902. crtcTab[31]=0x5; /* if we are videodelay 3 and 4 they respect 3 rules */
  903. /***************************************************************************/
  904. /* */
  905. /* calcul hsync delay for the register dub_ctl for the field hsync_del */
  906. /* */
  907. /***************************************************************************/
  908. switch (p_width)
  909. {
  910. case 8:
  911. mux_rate=ldclk_en_dotclk=4;
  912. break;
  913. case 16:
  914. mux_rate=ldclk_en_dotclk=2;
  915. break;
  916. /* PACK PIXEL add cas 24 */
  917. case 32:
  918. case 24:
  919. mux_rate=ldclk_en_dotclk=1;
  920. break;
  921. }
  922. switch (Hw[iBoard].DacType)
  923. {
  924. case BT485:
  925. case PX2085:
  926. /*********************************/
  927. /* For BT485 */
  928. /* */
  929. /* syncdel=1 ldclk expressed in */
  930. /* dotclock + 7 dotclock */
  931. /* --------------------- */
  932. /* (muxrate) */
  933. /* */
  934. /* syncdel= a whole value */
  935. /* and rounded */
  936. /* */
  937. /* muxrate= ( 8bpp=4:1) */
  938. /* = (16bpp=2:1) */
  939. /* = (32bpp=1:1) */
  940. /* */
  941. /* */
  942. /*********************************/
  943. crtcTab[33]=((ldclk_en_dotclk+7)*100/mux_rate+50)/100;
  944. break;
  945. case VIEWPOINT: /*********************************/
  946. /* */
  947. /* For VIEWPOINT */
  948. /* */
  949. /* syncdel=2 ldclk expressed in */
  950. /* dotclock + 14 dotclock*/
  951. /* --------------------- */
  952. /* (muxrate) */
  953. /* */
  954. /* syncdel= a whole value */
  955. /* and rounded */
  956. /* */
  957. /* muxrate= ( 8bpp=4:1) */
  958. /* = (16bpp=2:1) */
  959. /* = (32bpp=1:1) */
  960. /* */
  961. /* */
  962. /*********************************/
  963. crtcTab[33]=02/*((ldclk_en_dotclk*2 + 14)*100/(mux_rate*2)+50)/100*/;
  964. break;
  965. case TVP3026:
  966. crtcTab[33]=0;
  967. break;
  968. #ifdef SCRAP
  969. case BT481:
  970. crtcTab[33]=02;
  971. break;
  972. #endif
  973. default:
  974. crtcTab[33]=02;
  975. break;
  976. }
  977. }
  978. /************************************************************************/
  979. /*/
  980. * Name: getAthenaRevision
  981. *
  982. * synopsis: try to find the silicone revision of athena chip
  983. *
  984. *
  985. * returns: revision : -1 - Unknow or not a athena chip
  986. */
  987. /* --------------------------- D.A.T. GEN0?? ---------------------------*/
  988. /* Strap nomuxes block8 tram Athena rev| Type de ram */
  989. /* 0 0 0 2 |4Mbit (8-bit blk node) */
  990. /* 0 0 1 2 | " " " */
  991. /* 0 1 0 2 |4Mbit (4-bit blk node) */
  992. /* 0 1 1 1 |2Mbit (4-bit blk node) */
  993. /* | */
  994. /* 1 0 0 1 |4Mbit (8-bit blk node) */
  995. /* 1 0 1 1 | " " " */
  996. /* 1 1 0 1 |4Mbit (4-bit blk node) */
  997. /* 1 1 1 2 |2Mbit (4-bit blk node) */
  998. /*----------------------------------------------------------------------*/
  999. word getAthenaRevision(dword dst0, dword dst1)
  1000. {
  1001. byte _block8, _tram, _nomuxes;
  1002. word rev = 2;
  1003. _block8 = (dst0 & TITAN_DST0_BLKMODE_M) != 0;
  1004. _tram = (dst1 & TITAN_DST1_TRAM_M) != 0;
  1005. _nomuxes = (dst1 & TITAN_DST1_NOMUXES_M) != 0;
  1006. /* check if athena chip */
  1007. if( ((Hw[iBoard].ProductRev >> 4) & 0x0000000f) != ATHENA_CHIP)
  1008. return (word) -1;
  1009. if ( Hw[iBoard].DacType == TVP3026 )
  1010. {
  1011. if (_block8 && _tram) /* IMP+ /P */
  1012. {
  1013. rev = _nomuxes ? 2 : 1;
  1014. }
  1015. else
  1016. {
  1017. rev = _nomuxes ? 1 : 2;
  1018. }
  1019. }
  1020. else
  1021. {
  1022. if ( Hw[iBoard].VGAEnable )
  1023. rev = pciBoardInfo & PCI_FLAG_ATHENA_REV1 ? 1 : 2;
  1024. else
  1025. rev = 2;
  1026. }
  1027. return rev;
  1028. }
  1029. /************************************************************************/
  1030. /*/
  1031. * Name: detectPatchWithGal
  1032. *
  1033. * synopsis: Detect if the board has the patch that fixes the bug
  1034. * with SOE (See DAT on missing pixel in the bank switch).
  1035. *
  1036. *
  1037. * returns: byte : mtxOK - the board has the patch.
  1038. * mtxFAIL - it hasn't
  1039. */
  1040. byte detectPatchWithGal(void)
  1041. {
  1042. byte result=0;
  1043. dword TramDword;
  1044. /* general_info *genInfo; */
  1045. dword Dst0, Dst1;
  1046. dword InfoHardware;
  1047. if ( Hw[iBoard].DacType != TVP3026 )
  1048. return mtxFAIL; /* GAL in use on TVP3026 only */
  1049. if ((Hw[iBoard].ProductType & 0x0f) == BOARD_MGA_RESERVED)
  1050. return mtxFAIL; /* Always rev 2 */
  1051. /*------ Strap added in ATHENA For max clock dac support ----*/
  1052. GetMGAConfiguration(pMgaBaseAddr, &Dst0, &Dst1, &InfoHardware);
  1053. if ( Dst1 & TITAN_DST1_ABOVE1280_M )
  1054. return mtxFAIL; /* no gal on this board */
  1055. if ( getAthenaRevision(Dst0, Dst1) == 2)
  1056. return mtxFAIL; /* No gal on rev 2 */
  1057. mgaReadDWORD(*(pMgaBaseAddr+TITAN_OFFSET+TITAN_OPMODE),TramDword);
  1058. TramDword &= TITAN_TRAM_M;
  1059. /** The GAL is present on Rev2 or higher board with bit TRAM at 0 and
  1060. on board with bit TRAM at 1 (/P4) **/
  1061. if( (((Hw[iBoard].ProductRev & 0xf) >= 2) && !TramDword) || TramDword)
  1062. result = mtxOK;
  1063. else
  1064. result = mtxFAIL;
  1065. return(result);
  1066. }
  1067. word ConvBitToFreq (word BitFreq)
  1068. {
  1069. word result;
  1070. // bit 0: 43 Hz interlaced
  1071. // bit 1: 56 Hz
  1072. // bit 2: 60 Hz
  1073. // bit 3: 66 Hz
  1074. // bit 4: 70 Hz
  1075. // bit 5: 72 Hz
  1076. // bit 6: 75 Hz
  1077. // bit 7: 76 Hz
  1078. // bit 8: 80 Hz
  1079. // bit 9: 85 Hz
  1080. // bit 10: 90 Hz
  1081. // bit 11: 100 Hz
  1082. // bit 12: 120 Hz
  1083. switch (BitFreq)
  1084. {
  1085. case 0:
  1086. result = 43;
  1087. break;
  1088. case 1:
  1089. result = 56;
  1090. break;
  1091. case 2:
  1092. result = 60;
  1093. break;
  1094. case 3:
  1095. result = 66;
  1096. break;
  1097. case 4:
  1098. result = 70;
  1099. break;
  1100. case 5:
  1101. result = 72;
  1102. break;
  1103. case 6:
  1104. result = 75;
  1105. break;
  1106. case 7:
  1107. result = 76;
  1108. break;
  1109. case 8:
  1110. result = 80;
  1111. break;
  1112. case 9:
  1113. result = 85;
  1114. break;
  1115. case 10:
  1116. result = 90;
  1117. break;
  1118. case 11:
  1119. result = 100;
  1120. break;
  1121. case 12:
  1122. result = 120;
  1123. default:
  1124. result = 0;
  1125. break;
  1126. }
  1127. return(result);
  1128. }