sis_bridge.c

来自「linux下的MPEG1」· C语言 代码 · 共 836 行 · 第 1/2 页

C
836
字号
/**    Video bridge detection for SiS 300 and 310/325 series chips.    Copyright 2003 Jake Page, Sugar Media.    Based on SiS Xv driver:    Copyright 2002-2003 by Thomas Winischhofer, Vienna, Austria.    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 License, or    (at your option) 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**/#include <stdio.h>#include <stdlib.h>#include <unistd.h>#include "libdha.h"#include "sis_regs.h"#include "sis_defs.h"void sis_init_video_bridge(void);static void sis_ddc2_delay(unsigned short delaytime){    unsigned short i;    int temp;    for (i = 0; i < delaytime; i++) {	inSISIDXREG(SISSR, 0x05, temp);    }}static int sis_do_sense(int tempbl, int tempbh, int tempcl, int tempch){    int temp;    outSISIDXREG(SISPART4, 0x11, tempbl);    temp = tempbh | tempcl;    setSISIDXREG(SISPART4, 0x10, 0xe0, temp);    //usleep(200000);    sis_ddc2_delay(0x1000);    tempch &= 0x7f;    inSISIDXREG(SISPART4, 0x03, temp);    temp ^= 0x0e;    temp &= tempch;    return (temp == tempch);}/* sense connected devices on 30x bridge */static void sis_sense_30x(){    unsigned char backupP4_0d, backupP2_00, biosflag;    unsigned char testsvhs_tempbl, testsvhs_tempbh;    unsigned char testsvhs_tempcl, testsvhs_tempch;    unsigned char testcvbs_tempbl, testcvbs_tempbh;    unsigned char testcvbs_tempcl, testcvbs_tempch;    unsigned char testvga2_tempbl, testvga2_tempbh;    unsigned char testvga2_tempcl, testvga2_tempch;    int myflag, result = 0, i, j, haveresult;#if 0    unsigned short temp;#endif    inSISIDXREG(SISPART4, 0x0d, backupP4_0d);    outSISIDXREG(SISPART4, 0x0d, (backupP4_0d | 0x04));    inSISIDXREG(SISPART2, 0x00, backupP2_00);    outSISIDXREG(SISPART2, 0x00, (backupP2_00 | 0x1c));    sis_do_sense(0, 0, 0, 0);    if ((sis_vga_engine == SIS_315_VGA) ||	(sis_device_id == DEVICE_SIS_300)) {#if 0	if (0 /*pSiS->sishw_ext.UseROM */ ) {	    if (sis_vga_engine == SIS_300_VGA)		temp = 0xfe;	    else {		temp = 0xf3;		if (sis_device_id == DEVICE_SIS_330)		    temp = 0x11b;	    }	    if (pSiS->BIOS[temp] & 0x08) {		if (sis_verbose > 1) {		    printf			("[SiS] SiS30x: Video bridge has DVI-I TMDS/VGA combo connector\n");		}		orSISIDXREG(SISCR, 0x32, 0x80);	    } else {		andSISIDXREG(SISCR, 0x32, 0x7f);	    }	}#endif    }    if (sis_vga_engine == SIS_300_VGA) {	if (0 /*pSiS->sishw_ext.UseROM */ ) {#if 0	    testvga2_tempbh = pSiS->BIOS[0xf9];	    testvga2_tempbl = pSiS->BIOS[0xf8];	    testsvhs_tempbh = pSiS->BIOS[0xfb];	    testsvhs_tempbl = pSiS->BIOS[0xfa];	    testcvbs_tempbh = pSiS->BIOS[0xfd];	    testcvbs_tempbl = pSiS->BIOS[0xfc];	    biosflag = pSiS->BIOS[0xfe];#endif	} else {	    testvga2_tempbh = 0x00;	    testvga2_tempbl = 0xd1;	    testsvhs_tempbh = 0x00;	    testsvhs_tempbl = 0xb9;	    testcvbs_tempbh = 0x00;	    testcvbs_tempbl = 0xb3;	    biosflag = 0;	}	if (sis_vbflags & (VB_301B | VB_302B | VB_301LV | VB_302LV)) {	    testvga2_tempbh = 0x01;	    testvga2_tempbl = 0x90;	    testsvhs_tempbh = 0x01;	    testsvhs_tempbl = 0x6b;	    testcvbs_tempbh = 0x01;	    testcvbs_tempbl = 0x74;	}	inSISIDXREG(SISPART4, 0x01, myflag);	if (myflag & 0x04) {	    testvga2_tempbh = 0x00;	    testvga2_tempbl = 0xfd;	    testsvhs_tempbh = 0x00;	    testsvhs_tempbl = 0xdd;	    testcvbs_tempbh = 0x00;	    testcvbs_tempbl = 0xee;	}	testvga2_tempch = 0x0e;	testvga2_tempcl = 0x08;	testsvhs_tempch = 0x06;	testsvhs_tempcl = 0x04;	testcvbs_tempch = 0x08;	testcvbs_tempcl = 0x04;	if (sis_device_id == DEVICE_SIS_300) {	    inSISIDXREG(SISSR, 0x3b, myflag);	    if (!(myflag & 0x01)) {		testvga2_tempbh = 0x00;		testvga2_tempbl = 0x00;		testvga2_tempch = 0x00;		testvga2_tempcl = 0x00;	    }	}    } else {	if (0 /*pSiS->sishw_ext.UseROM */ ) {#if 0	    if (sis_device_id == DEVICE_SIS_330) {		testvga2_tempbh = pSiS->BIOS[0xe6];		testvga2_tempbl = pSiS->BIOS[0xe5];		testsvhs_tempbh = pSiS->BIOS[0xe8];		testsvhs_tempbl = pSiS->BIOS[0xe7];		testcvbs_tempbh = pSiS->BIOS[0xea];		testcvbs_tempbl = pSiS->BIOS[0xe9];		biosflag = pSiS->BIOS[0x11b];	    } else {		testvga2_tempbh = pSiS->BIOS[0xbe];		testvga2_tempbl = pSiS->BIOS[0xbd];		testsvhs_tempbh = pSiS->BIOS[0xc0];		testsvhs_tempbl = pSiS->BIOS[0xbf];		testcvbs_tempbh = pSiS->BIOS[0xc2];		testcvbs_tempbl = pSiS->BIOS[0xc1];		biosflag = pSiS->BIOS[0xf3];	    }#endif	} else {	    testvga2_tempbh = 0x00;	    testvga2_tempbl = 0xd1;	    testsvhs_tempbh = 0x00;	    testsvhs_tempbl = 0xb9;	    testcvbs_tempbh = 0x00;	    testcvbs_tempbl = 0xb3;	    biosflag = 0;	}	if (sis_vbflags & (VB_301B | VB_302B | VB_301LV | VB_302LV)) {	    if (0 /*pSiS->sishw_ext.UseROM */ ) {#if 0		if (sis_device_id == DEVICE_SIS_330) {		    testvga2_tempbh = pSiS->BIOS[0xec];		    testvga2_tempbl = pSiS->BIOS[0xeb];		    testsvhs_tempbh = pSiS->BIOS[0xee];		    testsvhs_tempbl = pSiS->BIOS[0xed];		    testcvbs_tempbh = pSiS->BIOS[0xf0];		    testcvbs_tempbl = pSiS->BIOS[0xef];		} else {		    testvga2_tempbh = pSiS->BIOS[0xc4];		    testvga2_tempbl = pSiS->BIOS[0xc3];		    testsvhs_tempbh = pSiS->BIOS[0xc6];		    testsvhs_tempbl = pSiS->BIOS[0xc5];		    testcvbs_tempbh = pSiS->BIOS[0xc8];		    testcvbs_tempbl = pSiS->BIOS[0xc7];		}#endif	    } else {		if (sis_vbflags & (VB_301B | VB_302B)) {		    testvga2_tempbh = 0x01;		    testvga2_tempbl = 0x90;		    testsvhs_tempbh = 0x01;		    testsvhs_tempbl = 0x6b;		    testcvbs_tempbh = 0x01;		    testcvbs_tempbl = 0x74;		} else {		    testvga2_tempbh = 0x00;		    testvga2_tempbl = 0x00;		    testsvhs_tempbh = 0x02;		    testsvhs_tempbl = 0x00;		    testcvbs_tempbh = 0x01;		    testcvbs_tempbl = 0x00;		}	    }	}	if (sis_vbflags & (VB_301 | VB_301B | VB_302B)) {	    inSISIDXREG(SISPART4, 0x01, myflag);	    if (myflag & 0x04) {		testvga2_tempbh = 0x00;		testvga2_tempbl = 0xfd;		testsvhs_tempbh = 0x00;		testsvhs_tempbl = 0xdd;		testcvbs_tempbh = 0x00;		testcvbs_tempbl = 0xee;	    }	}	if (sis_vbflags & (VB_301LV | VB_302LV)) {	    /* TW: No VGA2 or SCART on LV bridges */	    testvga2_tempbh = 0x00;	    testvga2_tempbl = 0x00;	    testvga2_tempch = 0x00;	    testvga2_tempcl = 0x00;	    testsvhs_tempch = 0x04;	    testsvhs_tempcl = 0x08;	    testcvbs_tempch = 0x08;	    testcvbs_tempcl = 0x08;	} else {	    testvga2_tempch = 0x0e;	    testvga2_tempcl = 0x08;	    testsvhs_tempch = 0x06;	    testsvhs_tempcl = 0x04;	    testcvbs_tempch = 0x08;	    testcvbs_tempcl = 0x04;	}    }    /* XXX: ?? andSISIDXREG(SISCR, 0x32, ~0x14); */    /* pSiS->postVBCR32 &= ~0x14; */    /* scan for VGA2/SCART */    if (testvga2_tempch || testvga2_tempcl ||	testvga2_tempbh || testvga2_tempbl) {	haveresult = 0;	for (j = 0; j < 10; j++) {	    result = 0;	    for (i = 0; i < 3; i++) {		if (sis_do_sense(testvga2_tempbl, testvga2_tempbh,				 testvga2_tempcl, testvga2_tempch))		    result++;	    }	    if ((result == 0) || (result >= 2))		break;	}	if (result) {	    if (biosflag & 0x01) {		if (sis_verbose > 1) {		    printf			("[SiS] SiS30x: Detected TV connected to SCART output\n");		}		sis_vbflags |= TV_SCART;		orSISIDXREG(SISCR, 0x32, 0x04);		/*pSiS->postVBCR32 |= 0x04; */	    } else {		if (sis_verbose > 1) {		    printf			("[SiS] SiS30x: Detected secondary VGA connection\n");		}		sis_vbflags |= VGA2_CONNECTED;		orSISIDXREG(SISCR, 0x32, 0x10);		/*pSiS->postVBCR32 |= 0x10; */	    }	}    }    /* scanning for TV */    /* XXX: ?? andSISIDXREG(SISCR, 0x32, ~0x03); */    /* pSiS->postVBCR32 &= ~0x03; */    result = sis_do_sense(testsvhs_tempbl, testsvhs_tempbh,			  testsvhs_tempcl, testsvhs_tempch);    haveresult = 0;    for (j = 0; j < 10; j++) {	result = 0;	for (i = 0; i < 3; i++) {	    if (sis_do_sense(testsvhs_tempbl, testsvhs_tempbh,			     testsvhs_tempcl, testsvhs_tempch))		result++;	}	if ((result == 0) || (result >= 2))	    break;    }    if (result) {	if (sis_verbose > 1) {	    printf		("[SiS] SiS30x: Detected TV connected to SVIDEO output\n");	}	/* TW: So we can be sure that there IS a SVIDEO output */	sis_vbflags |= TV_SVIDEO;	orSISIDXREG(SISCR, 0x32, 0x02);	//pSiS->postVBCR32 |= 0x02;    }    if ((biosflag & 0x02) || (!(result))) {	haveresult = 0;	for (j = 0; j < 10; j++) {	    result = 0;	    for (i = 0; i < 3; i++) {		if (sis_do_sense(testcvbs_tempbl, testcvbs_tempbh,				 testcvbs_tempcl, testcvbs_tempch))		    result++;	    }	    if ((result == 0) || (result >= 2))		break;	}	if (result) {	    if (sis_verbose > 1) {		printf		    ("[SiS] SiS30x: Detected TV connected to COMPOSITE output\n");	    }	    sis_vbflags |= TV_AVIDEO;	    orSISIDXREG(SISCR, 0x32, 0x01);	    //pSiS->postVBCR32 |= 0x01;	}    }    sis_do_sense(0, 0, 0, 0);    outSISIDXREG(SISPART2, 0x00, backupP2_00);    outSISIDXREG(SISPART4, 0x0d, backupP4_0d);}static void sis_detect_crt1(){    unsigned char CR32;    unsigned char CRT1Detected = 0;    unsigned char OtherDevices = 0;    if (!(sis_vbflags & VB_VIDEOBRIDGE)) {	sis_crt1_off = 0;	return;    }    inSISIDXREG(SISCR, 0x32, CR32);    if (CR32 & 0x20)	CRT1Detected = 1;    if (CR32 & 0x5F)	OtherDevices = 1;    if (sis_crt1_off == -1) {	if (!CRT1Detected) {	    /* BIOS detected no CRT1. */	    /* If other devices exist, switch it off */	    if (OtherDevices)		sis_crt1_off = 1;	    else		sis_crt1_off = 0;	} else {	    /* BIOS detected CRT1, leave/switch it on */	    sis_crt1_off = 0;	}    }    if (sis_verbose > 0) {	printf("[SiS] %sCRT1 connection detected\n",	       sis_crt1_off ? "No " : "");    }}#if 0 /* not used yet */static void sis_detect_lcd(){    unsigned char CR32;#if 0    /* not supported yet? */    unsigned char CR36, CR37;#endif    if (!(sis_vbflags & VB_VIDEOBRIDGE)) {	return;    }    inSISIDXREG(SISCR, 0x32, CR32);    if (CR32 & 0x08)	sis_vbflags |= CRT2_LCD;    /* DDC detection of LCD - not supported yet */

⌨️ 快捷键说明

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