init301.c 378 KB
Newer Older
1
/* $XFree86$ */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
2
/*
3 4
 * Mode initializing code (CRT2 section)
 * for SiS 300/305/540/630/730 and
5
 *     SiS 315/550/650/M650/651/661FX/M661xX/740/741/M741/330/660/M660/760/M760
6
 * (Universal module for Linux kernel framebuffer and XFree86 4.x)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
7
 *
8 9 10 11
 * Copyright (C) 2001-2004 by Thomas Winischhofer, Vienna, Austria
 *
 * If distributed as part of the Linux kernel, the following license terms
 * apply:
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
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
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
 * *    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.
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
50
 *
51 52 53 54
 * 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
 *
 * 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.
62
 * All comments in this file are by me, regardless if marked TW or not.
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
63 64
 *
 */
65

66
#if 1
67
#define SET_EMI		/* 302LV/ELV: Set EMI values */
68
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
69

70
#define COMPAL_HACK	/* Needed for Compal 1400x1050 (EMI) */
71
#define COMPAQ_HACK	/* Needed for Inventec/Compaq 1280x1024 (EMI) */
72
#define ASUS_HACK	/* Needed for Asus A2H 1024x768 (EMI) */
73

Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
74 75 76 77 78 79 80 81 82 83 84
#include "init301.h"

#ifdef SIS300
#include "oem300.h"
#endif

#ifdef SIS315H
#include "oem310.h"
#endif

#define SiS_I2CDELAY      1000
85
#define SiS_I2CDELAYSHORT  150
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
86

87 88
static USHORT SiS_GetBIOSLCDResInfo(SiS_Private *SiS_Pr);

89 90 91
/*********************************************/
/*         HELPER: Lock/Unlock CRT2          */
/*********************************************/
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
92

93 94 95
void
SiS_UnLockCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
96 97 98 99
   if(HwInfo->jChipType >= SIS_315H)
      SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x2f,0x01);
   else
      SiS_SetRegOR(SiS_Pr->SiS_Part1Port,0x24,0x01);
100
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
101

102 103 104
void
SiS_LockCRT2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
105 106 107 108
   if(HwInfo->jChipType >= SIS_315H)
      SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x2F,0xFE);
   else
      SiS_SetRegAND(SiS_Pr->SiS_Part1Port,0x24,0xFE);
109
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
110

111 112 113 114 115 116 117 118 119 120 121
/*********************************************/
/*            HELPER: Write SR11             */
/*********************************************/

static void
SiS_SetRegSR11ANDOR(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DataAND, USHORT DataOR)
{
   if(HwInfo->jChipType >= SIS_661) DataAND &= 0x0f;
   SiS_SetRegANDOR(SiS_Pr->SiS_P3c4,0x11,DataAND,DataOR);
}

122 123 124
/*********************************************/
/*    HELPER: Get Pointer to LCD structure   */
/*********************************************/
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
125

126 127
#ifdef SIS315H
static UCHAR *
128
GetLCDStructPtr661(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
129
{
130 131 132
   UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
   UCHAR  *myptr = NULL;
   USHORT romindex = 0;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
133

134 135 136
   /* Use the BIOS tables only for LVDS panels; DVI is unreliable
    * due to the variaty of panels the BIOS doesn't know about.
    */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
137

138 139 140 141 142 143 144 145 146
   if((SiS_Pr->SiS_ROMNew) && (SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) {
      myptr = (UCHAR *)SiS_LCDStruct661;
      romindex = SISGETROMW(0x100);  /* 10c, 0.93: 10e */
      if(romindex) {
         romindex += ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x7d) & 0x1f) * 26);
         myptr = &ROMAddr[romindex];
      }
   }
   return myptr;
147
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
148

149 150
static USHORT
GetLCDStructPtr661_2(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
151 152
{
   UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
153
   USHORT romptr = 0;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
154

155 156 157
   /* Use the BIOS tables only for LVDS panels; DVI is unreliable
    * due to the variaty of panels the BIOS doesn't know about.
    */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
158

159 160 161
   if((SiS_Pr->SiS_ROMNew) && (SiS_Pr->SiS_VBType & VB_SIS301LV302LV)) {
      romptr = SISGETROMW(0x102);  /* 2ad */
      romptr += ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4) * SiS_Pr->SiS661LCD2TableSize);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
162 163
   }

164
   return(romptr);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
165
}
166
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
167

168 169 170
/*********************************************/
/*           Adjust Rate for CRT2            */
/*********************************************/
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
171

172 173 174 175
static BOOLEAN
SiS_AdjustCRT2Rate(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
                   USHORT RefreshRateTableIndex, USHORT *i,
		   PSIS_HW_INFO HwInfo)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
176
{
177
  USHORT checkmask=0,modeid,infoflag;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
178

179
  modeid = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
180

181
  if(SiS_Pr->SiS_VBType & VB_SISVB) {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
182

183
     if(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC) {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
184

185
      	checkmask |= SupportRAMDAC2;
186
	if(HwInfo->jChipType >= SIS_315H) {
187
	   checkmask |= SupportRAMDAC2_135;
188
	   if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
189
	      checkmask |= SupportRAMDAC2_162;
190
	      if(SiS_Pr->SiS_VBType & VB_SIS301C) {
191
		 checkmask |= SupportRAMDAC2_202;
192 193 194
	      }
	   }
	}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
195

196
     } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
197

198
     	checkmask |= SupportLCD;
199
	if(HwInfo->jChipType >= SIS_315H) {
200 201 202
	   if(SiS_Pr->SiS_VBType & VB_SISVB) {
	      if((SiS_Pr->SiS_LCDInfo & DontExpandLCD) && (SiS_Pr->SiS_LCDInfo & LCDPass11)) {
	         if(modeid == 0x2e) checkmask |= Support64048060Hz;
203 204 205
	      }
	   }
	}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
206

207
     } else if(SiS_Pr->SiS_VBInfo & SetCRT2ToHiVision) {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
208

209
      	checkmask |= SupportHiVision;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
210

211
     } else if(SiS_Pr->SiS_VBInfo & (SetCRT2ToYPbPr525750|SetCRT2ToAVIDEO|SetCRT2ToSVIDEO|SetCRT2ToSCART)) {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
212

213
        checkmask |= SupportTV;
214
	if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
215 216 217 218 219 220
	   checkmask |= SupportTV1024;
	   if(SiS_Pr->SiS_VBInfo & SetCRT2ToYPbPr525750) {
	      if(SiS_Pr->SiS_TVMode & TVSetYPbPr750p) {
	         checkmask |= SupportYPbPr750p;
	      }
	   }
221
	}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
222

223
     }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
224

225
  } else {	/* LVDS */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
226

227 228
     if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
     	if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
229
           checkmask |= SupportCHTV;
230 231
      	}
     }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
232

233
     if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
234
     	checkmask |= SupportLCD;
235
     }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
236

237
  }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
238

239
  /* Look backwards in table for matching CRT2 mode */
240
  for(; SiS_Pr->SiS_RefIndex[RefreshRateTableIndex+(*i)].ModeID == modeid; (*i)--) {
241
     infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + (*i)].Ext_InfoFlag;
242
     if(infoflag & checkmask) return TRUE;
243 244
     if((*i) == 0) break;
  }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
245

246 247 248 249
  /* Look through the whole mode-section of the table from the beginning
   * for a matching CRT2 mode if no mode was found yet.
   */
  for((*i) = 0; ; (*i)++) {
250 251
     if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + (*i)].ModeID != modeid) {
     	return FALSE;
252 253
     }
     infoflag = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + (*i)].Ext_InfoFlag;
254
     if(infoflag & checkmask) return TRUE;
255
  }
256
  return TRUE;
257
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
258

259
/*********************************************/
260
/*              Get rate index               */
261
/*********************************************/
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
262

263 264 265 266 267 268 269 270 271 272 273
USHORT
SiS_GetRatePtr(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
               PSIS_HW_INFO HwInfo)
{
  SHORT  LCDRefreshIndex[] = { 0x00, 0x00, 0x01, 0x01,
                               0x01, 0x01, 0x01, 0x01,
			       0x01, 0x01, 0x01, 0x01,
			       0x01, 0x01, 0x01, 0x01,
			       0x00, 0x00, 0x00, 0x00 };
  USHORT RefreshRateTableIndex,i,backup_i;
  USHORT modeflag,index,temp,backupindex;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
274

275 276
  /* Do NOT check for UseCustomMode here, will skrew up FIFO */
  if(ModeNo == 0xfe) return 0;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
277

278 279 280 281
  if(ModeNo <= 0x13)
     modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
  else
     modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
282

283 284
  if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
     if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
285
     	if(modeflag & HalfDCLK) return 0;
286 287
     }
  }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
288

289
  if(ModeNo < 0x14) return 0xFFFF;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
290

291 292
  index = (SiS_GetReg(SiS_Pr->SiS_P3d4,0x33) >> SiS_Pr->SiS_SelectCRT2Rate) & 0x0F;
  backupindex = index;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
293

294
  if(index > 0) index--;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
295

296 297 298 299 300 301 302 303
  if(SiS_Pr->SiS_SetFlag & ProgrammingCRT2) {
     if(SiS_Pr->SiS_VBType & VB_SISVB) {
        if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCD) {
	   if(SiS_Pr->SiS_VBType & VB_NoLCD)		index = 0;
	   else if(SiS_Pr->SiS_LCDInfo & DontExpandLCD) index = backupindex = 0;
	}
	if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
	   if(!(SiS_Pr->SiS_VBType & VB_NoLCD)) {
304
              temp = LCDRefreshIndex[SiS_GetBIOSLCDResInfo(SiS_Pr)];
305 306 307 308 309 310 311 312 313 314
              if(index > temp) index = temp;
	   }
	}
     } else {
        if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) index = 0;
	if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) {
           if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) index = 0;
        }
     }
  }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
315

316 317
  RefreshRateTableIndex = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].REFindex;
  ModeNo = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].ModeID;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
318

319 320 321 322 323 324 325 326
  if(HwInfo->jChipType >= SIS_315H) {
     if(!(SiS_Pr->SiS_VBInfo & DriverMode)) {
        if( (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x105) ||
            (SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_VESAID == 0x107) ) {
           if(backupindex <= 1) RefreshRateTableIndex++;
        }
     }
  }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
327

328 329 330 331 332 333 334 335 336
  i = 0;
  do {
     if(SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + i].ModeID != ModeNo) break;
     temp = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
     temp &= ModeInfoFlag;
     if(temp < SiS_Pr->SiS_ModeType) break;
     i++;
     index--;
  } while(index != 0xFFFF);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
337

338 339 340 341 342 343
  if(!(SiS_Pr->SiS_VBInfo & SetCRT2ToRAMDAC)) {
     if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) {
      	temp = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex + i - 1].Ext_InfoFlag;
      	if(temp & InterlaceMode) i++;
     }
  }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
344

345
  i--;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
346

347 348 349 350 351 352
  if((SiS_Pr->SiS_SetFlag & ProgrammingCRT2) && (!(SiS_Pr->SiS_VBInfo & DisableCRT2Display))) {
     backup_i = i;
     if(!(SiS_AdjustCRT2Rate(SiS_Pr, ModeNo, ModeIdIndex, RefreshRateTableIndex, &i, HwInfo))) {
	i = backup_i;
     }
  }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
353

354 355
  return(RefreshRateTableIndex + i);
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
356

357 358 359
/*********************************************/
/*            STORE CRT2 INFO in CR34        */
/*********************************************/
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
360

361 362 363 364
static void
SiS_SaveCRT2Info(SiS_Private *SiS_Pr, USHORT ModeNo)
{
  USHORT temp1,temp2;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
365

366 367 368 369 370 371
  /* Store CRT1 ModeNo in CR34 */
  SiS_SetReg(SiS_Pr->SiS_P3d4,0x34,ModeNo);
  temp1 = (SiS_Pr->SiS_VBInfo & SetInSlaveMode) >> 8;
  temp2 = ~(SetInSlaveMode >> 8);
  SiS_SetRegANDOR(SiS_Pr->SiS_P3d4,0x31,temp2,temp1);
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
372

373 374 375
/*********************************************/
/*    HELPER: GET SOME DATA FROM BIOS ROM    */
/*********************************************/
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
376

377
#ifdef SIS300
378 379 380
static BOOLEAN
SiS_CR36BIOSWord23b(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
381
  UCHAR *ROMAddr = (UCHAR *)HwInfo->pjVirtualRomBase;
382
  USHORT temp,temp1;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
383

384
  if(SiS_Pr->SiS_UseROM) {
385 386
     if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
        temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xff) >> 4);
387
        temp1 = SISGETROMW(0x23b);
388
        if(temp1 & temp) return TRUE;
389 390
     }
  }
391
  return FALSE;
392
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
393

394 395 396
static BOOLEAN
SiS_CR36BIOSWord23d(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
397
  UCHAR *ROMAddr = (UCHAR *)HwInfo->pjVirtualRomBase;
398
  USHORT temp,temp1;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
399

400
  if(SiS_Pr->SiS_UseROM) {
401 402
     if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) {
        temp = 1 << ((SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) & 0xff) >> 4);
403
        temp1 = SISGETROMW(0x23d);
404
        if(temp1 & temp) return TRUE;
405 406
     }
  }
407
  return FALSE;
408
}
409
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
410

411 412 413
/*********************************************/
/*          HELPER: DELAY FUNCTIONS          */
/*********************************************/
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
414

415 416 417
void
SiS_DDC2Delay(SiS_Private *SiS_Pr, USHORT delaytime)
{
418
  USHORT i, j;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
419

420
  for(i=0; i<delaytime; i++) {
421
     j += SiS_GetReg(SiS_Pr->SiS_P3c4,0x05);
422 423
  }
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
424

425 426 427 428
static void
SiS_GenericDelay(SiS_Private *SiS_Pr, USHORT delay)
{
  USHORT temp,flag;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
429

430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
  flag = SiS_GetRegByte(0x61) & 0x10;

  while(delay) {
     temp = SiS_GetRegByte(0x61) & 0x10;
     if(temp == flag) continue;
     flag = temp;
     delay--;
  }
}

#ifdef SIS315H
static void
SiS_LongDelay(SiS_Private *SiS_Pr, USHORT delay)
{
  while(delay--) {
     SiS_GenericDelay(SiS_Pr,0x19df);
  }
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
448 449
#endif

450 451 452 453 454 455 456
static void
SiS_ShortDelay(SiS_Private *SiS_Pr, USHORT delay)
{
  while(delay--) {
     SiS_GenericDelay(SiS_Pr,0x42);
  }
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
457

458 459 460 461 462
static void
SiS_PanelDelay(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo, USHORT DelayTime)
{
  UCHAR  *ROMAddr = HwInfo->pjVirtualRomBase;
  USHORT PanelID, DelayIndex, Delay=0;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
463

464
  if(HwInfo->jChipType < SIS_315H) {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
465

466 467 468 469 470 471 472 473 474 475 476
#ifdef SIS300

      PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
      if(SiS_Pr->SiS_VBType & VB_SISVB) {
         if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x18) & 0x10)) PanelID = 0x12;
      }
      DelayIndex = PanelID >> 4;
      if((DelayTime >= 2) && ((PanelID & 0x0f) == 1))  {
         Delay = 3;
      } else {
         if(DelayTime >= 2) DelayTime -= 2;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
477

478 479 480 481 482
         if(!(DelayTime & 0x01)) {
       	    Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
         } else {
       	    Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
         }
483
	 if(SiS_Pr->SiS_UseROM) {
484 485 486 487 488 489 490 491 492 493
            if(ROMAddr[0x220] & 0x40) {
               if(!(DelayTime & 0x01)) {
	          Delay = (USHORT)ROMAddr[0x225];
               } else {
	    	  Delay = (USHORT)ROMAddr[0x226];
               }
            }
         }
      }
      SiS_ShortDelay(SiS_Pr,Delay);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
494

495
#endif  /* SIS300 */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
496

497
   } else {
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
498

499
#ifdef SIS315H
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
500

501 502 503 504 505 506 507 508 509
      if(HwInfo->jChipType >= SIS_661) {

         if(!(DelayTime & 0x01)) {
	    SiS_DDC2Delay(SiS_Pr, 0x1000);
         } else {
	    SiS_DDC2Delay(SiS_Pr, 0x4000);
         }

      } else if(HwInfo->jChipType >= SIS_330) return;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
510

511 512 513
      if((SiS_Pr->SiS_IF_DEF_LVDS == 1) ||
         (SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) ||
	 (SiS_Pr->SiS_CustomT == CUT_CLEVO1400)) {			/* 315 series, LVDS; Special */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
514

515 516 517 518 519 520 521
         if(SiS_Pr->SiS_IF_DEF_CH70xx == 0) {
            PanelID = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36);
	    if(SiS_Pr->SiS_CustomT == CUT_CLEVO1400) {
	       if(!(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1b) & 0x10)) PanelID = 0x12;
	    }
	    if(SiS_Pr->SiS_CustomT == CUT_COMPAQ1280) {
	       DelayIndex = PanelID & 0x0f;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
522
	    } else {
523
	       DelayIndex = PanelID >> 4;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
524
	    }
525 526 527 528 529 530 531 532 533
	    if((DelayTime >= 2) && ((PanelID & 0x0f) == 1))  {
               Delay = 3;
            } else {
               if(DelayTime >= 2) DelayTime -= 2;
               if(!(DelayTime & 0x01)) {
       		  Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[0];
               } else {
       		  Delay = SiS_Pr->SiS_PanelDelayTblLVDS[DelayIndex].timer[1];
               }
534
	       if((SiS_Pr->SiS_UseROM) && (!(SiS_Pr->SiS_ROMNew))) {
535 536 537 538 539 540 541 542 543 544 545
                  if(ROMAddr[0x13c] & 0x40) {
                     if(!(DelayTime & 0x01)) {
	    	        Delay = (USHORT)ROMAddr[0x17e];
                     } else {
	    	        Delay = (USHORT)ROMAddr[0x17f];
                     }
                  }
               }
            }
	    SiS_ShortDelay(SiS_Pr,Delay);
	 }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
546

547
      } else if(SiS_Pr->SiS_VBType & VB_SISVB) {			/* 315 series, all bridges */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
548

549
	 DelayIndex = SiS_GetReg(SiS_Pr->SiS_P3d4,0x36) >> 4;
550 551 552 553 554
         if(!(DelayTime & 0x01)) {
       	    Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[0];
         } else {
       	    Delay = SiS_Pr->SiS_PanelDelayTbl[DelayIndex].timer[1];
         }
555
	 Delay <<= 8;
556
	 SiS_DDC2Delay(SiS_Pr, Delay);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
557

558 559 560
      }

#endif /* SIS315H */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
561

562 563
   }
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
564

565 566 567 568 569 570 571 572 573 574 575
#ifdef SIS315H
static void
SiS_PanelDelayLoop(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo,
                      USHORT DelayTime, USHORT DelayLoop)
{
   int i;
   for(i=0; i<DelayLoop; i++) {
      SiS_PanelDelay(SiS_Pr, HwInfo, DelayTime);
   }
}
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
576

577 578 579
/*********************************************/
/*    HELPER: WAIT-FOR-RETRACE FUNCTIONS     */
/*********************************************/
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
580

581 582 583 584
void
SiS_WaitRetrace1(SiS_Private *SiS_Pr)
{
  USHORT watchdog;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
585

586
  if(SiS_GetReg(SiS_Pr->SiS_P3c4,0x1f) & 0xc0) return;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
587

588
  if(!(SiS_GetReg(SiS_Pr->SiS_P3d4,0x17) & 0x80)) return;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
589

590 591 592 593 594
  watchdog = 65535;
  while((SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08) && --watchdog);
  watchdog = 65535;
  while((!(SiS_GetRegByte(SiS_Pr->SiS_P3da) & 0x08)) && --watchdog);
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
595

596 597 598 599
static void
SiS_WaitRetrace2(SiS_Private *SiS_Pr, USHORT reg)
{
  USHORT watchdog;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
600

601 602 603 604 605
  watchdog = 65535;
  while((SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02) && --watchdog);
  watchdog = 65535;
  while((!(SiS_GetReg(SiS_Pr->SiS_Part1Port,reg) & 0x02)) && --watchdog);
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
606

607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
static void
SiS_WaitVBRetrace(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
  if(HwInfo->jChipType < SIS_315H) {
#ifdef SIS300
     if(SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV) {
        if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x20)) return;
     }
     if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x80)) {
        SiS_WaitRetrace1(SiS_Pr);
     } else {
        SiS_WaitRetrace2(SiS_Pr, 0x25);
     }
