📄 init301.c
字号:
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/sis/init301.c,v 1.3 2002/22/04 01:16:16 dawes Exp $ *//* * Mode switching code (CRT2 section) for SiS 300/540/630/730/315/550/650/740/330 * (Universal module for Linux kernel framebuffer, XFree86 4.x) * * Assembler-To-C translation * Copyright 2002, 2003 by Thomas Winischhofer <thomas@winischhofer.net> * Minor parts Copyright SiS, Inc. * * Based on BIOS * 1.10.07, 1.10a for 650/CH7019 * 1.11.21a for 740/CH7019 * 1.11.05 for 650/LVDS (w/o Chrontel) * 1.07.1b, 1.10.6s, 1.11.6w, 1.11.7w, 1.11.8r for 650/301(B/LV), 650/302LV * 2.04.50 (I) and 2.04.5c (II) for 630/301(B) * 2.02.3b, 2.03.02, 2.04.2c, 2.04.5c, 2.07a and 2.08.b3 for 630/LVDS/LVDS+CH7005 * 2.04.5c, 2.04.6c for 730+LVDS+CH7005 * 1.09b for 315/301(B) * 1.16.51 for 300+301LV (ECS A907) * 1.01.03 for 330 (Xabre 400) * * Known bugs: * 1024x768 panel, expanding (CR37=1): Mode 640x480 does not work on SOME panels * therefore, we always do the scaling ourselves for now. * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that * the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of the copyright holder not be used in * advertising or publicity pertaining to distribution of the software without * specific, written prior permission. The copyright holder makes no representations * about the suitability of this software for any purpose. It is provided * "as is" without express or implied warranty. * * THE COPYRIGHT HOLDER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY SPECIAL, INDIRECT OR * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR * PERFORMANCE OF THIS SOFTWARE. * * 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. * */ #if 1 #define NEWCH701x#endif#include "init301.h"#if 0#define TWNEWPANEL#endif#ifdef SIS300#include "oem300.h"#endif#ifdef SIS315H#include "oem310.h"#endif#define SiS_I2CDELAY 1000#define SiS_I2CDELAYSHORT 150BOOLEANSiS_SetCRT2Group301(SiS_Private *SiS_Pr, USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo, PSIS_HW_DEVICE_INFO HwDeviceExtension){ USHORT ModeIdIndex; USHORT RefreshRateTableIndex; SiS_Pr->SiS_SetFlag |= ProgrammingCRT2; if(!SiS_Pr->UseCustomMode) { SiS_SearchModeID(SiS_Pr,ROMAddr,&ModeNo,&ModeIdIndex); } else { ModeIdIndex = 0; } /* TW: Used for shifting CR33 */ SiS_Pr->SiS_SelectCRT2Rate = 4; SiS_UnLockCRT2(SiS_Pr, HwDeviceExtension, BaseAddr); RefreshRateTableIndex = SiS_GetRatePtrCRT2(SiS_Pr, ROMAddr,ModeNo,ModeIdIndex,HwDeviceExtension); SiS_SaveCRT2Info(SiS_Pr,ModeNo); if(SiS_LowModeStuff(SiS_Pr,ModeNo,HwDeviceExtension)) { SiS_DisableBridge(SiS_Pr,HwDeviceExtension,BaseAddr); if((SiS_Pr->SiS_IF_DEF_LVDS == 1) && (HwDeviceExtension->jChipType == SIS_730)) { SiS_SetReg1(SiS_Pr->SiS_Part1Port,0x00,0x80); } SiS_SetCRT2ModeRegs(SiS_Pr,BaseAddr,ModeNo,ModeIdIndex,HwDeviceExtension); } if(SiS_Pr->SiS_VBInfo & DisableCRT2Display) { SiS_LockCRT2(SiS_Pr,HwDeviceExtension, BaseAddr); SiS_DisplayOn(SiS_Pr); return(TRUE); } if(SiS_Pr->UseCustomMode) return(FALSE); SiS_GetCRT2Data(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, HwDeviceExtension); /* Set up Panel Link for LVDS, 301BDH and 650/30xLV(for LCDA) */ if( (SiS_Pr->SiS_IF_DEF_LVDS == 1) || ((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) || ((HwDeviceExtension->jChipType >= SIS_315H) && (SiS_Pr->SiS_VBType & VB_SIS301BLV302BLV)) ) { SiS_GetLVDSDesData(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex,RefreshRateTableIndex, HwDeviceExtension); } else { SiS_Pr->SiS_LCDHDES = SiS_Pr->SiS_LCDVDES = 0; }#ifdef LINUX_XF86#ifdef TWDEBUG xf86DrvMsg(0, X_INFO, "(init301: LCDHDES 0x%03x LCDVDES 0x%03x)\n", SiS_Pr->SiS_LCDHDES, SiS_Pr->SiS_LCDVDES); xf86DrvMsg(0, X_INFO, "(init301: HDE 0x%03x VDE 0x%03x)\n", SiS_Pr->SiS_HDE, SiS_Pr->SiS_VDE); xf86DrvMsg(0, X_INFO, "(init301: VGAHDE 0x%03x VGAVDE 0x%03x)\n", SiS_Pr->SiS_VGAHDE, SiS_Pr->SiS_VGAVDE); xf86DrvMsg(0, X_INFO, "(init301: HT 0x%03x VT 0x%03x)\n", SiS_Pr->SiS_HT, SiS_Pr->SiS_VT); xf86DrvMsg(0, X_INFO, "(init301: VGAHT 0x%03x VGAVT 0x%03x)\n", SiS_Pr->SiS_VGAHT, SiS_Pr->SiS_VGAVT);#endif#endif if(SiS_LowModeStuff(SiS_Pr,ModeNo,HwDeviceExtension)) { SiS_SetGroup1(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, HwDeviceExtension,RefreshRateTableIndex); } if(SiS_Pr->SiS_IF_DEF_LVDS == 0) { if(SiS_LowModeStuff(SiS_Pr,ModeNo,HwDeviceExtension)) { SiS_SetGroup2(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, RefreshRateTableIndex,HwDeviceExtension); SiS_SetGroup3(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, HwDeviceExtension); SiS_SetGroup4(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, RefreshRateTableIndex,HwDeviceExtension); SiS_SetGroup5(SiS_Pr,HwDeviceExtension, BaseAddr,ROMAddr, ModeNo,ModeIdIndex); /* TW: For 301BDH (Panel link initialization): */ if((SiS_Pr->SiS_VBType & VB_NoLCD) && (SiS_Pr->SiS_VBInfo & SetCRT2ToLCD)) { if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) { if(!((SiS_Pr->SiS_SetFlag & SetDOSMode) && ((ModeNo == 0x03) || (ModeNo = 0x10)))) { if(SiS_Pr->SiS_VBInfo & SetInSlaveMode) { SiS_ModCRT1CRTC(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex, RefreshRateTableIndex,HwDeviceExtension); } } } SiS_SetCRT2ECLK(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex, RefreshRateTableIndex,HwDeviceExtension); } } } else { if(SiS_Pr->SiS_LCDResInfo != SiS_Pr->SiS_Panel640x480) { if(SiS_Pr->SiS_IF_DEF_TRUMPION == 0) { SiS_ModCRT1CRTC(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex, RefreshRateTableIndex,HwDeviceExtension); } } if(SiS_Pr->SiS_IF_DEF_FSTN == 0) { SiS_SetCRT2ECLK(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex, RefreshRateTableIndex,HwDeviceExtension); } if(SiS_LowModeStuff(SiS_Pr,ModeNo,HwDeviceExtension)) { if(SiS_Pr->SiS_IF_DEF_CH70xx != 0) { if(SiS_Pr->SiS_VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { if(SiS_Pr->SiS_IF_DEF_CH70xx == 2) {#ifdef SIS315H SiS_SetCH701xForLCD(SiS_Pr,HwDeviceExtension,BaseAddr);#endif } } if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { SiS_SetCHTVReg(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex, RefreshRateTableIndex); } } } }#ifdef SIS300 if ( (HwDeviceExtension->jChipType == SIS_540) || (HwDeviceExtension->jChipType == SIS_630) || (HwDeviceExtension->jChipType == SIS_730) || (HwDeviceExtension->jChipType == SIS_300) ) { if(SiS_LowModeStuff(SiS_Pr,ModeNo,HwDeviceExtension)) { if(SiS_Pr->SiS_UseOEM) { if((SiS_Pr->SiS_UseROM) && ROMAddr && (SiS_Pr->SiS_UseOEM == -1)) { if((ROMAddr[0x233] == 0x12) && (ROMAddr[0x234] == 0x34)) { SiS_OEM300Setting(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo); } } else { SiS_OEM300Setting(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo); } } } }#endif#ifdef SIS315H if ( (HwDeviceExtension->jChipType == SIS_315H) || (HwDeviceExtension->jChipType == SIS_315) || (HwDeviceExtension->jChipType == SIS_315PRO)|| (HwDeviceExtension->jChipType == SIS_550) || (HwDeviceExtension->jChipType == SIS_740) || (HwDeviceExtension->jChipType == SIS_650) || (HwDeviceExtension->jChipType == SIS_330) ) { if(SiS_LowModeStuff(SiS_Pr,ModeNo,HwDeviceExtension)) { SiS_FinalizeLCD(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, HwDeviceExtension);#if 0 /* Instead of FinalizeLCD(), older BIOSes (A92x) used OEMLCD() */ SiS_OEMLCD(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo,ModeIdIndex);#endif if(SiS_Pr->SiS_UseOEM) { SiS_OEM310Setting(SiS_Pr,HwDeviceExtension,BaseAddr,ROMAddr,ModeNo,ModeIdIndex); } SiS_CRT2AutoThreshold(SiS_Pr,BaseAddr); } }#endif if(HwDeviceExtension->jChipType < SIS_315H) { if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { if(HwDeviceExtension->jChipType != SIS_730) { SiS_DisplayOn(SiS_Pr); } } } if(SiS_LowModeStuff(SiS_Pr,ModeNo,HwDeviceExtension)) { if(SiS_Pr->SiS_IF_DEF_LVDS == 1) { if(HwDeviceExtension->jChipType == SIS_730) { SiS_DisplayOn(SiS_Pr); } } SiS_EnableBridge(SiS_Pr,HwDeviceExtension,BaseAddr); } SiS_DisplayOn(SiS_Pr); if(SiS_Pr->SiS_IF_DEF_CH70xx == 1) { if(SiS_Pr->SiS_VBInfo & SetCRT2ToTV) { /* TW: Disable LCD panel when using TV */ SiS_SetRegOR(SiS_Pr->SiS_P3c4,0x11,0x0C); } else { /* TW: Disable TV when using LCD */ SiS_SetCH70xxANDOR(SiS_Pr,0x010E,0xF8); } } if(SiS_LowModeStuff(SiS_Pr,ModeNo,HwDeviceExtension)) { SiS_LockCRT2(SiS_Pr,HwDeviceExtension, BaseAddr); } return 1;}BOOLEANSiS_LowModeStuff(SiS_Private *SiS_Pr, USHORT ModeNo, PSIS_HW_DEVICE_INFO HwDeviceExtension){ USHORT temp,temp1,temp2; if((ModeNo != 0x03) && (ModeNo != 0x10) && (ModeNo != 0x12)) return(1); temp = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x11); SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x11,0x80); temp1 = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x00); SiS_SetReg1(SiS_Pr->SiS_P3d4,0x00,0x55); temp2 = SiS_GetReg1(SiS_Pr->SiS_P3d4,0x00); SiS_SetReg1(SiS_Pr->SiS_P3d4,0x00,temp1); SiS_SetReg1(SiS_Pr->SiS_P3d4,0x11,temp); if((HwDeviceExtension->jChipType >= SIS_315H) || (HwDeviceExtension->jChipType == SIS_300)) { if(temp2 == 0x55) return(0); else return(1); } else { if(temp2 != 0x55) return(1); else { SiS_SetRegOR(SiS_Pr->SiS_P3d4,0x35,0x01); return(0); } }}/* TW: Set Part1 registers */voidSiS_SetGroup1(SiS_Private *SiS_Pr,USHORT BaseAddr,UCHAR *ROMAddr,USHORT ModeNo, USHORT ModeIdIndex,PSIS_HW_DEVICE_INFO HwDeviceExtension, USHORT RefreshRateTableIndex){ USHORT temp=0, tempax=0, tempbx=0, tempcx=0; USHORT pushbx=0, CRT1Index=0;#ifdef SIS315H USHORT pushcx=0, tempbl=0;#endif USHORT modeflag, resinfo=0; if(ModeNo<=0x13) { modeflag = SiS_Pr->SiS_SModeIDTable[ModeIdIndex].St_ModeFlag; } else { CRT1Index = SiS_Pr->SiS_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC; resinfo = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_RESINFO; modeflag = SiS_Pr->SiS_EModeIDTable[ModeIdIndex].Ext_ModeFlag; } if(SiS_Pr->SiS_VBInfo & SetCRT2ToLCDA) { SiS_SetCRT2Sync(SiS_Pr,BaseAddr,ROMAddr,ModeNo, RefreshRateTableIndex,HwDeviceExtension);#ifdef SIS315H SiS_SetGroup1_LCDA(SiS_Pr,BaseAddr,ROMAddr,ModeNo,ModeIdIndex, HwDeviceExtension,RefreshRateTableIndex);#endif } else { if( (HwDeviceExtension->jChipType >= SIS_315H) && (SiS_Pr->SiS_IF_DEF_LVDS == 1) && (SiS_Pr->SiS_VBInfo & SetInSlaveMode)) { SiS_SetCRT2Sync(SiS_Pr,BaseAddr,ROMAddr,ModeNo, RefreshRateTableIndex,HwDeviceExtension); } else { SiS_SetCRT2Offset(SiS_Pr,ROMAddr,ModeNo,ModeIdIndex, RefreshRateTableIndex,HwDeviceExtension); if (HwDeviceExtension->jChipType < SIS_315H ) {#ifdef SIS300 SiS_SetCRT2FIFO_300(SiS_Pr,ROMAddr,ModeNo,HwDeviceExtension);#endif } else {#ifdef SIS315H SiS_SetCRT2FIFO_310(SiS_Pr,ROMAddr,ModeNo,HwDeviceExtension);#endif } SiS_SetCRT2Sync(SiS_Pr,BaseAddr,ROMAddr,ModeNo, RefreshRateTableIndex,HwDeviceExtension); /* 1. Horizontal setup */ if (HwDeviceExtension->jChipType < SIS_315H ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -