init.c 163 KB
Newer Older
1
/* $XFree86$ */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
2
/*
3 4
 * Mode initializing code (CRT1 section) for
 * for SiS 300/305/540/630/730 and
5
 *     SiS 315/550/650/M650/651/661FX/M661FX/740/741/M741/330/660/M660/760/M760
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
6 7
 * (Universal module for Linux kernel framebuffer and XFree86 4.x)
 *
8
 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
9
 *
10 11
 * If distributed as part of the Linux kernel, the following license terms
 * apply:
12
 *
13 14 15 16 17 18 19 20 21 22 23 24 25
 * * This program is free software; you can redistribute it and/or modify
 * * it under the terms of the GNU General Public License as published by
 * * the Free Software Foundation; either version 2 of the named License,
 * * or any later version.
 * *
 * * This program is distributed in the hope that it will be useful,
 * * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * * GNU General Public License for more details.
 * *
 * * You should have received a copy of the GNU General Public License
 * * along with this program; if not, write to the Free Software
 * * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
26
 *
27
 * Otherwise, the following license terms apply:
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
28
 *
29 30 31 32 33 34 35 36
 * * Redistribution and use in source and binary forms, with or without
 * * modification, are permitted provided that the following conditions
 * * are met:
 * * 1) Redistributions of source code must retain the above copyright
 * *    notice, this list of conditions and the following disclaimer.
 * * 2) Redistributions in binary form must reproduce the above copyright
 * *    notice, this list of conditions and the following disclaimer in the
 * *    documentation and/or other materials provided with the distribution.
37
 * * 3) The name of the author may not be used to endorse or promote products
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
 * *    derived from this software without specific prior written permission.
 * *
 * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESSED OR
 * * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Author: 	Thomas Winischhofer <thomas@winischhofer.net>
 *
 * Formerly based on non-functional code-fragements for 300 series by SiS, Inc.
 * Used by permission.
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
 *
 * TW says: This code looks awful, I know. But please don't do anything about
 * this otherwise debugging will be hell.
 * The code is extremely fragile as regards the different chipsets, different
 * video bridges and combinations thereof. If anything is changed, extreme
 * care has to be taken that that change doesn't break it for other chipsets,
 * bridges or combinations thereof.
 * All comments in this file are by me, regardless if they are marked TW or not.
 *
 */
 
#include "init.h"

#ifdef SIS300
#include "300vtbl.h"
#endif

#ifdef SIS315H
#include "310vtbl.h"
#endif

#if defined(ALLOC_PRAGMA)
#pragma alloc_text(PAGE,SiSSetMode)
#endif

80 81 82
/*********************************************/
/*         POINTER INITIALIZATION            */
/*********************************************/
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
83 84