#endif
  } else {
#ifdef SIS315H
     if(!(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00) & 0x40)) {
        SiS_WaitRetrace1(SiS_Pr);
     } else {
        SiS_WaitRetrace2(SiS_Pr, 0x30);
     }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
628 629
#endif
  }
630
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
631

632 633 634 635
static void
SiS_VBWait(SiS_Private *SiS_Pr)
{
  USHORT tempal,temp,i,j;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
636

637 638 639 640 641 642 643 644 645 646
  temp = 0;
  for(i=0; i<3; i++) {
    for(j=0; j<100; j++) {
       tempal = SiS_GetRegByte(SiS_Pr->SiS_P3da);
       if(temp & 0x01) {
          if((tempal & 0x08))  continue;
          if(!(tempal & 0x08)) break;
       } else {
          if(!(tempal & 0x08)) continue;
          if((tempal & 0x08))  break;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
647 648
       }
    }
649
    temp ^= 0x01;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
650
  }
651
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
652

653 654 655
static void
SiS_VBLongWait(SiS_Private *SiS_Pr)
{
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
656
  if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) {
657 658 659
     SiS_VBWait(SiS_Pr);
  } else {
     SiS_WaitRetrace1(SiS_Pr);
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
660
  }
661
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
662

663 664 665
/*********************************************/
/*               HELPER: MISC                */
/*********************************************/
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
666

667 668 669
static BOOLEAN
SiS_Is301B(SiS_Private *SiS_Pr)
{
670
  if(SiS_GetReg(SiS_Pr->SiS_Part4Port,0x01) >= 0xb0) return TRUE;
671
  return FALSE;
672
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
673

674 675 676 677
static BOOLEAN
SiS_CRT2IsLCD(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
  USHORT flag;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
678

679 680 681
  if(HwInfo->jChipType == SIS_730) {
     flag = SiS_GetReg(SiS_Pr->SiS_P3c4,0x13);
     if(flag & 0x20) return TRUE;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
682
  }
683 684 685 686
  flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
  if(flag & 0x20) return TRUE;
  return FALSE;
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
687

688 689 690 691 692
BOOLEAN
SiS_IsDualEdge(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
#ifdef SIS315H
  USHORT flag;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
693

694 695 696 697 698
  if(HwInfo->jChipType >= SIS_315H) {
     if((HwInfo->jChipType != SIS_650) || (SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f) & 0xf0)) {
        flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
        if(flag & EnableDualEdge) return TRUE;
     }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
699
  }
700 701 702
#endif
  return FALSE;
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
703

704 705 706 707 708
BOOLEAN
SiS_IsVAMode(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
#ifdef SIS315H
  USHORT flag;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
709

710 711 712
  if(HwInfo->jChipType >= SIS_315H) {
     flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
     if((flag & EnableDualEdge) && (flag & SetToLCDA)) return TRUE;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
713
  }
714 715 716
#endif
  return FALSE;
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
717

718 719 720 721 722 723 724 725 726
static BOOLEAN
SiS_IsDualLink(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
#ifdef SIS315H
  if(HwInfo->jChipType >= SIS_315H) {
     if((SiS_CRT2IsLCD(SiS_Pr, HwInfo)) ||
        (SiS_IsVAMode(SiS_Pr, HwInfo))) {
        if(SiS_Pr->SiS_LCDInfo & LCDDualLink) return TRUE;
     }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
727
  }
728 729 730
#endif
  return FALSE;
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
731

732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752
#ifdef SIS315H
static BOOLEAN
SiS_TVEnabled(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
  if((SiS_GetReg(SiS_Pr->SiS_Part2Port,0x00) & 0x0f) != 0x0c) return TRUE;
  if(SiS_Pr->SiS_VBType & (VB_SIS301C | VB_SIS301LV302LV)) {
     if(SiS_GetReg(SiS_Pr->SiS_Part2Port,0x4d) & 0x10) return TRUE;
  }
  return FALSE;
}
#endif

#ifdef SIS315H
static BOOLEAN
SiS_LCDAEnabled(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
  if(SiS_GetReg(SiS_Pr->SiS_Part1Port,0x13) & 0x04) return TRUE;
  return FALSE;
}
#endif

753 754 755 756 757 758 759 760 761 762 763 764 765
#ifdef SIS315H
static BOOLEAN
SiS_WeHaveBacklightCtrl(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
  USHORT flag;

  if((HwInfo->jChipType >= SIS_315H) && (HwInfo->jChipType < SIS_661)) {
     flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x79);
     if(flag & 0x10) return TRUE;
  }
  return FALSE;
}
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
766

767 768 769 770 771
#ifdef SIS315H
static BOOLEAN
SiS_IsNotM650orLater(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
  USHORT flag;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
772

773 774 775 776 777 778 779 780 781 782
  if(HwInfo->jChipType == SIS_650) {
     flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x5f);
     flag &= 0xF0;
     /* Check for revision != A0 only */
     if((flag == 0xe0) || (flag == 0xc0) ||
        (flag == 0xb0) || (flag == 0x90)) return FALSE;
  } else if(HwInfo->jChipType >= SIS_661) return FALSE;
  return TRUE;
}
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
783

784 785 786 787 788
#ifdef SIS315H
static BOOLEAN
SiS_IsYPbPr(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
  USHORT flag;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
789

790 791
  if(HwInfo->jChipType >= SIS_315H) {
     flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
792
     if(flag & EnableCHYPbPr) return TRUE;  /* = YPrPb = 0x08 */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
793
  }
794 795
  return FALSE;
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
796
#endif
797 798 799 800 801 802 803 804 805

#ifdef SIS315H
static BOOLEAN
SiS_IsChScart(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
  USHORT flag;

  if(HwInfo->jChipType >= SIS_315H) {
     flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
806
     if(flag & EnableCHScart) return TRUE;  /* = Scart = 0x04 */
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
807
  }
808 809
  return FALSE;
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
810 811
#endif

812 813 814 815 816
#ifdef SIS315H
static BOOLEAN
SiS_IsTVOrYPbPrOrScart(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
  USHORT flag;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
817

818 819 820 821
  if(HwInfo->jChipType >= SIS_315H) {
     flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
     if(flag & SetCRT2ToTV)        return TRUE;
     flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
822 823
     if(flag & EnableCHYPbPr)      return TRUE;  /* = YPrPb = 0x08 */
     if(flag & EnableCHScart)      return TRUE;  /* = Scart = 0x04 - TW */
824 825
  } else {
     flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
826
     if(flag & SetCRT2ToTV)        return TRUE;
827 828 829 830
  }
  return FALSE;
}
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
831

832 833 834 835 836
#ifdef SIS315H
static BOOLEAN
SiS_IsLCDOrLCDA(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
  USHORT flag;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
837

838 839 840 841 842 843 844
  if(HwInfo->jChipType >= SIS_315H) {
     flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
     if(flag & SetCRT2ToLCD) return TRUE;
     flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x38);
     if(flag & SetToLCDA)    return TRUE;
  } else {
     flag = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
845
     if(flag & SetCRT2ToLCD) return TRUE;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
846
  }
847 848 849
  return FALSE;
}
#endif
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
850

851 852 853 854
static BOOLEAN
SiS_BridgeIsOn(SiS_Private *SiS_Pr)
{
  USHORT flag;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
855

856 857 858 859 860
  if(SiS_Pr->SiS_IF_DEF_LVDS == 1) {
     return FALSE;
  } else if(SiS_Pr->SiS_VBType & VB_SISVB) {
     flag = SiS_GetReg(SiS_Pr->SiS_Part4Port,0x00);
     if((flag == 1) || (flag == 2)) return FALSE;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
861
  }
862 863
  return TRUE;
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
864

865 866 867 868
static BOOLEAN
SiS_BridgeIsEnabled(SiS_Private *SiS_Pr, PSIS_HW_INFO HwInfo)
{
  USHORT flag;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
869

870 871 872 873 874 875 876 877 878
  if(!(SiS_BridgeIsOn(SiS_Pr))) {
     flag = SiS_GetReg(SiS_Pr->SiS_Part1Port,0x00);
     if(HwInfo->jChipType < SIS_315H) {
       flag &= 0xa0;
       if((flag == 0x80) || (flag == 0x20)) return FALSE;
     } else {
       flag &= 0x50;
       if((flag == 0x40) || (flag == 0x10)) return FALSE;
     }
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
879
  }
880 881
  return TRUE;
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
882

883 884 885 886
static BOOLEAN
SiS_BridgeInSlave(SiS_Private *SiS_Pr)
{
  USHORT flag1;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
887

888 889 890 891
  flag1 = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31);
  if(flag1 & (SetInSlaveMode >> 8)) return TRUE;
  return FALSE;
}
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
892

893 894 895 896 897 898 899 900 901 902
/*********************************************/
/*       GET VIDEO BRIDGE CONFIG INFO        */
/*********************************************/

/* Setup general purpose IO for Chrontel communication */
void
SiS_SetChrontelGPIO(SiS_Private *SiS_Pr, USHORT myvbinfo)
{
   unsigned long  acpibase;
   unsigned short temp;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
903

904 905 906
   if(!(SiS_Pr->SiS_ChSW)) return;

#ifndef LINUX_XF86
907
   SiS_SetRegLong(0xcf8,0x80000874);		       /* get ACPI base */
908 909 910 911 912 913 914 915 916 917 918
   acpibase = SiS_GetRegLong(0xcfc);
#else
   acpibase = pciReadLong(0x00000800, 0x74);
#endif
   acpibase &= 0xFFFF;
   temp = SiS_GetRegShort((USHORT)(acpibase + 0x3c));  /* ACPI register 0x3c: GP Event 1 I/O mode select */
   temp &= 0xFEFF;
   SiS_SetRegShort((USHORT)(acpibase + 0x3c), temp);
   temp = SiS_GetRegShort((USHORT)(acpibase + 0x3c));
   temp = SiS_GetRegShort((USHORT)(acpibase + 0x3a));  /* ACPI register 0x3a: GP Pin Level (low/high) */
   temp &= 0xFEFF;
919
   if(!(myvbinfo & SetCRT2ToTV)) temp |= 0x0100;
920 921
   SiS_SetRegShort((USHORT)(acpibase + 0x3a), temp);
   temp = SiS_GetRegShort((USHORT)(acpibase + 0x3a));
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
922 923 924
}

void
925 926
SiS_GetVBInfo(SiS_Private *SiS_Pr, USHORT ModeNo, USHORT ModeIdIndex,
              PSIS_HW_INFO HwInfo, int checkcrt2mode)
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
927
{
928 929
  USHORT tempax,tempbx,temp;
  USHORT modeflag, resinfo=0;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
930

931 932
  if(ModeNo <= 0x13) {
     modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag;
933 934
  } else if(SiS_Pr->UseCustomMode) {
     modeflag = SiS_Pr->CModeFlag;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
935
  } else {
936 937
     modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
     resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
938 939
  }

940
  SiS_Pr->SiS_SetFlag = 0;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
941

942
  SiS_Pr->SiS_ModeType = modeflag & ModeInfoFlag;
Kaleb Keithley Keithley's avatar
Kaleb Keithley Keithley committed
943

944 945 946 947
  tempbx = 0;
  if(SiS_BridgeIsOn(SiS_Pr) == 0) {
    	temp = SiS_GetReg(SiS_Pr->SiS_P3d4,0x30);
#if 0
948 949 950 951 952 953 954 955 956 957
   	if(HwInfo->jChipType < SIS_661) {
	   /* NO - YPbPr not set yet ! */
	   if(SiS_Pr->SiS_YPbPr & <all ypbpr except 525i>) {
	      temp &= (SetCRT2ToHiVision | SwitchCRT2 | SetSimuScanMode); 	/* 0x83 */
	      temp |= SetCRT2ToHiVision;   					/* 0x80 */
   	   }
	   if(SiS_Pr->SiS_YPbPr & <ypbpr525i>) {
	      temp &= (SetCRT2ToHiVision | SwitchCRT2 | SetSimuScanMode); 	/* 0x83 */
	      temp |= SetCRT2ToSVIDEO;  					/* 0x08 */
	   }
958 959 960 961
	}
#endif
    	tempbx |= temp;
    	tempax = SiS_GetReg(SiS_Pr->SiS_P3d4,0x31) << 8;
962
        tempax &= (DriverMode | LoadDACFlag | SetNotSimuMode | SetPALTV);
963
    	tempbx |= tempax;