• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6.36/drivers/staging/xgifb/
1#include <linux/version.h>
2#include <asm/io.h>
3#include <linux/types.h>
4#include "XGIfb.h"
5
6#include "vb_def.h"
7#include "vgatypes.h"
8#include "vb_struct.h"
9#include "vb_util.h"
10#include "vb_setmode.h"
11#include "vb_ext.h"
12extern   unsigned char XGI330_SoftSetting;
13extern   unsigned char XGI330_OutputSelect;
14extern   unsigned short XGI330_RGBSenseData2;
15extern   unsigned short XGI330_YCSenseData2;
16extern   unsigned short XGI330_VideoSenseData2;
17void     XGI_GetSenseStatus(struct xgi_hw_device_info *HwDeviceExtension, struct vb_device_info *pVBInfo);
18unsigned char  XGINew_GetPanelID(struct vb_device_info *pVBInfo);
19unsigned short XGINew_SenseLCD(struct xgi_hw_device_info *,
20			       struct vb_device_info *pVBInfo);
21unsigned char XGINew_GetLCDDDCInfo(struct xgi_hw_device_info *HwDeviceExtension,
22			     struct vb_device_info *pVBInfo);
23void XGISetDPMS(struct xgi_hw_device_info *pXGIHWDE,
24		unsigned long VESA_POWER_STATE);
25unsigned char XGINew_BridgeIsEnable(struct xgi_hw_device_info *, struct vb_device_info *pVBInfo);
26unsigned char XGINew_Sense(unsigned short tempbx, unsigned short tempcx,
27		     struct vb_device_info *pVBInfo);
28unsigned char XGINew_SenseHiTV(struct xgi_hw_device_info *HwDeviceExtension,
29			       struct vb_device_info *pVBInfo);
30
31/**************************************************************
32	Dynamic Sense
33*************************************************************/
34
35void XGI_WaitDisplay(void);
36unsigned char XGI_Is301C(struct vb_device_info *);
37unsigned char XGI_Is301LV(struct vb_device_info *);
38
39
40
41/* --------------------------------------------------------------------- */
42/* Function : XGINew_Is301B */
43/* Input : */
44/* Output : */
45/* Description : */
46/* --------------------------------------------------------------------- */
47unsigned char XGINew_Is301B(struct vb_device_info *pVBInfo)
48{
49    unsigned short flag ;
50
51    flag = XGINew_GetReg1( pVBInfo->Part4Port , 0x01 ) ;
52
53    if ( flag > 0x0B0 )
54        return( 0 ) ;	/* 301b */
55    else
56        return( 1 ) ;
57}
58
59/* --------------------------------------------------------------------- */
60/* Function : XGI_Is301C */
61/* Input : */
62/* Output : */
63/* Description : */
64/* --------------------------------------------------------------------- */
65unsigned char XGI_Is301C(struct vb_device_info *pVBInfo)
66{
67    if ( ( XGINew_GetReg1( pVBInfo->Part4Port , 0x01 ) & 0xF0 ) == 0xC0 )
68        return( 1 ) ;
69
70    if ( XGINew_GetReg1( pVBInfo->Part4Port , 0x01 ) >= 0xD0 )
71    {
72        if ( XGINew_GetReg1( pVBInfo->Part4Port , 0x39 ) == 0xE0 )
73            return( 1 ) ;
74    }
75
76    return( 0 ) ;
77}
78
79
80/* --------------------------------------------------------------------- */
81/* Function : XGI_Is301LV */
82/* Input : */
83/* Output : */
84/* Description : */
85/* --------------------------------------------------------------------- */
86unsigned char XGI_Is301LV(struct vb_device_info *pVBInfo)
87{
88    if ( XGINew_GetReg1( pVBInfo->Part4Port , 0x01 ) >= 0xD0 )
89    {
90        if ( XGINew_GetReg1( pVBInfo->Part4Port , 0x39 ) == 0xFF )
91        {
92            return( 1 ) ;
93        }
94    }
95    return( 0 ) ;
96}
97
98
99/* --------------------------------------------------------------------- */
100/* Function : XGINew_Sense */
101/* Input : */
102/* Output : */
103/* Description : */
104/* --------------------------------------------------------------------- */
105unsigned char XGINew_Sense(unsigned short tempbx,
106		     unsigned short tempcx,
107		     struct vb_device_info *pVBInfo)
108{
109    unsigned short temp, i, tempch;
110
111    temp = tempbx & 0xFF ;
112    XGINew_SetReg1( pVBInfo->Part4Port , 0x11 , temp ) ;
113    temp = ( tempbx & 0xFF00 ) >> 8 ;
114    temp |= ( tempcx & 0x00FF ) ;
115    XGINew_SetRegANDOR( pVBInfo->Part4Port , 0x10 , ~0x1F , temp ) ;
116
117    for( i = 0 ; i < 10 ; i++ )
118        XGI_LongWait( pVBInfo) ;
119
120    tempch = ( tempcx & 0x7F00 ) >> 8 ;
121    temp = XGINew_GetReg1( pVBInfo->Part4Port , 0x03 ) ;
122    temp = temp ^ ( 0x0E ) ;
123    temp &= tempch ;
124
125    if ( temp > 0 )
126        return( 1 ) ;
127    else
128        return( 0 ) ;
129}
130
131
132/* --------------------------------------------------------------------- */
133/* Function : XGISetDPMS */
134/* Input : */
135/* Output : */
136/* Description : */
137/* --------------------------------------------------------------------- */
138void XGISetDPMS(struct xgi_hw_device_info *pXGIHWDE,
139		unsigned long VESA_POWER_STATE)
140{
141    unsigned short ModeNo, ModeIdIndex;
142    unsigned char temp;
143    struct vb_device_info VBINF;
144    struct vb_device_info *pVBInfo = &VBINF;
145    pVBInfo->BaseAddr = (unsigned long)pXGIHWDE->pjIOAddress ;
146    pVBInfo->ROMAddr  = pXGIHWDE->pjVirtualRomBase ;
147
148
149    pVBInfo->IF_DEF_LVDS = 0 ;
150    pVBInfo->IF_DEF_CH7005 = 0 ;
151    pVBInfo->IF_DEF_HiVision = 1 ;
152    pVBInfo->IF_DEF_LCDA = 1 ;
153    pVBInfo->IF_DEF_CH7017 = 0 ;
154    pVBInfo->IF_DEF_YPbPr = 1 ;
155    pVBInfo->IF_DEF_CRT2Monitor = 0 ;
156    pVBInfo->IF_DEF_VideoCapture = 0 ;
157    pVBInfo->IF_DEF_ScaleLCD = 0 ;
158    pVBInfo->IF_DEF_OEMUtil = 0 ;
159    pVBInfo->IF_DEF_PWD = 0 ;
160
161    InitTo330Pointer( pXGIHWDE->jChipType,  pVBInfo ) ;
162    ReadVBIOSTablData( pXGIHWDE->jChipType , pVBInfo) ;
163
164    pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14 ;
165    pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24 ;
166    pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10 ;
167    pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e ;
168    pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12 ;
169    pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a ;
170    pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16 ;
171    pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17 ;
172    pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18 ;
173    pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19 ;
174    pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A ;
175    pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00 ;
176    pVBInfo->Part1Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_04 ;
177    pVBInfo->Part2Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_10 ;
178    pVBInfo->Part3Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_12 ;
179    pVBInfo->Part4Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 ;
180    pVBInfo->Part5Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 + 2 ;
181
182    if ( pXGIHWDE->jChipType == XG27 )
183    {
184        if ( ( XGINew_GetReg1( pVBInfo->P3d4 , 0x38 ) & 0xE0 ) == 0xC0 )
185        {
186          if ( XGINew_GetReg1( pVBInfo->P3d4 , 0x30 ) & 0x20 )
187          {
188            pVBInfo->IF_DEF_LVDS = 1 ;
189          }
190        }
191    }
192
193    if ( pVBInfo->IF_DEF_CH7007 == 0 )
194    {
195        XGINew_SetModeScratch ( pXGIHWDE , pVBInfo ) ;
196    }
197    XGINew_SetReg1( pVBInfo->P3c4 , 0x05 , 0x86 ) ;	/* 1.Openkey */
198    XGI_UnLockCRT2( pXGIHWDE , pVBInfo) ;
199    ModeNo = XGINew_GetReg1( pVBInfo->P3d4 , 0x34 ) ;
200    XGI_SearchModeID( ModeNo , &ModeIdIndex, pVBInfo ) ;
201    XGI_GetVGAType( pXGIHWDE , pVBInfo ) ;
202
203    if ( ( pXGIHWDE->ujVBChipID == VB_CHIP_301 ) || ( pXGIHWDE->ujVBChipID == VB_CHIP_302 ) || ( pVBInfo->IF_DEF_CH7007 == 1 ))
204    {
205        XGI_GetVBType( pVBInfo ) ;
206        XGI_GetVBInfo( ModeNo , ModeIdIndex , pXGIHWDE, pVBInfo ) ;
207        XGI_GetTVInfo( ModeNo , ModeIdIndex, pVBInfo ) ;
208        XGI_GetLCDInfo( ModeNo , ModeIdIndex, pVBInfo ) ;
209    }
210
211    if ( VESA_POWER_STATE == 0x00000400 )
212	    XGINew_SetReg1(pVBInfo->Part4Port, 0x31, (unsigned char)(XGINew_GetReg1(pVBInfo->Part4Port, 0x31) & 0xFE));
213    else
214	    XGINew_SetReg1(pVBInfo->Part4Port, 0x31, (unsigned char)(XGINew_GetReg1(pVBInfo->Part4Port, 0x31) | 0x01));
215
216    temp = (unsigned char)XGINew_GetReg1(pVBInfo->P3c4, 0x1f);
217    temp &= 0x3f ;
218    switch ( VESA_POWER_STATE )
219    {
220        case 0x00000000: /* on */
221            if ( ( pXGIHWDE->ujVBChipID == VB_CHIP_301 ) || ( pXGIHWDE->ujVBChipID == VB_CHIP_302 ) )
222            {
223		XGINew_SetReg1(pVBInfo->P3c4, 0x1f, (unsigned char)(temp | 0x00));
224                XGI_EnableBridge( pXGIHWDE, pVBInfo ) ;
225            }
226            else
227            {
228               if ( pXGIHWDE->jChipType == XG21 )
229               {
230                 if ( pVBInfo->IF_DEF_LVDS == 1 )
231                 {
232                   XGI_XG21BLSignalVDD( 0x01 , 0x01, pVBInfo ) ; /* LVDS VDD on */
233                   XGI_XG21SetPanelDelay( 2,pVBInfo ) ;
234                 }
235               }
236               if ( pXGIHWDE->jChipType == XG27 )
237               {
238                 if ( pVBInfo->IF_DEF_LVDS == 1 )
239                 {
240                   XGI_XG27BLSignalVDD( 0x01 , 0x01, pVBInfo ) ; /* LVDS VDD on */
241                   XGI_XG21SetPanelDelay( 2,pVBInfo ) ;
242                 }
243               }
244               XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x1F , ~0xC0 , 0x00 ) ;
245               XGINew_SetRegAND( pVBInfo->P3c4 , 0x01 , ~0x20 ) ;		/* CRT on */
246
247               if ( pXGIHWDE->jChipType == XG21 )
248               {
249                 temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x38 ) ;
250                 if ( temp & 0xE0 )
251                 {
252                   XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x09 , ~0x80 , 0x80 ) ;	/* DVO ON */
253                   XGI_SetXG21FPBits( pVBInfo );
254                   XGINew_SetRegAND( pVBInfo->P3d4 , 0x4A , ~0x20 ) ; 		/* Enable write GPIOF */
255                   /*XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x48 , ~0x20 , 0x20 ) ;*/ 	/* LCD Display ON */
256                 }
257                 XGI_XG21BLSignalVDD( 0x20 , 0x20, pVBInfo ) ; /* LVDS signal on */
258                 XGI_DisplayOn( pXGIHWDE, pVBInfo );
259               }
260               if ( pXGIHWDE->jChipType == XG27 )
261               {
262                 temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x38 ) ;
263                 if ( temp & 0xE0 )
264                 {
265                   XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x09 , ~0x80 , 0x80 ) ;	/* DVO ON */
266                   XGI_SetXG27FPBits( pVBInfo );
267                   XGINew_SetRegAND( pVBInfo->P3d4 , 0x4A , ~0x20 ) ; 		/* Enable write GPIOF */
268                   /*XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x48 , ~0x20 , 0x20 ) ;*/ 	/* LCD Display ON */
269                 }
270                 XGI_XG27BLSignalVDD( 0x20 , 0x20, pVBInfo ) ; /* LVDS signal on */
271                 XGI_DisplayOn( pXGIHWDE, pVBInfo );
272               }
273            }
274            break ;
275        case 0x00000100: /* standby */
276            if ( pXGIHWDE->jChipType >= XG21 )
277            {
278                XGI_DisplayOff( pXGIHWDE, pVBInfo );
279            }
280
281	    XGINew_SetReg1(pVBInfo->P3c4, 0x1f, (unsigned char)(temp | 0x40));
282            break ;
283        case 0x00000200: /* suspend */
284            if ( pXGIHWDE->jChipType == XG21 )
285            {
286                XGI_DisplayOff( pXGIHWDE, pVBInfo );
287                XGI_XG21BLSignalVDD( 0x20 , 0x00, pVBInfo ) ; /* LVDS signal off */
288            }
289            if ( pXGIHWDE->jChipType == XG27 )
290            {
291                XGI_DisplayOff( pXGIHWDE, pVBInfo );
292                XGI_XG27BLSignalVDD( 0x20 , 0x00, pVBInfo ) ; /* LVDS signal off */
293            }
294	    XGINew_SetReg1(pVBInfo->P3c4, 0x1f, (unsigned char)(temp | 0x80));
295            break ;
296        case 0x00000400: /* off */
297            if ( (pXGIHWDE->ujVBChipID == VB_CHIP_301 ) || ( pXGIHWDE->ujVBChipID == VB_CHIP_302 ) )
298            {
299		XGINew_SetReg1(pVBInfo->P3c4, 0x1f, (unsigned char)(temp | 0xc0));
300                XGI_DisableBridge( pXGIHWDE, pVBInfo ) ;
301            }
302            else
303            {
304               if ( pXGIHWDE->jChipType == XG21 )
305               {
306                 XGI_DisplayOff( pXGIHWDE, pVBInfo );
307
308                 XGI_XG21BLSignalVDD( 0x20 , 0x00, pVBInfo ) ; /* LVDS signal off */
309
310                 temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x38 ) ;
311                 if ( temp & 0xE0 )
312                 {
313                   XGINew_SetRegAND( pVBInfo->P3c4 , 0x09 , ~0x80 ) ;		/* DVO Off */
314                   XGINew_SetRegAND( pVBInfo->P3d4 , 0x4A , ~0x20 ) ; 		/* Enable write GPIOF */
315                   /*XGINew_SetRegAND( pVBInfo->P3d4 , 0x48 , ~0x20 ) ;*/ 		/* LCD Display OFF */
316                 }
317               }
318               if ( pXGIHWDE->jChipType == XG27 )
319               {
320                 XGI_DisplayOff( pXGIHWDE, pVBInfo );
321
322                 XGI_XG27BLSignalVDD( 0x20 , 0x00, pVBInfo ) ; /* LVDS signal off */
323
324                 temp = XGINew_GetReg1( pVBInfo->P3d4 , 0x38 ) ;
325                 if ( temp & 0xE0 )
326                 {
327                   XGINew_SetRegAND( pVBInfo->P3c4 , 0x09 , ~0x80 ) ;		/* DVO Off */
328                 }
329               }
330               XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x1F , ~0xC0 , 0xC0 ) ;
331               XGINew_SetRegOR( pVBInfo->P3c4 , 0x01 , 0x20 ) ;		/* CRT Off */
332
333               if ( ( pXGIHWDE->jChipType == XG21 ) && ( pVBInfo->IF_DEF_LVDS == 1 ) )
334               {
335                 XGI_XG21SetPanelDelay( 4,pVBInfo ) ;
336                 XGI_XG21BLSignalVDD( 0x01 , 0x00, pVBInfo ) ; /* LVDS VDD off */
337                 XGI_XG21SetPanelDelay( 5,pVBInfo ) ;
338               }
339               if ( ( pXGIHWDE->jChipType == XG27 ) && ( pVBInfo->IF_DEF_LVDS == 1 ) )
340               {
341                 XGI_XG21SetPanelDelay( 4,pVBInfo ) ;
342                 XGI_XG27BLSignalVDD( 0x01 , 0x00, pVBInfo ) ; /* LVDS VDD off */
343                 XGI_XG21SetPanelDelay( 5,pVBInfo ) ;
344               }
345            }
346            break ;
347
348        default:
349            break ;
350    }
351    XGI_LockCRT2( pXGIHWDE , pVBInfo ) ;
352}
353
354
355
356/* --------------------------------------------------------------------- */
357/* Function : XGI_GetSenseStatus */
358/* Input : */
359/* Output : */
360/* Description : */
361/* --------------------------------------------------------------------- */
362void XGI_GetSenseStatus(struct xgi_hw_device_info *HwDeviceExtension, struct vb_device_info *pVBInfo)
363{
364    unsigned short tempax = 0 , tempbx , tempcx , temp ,
365           P2reg0 = 0 , SenseModeNo = 0 , OutputSelect = *pVBInfo->pOutputSelect ,
366           ModeIdIndex , i ;
367    pVBInfo->BaseAddr = (unsigned long)HwDeviceExtension->pjIOAddress ;
368
369    if ( pVBInfo->IF_DEF_LVDS == 1 )
370    {
371        tempax = XGINew_GetReg1( pVBInfo->P3c4 , 0x1A ) ;	/* ynlai 02/27/2002 */
372        tempbx = XGINew_GetReg1( pVBInfo->P3c4 , 0x1B ) ;
373        tempax = ( ( tempax & 0xFE ) >> 1 ) | ( tempbx << 8 ) ;
374        if ( tempax == 0x00 )
375        {		/* Get Panel id from DDC */
376            temp = XGINew_GetLCDDDCInfo( HwDeviceExtension, pVBInfo ) ;
377            if ( temp == 1 )
378            {		/* LCD connect */
379                XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x39 , 0xFF , 0x01 ) ;	/* set CR39 bit0="1" */
380                XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x37 , 0xEF , 0x00 ) ;	/* clean CR37 bit4="0" */
381                temp = LCDSense ;
382            }
383            else
384            {		/* LCD don't connect */
385                temp = 0 ;
386            }
387        }
388        else
389        {
390            XGINew_GetPanelID(pVBInfo) ;
391            temp = LCDSense ;
392        }
393
394        tempbx = ~( LCDSense | AVIDEOSense | SVIDEOSense ) ;
395        XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x32 , tempbx , temp ) ;
396    }
397    else
398    {		/* for 301 */
399        if ( pVBInfo->VBInfo & SetCRT2ToHiVisionTV )
400        {	/* for HiVision */
401            tempax = XGINew_GetReg1( pVBInfo->P3c4 , 0x38 ) ;
402            temp = tempax & 0x01 ;
403            tempax = XGINew_GetReg1( pVBInfo->P3c4 , 0x3A ) ;
404            temp = temp | ( tempax & 0x02 ) ;
405            XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x32 , 0xA0 , temp ) ;
406        }
407        else
408        {
409            if ( XGI_BridgeIsOn( pVBInfo ) )
410            {
411                P2reg0 = XGINew_GetReg1( pVBInfo->Part2Port , 0x00 ) ;
412                if ( !XGINew_BridgeIsEnable( HwDeviceExtension, pVBInfo ) )
413                {
414                    SenseModeNo = 0x2e ;
415                    /* XGINew_SetReg1( pVBInfo->P3d4 , 0x30 , 0x41 ) ; */
416                    /* XGISetModeNew( HwDeviceExtension , 0x2e ) ; // ynlai InitMode */
417
418                    temp = XGI_SearchModeID( SenseModeNo , &ModeIdIndex, pVBInfo ) ;
419                    XGI_GetVGAType( HwDeviceExtension , pVBInfo) ;
420                    XGI_GetVBType( pVBInfo ) ;
421                    pVBInfo->SetFlag = 0x00 ;
422                    pVBInfo->ModeType = ModeVGA ;
423                    pVBInfo->VBInfo = SetCRT2ToRAMDAC | LoadDACFlag | SetInSlaveMode ;
424                    XGI_GetLCDInfo( 0x2e , ModeIdIndex, pVBInfo ) ;
425                    XGI_GetTVInfo(  0x2e , ModeIdIndex, pVBInfo ) ;
426                    XGI_EnableBridge( HwDeviceExtension, pVBInfo ) ;
427                    XGI_SetCRT2Group301( SenseModeNo , HwDeviceExtension, pVBInfo ) ;
428                    XGI_SetCRT2ModeRegs( 0x2e , HwDeviceExtension, pVBInfo ) ;
429                    /* XGI_DisableBridge( HwDeviceExtension, pVBInfo ) ; */
430                    XGINew_SetRegANDOR( pVBInfo->P3c4 , 0x01 , 0xDF , 0x20 ) ;	/* Display Off 0212 */
431                    for( i = 0 ; i < 20 ; i++ )
432                    {
433                        XGI_LongWait(pVBInfo) ;
434                    }
435                }
436                XGINew_SetReg1( pVBInfo->Part2Port , 0x00 , 0x1c ) ;
437                tempax = 0 ;
438                tempbx = *pVBInfo->pRGBSenseData ;
439
440                if ( !( XGINew_Is301B( pVBInfo ) ) )
441                {
442                    tempbx = *pVBInfo->pRGBSenseData2 ;
443                }
444
445                tempcx = 0x0E08 ;
446                if ( XGINew_Sense(tempbx , tempcx, pVBInfo ) )
447                {
448                    if ( XGINew_Sense(tempbx , tempcx, pVBInfo ) )
449                    {
450                        tempax |= Monitor2Sense ;
451                    }
452                }
453
454                if ( pVBInfo->VBType & VB_XGI301C)
455                {
456                    XGINew_SetRegOR( pVBInfo->Part4Port , 0x0d , 0x04 ) ;
457                }
458
459		if ( XGINew_SenseHiTV( HwDeviceExtension , pVBInfo) )		/* add by kuku for Multi-adapter sense HiTV */
460		{
461		    tempax |= HiTVSense ;
462                    if ( ( pVBInfo->VBType & VB_XGI301C ) )
463                    {
464                	tempax ^= ( HiTVSense | YPbPrSense ) ;
465                    }
466                }
467
468		if ( !( tempax & ( HiTVSense | YPbPrSense ) ) )		/* start */
469                {
470
471                    tempbx = *pVBInfo->pYCSenseData ;
472
473                    if ( !( XGINew_Is301B(  pVBInfo ) ) )
474                    {
475                      tempbx=*pVBInfo->pYCSenseData2;
476                    }
477
478                    tempcx = 0x0604 ;
479                    if ( XGINew_Sense(tempbx , tempcx, pVBInfo ) )
480                    {
481                      if ( XGINew_Sense(tempbx , tempcx, pVBInfo ) )
482                      {
483                          tempax |= SVIDEOSense ;
484                      }
485                    }
486
487                    if ( OutputSelect & BoardTVType )
488                    {
489                      tempbx = *pVBInfo->pVideoSenseData ;
490
491                      if ( !( XGINew_Is301B( pVBInfo ) ) )
492                      {
493                          tempbx = *pVBInfo->pVideoSenseData2 ;
494                      }
495
496                      tempcx = 0x0804 ;
497                      if ( XGINew_Sense(tempbx , tempcx, pVBInfo ) )
498                      {
499                          if ( XGINew_Sense(tempbx , tempcx, pVBInfo ) )
500                          {
501                              tempax |= AVIDEOSense ;
502                          }
503                      }
504                    }
505                    else
506                    {
507                      if ( !( tempax & SVIDEOSense ) )
508                      {
509                        tempbx = *pVBInfo->pVideoSenseData ;
510
511                        if ( !( XGINew_Is301B( pVBInfo ) ) )
512                        {
513                            tempbx=*pVBInfo->pVideoSenseData2;
514                        }
515
516                        tempcx = 0x0804 ;
517                        if ( XGINew_Sense(tempbx , tempcx, pVBInfo ) )
518                        {
519                            if ( XGINew_Sense(tempbx , tempcx, pVBInfo ) )
520                            {
521                                tempax |= AVIDEOSense ;
522                            }
523                        }
524                      }
525                    }
526                }
527    	    } /* end */
528            if ( !( tempax & Monitor2Sense ) )
529            {
530                if ( XGINew_SenseLCD( HwDeviceExtension, pVBInfo ) )
531                {
532                    tempax |= LCDSense ;
533                }
534            }
535            tempbx = 0 ;
536            tempcx = 0 ;
537            XGINew_Sense(tempbx , tempcx, pVBInfo ) ;
538
539            XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x32 , ~0xDF , tempax ) ;
540            XGINew_SetReg1( pVBInfo->Part2Port , 0x00 , P2reg0 ) ;
541
542            if ( !( P2reg0 & 0x20 ) )
543            {
544                pVBInfo->VBInfo = DisableCRT2Display ;
545                /* XGI_SetCRT2Group301( SenseModeNo , HwDeviceExtension, pVBInfo ) ; */
546            }
547        }
548    }
549    XGI_DisableBridge( HwDeviceExtension, pVBInfo ) ;		/* shampoo 0226 */
550
551}
552
553
554
555/* --------------------------------------------------------------------- */
556/* Function : XGINew_SenseLCD */
557/* Input : */
558/* Output : */
559/* Description : */
560/* --------------------------------------------------------------------- */
561unsigned short XGINew_SenseLCD(struct xgi_hw_device_info *HwDeviceExtension,
562			       struct vb_device_info *pVBInfo)
563{
564    /* unsigned short SoftSetting ; */
565    unsigned short temp ;
566
567    if ( ( HwDeviceExtension->jChipType >= XG20 ) || ( HwDeviceExtension->jChipType >= XG40 ) )
568        temp = 0 ;
569    else
570        temp=XGINew_GetPanelID(pVBInfo) ;
571
572    if( !temp )
573        temp = XGINew_GetLCDDDCInfo( HwDeviceExtension, pVBInfo ) ;
574
575    return( temp ) ;
576}
577
578
579/* --------------------------------------------------------------------- */
580/* Function : XGINew_GetLCDDDCInfo */
581/* Input : */
582/* Output : */
583/* Description : */
584/* --------------------------------------------------------------------- */
585unsigned char XGINew_GetLCDDDCInfo(struct xgi_hw_device_info *HwDeviceExtension, struct vb_device_info *pVBInfo)
586{
587    unsigned short temp ;
588
589    /* add lcd sense */
590    if ( HwDeviceExtension->ulCRT2LCDType == LCD_UNKNOWN )
591    {
592        return( 0 ) ;
593    }
594    else
595    {
596	    temp = (unsigned short)HwDeviceExtension->ulCRT2LCDType ;
597        switch( HwDeviceExtension->ulCRT2LCDType )
598        {
599            case LCD_INVALID:
600            case LCD_800x600:
601            case LCD_1024x768:
602            case LCD_1280x1024:
603                break ;
604
605            case LCD_640x480:
606            case LCD_1024x600:
607            case LCD_1152x864:
608            case LCD_1280x960:
609            case LCD_1152x768:
610                temp = 0 ;
611                break ;
612
613            case LCD_1400x1050:
614            case LCD_1280x768:
615            case LCD_1600x1200:
616                break ;
617
618            case LCD_1920x1440:
619            case LCD_2048x1536:
620                temp = 0 ;
621                break ;
622
623            default:
624                break ;
625        }
626        XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x36 , 0xF0 , temp ) ;
627        return( 1 ) ;
628    }
629}
630
631
632/* --------------------------------------------------------------------- */
633/* Function : */
634/* Input : */
635/* Output : */
636/* Description : */
637/* --------------------------------------------------------------------- */
638unsigned char XGINew_GetPanelID(struct vb_device_info *pVBInfo)
639{
640	unsigned short PanelTypeTable[16] = {
641		SyncNN | PanelRGB18Bit | Panel800x600  | _PanelType00,
642		SyncNN | PanelRGB18Bit | Panel1024x768 | _PanelType01,
643		SyncNN | PanelRGB18Bit | Panel800x600  | _PanelType02,
644		SyncNN | PanelRGB18Bit | Panel640x480  | _PanelType03,
645		SyncNN | PanelRGB18Bit | Panel1024x768 | _PanelType04,
646		SyncNN | PanelRGB18Bit | Panel1024x768 | _PanelType05,
647		SyncNN | PanelRGB18Bit | Panel1024x768 | _PanelType06,
648		SyncNN | PanelRGB24Bit | Panel1024x768 | _PanelType07,
649		SyncNN | PanelRGB18Bit | Panel800x600  | _PanelType08,
650		SyncNN | PanelRGB18Bit | Panel1024x768 | _PanelType09,
651		SyncNN | PanelRGB18Bit | Panel800x600  | _PanelType0A,
652		SyncNN | PanelRGB18Bit | Panel1024x768 | _PanelType0B,
653		SyncNN | PanelRGB18Bit | Panel1024x768 | _PanelType0C,
654		SyncNN | PanelRGB24Bit | Panel1024x768 | _PanelType0D,
655		SyncNN | PanelRGB18Bit | Panel1024x768 | _PanelType0E,
656		SyncNN | PanelRGB18Bit | Panel1024x768 | _PanelType0F };
657	unsigned short tempax , tempbx, temp;
658    /* unsigned short return_flag ; */
659
660    tempax = XGINew_GetReg1( pVBInfo->P3c4 , 0x1A ) ;
661    tempbx = tempax & 0x1E ;
662
663    if ( tempax == 0 )
664        return( 0 ) ;
665    else
666    {
667/*
668        if ( !( tempax & 0x10 ) )
669        {
670            if ( pVBInfo->IF_DEF_LVDS == 1 )
671            {
672                tempbx = 0 ;
673                temp = XGINew_GetReg1( pVBInfo->P3c4 , 0x38 ) ;
674                if ( temp & 0x40 )
675                    tempbx |= 0x08 ;
676                if ( temp & 0x20 )
677                    tempbx |= 0x02 ;
678                if ( temp & 0x01 )
679                    tempbx |= 0x01 ;
680
681                temp = XGINew_GetReg1( pVBInfo->P3c4 , 0x39 ) ;
682                if ( temp & 0x80 )
683                    tempbx |= 0x04 ;
684            }
685            else
686            {
687                return( 0 ) ;
688            }
689        }
690*/
691
692        tempbx = tempbx >> 1 ;
693        temp = tempbx & 0x00F ;
694        XGINew_SetReg1( pVBInfo->P3d4 , 0x36 , temp ) ;
695        tempbx-- ;
696        tempbx = PanelTypeTable[ tempbx ] ;
697
698        temp = ( tempbx & 0xFF00 ) >> 8 ;
699        XGINew_SetRegANDOR( pVBInfo->P3d4 , 0x37 , ~( LCDSyncBit | LCDRGB18Bit ) , temp ) ;
700        return( 1 ) ;
701    }
702}
703
704
705/* --------------------------------------------------------------------- */
706/* Function : XGINew_BridgeIsEnable */
707/* Input : */
708/* Output : */
709/* Description : */
710/* --------------------------------------------------------------------- */
711unsigned char XGINew_BridgeIsEnable(struct xgi_hw_device_info *HwDeviceExtension, struct vb_device_info *pVBInfo)
712{
713    unsigned short flag ;
714
715    if ( XGI_BridgeIsOn( pVBInfo ) == 0 )
716    {
717        flag = XGINew_GetReg1( pVBInfo->Part1Port , 0x0 ) ;
718
719        if ( flag & 0x050 )
720        {
721            return( 1 ) ;
722        }
723        else
724        {
725            return( 0 ) ;
726        }
727
728    }
729    return( 0 ) ;
730}
731
732/* ------------------------------------------------------ */
733/* Function : XGINew_SenseHiTV */
734/* Input : */
735/* Output : */
736/* Description : */
737/* ------------------------------------------------------ */
738unsigned char XGINew_SenseHiTV(struct xgi_hw_device_info *HwDeviceExtension, struct vb_device_info *pVBInfo)
739{
740    unsigned short tempbx , tempcx , temp , i , tempch;
741
742    tempbx = *pVBInfo->pYCSenseData2 ;
743
744    tempcx = 0x0604 ;
745
746    temp = tempbx & 0xFF ;
747    XGINew_SetReg1( pVBInfo->Part4Port , 0x11 , temp ) ;
748    temp = ( tempbx & 0xFF00 ) >> 8 ;
749    temp |= ( tempcx & 0x00FF ) ;
750    XGINew_SetRegANDOR( pVBInfo->Part4Port , 0x10 , ~0x1F , temp ) ;
751
752    for( i = 0 ; i < 10 ; i++ )
753        XGI_LongWait(pVBInfo) ;
754
755    tempch = ( tempcx & 0xFF00 ) >> 8;
756    temp = XGINew_GetReg1( pVBInfo->Part4Port , 0x03 ) ;
757    temp = temp ^ ( 0x0E ) ;
758    temp &= tempch ;
759
760    if ( temp !=  tempch )
761        return( 0 ) ;
762
763    tempbx = *pVBInfo->pVideoSenseData2 ;
764
765    tempcx = 0x0804 ;
766    temp = tempbx & 0xFF ;
767    XGINew_SetReg1( pVBInfo->Part4Port , 0x11 , temp ) ;
768    temp = ( tempbx & 0xFF00 ) >> 8 ;
769    temp |= ( tempcx & 0x00FF ) ;
770    XGINew_SetRegANDOR( pVBInfo->Part4Port , 0x10 , ~0x1F , temp ) ;
771
772    for( i = 0 ; i < 10 ; i++ )
773        XGI_LongWait(pVBInfo) ;
774
775    tempch = ( tempcx & 0xFF00 ) >> 8;
776    temp = XGINew_GetReg1( pVBInfo->Part4Port , 0x03 ) ;
777    temp = temp ^ ( 0x0E ) ;
778    temp &= tempch ;
779
780    if ( temp !=  tempch )
781        return( 0 ) ;
782    else
783    {
784      tempbx = 0x3FF ;
785      tempcx = 0x0804 ;
786      temp = tempbx & 0xFF ;
787      XGINew_SetReg1( pVBInfo->Part4Port , 0x11 , temp ) ;
788      temp = ( tempbx & 0xFF00 ) >> 8 ;
789      temp |= ( tempcx & 0x00FF ) ;
790      XGINew_SetRegANDOR( pVBInfo->Part4Port , 0x10 , ~0x1F , temp ) ;
791
792      for( i = 0 ; i < 10 ; i++ )
793          XGI_LongWait(pVBInfo) ;
794
795      tempch = ( tempcx & 0xFF00 ) >> 8;
796      temp = XGINew_GetReg1( pVBInfo->Part4Port , 0x03 ) ;
797      temp = temp ^ ( 0x0E ) ;
798      temp &= tempch ;
799
800      if ( temp != tempch )
801          return( 1 ) ;
802      else
803	  return( 0 ) ;
804    }
805}
806
807
808
809/*
810;-----------------------------------------------------------------------------
811;       Description: Get Panel support
812;	O/P	   :
813;            BL: Panel ID=81h for no scaler LVDS
814;		     BH: Panel enhanced Mode Count
815;		     CX: Panel H. resolution
816;		     DX: PAnel V. resolution
817;-----------------------------------------------------------------------------
818*/
819void XGI_XG21Fun14Sub70(struct vb_device_info *pVBInfo, PX86_REGS pBiosArguments)
820{
821
822    unsigned short ModeIdIndex;
823    unsigned short ModeNo;
824
825    unsigned short EModeCount;
826    unsigned short lvdstableindex;
827
828    lvdstableindex = XGI_GetLVDSOEMTableIndex( pVBInfo );
829    pBiosArguments->h.bl = 0x81;
830    pBiosArguments->x.cx = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE;
831    pBiosArguments->x.dx = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE;
832    EModeCount = 0;
833
834    pBiosArguments->x.ax = 0x0014;
835    for( ModeIdIndex = 0 ; ;  ModeIdIndex ++ )
836    {
837        ModeNo = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeID;
838        if ( pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeID == 0xFF )
839        {
840	    pBiosArguments->h.bh = (unsigned char) EModeCount;
841            return;
842        }
843        if ( !XGI_XG21CheckLVDSMode( ModeNo , ModeIdIndex, pVBInfo) )
844        {
845          continue;
846        }
847        EModeCount++ ;
848    }
849}
850/*(
851;-----------------------------------------------------------------------------
852;
853;       Description: Get Panel mode ID for enhanced mode
854;	I/P	   : BH: EModeIndex ( which < Panel enhanced Mode Count )
855;	O/P	   :
856;            BL: Mode ID
857;		     CX: H. resolution of the assigned by the index
858;		     DX: V. resolution of the assigned by the index
859;
860;-----------------------------------------------------------------------------
861*/
862void XGI_XG21Fun14Sub71(struct vb_device_info *pVBInfo, PX86_REGS pBiosArguments)
863{
864
865    unsigned short EModeCount;
866    unsigned short ModeIdIndex, resindex;
867    unsigned short ModeNo;
868    unsigned short EModeIndex = pBiosArguments->h.bh;
869
870    EModeCount = 0;
871    for( ModeIdIndex = 0 ; ;  ModeIdIndex ++ )
872    {
873        ModeNo = pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeID;
874        if ( pVBInfo->EModeIDTable[ ModeIdIndex ].Ext_ModeID == 0xFF )
875        {
876            pBiosArguments->x.ax = 0x0114;
877            return;
878        }
879        if ( !XGI_XG21CheckLVDSMode( ModeNo , ModeIdIndex, pVBInfo) )
880        {
881          continue;
882        }
883        if (EModeCount == EModeIndex)
884        {
885            resindex = XGI_GetResInfo( ModeNo , ModeIdIndex, pVBInfo ) ;
886	    pBiosArguments->h.bl = (unsigned char) ModeNo;
887            pBiosArguments->x.cx = pVBInfo->ModeResInfo[ resindex ].HTotal ;			  /* xres->ax */
888            pBiosArguments->x.dx = pVBInfo->ModeResInfo[ resindex ].VTotal ;			  /* yres->bx */
889            pBiosArguments->x.ax = 0x0014;
890        }
891        EModeCount++ ;
892
893    }
894
895}
896/*
897;-----------------------------------------------------------------------------
898;
899;       Description: Validate Panel modes ID support
900;	I/P	   :
901;            BL: ModeID
902;	O/P	   :
903;		     CX: H. resolution of the assigned by the index
904;		     DX: V. resolution of the assigned by the index
905;
906;-----------------------------------------------------------------------------
907*/
908void XGI_XG21Fun14Sub72(struct vb_device_info *pVBInfo, PX86_REGS pBiosArguments)
909{
910    unsigned short ModeIdIndex, resindex;
911    unsigned short ModeNo;
912
913
914    ModeNo = pBiosArguments->h.bl ;
915    XGI_SearchModeID( ModeNo, &ModeIdIndex, pVBInfo);
916    if ( !XGI_XG21CheckLVDSMode( ModeNo , ModeIdIndex, pVBInfo) )
917    {
918        pBiosArguments->x.cx = 0;
919        pBiosArguments->x.dx = 0;
920        pBiosArguments->x.ax = 0x0114;
921        return;
922    }
923    resindex = XGI_GetResInfo( ModeNo , ModeIdIndex, pVBInfo ) ;
924    if ( ModeNo <= 0x13 )
925    {
926        pBiosArguments->x.cx = pVBInfo->StResInfo[ resindex ].HTotal ;
927        pBiosArguments->x.dx = pVBInfo->StResInfo[ resindex ].VTotal ;
928    }
929    else
930    {
931        pBiosArguments->x.cx = pVBInfo->ModeResInfo[ resindex ].HTotal ;			  /* xres->ax */
932        pBiosArguments->x.dx = pVBInfo->ModeResInfo[ resindex ].VTotal ;			  /* yres->bx */
933    }
934
935    pBiosArguments->x.ax = 0x0014;
936
937}
938
939/*
940;-----------------------------------------------------------------------------
941;	Description: Get Customized Panel misc. information support
942;	I/P	   : Select
943;		     to get panel horizontal timing
944;			 to get panel vertical timing
945;			 to get channel clock parameter
946;            to get panel misc information
947;
948;	O/P	   :
949;		     BL: for input Select = 0 ;
950;                       BX: *Value1 = Horizontal total
951;                       CX: *Value2 = Horizontal front porch
952;                       DX: *Value2 = Horizontal sync width
953;		     BL: for input Select = 1 ;
954;                       BX: *Value1 = Vertical total
955;                       CX: *Value2 = Vertical front porch
956;                       DX: *Value2 = Vertical sync width
957;            BL: for input Select = 2 ;
958;                       BX: Value1 = The first CLK parameter
959;                       CX: Value2 = The second CLK parameter
960;		     BL: for input Select = 4 ;
961;                       BX[15]: *Value1 D[15] VESA V. Polarity
962;                       BX[14]: *Value1 D[14] VESA H. Polarity
963;                       BX[7]: *Value1 D[7] Panel V. Polarity
964;                       BX[6]: *Value1 D[6] Panel H. Polarity
965;-----------------------------------------------------------------------------
966*/
967void XGI_XG21Fun14Sub73(struct vb_device_info *pVBInfo, PX86_REGS pBiosArguments)
968{
969    unsigned char Select;
970
971    unsigned short lvdstableindex;
972
973    lvdstableindex = XGI_GetLVDSOEMTableIndex( pVBInfo );
974    Select = pBiosArguments->h.bl;
975
976    switch (Select)
977    {
978        case 0:
979                pBiosArguments->x.bx = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHT;
980                pBiosArguments->x.cx = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHFP;
981                pBiosArguments->x.dx = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHSYNC;
982                break;
983        case 1:
984                pBiosArguments->x.bx = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVT;
985                pBiosArguments->x.cx = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVFP;
986                pBiosArguments->x.dx = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVSYNC;
987                break;
988        case 2:
989                pBiosArguments->x.bx = pVBInfo->XG21_LVDSCapList[lvdstableindex].VCLKData1;
990                pBiosArguments->x.cx = pVBInfo->XG21_LVDSCapList[lvdstableindex].VCLKData2;
991                break;
992        case 4:
993                pBiosArguments->x.bx = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDS_Capability;
994                break;
995    }
996
997    pBiosArguments->x.ax = 0x0014;
998}
999
1000
1001void XGI_XG21Fun14(struct xgi_hw_device_info *pXGIHWDE, PX86_REGS pBiosArguments)
1002{
1003    struct vb_device_info VBINF;
1004    struct vb_device_info *pVBInfo = &VBINF;
1005
1006    pVBInfo->IF_DEF_LVDS = 0 ;
1007    pVBInfo->IF_DEF_CH7005 = 0 ;
1008    pVBInfo->IF_DEF_HiVision = 1 ;
1009    pVBInfo->IF_DEF_LCDA = 1 ;
1010    pVBInfo->IF_DEF_CH7017 = 0 ;
1011    pVBInfo->IF_DEF_YPbPr = 1 ;
1012    pVBInfo->IF_DEF_CRT2Monitor = 0 ;
1013    pVBInfo->IF_DEF_VideoCapture = 0 ;
1014    pVBInfo->IF_DEF_ScaleLCD = 0 ;
1015    pVBInfo->IF_DEF_OEMUtil = 0 ;
1016    pVBInfo->IF_DEF_PWD = 0 ;
1017
1018    InitTo330Pointer( pXGIHWDE->jChipType,  pVBInfo ) ;
1019    ReadVBIOSTablData( pXGIHWDE->jChipType , pVBInfo) ;
1020
1021    pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14 ;
1022    pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24 ;
1023    pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10 ;
1024    pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e ;
1025    pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12 ;
1026    pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a ;
1027    pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16 ;
1028    pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17 ;
1029    pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18 ;
1030    pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19 ;
1031    pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A ;
1032    pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00 ;
1033    pVBInfo->Part1Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_04 ;
1034    pVBInfo->Part2Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_10 ;
1035    pVBInfo->Part3Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_12 ;
1036    pVBInfo->Part4Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 ;
1037    pVBInfo->Part5Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 + 2 ;
1038
1039    switch(pBiosArguments->x.ax)
1040    {
1041    case 0x1470:
1042         XGI_XG21Fun14Sub70( pVBInfo , pBiosArguments ) ;
1043         break;
1044    case 0x1471:
1045         XGI_XG21Fun14Sub71( pVBInfo , pBiosArguments ) ;
1046         break;
1047    case 0x1472:
1048         XGI_XG21Fun14Sub72( pVBInfo , pBiosArguments ) ;
1049         break;
1050    case 0x1473:
1051         XGI_XG21Fun14Sub73( pVBInfo , pBiosArguments ) ;
1052         break;
1053    }
1054}
1055