sis_301.c

来自「讲述linux的初始化过程」· C语言 代码 · 共 2,841 行 · 第 1/5 页

C
2,841
字号
	LCDTypeInfo=tempbh;		tempah=(UCHAR)GetReg1(P3d4,0x37);	LCDInfo=tempah;	if(IF_DEF_TRUMPION){		LCDInfo=LCDInfo&(~LCDNonExpanding);	}	if(IF_DEF_LVDS==1){		tempflag=*((USHORT *)(ROMAddr+ModeIDOffset+0x01));		// si+St_ModeFlag		if(tempflag&HalfDCLK){			if(IF_DEF_TRUMPION==0){				if(!(LCDInfo&LCDNonExpanding)){					if(LCDResInfo==Panel1024x768){						tempflag=*((UCHAR *)(ROMAddr+ModeIDOffset+0x09)); //si+Ext_ResInfo						if(tempflag==4){ //512x384							SetFlag=SetFlag|EnableLVDSDDA;						}					}else{						if(LCDResInfo==Panel800x600){							tempflag=*((UCHAR *)(ROMAddr+ModeIDOffset+0x09)); //si+Ext_ResInfo								if(tempflag==3){ //400x300								SetFlag=SetFlag|EnableLVDSDDA;							} 						}					}				}else{					SetFlag=SetFlag|EnableLVDSDDA;				}			}else{				SetFlag=SetFlag|EnableLVDSDDA;			}		}	}	if(!(VBInfo&SetCRT2ToLCD)){		return 1;					}	if(!(VBInfo&(SetSimuScanMode|SwitchToCRT2))){		return 1;		}	if(VBInfo&SetInSlaveMode){		if(VBInfo&SetNotSimuTVMode){			SetFlag=SetFlag|LCDVESATiming;	 		}		}else{		SetFlag=SetFlag|LCDVESATiming;			}	return 1;		}VOID PresetScratchregister(USHORT P3d4,PHW_DEVICE_EXTENSION HwDeviceExtension){	SetReg1(P3d4,0x37,0x00);		}BOOLEAN GetLCDDDCInfo(PHW_DEVICE_EXTENSION HwDeviceExtension){	USHORT tempah;	tempah=(HwDeviceExtension->usLCDType);// set in sisv.c											//0:no lcd 1:1024x768 2:1280x1024	if(tempah>0) tempah++; // usLCDType: 								// 0:no lcd 1:800x600 2:1024x768 3:1280x1024	SetReg1(P3d4,0x36,tempah);//cr 36 0:no LCD 1:800x600 2:1024x768 3:1280x1024	if(tempah>0) return 1;	else return 0;			}VOID SetTVSystem(PHW_DEVICE_EXTENSION HwDeviceExtension,ULONG ROMAddr){	USHORT tempah,temp;	if(IF_DEF_LVDS==0){ //301		if(PRIMARY_VGA==1){ //primary vga			if(HwDeviceExtension->jChipID >= SIS_Trojan){				tempah=GetReg1(P3c4,0x17);				if(tempah&ModeSwitchStatus){					tempah=GetReg1(P3c4,0x16);					tempah=tempah&ActivePAL;					tempah=tempah>>ActivePALShift;				}else{					temp=*((UCHAR *)(ROMAddr+SoftSettingAddr));					if(temp&SoftTVType){		 				tempah=*((UCHAR *)(ROMAddr+ModeSettingAddr));			 		}else{						tempah=GetReg1(P3c4,0x38);	//SR 38					}				}			}else{				temp=*((UCHAR *)(ROMAddr+SoftSettingAddr));				if(temp&SoftTVType){					tempah=*((UCHAR *)(ROMAddr+ModeSettingAddr));				}else{					tempah=GetReg1(P3c4,0x38);	//SR 38				}			}			tempah=tempah&0x01;		//get SR 38 D0 TV Type Selection									//0:NTSC 1:PAL			SetRegANDOR(P3d4,0x31,~0x01,tempah);//set CR 31 D0= SR 38 D0		}		else{ //Secondary 			tempah=GetReg1(P3c4,0x38);	//SR 38			tempah=tempah&0x01;			//get SR 38 D0 TV Type Selection										//0:NTSC 1:PAL			SetRegANDOR(P3d4,0x31,~0x01,tempah);//set CR 31 D0= SR 38 D0		}		return;	}else{ //LVDS		tempah=GetReg1(P3c4,0x16);	//SR 16		tempah=tempah&ActiveNonExpanding;		tempah=tempah>>ActiveNonExpandingShift;		tempah=tempah&0x01;			tempah=tempah<<LCDNonExpandingShift;		SetRegANDOR(P3d4,0x37,~LCDNonExpanding,tempah);		return;	}		}BOOLEAN GetSenseStatus(PHW_DEVICE_EXTENSION HwDeviceExtension,USHORT BaseAddr,ULONG ROMAddr){	USHORT flag1,tempbx,tempal,tempah,tempcx,i;	 	USHORT Part2Port,Part4Port;	USHORT RGBSenseData,YCSenseData,VideoSenseData;	USHORT P2reg0,SenseModeNo,OutputSelect;	Part2Port=BaseAddr+IND_SIS_CRT2_PORT_10;	Part4Port=BaseAddr+IND_SIS_CRT2_PORT_14;	RGBSenseData=*((USHORT *)(ROMAddr+0xF8)); //0:F8 in rompost.asm	YCSenseData=*((USHORT *)(ROMAddr+0xFA)); //0:FA in rompost.asm	VideoSenseData=*((USHORT *)(ROMAddr+0xFC)); //0:FC in rompost.asm	if(IF_DEF_LVDS==1){		GetPanelID();		tempah=LCDSense;		SetRegANDOR(P3d4,0x32,~0x5F,tempah); //Set CR 32		return 0;	}	 	flag1=GetReg1(P3c4,0x38);		//call BridgeisOn	if(!(flag1&0x20)){ return 0;}	P2reg0=GetReg1(Part2Port,0x00); //save Part2 Reg index 0		if(!(BridgeIsEnable(BaseAddr))){		SenseModeNo=0x2E;		ModeType=ModeVGA;		VBInfo=SetCRT2ToRAMDAC;		SetFlag=0;		SetCRT2Group(BaseAddr,ROMAddr,SenseModeNo,HwDeviceExtension);		//here perform I/O delay ,read SR 05					for(i=0;i<0x7FFF;i++){			flag1=GetReg1(P3c4,0x05);					}	}				SetReg1(Part2Port,0x00,0x1C);	//Set part2 index 0= 0x1C	tempah=0;		OutputSelect=*((UCHAR *)(ROMAddr+0xFE));	//OutputSelect 0:FE in Rompost.asm	if(OutputSelect&SetSCARTOutput){		tempal=SCARTSense;		}else{		tempal=Monitor2Sense;	}	tempbx=RGBSenseData;	tempcx=0x0E08;	if(Sense(Part4Port,tempbx,tempcx)){		if(Sense(Part4Port,tempbx,tempcx)){			tempah=tempah|tempal; 		}			}	tempbx=YCSenseData;	tempcx=0x0604;	if(Sense(Part4Port,tempbx,tempcx)){		if(Sense(Part4Port,tempbx,tempcx)){			tempah=tempah|SVIDEOSense;			//Skipped lines about HiTVSense, assuming not HiTV			}	}	//Assuming not HiTV ,below is of ifndef HiVisionTV	if(OutputSelect&BoardTVType){		tempbx=VideoSenseData;		tempcx=0x0804;		if(Sense(Part4Port,tempbx,tempcx)){			if(Sense(Part4Port,tempbx,tempcx)){				tempah=tempah|AVIDEOSense;			}					}		}else{		if(!(tempah&SVIDEOSense)){			tempbx=VideoSenseData;			tempcx=0x0804;			if(Sense(Part4Port,tempbx,tempcx)){				if(Sense(Part4Port,tempbx,tempcx)){					tempah=tempah|AVIDEOSense; 				}					}		}	}	//end of ifndef HivisionTv	if(SenseLCD(HwDeviceExtension,Part4Port,ROMAddr)){		if(SenseLCD(HwDeviceExtension,Part4Port,ROMAddr)){			tempah=tempah|LCDSense;		}			}		tempbx=0; 	tempcx=0;	Sense(Part4Port,tempbx,tempcx);		SetRegANDOR(P3d4,0x32,~0x5F,tempah); //Set CR 32	SetReg1(Part2Port,0x00,P2reg0);		//recover Part2 reg index 0		//here skipped lines about DisableCRT2Display 	return 0;	}BOOLEAN Sense(USHORT Part4Port,USHORT inputbx,USHORT inputcx){	USHORT tempah,tempcl,tempch;		tempah=inputbx&0xFF;	SetReg1(Part4Port,0x11,tempah);//Part4 index 11	tempah=(inputbx&0xFF00)>>8;	tempcl=inputcx&0xFF;	tempah=tempah|tempcl;	SetRegANDOR(Part4Port,0x10,~0x1F,tempah);//Part4 index 10		tempch=(inputcx&0xFF00)>>8;	tempch=tempch&0x7F;	//here skipped lines about call Delay	tempah=GetReg1(Part4Port,0x03);		//Part4 index 03	tempah=tempah^(0x0E);	tempah=tempah&tempch;	if(tempah>0) return 1;	else return 0;			}BOOLEAN SenseLCD(PHW_DEVICE_EXTENSION HwDeviceExtension,USHORT Part4Port,ULONG ROMAddr){	USHORT SoftSetting;	USHORT tempah;				SoftSetting=*((UCHAR *)(ROMAddr+0x52));//0:52 in rompost.asm	if(GetLCDDDCInfo(HwDeviceExtension)){		return 1;		}	if(SoftSetting&HotPlugFunction){		tempah=GetReg1(Part4Port,0x0F);		tempah=tempah&0x3F;		SetReg1(Part4Port,0x0F,tempah); //Part4 index 0F		if(Sense(Part4Port,0x0,0x9010)){			return 1; 		}else{			return 0;		}		}else{		return 0;	}		}#endifVOID SetRegANDOR(USHORT Port,USHORT Index,USHORT DataAND,USHORT DataOR){	USHORT temp1;	temp1=GetReg1(Port,Index);		//part1port index 02	temp1=(temp1&(DataAND))|DataOR;	SetReg1(Port,Index,temp1);}BOOLEAN DetectMonitor(PHW_DEVICE_EXTENSION HwDeviceExtension){	USHORT flag1	;	USHORT DAC_TEST_PARMS[3]={0x0F,0x0F,0x0F};	USHORT DAC_CLR_PARMS[3]={0x00,0x00,0x00};		flag1=GetReg1(P3c4,0x38);		//call BridgeisOn	if((flag1&0x20)){		SetReg1(P3d4,0x30,0x41);	}		SiSSetMode(HwDeviceExtension,0x2E); //set mode to 0x2E instead of 0x3 	ClearDAC(P3c8);	ClearALLBuffer(HwDeviceExtension);		LongWait();	//wait vertical retrace	LongWait();		flag1=TestMonitorType(DAC_TEST_PARMS[0],DAC_TEST_PARMS[1],			DAC_TEST_PARMS[2]);	if(flag1==0){		flag1=TestMonitorType(DAC_TEST_PARMS[0],DAC_TEST_PARMS[1],			DAC_TEST_PARMS[2]);			}			if(flag1==1){		SetRegANDOR(P3d4,0x32,~Monitor1Sense,Monitor1Sense);					 	}else{		SetRegANDOR(P3d4,0x32,~Monitor1Sense,0x0);	}	TestMonitorType(DAC_CLR_PARMS[0],DAC_CLR_PARMS[1],DAC_CLR_PARMS[2]);				SetReg1(P3d4,0x34,0x4A);	//Preset default CRT1 ModeNo =0x4A								//which is used in SetCRT2FIFO()	return 1;		}BOOLEAN TestMonitorType(USHORT d1,USHORT d2,USHORT d3){	USHORT temp;		SetReg3(P3c6,0xFF);	SetReg3(P3c8,0x00);	SetReg3(P3c9,d1);	SetReg3(P3c9,d2);	SetReg3(P3c9,d3);	WaitDisplay();			//wait horizontal retrace	temp=GetReg2(P3c2);	if(temp&0x10) return 1;	else return 0;			}VOID WaitDisplay(void){	USHORT temp; 	for(temp=0;temp==0;){		temp=GetReg2(P3da);		temp=temp&0x01;	 	}	for(;temp==1;){		temp=GetReg2(P3da);		temp=temp&0x01;	 	}		}VOID LongWait(void){	USHORT temp;		for(temp=1;temp>0;){		temp=GetReg2(P3da);		temp=temp&0x08;	 	}	for(;temp==0;){		temp=GetReg2(P3da);		temp=temp&0x08;	 	}		}#ifndef CONFIG_FB_SIS_LINUXBIOSVOID VBLongWait(VOID){	USHORT regsr1f,tempah,temp;	regsr1f=GetReg1(P3c4,0x1F);	tempah=regsr1f&(~0xC0);	SetReg1(P3c4,0x1F,tempah);	for(temp=1;temp>0;){		temp=GetReg2(P3da);		temp=temp&0x08;	 	}	for(;temp==0;){		temp=GetReg2(P3da);		temp=temp&0x08;	 	}	SetReg1(P3c4,0x1F,regsr1f);	return;	}BOOLEAN WaitVBRetrace(USHORT BaseAddr){	USHORT temp;	USHORT Part1Port;	Part1Port=BaseAddr+IND_SIS_CRT2_PORT_04;	temp=GetReg1(Part1Port,0x00);	if(!(temp&0x80)){		return 0;	}	for(temp=0;temp==0;){		temp=GetReg1(Part1Port,0x25);		temp=temp&0x01;	 	}	for(;temp>0;){		temp=GetReg1(Part1Port,0x25);		temp=temp&0x01;	 	}	return 1; }BOOLEAN GetPanelID(VOID){	USHORT PanelTypeTable[16]={ SyncPP|Panel800x600|PanelType00,								SyncPP|Panel1024x768|PanelType01,								SyncPP|Panel1024x768|PanelType02,								SyncPP|Panel1024x768|PanelType03,								SyncPP|Panel1024x768|PanelType04,								SyncPP|Panel1024x768|PanelType05,								SyncPP|Panel1024x768|PanelType06,								SyncPP|Panel1024x768|PanelType07,								SyncPP|Panel1024x768|PanelType08,								SyncPP|Panel1024x768|PanelType09,								SyncPP|Panel800x600|PanelType0A,								SyncPP|Panel1024x768|PanelType0B,								SyncPP|Panel1024x768|PanelType0C,								SyncPP|Panel1024x768|PanelType0D,								SyncPP|Panel1024x768|PanelType0E,								SyncPP|Panel1024x768|PanelType0F};	// Bit 15 BPLVSPLTY	// Bit 14 BPLHSPLTY	// Bit 6-3 Panel Type	// Bit 2-0 Display Resolution(001:800x600 010:1024x768 011:1280x1024)	USHORT tempah,tempbx;	USHORT return_flag;	tempah=GetReg1(P3c4,0x18);	tempbx=tempah&0x0F;	if(tempah&0x10){		return_flag=1;	}else{		return_flag=0;	}	if(return_flag==0){		if(IF_DEF_LVDS==1){			tempbx=0;			tempah=GetReg1(P3c4,0x38);			if(tempah&0x40) tempbx=tempbx|0x08;			if(tempah&0x20) tempbx=tempbx|0x02;			if(tempah&0x01) tempbx=tempbx|0x01;			tempah=GetReg1(P3c4,0x39);			if(tempah&0x80) tempbx=tempbx|0x04;		}else{			return 0;		}	}	if(IF_DEF_TRUMPION==1){		tempbx=1;	}	tempbx=PanelTypeTable[tempbx]; //LVDS table entry	tempbx=tempbx|(USHORT)(LCDSync<<8);	tempah=tempbx&0x0FF;	SetReg1(P3d4,0x36,tempah);	tempah=(tempbx&0xFF00)>>8;	SetRegANDOR(P3d4,0x37,~LCDSyncBit,tempah);	return 1;}VOID ModCRT1CRTC(ULONG ROMAddr,USHORT ModeNo){	USHORT OldREFIndex,temp,tempah,i,modeflag1;	OldREFIndex=(USHORT)REFIndex;	temp=GetLVDSCRT1Ptr(ROMAddr,ModeNo);	if(temp==0){		REFIndex=OldREFIndex;		return;	}	tempah=(UCHAR)GetReg1(P3d4,0x11);//unlock cr0-7	tempah=tempah&0x7F;	SetReg1(P3d4,0x11,tempah);	tempah=*((UCHAR *)(ROMAddr+REFIndex));	SetReg1(P3d4,0x0,tempah);	REFIndex++;	for(i=0x02;i<=0x05;REFIndex++){		tempah=*((UCHAR *)(ROMAddr+REFIndex));		SetReg1(P3d4,i,tempah); 	}	for(i=0x06;i<=0x07;REFIndex++){		tempah=*((UCHAR *)(ROMAddr+REFIndex));		SetReg1(P3d4,i,tempah); 	}	for(i=0x10;i<=0x11;REFIndex++){		tempah=*((UCHAR *)(ROMAddr+REFIndex));		SetReg1(P3d4,i,tempah); 	}	for(i=0x15;i<=0x16;REFIndex++){		tempah=*((UCHAR *)(ROMAddr+REFIndex));		SetReg1(P3d4,i,tempah); 	}	for(i=0x0A;i<=0x0C;REFIndex++){		tempah=*((UCHAR *)(ROMAddr+REFIndex));		SetReg1(P3c4,i,tempah); 	}	tempah=*((UCHAR *)(ROMAddr+REFIndex));	tempah=tempah&0x0E0;	SetReg1(P3c4,0x0E,tempah);	tempah=*((UCHAR *)(ROMAddr+REFIndex));	tempah=tempah&0x01;	tempah=tempah<<5;	modeflag1=*((USHORT *)(ROMAddr+ModeIDOffset+0x01));	// si+St_ModeFlag	if(modeflag1&DoubleScanMode){		tempah=tempah|0x080;	}	SetRegANDOR(P3d4,0x09,~0x020,tempah);	REFIndex=OldREFIndex;	return; }VOID SetCRT2ECLK(ULONG ROMAddr, USHORT ModeNo){	USHORT OldREFIndex,tempah,tempal;	USHORT P3cc=P3c9+3;	OldREFIndex=(USHORT)REFIndex;	if(IF_DEF_TRUMPION==0){	//no trumpion		tempal=GetReg2(P3cc);		tempal=tempal&0x0C;		SetReg3(P3c2,tempal);		REFIndex=GetVCLKPtr(ROMAddr,ModeNo);	}else{	//trumpion		SetFlag=SetFlag&(~ProgrammingCRT2);		tempal=*((UCHAR *)(ROMAddr+REFIndex+0x03));	 //di+Ext_CRTVCLK		tempal=tempal&0x03F;		if(tempal==0x02){ //31.5MHz			REFIndex=REFIndex-Ext2StructSize;		}		REFIndex=GetVCLKPtr(ROMAddr,ModeNo);		SetFlag=SetFlag|ProgrammingCRT2;	}	tempal=0x02B;	if(!(VBInfo&SetInSlaveMode)){		tempal=tempal+3;	}	tempah=*((UCHAR *)(ROMAddr+REFIndex));		SetReg1(P3c4,tempal,tempah);	tempah=*((UCHAR *)(ROMAddr+REFIndex+1));	tempal++; 	SetReg1(P3c4,tempal,tempah);	REFIndex=OldREFIndex;	return;}USHORT GetLVDSDesPtr(ULONG ROMAddr,USHORT ModeNo){	USHORT tempcl,tempbx,tempal,tempptr,LVDSDesPtrData;	tempcl=LVDSDesDataLen;	tempbx=LCDTypeInfo;	if(LCDInfo&LCDNonExpanding){		tempbx=tempbx+16;	}	if(ModeNo<=0x13){		tempal=*((UCHAR *)(ROMAddr+ModeIDOffset+0x04));	// si+St_CRT2CRTC	}else{		tempal=*((UCHAR *)(ROMAddr+REFIndex+4));	 //di+Ext_CRT2CRTC	}	tempal=tempal&0x1F;	tempal=tempal*tempcl;	tempbx=tempbx<<1;	LVDSDesPtrData=*((USHORT *)(ROMAddr+ADR_LVDSDesPtrData));	tempptr=*((USHORT *)(ROMAddr+LVDSDesPtrData+tempbx));	tempptr=tempptr+tempal;	return(tempptr);	}BOOLEAN GetLVDSCRT1Ptr(ULONG ROMAddr,USHORT ModeNo){	USHORT tempal,tempbx,modeflag1; 	USHORT LVDSCRT1DataPtr; 	if(

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?