init.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:159k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/sis/init.c,v 1.3 2002/24/04 01:16:16 dawes Exp $ */
  2. /*
  3.  * Mode switching code (CRT1 section) for SiS 300/540/630/730/315/550/650/740
  4.  * (Universal module for Linux kernel framebuffer and XFree86 4.x)
  5.  *
  6.  * Assembler-To-C translation
  7.  * Parts Copyright 2002 by Thomas Winischhofer <thomas@winischhofer.net>
  8.  *
  9.  * Based on BIOS
  10.  *     1.10.07 (1.10a) for SiS650/LVDS+CH7019
  11.  *     1.07.1b for SiS650/301(B/LV)
  12.  *     2.04.50 (I) and 2.04.5c (II), 2.07a for SiS630/301(B)
  13.  *     2.02.3b, 2.03.02 and 2.04.5c for 630/LVDS/LVDS+CH7005
  14.  *     1.09b for 315/301(B)
  15.  *
  16.  * Permission to use, copy, modify, distribute, and sell this software and its
  17.  * documentation for any purpose is hereby granted without fee, provided that
  18.  * the above copyright notice appear in all copies and that both that
  19.  * copyright notice and this permission notice appear in supporting
  20.  * documentation, and that the name of the copyright holder not be used in
  21.  * advertising or publicity pertaining to distribution of the software without
  22.  * specific, written prior permission.  The copyright holder makes no representations
  23.  * about the suitability of this software for any purpose.  It is provided
  24.  * "as is" without express or implied warranty.
  25.  *
  26.  * THE COPYRIGHT HOLDER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  27.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  28.  * EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  29.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  30.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  31.  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  32.  * PERFORMANCE OF THIS SOFTWARE.
  33.  *
  34.  */
  35. #include "init.h"
  36. #ifdef SIS300
  37. #include "300vtbl.h"
  38. #endif
  39. #ifdef SIS315H
  40. #include "310vtbl.h"
  41. #endif
  42. #ifdef LINUX_XF86
  43. BOOLEAN SiSBIOSSetMode(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,
  44.                        ScrnInfoPtr pScrn, DisplayModePtr mode);
  45. #ifdef SISDUALHEAD /* TW: For dual head */
  46. BOOLEAN SiSBIOSSetModeCRT1(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,
  47.                        ScrnInfoPtr pScrn, DisplayModePtr mode);
  48. BOOLEAN SiSBIOSSetModeCRT2(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,
  49.                        ScrnInfoPtr pScrn, DisplayModePtr mode);
  50. #endif /* dual head */
  51. #endif /* linux_xf86 */
  52. #ifdef LINUXBIOS
  53. BOOLEAN SiSInit(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension);
  54. #endif
  55. #ifdef LINUX_XF86
  56. BOOLEAN SiSSetMode(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,
  57.                    ScrnInfoPtr pScrn,USHORT ModeNo, BOOLEAN dosetpitch);
  58. #else
  59. BOOLEAN SiSSetMode(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,
  60.                    USHORT ModeNo);
  61. #endif
  62. #if defined(ALLOC_PRAGMA)
  63. #pragma alloc_text(PAGE,SiSSetMode)
  64. #pragma alloc_text(PAGE,SiSInit)
  65. #endif
  66. void DelaySeconds(int seconds);
  67. void DebugCode(SiS_Private *SiS_Pr, UCHAR code);
  68. #ifdef LINUX_XF86
  69. /* TW: Mode table for X driver */
  70. const UShort  ModeIndex_320x480[]      = {0x5A, 0x5B, 0x00, 0x00};  /* DSTN/FSTN */
  71. const UShort  ModeIndex_512x384[]      = {0x52, 0x58, 0x00, 0x5c};
  72. const UShort  ModeIndex_640x480[]      = {0x2E, 0x44, 0x00, 0x62};
  73. const UShort  ModeIndex_720x480[]      = {0x31, 0x33, 0x00, 0x35};
  74. const UShort  ModeIndex_720x576[]      = {0x32, 0x34, 0x00, 0x36};
  75. const UShort  ModeIndex_800x480[]      = {0x70, 0x7a, 0x00, 0x76};  /* 310/325 series only */
  76. const UShort  ModeIndex_800x600[]      = {0x30, 0x47, 0x00, 0x63};
  77. const UShort  ModeIndex_1024x768[]     = {0x38, 0x4A, 0x00, 0x64};
  78. const UShort  ModeIndex_1024x576[]     = {0x71, 0x74, 0x00, 0x77};  /* 310/325 series only */
  79. const UShort  ModeIndex_1024x600[]     = {0x20, 0x21, 0x00, 0x22};  /* 300 series only */
  80. const UShort  ModeIndex_1280x1024[]    = {0x3A, 0x4D, 0x00, 0x65};
  81. const UShort  ModeIndex_300_1280x960[] = {0x6e, 0x6f, 0x00, 0x7b};
  82. const UShort  ModeIndex_310_1280x960[] = {0x7C, 0x7D, 0x00, 0x7E};
  83. const UShort  ModeIndex_1152x768[]     = {0x23, 0x24, 0x00, 0x25};  /* 300 series only */
  84. const UShort  ModeIndex_1280x768[]     = {0x23, 0x24, 0x00, 0x25};  /* 310/325 series only */
  85. const UShort  ModeIndex_1280x720[]     = {0x79, 0x75, 0x00, 0x78};  /* 310/325 series only */
  86. const UShort  ModeIndex_1400x1050[]    = {0x26, 0x27, 0x00, 0x28};  /* 310/325 series only */
  87. const UShort  ModeIndex_1600x1200[]    = {0x3C, 0x3D, 0x00, 0x66};
  88. const UShort  ModeIndex_1920x1440[]    = {0x68, 0x69, 0x00, 0x6B};
  89. const UShort  ModeIndex_2048x1536[]    = {0x6c, 0x6d, 0x00, 0x6e};  /* 310/325 series only */
  90. #endif
  91. void
  92. DelaySeconds(int seconds)
  93. {
  94.   int i;
  95. #ifdef WIN2000
  96.   int j;
  97. #endif
  98.   for (i=0;i<seconds;i++) {
  99. #ifdef TC
  100.     delay(1000);
  101. #endif
  102. #ifdef WIN2000
  103.     for (j=0;j<20000;j++)
  104.       VideoPortStallExecution(50);
  105. #endif
  106. #ifdef WINCE_HEADER
  107. #endif
  108. #ifdef LINUX_KERNEL
  109. #endif
  110.   }
  111. }
  112. void
  113. DebugCode(SiS_Private *SiS_Pr, UCHAR code)
  114. {
  115.   OutPortByte(0x80, code);
  116.   DelaySeconds(0x3);
  117. }
  118. #ifdef SIS300
  119. void
  120. InitTo300Pointer(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension)
  121. {
  122.    SiS_Pr->SiS_SModeIDTable  = (SiS_StStruct *)SiS300_SModeIDTable;
  123.    SiS_Pr->SiS_VBModeIDTable = (SiS_VBModeStruct *)SiS300_VBModeIDTable;
  124.    SiS_Pr->SiS_StandTable    = (SiS_StandTableStruct *)SiS300_StandTable;
  125.    SiS_Pr->SiS_EModeIDTable  = (SiS_ExtStruct *)SiS300_EModeIDTable;
  126.    SiS_Pr->SiS_RefIndex      = (SiS_Ext2Struct *)SiS300_RefIndex;
  127.    SiS_Pr->SiS_CRT1Table     = (SiS_CRT1TableStruct *)SiS300_CRT1Table;
  128.    if(HwDeviceExtension->jChipType == SIS_300) {
  129.       SiS_Pr->SiS_MCLKData_0    = (SiS_MCLKDataStruct *)SiS300_MCLKData_300; /* 300 */
  130.    } else {
  131.       SiS_Pr->SiS_MCLKData_0    = (SiS_MCLKDataStruct *)SiS300_MCLKData_630; /* 630 */
  132.    }
  133.    SiS_Pr->SiS_ECLKData      = (SiS_ECLKDataStruct *)SiS300_ECLKData;
  134.    SiS_Pr->SiS_VCLKData      = (SiS_VCLKDataStruct *)SiS300_VCLKData;
  135.    SiS_Pr->SiS_VBVCLKData    = (SiS_VBVCLKDataStruct *)SiS300_VCLKData;
  136.    SiS_Pr->SiS_ScreenOffset  = SiS300_ScreenOffset;
  137.    SiS_Pr->SiS_StResInfo     = (SiS_StResInfoStruct *)SiS300_StResInfo;
  138.    SiS_Pr->SiS_ModeResInfo   = (SiS_ModeResInfoStruct *)SiS300_ModeResInfo;
  139.    SiS_Pr->pSiS_OutputSelect = &SiS300_OutputSelect;
  140.    SiS_Pr->pSiS_SoftSetting  = &SiS300_SoftSetting;
  141.    SiS_Pr->SiS_SR15  = SiS300_SR15;
  142. #ifndef LINUX_XF86
  143.    SiS_Pr->pSiS_SR07 = &SiS300_SR07;
  144.    SiS_Pr->SiS_CR40  = SiS300_CR40;
  145.    SiS_Pr->SiS_CR49  = SiS300_CR49;
  146.    SiS_Pr->pSiS_SR1F = &SiS300_SR1F;
  147.    SiS_Pr->pSiS_SR21 = &SiS300_SR21;
  148.    SiS_Pr->pSiS_SR22 = &SiS300_SR22;
  149.    SiS_Pr->pSiS_SR23 = &SiS300_SR23;
  150.    SiS_Pr->pSiS_SR24 = &SiS300_SR24;
  151.    SiS_Pr->SiS_SR25  = SiS300_SR25;
  152.    SiS_Pr->pSiS_SR31 = &SiS300_SR31;
  153.    SiS_Pr->pSiS_SR32 = &SiS300_SR32;
  154.    SiS_Pr->pSiS_SR33 = &SiS300_SR33;
  155.    SiS_Pr->pSiS_CRT2Data_1_2  = &SiS300_CRT2Data_1_2;
  156.    SiS_Pr->pSiS_CRT2Data_4_D  = &SiS300_CRT2Data_4_D;
  157.    SiS_Pr->pSiS_CRT2Data_4_E  = &SiS300_CRT2Data_4_E;
  158.    SiS_Pr->pSiS_CRT2Data_4_10 = &SiS300_CRT2Data_4_10;
  159.    SiS_Pr->pSiS_RGBSenseData    = &SiS300_RGBSenseData;
  160.    SiS_Pr->pSiS_VideoSenseData  = &SiS300_VideoSenseData;
  161.    SiS_Pr->pSiS_YCSenseData     = &SiS300_YCSenseData;
  162.    SiS_Pr->pSiS_RGBSenseData2   = &SiS300_RGBSenseData2;
  163.    SiS_Pr->pSiS_VideoSenseData2 = &SiS300_VideoSenseData2;
  164.    SiS_Pr->pSiS_YCSenseData2    = &SiS300_YCSenseData2;
  165. #endif
  166.    SiS_Pr->SiS_NTSCPhase  = SiS300_NTSCPhase;
  167.    SiS_Pr->SiS_PALPhase   = SiS300_PALPhase;
  168.    SiS_Pr->SiS_NTSCPhase2 = SiS300_NTSCPhase2;
  169.    SiS_Pr->SiS_PALPhase2  = SiS300_PALPhase2;
  170.    SiS_Pr->SiS_PALMPhase  = SiS300_PALMPhase;
  171.    SiS_Pr->SiS_PALNPhase  = SiS300_PALNPhase;
  172.    SiS_Pr->SiS_PALMPhase2 = SiS300_PALMPhase2;
  173.    SiS_Pr->SiS_PALNPhase2 = SiS300_PALNPhase2;
  174.    SiS_Pr->SiS_StLCD1024x768Data    = (SiS_LCDDataStruct *)SiS300_StLCD1024x768Data;
  175.    SiS_Pr->SiS_ExtLCD1024x768Data   = (SiS_LCDDataStruct *)SiS300_ExtLCD1024x768Data;
  176.    SiS_Pr->SiS_St2LCD1024x768Data   = (SiS_LCDDataStruct *)SiS300_St2LCD1024x768Data;
  177.    SiS_Pr->SiS_StLCD1280x1024Data   = (SiS_LCDDataStruct *)SiS300_StLCD1280x1024Data;
  178.    SiS_Pr->SiS_ExtLCD1280x1024Data  = (SiS_LCDDataStruct *)SiS300_ExtLCD1280x1024Data;
  179.    SiS_Pr->SiS_St2LCD1280x1024Data  = (SiS_LCDDataStruct *)SiS300_St2LCD1280x1024Data;
  180.    SiS_Pr->SiS_NoScaleData1024x768  = (SiS_LCDDataStruct *)SiS300_NoScaleData1024x768;
  181.    SiS_Pr->SiS_NoScaleData1280x1024 = (SiS_LCDDataStruct *)SiS300_NoScaleData1280x1024;
  182.    SiS_Pr->SiS_LCD1280x960Data      = (SiS_LCDDataStruct *)SiS300_LCD1280x960Data;
  183.    SiS_Pr->SiS_ExtLCD1400x1050Data  = (SiS_LCDDataStruct *)SiS300_ExtLCD1400x1050Data;
  184.    SiS_Pr->SiS_ExtLCD1600x1200Data  = (SiS_LCDDataStruct *)SiS300_ExtLCD1600x1200Data;
  185.    SiS_Pr->SiS_StLCD1400x1050Data   = (SiS_LCDDataStruct *)SiS300_StLCD1400x1050Data;
  186.    SiS_Pr->SiS_StLCD1600x1200Data   = (SiS_LCDDataStruct *)SiS300_StLCD1600x1200Data;
  187.    SiS_Pr->SiS_NoScaleData1400x1050 = (SiS_LCDDataStruct *)SiS300_NoScaleData1400x1050;
  188.    SiS_Pr->SiS_NoScaleData1600x1200 = (SiS_LCDDataStruct *)SiS300_NoScaleData1600x1200;
  189.    SiS_Pr->SiS_StPALData   = (SiS_TVDataStruct *)SiS300_StPALData;
  190.    SiS_Pr->SiS_ExtPALData  = (SiS_TVDataStruct *)SiS300_ExtPALData;
  191.    SiS_Pr->SiS_StNTSCData  = (SiS_TVDataStruct *)SiS300_StNTSCData;
  192.    SiS_Pr->SiS_ExtNTSCData = (SiS_TVDataStruct *)SiS300_ExtNTSCData;
  193. #ifdef oldHV
  194.    SiS_Pr->SiS_St1HiTVData = (SiS_TVDataStruct *)SiS300_St1HiTVData;
  195.    SiS_Pr->SiS_St2HiTVData = (SiS_TVDataStruct *)SiS300_St2HiTVData;
  196.    SiS_Pr->SiS_ExtHiTVData = (SiS_TVDataStruct *)SiS300_ExtHiTVData;
  197. #endif
  198.    SiS_Pr->SiS_NTSCTiming     = SiS300_NTSCTiming;
  199.    SiS_Pr->SiS_PALTiming      = SiS300_PALTiming;
  200. #ifdef oldHV
  201.    SiS_Pr->SiS_HiTVSt1Timing  = SiS300_HiTVSt1Timing;
  202.    SiS_Pr->SiS_HiTVSt2Timing  = SiS300_HiTVSt2Timing;
  203.    SiS_Pr->SiS_HiTVTextTiming = SiS300_HiTVTextTiming;
  204.    SiS_Pr->SiS_HiTVGroup3Data = SiS300_HiTVGroup3Data;
  205.    SiS_Pr->SiS_HiTVGroup3Simu = SiS300_HiTVGroup3Simu;
  206.    SiS_Pr->SiS_HiTVGroup3Text = SiS300_HiTVGroup3Text;
  207. #endif
  208.    SiS_Pr->SiS_PanelDelayTbl     = (SiS_PanelDelayTblStruct *)SiS300_PanelDelayTbl;
  209.    SiS_Pr->SiS_PanelDelayTblLVDS = (SiS_PanelDelayTblStruct *)SiS300_PanelDelayTblLVDS;
  210.    SiS_Pr->SiS_LVDS800x600Data_1   = (SiS_LVDSDataStruct *)SiS300_LVDS800x600Data_1;
  211.    SiS_Pr->SiS_LVDS800x600Data_2   = (SiS_LVDSDataStruct *)SiS300_LVDS800x600Data_2;
  212.    SiS_Pr->SiS_LVDS1024x768Data_1  = (SiS_LVDSDataStruct *)SiS300_LVDS1024x768Data_1;
  213.    SiS_Pr->SiS_LVDS1024x768Data_2  = (SiS_LVDSDataStruct *)SiS300_LVDS1024x768Data_2;
  214.    SiS_Pr->SiS_LVDS1280x1024Data_1 = (SiS_LVDSDataStruct *)SiS300_LVDS1280x1024Data_1;
  215.    SiS_Pr->SiS_LVDS1280x1024Data_2 = (SiS_LVDSDataStruct *)SiS300_LVDS1280x1024Data_2;
  216.    SiS_Pr->SiS_LVDS1280x960Data_1  = (SiS_LVDSDataStruct *)SiS300_LVDS1280x1024Data_1;
  217.    SiS_Pr->SiS_LVDS1280x960Data_2  = (SiS_LVDSDataStruct *)SiS300_LVDS1280x1024Data_2;
  218.    SiS_Pr->SiS_LVDS1400x1050Data_1 = (SiS_LVDSDataStruct *)SiS300_LVDS1400x1050Data_1;
  219.    SiS_Pr->SiS_LVDS1400x1050Data_2 = (SiS_LVDSDataStruct *)SiS300_LVDS1400x1050Data_2;
  220.    SiS_Pr->SiS_LVDS1024x600Data_1  = (SiS_LVDSDataStruct *)SiS300_LVDS1024x600Data_1;
  221.    SiS_Pr->SiS_LVDS1024x600Data_2  = (SiS_LVDSDataStruct *)SiS300_LVDS1024x600Data_2;
  222.    SiS_Pr->SiS_LVDS1152x768Data_1  = (SiS_LVDSDataStruct *)SiS300_LVDS1152x768Data_1;
  223.    SiS_Pr->SiS_LVDS1152x768Data_2  = (SiS_LVDSDataStruct *)SiS300_LVDS1152x768Data_2;
  224.    SiS_Pr->SiS_LVDSXXXxXXXData_1   = (SiS_LVDSDataStruct *)SiS300_LVDSXXXxXXXData_1;
  225.    SiS_Pr->SiS_LVDS320x480Data_1   = (SiS_LVDSDataStruct *)SiS300_LVDS320x480Data_1;
  226.    SiS_Pr->SiS_LVDS640x480Data_1   = (SiS_LVDSDataStruct *)SiS300_LVDS640x480Data_1;
  227.    SiS_Pr->SiS_LCDA1400x1050Data_1 = (SiS_LVDSDataStruct *)SiS300_LCDA1400x1050Data_1;
  228.    SiS_Pr->SiS_LCDA1400x1050Data_2 = (SiS_LVDSDataStruct *)SiS300_LCDA1400x1050Data_2;
  229.    SiS_Pr->SiS_LCDA1600x1200Data_1 = (SiS_LVDSDataStruct *)SiS300_LCDA1600x1200Data_1;
  230.    SiS_Pr->SiS_LCDA1600x1200Data_2 = (SiS_LVDSDataStruct *)SiS300_LCDA1600x1200Data_2;
  231.    SiS_Pr->SiS_CHTVUNTSCData = (SiS_LVDSDataStruct *)SiS300_CHTVUNTSCData;
  232.    SiS_Pr->SiS_CHTVONTSCData = (SiS_LVDSDataStruct *)SiS300_CHTVONTSCData;
  233.    SiS_Pr->SiS_CHTVUPALData  = (SiS_LVDSDataStruct *)SiS300_CHTVUPALData;
  234.    SiS_Pr->SiS_CHTVOPALData  = (SiS_LVDSDataStruct *)SiS300_CHTVOPALData;
  235.    SiS_Pr->SiS_PanelType00_1 = (SiS_LVDSDesStruct *)SiS300_PanelType00_1;
  236.    SiS_Pr->SiS_PanelType01_1 = (SiS_LVDSDesStruct *)SiS300_PanelType01_1;
  237.    SiS_Pr->SiS_PanelType02_1 = (SiS_LVDSDesStruct *)SiS300_PanelType02_1;
  238.    SiS_Pr->SiS_PanelType03_1 = (SiS_LVDSDesStruct *)SiS300_PanelType03_1;
  239.    SiS_Pr->SiS_PanelType04_1 = (SiS_LVDSDesStruct *)SiS300_PanelType04_1;
  240.    SiS_Pr->SiS_PanelType05_1 = (SiS_LVDSDesStruct *)SiS300_PanelType05_1;
  241.    SiS_Pr->SiS_PanelType06_1 = (SiS_LVDSDesStruct *)SiS300_PanelType06_1;
  242.    SiS_Pr->SiS_PanelType07_1 = (SiS_LVDSDesStruct *)SiS300_PanelType07_1;
  243.    SiS_Pr->SiS_PanelType08_1 = (SiS_LVDSDesStruct *)SiS300_PanelType08_1;
  244.    SiS_Pr->SiS_PanelType09_1 = (SiS_LVDSDesStruct *)SiS300_PanelType09_1;
  245.    SiS_Pr->SiS_PanelType0a_1 = (SiS_LVDSDesStruct *)SiS300_PanelType0a_1;
  246.    SiS_Pr->SiS_PanelType0b_1 = (SiS_LVDSDesStruct *)SiS300_PanelType0b_1;
  247.    SiS_Pr->SiS_PanelType0c_1 = (SiS_LVDSDesStruct *)SiS300_PanelType0c_1;
  248.    SiS_Pr->SiS_PanelType0d_1 = (SiS_LVDSDesStruct *)SiS300_PanelType0d_1;
  249.    SiS_Pr->SiS_PanelType0e_1 = (SiS_LVDSDesStruct *)SiS300_PanelType0e_1;
  250.    SiS_Pr->SiS_PanelType0f_1 = (SiS_LVDSDesStruct *)SiS300_PanelType0f_1;
  251.    SiS_Pr->SiS_PanelType00_2 = (SiS_LVDSDesStruct *)SiS300_PanelType00_2;
  252.    SiS_Pr->SiS_PanelType01_2 = (SiS_LVDSDesStruct *)SiS300_PanelType01_2;
  253.    SiS_Pr->SiS_PanelType02_2 = (SiS_LVDSDesStruct *)SiS300_PanelType02_2;
  254.    SiS_Pr->SiS_PanelType03_2 = (SiS_LVDSDesStruct *)SiS300_PanelType03_2;
  255.    SiS_Pr->SiS_PanelType04_2 = (SiS_LVDSDesStruct *)SiS300_PanelType04_2;
  256.    SiS_Pr->SiS_PanelType05_2 = (SiS_LVDSDesStruct *)SiS300_PanelType05_2;
  257.    SiS_Pr->SiS_PanelType06_2 = (SiS_LVDSDesStruct *)SiS300_PanelType06_2;
  258.    SiS_Pr->SiS_PanelType07_2 = (SiS_LVDSDesStruct *)SiS300_PanelType07_2;
  259.    SiS_Pr->SiS_PanelType08_2 = (SiS_LVDSDesStruct *)SiS300_PanelType08_2;
  260.    SiS_Pr->SiS_PanelType09_2 = (SiS_LVDSDesStruct *)SiS300_PanelType09_2;
  261.    SiS_Pr->SiS_PanelType0a_2 = (SiS_LVDSDesStruct *)SiS300_PanelType0a_2;
  262.    SiS_Pr->SiS_PanelType0b_2 = (SiS_LVDSDesStruct *)SiS300_PanelType0b_2;
  263.    SiS_Pr->SiS_PanelType0c_2 = (SiS_LVDSDesStruct *)SiS300_PanelType0c_2;
  264.    SiS_Pr->SiS_PanelType0d_2 = (SiS_LVDSDesStruct *)SiS300_PanelType0d_2;
  265.    SiS_Pr->SiS_PanelType0e_2 = (SiS_LVDSDesStruct *)SiS300_PanelType0e_2;
  266.    SiS_Pr->SiS_PanelType0f_2 = (SiS_LVDSDesStruct *)SiS300_PanelType0f_2;
  267.    SiS_Pr->SiS_CHTVUNTSCDesData = (SiS_LVDSDesStruct *)SiS300_CHTVUNTSCDesData;
  268.    SiS_Pr->SiS_CHTVONTSCDesData = (SiS_LVDSDesStruct *)SiS300_CHTVONTSCDesData;
  269.    SiS_Pr->SiS_CHTVUPALDesData  = (SiS_LVDSDesStruct *)SiS300_CHTVUPALDesData;
  270.    SiS_Pr->SiS_CHTVOPALDesData  = (SiS_LVDSDesStruct *)SiS300_CHTVOPALDesData;
  271.    SiS_Pr->SiS_LVDSCRT1800x600_1     = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT1800x600_1;
  272.    SiS_Pr->SiS_LVDSCRT11024x768_1    = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT11024x768_1;
  273.    SiS_Pr->SiS_LVDSCRT11280x1024_1   = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT11280x1024_1;
  274.    SiS_Pr->SiS_LVDSCRT11024x600_1    = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT11024x600_1;
  275.    SiS_Pr->SiS_LVDSCRT11152x768_1    = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT11152x768_1;
  276.    SiS_Pr->SiS_LVDSCRT1800x600_1_H   = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT1800x600_1_H;
  277.    SiS_Pr->SiS_LVDSCRT11024x768_1_H  = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT11024x768_1_H;
  278.    SiS_Pr->SiS_LVDSCRT11280x1024_1_H = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT11280x1024_1_H;
  279.    SiS_Pr->SiS_LVDSCRT11024x600_1_H  = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT11024x600_1_H;
  280.    SiS_Pr->SiS_LVDSCRT11152x768_1_H  = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT11152x768_1_H;
  281.    SiS_Pr->SiS_LVDSCRT1800x600_2     = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT1800x600_2;
  282.    SiS_Pr->SiS_LVDSCRT11024x768_2    = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT11024x768_2;
  283.    SiS_Pr->SiS_LVDSCRT11280x1024_2   = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT11280x1024_2;
  284.    SiS_Pr->SiS_LVDSCRT11024x600_2    = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT11024x600_2;
  285.    SiS_Pr->SiS_LVDSCRT11152x768_2    = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT11152x768_2;
  286.    SiS_Pr->SiS_LVDSCRT1800x600_2_H   = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT1800x600_2_H;
  287.    SiS_Pr->SiS_LVDSCRT11024x768_2_H  = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT11024x768_2_H;
  288.    SiS_Pr->SiS_LVDSCRT11280x1024_2_H = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT11280x1024_2_H;
  289.    SiS_Pr->SiS_LVDSCRT11024x600_2_H  = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT11024x600_2_H;
  290.    SiS_Pr->SiS_LVDSCRT11152x768_2_H  = (SiS_LVDSCRT1DataStruct *)SiS300_LVDSCRT11152x768_2_H;
  291.    SiS_Pr->SiS_CHTVCRT1UNTSC = (SiS_LVDSCRT1DataStruct *)SiS300_CHTVCRT1UNTSC;
  292.    SiS_Pr->SiS_CHTVCRT1ONTSC = (SiS_LVDSCRT1DataStruct *)SiS300_CHTVCRT1ONTSC;
  293.    SiS_Pr->SiS_CHTVCRT1UPAL  = (SiS_LVDSCRT1DataStruct *)SiS300_CHTVCRT1UPAL;
  294.    SiS_Pr->SiS_CHTVCRT1OPAL  = (SiS_LVDSCRT1DataStruct *)SiS300_CHTVCRT1OPAL;
  295.    SiS_Pr->SiS_CHTVReg_UNTSC = (SiS_CHTVRegDataStruct *)SiS300_CHTVReg_UNTSC;
  296.    SiS_Pr->SiS_CHTVReg_ONTSC = (SiS_CHTVRegDataStruct *)SiS300_CHTVReg_ONTSC;
  297.    SiS_Pr->SiS_CHTVReg_UPAL  = (SiS_CHTVRegDataStruct *)SiS300_CHTVReg_UPAL;
  298.    SiS_Pr->SiS_CHTVReg_OPAL  = (SiS_CHTVRegDataStruct *)SiS300_CHTVReg_OPAL;
  299.    SiS_Pr->SiS_CHTVVCLKUNTSC = SiS300_CHTVVCLKUNTSC;
  300.    SiS_Pr->SiS_CHTVVCLKONTSC = SiS300_CHTVVCLKONTSC;
  301.    SiS_Pr->SiS_CHTVVCLKUPAL  = SiS300_CHTVVCLKUPAL;
  302.    SiS_Pr->SiS_CHTVVCLKOPAL  = SiS300_CHTVVCLKOPAL;
  303.    /* TW: LCDResInfo will on 300 series be translated to 310/325 series definitions */
  304.    SiS_Pr->SiS_Panel320x480   = Panel_320x480;
  305.    SiS_Pr->SiS_Panel640x480   = Panel_640x480;
  306.    SiS_Pr->SiS_Panel800x600   = Panel_800x600;
  307.    SiS_Pr->SiS_Panel1024x768  = Panel_1024x768;
  308.    SiS_Pr->SiS_Panel1280x1024 = Panel_1280x1024;
  309.    SiS_Pr->SiS_Panel1280x960  = Panel_1280x960;
  310.    SiS_Pr->SiS_Panel1024x600  = Panel_1024x600;
  311.    SiS_Pr->SiS_Panel1152x768  = Panel_1152x768;
  312.    SiS_Pr->SiS_Panel1600x1200 = 16;   /* TW: Something illegal */
  313.    SiS_Pr->SiS_Panel1400x1050 = 16;   /* TW: Something illegal */
  314.    SiS_Pr->SiS_Panel1152x864  = 16;    /* TW: Something illegal */
  315.    SiS_Pr->SiS_Panel1280x768  = 16;    /* TW: Something illegal */
  316.    SiS_Pr->SiS_PanelMax       = Panel_320x480;     /* TW: highest value */
  317.    SiS_Pr->SiS_PanelMinLVDS   = Panel_800x600;     /* TW: Lowest value LVDS */
  318.    SiS_Pr->SiS_PanelMin301    = Panel_1024x768;    /* TW: lowest value 301 */
  319. }
  320. #endif
  321. #ifdef SIS315H
  322. void
  323. InitTo310Pointer(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension)
  324. {
  325.    SiS_Pr->SiS_SModeIDTable  = (SiS_StStruct *)SiS310_SModeIDTable;
  326.    SiS_Pr->SiS_StandTable    = (SiS_StandTableStruct *)SiS310_StandTable;
  327.    SiS_Pr->SiS_EModeIDTable  = (SiS_ExtStruct *)SiS310_EModeIDTable;
  328.    SiS_Pr->SiS_RefIndex      = (SiS_Ext2Struct *)SiS310_RefIndex;
  329.    SiS_Pr->SiS_CRT1Table     = (SiS_CRT1TableStruct *)SiS310_CRT1Table;
  330.    /* TW: MCLK is different */
  331.    if(HwDeviceExtension->jChipType > SIS_315PRO) {
  332.       SiS_Pr->SiS_MCLKData_0 = (SiS_MCLKDataStruct *)SiS310_MCLKData_0_650;  /* 550, 650 */
  333.    } else {
  334.       SiS_Pr->SiS_MCLKData_0 = (SiS_MCLKDataStruct *)SiS310_MCLKData_0_315;  /* 315 */
  335.    }
  336.    SiS_Pr->SiS_MCLKData_1    = (SiS_MCLKDataStruct *)SiS310_MCLKData_1;
  337.    SiS_Pr->SiS_ECLKData      = (SiS_ECLKDataStruct *)SiS310_ECLKData;
  338.    SiS_Pr->SiS_VCLKData      = (SiS_VCLKDataStruct *)SiS310_VCLKData;
  339.    SiS_Pr->SiS_VBVCLKData    = (SiS_VBVCLKDataStruct *)SiS310_VBVCLKData;
  340.    SiS_Pr->SiS_ScreenOffset  = SiS310_ScreenOffset;
  341.    SiS_Pr->SiS_StResInfo     = (SiS_StResInfoStruct *)SiS310_StResInfo;
  342.    SiS_Pr->SiS_ModeResInfo   = (SiS_ModeResInfoStruct *)SiS310_ModeResInfo;
  343.    SiS_Pr->pSiS_OutputSelect = &SiS310_OutputSelect;
  344.    SiS_Pr->pSiS_SoftSetting  = &SiS310_SoftSetting;
  345.    SiS_Pr->SiS_SR15  = SiS310_SR15;
  346. #ifndef LINUX_XF86
  347.    SiS_Pr->pSiS_SR07 = &SiS310_SR07;
  348.    SiS_Pr->SiS_CR40  = SiS310_CR40;
  349.    SiS_Pr->SiS_CR49  = SiS310_CR49;
  350.    SiS_Pr->pSiS_SR1F = &SiS310_SR1F;
  351.    SiS_Pr->pSiS_SR21 = &SiS310_SR21;
  352.    SiS_Pr->pSiS_SR22 = &SiS310_SR22;
  353.    SiS_Pr->pSiS_SR23 = &SiS310_SR23;
  354.    SiS_Pr->pSiS_SR24 = &SiS310_SR24;
  355.    SiS_Pr->SiS_SR25  = SiS310_SR25;
  356.    SiS_Pr->pSiS_SR31 = &SiS310_SR31;
  357.    SiS_Pr->pSiS_SR32 = &SiS310_SR32;
  358.    SiS_Pr->pSiS_SR33 = &SiS310_SR33;
  359.    SiS_Pr->pSiS_CRT2Data_1_2  = &SiS310_CRT2Data_1_2;
  360.    SiS_Pr->pSiS_CRT2Data_4_D  = &SiS310_CRT2Data_4_D;
  361.    SiS_Pr->pSiS_CRT2Data_4_E  = &SiS310_CRT2Data_4_E;
  362.    SiS_Pr->pSiS_CRT2Data_4_10 = &SiS310_CRT2Data_4_10;
  363.    SiS_Pr->pSiS_RGBSenseData    = &SiS310_RGBSenseData;
  364.    SiS_Pr->pSiS_VideoSenseData  = &SiS310_VideoSenseData;
  365.    SiS_Pr->pSiS_YCSenseData     = &SiS310_YCSenseData;
  366.    SiS_Pr->pSiS_RGBSenseData2   = &SiS310_RGBSenseData2;
  367.    SiS_Pr->pSiS_VideoSenseData2 = &SiS310_VideoSenseData2;
  368.    SiS_Pr->pSiS_YCSenseData2    = &SiS310_YCSenseData2;
  369. #endif
  370.    SiS_Pr->SiS_NTSCPhase    = SiS310_NTSCPhase;
  371.    SiS_Pr->SiS_PALPhase     = SiS310_PALPhase;
  372.    SiS_Pr->SiS_NTSCPhase2   = SiS310_NTSCPhase2;
  373.    SiS_Pr->SiS_PALPhase2    = SiS310_PALPhase2;
  374.    SiS_Pr->SiS_PALMPhase    = SiS310_PALMPhase;
  375.    SiS_Pr->SiS_PALNPhase    = SiS310_PALNPhase;
  376.    SiS_Pr->SiS_PALMPhase2   = SiS310_PALMPhase2;
  377.    SiS_Pr->SiS_PALNPhase2   = SiS310_PALNPhase2;
  378.    SiS_Pr->SiS_SpecialPhase = SiS310_SpecialPhase;
  379.    SiS_Pr->SiS_StLCD1024x768Data    = (SiS_LCDDataStruct *)SiS310_StLCD1024x768Data;
  380.    SiS_Pr->SiS_ExtLCD1024x768Data   = (SiS_LCDDataStruct *)SiS310_ExtLCD1024x768Data;
  381.    SiS_Pr->SiS_St2LCD1024x768Data   = (SiS_LCDDataStruct *)SiS310_St2LCD1024x768Data;
  382.    SiS_Pr->SiS_StLCD1280x1024Data   = (SiS_LCDDataStruct *)SiS310_StLCD1280x1024Data;
  383.    SiS_Pr->SiS_ExtLCD1280x1024Data  = (SiS_LCDDataStruct *)SiS310_ExtLCD1280x1024Data;
  384.    SiS_Pr->SiS_St2LCD1280x1024Data  = (SiS_LCDDataStruct *)SiS310_St2LCD1280x1024Data;
  385.    SiS_Pr->SiS_NoScaleData1024x768  = (SiS_LCDDataStruct *)SiS310_NoScaleData1024x768;
  386.    SiS_Pr->SiS_NoScaleData1280x1024 = (SiS_LCDDataStruct *)SiS310_NoScaleData1280x1024;
  387.    SiS_Pr->SiS_LCD1280x960Data      = (SiS_LCDDataStruct *)SiS310_LCD1280x960Data;
  388.    SiS_Pr->SiS_ExtLCD1400x1050Data  = (SiS_LCDDataStruct *)SiS310_ExtLCD1400x1050Data;
  389.    SiS_Pr->SiS_ExtLCD1600x1200Data  = (SiS_LCDDataStruct *)SiS310_ExtLCD1600x1200Data;
  390.    SiS_Pr->SiS_StLCD1400x1050Data   = (SiS_LCDDataStruct *)SiS310_StLCD1400x1050Data;
  391.    SiS_Pr->SiS_StLCD1600x1200Data   = (SiS_LCDDataStruct *)SiS310_StLCD1600x1200Data;
  392.    SiS_Pr->SiS_NoScaleData1400x1050 = (SiS_LCDDataStruct *)SiS310_NoScaleData1400x1050;
  393.    SiS_Pr->SiS_NoScaleData1600x1200 = (SiS_LCDDataStruct *)SiS310_NoScaleData1600x1200;
  394.    SiS_Pr->SiS_StPALData   = (SiS_TVDataStruct *)SiS310_StPALData;
  395.    SiS_Pr->SiS_ExtPALData  = (SiS_TVDataStruct *)SiS310_ExtPALData;
  396.    SiS_Pr->SiS_StNTSCData  = (SiS_TVDataStruct *)SiS310_StNTSCData;
  397.    SiS_Pr->SiS_ExtNTSCData = (SiS_TVDataStruct *)SiS310_ExtNTSCData;
  398. #ifdef oldHV
  399.    SiS_Pr->SiS_St1HiTVData = (SiS_TVDataStruct *)SiS310_St1HiTVData;
  400.    SiS_Pr->SiS_St2HiTVData = (SiS_TVDataStruct *)SiS310_St2HiTVData;
  401.    SiS_Pr->SiS_ExtHiTVData = (SiS_TVDataStruct *)SiS310_ExtHiTVData;
  402. #endif
  403.    SiS_Pr->SiS_NTSCTiming     = SiS310_NTSCTiming;
  404.    SiS_Pr->SiS_PALTiming      = SiS310_PALTiming;
  405. #ifdef oldHV
  406.    SiS_Pr->SiS_HiTVSt1Timing  = SiS310_HiTVSt1Timing;
  407.    SiS_Pr->SiS_HiTVSt2Timing  = SiS310_HiTVSt2Timing;
  408.    SiS_Pr->SiS_HiTVTextTiming = SiS310_HiTVTextTiming;
  409.    SiS_Pr->SiS_HiTVExtTiming  = SiS310_HiTVExtTiming;
  410.    SiS_Pr->SiS_HiTVGroup3Data = SiS310_HiTVGroup3Data;
  411.    SiS_Pr->SiS_HiTVGroup3Simu = SiS310_HiTVGroup3Simu;
  412.    SiS_Pr->SiS_HiTVGroup3Text = SiS310_HiTVGroup3Text;
  413. #endif
  414.    SiS_Pr->SiS_PanelDelayTbl = (SiS_PanelDelayTblStruct *)SiS310_PanelDelayTbl;
  415.    SiS_Pr->SiS_PanelDelayTblLVDS = (SiS_PanelDelayTblStruct *)SiS310_PanelDelayTblLVDS;
  416.    SiS_Pr->SiS_LVDS800x600Data_1   = (SiS_LVDSDataStruct *)SiS310_LVDS800x600Data_1;
  417.    SiS_Pr->SiS_LVDS800x600Data_2   = (SiS_LVDSDataStruct *)SiS310_LVDS800x600Data_2;
  418.    SiS_Pr->SiS_LVDS1024x768Data_1  = (SiS_LVDSDataStruct *)SiS310_LVDS1024x768Data_1;
  419.    SiS_Pr->SiS_LVDS1024x768Data_2  = (SiS_LVDSDataStruct *)SiS310_LVDS1024x768Data_2;
  420.    SiS_Pr->SiS_LVDS1280x1024Data_1 = (SiS_LVDSDataStruct *)SiS310_LVDS1280x1024Data_1;
  421.    SiS_Pr->SiS_LVDS1280x1024Data_2 = (SiS_LVDSDataStruct *)SiS310_LVDS1280x1024Data_2;
  422.    SiS_Pr->SiS_LVDS1280x960Data_1  = (SiS_LVDSDataStruct *)SiS310_LVDS1280x960Data_1;
  423.    SiS_Pr->SiS_LVDS1280x960Data_2  = (SiS_LVDSDataStruct *)SiS310_LVDS1280x960Data_2;
  424.    SiS_Pr->SiS_LVDS1400x1050Data_1 = (SiS_LVDSDataStruct *)SiS310_LVDS1400x1050Data_1;
  425.    SiS_Pr->SiS_LVDS1400x1050Data_2 = (SiS_LVDSDataStruct *)SiS310_LVDS1400x1050Data_2;
  426.    SiS_Pr->SiS_LVDS1024x600Data_1  = (SiS_LVDSDataStruct *)SiS310_LVDS1024x600Data_1;
  427.    SiS_Pr->SiS_LVDS1024x600Data_2  = (SiS_LVDSDataStruct *)SiS310_LVDS1024x600Data_2;
  428.    SiS_Pr->SiS_LVDS1152x768Data_1  = (SiS_LVDSDataStruct *)SiS310_LVDS1152x768Data_1;
  429.    SiS_Pr->SiS_LVDS1152x768Data_2  = (SiS_LVDSDataStruct *)SiS310_LVDS1152x768Data_2;
  430.    SiS_Pr->SiS_LVDSXXXxXXXData_1   = (SiS_LVDSDataStruct *)SiS310_LVDSXXXxXXXData_1;
  431.    SiS_Pr->SiS_LVDS320x480Data_1   = (SiS_LVDSDataStruct *)SiS310_LVDS320x480Data_1;
  432.    SiS_Pr->SiS_LVDS640x480Data_1   = (SiS_LVDSDataStruct *)SiS310_LVDS640x480Data_1;
  433.    SiS_Pr->SiS_LCDA1400x1050Data_1  = (SiS_LVDSDataStruct *)SiS310_LCDA1400x1050Data_1;
  434.    SiS_Pr->SiS_LCDA1400x1050Data_2  = (SiS_LVDSDataStruct *)SiS310_LCDA1400x1050Data_2;
  435.    SiS_Pr->SiS_LCDA1600x1200Data_1  = (SiS_LVDSDataStruct *)SiS310_LCDA1600x1200Data_1;
  436.    SiS_Pr->SiS_LCDA1600x1200Data_2  = (SiS_LVDSDataStruct *)SiS310_LCDA1600x1200Data_2;
  437.    SiS_Pr->SiS_CHTVUNTSCData = (SiS_LVDSDataStruct *)SiS310_CHTVUNTSCData;
  438.    SiS_Pr->SiS_CHTVONTSCData = (SiS_LVDSDataStruct *)SiS310_CHTVONTSCData;
  439.    SiS_Pr->SiS_CHTVUPALData  = (SiS_LVDSDataStruct *)SiS310_CHTVUPALData;
  440.    SiS_Pr->SiS_CHTVOPALData  = (SiS_LVDSDataStruct *)SiS310_CHTVOPALData;
  441.    SiS_Pr->SiS_PanelType00_1 = (SiS_LVDSDesStruct *)SiS310_PanelType00_1;
  442.    SiS_Pr->SiS_PanelType01_1 = (SiS_LVDSDesStruct *)SiS310_PanelType01_1;
  443.    SiS_Pr->SiS_PanelType02_1 = (SiS_LVDSDesStruct *)SiS310_PanelType02_1;
  444.    SiS_Pr->SiS_PanelType03_1 = (SiS_LVDSDesStruct *)SiS310_PanelType03_1;
  445.    SiS_Pr->SiS_PanelType04_1 = (SiS_LVDSDesStruct *)SiS310_PanelType04_1;
  446.    SiS_Pr->SiS_PanelType05_1 = (SiS_LVDSDesStruct *)SiS310_PanelType05_1;
  447.    SiS_Pr->SiS_PanelType06_1 = (SiS_LVDSDesStruct *)SiS310_PanelType06_1;
  448.    SiS_Pr->SiS_PanelType07_1 = (SiS_LVDSDesStruct *)SiS310_PanelType07_1;
  449.    SiS_Pr->SiS_PanelType08_1 = (SiS_LVDSDesStruct *)SiS310_PanelType08_1;
  450.    SiS_Pr->SiS_PanelType09_1 = (SiS_LVDSDesStruct *)SiS310_PanelType09_1;
  451.    SiS_Pr->SiS_PanelType0a_1 = (SiS_LVDSDesStruct *)SiS310_PanelType0a_1;
  452.    SiS_Pr->SiS_PanelType0b_1 = (SiS_LVDSDesStruct *)SiS310_PanelType0b_1;
  453.    SiS_Pr->SiS_PanelType0c_1 = (SiS_LVDSDesStruct *)SiS310_PanelType0c_1;
  454.    SiS_Pr->SiS_PanelType0d_1 = (SiS_LVDSDesStruct *)SiS310_PanelType0d_1;
  455.    SiS_Pr->SiS_PanelType0e_1 = (SiS_LVDSDesStruct *)SiS310_PanelType0e_1;
  456.    SiS_Pr->SiS_PanelType0f_1 = (SiS_LVDSDesStruct *)SiS310_PanelType0f_1;
  457.    SiS_Pr->SiS_PanelType00_2 = (SiS_LVDSDesStruct *)SiS310_PanelType00_2;
  458.    SiS_Pr->SiS_PanelType01_2 = (SiS_LVDSDesStruct *)SiS310_PanelType01_2;
  459.    SiS_Pr->SiS_PanelType02_2 = (SiS_LVDSDesStruct *)SiS310_PanelType02_2;
  460.    SiS_Pr->SiS_PanelType03_2 = (SiS_LVDSDesStruct *)SiS310_PanelType03_2;
  461.    SiS_Pr->SiS_PanelType04_2 = (SiS_LVDSDesStruct *)SiS310_PanelType04_2;
  462.    SiS_Pr->SiS_PanelType05_2 = (SiS_LVDSDesStruct *)SiS310_PanelType05_2;
  463.    SiS_Pr->SiS_PanelType06_2 = (SiS_LVDSDesStruct *)SiS310_PanelType06_2;
  464.    SiS_Pr->SiS_PanelType07_2 = (SiS_LVDSDesStruct *)SiS310_PanelType07_2;
  465.    SiS_Pr->SiS_PanelType08_2 = (SiS_LVDSDesStruct *)SiS310_PanelType08_2;
  466.    SiS_Pr->SiS_PanelType09_2 = (SiS_LVDSDesStruct *)SiS310_PanelType09_2;
  467.    SiS_Pr->SiS_PanelType0a_2 = (SiS_LVDSDesStruct *)SiS310_PanelType0a_2;
  468.    SiS_Pr->SiS_PanelType0b_2 = (SiS_LVDSDesStruct *)SiS310_PanelType0b_2;
  469.    SiS_Pr->SiS_PanelType0c_2 = (SiS_LVDSDesStruct *)SiS310_PanelType0c_2;
  470.    SiS_Pr->SiS_PanelType0d_2 = (SiS_LVDSDesStruct *)SiS310_PanelType0d_2;
  471.    SiS_Pr->SiS_PanelType0e_2 = (SiS_LVDSDesStruct *)SiS310_PanelType0e_2;
  472.    SiS_Pr->SiS_PanelType0f_2 = (SiS_LVDSDesStruct *)SiS310_PanelType0f_2;
  473.    SiS_Pr->LVDS1024x768Des_1  = (SiS_LVDSDesStruct *)SiS310_PanelType1076_1;
  474.    SiS_Pr->LVDS1280x1024Des_1 = (SiS_LVDSDesStruct *)SiS310_PanelType1210_1;
  475.    SiS_Pr->LVDS1400x1050Des_1 = (SiS_LVDSDesStruct *)SiS310_PanelType1296_1 ;
  476.    SiS_Pr->LVDS1600x1200Des_1 = (SiS_LVDSDesStruct *)SiS310_PanelType1600_1 ;
  477.    SiS_Pr->LVDS1024x768Des_2  = (SiS_LVDSDesStruct *)SiS310_PanelType1076_2;
  478.    SiS_Pr->LVDS1280x1024Des_2 = (SiS_LVDSDesStruct *)SiS310_PanelType1210_2;
  479.    SiS_Pr->LVDS1400x1050Des_2 = (SiS_LVDSDesStruct *)SiS310_PanelType1296_2;
  480.    SiS_Pr->LVDS1600x1200Des_2 = (SiS_LVDSDesStruct *)SiS310_PanelType1600_2 ;
  481.    /* TW: New from 650/301LV BIOS */
  482.    SiS_Pr->SiS_CRT2Part2_1024x768_1  = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_1024x768_1;
  483.    SiS_Pr->SiS_CRT2Part2_1280x1024_1 = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_1280x1024_1;
  484.    SiS_Pr->SiS_CRT2Part2_1400x1050_1 = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_1400x1050_1;
  485.    SiS_Pr->SiS_CRT2Part2_1600x1200_1 = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_1600x1200_1;
  486.    SiS_Pr->SiS_CRT2Part2_1024x768_2  = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_1024x768_2;
  487.    SiS_Pr->SiS_CRT2Part2_1280x1024_2 = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_1280x1024_2;
  488.    SiS_Pr->SiS_CRT2Part2_1400x1050_2 = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_1400x1050_2;
  489.    SiS_Pr->SiS_CRT2Part2_1600x1200_2 = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_1600x1200_2;
  490.    SiS_Pr->SiS_CRT2Part2_1024x768_3  = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_1024x768_3;
  491.    SiS_Pr->SiS_CRT2Part2_1280x1024_3 = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_1280x1024_3;
  492.    SiS_Pr->SiS_CRT2Part2_1400x1050_3 = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_1400x1050_3;
  493.    SiS_Pr->SiS_CRT2Part2_1600x1200_3 = (SiS_Part2PortTblStruct *)SiS310_CRT2Part2_1600x1200_3;
  494.    SiS_Pr->SiS_CHTVUNTSCDesData = (SiS_LVDSDesStruct *)SiS310_CHTVUNTSCDesData;
  495.    SiS_Pr->SiS_CHTVONTSCDesData = (SiS_LVDSDesStruct *)SiS310_CHTVONTSCDesData;
  496.    SiS_Pr->SiS_CHTVUPALDesData  = (SiS_LVDSDesStruct *)SiS310_CHTVUPALDesData;
  497.    SiS_Pr->SiS_CHTVOPALDesData  = (SiS_LVDSDesStruct *)SiS310_CHTVOPALDesData;
  498.    SiS_Pr->SiS_LVDSCRT1800x600_1     = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT1800x600_1;
  499.    SiS_Pr->SiS_LVDSCRT11024x768_1    = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11024x768_1;
  500.    SiS_Pr->SiS_LVDSCRT11280x1024_1   = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11280x1024_1;
  501.    SiS_Pr->SiS_LVDSCRT11400x1050_1   = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11400x1050_1;
  502.    SiS_Pr->SiS_LVDSCRT11024x600_1    = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11024x600_1;
  503.    SiS_Pr->SiS_LVDSCRT11152x768_1    = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11152x768_1;
  504.    SiS_Pr->SiS_LVDSCRT11600x1200_1   = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11600x1200_1;
  505.    SiS_Pr->SiS_LVDSCRT1800x600_1_H   = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT1800x600_1_H;
  506.    SiS_Pr->SiS_LVDSCRT11024x768_1_H  = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11024x768_1_H;
  507.    SiS_Pr->SiS_LVDSCRT11280x1024_1_H = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11280x1024_1_H;
  508.    SiS_Pr->SiS_LVDSCRT11400x1050_1_H = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11400x1050_1_H;
  509.    SiS_Pr->SiS_LVDSCRT11024x600_1_H  = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11024x600_1_H;
  510.    SiS_Pr->SiS_LVDSCRT11152x768_1_H  = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11152x768_1_H;
  511.    SiS_Pr->SiS_LVDSCRT11600x1200_1_H = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11600x1200_1_H;
  512.    SiS_Pr->SiS_LVDSCRT1800x600_2     = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT1800x600_2;
  513.    SiS_Pr->SiS_LVDSCRT11024x768_2    = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11024x768_2;
  514.    SiS_Pr->SiS_LVDSCRT11280x1024_2   = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11280x1024_2;
  515.    SiS_Pr->SiS_LVDSCRT11400x1050_2   = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11400x1050_2;
  516.    SiS_Pr->SiS_LVDSCRT11024x600_2    = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11024x600_2;
  517.    SiS_Pr->SiS_LVDSCRT11152x768_2    = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11152x768_2;
  518.    SiS_Pr->SiS_LVDSCRT11600x1200_2   = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11600x1200_2;
  519.    SiS_Pr->SiS_LVDSCRT1800x600_2_H   = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT1800x600_2_H;
  520.    SiS_Pr->SiS_LVDSCRT11024x768_2_H  = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11024x768_2_H;
  521.    SiS_Pr->SiS_LVDSCRT11280x1024_2_H = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11280x1024_2_H;
  522.    SiS_Pr->SiS_LVDSCRT11400x1050_2_H = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11400x1050_2_H;
  523.    SiS_Pr->SiS_LVDSCRT11024x600_2_H  = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11024x600_2_H;
  524.    SiS_Pr->SiS_LVDSCRT11152x768_2_H  = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11152x768_2_H;
  525.    SiS_Pr->SiS_LVDSCRT11600x1200_2_H = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT11600x1200_2_H;
  526.    SiS_Pr->SiS_LVDSCRT1XXXxXXX_1     = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT1XXXxXXX_1;
  527.    SiS_Pr->SiS_LVDSCRT1320x480_1     = (SiS_LVDSCRT1DataStruct *)SiS310_LVDSCRT1320x480_1;
  528.    SiS_Pr->SiS_CHTVCRT1UNTSC = (SiS_LVDSCRT1DataStruct *)SiS310_CHTVCRT1UNTSC;
  529.    SiS_Pr->SiS_CHTVCRT1ONTSC = (SiS_LVDSCRT1DataStruct *)SiS310_CHTVCRT1ONTSC;
  530.    SiS_Pr->SiS_CHTVCRT1UPAL  = (SiS_LVDSCRT1DataStruct *)SiS310_CHTVCRT1UPAL;
  531.    SiS_Pr->SiS_CHTVCRT1OPAL  = (SiS_LVDSCRT1DataStruct *)SiS310_CHTVCRT1OPAL;
  532.    SiS_Pr->SiS_CHTVReg_UNTSC = (SiS_CHTVRegDataStruct *)SiS310_CHTVReg_UNTSC;
  533.    SiS_Pr->SiS_CHTVReg_ONTSC = (SiS_CHTVRegDataStruct *)SiS310_CHTVReg_ONTSC;
  534.    SiS_Pr->SiS_CHTVReg_UPAL  = (SiS_CHTVRegDataStruct *)SiS310_CHTVReg_UPAL;
  535.    SiS_Pr->SiS_CHTVReg_OPAL  = (SiS_CHTVRegDataStruct *)SiS310_CHTVReg_OPAL;
  536.    SiS_Pr->SiS_LCDACRT1800x600_1     = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT1800x600_1;
  537.    SiS_Pr->SiS_LCDACRT11024x768_1    = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT11024x768_1;
  538.    SiS_Pr->SiS_LCDACRT11280x1024_1   = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT11280x1024_1;
  539.    SiS_Pr->SiS_LCDACRT11400x1050_1   = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT11400x1050_1;
  540.    SiS_Pr->SiS_LCDACRT11600x1200_1   = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT11600x1200_1;
  541.    SiS_Pr->SiS_LCDACRT1800x600_1_H   = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT1800x600_1_H;
  542.    SiS_Pr->SiS_LCDACRT11024x768_1_H  = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT11024x768_1_H;
  543.    SiS_Pr->SiS_LCDACRT11280x1024_1_H = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT11280x1024_1_H;
  544.    SiS_Pr->SiS_LCDACRT11400x1050_1_H = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT11400x1050_1_H;
  545.    SiS_Pr->SiS_LCDACRT11600x1200_1_H = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT11600x1200_1_H;
  546.    SiS_Pr->SiS_LCDACRT1800x600_2     = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT1800x600_2;
  547.    SiS_Pr->SiS_LCDACRT11024x768_2    = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT11024x768_2;
  548.    SiS_Pr->SiS_LCDACRT11280x1024_2   = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT11280x1024_2;
  549.    SiS_Pr->SiS_LCDACRT11400x1050_2   = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT11400x1050_2;
  550.    SiS_Pr->SiS_LCDACRT11600x1200_2   = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT11600x1200_2;
  551.    SiS_Pr->SiS_LCDACRT1800x600_2_H   = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT1800x600_2_H;
  552.    SiS_Pr->SiS_LCDACRT11024x768_2_H  = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT11024x768_2_H;
  553.    SiS_Pr->SiS_LCDACRT11280x1024_2_H = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT11280x1024_2_H;
  554.    SiS_Pr->SiS_LCDACRT11400x1050_2_H = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT11400x1050_2_H;
  555.    SiS_Pr->SiS_LCDACRT11600x1200_2_H = (SiS_LCDACRT1DataStruct *)SiS310_LCDACRT11600x1200_2_H;
  556.    SiS_Pr->SiS_CHTVVCLKUNTSC = SiS310_CHTVVCLKUNTSC;
  557.    SiS_Pr->SiS_CHTVVCLKONTSC = SiS310_CHTVVCLKONTSC;
  558.    SiS_Pr->SiS_CHTVVCLKUPAL  = SiS310_CHTVVCLKUPAL;
  559.    SiS_Pr->SiS_CHTVVCLKOPAL  = SiS310_CHTVVCLKOPAL;
  560.    SiS_Pr->SiS_Panel320x480   = Panel_320x480;
  561.    SiS_Pr->SiS_Panel640x480   = Panel_640x480;
  562.    SiS_Pr->SiS_Panel800x600   = Panel_800x600;
  563.    SiS_Pr->SiS_Panel1024x768  = Panel_1024x768;
  564.    SiS_Pr->SiS_Panel1280x1024 = Panel_1280x1024;
  565.    SiS_Pr->SiS_Panel1280x960  = Panel_1280x960;
  566.    SiS_Pr->SiS_Panel1600x1200 = Panel_1600x1200;
  567.    SiS_Pr->SiS_Panel1400x1050 = Panel_1400x1050;
  568.    SiS_Pr->SiS_Panel1152x768  = Panel_1152x768;
  569.    SiS_Pr->SiS_Panel1152x864  = Panel_1152x864;
  570.    SiS_Pr->SiS_Panel1280x768  = Panel_1280x768;
  571.    SiS_Pr->SiS_Panel1024x600  = Panel_1024x600;
  572.    SiS_Pr->SiS_PanelMax       = Panel_320x480;    /* TW: highest value */
  573.    SiS_Pr->SiS_PanelMinLVDS   = Panel_800x600;    /* TW: lowest value LVDS/LCDA */
  574.    SiS_Pr->SiS_PanelMin301    = Panel_1024x768;   /* TW: lowest value 301 */
  575. }
  576. #endif
  577. #ifdef LINUXBIOS
  578. /* -------------- SiSInit -----------------*/
  579. /* TW: I degraded this for LINUXBIOS only, because we
  580.  *     don't need this otherwise
  581.  */
  582. BOOLEAN
  583. SiSInit(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension)
  584. {
  585.    UCHAR  *ROMAddr  = HwDeviceExtension->pjVirtualRomBase;
  586.    ULONG   FBAddr   = (ULONG)HwDeviceExtension->pjVideoMemoryAddress;
  587.    USHORT  BaseAddr = (USHORT)HwDeviceExtension->ulIOAddress;
  588.    UCHAR   i, temp=0;
  589.    UCHAR   SR11;
  590. #ifdef LINUX_KERNEL
  591.    UCHAR   temp1;
  592.    ULONG   base;
  593. #endif
  594.    UCHAR   SR13=0, SR14=0, SR16=0
  595.    UCHAR   SR17=0, SR19=0, SR1A=0;
  596. #ifdef SIS300
  597.    UCHAR   SR18=0, SR12=0;
  598. #endif
  599. #ifdef SIS315H
  600.    UCHAR   CR37=0, CR38=0, CR79=0,
  601.    UCHAR   CR7A=0, CR7B=0, CR7C=0;
  602.    UCHAR   SR1B=0, SR15=0;
  603.    PSIS_DSReg pSR;
  604.    ULONG   Temp;
  605. #endif
  606.    UCHAR   VBIOSVersion[5];
  607.    if(FBAddr==0)    return (FALSE);
  608.    if(BaseAddr==0)  return (FALSE);
  609.    SiS_SetReg3((USHORT)(BaseAddr+0x12),  0x67);  /* Misc */
  610. #ifdef SIS315H
  611.    if(HwDeviceExtension->jChipType > SIS_315PRO) {
  612.      if(!HwDeviceExtension->bIntegratedMMEnabled)
  613.       return (FALSE);
  614.    }
  615. #endif
  616.    SiS_MemoryCopy(VBIOSVersion,HwDeviceExtension->szVBIOSVer,4);
  617.    VBIOSVersion[4]= 0x00;
  618.    SiSDetermineROMUsage(SiS_Pr, HwDeviceExtension, ROMAddr);
  619.    /* TW: Init pointers */
  620. #ifdef SIS315H
  621.    if((HwDeviceExtension->jChipType == SIS_315H) ||
  622.       (HwDeviceExtension->jChipType == SIS_315PRO) ||
  623.       (HwDeviceExtension->jChipType == SIS_550) ||
  624.       (HwDeviceExtension->jChipType == SIS_640) ||
  625.       (HwDeviceExtension->jChipType == SIS_740) ||
  626.       (HwDeviceExtension->jChipType == SIS_650))
  627.      InitTo310Pointer(SiS_Pr, HwDeviceExtension);
  628. #endif
  629. #ifdef SIS300
  630.    if((HwDeviceExtension->jChipType == SIS_540) ||
  631.       (HwDeviceExtension->jChipType == SIS_630) ||
  632.       (HwDeviceExtension->jChipType == SIS_730) ||
  633.       (HwDeviceExtension->jChipType == SIS_300))
  634.      InitTo300Pointer(SiS_Pr, HwDeviceExtension);
  635. #endif
  636.    /* TW: Set SiS Register definitions */
  637.    SiSRegInit(SiS_Pr, BaseAddr);
  638.    /* TW: Determine LVDS/CH70xx/TRUMPION */
  639.    SiS_Set_LVDS_TRUMPION(SiS_Pr, HwDeviceExtension);
  640.    /* TW: Unlock registers */
  641.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x05,0x86);
  642. #ifdef LINUX_KERNEL
  643. #ifdef SIS300                                          /* Set SR14 */
  644.    if((HwDeviceExtension->jChipType==SIS_540) ||
  645.       (HwDeviceExtension->jChipType==SIS_630) ||
  646.       (HwDeviceExtension->jChipType==SIS_730)) {
  647.      base=0x80000060;
  648.      OutPortLong(base,0xcf8);
  649.      temp1 = InPortLong(0xcfc);
  650.      temp1 >>= (16+8+4);
  651.      temp1 &= 0x07;
  652.      temp1++;
  653.      temp1 = 1 << temp1;
  654.      SR14 = temp1 - 1;
  655.      base = 0x80000064;
  656.      OutPortLong(base,0xcf8);
  657.      temp1 = InPortLong(0xcfc);
  658.      temp1 &= 0x00000020;
  659.      if(temp1)  SR14 |= 0x80;
  660.      else       SR14 |= 0x40;
  661.    }
  662. #endif
  663. #ifdef SIS315H                                          /* Set SR14 */
  664.    if(HwDeviceExtension->jChipType==SIS_550) {
  665.      base = 0x80000060;
  666.      OutPortLong(base,0xcf8);
  667.      temp1 = InPortLong(0xcfc);
  668.      temp1 >>= (16+8+4);
  669.      temp1 &= 0x07;
  670.      temp1++;
  671.      temp1 = 1 << temp1;
  672.      SR14 = temp1 - 1;
  673.      base = 0x80000064;
  674.      OutPortLong(base,0xcf8);
  675.      temp1 = InPortLong(0xcfc);
  676.      temp1 &= 0x00000020;
  677.      if(temp1)  SR14 |= 0x80;
  678.      else       SR14 |= 0x40;
  679.    }
  680.    if((HwDeviceExtension->jChipType == SIS_640) ||      /* Set SR14 */
  681.       (HwDeviceExtension->jChipType == SIS_740) ||
  682.       (HwDeviceExtension->jChipType == SIS_650)) {
  683.      base = 0x80000064;
  684.      OutPortLong(base,0xcf8);
  685.      temp1=InPortLong(0xcfc);
  686.      temp1 >>= 4;
  687.      temp1 &= 0x07;
  688.      if(temp1 > 2) {
  689.        temp = temp1;
  690.        switch(temp) {
  691.         case 3: temp1 = 0x07;  break;
  692.         case 4: temp1 = 0x0F;  break;
  693.         case 5: temp1 = 0x1F;  break;
  694.         case 6: temp1 = 0x05;  break;
  695.         case 7: temp1 = 0x17;  break;
  696.         case 8: break;
  697.         case 9: break;
  698.        }
  699.      }
  700.      SR14 = temp1;
  701.      base = 0x8000007C;
  702.      OutPortLong(base,0xcf8);
  703.      temp1 = InPortLong(0xcfc);
  704.      temp1 &= 0x00000020;
  705.      if(temp1)  SR14 |= 0x80;
  706.    }
  707. #endif
  708. #endif  /* Linux kernel */
  709. #ifdef SIS300
  710.    if((HwDeviceExtension->jChipType == SIS_540)||
  711.       (HwDeviceExtension->jChipType == SIS_630)||
  712.       (HwDeviceExtension->jChipType == SIS_730)) {
  713.      SR12 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x12);
  714.      SR13 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x13);
  715.      SR14 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x14);
  716.      SR16 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x16);
  717.      SR17 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x17);
  718.      SR18 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x18);
  719.      SR19 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x19);
  720.      SR1A = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x1A);
  721.    } else if(HwDeviceExtension->jChipType == SIS_300){
  722.      SR13 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x13);
  723.      SR14 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x14);
  724.    }
  725. #endif
  726. #ifdef SIS315H
  727.    if((HwDeviceExtension->jChipType == SIS_550) ||
  728.       (HwDeviceExtension->jChipType == SIS_640) ||
  729.       (HwDeviceExtension->jChipType == SIS_740) ||
  730.       (HwDeviceExtension->jChipType == SIS_650)) {
  731.      SR19 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x19);
  732.      SR19 = (SR19)||0x01;  /* TW: ??? || ??? */
  733.      if(SR19==0x00) {
  734.       SR13 = 0x22;
  735.       SR14 = 0x00;
  736.      SR15 = 0x01;
  737.       SR16 = 0x00;
  738.       SR17 = 0x00;
  739.       SR1A = 0x00;
  740.       SR1B = 0x00;
  741.       CR37 = 0x00;
  742.       CR38 = 0x00;
  743.       CR79 = 0x00;
  744.       CR7A = 0x00;
  745.       CR7B = 0x00;
  746.       CR7C = 0x00;
  747.      } else {
  748.       SR13 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x13);
  749.       SR14 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x14);
  750.       SR15 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x15);
  751.       SR16 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x16);
  752.       SR17 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x17);
  753.       SR1A = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x1A);
  754.       SR1B = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x1B);
  755.       CR37 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3d4,0x37);  /* TW: Was 0x02 - why? */
  756.       CR38 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3d4,0x38);
  757.       CR79 = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3d4,0x79);
  758.       CR7A = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3d4,0x7A);
  759.       CR7B = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3d4,0x7B);
  760.       CR7C = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3d4,0x7C);
  761.      }
  762.    }
  763. #endif
  764.    /* Reset extended registers */
  765.    for(i=0x06; i< 0x20; i++) SiS_SetReg1(SiS_Pr->SiS_P3c4,i,0);
  766.    for(i=0x21; i<=0x27; i++) SiS_SetReg1(SiS_Pr->SiS_P3c4,i,0);
  767.    for(i=0x31; i<=0x3D; i++) SiS_SetReg1(SiS_Pr->SiS_P3c4,i,0);
  768. #ifdef SIS300
  769.    if((HwDeviceExtension->jChipType == SIS_540) ||
  770.       (HwDeviceExtension->jChipType == SIS_630) ||
  771.       (HwDeviceExtension->jChipType == SIS_730) ||
  772.       (HwDeviceExtension->jChipType == SIS_300)) {
  773.       for(i=0x38; i<=0x3F; i++) SiS_SetReg1(SiS_Pr->SiS_P3d4,i,0);
  774.    }
  775. #endif
  776. #ifdef SIS315H
  777.    if((HwDeviceExtension->jChipType == SIS_315H) ||
  778.       (HwDeviceExtension->jChipType == SIS_315PRO) ||
  779.       (HwDeviceExtension->jChipType == SIS_550) ||
  780.       (HwDeviceExtension->jChipType == SIS_640) ||
  781.       (HwDeviceExtension->jChipType == SIS_740) ||
  782.       (HwDeviceExtension->jChipType == SIS_650)) {
  783.     for(i=0x12; i<=0x1B; i++) SiS_SetReg1(SiS_Pr->SiS_P3c4,i,0);
  784.     for(i=0x79; i<=0x7C; i++) SiS_SetReg1(SiS_Pr->SiS_P3d4,i,0);
  785.    }
  786. #endif
  787.    /* Restore Extended Registers */
  788. #ifdef SIS300
  789.    if((HwDeviceExtension->jChipType == SIS_540) ||
  790.       (HwDeviceExtension->jChipType == SIS_630) ||
  791.       (HwDeviceExtension->jChipType == SIS_730)) {
  792.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x12,SR12);
  793.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x13,SR13);
  794.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,SR14);
  795.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x16,SR16);
  796.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x17,SR17);
  797.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x18,SR18);
  798.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x19,SR19);
  799.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x1A,SR1A);
  800.    }
  801. #endif
  802. #ifdef SIS315H
  803.    if((HwDeviceExtension->jChipType == SIS_550) ||
  804.       (HwDeviceExtension->jChipType == SIS_640) ||
  805.       (HwDeviceExtension->jChipType == SIS_740) ||
  806.       (HwDeviceExtension->jChipType == SIS_650)) {
  807.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x13,SR13);
  808.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,SR14);
  809.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x15,SR15);
  810.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x16,SR16);
  811.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x17,SR17);
  812.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x19,SR19);
  813.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x1A,SR1A);
  814.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x1B,SR1B);
  815.      SiS_SetReg1(SiS_Pr->SiS_P3d4,0x37,CR37);
  816.      SiS_SetReg1(SiS_Pr->SiS_P3d4,0x38,CR38);
  817.      SiS_SetReg1(SiS_Pr->SiS_P3d4,0x79,CR79);
  818.      SiS_SetReg1(SiS_Pr->SiS_P3d4,0x7A,CR7A);
  819.      SiS_SetReg1(SiS_Pr->SiS_P3d4,0x7B,CR7B);
  820.      SiS_SetReg1(SiS_Pr->SiS_P3d4,0x7C,CR7C);
  821.    }
  822. #endif
  823. #ifdef SIS300
  824.    if((HwDeviceExtension->jChipType==SIS_540) ||
  825.       (HwDeviceExtension->jChipType==SIS_630) ||
  826.       (HwDeviceExtension->jChipType==SIS_730)) {
  827.       temp = (UCHAR)SR1A & 0x03;
  828.    } else if(HwDeviceExtension->jChipType==SIS_300) {
  829.         /* TW: Nothing */
  830.    }
  831. #endif
  832. #ifdef SIS315H
  833.    if((HwDeviceExtension->jChipType == SIS_315H )||
  834.       (HwDeviceExtension->jChipType == SIS_315PRO)) {
  835.        if((*SiS_Pr->pSiS_SoftSetting & SoftDRAMType) == 0){
  836.            temp = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x3A) & 0x03;
  837.         }
  838.    }
  839.    if((HwDeviceExtension->jChipType == SIS_550) ||
  840.       (HwDeviceExtension->jChipType == SIS_640) ||
  841.       (HwDeviceExtension->jChipType == SIS_740) ||
  842.       (HwDeviceExtension->jChipType == SIS_650)) {
  843.         if((*SiS_Pr->pSiS_SoftSetting & SoftDRAMType) == 0){
  844.            temp = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x13) & 0x07;
  845.         }
  846.    }
  847. #endif
  848.    SiS_Pr->SiS_RAMType = temp;
  849.    SiS_SetMemoryClock(SiS_Pr, ROMAddr, HwDeviceExtension);
  850.    /* Set default register contents */
  851.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x07,*SiS_Pr->pSiS_SR07);  /* DAC speed */
  852.    if((HwDeviceExtension->jChipType != SIS_540) &&
  853.       (HwDeviceExtension->jChipType != SIS_630) &&
  854.       (HwDeviceExtension->jChipType != SIS_730)){
  855.       for(i=0x15;i<0x1C;i++) {
  856.             SiS_SetReg1(SiS_Pr->SiS_P3c4,i,SiS_Pr->SiS_SR15[i-0x15][SiS_Pr->SiS_RAMType]);
  857.       }
  858.    }
  859. #ifdef SIS315H
  860.    if ((HwDeviceExtension->jChipType == SIS_315H ) ||
  861.        (HwDeviceExtension->jChipType == SIS_315PRO)) {
  862.       for(i=0x40;i<=0x44;i++) {
  863.             SiS_SetReg1(SiS_Pr->SiS_P3d4,i,SiS_Pr->SiS_CR40[i-0x40][SiS_Pr->SiS_RAMType]);
  864.       }
  865.       SiS_SetReg1(SiS_Pr->SiS_P3d4,0x48,0x23);
  866.       SiS_SetReg1(SiS_Pr->SiS_P3d4,0x49,SiS_Pr->SiS_CR49[0]);
  867.     /*  SiS_SetReg1(SiS_Pr->SiS_P3c4,0x25,SiS_Pr->SiS_SR25[0]);  */
  868.    }
  869. #endif
  870.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x1F,*SiS_Pr->pSiS_SR1F);  /* DAC pedestal */
  871.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x20,0xA0);
  872.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x23,*SiS_Pr->pSiS_SR23);
  873.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x24,*SiS_Pr->pSiS_SR24);
  874.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x25,SiS_Pr->SiS_SR25[0]);
  875. #ifdef SIS300
  876.    if(HwDeviceExtension->jChipType == SIS_300) {
  877.       SiS_SetReg1(SiS_Pr->SiS_P3c4,0x21,0x84);
  878.       SiS_SetReg1(SiS_Pr->SiS_P3c4,0x22,0x00);
  879.    }
  880. #endif
  881.    SR11 = 0x0F;
  882.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x11,SR11); /* Power Management & DDC port */
  883.    SiS_UnLockCRT2(SiS_Pr, HwDeviceExtension, BaseAddr);
  884.    SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x00,0x00);
  885.    SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x02,*SiS_Pr->pSiS_CRT2Data_1_2);
  886. #ifdef SIS315H
  887.    if((HwDeviceExtension->jChipType == SIS_315H) ||
  888.       (HwDeviceExtension->jChipType == SIS_315PRO) ||
  889.       (HwDeviceExtension->jChipType == SIS_550) ||
  890.       (HwDeviceExtension->jChipType == SIS_640) ||
  891.       (HwDeviceExtension->jChipType == SIS_740) ||
  892.       (HwDeviceExtension->jChipType == SIS_650))
  893.       SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x2E,0x08);    /* use VB */
  894. #endif
  895.    temp = *SiS_Pr->pSiS_SR32;
  896.    if(SiS_BridgeIsOn(SiS_Pr, BaseAddr)) {
  897.       temp &= 0xEF;
  898.    }
  899.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x32,temp);
  900. #ifdef SIS315H
  901.    if((HwDeviceExtension->jChipType == SIS_315H) ||
  902.       (HwDeviceExtension->jChipType == SIS_315PRO)) {
  903.      HwDeviceExtension->pQueryVGAConfigSpace(HwDeviceExtension,0x50,0,&Temp);
  904.      Temp >>= 20;
  905.      Temp &= 0xF;
  906.      if (Temp != 1) {
  907.       SiS_SetReg1(SiS_Pr->SiS_P3c4,0x25,SiS_Pr->SiS_SR25[1]);
  908.       SiS_SetReg1(SiS_Pr->SiS_P3d4,0x49,SiS_Pr->SiS_CR49[1]);
  909.      }
  910.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x27,0x1F);
  911.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x31,*SiS_Pr->pSiS_SR31);
  912.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x32,*SiS_Pr->pSiS_SR32);
  913.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x33,*SiS_Pr->pSiS_SR33);
  914.    }
  915. #endif
  916.    if (SiS_BridgeIsOn(SiS_Pr, BaseAddr) == 0) {
  917.       if(SiS_Pr->SiS_IF_DEF_LVDS == 0) {
  918.         SiS_SetReg1(SiS_Pr->SiS_Part2Port,0x00,0x1C);
  919.         SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x0D,*SiS_Pr->pSiS_CRT2Data_4_D);
  920.         SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x0E,*SiS_Pr->pSiS_CRT2Data_4_E);
  921.         SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x10,*SiS_Pr->pSiS_CRT2Data_4_10);
  922.         SiS_SetReg1(SiS_Pr->SiS_Part4Port,0x0F,0x3F);
  923.       }
  924.       SiS_LockCRT2(SiS_Pr, HwDeviceExtension, BaseAddr);
  925.    }
  926.    SiS_SetReg1(SiS_Pr->SiS_P3d4,0x83,0x00);
  927. #ifdef SIS315H
  928.    if ((HwDeviceExtension->jChipType==SIS_315H) ||
  929.        (HwDeviceExtension->jChipType==SIS_315PRO)) {
  930.         if (HwDeviceExtension->bSkipDramSizing==TRUE) {
  931.           SiS_SetDRAMModeRegister(SiS_Pr, ROMAddr,HwDeviceExtension);
  932.           pSR = HwDeviceExtension->pSR;
  933.           if (pSR!=NULL) {
  934.             while (pSR->jIdx!=0xFF) {
  935.               SiS_SetReg1(SiS_Pr->SiS_P3c4,pSR->jIdx,pSR->jVal);
  936.               pSR++;
  937.             }
  938.           }
  939.        } else SiS_SetDRAMSize_310(SiS_Pr, HwDeviceExtension);
  940.    }
  941. #endif
  942. #ifdef SIS315H
  943.    if((HwDeviceExtension->jChipType==SIS_550)){
  944.        /* SetDRAMConfig begin */
  945. /*     SiS_SetReg1(SiS_Pr->SiS_P3c4,0x12,SR12);
  946.        SiS_SetReg1(SiS_Pr->SiS_P3c4,0x13,SR13);
  947.        SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,SR14);
  948.        SiS_SetReg1(SiS_Pr->SiS_P3c4,0x16,SR16);
  949.        SiS_SetReg1(SiS_Pr->SiS_P3c4,0x17,SR17);
  950.        SiS_SetReg1(SiS_Pr->SiS_P3c4,0x18,SR18);
  951.        SiS_SetReg1(SiS_Pr->SiS_P3c4,0x19,SR19);
  952.        SiS_SetReg1(SiS_Pr->SiS_P3c4,0x1A,SR1A);   */
  953.        /* SetDRAMConfig end */
  954.    }
  955. #endif
  956. #ifdef SIS300
  957.    if(HwDeviceExtension->jChipType == SIS_300) {
  958.         if (HwDeviceExtension->bSkipDramSizing == TRUE) {
  959. /*        SiS_SetDRAMModeRegister(ROMAddr,HwDeviceExtension);
  960.           temp = (HwDeviceExtension->pSR)->jVal;
  961.           SiS_SetReg1(SiS_Pr->SiS_P3c4,0x13,temp);
  962.           temp = (HwDeviceExtension->pSR)->jVal;
  963.           SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,temp);   */
  964.        } else {
  965. #ifdef TC
  966.           SiS_SetReg1(SiS_Pr->SiS_P3c4,0x13,SR13);
  967.           SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,SR14);
  968.           SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x15,0xFF,0x04);
  969. #else
  970.           SiS_SetDRAMSize_300(SiS_Pr, HwDeviceExtension);
  971.           SiS_SetDRAMSize_300(SiS_Pr, HwDeviceExtension);
  972. #endif
  973.        }
  974.    }
  975.    if((HwDeviceExtension->jChipType==SIS_540)||
  976.       (HwDeviceExtension->jChipType==SIS_630)||
  977.       (HwDeviceExtension->jChipType==SIS_730)) {
  978. #if 0
  979.       SiS_SetReg1(SiS_Pr->SiS_P3c4,0x12,SR12);
  980.         SiS_SetReg1(SiS_Pr->SiS_P3c4,0x13,SR13);
  981.         SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,SR14);
  982.         SiS_SetReg1(SiS_Pr->SiS_P3c4,0x16,SR16);
  983.         SiS_SetReg1(SiS_Pr->SiS_P3c4,0x17,SR17);
  984.         SiS_SetReg1(SiS_Pr->SiS_P3c4,0x18,SR18);
  985.         SiS_SetReg1(SiS_Pr->SiS_P3c4,0x19,SR19);
  986.         SiS_SetReg1(SiS_Pr->SiS_P3c4,0x1A,SR1A);
  987. #endif
  988.    }
  989. /* SetDRAMSize end */
  990. #endif /* SIS300 */
  991.    /* Set default Ext2Regs */
  992. #if 0
  993.    AGP=1;
  994.    temp=(UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x3A);
  995.    temp &= 0x30;
  996.    if(temp == 0x30) AGP=0;
  997.    if(AGP == 0) *SiS_Pr->pSiS_SR21 &= 0xEF;
  998.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x21,*SiS_Pr->pSiS_SR21);
  999.    if(AGP == 1) *SiS_Pr->pSiS_SR22 &= 0x20;
  1000.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x22,*SiS_Pr->pSiS_SR22);
  1001. #endif
  1002.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x21,*SiS_Pr->pSiS_SR21);
  1003.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x22,*SiS_Pr->pSiS_SR22);
  1004. #if 0
  1005.    SiS_SetReg3(SiS_Pr->SiS_P3c6,0xff);
  1006.    SiS_ClearDAC(SiS_Pr, SiS_Pr->SiS_P3c8);
  1007. #endif
  1008. #ifdef LINUXBIOS   /* TW: This is not needed for our purposes */
  1009.    SiS_DetectMonitor(SiS_Pr, HwDeviceExtension,BaseAddr);    /* Sense CRT1 */
  1010.    SiS_GetSenseStatus(SiS_Pr, HwDeviceExtension,ROMAddr);    /* Sense CRT2 */
  1011. #endif
  1012.    return(TRUE);
  1013. }
  1014. void
  1015. SiS_Set_LVDS_TRUMPION(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension)
  1016. {
  1017.   USHORT temp = 0;
  1018. #ifdef SiS300
  1019.   if((HwDeviceExtension->jChipType == SIS_540) ||
  1020.      (HwDeviceExtension->jChipType == SIS_630) ||
  1021.      (HwDeviceExtension->jChipType == SIS_730)) {
  1022.         /* TW: Read POWER_ON_TRAP and copy to CR37 */
  1023.      temp = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x1A);
  1024.      temp = (temp & 0xE0) >> 4;
  1025.     SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x37,0xF1,temp);
  1026.   }
  1027. #endif
  1028. #ifdef SIS315H
  1029.   if((HwDeviceExtension->jChipType == SIS_640) ||
  1030.      (HwDeviceExtension->jChipType == SIS_740) ||
  1031.      (HwDeviceExtension->jChipType == SIS_650)) {
  1032. #if 0 /* TW: This is not required */
  1033.         /* TW: Read POWER_ON_TRAP and copy to CR37 */
  1034.      temp = (UCHAR)SiS_GetReg1(SiS_Pr->SiS_P3c4,0x1A);
  1035.      temp = (temp & 0xE0) >> 4;
  1036.     SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x37,0xF1,temp);
  1037. #endif
  1038.   }
  1039. #endif
  1040.    SiSSetLVDSetc(SiS_Pr, HwDeviceExtension, 0);
  1041. }
  1042. /* ===============  SiS 300 dram sizing begin  =============== */
  1043. #ifdef SIS300
  1044. void
  1045. SiS_SetDRAMSize_300(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension)
  1046. {
  1047.    ULONG   FBAddr = (ULONG)HwDeviceExtension->pjVideoMemoryAddress;
  1048.    USHORT  SR13, SR14=0, buswidth, Done;
  1049.    SHORT   i, j, k;
  1050.    USHORT  data, TotalCapacity, PhysicalAdrOtherPage=0;
  1051.    ULONG   Addr;
  1052.    UCHAR   temp;
  1053.    int     PseudoRankCapacity, PseudoTotalCapacity, PseudoAdrPinCount;
  1054.    int     RankCapacity, AdrPinCount, BankNumHigh, BankNumMid, MB2Bank;
  1055.    int     PageCapacity, PhysicalAdrHigh, PhysicalAdrHalfPage;
  1056.    SiSSetMode(SiS_Pr, HwDeviceExtension, 0x2e);
  1057.    SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x01,0x20);        /* Turn OFF Display  */
  1058.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x13,0x00);
  1059.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,0xBF);
  1060.    buswidth = SiS_ChkBUSWidth_300(SiS_Pr, FBAddr);
  1061.    MB2Bank = 16;
  1062.    Done = 0;
  1063.    for(i=6; i>=0; i--) {
  1064.       if(Done == 1) break;
  1065.       PseudoRankCapacity = 1 << i;
  1066.       for(j=4; j>=1; j--) {
  1067.          if(Done == 1) break;
  1068.          PseudoTotalCapacity = PseudoRankCapacity * j;
  1069.          PseudoAdrPinCount = 15 - j;
  1070.          if(PseudoTotalCapacity <= 64) {
  1071.             for(k=0; k<=16; k++) {
  1072.                if(Done == 1) break;
  1073.                RankCapacity = buswidth * SiS_DRAMType[k][3];
  1074.                AdrPinCount = SiS_DRAMType[k][2] + SiS_DRAMType[k][0];
  1075.                if(RankCapacity == PseudoRankCapacity)
  1076.                  if(AdrPinCount <= PseudoAdrPinCount) {
  1077.                     if(j == 3) {             /* Rank No */
  1078.                        BankNumHigh = RankCapacity * MB2Bank * 3 - 1;
  1079.                        BankNumMid = RankCapacity * MB2Bank * 1 - 1;
  1080.                     } else {
  1081.                        BankNumHigh = RankCapacity * MB2Bank * j - 1;
  1082.                        BankNumMid = RankCapacity * MB2Bank * j / 2 - 1;
  1083.                     }
  1084.                     PageCapacity = (1 << SiS_DRAMType[k][1]) * buswidth * 4;
  1085.                     PhysicalAdrHigh = BankNumHigh;
  1086.                     PhysicalAdrHalfPage = (PageCapacity / 2 + PhysicalAdrHigh) % PageCapacity;
  1087.                     PhysicalAdrOtherPage = PageCapacity * SiS_DRAMType[k][2] + PhysicalAdrHigh;
  1088.                     /* Write data */
  1089.                     /*Test*/
  1090.                     SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x15,0xFB);
  1091.                     SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x15,0x04);
  1092.                     /*/Test*/
  1093.                     TotalCapacity = SiS_DRAMType[k][3] * buswidth;
  1094.                     SR13 = SiS_DRAMType[k][4];
  1095.                     if(buswidth == 4) SR14 = (TotalCapacity - 1) | 0x80;
  1096.                     if(buswidth == 2) SR14 = (TotalCapacity - 1) | 0x40;
  1097.                     if(buswidth == 1) SR14 = (TotalCapacity - 1) | 0x00;
  1098.                     SiS_SetReg1(SiS_Pr->SiS_P3c4,0x13,SR13);
  1099.                     SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,SR14);
  1100.                     Addr = FBAddr + (BankNumHigh) * 64 * 1024 + PhysicalAdrHigh;
  1101.                     *((USHORT *)(Addr)) = (USHORT)PhysicalAdrHigh;
  1102.                     Addr = FBAddr + (BankNumMid) * 64 * 1024 + PhysicalAdrHigh;
  1103.                     *((USHORT *)(Addr)) = (USHORT)BankNumMid;
  1104.                     Addr = FBAddr + (BankNumHigh) * 64 * 1024 + PhysicalAdrHalfPage;
  1105.                     *((USHORT *)(Addr)) = (USHORT)PhysicalAdrHalfPage;
  1106.                     Addr = FBAddr + (BankNumHigh) * 64 * 1024 + PhysicalAdrOtherPage;
  1107.                     *((USHORT *)(Addr)) = PhysicalAdrOtherPage;
  1108.                     /* Read data */
  1109.                     Addr = FBAddr + (BankNumHigh) * 64 * 1024 + PhysicalAdrHigh;
  1110.                     data = *((USHORT *)(Addr));
  1111.                     if(data == PhysicalAdrHigh) Done = 1;
  1112.                  }  /* if struct */
  1113.             }  /* for loop (k) */
  1114.          }  /* if struct */
  1115.       }  /* for loop (j) */
  1116.    }  /* for loop (i) */
  1117. }
  1118. USHORT
  1119. SiS_ChkBUSWidth_300(SiS_Private *SiS_Pr, ULONG FBAddress)
  1120. {
  1121.    PULONG  pVideoMemory;
  1122.    pVideoMemory = (PULONG)FBAddress;
  1123.    pVideoMemory[0] = 0x01234567L;
  1124.    pVideoMemory[1] = 0x456789ABL;
  1125.    pVideoMemory[2] = 0x89ABCDEFL;
  1126.    pVideoMemory[3] = 0xCDEF0123L;
  1127.    if (pVideoMemory[3]==0xCDEF0123L) {  /* Channel A 128bit */
  1128.      return(4);
  1129.    }
  1130.    if (pVideoMemory[1]==0x456789ABL) {  /* Channel B 64bit */
  1131.      return(2);
  1132.    }
  1133.    return(1);
  1134. }
  1135. #endif
  1136. /* ===============  SiS 300 dram sizing end    =============== */
  1137. /* ============  SiS 310/325 dram sizing begin  ============== */
  1138. #ifdef SIS315H
  1139. /* TW: Moved Get310DRAMType further down */
  1140. void
  1141. SiS_Delay15us(SiS_Private *SiS_Pr, ULONG ulMicrsoSec)
  1142. {
  1143. }
  1144. void
  1145. SiS_SDR_MRS(SiS_Private *SiS_Pr, )
  1146. {
  1147.    USHORT  data;
  1148.    data = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x16);
  1149.    data &= 0x3F;                   /* SR16 D7=0, D6=0 */
  1150.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x16,data);    /* enable mode register set(MRS) low */
  1151.    SiS_Delay15us(SiS_Pr, 0x100);
  1152.    data |= 0x80;                   /* SR16 D7=1, D6=0 */
  1153.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x16,data);    /* enable mode register set(MRS) high */
  1154.    SiS_Delay15us(SiS_Pr, 0x100);
  1155. }
  1156. void
  1157. SiS_DDR_MRS(SiS_Private *SiS_Pr)
  1158. {
  1159.    USHORT  data;
  1160.    /* SR16 <- 1F,DF,2F,AF */
  1161.    /* enable DLL of DDR SD/SGRAM , SR16 D4=1 */
  1162.    data=SiS_GetReg1(SiS_Pr->SiS_P3c4,0x16);
  1163.    data &= 0x0F;
  1164.    data |= 0x10;
  1165.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x16,data);
  1166.    if (!(SiS_Pr->SiS_SR15[1][SiS_Pr->SiS_RAMType] & 0x10))
  1167.      data &= 0x0F;
  1168.    /* SR16 D7=1,D6=1 */
  1169.    data |= 0xC0;
  1170.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x16,data);
  1171.    
  1172.    /* SR16 D7=1,D6=0,D5=1,D4=0 */
  1173.    data &= 0x0F;
  1174.    data |= 0x20;
  1175.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x16,data);
  1176.    if (!(SiS_Pr->SiS_SR15[1][SiS_Pr->SiS_RAMType] & 0x10))
  1177.      data &= 0x0F;
  1178.    /* SR16 D7=1 */
  1179.    data |= 0x80;
  1180.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x16,data);
  1181. }
  1182. void
  1183. SiS_SetDRAMModeRegister(SiS_Private *SiS_Pr, UCHAR *ROMAddr, PSIS_HW_DEVICE_INFO HwDeviceExtension)
  1184. {
  1185.     if (SiS_Get310DRAMType(ROMAddr,HwDeviceExtension) < 2)
  1186.         SiS_SDR_MRS(SiS_Pr);
  1187.     else
  1188.         /* SR16 <- 0F,CF,0F,8F */
  1189.         SiS_DDR_MRS(SiS_Pr);
  1190. }
  1191. void
  1192. SiS_DisableRefresh(SiS_Private *SiS_Pr)
  1193. {
  1194.    SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x17,0xF8);
  1195.    SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x19,0x03);
  1196. }
  1197. void
  1198. SiS_EnableRefresh(SiS_Private *SiS_Pr, UCHAR *ROMAddr)
  1199. {
  1200.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x17,SiS_Pr->SiS_SR15[2][SiS_Pr->SiS_RAMType]);
  1201.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x19,SiS_Pr->SiS_SR15[4][SiS_Pr->SiS_RAMType]);
  1202. }
  1203. void
  1204. SiS_DisableChannelInterleaving(SiS_Private *SiS_Pr, int index,
  1205.                                USHORT SiS_DDRDRAM_TYPE[][5])
  1206. {
  1207.    USHORT  data;
  1208.    data=SiS_GetReg1(SiS_Pr->SiS_P3c4,0x15);
  1209.    data &= 0x1F;
  1210.    switch (SiS_DDRDRAM_TYPE[index][3])
  1211.    {
  1212.      case 64: data |= 0;  break;
  1213.      case 32: data |= 0x20; break;
  1214.      case 16: data |= 0x40;     break;
  1215.      case 4:  data |= 0x60;     break;
  1216.    }
  1217.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x15,data);
  1218. }
  1219. void
  1220. SiS_SetDRAMSizingType(SiS_Private *SiS_Pr, int index, USHORT DRAMTYPE_TABLE[][5])
  1221. {
  1222.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x13,DRAMTYPE_TABLE[index][4]);
  1223.    /* should delay 50 ns */
  1224. }
  1225. void
  1226. SiS_CheckBusWidth_310(SiS_Private *SiS_Pr, UCHAR *ROMAddress,ULONG FBAddress,
  1227.                       PSIS_HW_DEVICE_INFO HwDeviceExtension)
  1228. {
  1229.    USHORT  data;
  1230.    PULONG volatile pVideoMemory;
  1231.    pVideoMemory = (PULONG)FBAddress;
  1232.    if(SiS_Get310DRAMType(ROMAddress,HwDeviceExtension) < 2) {
  1233.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x13,0x00);
  1234.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,0x12);
  1235.      /* should delay */
  1236.      SiS_SDR_MRS(SiS_Pr);
  1237.      SiS_Pr->SiS_ChannelAB = 0;
  1238.      SiS_Pr->SiS_DataBusWidth = 128;
  1239.      pVideoMemory[0] = 0x01234567L;
  1240.      pVideoMemory[1] = 0x456789ABL;
  1241.      pVideoMemory[2] = 0x89ABCDEFL;
  1242.      pVideoMemory[3] = 0xCDEF0123L;
  1243.      pVideoMemory[4] = 0x55555555L;
  1244.      pVideoMemory[5] = 0x55555555L;
  1245.      pVideoMemory[6] = 0xFFFFFFFFL;
  1246.      pVideoMemory[7] = 0xFFFFFFFFL;
  1247.      if ((pVideoMemory[3]!=0xCDEF0123L) || (pVideoMemory[2] != 0x89ABCDEFL)) {
  1248.        /*Channel A 64Bit */
  1249.        SiS_Pr->SiS_DataBusWidth = 64;
  1250.        SiS_Pr->SiS_ChannelAB = 0;
  1251.        data=SiS_GetReg1(SiS_Pr->SiS_P3c4,0x14);
  1252.        SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,(USHORT)(data & 0xFD));
  1253.      }
  1254.      if ((pVideoMemory[1]!=0x456789ABL) || (pVideoMemory[0] != 0x01234567L)) {
  1255.        /*Channel B 64Bit */
  1256.        SiS_Pr->SiS_DataBusWidth = 64;
  1257.        SiS_Pr->SiS_ChannelAB = 1;
  1258.        data=SiS_GetReg1(SiS_Pr->SiS_P3c4,0x14);
  1259.        SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,(USHORT)((data&0xFD)|0x01));
  1260.      }
  1261.      return;
  1262.    } else {
  1263.      /* DDR Dual channel */
  1264.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x13,0x00);
  1265.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,0x02); /* Channel A, 64bit */
  1266.      /* should delay */
  1267.      SiS_DDR_MRS(SiS_Pr);
  1268.      SiS_Pr->SiS_ChannelAB = 0;
  1269.      SiS_Pr->SiS_DataBusWidth = 64;
  1270.      pVideoMemory[0] = 0x01234567L;
  1271.      pVideoMemory[1] = 0x456789ABL;
  1272.      pVideoMemory[2] = 0x89ABCDEFL;
  1273.      pVideoMemory[3] = 0xCDEF0123L;
  1274.      pVideoMemory[4] = 0x55555555L;
  1275.      pVideoMemory[5] = 0x55555555L;
  1276.      pVideoMemory[6] = 0xAAAAAAAAL;
  1277.      pVideoMemory[7] = 0xAAAAAAAAL;
  1278.      if (pVideoMemory[1] == 0x456789ABL) {
  1279.        if (pVideoMemory[0] == 0x01234567L) {
  1280.          /* Channel A 64bit */
  1281.          return;
  1282.        }
  1283.      } else {
  1284.        if (pVideoMemory[0] == 0x01234567L) {
  1285.          /* Channel A 32bit */
  1286.          SiS_Pr->SiS_DataBusWidth = 32;
  1287.          SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,0x00);
  1288.          return;
  1289.        }
  1290.      }
  1291.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,0x03); /* Channel B, 64bit */
  1292.      SiS_DDR_MRS(SiS_Pr);
  1293.      SiS_Pr->SiS_ChannelAB = 1;
  1294.      SiS_Pr->SiS_DataBusWidth = 64;
  1295.      pVideoMemory[0] = 0x01234567L;
  1296.      pVideoMemory[1] = 0x456789ABL;
  1297.      pVideoMemory[2] = 0x89ABCDEFL;
  1298.      pVideoMemory[3] = 0xCDEF0123L;
  1299.      pVideoMemory[4] = 0x55555555L;
  1300.      pVideoMemory[5] = 0x55555555L;
  1301.      pVideoMemory[6] = 0xAAAAAAAAL;
  1302.      pVideoMemory[7] = 0xAAAAAAAAL;
  1303.      if (pVideoMemory[1] == 0x456789ABL) {
  1304.        /* Channel B 64 */
  1305.        if (pVideoMemory[0] == 0x01234567L) {
  1306.          /* Channel B 64bit */
  1307.          return;
  1308.        } else {
  1309.          /* error */
  1310.        }
  1311.      } else {
  1312.        if (pVideoMemory[0] == 0x01234567L) {
  1313.          /* Channel B 32 */
  1314.          SiS_Pr->SiS_DataBusWidth = 32;
  1315.          SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,0x01);
  1316.        } else {
  1317.          /* error */
  1318.        }
  1319.      }
  1320.    }
  1321. }
  1322. int
  1323. SiS_SetRank(SiS_Private *SiS_Pr, int index,UCHAR RankNo,USHORT DRAMTYPE_TABLE[][5])
  1324. {
  1325.   USHORT  data;
  1326.   int RankSize;
  1327.   if ((RankNo==2)&&(DRAMTYPE_TABLE[index][0]==2))
  1328.          return 0;
  1329.   RankSize = DRAMTYPE_TABLE[index][3]/2 * SiS_Pr->SiS_DataBusWidth / 32;
  1330.   if (RankNo * RankSize <= 128) {
  1331.     data = 0;
  1332.     while((RankSize >>= 1) > 0) {
  1333.       data += 0x10;
  1334.     }
  1335.     data |= (RankNo - 1) << 2;
  1336.     data |= (SiS_Pr->SiS_DataBusWidth / 64) & 2;
  1337.     data |= SiS_Pr->SiS_ChannelAB;
  1338.     SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,data);
  1339.     /* should delay */
  1340.     SiS_SDR_MRS(SiS_Pr);
  1341.     return 1;
  1342.   } else
  1343.     return 0;
  1344. }
  1345. int
  1346. SiS_SetDDRChannel(SiS_Private *SiS_Pr, int index,UCHAR ChannelNo,
  1347.                   USHORT DRAMTYPE_TABLE[][5])
  1348. {
  1349.   USHORT  data;
  1350.   int RankSize;
  1351.   RankSize = DRAMTYPE_TABLE[index][3]/2 * SiS_Pr->SiS_DataBusWidth / 32;
  1352.   /* RankSize = DRAMTYPE_TABLE[index][3]; */
  1353.   if (ChannelNo * RankSize <= 128) {
  1354.     data = 0;
  1355.     while((RankSize >>= 1) > 0) {
  1356.       data += 0x10;
  1357.     }
  1358.     if(ChannelNo == 2) data |= 0x0C;
  1359.     data |= (SiS_Pr->SiS_DataBusWidth / 32) & 2;
  1360.     data |= SiS_Pr->SiS_ChannelAB;
  1361.     SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,data);
  1362.     /* should delay */
  1363.     SiS_DDR_MRS(SiS_Pr);
  1364.     return 1;
  1365.   } else
  1366.     return 0;
  1367. }
  1368. int
  1369. SiS_CheckColumn(SiS_Private *SiS_Pr, int index,USHORT DRAMTYPE_TABLE[][5],ULONG FBAddress)
  1370. {
  1371.   int i;
  1372.   ULONG Increment,Position;
  1373.   /*Increment = 1<<(DRAMTYPE_TABLE[index][2] + SiS_Pr->SiS_DataBusWidth / 64 + 1); */
  1374.   Increment = 1 << (10 + SiS_Pr->SiS_DataBusWidth / 64);
  1375.   for (i=0,Position=0;i<2;i++) {
  1376.          *((PULONG)(FBAddress + Position)) = Position;
  1377.          Position += Increment;
  1378.   }
  1379.   for (i=0,Position=0;i<2;i++) {
  1380. /*    if (FBAddress[Position]!=Position) */
  1381.          if((*(PULONG)(FBAddress + Position)) != Position)
  1382.                 return 0;
  1383.          Position += Increment;
  1384.   }
  1385.   return 1;
  1386. }
  1387. int
  1388. SiS_CheckBanks(SiS_Private *SiS_Pr, int index,USHORT DRAMTYPE_TABLE[][5],ULONG FBAddress)
  1389. {
  1390.   int i;
  1391.   ULONG Increment,Position;
  1392.   Increment = 1 << (DRAMTYPE_TABLE[index][2] + SiS_Pr->SiS_DataBusWidth / 64 + 2);
  1393.   for (i=0,Position=0;i<4;i++) {
  1394. /*    FBAddress[Position]=Position; */
  1395.     *((PULONG)(FBAddress + Position)) = Position;
  1396.     Position += Increment;
  1397.   }
  1398.   for (i=0,Position=0;i<4;i++) {
  1399. /*    if (FBAddress[Position]!=Position) */
  1400.     if((*(PULONG)(FBAddress + Position)) != Position)
  1401.       return 0;
  1402.     Position += Increment;
  1403.   }
  1404.   return 1;
  1405. }
  1406. int
  1407. SiS_CheckRank(SiS_Private *SiS_Pr, int RankNo,int index,USHORT DRAMTYPE_TABLE[][5],ULONG FBAddress)
  1408. {
  1409.   int i;
  1410.   ULONG Increment,Position;
  1411.   Increment = 1<<(DRAMTYPE_TABLE[index][2] + DRAMTYPE_TABLE[index][1] +
  1412.                   DRAMTYPE_TABLE[index][0] + SiS_Pr->SiS_DataBusWidth / 64 + RankNo);
  1413.   for (i=0,Position=0;i<2;i++) {
  1414. /*    FBAddress[Position]=Position; */
  1415.     *((PULONG)(FBAddress+Position))=Position;
  1416.     /* *((PULONG)(FBAddress))=Position; */
  1417.     Position += Increment;
  1418.   }
  1419.   for (i=0,Position=0;i<2;i++) {
  1420. /*    if (FBAddress[Position]!=Position) */
  1421.          if ( (*(PULONG) (FBAddress + Position)) !=Position)
  1422.     /*if ( (*(PULONG) (FBAddress )) !=Position) */
  1423.       return 0;
  1424.     Position += Increment;
  1425.   }
  1426.   return 1;
  1427. }
  1428. int
  1429. SiS_CheckDDRRank(SiS_Private *SiS_Pr, int RankNo,int index,USHORT DRAMTYPE_TABLE[][5],ULONG FBAddress)
  1430. {
  1431.   ULONG Increment,Position;
  1432.   USHORT  data;
  1433.   Increment = 1<<(DRAMTYPE_TABLE[index][2] + DRAMTYPE_TABLE[index][1] +
  1434.                   DRAMTYPE_TABLE[index][0] + SiS_Pr->SiS_DataBusWidth / 64 + RankNo);
  1435.   Increment += Increment/2;
  1436.   Position =0;
  1437.   *((PULONG)(FBAddress+Position + 0)) = 0x01234567;
  1438.   *((PULONG)(FBAddress+Position + 1)) = 0x456789AB;
  1439.   *((PULONG)(FBAddress+Position + 2)) = 0x55555555;
  1440.   *((PULONG)(FBAddress+Position + 3)) = 0x55555555;
  1441.   *((PULONG)(FBAddress+Position + 4)) = 0xAAAAAAAA;
  1442.   *((PULONG)(FBAddress+Position + 5)) = 0xAAAAAAAA;
  1443.   if ( (*(PULONG) (FBAddress + 1)) == 0x456789AB)
  1444.     return 1;
  1445.   if ( (*(PULONG) (FBAddress + 0)) == 0x01234567)
  1446.     return 0;
  1447.   data=SiS_GetReg1(SiS_Pr->SiS_P3c4,0x14);
  1448.   data &= 0xF3;
  1449.   data |= 0x08;
  1450.   SiS_SetReg1(SiS_Pr->SiS_P3c4,0x14,data);
  1451.   data=SiS_GetReg1(SiS_Pr->SiS_P3c4,0x15);
  1452.   data += 0x20;
  1453.   SiS_SetReg1(SiS_Pr->SiS_P3c4,0x15,data);
  1454.   return 1;
  1455. }
  1456. int
  1457. SiS_CheckRanks(SiS_Private *SiS_Pr, int RankNo,int index,USHORT DRAMTYPE_TABLE[][5],ULONG FBAddress)
  1458. {
  1459.   int r;
  1460.   for (r=RankNo;r>=1;r--) {
  1461.     if (!SiS_CheckRank(SiS_Pr, r, index, DRAMTYPE_TABLE, FBAddress))
  1462.       return 0;
  1463.   }
  1464.   if (!SiS_CheckBanks(SiS_Pr, index, DRAMTYPE_TABLE, FBAddress))
  1465.     return 0;
  1466.   if (!SiS_CheckColumn(SiS_Pr, index, DRAMTYPE_TABLE, FBAddress))
  1467.     return 0;
  1468.   return 1;
  1469. }
  1470. int
  1471. SiS_CheckDDRRanks(SiS_Private *SiS_Pr, int RankNo,int index,USHORT DRAMTYPE_TABLE[][5],
  1472.                   ULONG FBAddress)
  1473. {
  1474.   int r;
  1475.   for (r=RankNo;r>=1;r--) {
  1476.     if (!SiS_CheckDDRRank(SiS_Pr, r,index,DRAMTYPE_TABLE,FBAddress))
  1477.       return 0;
  1478.   }
  1479.   if (!SiS_CheckBanks(SiS_Pr, index,DRAMTYPE_TABLE,FBAddress))
  1480.     return 0;
  1481.   if (!SiS_CheckColumn(SiS_Pr, index,DRAMTYPE_TABLE,FBAddress))
  1482.     return 0;
  1483.   return 1;
  1484. }
  1485. int
  1486. SiS_SDRSizing(SiS_Private *SiS_Pr, ULONG FBAddress)
  1487. {
  1488.   int    i;
  1489.   UCHAR  j;
  1490.   for (i=0;i<13;i++) {
  1491.     SiS_SetDRAMSizingType(SiS_Pr, i, SiS_SDRDRAM_TYPE);
  1492.     for (j=2;j>0;j--) {
  1493.       if (!SiS_SetRank(SiS_Pr, i,(UCHAR) j, SiS_SDRDRAM_TYPE))
  1494.         continue;
  1495.       else {
  1496.         if (SiS_CheckRanks(SiS_Pr, j,i,SiS_SDRDRAM_TYPE, FBAddress))
  1497.           return 1;
  1498.       }
  1499.     }
  1500.   }
  1501.   return 0;
  1502. }
  1503. int
  1504. SiS_DDRSizing(SiS_Private *SiS_Pr, ULONG FBAddress)
  1505. {
  1506.   int    i;
  1507.   UCHAR  j;
  1508.   for (i=0; i<4; i++){
  1509.     SiS_SetDRAMSizingType(SiS_Pr, i, SiS_DDRDRAM_TYPE);
  1510.     SiS_DisableChannelInterleaving(SiS_Pr, i, SiS_DDRDRAM_TYPE);
  1511.     for (j=2; j>0; j--) {
  1512.       SiS_SetDDRChannel(SiS_Pr, i, j, SiS_DDRDRAM_TYPE);
  1513.       if (!SiS_SetRank(SiS_Pr, i, (UCHAR) j, SiS_DDRDRAM_TYPE))
  1514.         continue;
  1515.       else {
  1516.         if (SiS_CheckDDRRanks(SiS_Pr, j, i, SiS_DDRDRAM_TYPE, FBAddress))
  1517.           return 1;
  1518.       }
  1519.     }
  1520.   }
  1521.   return 0;
  1522. }
  1523. /*
  1524.  check if read cache pointer is correct
  1525. */
  1526. void
  1527. SiS_VerifyMclk(SiS_Private *SiS_Pr, ULONG FBAddr)
  1528. {
  1529.    PUCHAR  pVideoMemory = (PUCHAR) FBAddr;
  1530.    UCHAR   i, j;
  1531.    USHORT  Temp,SR21;
  1532.    pVideoMemory[0] = 0xaa;  /* alan */
  1533.    pVideoMemory[16] = 0x55; /* note: PCI read cache is off */
  1534.    if((pVideoMemory[0] != 0xaa) || (pVideoMemory[16] != 0x55)) {
  1535.      for (i=0,j=16; i<2; i++,j+=16)  {
  1536.        SR21 = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x21);
  1537.        Temp = SR21 & 0xFB;           /* disable PCI post write buffer empty gating */
  1538.        SiS_SetReg1(SiS_Pr->SiS_P3c4,0x21,Temp);
  1539.        Temp = SiS_GetReg1(SiS_Pr->SiS_P3c4, 0x3C);
  1540.        Temp |= 0x01;                 /* MCLK reset */
  1541.        SiS_SetReg1(SiS_Pr->SiS_P3c4,0x3C,Temp);
  1542.        Temp = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x3C);
  1543.        Temp &= 0xFE;                 /* MCLK normal operation */
  1544.        SiS_SetReg1(SiS_Pr->SiS_P3c4,0x3C,Temp);
  1545.        SiS_SetReg1(SiS_Pr->SiS_P3c4,0x21,SR21);
  1546.        pVideoMemory[16+j] = j;
  1547.        if(pVideoMemory[16+j] == j) {
  1548.          pVideoMemory[j] = j;
  1549.          break;
  1550.        }
  1551.      }
  1552.    }
  1553. }
  1554. /* TW: Is this a 315E? */
  1555. int
  1556. Is315E(SiS_Private *SiS_Pr)
  1557. {
  1558.    USHORT  data;
  1559.    data = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x5F);
  1560.    if(data & 0x10) return 1;
  1561.    else return 0;
  1562. }
  1563. /* TW: For 315 only */
  1564. void
  1565. SiS_SetDRAMSize_310(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension)
  1566. {
  1567.    UCHAR  *ROMAddr  = HwDeviceExtension->pjVirtualRomBase;
  1568.    ULONG   FBAddr   = (ULONG)HwDeviceExtension->pjVideoMemoryAddress;
  1569.    USHORT  data;
  1570. #ifdef SIS301 /* TW: SIS301 ??? */
  1571.    /*SiS_SetReg1(SiS_Pr->SiS_P3d4,0x30,0x40);   */
  1572. #endif
  1573. #ifdef SIS302   /* TW: SIS302 ??? */
  1574.    SiS_SetReg1(SiS_Pr->SiS_P3d4,0x30,0x4D);  /* alan,should change value */
  1575.    SiS_SetReg1(SiS_Pr->SiS_P3d4,0x31,0xc0);  /* alan,should change value */
  1576.    SiS_SetReg1(SiS_Pr->SiS_P3d4,0x34,0x3F);  /* alan,should change value */
  1577. #endif
  1578.    SiSSetMode(SiS_Pr, HwDeviceExtension, 0x2e);
  1579.    data = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x21);
  1580.    SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x21,0xDF);                 /* disable read cache */
  1581.    SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x01,0x20);                  /* Turn OFF Display */
  1582.    SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x16,0x0F);                  /* assume lowest speed DRAM */
  1583.    SiS_SetDRAMModeRegister(SiS_Pr, ROMAddr, HwDeviceExtension);
  1584.    SiS_DisableRefresh(SiS_Pr);
  1585.    SiS_CheckBusWidth_310(SiS_Pr, ROMAddr, FBAddr, HwDeviceExtension);
  1586.    SiS_VerifyMclk(SiS_Pr, FBAddr);
  1587.    if(SiS_Get310DRAMType(SiS_Pr, ROMAddr, HwDeviceExtension) < 2)
  1588.      SiS_SDRSizing(SiS_Pr, FBAddr);
  1589.    else
  1590.      SiS_DDRSizing(SiS_Pr, FBAddr);
  1591.    if(Is315E(SiS_Pr)) {
  1592.      data = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x14);
  1593.      if((data & 0x0C) == 0x0C) {  /* dual channel */
  1594.       if((data & 0xF0) > 0x40)
  1595.         data = (data & 0x0F) | 0x40;
  1596.      } else {  /* single channel */
  1597.       if((data & 0xF0) > 0x50)
  1598.         data = (data & 0x0F) | 0x50;
  1599.      }
  1600.    }
  1601.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x16,SiS_Pr->SiS_SR15[1][SiS_Pr->SiS_RAMType]);  /* restore SR16 */
  1602.    SiS_EnableRefresh(SiS_Pr, ROMAddr);
  1603.    SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x21,0x20);       /* enable read cache */
  1604. }
  1605. #endif
  1606. void
  1607. SiS_SetMemoryClock(SiS_Private *SiS_Pr, UCHAR *ROMAddr,PSIS_HW_DEVICE_INFO HwDeviceExtension)
  1608. {
  1609.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x28,SiS_Pr->SiS_MCLKData_0[SiS_Pr->SiS_RAMType].SR28);
  1610.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x29,SiS_Pr->SiS_MCLKData_0[SiS_Pr->SiS_RAMType].SR29);
  1611.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x2A,SiS_Pr->SiS_MCLKData_0[SiS_Pr->SiS_RAMType].SR2A);
  1612.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x2E,SiS_Pr->SiS_ECLKData[SiS_Pr->SiS_RAMType].SR2E);
  1613.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x2F,SiS_Pr->SiS_ECLKData[SiS_Pr->SiS_RAMType].SR2F);
  1614.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x30,SiS_Pr->SiS_ECLKData[SiS_Pr->SiS_RAMType].SR30);
  1615. #ifdef SIS315H
  1616.    if (Is315E(SiS_Pr)) {
  1617.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x28,0x3B); /* 143 */
  1618.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x29,0x22);
  1619.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x2E,0x3B); /* 143 */
  1620.      SiS_SetReg1(SiS_Pr->SiS_P3c4,0x2F,0x22);
  1621.    }
  1622. #endif
  1623. }
  1624. #endif /* ifdef LINUXBIOS */
  1625. #ifdef SIS315H
  1626. UCHAR
  1627. SiS_Get310DRAMType(SiS_Private *SiS_Pr, UCHAR *ROMAddr,PSIS_HW_DEVICE_INFO HwDeviceExtension)
  1628. {
  1629.    UCHAR   data;
  1630.    if(*SiS_Pr->pSiS_SoftSetting & SoftDRAMType) {
  1631.      data = *SiS_Pr->pSiS_SoftSetting & 0x03;
  1632.    } else {
  1633.      if(HwDeviceExtension->jChipType > SIS_315PRO) {
  1634.         data = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x13) & 0x07;
  1635.      } else { /* TW: 315 */
  1636.         data = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x3a) & 0x03;
  1637.      }
  1638.    }
  1639.    return data;
  1640. }
  1641. #endif
  1642. /* SiSInit END */
  1643. /* ----------------------------------------- */
  1644. void SiSRegInit(SiS_Private *SiS_Pr, USHORT BaseAddr)
  1645. {
  1646.    SiS_Pr->SiS_P3c4 = BaseAddr + 0x14;
  1647.    SiS_Pr->SiS_P3d4 = BaseAddr + 0x24;
  1648.    SiS_Pr->SiS_P3c0 = BaseAddr + 0x10;
  1649.    SiS_Pr->SiS_P3ce = BaseAddr + 0x1e;
  1650.    SiS_Pr->SiS_P3c2 = BaseAddr + 0x12;
  1651.    SiS_Pr->SiS_P3ca = BaseAddr + 0x1a;
  1652.    SiS_Pr->SiS_P3c6 = BaseAddr + 0x16;
  1653.    SiS_Pr->SiS_P3c7 = BaseAddr + 0x17;
  1654.    SiS_Pr->SiS_P3c8 = BaseAddr + 0x18;
  1655.    SiS_Pr->SiS_P3c9 = BaseAddr + 0x19;
  1656.    SiS_Pr->SiS_P3da = BaseAddr + 0x2A;
  1657.    SiS_Pr->SiS_Part1Port = BaseAddr + SIS_CRT2_PORT_04;   /* Digital video interface registers (LCD) */
  1658.    SiS_Pr->SiS_Part2Port = BaseAddr + SIS_CRT2_PORT_10;   /* 301 TV Encoder registers */
  1659.    SiS_Pr->SiS_Part3Port = BaseAddr + SIS_CRT2_PORT_12;   /* 301 Macrovision registers */
  1660.    SiS_Pr->SiS_Part4Port = BaseAddr + SIS_CRT2_PORT_14;   /* 301 VGA2 (and LCD) registers */
  1661.    SiS_Pr->SiS_Part5Port = BaseAddr + SIS_CRT2_PORT_14+2; /* 301 palette address port registers */
  1662.    SiS_Pr->SiS_DDC_Port = BaseAddr + 0x14;                /* DDC Port ( = P3C4, SR11/0A) */
  1663. }
  1664. void
  1665. SiSInitPCIetc(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension)
  1666. {
  1667. /* #ifdef LINUX_XF86 */
  1668.    if ((HwDeviceExtension->jChipType == SIS_540)||
  1669.        (HwDeviceExtension->jChipType == SIS_630)||
  1670.        (HwDeviceExtension->jChipType == SIS_730)||
  1671.        (HwDeviceExtension->jChipType == SIS_300)) {
  1672.        /* TW: Set - PCI LINEAR ADDRESSING ENABLE (0x80)
  1673.   - PCI IO ENABLE  (0x20)
  1674.   - MMIO ENABLE (0x1)
  1675.    */
  1676.        SiS_SetReg1(SiS_Pr->SiS_P3c4,0x20,0xa1);
  1677.        /* TW: Enable 2D (0x42) & 3D accelerator (0x18) */
  1678.        SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x1E,0xFF,0x5A);
  1679.    }
  1680.    if((HwDeviceExtension->jChipType == SIS_315H)||
  1681.       (HwDeviceExtension->jChipType == SIS_315PRO)||
  1682.       (HwDeviceExtension->jChipType == SIS_550)||
  1683.       (HwDeviceExtension->jChipType == SIS_640)||
  1684.       (HwDeviceExtension->jChipType == SIS_740)||
  1685.       (HwDeviceExtension->jChipType == SIS_650)) {
  1686.       /* TW: This seems to be done the same way on these chipsets */
  1687.       SiS_SetReg1(SiS_Pr->SiS_P3c4,0x20,0xa1);
  1688.       SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x1E,0xFF,0x5A);
  1689.    }
  1690. /* #endif */
  1691. }
  1692. void
  1693. SiSSetLVDSetc(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT ModeNo)
  1694. {
  1695.    ULONG   temp;
  1696.    SiS_Pr->SiS_IF_DEF_LVDS = 0;
  1697.    SiS_Pr->SiS_IF_DEF_TRUMPION = 0;
  1698.    SiS_Pr->SiS_IF_DEF_CH70xx = 0;
  1699.    SiS_Pr->SiS_IF_DEF_HiVision = 0;
  1700.    SiS_Pr->SiS_IF_DEF_DSTN = 0;
  1701.    SiS_Pr->SiS_IF_DEF_FSTN = 0;
  1702.    SiS_Pr->SiS_ChrontelInit = 0;
  1703.    if((ModeNo == 0x5a) || (ModeNo == 0x5b)) {
  1704.     SiS_Pr->SiS_IF_DEF_DSTN = 1;   /* for 550 dstn */
  1705.     SiS_Pr->SiS_IF_DEF_FSTN = 1;   /* for fstn */
  1706.    }
  1707. #ifdef SIS300
  1708.    if((HwDeviceExtension->jChipType == SIS_540) ||
  1709.       (HwDeviceExtension->jChipType == SIS_630) ||
  1710.       (HwDeviceExtension->jChipType == SIS_730))
  1711.     {
  1712.         /* TW: Check for SiS30x first */
  1713.         temp = SiS_GetReg1(SiS_Pr->SiS_Part4Port,0x00);
  1714. if((temp == 1) || (temp == 2)) return;
  1715.        temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x37);
  1716.        temp = (temp & 0x0E) >> 1;
  1717.        if((temp >= 2) && (temp <= 5)) SiS_Pr->SiS_IF_DEF_LVDS = 1;
  1718.        if(temp == 3)   SiS_Pr->SiS_IF_DEF_TRUMPION = 1;
  1719.        if((temp == 4) || (temp == 5)) {
  1720. /* TW: Save power status (and error check) */
  1721. SiS_Pr->SiS_Backup70xx = SiS_GetCH700x(SiS_Pr, 0x0e);
  1722. SiS_Pr->SiS_IF_DEF_CH70xx = 1;
  1723.         }
  1724.    }
  1725. #endif
  1726. #ifdef SIS315H
  1727.    if((HwDeviceExtension->jChipType == SIS_550) ||
  1728.       (HwDeviceExtension->jChipType == SIS_640) ||
  1729.       (HwDeviceExtension->jChipType == SIS_740) ||
  1730.       (HwDeviceExtension->jChipType == SIS_650))
  1731.     {
  1732.         /* TW: CR37 is different on 310/325 series */
  1733.         if (SiS_Pr->SiS_IF_DEF_FSTN)                       /* fstn: set CR37=0x04 */
  1734.              SiS_SetReg1(SiS_Pr->SiS_P3d4,0x37,0x04);      /* (fake LVDS bridge) */
  1735. temp=SiS_GetReg1(SiS_Pr->SiS_P3d4,0x37);
  1736.        temp = (temp & 0x0E) >> 1;
  1737.        if((temp >= 2) && (temp <= 3)) SiS_Pr->SiS_IF_DEF_LVDS = 1;
  1738.        if(temp == 3)  {
  1739. SiS_Pr->SiS_IF_DEF_CH70xx = 2;
  1740.         }
  1741. /* SiS_Pr->SiS_IF_DEF_HiVision = 1; */
  1742.     }
  1743. #endif
  1744. }
  1745. void
  1746. SiSInitPtr(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension)
  1747. {
  1748. #ifdef SIS315H
  1749.    if((HwDeviceExtension->jChipType == SIS_315H) ||
  1750.       (HwDeviceExtension->jChipType == SIS_315PRO) ||
  1751.       (HwDeviceExtension->jChipType == SIS_550) ||
  1752.       (HwDeviceExtension->jChipType == SIS_640) ||
  1753.       (HwDeviceExtension->jChipType == SIS_740) ||
  1754.       (HwDeviceExtension->jChipType == SIS_650))
  1755.      InitTo310Pointer(SiS_Pr, HwDeviceExtension);
  1756. #endif
  1757. #ifdef SIS300
  1758.    if ((HwDeviceExtension->jChipType == SIS_540) ||
  1759.        (HwDeviceExtension->jChipType == SIS_630) ||
  1760.        (HwDeviceExtension->jChipType == SIS_730) ||
  1761.        (HwDeviceExtension->jChipType == SIS_300))
  1762.      InitTo300Pointer(SiS_Pr, HwDeviceExtension);
  1763. #endif
  1764. }
  1765. void
  1766. SiSDetermineROMUsage(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, UCHAR *ROMAddr)
  1767. {
  1768.    if((ROMAddr) && (HwDeviceExtension->UseROM)) {
  1769.      if((ROMAddr[0x00] != 0x55) || (ROMAddr[0x01] != 0xAA)) {
  1770.         SiS_Pr->SiS_UseROM = FALSE;
  1771.      } else if(HwDeviceExtension->jChipType < SIS_315H) {
  1772.         /* TW: We don't use the ROM image if BIOS version < 2.0.0 as
  1773.          *     such old BIOSes don't have the needed data at the
  1774.  *     expected locations
  1775.  */
  1776.         if(ROMAddr[0x06] < '2')  SiS_Pr->SiS_UseROM = FALSE;
  1777. else                     SiS_Pr->SiS_UseROM = TRUE;
  1778.      } else {
  1779.         /* TW: TODO: Check this for 310/325 series */
  1780. SiS_Pr->SiS_UseROM = TRUE;
  1781.      }
  1782.    } else SiS_Pr->SiS_UseROM = FALSE;
  1783. }
  1784. /*
  1785.   =========================================
  1786.   ======== SiS SetMode Functions ==========
  1787.   =========================================
  1788. */
  1789. #ifdef LINUX_XF86
  1790. /* TW: This is used for non-Dual-Head mode from X */
  1791. BOOLEAN
  1792. SiSBIOSSetMode(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, ScrnInfoPtr pScrn,
  1793.                DisplayModePtr mode)
  1794. {
  1795.    UShort  ModeNo=0;
  1796.    ModeNo = SiS_CalcModeIndex(pScrn, mode);
  1797.    if(!ModeNo) return FALSE;
  1798.    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Setting mode 0x%xn", ModeNo);
  1799.    return(SiSSetMode(SiS_Pr, HwDeviceExtension, pScrn, ModeNo, TRUE));
  1800. }
  1801. #ifdef SISDUALHEAD
  1802. /* TW: Set CRT1 mode (used for dual head) */
  1803. BOOLEAN
  1804. SiSBIOSSetModeCRT1(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, ScrnInfoPtr pScrn,
  1805.                DisplayModePtr mode)
  1806. {
  1807.    ULONG   temp;
  1808.    USHORT  ModeIdIndex;
  1809.    UCHAR  *ROMAddr  = HwDeviceExtension->pjVirtualRomBase;
  1810.    USHORT  BaseAddr = (USHORT)HwDeviceExtension->ulIOAddress;
  1811.    SISPtr  pSiS = SISPTR(pScrn);
  1812.    SISEntPtr pSiSEnt = pSiS->entityPrivate;
  1813.    UShort  ModeNo=0;
  1814.    ModeNo = SiS_CalcModeIndex(pScrn, mode);
  1815.    if(!ModeNo) return FALSE;
  1816.    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Setting mode 0x%x on CRT1n", ModeNo);
  1817.    SiSInitPtr(SiS_Pr, HwDeviceExtension);
  1818.    SiSRegInit(SiS_Pr, BaseAddr);
  1819.    SiS_Pr->SiS_VGAINFO = SiS_GetSetMMIOReg(pScrn, 0x489, 0xff);
  1820.    SiSInitPCIetc(SiS_Pr, HwDeviceExtension);
  1821.    SiSSetLVDSetc(SiS_Pr, HwDeviceExtension, ModeNo);
  1822.    SiSDetermineROMUsage(SiS_Pr, HwDeviceExtension, ROMAddr);
  1823.    /* TW: We don't clear the buffer under X */
  1824.    SiS_Pr->SiS_flag_clearbuffer=0;
  1825.    /* 1.Openkey */
  1826.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x05,0x86);
  1827.    SiS_UnLockCRT2(SiS_Pr, HwDeviceExtension, BaseAddr);
  1828.    /* 2.Get ModeID Table  */
  1829.    temp = SiS_SearchModeID(SiS_Pr, ROMAddr,&ModeNo,&ModeIdIndex);
  1830.    if(temp == 0)  return(0);
  1831.    /* TW: Determine VBType (301,301B,301LV,302B,302LV) */
  1832.    SiS_GetVBType(SiS_Pr, BaseAddr,HwDeviceExtension);
  1833.    /* TW: Get VB information (connectors, connected devices) */
  1834.    SiS_GetVBInfo(SiS_Pr, BaseAddr,ROMAddr,ModeNo,ModeIdIndex,HwDeviceExtension);
  1835.    SiS_SetHiVision(SiS_Pr, BaseAddr,HwDeviceExtension);
  1836.    SiS_GetLCDResInfo(SiS_Pr, ROMAddr,ModeNo,ModeIdIndex,HwDeviceExtension);
  1837.    /* TW: I am not sure the flag's name is correct */
  1838.    if(HwDeviceExtension->jChipType >= SIS_315H) {
  1839.       if(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x17) & 0x08)  {
  1840.           if(ModeNo != 0x10)  SiS_Pr->SiS_SetFlag |= CRT2IsVGA;
  1841.       }
  1842.    }
  1843.    /* TW: Set mode on CRT1 */
  1844.    SiS_SetCRT1Group(SiS_Pr, ROMAddr,HwDeviceExtension,ModeNo,ModeIdIndex,BaseAddr);
  1845.    pSiSEnt->CRT1ModeNo = ModeNo;
  1846.    pSiSEnt->CRT1DMode = mode;
  1847.    /* TW: SetPitch: Adapt to virtual size & position */
  1848.    if(ModeNo > 0x13) {
  1849.       SiS_SetPitchCRT1(SiS_Pr, pScrn, BaseAddr);
  1850.    }
  1851.    /* We have to reset CRT2 if changing mode on CRT1 */
  1852.    if(pSiSEnt->CRT2ModeNo != -1) {
  1853.         xf86DrvMsg(pScrn->scrnIndex, X_INFO, "(Re-)Setting mode 0x%x on CRT2n",
  1854. pSiSEnt->CRT2ModeNo);
  1855. SiSBIOSSetModeCRT2(SiS_Pr, HwDeviceExtension, pSiSEnt->pScrn_1,
  1856. pSiSEnt->CRT2DMode);
  1857.    }
  1858.    if((HwDeviceExtension->jChipType > SIS_315PRO) && (SiS_Pr->SiS_IF_DEF_LVDS == 0)) {
  1859.       /* TW: *** For 650 only! *** */
  1860.       SiS_HandleCRT1(SiS_Pr);
  1861.    }
  1862.    SiS_DisplayOn(SiS_Pr);
  1863.    SiS_SetReg3(SiS_Pr->SiS_P3c6,0xFF);
  1864.    if((HwDeviceExtension->jChipType >= SIS_315H) && (SiS_Pr->SiS_IF_DEF_LVDS == 0)) {
  1865.       if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) {
  1866.           SiS_Handle301B_1400x1050(SiS_Pr, ModeNo);
  1867.       }
  1868.    }
  1869.    /* Backup/Set ModeNo in MMIO */
  1870.    SiS_GetSetModeID(pScrn,ModeNo);
  1871.    return TRUE;
  1872. }
  1873. /* TW: Set CRT2 mode (used for dual head) */
  1874. BOOLEAN
  1875. SiSBIOSSetModeCRT2(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension, ScrnInfoPtr pScrn,
  1876.                DisplayModePtr mode)
  1877. {
  1878.    ULONG   temp;
  1879.    USHORT  ModeIdIndex;
  1880.    UCHAR  *ROMAddr  = HwDeviceExtension->pjVirtualRomBase;
  1881.    USHORT  BaseAddr = (USHORT)HwDeviceExtension->ulIOAddress;
  1882.    UShort  ModeNo   = 0;
  1883.    SISPtr  pSiS     = SISPTR(pScrn);
  1884.    SISEntPtr pSiSEnt = pSiS->entityPrivate;
  1885.    ModeNo = SiS_CalcModeIndex(pScrn, mode);
  1886.    if(!ModeNo) return FALSE;
  1887.    SiSInitPtr(SiS_Pr, HwDeviceExtension);
  1888.    SiSRegInit(SiS_Pr, BaseAddr);
  1889.    SiS_Pr->SiS_VGAINFO = SiS_GetSetMMIOReg(pScrn, 0x489, 0xff);
  1890.    SiSInitPCIetc(SiS_Pr, HwDeviceExtension);
  1891.    SiSSetLVDSetc(SiS_Pr, HwDeviceExtension, ModeNo);
  1892.    SiSDetermineROMUsage(SiS_Pr, HwDeviceExtension, ROMAddr);
  1893.    /* TW: We don't clear the buffer under X */
  1894.    SiS_Pr->SiS_flag_clearbuffer=0;
  1895.    /* TW: Save ModeNo so we can set it from within SetMode for CRT1 */
  1896.    pSiSEnt->CRT2ModeNo = ModeNo;
  1897.    pSiSEnt->CRT2DMode = mode;
  1898.    /* TW: We can't set CRT2 mode before CRT1 mode is set */
  1899.    if(pSiSEnt->CRT1ModeNo == -1) {
  1900.     xf86DrvMsg(pScrn->scrnIndex, X_INFO,
  1901. "Setting CRT2 mode delayed until after setting CRT1 moden");
  1902.     return TRUE;
  1903.    }
  1904.    xf86DrvMsg(pScrn->scrnIndex, X_INFO, "Setting mode 0x%x on CRT2n", ModeNo);
  1905.    /* 1.Openkey */
  1906.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x05,0x86);
  1907.    SiS_UnLockCRT2(SiS_Pr, HwDeviceExtension, BaseAddr);
  1908.    /* 2.Get ModeID */
  1909.    temp = SiS_SearchModeID(SiS_Pr, ROMAddr,&ModeNo,&ModeIdIndex);
  1910.    if(temp == 0)  return(0);
  1911.    /* TW: Determine VBType (301,301B,301LV,302B,302LV) */
  1912.    SiS_GetVBType(SiS_Pr, BaseAddr,HwDeviceExtension);
  1913.    /* TW: Get VB information (connectors, connected devices) */
  1914.    SiS_GetVBInfo(SiS_Pr, BaseAddr,ROMAddr,ModeNo,ModeIdIndex,HwDeviceExtension);
  1915.    SiS_SetHiVision(SiS_Pr, BaseAddr,HwDeviceExtension);
  1916.    SiS_GetLCDResInfo(SiS_Pr, ROMAddr,ModeNo,ModeIdIndex,HwDeviceExtension);
  1917.    if(HwDeviceExtension->jChipType >= SIS_315H) {
  1918.       if(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x17) & 0x08)  {
  1919.           /* TW: I am not sure the flag's name is correct */
  1920.           if(ModeNo != 0x10)  SiS_Pr->SiS_SetFlag |= CRT2IsVGA;
  1921.       }
  1922.    }
  1923.    /* Set mode on CRT2 */
  1924.    switch (HwDeviceExtension->ujVBChipID) {
  1925.      case VB_CHIP_301:
  1926.      case VB_CHIP_301B:
  1927.      case VB_CHIP_301LV:
  1928.      case VB_CHIP_301LVX:
  1929.      case VB_CHIP_302:
  1930.      case VB_CHIP_302B:
  1931.      case VB_CHIP_302LV:
  1932.      case VB_CHIP_302LVX:
  1933.         SiS_SetCRT2Group301(SiS_Pr, BaseAddr,ROMAddr,ModeNo,HwDeviceExtension);
  1934.         break;
  1935.      case VB_CHIP_303:
  1936.         break;
  1937.      case VB_CHIP_UNKNOWN:
  1938.         if (SiS_Pr->SiS_IF_DEF_LVDS == 1 || SiS_Pr->SiS_IF_DEF_CH70xx == 1 ||
  1939.                                                SiS_Pr->SiS_IF_DEF_TRUMPION != 0)
  1940.               SiS_SetCRT2Group301(SiS_Pr,BaseAddr,ROMAddr,ModeNo,HwDeviceExtension);
  1941.         break;
  1942.    }
  1943.    SiS_DisplayOn(SiS_Pr);
  1944.    SiS_SetReg3(SiS_Pr->SiS_P3c6,0xFF);
  1945.    if((HwDeviceExtension->jChipType >= SIS_315H) && (SiS_Pr->SiS_IF_DEF_LVDS == 0)) {
  1946.       if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) {
  1947.           SiS_Handle301B_1400x1050(SiS_Pr, ModeNo);
  1948.       }
  1949.    }
  1950.    /* TW: SetPitch: Adapt to virtual size & position */
  1951.    if(ModeNo > 0x13) {
  1952.        SiS_SetPitchCRT2(SiS_Pr, pScrn, BaseAddr);
  1953.    }
  1954.    return TRUE;
  1955. }
  1956. #endif /* Dualhead */
  1957. #endif /* Linux_XF86 */
  1958. #ifdef LINUX_XF86
  1959. /* TW: We need pScrn for setting the pitch correctly */
  1960. BOOLEAN
  1961. SiSSetMode(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,ScrnInfoPtr pScrn,USHORT ModeNo, BOOLEAN dosetpitch)
  1962. #else
  1963. BOOLEAN
  1964. SiSSetMode(SiS_Private *SiS_Pr, PSIS_HW_DEVICE_INFO HwDeviceExtension,USHORT ModeNo)
  1965. #endif
  1966. {
  1967.    ULONG   temp;
  1968.    USHORT  ModeIdIndex,KeepLockReg;
  1969.    UCHAR  *ROMAddr  = HwDeviceExtension->pjVirtualRomBase;
  1970.    USHORT  BaseAddr = (USHORT)HwDeviceExtension->ulIOAddress;
  1971.    SiSInitPtr(SiS_Pr, HwDeviceExtension);
  1972.    SiSRegInit(SiS_Pr, BaseAddr);
  1973. #ifdef LINUX_XF86
  1974.    if(pScrn) SiS_Pr->SiS_VGAINFO = SiS_GetSetMMIOReg(pScrn, 0x489, 0xff);
  1975.    else
  1976. #endif
  1977.          SiS_Pr->SiS_VGAINFO = 0x11;
  1978.    SiSInitPCIetc(SiS_Pr, HwDeviceExtension);
  1979.    SiSSetLVDSetc(SiS_Pr, HwDeviceExtension, ModeNo);
  1980.    SiSDetermineROMUsage(SiS_Pr, HwDeviceExtension, ROMAddr);
  1981.    /* TW: Shift the clear-buffer-bit away */
  1982.    ModeNo = ((ModeNo & 0x80) << 8) | (ModeNo & 0x7f);
  1983. #ifdef LINUX_XF86
  1984.    /* TW: We never clear the buffer in X */
  1985.    ModeNo |= 0x8000;
  1986. #endif
  1987.    if(ModeNo & 0x8000) {
  1988.       ModeNo &= 0x007F;
  1989.       SiS_Pr->SiS_flag_clearbuffer = 0;
  1990.    } else {
  1991.       SiS_Pr->SiS_flag_clearbuffer = 1;
  1992.    }
  1993.    /* 1.Openkey */
  1994.    KeepLockReg = SiS_GetReg1(SiS_Pr->SiS_P3c4,0x05);
  1995.    SiS_SetReg1(SiS_Pr->SiS_P3c4,0x05,0x86);
  1996.    SiS_UnLockCRT2(SiS_Pr, HwDeviceExtension, BaseAddr);
  1997.    /* 2.Get ModeID Table  */
  1998.    temp = SiS_SearchModeID(SiS_Pr,ROMAddr,&ModeNo,&ModeIdIndex);
  1999.    if(temp == 0) return(0);
  2000.    /* TW: Determine VBType (301,301B,301LV,302B,302LV) */
  2001.    SiS_GetVBType(SiS_Pr,BaseAddr,HwDeviceExtension);
  2002.    /* TW: Init/restore some VB registers */
  2003.    if(HwDeviceExtension->jChipType >= SIS_315H) {
  2004.       if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
  2005.          if(ROMAddr && SiS_Pr->SiS_UseROM) {
  2006.            temp = ROMAddr[VB310Data_1_2_Offset];
  2007.    temp |= 0x40;
  2008.            SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x02,temp);
  2009.    SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x32,0x10);
  2010.          }
  2011.       }
  2012.    }
  2013.    /* TW: Get VB information (connectors, connected devices) */
  2014.    SiS_GetVBInfo(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex,HwDeviceExtension);
  2015.    SiS_SetHiVision(SiS_Pr,BaseAddr,HwDeviceExtension);
  2016.    SiS_GetLCDResInfo(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,HwDeviceExtension);
  2017.    /* 3. Check memory size */
  2018.    temp = SiS_CheckMemorySize(SiS_Pr,ROMAddr,HwDeviceExtension,ModeNo,ModeIdIndex);
  2019.    if(!temp) return(0);
  2020.    if(HwDeviceExtension->jChipType >= SIS_315H) {
  2021.       if(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x17) & 0x08)  {
  2022.           /* TW: I am not sure the flag's name is correct */
  2023.           if(ModeNo != 0x10)  SiS_Pr->SiS_SetFlag |= CRT2IsVGA;
  2024.       }
  2025.    }
  2026.    /* TW: Set mode on CRT1 */
  2027.    if(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) {
  2028.     SiS_SetCRT1Group(SiS_Pr,ROMAddr,HwDeviceExtension,ModeNo,ModeIdIndex,BaseAddr);
  2029.    } else {
  2030.      if(!(SiS_Pr->SiS_VBInfo & SwitchToCRT2)) {
  2031.         SiS_SetCRT1Group(SiS_Pr,ROMAddr,HwDeviceExtension,ModeNo,ModeIdIndex,BaseAddr);
  2032.      }
  2033.    }
  2034.    /* TW: Set mode on CRT2 */
  2035.    if(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchToCRT2 | SetCRT2ToLCDA)) {
  2036.      switch (HwDeviceExtension->ujVBChipID) {
  2037.      case VB_CHIP_301:
  2038.      case VB_CHIP_301B:
  2039.      case VB_CHIP_301LV:
  2040.      case VB_CHIP_301LVX:
  2041.      case VB_CHIP_302:
  2042.      case VB_CHIP_302B:
  2043.      case VB_CHIP_302LV:
  2044.      case VB_CHIP_302LVX:
  2045.         SiS_SetCRT2Group301(SiS_Pr,BaseAddr,ROMAddr,ModeNo,HwDeviceExtension);
  2046.         break;
  2047.      case VB_CHIP_303:
  2048.         break;
  2049.      case VB_CHIP_UNKNOWN:
  2050. if(SiS_Pr->SiS_IF_DEF_LVDS == 1   ||
  2051.    SiS_Pr->SiS_IF_DEF_CH70xx != 0 ||
  2052.    SiS_Pr->SiS_IF_DEF_TRUMPION != 0)
  2053.               SiS_SetCRT2Group301(SiS_Pr,BaseAddr,ROMAddr,ModeNo,HwDeviceExtension);
  2054.         break;
  2055.      }
  2056.    }
  2057.    if((HwDeviceExtension->jChipType > SIS_315PRO) && (SiS_Pr->SiS_IF_DEF_LVDS == 0)) {
  2058.       /* TW: For 650 only! */
  2059.       SiS_HandleCRT1(SiS_Pr);
  2060.    }
  2061.    SiS_DisplayOn(SiS_Pr);
  2062.    SiS_SetReg3(SiS_Pr->SiS_P3c6,0xFF);
  2063.    if((HwDeviceExtension->jChipType >= SIS_315H) && (SiS_Pr->SiS_IF_DEF_LVDS == 0)) {
  2064.       if(SiS_Pr->SiS_LCDResInfo == SiS_Pr->SiS_Panel1400x1050) {
  2065.           SiS_Handle301B_1400x1050(SiS_Pr, ModeNo);
  2066.       }
  2067.    }
  2068. #ifdef LINUX_XF86
  2069.    if(pScrn) {
  2070.       /* TW: SetPitch: Adapt to virtual size & position */
  2071.       if((ModeNo > 0x13) && (dosetpitch)) {
  2072.          SiS_SetPitch(SiS_Pr, pScrn, BaseAddr);
  2073.       }
  2074.       /* Backup/Set ModeNo in MMIO */
  2075.       SiS_GetSetModeID(pScrn, ModeNo);
  2076.    }
  2077. #endif
  2078. #ifndef LINUX_XF86  /* TW: We never lock registers in XF86 */
  2079.    if(KeepLockReg == 0xA1) SiS_SetReg1(SiS_Pr->SiS_P3c4,0x05,0x86);
  2080.    else SiS_SetReg1(SiS_Pr->SiS_P3c4,0x05,0x00);
  2081. #endif
  2082.    return TRUE;
  2083. }
  2084. void
  2085. SetEnableDstn(SiS_Private *SiS_Pr) /* TW: Called from sis_main.c */
  2086. {
  2087.    /* For 550 dstn */
  2088.    SiS_Pr->SiS_IF_DEF_DSTN = 1;
  2089. }
  2090. void
  2091. SiS_HandleCRT1(SiS_Private *SiS_Pr)
  2092. {
  2093.   /* TW: Do this on 650 only! */
  2094.   /* TW: No, we don't do this at all. There is a new
  2095.    * CRT1-is-connected-at-boot-time logic in the 650, which
  2096.    * confuses our own. So just clear the bit and skip the rest.
  2097.    */
  2098.   SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x63,0xbf);
  2099. #if 0
  2100.   if(!(SiS_GetReg1(SiS_Pr->SiS_P3c4,0x15) & 0x01))
  2101.      SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x63,0x40);
  2102.   }
  2103. #endif
  2104. }
  2105. void
  2106. SiS_Handle301B_1400x1050(SiS_Private *SiS_Pr, USHORT ModeNo)
  2107. {
  2108.   if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x30) & SetCRT2ToLCD) {
  2109.      if(ModeNo <= 0x13) {
  2110.         if(SiS_GetReg1(SiS_Pr->SiS_P3d4,0x31) & (SetNotSimuMode >> 8)) {
  2111.    SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x38,0xFC);
  2112. }
  2113.      }
  2114.   }
  2115. }
  2116. void
  2117. SiS_SetCRT1Group(SiS_Private *SiS_Pr, UCHAR *ROMAddr,PSIS_HW_DEVICE_INFO HwDeviceExtension,
  2118.                  USHORT ModeNo,USHORT ModeIdIndex,USHORT BaseAddr)
  2119. {
  2120.   USHORT  StandTableIndex,RefreshRateTableIndex;
  2121.   SiS_Pr->SiS_CRT1Mode = ModeNo;
  2122.   StandTableIndex = SiS_GetModePtr(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex);
  2123.   if(SiS_LowModeStuff(SiS_Pr,ModeNo,HwDeviceExtension)) {
  2124.     if(SiS_Pr->SiS_VBInfo & (SetSimuScanMode | SwitchToCRT2)) {
  2125.        SiS_DisableBridge(SiS_Pr,HwDeviceExtension,BaseAddr);
  2126.     }
  2127.   }
  2128.   SiS_SetSeqRegs(SiS_Pr,ROMAddr,StandTableIndex);
  2129.   SiS_SetMiscRegs(SiS_Pr,ROMAddr,StandTableIndex);
  2130.   SiS_SetCRTCRegs(SiS_Pr,ROMAddr,HwDeviceExtension,StandTableIndex);
  2131.   SiS_SetATTRegs(SiS_Pr,ROMAddr,StandTableIndex,ModeNo,HwDeviceExtension);
  2132.   SiS_SetGRCRegs(SiS_Pr,ROMAddr,StandTableIndex);
  2133.   SiS_ClearExt1Regs(SiS_Pr,HwDeviceExtension);
  2134.   SiS_ResetCRT1VCLK(SiS_Pr,ROMAddr,HwDeviceExtension);