static void
85
InitCommonPointer(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
86
{
87 88 89 90
   SiS_Pr->SiS_StResInfo     = SiS_StResInfo;
   SiS_Pr->SiS_ModeResInfo   = SiS_ModeResInfo;
   SiS_Pr->SiS_StandTable    = SiS_StandTable;

91 92 93 94 95 96 97 98 99 100 101
   SiS_Pr->SiS_NTSCPhase     = SiS_NTSCPhase;
   SiS_Pr->SiS_PALPhase      = SiS_PALPhase;
   SiS_Pr->SiS_NTSCPhase2    = SiS_NTSCPhase2;
   SiS_Pr->SiS_PALPhase2     = SiS_PALPhase2;
   SiS_Pr->SiS_PALMPhase     = SiS_PALMPhase;
   SiS_Pr->SiS_PALNPhase     = SiS_PALNPhase;
   SiS_Pr->SiS_PALMPhase2    = SiS_PALMPhase2;
   SiS_Pr->SiS_PALNPhase2    = SiS_PALNPhase2;
   SiS_Pr->SiS_SpecialPhase  = SiS_SpecialPhase;
   SiS_Pr->SiS_SpecialPhaseM = SiS_SpecialPhaseM;
   SiS_Pr->SiS_SpecialPhaseJ = SiS_SpecialPhaseJ;
102 103 104 105 106

   SiS_Pr->SiS_NTSCTiming     = SiS_NTSCTiming;
   SiS_Pr->SiS_PALTiming      = SiS_PALTiming;
   SiS_Pr->SiS_HiTVSt1Timing  = SiS_HiTVSt1Timing;
   SiS_Pr->SiS_HiTVSt2Timing  = SiS_HiTVSt2Timing;
107

108 109 110
   SiS_Pr->SiS_HiTVExtTiming  = SiS_HiTVExtTiming;
   SiS_Pr->SiS_HiTVGroup3Data = SiS_HiTVGroup3Data;
   SiS_Pr->SiS_HiTVGroup3Simu = SiS_HiTVGroup3Simu;
111 112
#if 0
   SiS_Pr->SiS_HiTVTextTiming = SiS_HiTVTextTiming;
113
   SiS_Pr->SiS_HiTVGroup3Text = SiS_HiTVGroup3Text;
114
#endif
115 116 117 118 119

   SiS_Pr->SiS_StPALData   = SiS_StPALData;
   SiS_Pr->SiS_ExtPALData  = SiS_ExtPALData;
   SiS_Pr->SiS_StNTSCData  = SiS_StNTSCData;
   SiS_Pr->SiS_ExtNTSCData = SiS_ExtNTSCData;
120
   SiS_Pr->SiS_St1HiTVData = SiS_StHiTVData; 
121 122
   SiS_Pr->SiS_St2HiTVData = SiS_St2HiTVData;
   SiS_Pr->SiS_ExtHiTVData = SiS_ExtHiTVData;
123 124 125 126 127 128
   SiS_Pr->SiS_St525iData  = SiS_StNTSCData;
   SiS_Pr->SiS_St525pData  = SiS_St525pData;
   SiS_Pr->SiS_St750pData  = SiS_St750pData;
   SiS_Pr->SiS_Ext525iData = SiS_ExtNTSCData;
   SiS_Pr->SiS_Ext525pData = SiS_ExtNTSCData;
   SiS_Pr->SiS_Ext750pData = SiS_Ext750pData;
129 130 131 132

   SiS_Pr->pSiS_OutputSelect = &SiS_OutputSelect;
   SiS_Pr->pSiS_SoftSetting  = &SiS_SoftSetting;

133 134 135 136 137
   SiS_Pr->SiS_LCD1280x720Data      = SiS_LCD1280x720Data;
   SiS_Pr->SiS_StLCD1280x768_2Data  = SiS_StLCD1280x768_2Data;
   SiS_Pr->SiS_ExtLCD1280x768_2Data = SiS_ExtLCD1280x768_2Data;
   SiS_Pr->SiS_LCD1280x768_3Data    = SiS_LCD1280x768_3Data;
   SiS_Pr->SiS_LCD1280x800Data      = SiS_LCD1280x800Data;
138 139
   SiS_Pr->SiS_LCD1280x960Data      = SiS_LCD1280x960Data;
   SiS_Pr->SiS_StLCD1400x1050Data   = SiS_StLCD1400x1050Data;
140 141
   SiS_Pr->SiS_ExtLCD1400x1050Data  = SiS_ExtLCD1400x1050Data;
   SiS_Pr->SiS_LCD1680x1050Data     = SiS_LCD1680x1050Data;
142
   SiS_Pr->SiS_StLCD1600x1200Data   = SiS_StLCD1600x1200Data;
143
   SiS_Pr->SiS_ExtLCD1600x1200Data  = SiS_ExtLCD1600x1200Data;
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
   SiS_Pr->SiS_NoScaleData          = SiS_NoScaleData;

   SiS_Pr->SiS_LVDS320x480Data_1   = SiS_LVDS320x480Data_1;
   SiS_Pr->SiS_LVDS800x600Data_1   = SiS_LVDS800x600Data_1;
   SiS_Pr->SiS_LVDS800x600Data_2   = SiS_LVDS800x600Data_2;
   SiS_Pr->SiS_LVDS1024x768Data_1  = SiS_LVDS1024x768Data_1;
   SiS_Pr->SiS_LVDS1024x768Data_2  = SiS_LVDS1024x768Data_2;
   SiS_Pr->SiS_LVDS1280x1024Data_1 = SiS_LVDS1280x1024Data_1;
   SiS_Pr->SiS_LVDS1280x1024Data_2 = SiS_LVDS1280x1024Data_2;
   SiS_Pr->SiS_LVDS1400x1050Data_1 = SiS_LVDS1400x1050Data_1;
   SiS_Pr->SiS_LVDS1400x1050Data_2 = SiS_LVDS1400x1050Data_2;
   SiS_Pr->SiS_LVDS1600x1200Data_1 = SiS_LVDS1600x1200Data_1;
   SiS_Pr->SiS_LVDS1600x1200Data_2 = SiS_LVDS1600x1200Data_2;
   SiS_Pr->SiS_LVDS1280x768Data_1  = SiS_LVDS1280x768Data_1;
   SiS_Pr->SiS_LVDS1280x768Data_2  = SiS_LVDS1280x768Data_2;
   SiS_Pr->SiS_LVDS1024x600Data_1  = SiS_LVDS1024x600Data_1;
   SiS_Pr->SiS_LVDS1024x600Data_2  = SiS_LVDS1024x600Data_2;
   SiS_Pr->SiS_LVDS1152x768Data_1  = SiS_LVDS1152x768Data_1;
   SiS_Pr->SiS_LVDS1152x768Data_2  = SiS_LVDS1152x768Data_2;
   SiS_Pr->SiS_LVDSXXXxXXXData_1   = SiS_LVDSXXXxXXXData_1;
   SiS_Pr->SiS_LVDS1280x960Data_1  = SiS_LVDS1280x960Data_1;
   SiS_Pr->SiS_LVDS1280x960Data_2  = SiS_LVDS1280x960Data_2;
   SiS_Pr->SiS_LVDS640x480Data_1   = SiS_LVDS640x480Data_1;
   SiS_Pr->SiS_LVDS1280x960Data_1  = SiS_LVDS1280x1024Data_1;
   SiS_Pr->SiS_LVDS1280x960Data_2  = SiS_LVDS1280x1024Data_2;
   SiS_Pr->SiS_LVDS640x480Data_1   = SiS_LVDS640x480Data_1;
   SiS_Pr->SiS_LVDS640x480Data_2   = SiS_LVDS640x480Data_2;

   SiS_Pr->SiS_LVDS848x480Data_1   = SiS_LVDS848x480Data_1;
   SiS_Pr->SiS_LVDS848x480Data_2   = SiS_LVDS848x480Data_2;
174 175 176 177
   SiS_Pr->SiS_LVDSBARCO1024Data_1 = SiS_LVDSBARCO1024Data_1;
   SiS_Pr->SiS_LVDSBARCO1024Data_2 = SiS_LVDSBARCO1024Data_2;
   SiS_Pr->SiS_LVDSBARCO1366Data_1 = SiS_LVDSBARCO1366Data_1;
   SiS_Pr->SiS_LVDSBARCO1366Data_2 = SiS_LVDSBARCO1366Data_2;
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197

   SiS_Pr->SiS_LVDSCRT11280x768_1    = SiS_LVDSCRT11280x768_1;
   SiS_Pr->SiS_LVDSCRT11024x600_1    = SiS_LVDSCRT11024x600_1;
   SiS_Pr->SiS_LVDSCRT11152x768_1    = SiS_LVDSCRT11152x768_1;
   SiS_Pr->SiS_LVDSCRT11280x768_1_H  = SiS_LVDSCRT11280x768_1_H;
   SiS_Pr->SiS_LVDSCRT11024x600_1_H  = SiS_LVDSCRT11024x600_1_H;
   SiS_Pr->SiS_LVDSCRT11152x768_1_H  = SiS_LVDSCRT11152x768_1_H;
   SiS_Pr->SiS_LVDSCRT11280x768_2    = SiS_LVDSCRT11280x768_2;
   SiS_Pr->SiS_LVDSCRT11024x600_2    = SiS_LVDSCRT11024x600_2;
   SiS_Pr->SiS_LVDSCRT11152x768_2    = SiS_LVDSCRT11152x768_2;
   SiS_Pr->SiS_LVDSCRT11280x768_2_H  = SiS_LVDSCRT11280x768_2_H;
   SiS_Pr->SiS_LVDSCRT11024x600_2_H  = SiS_LVDSCRT11024x600_2_H;
   SiS_Pr->SiS_LVDSCRT11152x768_2_H  = SiS_LVDSCRT11152x768_2_H;
   SiS_Pr->SiS_LVDSCRT1320x480_1     = SiS_LVDSCRT1320x480_1;
   SiS_Pr->SiS_LVDSCRT1640x480_1     = SiS_LVDSCRT1640x480_1;
   SiS_Pr->SiS_LVDSCRT1640x480_1_H   = SiS_LVDSCRT1640x480_1_H;
   SiS_Pr->SiS_LVDSCRT1640x480_2     = SiS_LVDSCRT1640x480_2;
   SiS_Pr->SiS_LVDSCRT1640x480_2_H   = SiS_LVDSCRT1640x480_2_H;
   SiS_Pr->SiS_LVDSCRT1640x480_3     = SiS_LVDSCRT1640x480_3;
   SiS_Pr->SiS_LVDSCRT1640x480_3_H   = SiS_LVDSCRT1640x480_3_H;
198 199 200 201 202 203 204 205 206 207 208

   SiS_Pr->SiS_CHTVUNTSCData = SiS_CHTVUNTSCData;
   SiS_Pr->SiS_CHTVONTSCData = SiS_CHTVONTSCData;

   SiS_Pr->SiS_CHTVUNTSCDesData = SiS_CHTVUNTSCDesData;
   SiS_Pr->SiS_CHTVONTSCDesData = SiS_CHTVONTSCDesData;
   SiS_Pr->SiS_CHTVUPALDesData  = SiS_CHTVUPALDesData;
   SiS_Pr->SiS_CHTVOPALDesData  = SiS_CHTVOPALDesData;

   SiS_Pr->SiS_PanelMinLVDS   = Panel_800x600;    /* lowest value LVDS/LCDA */
   SiS_Pr->SiS_PanelMin301    = Panel_1024x768;   /* lowest value 301 */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
209 210 211 212
}

#ifdef SIS300
static void
213
InitTo300Pointer(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
214
{
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
   InitCommonPointer(SiS_Pr, HwInfo);

   SiS_StandTable[0x04].CRTC[4] = 0x2b;
   SiS_StandTable[0x05].CRTC[4] = 0x2b;
   SiS_StandTable[0x06].CRTC[4] = 0x54;
   SiS_StandTable[0x06].CRTC[5] = 0x80;
   SiS_StandTable[0x0d].CRTC[4] = 0x2b;
   SiS_StandTable[0x0e].CRTC[4] = 0x54;
   SiS_StandTable[0x0e].CRTC[5] = 0x80;
   SiS_StandTable[0x11].CRTC[4] = 0x54;
   SiS_StandTable[0x11].CRTC[5] = 0x80;
   SiS_StandTable[0x11].CRTC[16] = 0x83;
   SiS_StandTable[0x11].CRTC[17] = 0x85;
   SiS_StandTable[0x12].CRTC[4] = 0x54;
   SiS_StandTable[0x12].CRTC[5] = 0x80;
   SiS_StandTable[0x12].CRTC[16] = 0x83;
   SiS_StandTable[0x12].CRTC[17] = 0x85;
   SiS_StandTable[0x13].CRTC[5] = 0xa0;
   SiS_StandTable[0x17].CRTC[5] = 0xa0;
   SiS_StandTable[0x1a].CRTC[4] = 0x54;
   SiS_StandTable[0x1a].CRTC[5] = 0x80;
   SiS_StandTable[0x1a].CRTC[16] = 0xea;
   SiS_StandTable[0x1a].CRTC[17] = 0x8c;
   SiS_StandTable[0x1b].CRTC[4] = 0x54;
   SiS_StandTable[0x1b].CRTC[5] = 0x80;
   SiS_StandTable[0x1b].CRTC[16] = 0xea;
   SiS_StandTable[0x1b].CRTC[17] = 0x8c;
   SiS_StandTable[0x1c].CRTC[4] = 0x54;
   SiS_StandTable[0x1c].CRTC[5] = 0x80;

245 246 247 248 249
   SiS_Pr->SiS_SModeIDTable  = SiS300_SModeIDTable;
   SiS_Pr->SiS_VBModeIDTable = SiS300_VBModeIDTable;
   SiS_Pr->SiS_EModeIDTable  = SiS300_EModeIDTable;
   SiS_Pr->SiS_RefIndex      = SiS300_RefIndex;
   SiS_Pr->SiS_CRT1Table     = SiS300_CRT1Table;
250
   if(HwInfo->jChipType == SIS_300) {
251
      SiS_Pr->SiS_MCLKData_0    = SiS300_MCLKData_300; /* 300 */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
252
   } else {
253
      SiS_Pr->SiS_MCLKData_0    = SiS300_MCLKData_630; /* 630, 730 */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
254
   }
255
   SiS_Pr->SiS_VCLKData      = SiS300_VCLKData;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
   SiS_Pr->SiS_VBVCLKData    = (SiS_VBVCLKDataStruct *)SiS300_VCLKData;

   SiS_Pr->SiS_SR15  = SiS300_SR15;

#ifndef LINUX_XF86
   SiS_Pr->pSiS_SR07 = &SiS300_SR07;
   SiS_Pr->SiS_CR40  = SiS300_CR40;
   SiS_Pr->SiS_CR49  = SiS300_CR49;
   SiS_Pr->pSiS_SR1F = &SiS300_SR1F;
   SiS_Pr->pSiS_SR21 = &SiS300_SR21;
   SiS_Pr->pSiS_SR22 = &SiS300_SR22;
   SiS_Pr->pSiS_SR23 = &SiS300_SR23;
   SiS_Pr->pSiS_SR24 = &SiS300_SR24;
   SiS_Pr->SiS_SR25  = SiS300_SR25;
   SiS_Pr->pSiS_SR31 = &SiS300_SR31;
   SiS_Pr->pSiS_SR32 = &SiS300_SR32;
   SiS_Pr->pSiS_SR33 = &SiS300_SR33;
   SiS_Pr->pSiS_CRT2Data_1_2  = &SiS300_CRT2Data_1_2;
   SiS_Pr->pSiS_CRT2Data_4_D  = &SiS300_CRT2Data_4_D;
   SiS_Pr->pSiS_CRT2Data_4_E  = &SiS300_CRT2Data_4_E;
   SiS_Pr->pSiS_CRT2Data_4_10 = &SiS300_CRT2Data_4_10;
   SiS_Pr->pSiS_RGBSenseData    = &SiS300_RGBSenseData;
   SiS_Pr->pSiS_VideoSenseData  = &SiS300_VideoSenseData;
   SiS_Pr->pSiS_YCSenseData     = &SiS300_YCSenseData;
   SiS_Pr->pSiS_RGBSenseData2   = &SiS300_RGBSenseData2;
   SiS_Pr->pSiS_VideoSenseData2 = &SiS300_VideoSenseData2;
   SiS_Pr->pSiS_YCSenseData2    = &SiS300_YCSenseData2;
#endif

285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341
   SiS_Pr->SiS_PanelDelayTbl     = SiS300_PanelDelayTbl;
   SiS_Pr->SiS_PanelDelayTblLVDS = SiS300_PanelDelayTbl;

   SiS_Pr->SiS_ExtLCD1024x768Data   = SiS300_ExtLCD1024x768Data;
   SiS_Pr->SiS_St2LCD1024x768Data   = SiS300_St2LCD1024x768Data;
   SiS_Pr->SiS_ExtLCD1280x1024Data  = SiS300_ExtLCD1280x1024Data;
   SiS_Pr->SiS_St2LCD1280x1024Data  = SiS300_St2LCD1280x1024Data;

   SiS_Pr->SiS_CRT2Part2_1024x768_1  = SiS300_CRT2Part2_1024x768_1;
   SiS_Pr->SiS_CRT2Part2_1280x1024_1 = SiS300_CRT2Part2_1280x1024_1;
   SiS_Pr->SiS_CRT2Part2_1024x768_2  = SiS300_CRT2Part2_1024x768_2;
   SiS_Pr->SiS_CRT2Part2_1280x1024_2 = SiS300_CRT2Part2_1280x1024_2;
   SiS_Pr->SiS_CRT2Part2_1024x768_3  = SiS300_CRT2Part2_1024x768_3;
   SiS_Pr->SiS_CRT2Part2_1280x1024_3 = SiS300_CRT2Part2_1280x1024_3;

   SiS_Pr->SiS_CHTVUPALData  = SiS300_CHTVUPALData;
   SiS_Pr->SiS_CHTVOPALData  = SiS300_CHTVOPALData;
   SiS_Pr->SiS_CHTVUPALMData = SiS_CHTVUNTSCData;    /* not supported on 300 series */
   SiS_Pr->SiS_CHTVOPALMData = SiS_CHTVONTSCData;    /* not supported on 300 series */
   SiS_Pr->SiS_CHTVUPALNData = SiS300_CHTVUPALData;  /* not supported on 300 series */
   SiS_Pr->SiS_CHTVOPALNData = SiS300_CHTVOPALData;  /* not supported on 300 series */
   SiS_Pr->SiS_CHTVSOPALData = SiS300_CHTVSOPALData;

   SiS_Pr->SiS_PanelType00_1 = SiS300_PanelType00_1;
   SiS_Pr->SiS_PanelType01_1 = SiS300_PanelType01_1;
   SiS_Pr->SiS_PanelType02_1 = SiS300_PanelType02_1;
   SiS_Pr->SiS_PanelType03_1 = SiS300_PanelType03_1;
   SiS_Pr->SiS_PanelType04_1 = SiS300_PanelType04_1;
   SiS_Pr->SiS_PanelType05_1 = SiS300_PanelType05_1;
   SiS_Pr->SiS_PanelType06_1 = SiS300_PanelType06_1;
   SiS_Pr->SiS_PanelType07_1 = SiS300_PanelType07_1;
   SiS_Pr->SiS_PanelType08_1 = SiS300_PanelType08_1;
   SiS_Pr->SiS_PanelType09_1 = SiS300_PanelType09_1;
   SiS_Pr->SiS_PanelType0a_1 = SiS300_PanelType0a_1;
   SiS_Pr->SiS_PanelType0b_1 = SiS300_PanelType0b_1;
   SiS_Pr->SiS_PanelType0c_1 = SiS300_PanelType0c_1;
   SiS_Pr->SiS_PanelType0d_1 = SiS300_PanelType0d_1;
   SiS_Pr->SiS_PanelType0e_1 = SiS300_PanelType0e_1;
   SiS_Pr->SiS_PanelType0f_1 = SiS300_PanelType0f_1;
   SiS_Pr->SiS_PanelType00_2 = SiS300_PanelType00_2;
   SiS_Pr->SiS_PanelType01_2 = SiS300_PanelType01_2;
   SiS_Pr->SiS_PanelType02_2 = SiS300_PanelType02_2;
   SiS_Pr->SiS_PanelType03_2 = SiS300_PanelType03_2;
   SiS_Pr->SiS_PanelType04_2 = SiS300_PanelType04_2;
   SiS_Pr->SiS_PanelType05_2 = SiS300_PanelType05_2;
   SiS_Pr->SiS_PanelType06_2 = SiS300_PanelType06_2;
   SiS_Pr->SiS_PanelType07_2 = SiS300_PanelType07_2;
   SiS_Pr->SiS_PanelType08_2 = SiS300_PanelType08_2;
   SiS_Pr->SiS_PanelType09_2 = SiS300_PanelType09_2;
   SiS_Pr->SiS_PanelType0a_2 = SiS300_PanelType0a_2;
   SiS_Pr->SiS_PanelType0b_2 = SiS300_PanelType0b_2;
   SiS_Pr->SiS_PanelType0c_2 = SiS300_PanelType0c_2;
   SiS_Pr->SiS_PanelType0d_2 = SiS300_PanelType0d_2;
   SiS_Pr->SiS_PanelType0e_2 = SiS300_PanelType0e_2;
   SiS_Pr->SiS_PanelType0f_2 = SiS300_PanelType0f_2;
   SiS_Pr->SiS_PanelTypeNS_1 = SiS300_PanelTypeNS_1;
   SiS_Pr->SiS_PanelTypeNS_2 = SiS300_PanelTypeNS_2;
342 343

   if(SiS_Pr->SiS_CustomT == CUT_BARCO1366) {
344 345
      SiS_Pr->SiS_PanelType04_1 = SiS300_PanelType04_1a;
      SiS_Pr->SiS_PanelType04_2 = SiS300_PanelType04_2a;
346 347
   }
   if(SiS_Pr->SiS_CustomT == CUT_BARCO1024) {
348 349
      SiS_Pr->SiS_PanelType04_1 = SiS300_PanelType04_1b;
      SiS_Pr->SiS_PanelType04_2 = SiS300_PanelType04_2b;
350 351
   }

352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380
   SiS_Pr->SiS_LVDSCRT1800x600_1     = SiS300_LVDSCRT1800x600_1;
   SiS_Pr->SiS_LVDSCRT1800x600_1_H   = SiS300_LVDSCRT1800x600_1_H;
   SiS_Pr->SiS_LVDSCRT1800x600_2     = SiS300_LVDSCRT1800x600_2;
   SiS_Pr->SiS_LVDSCRT1800x600_2_H   = SiS300_LVDSCRT1800x600_2_H;
   SiS_Pr->SiS_LVDSCRT11024x768_1    = SiS300_LVDSCRT11024x768_1;
   SiS_Pr->SiS_LVDSCRT11024x768_1_H  = SiS300_LVDSCRT11024x768_1_H;
   SiS_Pr->SiS_LVDSCRT11024x768_2    = SiS300_LVDSCRT11024x768_2;
   SiS_Pr->SiS_LVDSCRT11024x768_2_H  = SiS300_LVDSCRT11024x768_2_H;
   SiS_Pr->SiS_LVDSCRT11280x1024_1   = SiS300_LVDSCRT11280x1024_1;
   SiS_Pr->SiS_LVDSCRT11280x1024_1_H = SiS300_LVDSCRT11280x1024_1_H;
   SiS_Pr->SiS_LVDSCRT11280x1024_2   = SiS300_LVDSCRT11280x1024_2;
   SiS_Pr->SiS_LVDSCRT11280x1024_2_H = SiS300_LVDSCRT11280x1024_2_H;
   SiS_Pr->SiS_LVDSCRT1XXXxXXX_1     = SiS300_LVDSCRT1XXXxXXX_1;
   SiS_Pr->SiS_LVDSCRT1XXXxXXX_1_H   = SiS300_LVDSCRT1XXXxXXX_1_H;

   SiS_Pr->SiS_CHTVCRT1UNTSC = SiS300_CHTVCRT1UNTSC;
   SiS_Pr->SiS_CHTVCRT1ONTSC = SiS300_CHTVCRT1ONTSC;
   SiS_Pr->SiS_CHTVCRT1UPAL  = SiS300_CHTVCRT1UPAL;
   SiS_Pr->SiS_CHTVCRT1OPAL  = SiS300_CHTVCRT1OPAL;
   SiS_Pr->SiS_CHTVCRT1SOPAL = SiS300_CHTVCRT1SOPAL;
   SiS_Pr->SiS_CHTVReg_UNTSC = SiS300_CHTVReg_UNTSC;
   SiS_Pr->SiS_CHTVReg_ONTSC = SiS300_CHTVReg_ONTSC;
   SiS_Pr->SiS_CHTVReg_UPAL  = SiS300_CHTVReg_UPAL;
   SiS_Pr->SiS_CHTVReg_OPAL  = SiS300_CHTVReg_OPAL;
   SiS_Pr->SiS_CHTVReg_UPALM = SiS300_CHTVReg_UNTSC;  /* not supported on 300 series */
   SiS_Pr->SiS_CHTVReg_OPALM = SiS300_CHTVReg_ONTSC;  /* not supported on 300 series */
   SiS_Pr->SiS_CHTVReg_UPALN = SiS300_CHTVReg_UPAL;   /* not supported on 300 series */
   SiS_Pr->SiS_CHTVReg_OPALN = SiS300_CHTVReg_OPAL;   /* not supported on 300 series */
   SiS_Pr->SiS_CHTVReg_SOPAL = SiS300_CHTVReg_SOPAL;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
381 382 383 384 385 386 387 388 389 390 391 392 393 394
   SiS_Pr->SiS_CHTVVCLKUNTSC = SiS300_CHTVVCLKUNTSC;
   SiS_Pr->SiS_CHTVVCLKONTSC = SiS300_CHTVVCLKONTSC;
   SiS_Pr->SiS_CHTVVCLKUPAL  = SiS300_CHTVVCLKUPAL;
   SiS_Pr->SiS_CHTVVCLKOPAL  = SiS300_CHTVVCLKOPAL;
   SiS_Pr->SiS_CHTVVCLKUPALM = SiS300_CHTVVCLKUNTSC;  /* not supported on 300 series */
   SiS_Pr->SiS_CHTVVCLKOPALM = SiS300_CHTVVCLKONTSC;  /* not supported on 300 series */
   SiS_Pr->SiS_CHTVVCLKUPALN = SiS300_CHTVVCLKUPAL;   /* not supported on 300 series */
   SiS_Pr->SiS_CHTVVCLKOPALN = SiS300_CHTVVCLKOPAL;   /* not supported on 300 series */
   SiS_Pr->SiS_CHTVVCLKSOPAL = SiS300_CHTVVCLKSOPAL;
}
#endif

#ifdef SIS315H
static void
395
InitTo310Pointer(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
396
{
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
   InitCommonPointer(SiS_Pr, HwInfo);

   SiS_StandTable[0x04].CRTC[4] = 0x2c;
   SiS_StandTable[0x05].CRTC[4] = 0x2c;
   SiS_StandTable[0x06].CRTC[4] = 0x55;
   SiS_StandTable[0x06].CRTC[5] = 0x81;
   SiS_StandTable[0x0d].CRTC[4] = 0x2c;
   SiS_StandTable[0x0e].CRTC[4] = 0x55;
   SiS_StandTable[0x0e].CRTC[5] = 0x81;
   SiS_StandTable[0x11].CRTC[4] = 0x55;
   SiS_StandTable[0x11].CRTC[5] = 0x81;
   SiS_StandTable[0x11].CRTC[16] = 0x82;
   SiS_StandTable[0x11].CRTC[17] = 0x84;
   SiS_StandTable[0x12].CRTC[4] = 0x55;
   SiS_StandTable[0x12].CRTC[5] = 0x81;
   SiS_StandTable[0x12].CRTC[16] = 0x82;
   SiS_StandTable[0x12].CRTC[17] = 0x84;
   SiS_StandTable[0x13].CRTC[5] = 0xb1;
   SiS_StandTable[0x17].CRTC[5] = 0xb1;
   SiS_StandTable[0x1a].CRTC[4] = 0x55;
   SiS_StandTable[0x1a].CRTC[5] = 0x81;
   SiS_StandTable[0x1a].CRTC[16] = 0xe9;
   SiS_StandTable[0x1a].CRTC[17] = 0x8b;
   SiS_StandTable[0x1b].CRTC[4] = 0x55;
   SiS_StandTable[0x1b].CRTC[5] = 0x81;
   SiS_StandTable[0x1b].CRTC[16] = 0xe9;
   SiS_StandTable[0x1b].CRTC[17] = 0x8b;
   SiS_StandTable[0x1c].CRTC[4] = 0x55;
   SiS_StandTable[0x1c].CRTC[5] = 0x81;

427 428
   SiS_Pr->SiS_SModeIDTable  = SiS310_SModeIDTable;
   SiS_Pr->SiS_EModeIDTable  = SiS310_EModeIDTable;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
429
   SiS_Pr->SiS_RefIndex      = (SiS_Ext2Struct *)SiS310_RefIndex;
430 431 432 433 434
   SiS_Pr->SiS_CRT1Table     = SiS310_CRT1Table;
   if(HwInfo->jChipType >= SIS_760) {
      SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_760;  /* 760 */
   } else if(HwInfo->jChipType >= SIS_661) {
      SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_660;  /* 661/741 */
435
   } else if(HwInfo->jChipType == SIS_330) {
436
      SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_330;  /* 330 */
437
   } else if(HwInfo->jChipType > SIS_315PRO) {
438
      SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_650;  /* 550, 650, 740 */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
439
   } else {
440
      SiS_Pr->SiS_MCLKData_0 = SiS310_MCLKData_0_315;  /* 315 */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
441
   }
442 443 444
   SiS_Pr->SiS_MCLKData_1    = SiS310_MCLKData_1;
   SiS_Pr->SiS_VCLKData      = SiS310_VCLKData;
   SiS_Pr->SiS_VBVCLKData    = SiS310_VBVCLKData;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472

   SiS_Pr->SiS_SR15  = SiS310_SR15;

#ifndef LINUX_XF86
   SiS_Pr->pSiS_SR07 = &SiS310_SR07;
   SiS_Pr->SiS_CR40  = SiS310_CR40;
   SiS_Pr->SiS_CR49  = SiS310_CR49;
   SiS_Pr->pSiS_SR1F = &SiS310_SR1F;
   SiS_Pr->pSiS_SR21 = &SiS310_SR21;
   SiS_Pr->pSiS_SR22 = &SiS310_SR22;
   SiS_Pr->pSiS_SR23 = &SiS310_SR23;
   SiS_Pr->pSiS_SR24 = &SiS310_SR24;
   SiS_Pr->SiS_SR25  = SiS310_SR25;
   SiS_Pr->pSiS_SR31 = &SiS310_SR31;
   SiS_Pr->pSiS_SR32 = &SiS310_SR32;
   SiS_Pr->pSiS_SR33 = &SiS310_SR33;
   SiS_Pr->pSiS_CRT2Data_1_2  = &SiS310_CRT2Data_1_2;
   SiS_Pr->pSiS_CRT2Data_4_D  = &SiS310_CRT2Data_4_D;
   SiS_Pr->pSiS_CRT2Data_4_E  = &SiS310_CRT2Data_4_E;
   SiS_Pr->pSiS_CRT2Data_4_10 = &SiS310_CRT2Data_4_10;
   SiS_Pr->pSiS_RGBSenseData    = &SiS310_RGBSenseData;
   SiS_Pr->pSiS_VideoSenseData  = &SiS310_VideoSenseData;
   SiS_Pr->pSiS_YCSenseData     = &SiS310_YCSenseData;
   SiS_Pr->pSiS_RGBSenseData2   = &SiS310_RGBSenseData2;
   SiS_Pr->pSiS_VideoSenseData2 = &SiS310_VideoSenseData2;
   SiS_Pr->pSiS_YCSenseData2    = &SiS310_YCSenseData2;
#endif

473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562
   SiS_Pr->SiS_PanelDelayTbl     = SiS310_PanelDelayTbl;
   SiS_Pr->SiS_PanelDelayTblLVDS = SiS310_PanelDelayTblLVDS;

   SiS_Pr->SiS_St2LCD1024x768Data   = SiS310_St2LCD1024x768Data;
   SiS_Pr->SiS_ExtLCD1024x768Data   = SiS310_ExtLCD1024x768Data;
   SiS_Pr->SiS_St2LCD1280x1024Data  = SiS310_St2LCD1280x1024Data;
   SiS_Pr->SiS_ExtLCD1280x1024Data  = SiS310_ExtLCD1280x1024Data;

   SiS_Pr->SiS_CRT2Part2_1024x768_1  = SiS310_CRT2Part2_1024x768_1;

   SiS_Pr->SiS_PanelType00_1 = SiS310_PanelType00_1;
   SiS_Pr->SiS_PanelType01_1 = SiS310_PanelType01_1;
   SiS_Pr->SiS_PanelType02_1 = SiS310_PanelType02_1;
   SiS_Pr->SiS_PanelType03_1 = SiS310_PanelType03_1;
   SiS_Pr->SiS_PanelType04_1 = SiS310_PanelType04_1;
   SiS_Pr->SiS_PanelType05_1 = SiS310_PanelType05_1;
   SiS_Pr->SiS_PanelType06_1 = SiS310_PanelType06_1;
   SiS_Pr->SiS_PanelType07_1 = SiS310_PanelType07_1;
   SiS_Pr->SiS_PanelType08_1 = SiS310_PanelType08_1;
   SiS_Pr->SiS_PanelType09_1 = SiS310_PanelType09_1;
   SiS_Pr->SiS_PanelType0a_1 = SiS310_PanelType0a_1;
   SiS_Pr->SiS_PanelType0b_1 = SiS310_PanelType0b_1;
   SiS_Pr->SiS_PanelType0c_1 = SiS310_PanelType0c_1;
   SiS_Pr->SiS_PanelType0d_1 = SiS310_PanelType0d_1;
   SiS_Pr->SiS_PanelType0e_1 = SiS310_PanelType0e_1;
   SiS_Pr->SiS_PanelType0f_1 = SiS310_PanelType0f_1;
   SiS_Pr->SiS_PanelType00_2 = SiS310_PanelType00_2;
   SiS_Pr->SiS_PanelType01_2 = SiS310_PanelType01_2;
   SiS_Pr->SiS_PanelType02_2 = SiS310_PanelType02_2;
   SiS_Pr->SiS_PanelType03_2 = SiS310_PanelType03_2;
   SiS_Pr->SiS_PanelType04_2 = SiS310_PanelType04_2;
   SiS_Pr->SiS_PanelType05_2 = SiS310_PanelType05_2;
   SiS_Pr->SiS_PanelType06_2 = SiS310_PanelType06_2;
   SiS_Pr->SiS_PanelType07_2 = SiS310_PanelType07_2;
   SiS_Pr->SiS_PanelType08_2 = SiS310_PanelType08_2;
   SiS_Pr->SiS_PanelType09_2 = SiS310_PanelType09_2;
   SiS_Pr->SiS_PanelType0a_2 = SiS310_PanelType0a_2;
   SiS_Pr->SiS_PanelType0b_2 = SiS310_PanelType0b_2;
   SiS_Pr->SiS_PanelType0c_2 = SiS310_PanelType0c_2;
   SiS_Pr->SiS_PanelType0d_2 = SiS310_PanelType0d_2;
   SiS_Pr->SiS_PanelType0e_2 = SiS310_PanelType0e_2;
   SiS_Pr->SiS_PanelType0f_2 = SiS310_PanelType0f_2;
   SiS_Pr->SiS_PanelTypeNS_1 = SiS310_PanelTypeNS_1;
   SiS_Pr->SiS_PanelTypeNS_2 = SiS310_PanelTypeNS_2;

   SiS_Pr->SiS_CHTVUPALData  = SiS310_CHTVUPALData;
   SiS_Pr->SiS_CHTVOPALData  = SiS310_CHTVOPALData;
   SiS_Pr->SiS_CHTVUPALMData = SiS310_CHTVUPALMData;
   SiS_Pr->SiS_CHTVOPALMData = SiS310_CHTVOPALMData;
   SiS_Pr->SiS_CHTVUPALNData = SiS310_CHTVUPALNData;
   SiS_Pr->SiS_CHTVOPALNData = SiS310_CHTVOPALNData;
   SiS_Pr->SiS_CHTVSOPALData = SiS310_CHTVSOPALData;

   SiS_Pr->SiS_LVDSCRT1800x600_1     = SiS310_LVDSCRT1800x600_1;
   SiS_Pr->SiS_LVDSCRT11024x768_1    = SiS310_LVDSCRT11024x768_1;
   SiS_Pr->SiS_LVDSCRT11280x1024_1   = SiS310_LVDSCRT11280x1024_1;
   SiS_Pr->SiS_LVDSCRT11400x1050_1   = SiS310_LVDSCRT11400x1050_1;
   SiS_Pr->SiS_LVDSCRT11600x1200_1   = SiS310_LVDSCRT11600x1200_1;
   SiS_Pr->SiS_LVDSCRT1800x600_1_H   = SiS310_LVDSCRT1800x600_1_H;
   SiS_Pr->SiS_LVDSCRT11024x768_1_H  = SiS310_LVDSCRT11024x768_1_H;
   SiS_Pr->SiS_LVDSCRT11280x1024_1_H = SiS310_LVDSCRT11280x1024_1_H;
   SiS_Pr->SiS_LVDSCRT11400x1050_1_H = SiS310_LVDSCRT11400x1050_1_H;
   SiS_Pr->SiS_LVDSCRT11600x1200_1_H = SiS310_LVDSCRT11600x1200_1_H;
   SiS_Pr->SiS_LVDSCRT1800x600_2     = SiS310_LVDSCRT1800x600_2;
   SiS_Pr->SiS_LVDSCRT11024x768_2    = SiS310_LVDSCRT11024x768_2;
   SiS_Pr->SiS_LVDSCRT11280x1024_2   = SiS310_LVDSCRT11280x1024_2;
   SiS_Pr->SiS_LVDSCRT11400x1050_2   = SiS310_LVDSCRT11400x1050_2;
   SiS_Pr->SiS_LVDSCRT11600x1200_2   = SiS310_LVDSCRT11600x1200_2;
   SiS_Pr->SiS_LVDSCRT1800x600_2_H   = SiS310_LVDSCRT1800x600_2_H;
   SiS_Pr->SiS_LVDSCRT11024x768_2_H  = SiS310_LVDSCRT11024x768_2_H;
   SiS_Pr->SiS_LVDSCRT11280x1024_2_H = SiS310_LVDSCRT11280x1024_2_H;
   SiS_Pr->SiS_LVDSCRT11400x1050_2_H = SiS310_LVDSCRT11400x1050_2_H;
   SiS_Pr->SiS_LVDSCRT11600x1200_2_H = SiS310_LVDSCRT11600x1200_2_H;
   SiS_Pr->SiS_LVDSCRT1XXXxXXX_1     = SiS310_LVDSCRT1XXXxXXX_1;
   SiS_Pr->SiS_LVDSCRT1XXXxXXX_1_H   = SiS310_LVDSCRT1XXXxXXX_1_H;
   SiS_Pr->SiS_CHTVCRT1UNTSC         = SiS310_CHTVCRT1UNTSC;
   SiS_Pr->SiS_CHTVCRT1ONTSC         = SiS310_CHTVCRT1ONTSC;
   SiS_Pr->SiS_CHTVCRT1UPAL          = SiS310_CHTVCRT1UPAL;
   SiS_Pr->SiS_CHTVCRT1OPAL          = SiS310_CHTVCRT1OPAL;
   SiS_Pr->SiS_CHTVCRT1SOPAL         = SiS310_CHTVCRT1OPAL;

   SiS_Pr->SiS_CHTVReg_UNTSC = SiS310_CHTVReg_UNTSC;
   SiS_Pr->SiS_CHTVReg_ONTSC = SiS310_CHTVReg_ONTSC;
   SiS_Pr->SiS_CHTVReg_UPAL  = SiS310_CHTVReg_UPAL;
   SiS_Pr->SiS_CHTVReg_OPAL  = SiS310_CHTVReg_OPAL;
   SiS_Pr->SiS_CHTVReg_UPALM = SiS310_CHTVReg_UPALM;
   SiS_Pr->SiS_CHTVReg_OPALM = SiS310_CHTVReg_OPALM;
   SiS_Pr->SiS_CHTVReg_UPALN = SiS310_CHTVReg_UPALN;
   SiS_Pr->SiS_CHTVReg_OPALN = SiS310_CHTVReg_OPALN;
   SiS_Pr->SiS_CHTVReg_SOPAL = SiS310_CHTVReg_OPAL;
563

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
564 565 566 567 568 569 570
   SiS_Pr->SiS_CHTVVCLKUNTSC = SiS310_CHTVVCLKUNTSC;
   SiS_Pr->SiS_CHTVVCLKONTSC = SiS310_CHTVVCLKONTSC;
   SiS_Pr->SiS_CHTVVCLKUPAL  = SiS310_CHTVVCLKUPAL;
   SiS_Pr->SiS_CHTVVCLKOPAL  = SiS310_CHTVVCLKOPAL;
   SiS_Pr->SiS_CHTVVCLKUPALM = SiS310_CHTVVCLKUPALM;
   SiS_Pr->SiS_CHTVVCLKOPALM = SiS310_CHTVVCLKOPALM;
   SiS_Pr->SiS_CHTVVCLKUPALN = SiS310_CHTVVCLKUPALN;
571
   SiS_Pr->SiS_CHTVVCLKOPALN = SiS310_CHTVVCLKOPALN;
572
   SiS_Pr->SiS_CHTVVCLKSOPAL = SiS310_CHTVVCLKOPAL;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
573 574 575
}
#endif

576 577
static void
SiSInitPtr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
578
{
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
   switch(HwInfo->jChipType) {
#ifdef SIS315H
   case SIS_315H:
   case SIS_315:
   case SIS_315PRO:
   case SIS_550:
   case SIS_650:
   case SIS_740:
   case SIS_330:
   case SIS_661:
   case SIS_741:
   case SIS_660:
   case SIS_760:
      InitTo310Pointer(SiS_Pr, HwInfo);
      break;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
594 595
#endif
#ifdef SIS300
596 597 598 599 600 601
   case SIS_300:
   case SIS_540:
   case SIS_630:
   case SIS_730:
      InitTo300Pointer(SiS_Pr, HwInfo);
      break;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
602
#endif
603 604 605 606
   default:
      break;
   }
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
607

608 609 610
/*********************************************/
/*            HELPER: Get ModeID             */
/*********************************************/
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
611

612
USHORT
613 614
SiS_GetModeID(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay,
              int Depth, BOOLEAN FSTN, int LCDwidth, int LCDheight)
615 616
{
   USHORT ModeIndex = 0;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
617

618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681
   switch(HDisplay)
   {
     case 320:
     	  if(VDisplay == 200)     ModeIndex = ModeIndex_320x200[Depth];
	  else if(VDisplay == 240) {
	     if(FSTN) ModeIndex = ModeIndex_320x240_FSTN[Depth];
	     else     ModeIndex = ModeIndex_320x240[Depth];
          }
          break;
     case 400:
          if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
          break;
     case 512:
          if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
          break;
     case 640:
          if(VDisplay == 480)      ModeIndex = ModeIndex_640x480[Depth];
	  else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
          break;
     case 720:
          if(!(VBFlags & CRT1_LCDA)) {
             if(VDisplay == 480)      ModeIndex = ModeIndex_720x480[Depth];
             else if(VDisplay == 576) ModeIndex = ModeIndex_720x576[Depth];
          }
          break;
     case 768:
          if(!(VBFlags & CRT1_LCDA)) {
             if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
          }
	  break;
     case 800:
	  if(VDisplay == 600)    ModeIndex = ModeIndex_800x600[Depth];
	  else if(!(VBFlags & CRT1_LCDA)) {
	     if(VDisplay == 480) ModeIndex = ModeIndex_800x480[Depth];
	  }
          break;
     case 848:
          if(!(VBFlags & CRT1_LCDA)) {
	     if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
	  }
	  break;
     case 856:
          if(!(VBFlags & CRT1_LCDA)) {
	     if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
	  }
	  break;
     case 1024:
          if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
	  else if(!(VBFlags & CRT1_LCDA)) {
	     if(VDisplay == 576)    ModeIndex = ModeIndex_1024x576[Depth];
	     else if(VGAEngine == SIS_300_VGA) {
	        if(VDisplay == 600) ModeIndex = ModeIndex_1024x600[Depth];
             }
	  }
          break;
     case 1152:
          if(!(VBFlags & CRT1_LCDA)) {
             if(VDisplay == 864)    ModeIndex = ModeIndex_1152x864[Depth];
             else if(VGAEngine == SIS_300_VGA) {
	        if(VDisplay == 768) ModeIndex = ModeIndex_1152x768[Depth];
             }
	  }
	  break;
     case 1280:
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
          if(VDisplay == 1024) ModeIndex = ModeIndex_1280x1024[Depth];
	  else if(VDisplay == 800) {
	     if(VGAEngine == SIS_315_VGA) {
	        if((VBFlags & CRT1_LCDA) && (LCDwidth == 1280) && (LCDheight == 800)) {
	           ModeIndex = ModeIndex_1280x800[Depth];
	        } else if(!(VBFlags & CRT1_LCDA)) {
	           ModeIndex = ModeIndex_1280x800[Depth];
	        }
	     }
	  } else if(VDisplay == 720) {
	     if((VBFlags & CRT1_LCDA) && (LCDwidth == 1280) && (LCDheight == 720)) {
	        ModeIndex = ModeIndex_1280x720[Depth];
	     } else if(!(VBFlags & CRT1_LCDA)) {
	        ModeIndex = ModeIndex_1280x720[Depth];
	     }
	  } else if(!(VBFlags & CRT1_LCDA)) {
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717
             if(VDisplay == 960)      ModeIndex = ModeIndex_1280x960[Depth];
	     else if(VDisplay == 768) {
	        if(VGAEngine == SIS_300_VGA) {
	           ModeIndex = ModeIndex_300_1280x768[Depth];
	        } else {
	           ModeIndex = ModeIndex_310_1280x768[Depth];
	        }
	     }
	  }
          break;
     case 1360:
          if(!(VBFlags & CRT1_LCDA)) {
	     if(VDisplay == 768)     ModeIndex = ModeIndex_1360x768[Depth];
	     else if(VGAEngine == SIS_300_VGA) {
	        if(VDisplay == 1024) ModeIndex = ModeIndex_300_1360x1024[Depth];
             }
	  }
          break;
     case 1400:
          if(VGAEngine == SIS_315_VGA) {
718 719 720 721 722 723 724 725 726
	     if(VDisplay == 1050) {
	        if((VBFlags & CRT1_LCDA) &&
	           (((LCDwidth == 1400) && (LCDheight == 1050)) ||
		    ((LCDwidth == 1600) && (LCDheight == 1200)))) {
	           ModeIndex = ModeIndex_1400x1050[Depth];
	        } else if(!(VBFlags & CRT1_LCDA)) {
	           ModeIndex = ModeIndex_1400x1050[Depth];
	        }
	     }
727 728 729 730 731
	  }
          break;
     case 1600:
          if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
          break;
732 733 734 735 736
     case 1680:
          if(VGAEngine == SIS_315_VGA) {
             if(VDisplay == 1050) ModeIndex = ModeIndex_1680x1050[Depth];
	  }
          break;
737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752
     case 1920:
          if(!(VBFlags & CRT1_LCDA)) {
             if(VDisplay == 1440) ModeIndex = ModeIndex_1920x1440[Depth];
	  }
          break;
     case 2048:
          if(!(VBFlags & CRT1_LCDA)) {
             if(VDisplay == 1536) {
                if(VGAEngine == SIS_300_VGA) {
	            ModeIndex = ModeIndex_300_2048x1536[Depth];
  	        } else {
	            ModeIndex = ModeIndex_310_2048x1536[Depth];
                }
	     }
	  }
          break;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
753 754
   }

755 756
   return(ModeIndex);
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
757

758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780
USHORT
SiS_GetModeID_LCD(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay,
                  int Depth, BOOLEAN FSTN, USHORT CustomT, int LCDwidth, int LCDheight)
{
   USHORT ModeIndex = 0;

   if(VBFlags & (VB_LVDS | VB_30xBDH)) {

      switch(HDisplay)
      {
	case 320:
	     if(CustomT != CUT_PANEL848) {
     	  	if(VDisplay == 200) ModeIndex = ModeIndex_320x200[Depth];
	  	else if(VDisplay == 240) {
		   if(!FSTN) ModeIndex = ModeIndex_320x240[Depth];
          	   else if(VGAEngine == SIS_315_VGA) {
                      ModeIndex = ModeIndex_320x240_FSTN[Depth];
		   }
		}
	     }
             break;
     	case 400:
	     if(CustomT != CUT_PANEL848) {
781 782 783
	        if(!((VGAEngine == SIS_300_VGA) && (VBFlags & VB_TRUMPION))) {
          	   if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
		}
784 785 786 787
	     }
             break;
	case 512:
	     if(CustomT != CUT_PANEL848) {
788
	        if(!((VGAEngine == SIS_300_VGA) && (VBFlags & VB_TRUMPION))) {
789
		   if(LCDwidth != 1024 || LCDheight != 600) {
790 791 792
		      if(VDisplay == 384) {
		         ModeIndex = ModeIndex_512x384[Depth];
		      }
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
		   }
		}
	     }
	     break;
	case 640:
	     if(VDisplay == 480)            ModeIndex = ModeIndex_640x480[Depth];
	     else if(VDisplay == 400) {
	        if(CustomT != CUT_PANEL848) ModeIndex = ModeIndex_640x400[Depth];
	     }
	     break;
	case 800:
	     if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
	     break;
	case 848:
	     if(CustomT == CUT_PANEL848) {
	        if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
	     }
	     break;
	case 1024:
	     if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
	     else if(VGAEngine == SIS_300_VGA) {
		if((VDisplay == 600) && (LCDheight == 600)) {
		   ModeIndex = ModeIndex_1024x600[Depth];
		}
	     }
	     break;
	case 1152:
	     if(VGAEngine == SIS_300_VGA) {
	        if((VDisplay == 768) && (LCDheight == 768)) {
		   ModeIndex = ModeIndex_1152x768[Depth];
		}
	     }
	     break;
        case 1280:
	     if(VDisplay == 1024) ModeIndex = ModeIndex_1280x1024[Depth];
	     else if(VGAEngine == SIS_315_VGA) {
	        if((VDisplay == 768) && (LCDheight == 768)) {
		   ModeIndex = ModeIndex_310_1280x768[Depth];
		}
832 833 834
		if((VDisplay == 800) && (LCDheight == 800)) {
		   ModeIndex = ModeIndex_310_1280x768[Depth];
		}
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856
	     }
	     break;
	case 1360:
	     if(VGAEngine == SIS_300_VGA) {
	        if(CustomT == CUT_BARCO1366) {
		   if(VDisplay == 1024) ModeIndex = ModeIndex_300_1360x1024[Depth];
		}
	     }
	     if(CustomT == CUT_PANEL848) {
	        if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
	     }
	     break;
	case 1400:
	     if(VGAEngine == SIS_315_VGA) {
	        if(VDisplay == 1050) ModeIndex = ModeIndex_1400x1050[Depth];
	     }
	     break;
	case 1600:
	     if(VGAEngine == SIS_315_VGA) {
	        if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
	     }
	     break;
857
      }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
858

859
   } else if(VBFlags & VB_SISBRIDGE) {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
860

861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885
      switch(HDisplay)
      {
	case 320:
     	     if(VDisplay == 200)      ModeIndex = ModeIndex_320x200[Depth];
	     else if(VDisplay == 240) ModeIndex = ModeIndex_320x240[Depth];
             break;
     	case 400:
             if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
             break;
	case 512:
	     if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
	     break;
	case 640:
	     if(VDisplay == 480)      ModeIndex = ModeIndex_640x480[Depth];
	     else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
	     break;
	case 800:
	     if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
	     break;
	case 1024:
	     if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
	     break;
	case 1280:
	     if(VDisplay == 1024) ModeIndex = ModeIndex_1280x1024[Depth];
	     else if(VDisplay == 768) {
886
		if((LCDheight == 768) || (LCDwidth == 1680) ||
887
		   ((LCDheight == 1024) && (VBFlags & (VB_301|VB_301B|VB_301C|VB_302B)))) {
888 889 890 891 892 893 894
		   if(VGAEngine == SIS_300_VGA) {
		      ModeIndex = ModeIndex_300_1280x768[Depth];
		   } else {
		      ModeIndex = ModeIndex_310_1280x768[Depth];
		   }
		}
	     } else if(VDisplay == 960) {
895 896
	        if((LCDheight == 960) ||
		   ((LCDheight == 1024) && (VBFlags & (VB_301|VB_301B|VB_301C|VB_302B)))) {
897 898
		   ModeIndex = ModeIndex_1280x960[Depth];
		}
899 900 901 902 903 904 905 906 907 908 909 910
	     } else if(VGAEngine == SIS_315_VGA) {
	        if(VDisplay == 800) {
		   if((LCDheight == 800) || (LCDwidth == 1680) ||
		      ((LCDheight == 1024) && (VBFlags & (VB_301|VB_301B|VB_301C|VB_302B)))) {
		      ModeIndex = ModeIndex_1280x800[Depth];
		   }
		} else if(VDisplay == 720) {
		   if((LCDheight == 720) || (LCDwidth == 1680) ||
		      ((LCDheight == 1024) && (VBFlags & (VB_301|VB_301B|VB_301C|VB_302B)))) {
		      ModeIndex = ModeIndex_1280x720[Depth];
		   }
		}
911 912 913 914 915
	     }
	     break;
	case 1400:
	     if(VGAEngine == SIS_315_VGA) {
	        if(VBFlags & (VB_301B | VB_301C | VB_302B | VB_302LV | VB_302ELV)) {
916 917
		   if((LCDwidth == 1400) || (LCDwidth == 1600) || (LCDwidth == 1680)) {
		      ModeIndex = ModeIndex_1400x1050[Depth];
918
		   }
919 920 921 922
		}
	     }
	     break;
	case 1600:
923 924 925 926 927 928 929 930 931 932 933
	     if(VGAEngine == SIS_315_VGA) {
	        if(VBFlags & (VB_301C | VB_302B | VB_302LV | VB_302ELV)) {
	           if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
		}
	     }
	     break;
	case 1680:
	     if(VGAEngine == SIS_315_VGA) {
	        if(VBFlags & (VB_301C | VB_302B | VB_302LV | VB_302ELV)) {
	           if(VDisplay == 1050) ModeIndex = ModeIndex_1680x1050[Depth];
		}
934 935 936 937
	     }
	     break;
      }
   }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
938

939 940
   return ModeIndex;
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
941

942 943 944 945
USHORT
SiS_GetModeID_TV(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int Depth)
{
   USHORT ModeIndex = 0;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
946

947
   if(VBFlags & VB_CHRONTEL) {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
948

949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968
      switch(HDisplay)
      {
      	case 512:
	     if(VGAEngine == SIS_315_VGA) {
		if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
	     }
	     break;
	case 640:
	     if(VDisplay == 480)      ModeIndex = ModeIndex_640x480[Depth];
	     else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
	     break;
	case 800:
	     if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
	     break;
	case 1024:
	     if(VGAEngine == SIS_315_VGA) {
	        if(VDisplay == 768) ModeIndex = ModeIndex_1024x768[Depth];
	     }
	     break;
      }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
969

970
   } else if(VBFlags & VB_SISTVBRIDGE) {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
971

972 973 974 975 976 977 978 979 980 981
      switch(HDisplay)
      {
	case 320:
     	     if(VDisplay == 200)      ModeIndex = ModeIndex_320x200[Depth];
	     else if(VDisplay == 240) ModeIndex = ModeIndex_320x240[Depth];
             break;
        case 400:
             if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
             break;
      	case 512:
982 983
	     if( ((VBFlags & TV_YPBPR) && (VBFlags & (TV_YPBPR750P | TV_YPBPR1080I))) ||
	         (VBFlags & TV_HIVISION) 					      ||
984
	         ((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) ) {
985 986 987 988 989 990 991 992
	        if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
	     }
	     break;
	case 640:
	     if(VDisplay == 480)      ModeIndex = ModeIndex_640x480[Depth];
	     else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
	     break;
	case 720:
993
	     if((!(VBFlags & TV_HIVISION)) && (!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)))) {
994
                if(VDisplay == 480) {
995
		   if((VBFlags & TV_YPBPR) || (VBFlags & (TV_NTSC | TV_PALM)))
996 997
                      ModeIndex = ModeIndex_720x480[Depth];
                } else if(VDisplay == 576) {
998
		   if((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL))
999 1000 1001 1002 1003
                      ModeIndex = ModeIndex_720x576[Depth];
                }
	     }
             break;
	case 768:
1004 1005
	     if((!(VBFlags & TV_HIVISION)) && (!((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I)))) {
	        if((!(VBFlags & (TV_YPBPR | TV_PALM))) && (VBFlags & TV_PAL)) {
1006 1007 1008 1009 1010 1011 1012
          	   if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
		}
             }
	     break;
	case 800:
	     if(VDisplay == 600) ModeIndex = ModeIndex_800x600[Depth];
	     else if(VDisplay == 480) {
1013 1014
	        if((VBFlags & TV_HIVISION) || ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I))) {
		   ModeIndex = ModeIndex_800x480[Depth];
1015 1016 1017 1018 1019 1020 1021 1022 1023
		}
	     }
	     break;
	case 1024:
	     if(VDisplay == 768) {
		if(VBFlags & (VB_301B|VB_301C|VB_302B|VB_301LV|VB_302LV|VB_302ELV)) {
		   ModeIndex = ModeIndex_1024x768[Depth];
		}
	     } else if(VDisplay == 576) {
1024
	        if((VBFlags & TV_HIVISION) || ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I))) {
1025 1026 1027 1028 1029
		   ModeIndex = ModeIndex_1024x576[Depth];
		}
	     }
	     break;
	case 1280:
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039
	     if(VDisplay == 720) {
	        if((VBFlags & TV_HIVISION) ||
		   ((VBFlags & TV_YPBPR) && (VBFlags & (TV_YPBPR1080I | TV_YPBPR750P)))) {
	           ModeIndex = ModeIndex_1280x720[Depth];
		}
	     } else if(VDisplay == 1024) {
	        if((VBFlags & TV_HIVISION) ||
		   ((VBFlags & TV_YPBPR) && (VBFlags & TV_YPBPR1080I))) {
	           ModeIndex = ModeIndex_1280x1024[Depth];
		}
1040 1041 1042
	     }
	     break;
      }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1043
   }
1044 1045
   return ModeIndex;
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1046

1047 1048 1049 1050
USHORT
SiS_GetModeID_VGA2(int VGAEngine, ULONG VBFlags, int HDisplay, int VDisplay, int Depth)
{
   USHORT ModeIndex = 0;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1051

1052
   if(!(VBFlags & (VB_301|VB_301B|VB_301C|VB_302B))) return 0;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1053

1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
   switch(HDisplay)
   {
	case 320:
     	  	if(VDisplay == 200)      ModeIndex = ModeIndex_320x200[Depth];
	  	else if(VDisplay == 240) ModeIndex = ModeIndex_320x240[Depth];
          	break;
     	case 400:
          	if(VDisplay == 300) ModeIndex = ModeIndex_400x300[Depth];
          	break;
  	case 512:
		if(VDisplay == 384) ModeIndex = ModeIndex_512x384[Depth];
		break;
	case 640:
		if(VDisplay == 480)      ModeIndex = ModeIndex_640x480[Depth];
		else if(VDisplay == 400) ModeIndex = ModeIndex_640x400[Depth];
		break;
	case 720:
		if(VDisplay == 480)      ModeIndex = ModeIndex_720x480[Depth];
		else if(VDisplay == 576) ModeIndex = ModeIndex_720x576[Depth];
		break;
	case 768:
          	if(VDisplay == 576) ModeIndex = ModeIndex_768x576[Depth];
	  	break;
	case 800:
		if(VDisplay == 600)      ModeIndex = ModeIndex_800x600[Depth];
   	        else if(VDisplay == 480) ModeIndex = ModeIndex_800x480[Depth];
		break;
	case 848:
		if(VDisplay == 480) ModeIndex = ModeIndex_848x480[Depth];
		break;
	case 856:
		if(VDisplay == 480) ModeIndex = ModeIndex_856x480[Depth];
		break;
	case 1024:
		if(VDisplay == 768)      ModeIndex = ModeIndex_1024x768[Depth];
		else if(VDisplay == 576) ModeIndex = ModeIndex_1024x576[Depth];
		break;
	case 1152:
	        if(VDisplay == 864)    ModeIndex = ModeIndex_1152x864[Depth];
		else if(VGAEngine == SIS_300_VGA) {
		   if(VDisplay == 768) ModeIndex = ModeIndex_1152x768[Depth];
		}
		break;
	case 1280:
	        if(VDisplay == 768) {
		   if(VGAEngine == SIS_300_VGA) {
		      ModeIndex = ModeIndex_300_1280x768[Depth];
		   } else {
		      ModeIndex = ModeIndex_310_1280x768[Depth];
		   }
		} else if(VDisplay == 1024) ModeIndex = ModeIndex_1280x1024[Depth];
		else if(VDisplay == 720)    ModeIndex = ModeIndex_1280x720[Depth];
1106
		else if(VDisplay == 800)    ModeIndex = ModeIndex_1280x800[Depth];
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123
		else if(VDisplay == 960)    ModeIndex = ModeIndex_1280x960[Depth];
		break;
        case 1360:
	        if(VDisplay == 768) ModeIndex = ModeIndex_1360x768[Depth];
                break;
        case 1400:
		if(VGAEngine == SIS_315_VGA) {
	           if(VDisplay == 1050) ModeIndex = ModeIndex_1400x1050[Depth];
		}
		break;
	case 1600:
		if(VGAEngine == SIS_315_VGA) {
		   if(VBFlags & (VB_301B|VB_301C|VB_302B)) {
	              if(VDisplay == 1200) ModeIndex = ModeIndex_1600x1200[Depth];
		   }
		}
		break;
1124 1125 1126 1127 1128 1129 1130
	case 1680:
		if(VGAEngine == SIS_315_VGA) {
		   if(VBFlags & (VB_301B|VB_301C|VB_302B)) {
	              if(VDisplay == 1050) ModeIndex = ModeIndex_1680x1050[Depth];
		   }
		}
		break;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1131 1132
   }

1133 1134
   return ModeIndex;
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1135 1136


1137 1138 1139
/*********************************************/
/*          HELPER: SetReg, GetReg           */
/*********************************************/
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1140

1141 1142 1143 1144 1145
void
SiS_SetReg(SISIOADDRESS port, USHORT index, USHORT data)
{
   OutPortByte(port,index);
   OutPortByte(port + 1,data);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1146 1147 1148
}

void
1149
SiS_SetRegByte(SISIOADDRESS port, USHORT data)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1150
{
1151
   OutPortByte(port,data);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1152 1153 1154
}

void
1155
SiS_SetRegShort(SISIOADDRESS port, USHORT data)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1156
{
1157
   OutPortWord(port,data);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1158 1159
}

1160 1161
void
SiS_SetRegLong(SISIOADDRESS port, ULONG data)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1162
{
1163
   OutPortLong(port,data);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1164 1165
}

1166 1167 1168 1169 1170 1171
UCHAR
SiS_GetReg(SISIOADDRESS port, USHORT index)
{
   OutPortByte(port,index);
   return(InPortByte(port + 1));
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1172

1173 1174 1175 1176 1177
UCHAR
SiS_GetRegByte(SISIOADDRESS port)
{
   return(InPortByte(port));
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1178

1179 1180
USHORT
SiS_GetRegShort(SISIOADDRESS port)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1181
{
1182
   return(InPortWord(port));
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1183 1184
}

1185 1186
ULONG
SiS_GetRegLong(SISIOADDRESS port)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1187
{
1188
   return(InPortLong(port));
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1189 1190 1191
}

void
1192
SiS_SetRegANDOR(SISIOADDRESS Port,USHORT Index,USHORT DataAND,USHORT DataOR)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1193
{
1194
  USHORT temp;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1195

1196 1197 1198 1199
  temp = SiS_GetReg(Port,Index);
  temp = (temp & (DataAND)) | DataOR;
  SiS_SetReg(Port,Index,temp);
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1200

1201 1202 1203 1204
void
SiS_SetRegAND(SISIOADDRESS Port,USHORT Index,USHORT DataAND)
{
  USHORT temp;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1205

1206 1207 1208
  temp = SiS_GetReg(Port,Index);
  temp &= DataAND;
  SiS_SetReg(Port,Index,temp);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1209 1210 1211
}

void
1212
SiS_SetRegOR(SISIOADDRESS Port,USHORT Index,USHORT DataOR)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1213
{
1214 1215 1216 1217 1218
  USHORT temp;

  temp = SiS_GetReg(Port,Index);
  temp |= DataOR;
  SiS_SetReg(Port,Index,temp);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1219 1220
}

1221 1222 1223 1224
/*********************************************/
/*      HELPER: DisplayOn, DisplayOff        */
/*********************************************/

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1225
void
1226
SiS_DisplayOn(SiS_Private *SiS_Pr)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1227
{
1228
   SiS_SetRegAND(SiS_Pr->SiS_P3c4,0x01,0xDF);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1229 1230 1231
}

void
1232
SiS_DisplayOff(SiS_Private *SiS_Pr)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1233
{
1234
   SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x01,0x20);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1235 1236
}

1237 1238 1239 1240 1241

/*********************************************/
/*        HELPER: Init Port Addresses        */
/*********************************************/

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1242
void
1243
SiSRegInit(SiS_Private *SiS_Pr, SISIOADDRESS BaseAddr)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1244
{
1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266
   SiS_Pr->SiS_P3c4 = BaseAddr + 0x14;
   SiS_Pr->SiS_P3d4 = BaseAddr + 0x24;
   SiS_Pr->SiS_P3c0 = BaseAddr + 0x10;
   SiS_Pr->SiS_P3ce = BaseAddr + 0x1e;
   SiS_Pr->SiS_P3c2 = BaseAddr + 0x12;
   SiS_Pr->SiS_P3ca = BaseAddr + 0x1a;
   SiS_Pr->SiS_P3c6 = BaseAddr + 0x16;
   SiS_Pr->SiS_P3c7 = BaseAddr + 0x17;
   SiS_Pr->SiS_P3c8 = BaseAddr + 0x18;
   SiS_Pr->SiS_P3c9 = BaseAddr + 0x19;
   SiS_Pr->SiS_P3cb = BaseAddr + 0x1b;
   SiS_Pr->SiS_P3cd = BaseAddr + 0x1d;
   SiS_Pr->SiS_P3da = BaseAddr + 0x2a;
   SiS_Pr->SiS_Part1Port = BaseAddr + SIS_CRT2_PORT_04;     /* Digital video interface registers (LCD) */
   SiS_Pr->SiS_Part2Port = BaseAddr + SIS_CRT2_PORT_10;     /* 301 TV Encoder registers */
   SiS_Pr->SiS_Part3Port = BaseAddr + SIS_CRT2_PORT_12;     /* 301 Macrovision registers */
   SiS_Pr->SiS_Part4Port = BaseAddr + SIS_CRT2_PORT_14;     /* 301 VGA2 (and LCD) registers */
   SiS_Pr->SiS_Part5Port = BaseAddr + SIS_CRT2_PORT_14 + 2; /* 301 palette address port registers */
   SiS_Pr->SiS_DDC_Port = BaseAddr + 0x14;                  /* DDC Port ( = P3C4, SR11/0A) */
   SiS_Pr->SiS_VidCapt = BaseAddr + SIS_VIDEO_CAPTURE;
   SiS_Pr->SiS_VidPlay = BaseAddr + SIS_VIDEO_PLAYBACK;
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1267

1268 1269 1270 1271 1272 1273 1274 1275 1276
/*********************************************/
/*             HELPER: GetSysFlags           */
/*********************************************/

static void
SiS_GetSysFlags(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
   unsigned char cr5f, temp1, temp2;

1277 1278 1279 1280 1281 1282 1283 1284 1285
   /* 661 and newer: NEVER write non-zero to SR11[7:4] */
   /* (SR11 is used for DDC and in enable/disablebridge) */
   SiS_Pr->SiS_SensibleSR11 = FALSE;
   SiS_Pr->SiS_MyCR63 = 0x63;
   if(HwInfo->jChipType >= SIS_661) {
      SiS_Pr->SiS_SensibleSR11 = TRUE;
      SiS_Pr->SiS_MyCR63 = 0x53;
   }

1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321
   /* You should use the macros, not these flags directly */

   SiS_Pr->SiS_SysFlags = 0;
   if(HwInfo->jChipType == SIS_650) {
      cr5f = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0;
      SiS_SetRegAND(SiS_Pr->SiS_P3d4,0x5c,0x07);
      temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
      SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x5c,0xf8);
      temp2 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
      if((!temp1) || (temp2)) {
         switch(cr5f) {
	    case 0x80:
	    case 0x90:
	    case 0xc0:
	       SiS_Pr->SiS_SysFlags |= SF_IsM650;  break;
	    case 0xa0:
	    case 0xb0:
	    case 0xe0:
	       SiS_Pr->SiS_SysFlags |= SF_Is651;   break;
	 }
      } else {
         switch(cr5f) {
	    case 0x90:
	       temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5c) & 0xf8;
	       switch(temp1) {
	          case 0x00: SiS_Pr->SiS_SysFlags |= SF_IsM652; break;
		  case 0x40: SiS_Pr->SiS_SysFlags |= SF_IsM653; break;
		  default:   SiS_Pr->SiS_SysFlags |= SF_IsM650; break;
	       }
	       break;
	    case 0xb0:
	       SiS_Pr->SiS_SysFlags |= SF_Is652;  break;
	    default:
	       SiS_Pr->SiS_SysFlags |= SF_IsM650; break;
	 }
      }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1322
   }
1323 1324 1325 1326
   if(HwInfo->jChipType == SIS_760) {
      temp1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x78);
      if(temp1 & 0x30) SiS_Pr->SiS_SysFlags |= SF_760UMA;
   }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1327 1328
}

1329 1330 1331 1332 1333 1334
/*********************************************/
/*         HELPER: Init PCI & Engines        */
/*********************************************/

static void
SiSInitPCIetc(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1335
{
1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378
   switch(HwInfo->jChipType) {
   case SIS_300:
   case SIS_540:
   case SIS_630:
   case SIS_730:
      /* Set - PCI LINEAR ADDRESSING ENABLE (0x80)
       *     - RELOCATED VGA IO  (0x20)
       *     - MMIO ENABLE (0x1)
       */
      SiS_SetReg(SiS_Pr->SiS_P3c4,0x20,0xa1);
      /*  - Enable 2D (0x40)
       *  - Enable 3D (0x02)
       *  - Enable 3D Vertex command fetch (0x10) ?
       *  - Enable 3D command parser (0x08) ?
       */
      SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x5A);
      break;
   case SIS_315H:
   case SIS_315:
   case SIS_315PRO:
   case SIS_650:
   case SIS_740:
   case SIS_330:
   case SIS_661:
   case SIS_741:
   case SIS_660:
   case SIS_760:
      SiS_SetReg(SiS_Pr->SiS_P3c4,0x20,0xa1);
      /*  - Enable 2D (0x40)
       *  - Enable 3D (0x02)
       *  - Enable 3D vertex command fetch (0x10)
       *  - Enable 3D command parser (0x08)
       *  - Enable 3D G/L transformation engine (0x80)
       */
      SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0xDA);
      break;
   case SIS_550:
      SiS_SetReg(SiS_Pr->SiS_P3c4,0x20,0xa1);
      /* No 3D engine ! */
      /*  - Enable 2D (0x40)
       */
      SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x1E,0x40);
   }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1379 1380
}

1381 1382 1383 1384
/*********************************************/
/*             HELPER: SetLVDSetc            */
/*********************************************/

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1385
void
1386
SiSSetLVDSetc(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1387
{
1388
   ULONG   temp;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1389

1390 1391 1392 1393 1394 1395
   SiS_Pr->SiS_IF_DEF_LVDS = 0;
   SiS_Pr->SiS_IF_DEF_TRUMPION = 0;
   SiS_Pr->SiS_IF_DEF_CH70xx = 0;
   SiS_Pr->SiS_IF_DEF_DSTN = 0;
   SiS_Pr->SiS_IF_DEF_FSTN = 0;
   SiS_Pr->SiS_IF_DEF_CONEX = 0;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
1396

1397
   SiS_Pr->SiS_ChrontelInit = 0;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed