1dfe64dd3Smacallan/* Copyright (C) 2003-2006 by XGI Technology, Taiwan.
2dfe64dd3Smacallan *
3dfe64dd3Smacallan * All Rights Reserved.
4dfe64dd3Smacallan *
5dfe64dd3Smacallan * Permission is hereby granted, free of charge, to any person obtaining
6dfe64dd3Smacallan * a copy of this software and associated documentation files (the
7dfe64dd3Smacallan * "Software"), to deal in the Software without restriction, including
8dfe64dd3Smacallan * without limitation on the rights to use, copy, modify, merge,
9dfe64dd3Smacallan * publish, distribute, sublicense, and/or sell copies of the Software,
10dfe64dd3Smacallan * and to permit persons to whom the Software is furnished to do so,
11dfe64dd3Smacallan * subject to the following conditions:
12dfe64dd3Smacallan *
13dfe64dd3Smacallan * The above copyright notice and this permission notice (including the
14dfe64dd3Smacallan * next paragraph) shall be included in all copies or substantial
15dfe64dd3Smacallan * portions of the Software.
16dfe64dd3Smacallan *
17dfe64dd3Smacallan * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18dfe64dd3Smacallan * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19dfe64dd3Smacallan * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20dfe64dd3Smacallan * NON-INFRINGEMENT.  IN NO EVENT SHALL XGI AND/OR
21dfe64dd3Smacallan *  ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22dfe64dd3Smacallan * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23dfe64dd3Smacallan * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24dfe64dd3Smacallan * DEALINGS IN THE SOFTWARE.
25dfe64dd3Smacallan */
26dfe64dd3Smacallan#ifdef HAVE_CONFIG_H
27dfe64dd3Smacallan#include "config.h"
28dfe64dd3Smacallan#endif
29dfe64dd3Smacallan
30dfe64dd3Smacallan#include "osdef.h"
31dfe64dd3Smacallan#include "vgatypes.h"
32dfe64dd3Smacallan
33dfe64dd3Smacallan
34dfe64dd3Smacallan#ifdef LINUX_KERNEL
35dfe64dd3Smacallan#include <linux/version.h>
36dfe64dd3Smacallan#include <linux/types.h>
37dfe64dd3Smacallan#include <linux/delay.h> /* udelay */
38dfe64dd3Smacallan#include "XGIfb.h"
39dfe64dd3Smacallan#endif
40dfe64dd3Smacallan
41dfe64dd3Smacallan#include "vb_def.h"
42dfe64dd3Smacallan#include "vb_struct.h"
43dfe64dd3Smacallan#include "vb_setmode.h"
44dfe64dd3Smacallan#include "vb_init.h"
45dfe64dd3Smacallan#include "vb_ext.h"
46dfe64dd3Smacallan
47dfe64dd3Smacallan#ifdef LINUX_XF86
48dfe64dd3Smacallan#include "xf86.h"
49dfe64dd3Smacallan#include "xf86PciInfo.h"
50dfe64dd3Smacallan#include "xgi.h"
51dfe64dd3Smacallan#include "xgi_regs.h"
52dfe64dd3Smacallan#endif
53dfe64dd3Smacallan
54dfe64dd3Smacallan#ifdef LINUX_KERNEL
55dfe64dd3Smacallan#include <asm/io.h>
56dfe64dd3Smacallan#include <linux/types.h>
57dfe64dd3Smacallan#endif
58dfe64dd3Smacallan
59dfe64dd3Smacallan
60dfe64dd3Smacallan
61dfe64dd3Smacallan
62dfe64dd3Smacallanstatic UCHAR XGINew_ChannelAB;
63dfe64dd3Smacallanstatic UCHAR XGINew_DataBusWidth;
64dfe64dd3Smacallan
65dfe64dd3SmacallanUSHORT XGINew_DRAMType[17][5]={{0x0C,0x0A,0x02,0x40,0x39},{0x0D,0x0A,0x01,0x40,0x48},
66dfe64dd3Smacallan                     {0x0C,0x09,0x02,0x20,0x35},{0x0D,0x09,0x01,0x20,0x44},
67dfe64dd3Smacallan                     {0x0C,0x08,0x02,0x10,0x31},{0x0D,0x08,0x01,0x10,0x40},
68dfe64dd3Smacallan                     {0x0C,0x0A,0x01,0x20,0x34},{0x0C,0x09,0x01,0x08,0x32},
69dfe64dd3Smacallan                     {0x0B,0x08,0x02,0x08,0x21},{0x0C,0x08,0x01,0x08,0x30},
70dfe64dd3Smacallan                     {0x0A,0x08,0x02,0x04,0x11},{0x0B,0x0A,0x01,0x10,0x28},
71dfe64dd3Smacallan                     {0x09,0x08,0x02,0x02,0x01},{0x0B,0x09,0x01,0x08,0x24},
72dfe64dd3Smacallan                     {0x0B,0x08,0x01,0x04,0x20},{0x0A,0x08,0x01,0x02,0x10},
73dfe64dd3Smacallan                     {0x09,0x08,0x01,0x01,0x00}};
74dfe64dd3Smacallan
75dfe64dd3Smacallanstatic const USHORT XGINew_SDRDRAM_TYPE[13][5]=
76dfe64dd3Smacallan{
77dfe64dd3Smacallan    { 2,12, 9,64,0x35},
78dfe64dd3Smacallan    { 1,13, 9,64,0x44},
79dfe64dd3Smacallan    { 2,12, 8,32,0x31},
80dfe64dd3Smacallan    { 2,11, 9,32,0x25},
81dfe64dd3Smacallan    { 1,12, 9,32,0x34},
82dfe64dd3Smacallan    { 1,13, 8,32,0x40},
83dfe64dd3Smacallan    { 2,11, 8,16,0x21},
84dfe64dd3Smacallan    { 1,12, 8,16,0x30},
85dfe64dd3Smacallan    { 1,11, 9,16,0x24},
86dfe64dd3Smacallan    { 1,11, 8, 8,0x20},
87dfe64dd3Smacallan    { 2, 9, 8, 4,0x01},
88dfe64dd3Smacallan    { 1,10, 8, 4,0x10},
89dfe64dd3Smacallan    { 1, 9, 8, 2,0x00}
90dfe64dd3Smacallan};
91dfe64dd3Smacallan
92dfe64dd3Smacallanstatic const USHORT XGINew_DDRDRAM_TYPE[4][5]=
93dfe64dd3Smacallan{
94dfe64dd3Smacallan    { 2,12, 9,64,0x35},
95dfe64dd3Smacallan    { 2,12, 8,32,0x31},
96dfe64dd3Smacallan    { 2,11, 8,16,0x21},
97dfe64dd3Smacallan    { 2, 9, 8, 4,0x01}
98dfe64dd3Smacallan};
99dfe64dd3Smacallan
100dfe64dd3Smacallanstatic const USHORT XGINew_DDRDRAM_TYPE340[4][5]=
101dfe64dd3Smacallan{
102dfe64dd3Smacallan    { 2,13, 9,64,0x45},
103dfe64dd3Smacallan    { 2,12, 9,32,0x35},
104dfe64dd3Smacallan    { 2,12, 8,16,0x31},
105dfe64dd3Smacallan    { 2,11, 8, 8,0x21}
106dfe64dd3Smacallan};
107dfe64dd3Smacallan
108dfe64dd3Smacallan/* Jong 10/05/2007; merge code */
109dfe64dd3SmacallanUSHORT XGINew_DDRDRAM_TYPE20[12][5]=
110dfe64dd3Smacallan{
111dfe64dd3Smacallan{ 2,14,11,128,0x5D},
112dfe64dd3Smacallan{ 2,14,10,64,0x59},
113dfe64dd3Smacallan{ 2,13,11,64,0x4D},
114dfe64dd3Smacallan{ 2,14, 9,32,0x55},
115dfe64dd3Smacallan{ 2,13,10,32,0x49},
116dfe64dd3Smacallan{ 2,12,11,32,0x3D},
117dfe64dd3Smacallan{ 2,14, 8,16,0x51},
118dfe64dd3Smacallan{ 2,13, 9,16,0x45},
119dfe64dd3Smacallan{ 2,12,10,16,0x39},
120dfe64dd3Smacallan{ 2,13, 8, 8,0x41},
121dfe64dd3Smacallan{ 2,12, 9, 8,0x35},
122dfe64dd3Smacallan{ 2,12, 8, 4,0x31}
123dfe64dd3Smacallan};
124dfe64dd3Smacallan
125dfe64dd3Smacallanstatic void XGINew_SetDRAMSize_340(PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO);
126dfe64dd3Smacallanstatic void XGINew_SetDRAMSize_XG45(PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO);
127dfe64dd3Smacallanstatic void XGINew_SetMemoryClock(PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO);
128dfe64dd3Smacallanstatic void XGINew_SetDRAMModeRegister340(PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO);
129dfe64dd3Smacallanstatic void XGINew_SetDRAMDefaultRegister340(PXGI_HW_DEVICE_INFO, USHORT,
130dfe64dd3Smacallan    PVB_DEVICE_INFO);
131dfe64dd3Smacallanstatic void XGINew_SetDRAMDefaultRegisterXG45(PXGI_HW_DEVICE_INFO, USHORT,
132dfe64dd3Smacallan    PVB_DEVICE_INFO);
133dfe64dd3Smacallanstatic UCHAR XGINew_Get340DRAMType(PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO);
134dfe64dd3Smacallan
135dfe64dd3Smacallanstatic int XGINew_SetDDRChannel(int index, UCHAR ChannelNo,
136dfe64dd3Smacallan    UCHAR XGINew_ChannelAB, const USHORT DRAMTYPE_TABLE[][5],
137dfe64dd3Smacallan    PVB_DEVICE_INFO pVBInfo);
138dfe64dd3Smacallan
139dfe64dd3Smacallanstatic void XGINew_SetDRAMSizingType(int index ,
140dfe64dd3Smacallan    const USHORT DRAMTYPE_TABLE[][5], PVB_DEVICE_INFO pVBInfo);
141dfe64dd3Smacallanstatic USHORT XGINew_SetDRAMSizeReg(int index,
142dfe64dd3Smacallan    const USHORT DRAMTYPE_TABLE[][5], PVB_DEVICE_INFO pVBInfo);
143dfe64dd3Smacallan
144dfe64dd3Smacallanstatic int XGINew_SetRank(int index, UCHAR RankNo, UCHAR XGINew_ChannelAB,
145dfe64dd3Smacallan    const USHORT DRAMTYPE_TABLE[][5], PVB_DEVICE_INFO pVBInfo);
146dfe64dd3Smacallan
147dfe64dd3Smacallanstatic int XGINew_CheckRanks(int RankNo, int index,
148dfe64dd3Smacallan    const USHORT DRAMTYPE_TABLE[][5], PVB_DEVICE_INFO pVBInfo);
149dfe64dd3Smacallanstatic int XGINew_CheckRank(int RankNo, int index,
150dfe64dd3Smacallan    const USHORT DRAMTYPE_TABLE[][5], PVB_DEVICE_INFO pVBInfo);
151dfe64dd3Smacallanstatic int XGINew_CheckDDRRank(int RankNo, int index,
152dfe64dd3Smacallan    const USHORT DRAMTYPE_TABLE[][5], PVB_DEVICE_INFO pVBInfo);
153dfe64dd3Smacallanstatic int XGINew_CheckDDRRanks(int RankNo, int index,
154dfe64dd3Smacallan    const USHORT DRAMTYPE_TABLE[][5], PVB_DEVICE_INFO pVBInfo);
155dfe64dd3Smacallan
156dfe64dd3Smacallanstatic int XGINew_CheckBanks(int index, const USHORT DRAMTYPE_TABLE[][5],
157dfe64dd3Smacallan    PVB_DEVICE_INFO pVBInfo);
158dfe64dd3Smacallanstatic int XGINew_CheckColumn(int index, const USHORT DRAMTYPE_TABLE[][5],
159dfe64dd3Smacallan    PVB_DEVICE_INFO pVBInfo);
160dfe64dd3Smacallan
161dfe64dd3Smacallanstatic int XGINew_DDRSizing340(PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO);
162dfe64dd3Smacallanstatic int XGINew_DDRSizingXG45(PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO);
163dfe64dd3Smacallanstatic int XGINew_SDRSizing(PVB_DEVICE_INFO);
164dfe64dd3Smacallanstatic int XGINew_DDRSizing(PVB_DEVICE_INFO);
165dfe64dd3Smacallan
166dfe64dd3Smacallan/* Jong 10/05/2007; merge code */
167dfe64dd3Smacallanstatic void     XGINew_GetXG21Sense(PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo) ;
168dfe64dd3Smacallanstatic UCHAR    GetXG21FPBits(PVB_DEVICE_INFO pVBInfo);
169dfe64dd3Smacallanstatic void     XGINew_GetXG27Sense(PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo) ;
170dfe64dd3Smacallanstatic UCHAR    GetXG27FPBits(PVB_DEVICE_INFO pVBInfo);
171dfe64dd3Smacallan
172dfe64dd3Smacallanstatic void XGINew_DDR_MRS(PVB_DEVICE_INFO pVBInfo);
173dfe64dd3Smacallanstatic void XGINew_SDR_MRS(PVB_DEVICE_INFO pVBInfo);
174dfe64dd3Smacallanstatic void XGINew_DDR1x_MRS_340(PXGI_HW_DEVICE_INFO HwDeviceExtension,
175dfe64dd3Smacallan    USHORT P3c4, PVB_DEVICE_INFO pVBInfo);
176dfe64dd3Smacallanstatic void XGINew_DDR2x_MRS_340(PXGI_HW_DEVICE_INFO HwDeviceExtension,
177dfe64dd3Smacallan    USHORT P3c4, PVB_DEVICE_INFO pVBInfo);
178dfe64dd3Smacallanstatic void XGINew_DDR2_MRS_340(PXGI_HW_DEVICE_INFO HwDeviceExtension,
179dfe64dd3Smacallan    USHORT P3c4, PVB_DEVICE_INFO pVBInfo);
180dfe64dd3Smacallanstatic void XGINew_DDR1x_DefaultRegister(PXGI_HW_DEVICE_INFO HwDeviceExtension,
181dfe64dd3Smacallan    USHORT Port, PVB_DEVICE_INFO pVBInfo);
182dfe64dd3Smacallanstatic void XGINew_DDR2x_DefaultRegister(PXGI_HW_DEVICE_INFO HwDeviceExtension,
183dfe64dd3Smacallan    USHORT Port, PVB_DEVICE_INFO pVBInfo);
184dfe64dd3Smacallanstatic void XGINew_DDR2_DefaultRegister(PXGI_HW_DEVICE_INFO HwDeviceExtension,
185dfe64dd3Smacallan    USHORT Port, PVB_DEVICE_INFO pVBInfo);
186dfe64dd3Smacallan
187dfe64dd3Smacallanstatic void XGINew_DisableChannelInterleaving(int index,
188dfe64dd3Smacallan    const USHORT XGINew_DDRDRAM_TYPE[][5], PVB_DEVICE_INFO pVBInfo);
189dfe64dd3Smacallan
190dfe64dd3Smacallanstatic void DualChipInit(PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO);
191dfe64dd3Smacallan
192dfe64dd3Smacallanstatic void XGINew_DisableRefresh(PXGI_HW_DEVICE_INFO ,PVB_DEVICE_INFO);
193dfe64dd3Smacallanstatic void XGINew_EnableRefresh(PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO);
194dfe64dd3Smacallan
195dfe64dd3Smacallanstatic void XGINew_Delay15us(ULONG);
196dfe64dd3Smacallanstatic void SetPowerConsume(PXGI_HW_DEVICE_INFO, USHORT);
197dfe64dd3Smacallanstatic void XGINew_DDR1x_MRS_XG20(USHORT, PVB_DEVICE_INFO);
198dfe64dd3Smacallanstatic void XGINew_SetDRAMModeRegister_XG20(PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO);
199dfe64dd3Smacallanstatic void XGINew_ChkSenseStatus(PXGI_HW_DEVICE_INFO, PVB_DEVICE_INFO);
200dfe64dd3Smacallan
201dfe64dd3Smacallanstatic int XGINew_ReadWriteRest( USHORT StopAddr, USHORT StartAddr,
202dfe64dd3Smacallan    PVB_DEVICE_INFO pVBInfo);
203dfe64dd3Smacallanstatic int XGI45New_ReadWriteRest(USHORT StopAddr, USHORT StartAddr,
204dfe64dd3Smacallan    PVB_DEVICE_INFO pVBInfo);
205dfe64dd3Smacallanstatic UCHAR XGINew_CheckFrequence(PVB_DEVICE_INFO pVBInfo);
206dfe64dd3Smacallanstatic void XGINew_CheckChannel(PXGI_HW_DEVICE_INFO HwDeviceExtension,
207dfe64dd3Smacallan				PVB_DEVICE_INFO pVBInfo);
208dfe64dd3Smacallan
209dfe64dd3Smacallanstatic int XGINew_RAMType;                  /*int      ModeIDOffset,StandTable,CRT1Table,ScreenOffset,REFIndex;*/
210dfe64dd3Smacallanstatic ULONG UNIROM;			  /* UNIROM */
211dfe64dd3Smacallan
212dfe64dd3Smacallan
213dfe64dd3Smacallan#ifdef LINUX_KERNEL
214dfe64dd3Smacallanvoid DelayUS(ULONG MicroSeconds)
215dfe64dd3Smacallan{
216dfe64dd3Smacallan	udelay(MicroSeconds);
217dfe64dd3Smacallan}
218dfe64dd3Smacallan#endif
219dfe64dd3Smacallan
220dfe64dd3Smacallan/* --------------------------------------------------------------------- */
221dfe64dd3Smacallan/* Function : XGIInitNew */
222dfe64dd3Smacallan/* Input : */
223dfe64dd3Smacallan/* Output : */
224dfe64dd3Smacallan/* Description : */
225dfe64dd3Smacallan/* --------------------------------------------------------------------- */
226dfe64dd3SmacallanBOOLEAN XGIInitNew(PXGI_HW_DEVICE_INFO HwDeviceExtension,
227dfe64dd3Smacallan		   PVB_DEVICE_INFO pVBInfo)
228dfe64dd3Smacallan{
229dfe64dd3Smacallan#ifndef LINUX_XF86
230dfe64dd3Smacallan    USHORT Mclockdata[ 30 ] , Eclockdata[ 30 ] ;
231dfe64dd3Smacallan    UCHAR  j , SR11 , SR17 = 0 , SR18 = 0 , SR19 = 0 ;
232dfe64dd3Smacallan    UCHAR  CR37 = 0 , CR38 = 0 , CR79 = 0 , CR7A = 0 ,
233dfe64dd3Smacallan           CR7B = 0 , CR36 = 0 , CR78 = 0 , CR3C = 0 ,
234dfe64dd3Smacallan           CR3D = 0 , CR3E = 0 , CR3F = 0 , CR35 = 0 ;
235dfe64dd3Smacallan#endif
236dfe64dd3Smacallan    UCHAR   i , temp = 0 , temp1 ,
237dfe64dd3Smacallan            VBIOSVersion[ 5 ] ;
238dfe64dd3Smacallan    ULONG   base,ChipsetID,VendorID,GraphicVendorID;
239dfe64dd3Smacallan    PUCHAR  volatile pVideoMemory;
240dfe64dd3Smacallan
241dfe64dd3Smacallan    /* ULONG j, k ; */
242dfe64dd3Smacallan
243dfe64dd3Smacallan    PXGI_DSReg pSR ;
244dfe64dd3Smacallan
245dfe64dd3Smacallan    ULONG Temp ;
246dfe64dd3Smacallan
247dfe64dd3Smacallan
248dfe64dd3Smacallan    XGINew_InitVBIOSData(HwDeviceExtension, pVBInfo);
249dfe64dd3Smacallan
250dfe64dd3Smacallan    pVideoMemory = ( PUCHAR )pVBInfo->ROMAddr;
251dfe64dd3Smacallan
252dfe64dd3Smacallan
253dfe64dd3Smacallan    Newdebugcode( 0x99 ) ;
254dfe64dd3Smacallan
255dfe64dd3Smacallan   /* if ( pVBInfo->ROMAddr == 0 ) */
256dfe64dd3Smacallan   /* return( FALSE ) ; */
257dfe64dd3Smacallan
258dfe64dd3Smacallan    if ( pVBInfo->FBAddr == 0 )
259dfe64dd3Smacallan        return( FALSE ) ;
260dfe64dd3Smacallan
261dfe64dd3Smacallan    if ( pVBInfo->BaseAddr == 0 )
262dfe64dd3Smacallan        return( FALSE ) ;
263dfe64dd3Smacallan
264dfe64dd3Smacallan    XGI_SetRegByte((XGIIOADDRESS) ( USHORT )( pVBInfo->BaseAddr + 0x12 ) , 0x67 ) ;	/* 3c2 <- 67 ,ynlai */
265dfe64dd3Smacallan
266dfe64dd3Smacallan
267dfe64dd3Smacallan    if ( !HwDeviceExtension->bIntegratedMMEnabled )
268dfe64dd3Smacallan        return( FALSE ) ;	/* alan */
269dfe64dd3Smacallan
270dfe64dd3Smacallan
271dfe64dd3Smacallan
272dfe64dd3Smacallan    XGI_MemoryCopy( VBIOSVersion , HwDeviceExtension->szVBIOSVer , 4 ) ;
273dfe64dd3Smacallan
274dfe64dd3Smacallan    VBIOSVersion[ 4 ] = 0x0 ;
275dfe64dd3Smacallan
276dfe64dd3Smacallan
277dfe64dd3Smacallan    /* ReadVBIOSData */
278dfe64dd3Smacallan    ReadVBIOSTablData( HwDeviceExtension->jChipType , pVBInfo) ;
279dfe64dd3Smacallan
280dfe64dd3Smacallan    /* 1.Openkey */
281dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x05 , 0x86 ) ;
282dfe64dd3Smacallan
283dfe64dd3Smacallan
284dfe64dd3Smacallan
285dfe64dd3Smacallan    /* 2.Reset Extended register */
286dfe64dd3Smacallan
287dfe64dd3Smacallan    for( i = 0x06 ; i < 0x20 ; i++ )
288dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , i , 0 ) ;
289dfe64dd3Smacallan
290dfe64dd3Smacallan    for( i = 0x21 ; i <= 0x27 ; i++ )
291dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , i , 0 ) ;
292dfe64dd3Smacallan
293dfe64dd3Smacallan    /* for( i = 0x06 ; i <= 0x27 ; i++ ) */
294dfe64dd3Smacallan    /* XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , i , 0 ) ; */
295dfe64dd3Smacallan
296dfe64dd3Smacallan
297dfe64dd3Smacallan    if(( HwDeviceExtension->jChipType == XG20 ) || ( HwDeviceExtension->jChipType >= XG40))
298dfe64dd3Smacallan    {
299dfe64dd3Smacallan        for( i = 0x31 ; i <= 0x3B ; i++ )
300dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , i , 0 ) ;
301dfe64dd3Smacallan    }
302dfe64dd3Smacallan    else
303dfe64dd3Smacallan    {
304dfe64dd3Smacallan        for( i = 0x31 ; i <= 0x3D ; i++ )
305dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , i , 0 ) ;
306dfe64dd3Smacallan    }
307dfe64dd3Smacallan
308dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType == XG42 )			/* [Hsuan] 2004/08/20 Auto over driver for XG42 */
309dfe64dd3Smacallan      XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x3B , 0xC0 ) ;
310dfe64dd3Smacallan
311dfe64dd3Smacallan    /* for( i = 0x30 ; i <= 0x3F ; i++ ) */
312dfe64dd3Smacallan    /* XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , i , 0 ) ; */
313dfe64dd3Smacallan
314dfe64dd3Smacallan    for( i = 0x79 ; i <= 0x7C ; i++ )
315dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , i , 0 ) ;		/* shampoo 0208 */
316dfe64dd3Smacallan
317dfe64dd3Smacallan    /* Jong 10/01/2007; SetDefPCIRegs */                                   /* alan 12/07/2006 */
318dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType == XG27 )
319dfe64dd3Smacallan    {
320dfe64dd3Smacallan      for( i = 0xD0 ; i <= 0xDB ; i++ )
321dfe64dd3Smacallan        XGI_SetReg( (XGIIOADDRESS) pVBInfo->P3d4 , i , pVBInfo->pCRD0[i-0xd0] ) ;
322dfe64dd3Smacallan      for( i = 0xDE ; i <= 0xDF ; i++ )
323dfe64dd3Smacallan        XGI_SetReg( (XGIIOADDRESS) pVBInfo->P3d4 , i , pVBInfo->pCRDE[i-0xdE] ) ;
324dfe64dd3Smacallan    }
325dfe64dd3Smacallan
326dfe64dd3Smacallan
327dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType >= XG20 )
328dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4, 0x97, pVBInfo->CR97);
329dfe64dd3Smacallan
330dfe64dd3Smacallan    /* 3.SetMemoryClock */
331dfe64dd3Smacallan    if (!(pVBInfo->SoftSetting & SoftDRAMType)) {
332dfe64dd3Smacallan        if (( HwDeviceExtension->jChipType == XG20 )||( HwDeviceExtension->jChipType == XG21 )||( HwDeviceExtension->jChipType == XG27 ))
333dfe64dd3Smacallan        {
334dfe64dd3Smacallan            temp = ( UCHAR )XGI_GetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x97 ) ;
335dfe64dd3Smacallan        }
336dfe64dd3Smacallan        else if (HwDeviceExtension->jChipType == XG45)
337dfe64dd3Smacallan        {
338dfe64dd3Smacallan            temp = 0x02 ;
339dfe64dd3Smacallan        }
340dfe64dd3Smacallan        else
341dfe64dd3Smacallan        {
342dfe64dd3Smacallan            temp = ( UCHAR )XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x3A ) ;
343dfe64dd3Smacallan        }
344dfe64dd3Smacallan    }
345dfe64dd3Smacallan
346dfe64dd3Smacallan
347dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType == XG20 )
348dfe64dd3Smacallan    	XGINew_RAMType = temp & 0x01 ;
349dfe64dd3Smacallan    else
350dfe64dd3Smacallan    {
351dfe64dd3Smacallan        XGINew_RAMType = temp & 0x03 ;	/* alan */
352dfe64dd3Smacallan    }
353dfe64dd3Smacallan
354dfe64dd3Smacallan    /* Get DRAM type */
355dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType == XG45 )
356dfe64dd3Smacallan    { }
357dfe64dd3Smacallan    else if ( HwDeviceExtension->jChipType >= XG40 )
358dfe64dd3Smacallan        XGINew_RAMType = ( int )XGINew_Get340DRAMType( HwDeviceExtension , pVBInfo) ;
359dfe64dd3Smacallan
360dfe64dd3Smacallan    if ( UNIROM == 1 ) XGINew_RAMType = 0;
361dfe64dd3Smacallan
362dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType < XG40 )
363dfe64dd3Smacallan        XGINew_SetMemoryClock( HwDeviceExtension , pVBInfo ) ;
364dfe64dd3Smacallan
365dfe64dd3Smacallan    /* 4.SetDefExt1Regs begin */
366dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4, 0x07, pVBInfo->SR07);
367dfe64dd3Smacallan
368dfe64dd3Smacallan    /* Jong 10/01/2007; add for ??? */
369dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType == XG27 )
370dfe64dd3Smacallan    {
371dfe64dd3Smacallan        XGI_SetReg( (XGIIOADDRESS) pVBInfo->P3c4 , 0x40 , *pVBInfo->pSR40 ) ;
372dfe64dd3Smacallan        XGI_SetReg( (XGIIOADDRESS)pVBInfo->P3c4 , 0x41 , *pVBInfo->pSR41 ) ;
373dfe64dd3Smacallan    }
374dfe64dd3Smacallan
375dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4, 0x11, 0x0F);
376dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4, 0x1F, pVBInfo->SR1F);
377dfe64dd3Smacallan    /* XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4, 0x20, 0x20); */
378dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4, 0x20, 0xA0);  /* alan, 2001/6/26 Frame buffer can read/write SR20 */
379dfe64dd3Smacallan
380dfe64dd3Smacallan    /* Jong 10/01/2007; added for ??? */
381dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) pVBInfo->P3c4 , 0x36 , 0x70 ) ;	/* Hsuan, 2006/01/01 H/W request for slow corner chip */
382dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType == XG27 )         /* Alan 12/07/2006 */
383dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) pVBInfo->P3c4 , 0x36 , *pVBInfo->pSR36 ) ;
384dfe64dd3Smacallan
385dfe64dd3Smacallan    /* SR11 = 0x0F ; */
386dfe64dd3Smacallan    /* XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x11 , SR11 ) ; */
387dfe64dd3Smacallan
388dfe64dd3Smacallan
389dfe64dd3Smacallan    if ( (HwDeviceExtension->jChipType != XG20)
390dfe64dd3Smacallan		&&(HwDeviceExtension->jChipType != XG21)
391dfe64dd3Smacallan		&&(HwDeviceExtension->jChipType != XG27)
392dfe64dd3Smacallan		&&(HwDeviceExtension->jChipType != XG45) )		/* kuku 2004/06/25 */
393dfe64dd3Smacallan    {
394dfe64dd3Smacallan    /* Set AGP Rate */
395dfe64dd3Smacallan    temp1 = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x3B ) ;
396dfe64dd3Smacallan    temp1 &= 0x02 ;
397dfe64dd3Smacallan    if ( temp1 == 0x02 )
398dfe64dd3Smacallan    {
399dfe64dd3Smacallan        XGI_SetRegLong((XGIIOADDRESS) 0xcf8 , 0x80000000 ) ;
400dfe64dd3Smacallan        ChipsetID = XGI_GetRegLong((XGIIOADDRESS) 0x0cfc ) ;
401dfe64dd3Smacallan        XGI_SetRegLong((XGIIOADDRESS) 0xcf8 , 0x8000002C ) ;
402dfe64dd3Smacallan        VendorID = XGI_GetRegLong((XGIIOADDRESS) 0x0cfc ) ;
403dfe64dd3Smacallan        VendorID &= 0x0000FFFF ;
404dfe64dd3Smacallan        XGI_SetRegLong((XGIIOADDRESS) 0xcf8 , 0x8001002C ) ;
405dfe64dd3Smacallan        GraphicVendorID = XGI_GetRegLong((XGIIOADDRESS) 0x0cfc ) ;
406dfe64dd3Smacallan        GraphicVendorID &= 0x0000FFFF;
407dfe64dd3Smacallan
408dfe64dd3Smacallan        if ( ChipsetID == 0x7301039 )
409dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x5F , 0x09 ) ;
410dfe64dd3Smacallan
411dfe64dd3Smacallan        ChipsetID &= 0x0000FFFF ;
412dfe64dd3Smacallan
413dfe64dd3Smacallan        if ( ( ChipsetID == 0x700E ) || ( ChipsetID == 0x1022 ) || ( ChipsetID == 0x1106 ) || ( ChipsetID == 0x10DE ) )
414dfe64dd3Smacallan        {
415dfe64dd3Smacallan            if ( ChipsetID == 0x1106 )
416dfe64dd3Smacallan            {
417dfe64dd3Smacallan                if ( ( VendorID == 0x1019 ) && ( GraphicVendorID == 0x1019 ) )
418dfe64dd3Smacallan                    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x5F , 0x0D ) ;
419dfe64dd3Smacallan                else
420dfe64dd3Smacallan                    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x5F , 0x0B ) ;
421dfe64dd3Smacallan            }
422dfe64dd3Smacallan            else
423dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x5F , 0x0B ) ;
424dfe64dd3Smacallan        }
425dfe64dd3Smacallan    }
426dfe64dd3Smacallan
427dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType >= XG40 )
428dfe64dd3Smacallan    {
429dfe64dd3Smacallan        /* Set AGP customize registers (in SetDefAGPRegs) Start */
430dfe64dd3Smacallan        for( i = 0x47 ; i <= 0x4C ; i++ )
431dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , i , pVBInfo->AGPReg[ i - 0x47 ] ) ;
432dfe64dd3Smacallan
433dfe64dd3Smacallan        for( i = 0x70 ; i <= 0x71 ; i++ )
434dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , i , pVBInfo->AGPReg[ 6 + i - 0x70 ] ) ;
435dfe64dd3Smacallan
436dfe64dd3Smacallan        for( i = 0x74 ; i <= 0x77 ; i++ )
437dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , i , pVBInfo->AGPReg[ 8 + i - 0x74 ] ) ;
438dfe64dd3Smacallan        /* Set AGP customize registers (in SetDefAGPRegs) End */
439dfe64dd3Smacallan        /*[Hsuan]2004/12/14 AGP Input Delay Adjustment on 850 */
440dfe64dd3Smacallan        XGI_SetRegLong((XGIIOADDRESS) 0xcf8 , 0x80000000 ) ;
441dfe64dd3Smacallan        ChipsetID = XGI_GetRegLong((XGIIOADDRESS) 0x0cfc ) ;
442dfe64dd3Smacallan        if ( ChipsetID == 0x25308086 )
443dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x77 , 0xF0 ) ;
444dfe64dd3Smacallan
445dfe64dd3Smacallan        HwDeviceExtension->pQueryVGAConfigSpace( HwDeviceExtension , 0x50 , 0 , &Temp ) ;	/* Get */
446dfe64dd3Smacallan        Temp >>= 20 ;
447dfe64dd3Smacallan        Temp &= 0xF ;
448dfe64dd3Smacallan
449dfe64dd3Smacallan        if ( Temp == 1 )
450dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x48 , 0x20 ) ;	/* CR48 */
451dfe64dd3Smacallan    }
452dfe64dd3Smacallan
453dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType < XG40 )
454dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x49 , pVBInfo->CR49[ 0 ] ) ;
455dfe64dd3Smacallan    }	/* != XG20 */
456dfe64dd3Smacallan
457dfe64dd3Smacallan    /* Set PCI */
458dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4, 0x23, pVBInfo->SR23);
459dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4, 0x24, pVBInfo->SR24);
460dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4, 0x25, pVBInfo->SR25[0]);
461dfe64dd3Smacallan
462dfe64dd3Smacallan    if ( (HwDeviceExtension->jChipType != XG20) &&
463dfe64dd3Smacallan		 (HwDeviceExtension->jChipType != XG21) &&
464dfe64dd3Smacallan		 (HwDeviceExtension->jChipType != XG27)	)		/* kuku 2004/06/25 */
465dfe64dd3Smacallan    {
466dfe64dd3Smacallan    /* Set VB */
467dfe64dd3Smacallan    XGI_UnLockCRT2( HwDeviceExtension, pVBInfo) ;
468dfe64dd3Smacallan    XGI_SetRegANDOR((XGIIOADDRESS) pVBInfo->Part0Port , 0x3F , 0xEF , 0x00 ) ;	/* alan, disable VideoCapture */
469dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->Part1Port , 0x00 , 0x00 ) ;
470dfe64dd3Smacallan    temp1 = ( UCHAR )XGI_GetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x7B ) ;		/* chk if BCLK>=100MHz */
471dfe64dd3Smacallan    temp = ( UCHAR )( ( temp1 >> 4 ) & 0x0F ) ;
472dfe64dd3Smacallan
473dfe64dd3Smacallan
474dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) pVBInfo->Part1Port, 0x02,
475dfe64dd3Smacallan                   pVBInfo->CRT2Data_1_2);
476dfe64dd3Smacallan
477dfe64dd3Smacallan
478dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->Part1Port , 0x2E , 0x08 ) ;	/* use VB */
479dfe64dd3Smacallan    } /* != XG20 */
480dfe64dd3Smacallan
481dfe64dd3Smacallan
482dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x27 , 0x1F ) ;
483dfe64dd3Smacallan
484dfe64dd3Smacallan    /* Not DDR */
485dfe64dd3Smacallan    if ((HwDeviceExtension->jChipType == XG42)
486dfe64dd3Smacallan	&& XGINew_Get340DRAMType(HwDeviceExtension, pVBInfo) != 0) {
487dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4, 0x31, (pVBInfo->SR31 & 0x3F) | 0x40);
488dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4, 0x32, (pVBInfo->SR32 & 0xFC) | 0x01);
489dfe64dd3Smacallan    }
490dfe64dd3Smacallan    else {
491dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4, 0x31, pVBInfo->SR31);
492dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4, 0x32, pVBInfo->SR32);
493dfe64dd3Smacallan    }
494dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4, 0x33, pVBInfo->SR33);
495dfe64dd3Smacallan
496dfe64dd3Smacallan
497dfe64dd3Smacallan
498dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType >= XG40 )
499dfe64dd3Smacallan      SetPowerConsume ( HwDeviceExtension , pVBInfo->P3c4);
500dfe64dd3Smacallan
501dfe64dd3Smacallan    if ( (HwDeviceExtension->jChipType != XG20) &&
502dfe64dd3Smacallan		 (HwDeviceExtension->jChipType != XG21) &&
503dfe64dd3Smacallan		 (HwDeviceExtension->jChipType != XG27) )		/* kuku 2004/06/25 */
504dfe64dd3Smacallan    {
505dfe64dd3Smacallan    if ( XGI_BridgeIsOn( pVBInfo ) == 1 )
506dfe64dd3Smacallan    {
507dfe64dd3Smacallan        {
508dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) pVBInfo->Part2Port, 0x00, 0x1C);
509dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) pVBInfo->Part4Port, 0x0D, pVBInfo->CRT2Data_4_D);
510dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) pVBInfo->Part4Port, 0x0E, pVBInfo->CRT2Data_4_E);
511dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) pVBInfo->Part4Port, 0x10, pVBInfo->CRT2Data_4_10);
512dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) pVBInfo->Part4Port, 0x0F, 0x3F);
513dfe64dd3Smacallan        }
514dfe64dd3Smacallan
515dfe64dd3Smacallan        XGI_LockCRT2( HwDeviceExtension, pVBInfo ) ;
516dfe64dd3Smacallan    }
517dfe64dd3Smacallan    }	/* != XG20 */
518dfe64dd3Smacallan
519dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType < XG40 )
520dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x83 , 0x00 ) ;
521dfe64dd3Smacallan
522dfe64dd3Smacallan
523dfe64dd3Smacallan    /* Jong 10/01/2007; added for ??? */
524dfe64dd3Smacallan    if ( HwDeviceExtension->bSkipSense == FALSE )
525dfe64dd3Smacallan    {
526dfe64dd3Smacallan        XGI_SenseCRT1(pVBInfo) ;
527dfe64dd3Smacallan        /* XGINew_DetectMonitor( HwDeviceExtension ) ; */
528dfe64dd3Smacallan        if ( ( HwDeviceExtension->jChipType == XG21 ) && (pVBInfo->IF_DEF_CH7007) )
529dfe64dd3Smacallan        {
530dfe64dd3Smacallan           XGI_GetSenseStatus( HwDeviceExtension , pVBInfo ) ; 	/* sense CRT2 */
531dfe64dd3Smacallan        }
532dfe64dd3Smacallan        if ( HwDeviceExtension->jChipType == XG21 )
533dfe64dd3Smacallan        {
534dfe64dd3Smacallan          XGI_SetRegANDOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x32 , ~Monitor1Sense , Monitor1Sense ) ;	/* Z9 default has CRT */
535dfe64dd3Smacallan       	  temp = GetXG21FPBits( pVBInfo ) ;
536dfe64dd3Smacallan          XGI_SetRegANDOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x37 , ~0x01, temp ) ;
537dfe64dd3Smacallan        }
538dfe64dd3Smacallan        if ( HwDeviceExtension->jChipType == XG27 )
539dfe64dd3Smacallan        {
540dfe64dd3Smacallan          XGI_SetRegANDOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x32 , ~Monitor1Sense , Monitor1Sense ) ;	/* Z9 default has CRT */
541dfe64dd3Smacallan       	  temp = GetXG27FPBits( pVBInfo ) ;
542dfe64dd3Smacallan          XGI_SetRegANDOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x37 , ~0x03, temp ) ;
543dfe64dd3Smacallan        }
544dfe64dd3Smacallan    }
545dfe64dd3Smacallan
546dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType >= XG40 )
547dfe64dd3Smacallan    {
548dfe64dd3Smacallan    	if (HwDeviceExtension->jChipType == XG45)
549dfe64dd3Smacallan            XGINew_SetDRAMDefaultRegisterXG45( HwDeviceExtension ,  pVBInfo->P3d4,  pVBInfo ) ;
550dfe64dd3Smacallan        else
551dfe64dd3Smacallan            XGINew_SetDRAMDefaultRegister340( HwDeviceExtension ,  pVBInfo->P3d4,  pVBInfo ) ;
552dfe64dd3Smacallan
553dfe64dd3Smacallan        if ( HwDeviceExtension->bSkipDramSizing == TRUE )
554dfe64dd3Smacallan        {
555dfe64dd3Smacallan            pSR = HwDeviceExtension->pSR ;
556dfe64dd3Smacallan            if ( pSR!=NULL )
557dfe64dd3Smacallan            {
558dfe64dd3Smacallan                while( pSR->jIdx != 0xFF )
559dfe64dd3Smacallan                {
560dfe64dd3Smacallan                    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , pSR->jIdx , pSR->jVal ) ;
561dfe64dd3Smacallan                    pSR++ ;
562dfe64dd3Smacallan                }
563dfe64dd3Smacallan            }
564dfe64dd3Smacallan            /* XGINew_SetDRAMModeRegister340( pVBInfo ) ; */
565dfe64dd3Smacallan        }   	/* SkipDramSizing */
566dfe64dd3Smacallan        else
567dfe64dd3Smacallan        {
568dfe64dd3Smacallan/*            if ( HwDeviceExtension->jChipType == XG20 )
569dfe64dd3Smacallan            {
570dfe64dd3Smacallan            	XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , pVBInfo->SR15[0][XGINew_RAMType] ) ;
571dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , pVBInfo->SR15[1][XGINew_RAMType] ) ;
572dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x20 , 0x20 ) ;
573dfe64dd3Smacallan            }
574dfe64dd3Smacallan            else*/
575dfe64dd3Smacallan            if ( HwDeviceExtension->jChipType == XG45 )
576dfe64dd3Smacallan                XGINew_SetDRAMSize_XG45( HwDeviceExtension , pVBInfo) ;
577dfe64dd3Smacallan            else
578dfe64dd3Smacallan                XGINew_SetDRAMSize_340( HwDeviceExtension , pVBInfo) ;
579dfe64dd3Smacallan        }
580dfe64dd3Smacallan    }		/* XG40 */
581dfe64dd3Smacallan
582dfe64dd3Smacallan
583dfe64dd3Smacallan
584dfe64dd3Smacallan
585dfe64dd3Smacallan    /* SetDefExt2Regs begin */
586dfe64dd3Smacallan/*
587dfe64dd3Smacallan    AGP = 1 ;
588dfe64dd3Smacallan    temp =( UCHAR )XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x3A ) ;
589dfe64dd3Smacallan    temp &= 0x30 ;
590dfe64dd3Smacallan    if ( temp == 0x30 )
591dfe64dd3Smacallan        AGP = 0 ;
592dfe64dd3Smacallan
593dfe64dd3Smacallan    if ( AGP == 0 )
594dfe64dd3Smacallan        pVBInfo->SR21 &= 0xEF ;
595dfe64dd3Smacallan
596dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x21 , pVBInfo->SR21 ) ;
597dfe64dd3Smacallan    if ( AGP == 1 )
598dfe64dd3Smacallan        pVBInfo->SR22 &= 0x20;
599dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x22 , pVBInfo->SR22 ) ;
600dfe64dd3Smacallan*/
601dfe64dd3Smacallan
602dfe64dd3Smacallan    base = 0x80000000;
603dfe64dd3Smacallan    XGI_SetRegLong(0xcf8, base);
604dfe64dd3Smacallan    Temp = (XGI_GetRegLong(0xcfc) & 0x0000FFFF);
605dfe64dd3Smacallan    if (Temp == 0x1039) {
606dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4, 0x22, pVBInfo->SR22 & 0xFE);
607dfe64dd3Smacallan    }
608dfe64dd3Smacallan    else {
609dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4, 0x22, pVBInfo->SR22);
610dfe64dd3Smacallan    }
611dfe64dd3Smacallan
612dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4, 0x21, pVBInfo->SR21);
613dfe64dd3Smacallan
614dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType == XG40 )	/* Initialize seconary chip */
615dfe64dd3Smacallan    {
616dfe64dd3Smacallan        if ( CheckDualChip(pVBInfo) )
617dfe64dd3Smacallan            DualChipInit( HwDeviceExtension , pVBInfo) ;
618dfe64dd3Smacallan        /* SetDefExt2Regs end */
619dfe64dd3Smacallan    }
620dfe64dd3Smacallan
621dfe64dd3Smacallan    /* Jong 10/01/2007; be removed and recoded */
622dfe64dd3Smacallan#if 0
623dfe64dd3Smacallan    if ( HwDeviceExtension->bSkipSense == FALSE )
624dfe64dd3Smacallan    {
625dfe64dd3Smacallan        XGI_SenseCRT1(pVBInfo) ;
626dfe64dd3Smacallan        /* XGINew_DetectMonitor( HwDeviceExtension ) ; */
627dfe64dd3Smacallan        XGI_GetSenseStatus( HwDeviceExtension , pVBInfo ) ;	/* sense CRT2 */
628dfe64dd3Smacallan    }
629dfe64dd3Smacallan#endif
630dfe64dd3Smacallan
631dfe64dd3Smacallan    XGINew_ChkSenseStatus ( HwDeviceExtension , pVBInfo ) ;
632dfe64dd3Smacallan    XGINew_SetModeScratch ( HwDeviceExtension , pVBInfo ) ;
633dfe64dd3Smacallan
634dfe64dd3Smacallan    Newdebugcode( 0x88 ) ;
635dfe64dd3Smacallan
636dfe64dd3Smacallan    /* Johnson@062403. To save time for power management. */
637dfe64dd3Smacallan    /* DelayMS(1000); */
638dfe64dd3Smacallan    /* ~Johnson@062403. */
639dfe64dd3Smacallan    /* XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x32 , 0x28 ) ; //0207 temp */
640dfe64dd3Smacallan    /* XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x36 , 0x02 ) ; //0207 temp */
641dfe64dd3Smacallan
642dfe64dd3Smacallan    return( TRUE ) ;
643dfe64dd3Smacallan} /* end of init */
644dfe64dd3Smacallan
645dfe64dd3Smacallan
646dfe64dd3Smacallan
647dfe64dd3Smacallan/* --------------------------------------------------------------------- */
648dfe64dd3Smacallan/* Function : DualChipInit */
649dfe64dd3Smacallan/* Input : */
650dfe64dd3Smacallan/* Output : */
651dfe64dd3Smacallan/* Description : Initialize the secondary chip. */
652dfe64dd3Smacallan/* --------------------------------------------------------------------- */
653dfe64dd3Smacallanvoid DualChipInit( PXGI_HW_DEVICE_INFO HwDeviceExtension ,PVB_DEVICE_INFO pVBInfo)
654dfe64dd3Smacallan{
655dfe64dd3Smacallan#ifdef LINUX_XF86
656dfe64dd3Smacallan    USHORT  BaseAddr2nd = (USHORT)(ULONG)HwDeviceExtension->pj2ndIOAddress ;
657dfe64dd3Smacallan#else
658dfe64dd3Smacallan    USHORT  BaseAddr2nd = (USHORT)HwDeviceExtension->pj2ndIOAddress ;
659dfe64dd3Smacallan#endif
660dfe64dd3Smacallan    USHORT  XGINew_P3C3 = pVBInfo->BaseAddr + VIDEO_SUBSYSTEM_ENABLE_PORT ;
661dfe64dd3Smacallan    USHORT  XGINew_P3CC = pVBInfo->BaseAddr + MISC_OUTPUT_REG_READ_PORT ;
662dfe64dd3Smacallan    USHORT  XGINew_2ndP3C3 = BaseAddr2nd + VIDEO_SUBSYSTEM_ENABLE_PORT ;
663dfe64dd3Smacallan    USHORT  XGINew_2ndP3D4 = BaseAddr2nd + CRTC_ADDRESS_PORT_COLOR ;
664dfe64dd3Smacallan    USHORT  XGINew_2ndP3C4 = BaseAddr2nd + SEQ_ADDRESS_PORT ;
665dfe64dd3Smacallan    USHORT  XGINew_2ndP3C2 = BaseAddr2nd + MISC_OUTPUT_REG_WRITE_PORT ;
666dfe64dd3Smacallan    ULONG   Temp ;
667dfe64dd3Smacallan    UCHAR   tempal , i ;
668dfe64dd3Smacallan
669dfe64dd3Smacallan    pVBInfo->ROMAddr     = HwDeviceExtension->pjVirtualRomBase ;
670dfe64dd3Smacallan    pVBInfo->BaseAddr    = (USHORT)HwDeviceExtension->pjIOAddress ;
671dfe64dd3Smacallan    /* Programming Congiguration Space in Secondary Chip */
672dfe64dd3Smacallan    /* set CRA1 D[6] = 1 */
673dfe64dd3Smacallan    XGI_SetRegANDOR((XGIIOADDRESS) pVBInfo->P3d4 , 0xA1 , 0xBF , 0x40 ) ;
674dfe64dd3Smacallan
675dfe64dd3Smacallan    /* Write 2nd Chip Configuration Info into Configuration Space */
676dfe64dd3Smacallan    /* Command CNFG04 */
677dfe64dd3Smacallan    HwDeviceExtension->pQueryVGAConfigSpace( HwDeviceExtension , PCI_COMMAND , 0 , &Temp ) ; /* Get */
678dfe64dd3Smacallan    HwDeviceExtension->pQueryVGAConfigSpace( HwDeviceExtension , PCI_COMMAND + 0x80 , 1 , &Temp ) ; /* Set */
679dfe64dd3Smacallan    /* Latency Timer CNFG0C */
680dfe64dd3Smacallan    HwDeviceExtension->pQueryVGAConfigSpace( HwDeviceExtension , 0x0c , 0 , &Temp ) ; /* Get */
681dfe64dd3Smacallan    HwDeviceExtension->pQueryVGAConfigSpace( HwDeviceExtension , 0x0c + 0x80 , 1 , &Temp ) ; /* Set */
682dfe64dd3Smacallan    /* Linear space */
683dfe64dd3Smacallan    HwDeviceExtension->pQueryVGAConfigSpace( HwDeviceExtension , 0x10 , 0 , &Temp ) ; /* Get */
684dfe64dd3Smacallan    HwDeviceExtension->pQueryVGAConfigSpace( HwDeviceExtension , 0x10 + 0x80 , 1 , &Temp ) ; /* Set */
685dfe64dd3Smacallan    /* MMIO space */
686dfe64dd3Smacallan    HwDeviceExtension->pQueryVGAConfigSpace( HwDeviceExtension , 0x14 , 0 , &Temp ) ; /* Get */
687dfe64dd3Smacallan    Temp += 0x40000;
688dfe64dd3Smacallan    HwDeviceExtension->pQueryVGAConfigSpace( HwDeviceExtension , 0x14 + 0x80 , 1 , &Temp ) ; /* Set */
689dfe64dd3Smacallan    /* Relocated IO space */
690dfe64dd3Smacallan    HwDeviceExtension->pQueryVGAConfigSpace( HwDeviceExtension , 0x18 , 0 , &Temp ) ; /* Get */
691dfe64dd3Smacallan    Temp += 0x80;
692dfe64dd3Smacallan    HwDeviceExtension->pQueryVGAConfigSpace( HwDeviceExtension , 0x18 + 0x80 , 1 , &Temp ) ; /* Set */
693dfe64dd3Smacallan    /* Miscellaneous reg(input port 3cch,output port 3c2h) */
694dfe64dd3Smacallan    tempal = XGI_GetRegByte((XGIIOADDRESS) XGINew_P3CC ) ;	/* 3cc */
695dfe64dd3Smacallan    XGI_SetRegByte((XGIIOADDRESS) XGINew_2ndP3C2 , tempal ) ;
696dfe64dd3Smacallan    /* VGA enable reg(port 3C3h) */
697dfe64dd3Smacallan    tempal = XGI_GetRegByte((XGIIOADDRESS) XGINew_P3C3 ) ;	/* 3c3 */
698dfe64dd3Smacallan    XGI_SetRegByte((XGIIOADDRESS) XGINew_2ndP3C3 , tempal ) ;
699dfe64dd3Smacallan    SetPowerConsume ( HwDeviceExtension , XGINew_2ndP3D4);
700dfe64dd3Smacallan    /* ----- CRA0=42, CRA1=81, CRA2=60, CRA3=20, CRA4=50, CRA5=40, CRA8=88 -----// */
701dfe64dd3Smacallan    /* ----- CRA9=10, CRAA=80, CRAB=01, CRAC=F1, CRAE=80, CRAF=45, CRB7=24 -----// */
702dfe64dd3Smacallan    /* primary chip */
703dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0xA0 , 0x72 ) ;
704dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0xA1 , 0x81 ) ;
705dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0xA2 , 0x60 ) ;
706dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0xA3 , 0x20 ) ;
707dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0xA4 , 0x50 ) ;
708dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0xA5 , 0x40 ) ;
709dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0xA8 , 0x88 ) ;
710dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0xA9 , 0x10 ) ;
711dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0xAA , 0x80 ) ;
712dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0xAB , 0x01 ) ;
713dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0xAC , 0xF1 ) ;
714dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0xAE , 0x80 ) ;
715dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0xAF , 0x45 ) ;
716dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0xB7 , 0x24 ) ;
717dfe64dd3Smacallan
718dfe64dd3Smacallan    /* secondary chip */
719dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3D4 , 0xA0 , 0x72 ) ;
720dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3D4 , 0xA1 , 0x81 ) ;
721dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3D4 , 0xA2 , 0x60 ) ;
722dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3D4 , 0xA3 , 0x20 ) ;
723dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3D4 , 0xA4 , 0x50 ) ;
724dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3D4 , 0xA5 , 0x40 ) ;
725dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3D4 , 0xA8 , 0x88 ) ;
726dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3D4 , 0xA9 , 0x10 ) ;
727dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3D4 , 0xAA , 0x80 ) ;
728dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3D4 , 0xAB , 0x01 ) ;
729dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3D4 , 0xAC , 0xF1 ) ;
730dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3D4 , 0xAE , 0x80 ) ;
731dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3D4 , 0xAF , 0x45 ) ;
732dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3D4 , 0xB7 , 0x24 ) ;
733dfe64dd3Smacallan
734dfe64dd3Smacallan    /* 06/20/2003 [christine] CRT threshold setting request */
735dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x78 , 0x40 ) ;
736dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x79 , 0x0C ) ;
737dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x7A , 0x34 ) ;
738dfe64dd3Smacallan
739dfe64dd3Smacallan    /* OpenKey in 2nd chip */
740dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3C4 , 0x05 , 0x86 ) ;
741dfe64dd3Smacallan
742dfe64dd3Smacallan    /* Set PCI registers */
743dfe64dd3Smacallan    tempal = (UCHAR)XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x06 ) ;
744dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3C4 , 0x06 , tempal ) ;
745dfe64dd3Smacallan
746dfe64dd3Smacallan    for( i = 0x20 ; i <= 0x25 ; i++ )
747dfe64dd3Smacallan    {
748dfe64dd3Smacallan        tempal = ( UCHAR )XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , i ) ;
749dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3C4 , i , tempal ) ;
750dfe64dd3Smacallan    }
751dfe64dd3Smacallan    for(i = 0x31; i <= 0x32; i++ )
752dfe64dd3Smacallan    {
753dfe64dd3Smacallan        tempal = ( UCHAR )XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , i ) ;
754dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3C4 , i , tempal ) ;
755dfe64dd3Smacallan    }
756dfe64dd3Smacallan    XGINew_SetDRAMDefaultRegister340( HwDeviceExtension , XGINew_2ndP3D4 , pVBInfo) ;
757dfe64dd3Smacallan
758dfe64dd3Smacallan    for(i = 0x13; i <= 0x14; i++ )
759dfe64dd3Smacallan    {
760dfe64dd3Smacallan        tempal = ( UCHAR )XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , i ) ;
761dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3C4 , i , tempal ) ;
762dfe64dd3Smacallan    }
763dfe64dd3Smacallan
764dfe64dd3Smacallan    /* Close key in 2nd chip */
765dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) XGINew_2ndP3C4 , 0x05 , 0x00 ) ;
766dfe64dd3Smacallan}
767dfe64dd3Smacallan
768dfe64dd3Smacallan
769dfe64dd3Smacallan
770dfe64dd3Smacallan
771dfe64dd3Smacallan/* ============== alan ====================== */
772dfe64dd3Smacallan
773dfe64dd3Smacallan/* --------------------------------------------------------------------- */
774dfe64dd3Smacallan/* Function : XGINew_Get340DRAMType */
775dfe64dd3Smacallan/* Input : */
776dfe64dd3Smacallan/* Output : */
777dfe64dd3Smacallan/* Description : */
778dfe64dd3Smacallan/* --------------------------------------------------------------------- */
779dfe64dd3SmacallanUCHAR XGINew_Get340DRAMType( PXGI_HW_DEVICE_INFO HwDeviceExtension , PVB_DEVICE_INFO pVBInfo)
780dfe64dd3Smacallan{
781dfe64dd3Smacallan    UCHAR data, temp ; /* Jong 10/05/2007; merge code */
782dfe64dd3Smacallan
783dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType < XG20 )
784dfe64dd3Smacallan    {
785dfe64dd3Smacallan        if (pVBInfo->SoftSetting & SoftDRAMType) {
786dfe64dd3Smacallan            return (pVBInfo->SoftSetting & 0x07);
787dfe64dd3Smacallan        }
788dfe64dd3Smacallan        else
789dfe64dd3Smacallan        {
790dfe64dd3Smacallan            data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x39 ) & 0x02 ;
791dfe64dd3Smacallan
792dfe64dd3Smacallan            if ( data == 0 )
793dfe64dd3Smacallan                data = ( XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x3A ) & 0x02 ) >> 1 ;
794dfe64dd3Smacallan
795dfe64dd3Smacallan            return( data ) ;
796dfe64dd3Smacallan        }
797dfe64dd3Smacallan    }
798dfe64dd3Smacallan    else if ( HwDeviceExtension->jChipType == XG27 )
799dfe64dd3Smacallan    {
800dfe64dd3Smacallan        if ( pVBInfo->SoftSetting & SoftDRAMType )
801dfe64dd3Smacallan        {
802dfe64dd3Smacallan            data = pVBInfo->SoftSetting & 0x07 ;
803dfe64dd3Smacallan            return( data ) ;
804dfe64dd3Smacallan        }
805dfe64dd3Smacallan        temp = XGI_GetReg( (XGIIOADDRESS) pVBInfo->P3c4 , 0x3B ) ;
806dfe64dd3Smacallan
807dfe64dd3Smacallan     	if (( temp & 0x88 )==0x80)		/* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
808dfe64dd3Smacallan       	  data = 0 ;					/*DDR*/
809dfe64dd3Smacallan        else
810dfe64dd3Smacallan       	  data = 1 ; 					/*DDRII*/
811dfe64dd3Smacallan       	return( data ) ;
812dfe64dd3Smacallan    }
813dfe64dd3Smacallan    else if ( HwDeviceExtension->jChipType == XG21 )
814dfe64dd3Smacallan    {
815dfe64dd3Smacallan        XGI_SetRegAND( (XGIIOADDRESS) pVBInfo->P3d4 , 0xB4 , ~0x02 ) ;     		/* Independent GPIO control */
816dfe64dd3Smacallan     	DelayUS(800);
817dfe64dd3Smacallan        XGI_SetRegOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x4A , 0x80 ) ;		/* Enable GPIOH read */
818dfe64dd3Smacallan        temp = XGI_GetReg( (XGIIOADDRESS) pVBInfo->P3d4 , 0x48 ) ;       		/* GPIOF 0:DVI 1:DVO */
819dfe64dd3Smacallan
820dfe64dd3Smacallan        /* HOTPLUG_SUPPORT   */
821dfe64dd3Smacallan        /* for current XG20 & XG21, GPIOH is floating, driver will fix DDR temporarily 	*/
822dfe64dd3Smacallan     	if ( temp & 0x01 )						/* DVI read GPIOH */
823dfe64dd3Smacallan       	  data = 1 ;							/*DDRII*/
824dfe64dd3Smacallan        else
825dfe64dd3Smacallan       	  data = 0 ; 							/*DDR*/
826dfe64dd3Smacallan
827dfe64dd3Smacallan        /*~HOTPLUG_SUPPORT    */
828dfe64dd3Smacallan       	XGI_SetRegOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0xB4 , 0x02 ) ;
829dfe64dd3Smacallan       	return( data ) ;
830dfe64dd3Smacallan    }
831dfe64dd3Smacallan    else
832dfe64dd3Smacallan    {
833dfe64dd3Smacallan    	data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x97 ) & 0x01 ;
834dfe64dd3Smacallan
835dfe64dd3Smacallan    	if ( data == 1 )
836dfe64dd3Smacallan            data ++ ;
837dfe64dd3Smacallan
838dfe64dd3Smacallan    	return( data );
839dfe64dd3Smacallan    }
840dfe64dd3Smacallan}
841dfe64dd3Smacallan
842dfe64dd3Smacallan
843dfe64dd3Smacallan/* --------------------------------------------------------------------- */
844dfe64dd3Smacallan/* Function : XGINew_Delay15us */
845dfe64dd3Smacallan/* Input : */
846dfe64dd3Smacallan/* Output : */
847dfe64dd3Smacallan/* Description : */
848dfe64dd3Smacallan/* --------------------------------------------------------------------- */
849dfe64dd3Smacallan/*
850dfe64dd3Smacallanvoid XGINew_Delay15us(ULONG ulMicrsoSec)
851dfe64dd3Smacallan{
852dfe64dd3Smacallan}
853dfe64dd3Smacallan*/
854dfe64dd3Smacallan
855dfe64dd3Smacallan
856dfe64dd3Smacallan/* --------------------------------------------------------------------- */
857dfe64dd3Smacallan/* Function : XGINew_SDR_MRS */
858dfe64dd3Smacallan/* Input : */
859dfe64dd3Smacallan/* Output : */
860dfe64dd3Smacallan/* Description : */
861dfe64dd3Smacallan/* --------------------------------------------------------------------- */
862dfe64dd3Smacallanvoid XGINew_SDR_MRS(PVB_DEVICE_INFO pVBInfo)
863dfe64dd3Smacallan{
864dfe64dd3Smacallan    USHORT data ;
865dfe64dd3Smacallan
866dfe64dd3Smacallan    data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x16 ) ;
867dfe64dd3Smacallan    data &= 0x3F ;          /* SR16 D7=0,D6=0 */
868dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x16 , data ) ;   /* enable mode register set(MRS) low */
869dfe64dd3Smacallan    /* XGINew_Delay15us( 0x100 ) ; */
870dfe64dd3Smacallan    data |= 0x80 ;          /* SR16 D7=1,D6=0 */
871dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x16 , data ) ;   /* enable mode register set(MRS) high */
872dfe64dd3Smacallan    /* XGINew_Delay15us( 0x100 ) ; */
873dfe64dd3Smacallan}
874dfe64dd3Smacallan
875dfe64dd3Smacallan
876dfe64dd3Smacallan/* --------------------------------------------------------------------- */
877dfe64dd3Smacallan/* Function : XGINew_DDR1x_MRS_340 */
878dfe64dd3Smacallan/* Input : */
879dfe64dd3Smacallan/* Output : */
880dfe64dd3Smacallan/* Description : */
881dfe64dd3Smacallan/* --------------------------------------------------------------------- */
882dfe64dd3Smacallanvoid XGINew_DDR1x_MRS_340(PXGI_HW_DEVICE_INFO HwDeviceExtension, USHORT P3c4,
883dfe64dd3Smacallan			  PVB_DEVICE_INFO pVBInfo)
884dfe64dd3Smacallan{
885dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , 0x01 ) ;
886dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType == XG42 )		/* XG42 BA0 & BA1  layout change */
887dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x40 ) ;
888dfe64dd3Smacallan    else
889dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x20 ) ;
890dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;
891dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x80 ) ;
892dfe64dd3Smacallan
893dfe64dd3Smacallan    /* Samsung F Die */
894dfe64dd3Smacallan    if (pVBInfo->DRAMTypeDefinition != 0x0C) {
895dfe64dd3Smacallan        DelayUS( 3000 ) ;	/* Delay 67 x 3 Delay15us */
896dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , 0x00 ) ;
897dfe64dd3Smacallan        if ( HwDeviceExtension->jChipType == XG42 )
898dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x40 ) ;
899dfe64dd3Smacallan        else
900dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x20 ) ;
901dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;
902dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x80 ) ;
903dfe64dd3Smacallan    }
904dfe64dd3Smacallan
905dfe64dd3Smacallan    DelayUS( 60 ) ;
906dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , pVBInfo->SR15[ 2 ][ XGINew_RAMType ] ) ;	/* SR18 */
907dfe64dd3Smacallan
908dfe64dd3Smacallan    if (HwDeviceExtension->jChipType == XG45)
909dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x01 ) ;				/*TSop DRAM DLL pin jump to A9*/
910dfe64dd3Smacallan    else
911dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x02 ) ;				/*TSop DRAM DLL pin jump to A9*/
912dfe64dd3Smacallan
913dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , pVBInfo->SR16[ 0 ] ) ;
914dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , pVBInfo->SR16[ 1 ] ) ;
915dfe64dd3Smacallan    DelayUS( 1000 ) ;
916dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x1B , 0x03 ) ;
917dfe64dd3Smacallan    DelayUS( 500 ) ;
918dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , pVBInfo->SR15[ 2 ][ XGINew_RAMType ] ) ;	/* SR18 */
919dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x00 ) ;
920dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , pVBInfo->SR16[ 2 ] ) ;
921dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , pVBInfo->SR16[ 3 ] ) ;
922dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x1B , 0x00 ) ;
923dfe64dd3Smacallan}
924dfe64dd3Smacallan
925dfe64dd3Smacallan
926dfe64dd3Smacallan/* --------------------------------------------------------------------- */
927dfe64dd3Smacallan/* Function : XGINew_DDR2x_MRS_340 */
928dfe64dd3Smacallan/* Input : */
929dfe64dd3Smacallan/* Output : */
930dfe64dd3Smacallan/* Description : */
931dfe64dd3Smacallan/* --------------------------------------------------------------------- */
932dfe64dd3Smacallanvoid XGINew_DDR2x_MRS_340(PXGI_HW_DEVICE_INFO HwDeviceExtension, USHORT P3c4,
933dfe64dd3Smacallan			  PVB_DEVICE_INFO pVBInfo)
934dfe64dd3Smacallan{
935dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , 0x00 ) ;
936dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType == XG42 )		/*XG42 BA0 & BA1  layout change*/
937dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x40 ) ;
938dfe64dd3Smacallan    else
939dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x20 ) ;
940dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;
941dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x80 ) ;
942dfe64dd3Smacallan
943dfe64dd3Smacallan    /* Samsung F Die */
944dfe64dd3Smacallan    if (pVBInfo->DRAMTypeDefinition != 0x0C) {
945dfe64dd3Smacallan        DelayUS( 3000 ) ;	/* Delay 67 x 3 Delay15us */
946dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , 0x00 ) ;
947dfe64dd3Smacallan        if ( HwDeviceExtension->jChipType == XG42 )
948dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x40 ) ;
949dfe64dd3Smacallan        else
950dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x20 ) ;
951dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;
952dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x80 ) ;
953dfe64dd3Smacallan    }
954dfe64dd3Smacallan
955dfe64dd3Smacallan    DelayUS( 60 ) ;
956dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , pVBInfo->SR15[ 2 ][ XGINew_RAMType ] ) ;	/* SR18 */
957dfe64dd3Smacallan    /* XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , 0x31 ) ; */
958dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x02 ) ;				/*TSop DRAM DLL pin jump to A9*/
959dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , pVBInfo->SR16[ 0 ] ) ;
960dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , pVBInfo->SR16[ 1 ] ) ;
961dfe64dd3Smacallan    DelayUS( 1000 ) ;
962dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x1B , 0x03 ) ;
963dfe64dd3Smacallan    DelayUS( 500 ) ;
964dfe64dd3Smacallan    /* XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , 0x31 ) ; */
965dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , pVBInfo->SR15[ 2 ][ XGINew_RAMType ] ) ;	/* SR18 */
966dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x00 ) ;
967dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , pVBInfo->SR16[ 2 ] ) ;
968dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , pVBInfo->SR16[ 3 ] ) ;
969dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x1B , 0x00 ) ;
970dfe64dd3Smacallan}
971dfe64dd3Smacallan
972dfe64dd3Smacallan
973dfe64dd3Smacallan/* --------------------------------------------------------------------- */
974dfe64dd3Smacallan/* Function : XGINew_DDR2_MRS_340 */
975dfe64dd3Smacallan/* Input : */
976dfe64dd3Smacallan/* Output : */
977dfe64dd3Smacallan/* Description : */
978dfe64dd3Smacallan/* --------------------------------------------------------------------- */
979dfe64dd3Smacallanvoid XGINew_DDR2_MRS_340(PXGI_HW_DEVICE_INFO HwDeviceExtension, USHORT P3c4,
980dfe64dd3Smacallan			 PVB_DEVICE_INFO pVBInfo)
981dfe64dd3Smacallan{
982dfe64dd3Smacallan    USHORT P3d4 = P3c4 + 0x10 ;
983dfe64dd3Smacallan    UCHAR data ;
984dfe64dd3Smacallan
985dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x28 , 0x64 ) ;	/* SR28 */
986dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x29 , 0x63 ) ;	/* SR29 */
987dfe64dd3Smacallan    DelayUS( 200 ) ;
988dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , 0x00 ) ;
989dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x20 ) ;
990dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;
991dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x80 ) ;
992dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , 0xC5 ) ;
993dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x23 ) ;
994dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;
995dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x80 ) ;
996dfe64dd3Smacallan    DelayUS( 2 ) ;
997dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x97 , 0x11 ) ;	/* CR97 */
998dfe64dd3Smacallan
999dfe64dd3Smacallan    if( P3c4 != pVBInfo->P3c4 )
1000dfe64dd3Smacallan    {
1001dfe64dd3Smacallan        data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x28 ) ;
1002dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3c4 , 0x28 , data ) ;	/* SR28 */
1003dfe64dd3Smacallan        data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x29 ) ;
1004dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3c4 , 0x29 , data ) ;	/* SR29 */
1005dfe64dd3Smacallan        data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x2A ) ;
1006dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3c4 , 0x2A , data ) ;	/* SR2A */
1007dfe64dd3Smacallan
1008dfe64dd3Smacallan        data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x2E ) ;
1009dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3c4 , 0x2e , data ) ;	/* SR2E */
1010dfe64dd3Smacallan        data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x2F ) ;
1011dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3c4 , 0x2f , data ) ;	/* SR2F */
1012dfe64dd3Smacallan        data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x30 ) ;
1013dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3c4 , 0x30 , data ) ;	/* SR30 */
1014dfe64dd3Smacallan    }
1015dfe64dd3Smacallan    else
1016dfe64dd3Smacallan        XGINew_SetMemoryClock( HwDeviceExtension , pVBInfo ) ;
1017dfe64dd3Smacallan
1018dfe64dd3Smacallan    DelayUS( 1000 ) ;
1019dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , 0xC5 ) ;
1020dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x23 ) ;
1021dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;
1022dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x80 ) ;
1023dfe64dd3Smacallan    DelayUS( 1 ) ;
1024dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x1B , 0x04 ) ;	/* SR1B */
1025dfe64dd3Smacallan    DelayUS( 5) ;
1026dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x1B , 0x00 ) ;	/* SR1B */
1027dfe64dd3Smacallan    DelayUS( 5 ) ;
1028dfe64dd3Smacallan    /* XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , 0x72 ) ; */
1029dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , pVBInfo->SR15[ 2 ][ XGINew_RAMType ] ) ;	/* SR18 */
1030dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x06 ) ;
1031dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x05 ) ;
1032dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x85 ) ;
1033dfe64dd3Smacallan    DelayUS( 1 ) ;
1034dfe64dd3Smacallan}
1035dfe64dd3Smacallan
1036dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1037dfe64dd3Smacallan/* Function : XGINew_DDRII_Bootup_XG27 */
1038dfe64dd3Smacallan/* Input : */
1039dfe64dd3Smacallan/* Output : */
1040dfe64dd3Smacallan/* Description : */
1041dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1042dfe64dd3Smacallanvoid XGINew_DDRII_Bootup_XG27( PXGI_HW_DEVICE_INFO HwDeviceExtension ,  USHORT P3c4 , PVB_DEVICE_INFO pVBInfo)
1043dfe64dd3Smacallan{
1044dfe64dd3Smacallan    USHORT P3d4 = P3c4 + 0x10 ;
1045dfe64dd3Smacallan    UCHAR data ;
1046dfe64dd3Smacallan    XGINew_RAMType = ( int )XGINew_GetXG20DRAMType( HwDeviceExtension , pVBInfo ) ;
1047dfe64dd3Smacallan    XGINew_SetMemoryClock( HwDeviceExtension , pVBInfo ) ;
1048dfe64dd3Smacallan
1049dfe64dd3Smacallan   /* Set Double Frequency */
1050dfe64dd3Smacallan    /* XGINew_SetReg1( P3d4 , 0x97 , 0x11 ) ; */		/* CR97 */
1051dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3d4 , 0x97 , pVBInfo->CR97 ) ;    /* CR97 */
1052dfe64dd3Smacallan
1053dfe64dd3Smacallan    DelayUS( 200 ) ;
1054dfe64dd3Smacallan
1055dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x00 ) ;   /* Set SR18 */ /*EMRS2*/
1056dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0x80 ) ;   /* Set SR19 */
1057dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x20 ) ;   /* Set SR16 */
1058dfe64dd3Smacallan    DelayUS( 15 ) ;
1059dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0xA0 ) ;   /* Set SR16 */
1060dfe64dd3Smacallan    DelayUS( 15 ) ;
1061dfe64dd3Smacallan
1062dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x00 ) ;   /* Set SR18 */ /*EMRS3*/
1063dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0xC0 ) ;   /* Set SR19 */
1064dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x20 ) ;   /* Set SR16 */
1065dfe64dd3Smacallan    DelayUS( 15 ) ;
1066dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0xA0 ) ;   /* Set SR16 */
1067dfe64dd3Smacallan    DelayUS( 15) ;
1068dfe64dd3Smacallan
1069dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x00 ) ;   /* Set SR18 */ /*EMRS1*/
1070dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0x40 ) ;   /* Set SR19 */
1071dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x20 ) ;   /* Set SR16 */
1072dfe64dd3Smacallan    DelayUS( 30 ) ;
1073dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0xA0 ) ;   /* Set SR16 */
1074dfe64dd3Smacallan    DelayUS( 15 ) ;
1075dfe64dd3Smacallan
1076dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x42 ) ;   /* Set SR18 */ /*MRS, DLL Enable*/
1077dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0x0A ) ;   /* Set SR19 */
1078dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;   /* Set SR16 */
1079dfe64dd3Smacallan    DelayUS( 30 ) ;
1080dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;   /* Set SR16 */
1081dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x80 ) ;   /* Set SR16 */
1082dfe64dd3Smacallan    /* DelayUS( 15 ) ; */
1083dfe64dd3Smacallan
1084dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x1B , 0x04 ) ;   /* Set SR1B */
1085dfe64dd3Smacallan    DelayUS( 60 ) ;
1086dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x1B , 0x00 ) ;   /* Set SR1B */
1087dfe64dd3Smacallan
1088dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x42 ) ;   /* Set SR18 */ /*MRS, DLL Reset*/
1089dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0x08 ) ;   /* Set SR19 */
1090dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;   /* Set SR16 */
1091dfe64dd3Smacallan
1092dfe64dd3Smacallan    DelayUS( 30 ) ;
1093dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x83 ) ;   /* Set SR16 */
1094dfe64dd3Smacallan    DelayUS( 15 ) ;
1095dfe64dd3Smacallan
1096dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x80 ) ;   /* Set SR18 */ /*MRS, ODT*/
1097dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0x46 ) ;   /* Set SR19 */
1098dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x20 ) ;   /* Set SR16 */
1099dfe64dd3Smacallan    DelayUS( 30 ) ;
1100dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0xA0 ) ;   /* Set SR16 */
1101dfe64dd3Smacallan    DelayUS( 15 ) ;
1102dfe64dd3Smacallan
1103dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x00 ) ;   /* Set SR18 */ /*EMRS*/
1104dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0x40 ) ;   /* Set SR19 */
1105dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x20 ) ;   /* Set SR16 */
1106dfe64dd3Smacallan    DelayUS( 30 ) ;
1107dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0xA0 ) ;   /* Set SR16 */
1108dfe64dd3Smacallan    DelayUS( 15 ) ;
1109dfe64dd3Smacallan
1110dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x1B , 0x04 ) ;   /* Set SR1B refresh control 000:close; 010:open */
1111dfe64dd3Smacallan    DelayUS( 200 ) ;
1112dfe64dd3Smacallan}
1113dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1114dfe64dd3Smacallan/* Function : XGINew_DDR2_MRS_XG20 */
1115dfe64dd3Smacallan/* Input : */
1116dfe64dd3Smacallan/* Output : */
1117dfe64dd3Smacallan/* Description : */
1118dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1119dfe64dd3Smacallanvoid XGINew_DDR2_MRS_XG20( PXGI_HW_DEVICE_INFO HwDeviceExtension ,  USHORT P3c4 , PVB_DEVICE_INFO pVBInfo)
1120dfe64dd3Smacallan{
1121dfe64dd3Smacallan    USHORT P3d4 = P3c4 + 0x10 ;
1122dfe64dd3Smacallan    UCHAR data ;
1123dfe64dd3Smacallan
1124dfe64dd3Smacallan    XGINew_RAMType = ( int )XGINew_GetXG20DRAMType( HwDeviceExtension , pVBInfo ) ;
1125dfe64dd3Smacallan    XGINew_SetMemoryClock( HwDeviceExtension , pVBInfo ) ;
1126dfe64dd3Smacallan
1127dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3d4 , 0x97 , 0x11 ) ; 	         	/* CR97 */
1128dfe64dd3Smacallan
1129dfe64dd3Smacallan    DelayUS( 200 ) ;
1130dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x00 ) ;			/* EMRS2 */
1131dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0x80 ) ;
1132dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x05 ) ;
1133dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x85 ) ;
1134dfe64dd3Smacallan
1135dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x00 ) ;			/* EMRS3 */
1136dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0xC0 ) ;
1137dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x05 ) ;
1138dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x85 ) ;
1139dfe64dd3Smacallan
1140dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x00 ) ;			/* EMRS1 */
1141dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0x40 ) ;
1142dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x05 ) ;
1143dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x85 ) ;
1144dfe64dd3Smacallan
1145dfe64dd3Smacallan   /* XGINew_SetReg1( P3c4 , 0x18 , 0x52 ) ;*/			/* MRS1 */
1146dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x42 ) ;			/* MRS1 */
1147dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0x02 ) ;
1148dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x05 ) ;
1149dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x85 ) ;
1150dfe64dd3Smacallan
1151dfe64dd3Smacallan    DelayUS( 15 ) ;
1152dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x1B , 0x04 ) ;			/* SR1B */
1153dfe64dd3Smacallan    DelayUS( 30 ) ;
1154dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x1B , 0x00 ) ;			/* SR1B */
1155dfe64dd3Smacallan    DelayUS( 100 ) ;
1156dfe64dd3Smacallan
1157dfe64dd3Smacallan    /*XGINew_SetReg1( P3c4 , 0x18 , 0x52 ) ;*/			/* MRS2 */
1158dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x42 ) ;			/* MRS1 */
1159dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0x00 ) ;
1160dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x05 ) ;
1161dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x85 ) ;
1162dfe64dd3Smacallan
1163dfe64dd3Smacallan    DelayUS( 200 ) ;
1164dfe64dd3Smacallan}
1165dfe64dd3Smacallan
1166dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1167dfe64dd3Smacallan/* Function : XGINew_DDR2_MRS_XG27 */
1168dfe64dd3Smacallan/* Input : */
1169dfe64dd3Smacallan/* Output : */
1170dfe64dd3Smacallan/* Description : */
1171dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1172dfe64dd3Smacallanvoid XGINew_DDR2_MRS_XG27( PXGI_HW_DEVICE_INFO HwDeviceExtension ,  USHORT P3c4 , PVB_DEVICE_INFO pVBInfo)
1173dfe64dd3Smacallan{
1174dfe64dd3Smacallan    USHORT P3d4 = P3c4 + 0x10 ;
1175dfe64dd3Smacallan    UCHAR data ;
1176dfe64dd3Smacallan
1177dfe64dd3Smacallan     XGINew_RAMType = ( int )XGINew_GetXG20DRAMType( HwDeviceExtension , pVBInfo ) ;
1178dfe64dd3Smacallan     XGINew_SetMemoryClock( HwDeviceExtension , pVBInfo ) ;
1179dfe64dd3Smacallan
1180dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3d4 , 0x97 , 0x11 ) ;			/* CR97 */
1181dfe64dd3Smacallan    DelayUS( 200 ) ;
1182dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x00 ) ;			/* EMRS2 */
1183dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0x80 ) ;
1184dfe64dd3Smacallan
1185dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x10 ) ;
1186dfe64dd3Smacallan    DelayUS( 15 ) ;                          /* 06/11/23 XG27 A0 for CKE enable*/
1187dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x90 ) ;
1188dfe64dd3Smacallan
1189dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x00 ) ;			/* EMRS3 */
1190dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0xC0 ) ;
1191dfe64dd3Smacallan
1192dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;
1193dfe64dd3Smacallan    DelayUS( 15 ) ;                          /*06/11/22 XG27 A0*/
1194dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x80 ) ;
1195dfe64dd3Smacallan
1196dfe64dd3Smacallan
1197dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x00 ) ;			/* EMRS1 */
1198dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0x40 ) ;
1199dfe64dd3Smacallan
1200dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;
1201dfe64dd3Smacallan    DelayUS( 15 ) ;                          /*06/11/22 XG27 A0 */
1202dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x80 ) ;
1203dfe64dd3Smacallan
1204dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x42 ) ;			/* MRS1 */
1205dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0x06 ) ;   /*[Billy]06/11/22 DLL Reset for XG27 Hynix DRAM*/
1206dfe64dd3Smacallan
1207dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;
1208dfe64dd3Smacallan    DelayUS( 15 ) ;                          /*06/11/23 XG27 A0*/
1209dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x80 ) ;
1210dfe64dd3Smacallan
1211dfe64dd3Smacallan    DelayUS( 30 ) ;                          /*06/11/23 XG27 A0 Start Auto-PreCharge*/
1212dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x1B , 0x04 ) ;			/* SR1B */
1213dfe64dd3Smacallan    DelayUS( 60 ) ;
1214dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x1B , 0x00 ) ;			/* SR1B */
1215dfe64dd3Smacallan
1216dfe64dd3Smacallan
1217dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x42 ) ;			/* MRS1 */
1218dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0x04 ) ;   /* DLL without Reset for XG27 Hynix DRAM*/
1219dfe64dd3Smacallan
1220dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;
1221dfe64dd3Smacallan    DelayUS( 30 ) ;
1222dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x80 ) ;
1223dfe64dd3Smacallan
1224dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x80 );     /*XG27 OCD ON */
1225dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0x46 );
1226dfe64dd3Smacallan
1227dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;
1228dfe64dd3Smacallan    DelayUS( 30 ) ;
1229dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x80 ) ;
1230dfe64dd3Smacallan
1231dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x18 , 0x00 );
1232dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x19 , 0x40 );
1233dfe64dd3Smacallan
1234dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;
1235dfe64dd3Smacallan    DelayUS( 30 ) ;
1236dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x16 , 0x80 ) ;
1237dfe64dd3Smacallan
1238dfe64dd3Smacallan    DelayUS( 15 ) ;                         /*Start Auto-PreCharge*/
1239dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x1B , 0x04 ) ;			/* SR1B */
1240dfe64dd3Smacallan    DelayUS( 200 ) ;
1241dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x1B , 0x03 ) ;			/* SR1B */
1242dfe64dd3Smacallan}
1243dfe64dd3Smacallan
1244dfe64dd3Smacallan
1245dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1246dfe64dd3Smacallan/* Function : XGINew_DDR1x_DefaultRegister */
1247dfe64dd3Smacallan/* Input : */
1248dfe64dd3Smacallan/* Output : */
1249dfe64dd3Smacallan/* Description : */
1250dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1251dfe64dd3Smacallanvoid XGINew_DDR1x_DefaultRegister(PXGI_HW_DEVICE_INFO HwDeviceExtension,
1252dfe64dd3Smacallan				  USHORT Port, PVB_DEVICE_INFO pVBInfo)
1253dfe64dd3Smacallan{
1254dfe64dd3Smacallan    USHORT P3d4 = Port ,
1255dfe64dd3Smacallan           P3c4 = Port - 0x10 ;
1256dfe64dd3Smacallan#ifndef LINUX_XF86
1257dfe64dd3Smacallan    UCHAR  data ;
1258dfe64dd3Smacallan#endif
1259dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType >= XG20 )
1260dfe64dd3Smacallan    {
1261dfe64dd3Smacallan        XGINew_SetMemoryClock( HwDeviceExtension , pVBInfo ) ;
1262dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , 0x82 , pVBInfo->CR40[ 11 ][ XGINew_RAMType ] ) ;	/* CR82 */
1263dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , 0x85 , pVBInfo->CR40[ 12 ][ XGINew_RAMType ] ) ;	/* CR85 */
1264dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , 0x86 , pVBInfo->CR40[ 13 ][ XGINew_RAMType ] ) ;	/* CR86 */
1265dfe64dd3Smacallan
1266dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , 0x98 , 0x01 ) ;
1267dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , 0x9A , 0x02 ) ;
1268dfe64dd3Smacallan
1269dfe64dd3Smacallan        XGINew_DDR1x_MRS_XG20( P3c4 , pVBInfo) ;
1270dfe64dd3Smacallan    }
1271dfe64dd3Smacallan    else
1272dfe64dd3Smacallan    {
1273dfe64dd3Smacallan        XGINew_SetMemoryClock( HwDeviceExtension , pVBInfo ) ;
1274dfe64dd3Smacallan
1275dfe64dd3Smacallan        switch( HwDeviceExtension->jChipType )
1276dfe64dd3Smacallan        {
1277dfe64dd3Smacallan            case XG41:
1278dfe64dd3Smacallan            case XG42:
1279dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) P3d4 , 0x82 , pVBInfo->CR40[ 11 ][ XGINew_RAMType ] ) ;	/* CR82 */
1280dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) P3d4 , 0x85 , pVBInfo->CR40[ 12 ][ XGINew_RAMType ] ) ;	/* CR85 */
1281dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) P3d4 , 0x86 , pVBInfo->CR40[ 13 ][ XGINew_RAMType ] ) ;	/* CR86 */
1282dfe64dd3Smacallan                break ;
1283dfe64dd3Smacallan            default:
1284dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) P3d4 , 0x82 , 0x88 ) ;
1285dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) P3d4 , 0x86 , 0x00 ) ;
1286dfe64dd3Smacallan                XGI_GetReg((XGIIOADDRESS) P3d4 , 0x86 ) ;				/* Insert read command for delay */
1287dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) P3d4 , 0x86 , 0x88 ) ;
1288dfe64dd3Smacallan                XGI_GetReg((XGIIOADDRESS) P3d4 , 0x86 ) ;
1289dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) P3d4 , 0x86 , pVBInfo->CR40[ 13 ][ XGINew_RAMType ] ) ;
1290dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) P3d4 , 0x82 , 0x77 ) ;
1291dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) P3d4 , 0x85 , 0x00 ) ;
1292dfe64dd3Smacallan                XGI_GetReg((XGIIOADDRESS) P3d4 , 0x85 ) ;				/* Insert read command for delay */
1293dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) P3d4 , 0x85 , 0x88 ) ;
1294dfe64dd3Smacallan                XGI_GetReg((XGIIOADDRESS) P3d4 , 0x85 ) ;				/* Insert read command for delay */
1295dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) P3d4 , 0x85 , pVBInfo->CR40[ 12 ][ XGINew_RAMType ] ) ;	/* CR85 */
1296dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) P3d4 , 0x82 , pVBInfo->CR40[ 11 ][ XGINew_RAMType ] ) ;	/* CR82 */
1297dfe64dd3Smacallan                break ;
1298dfe64dd3Smacallan        }
1299dfe64dd3Smacallan        if (HwDeviceExtension->jChipType != XG45)
1300dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) P3d4 , 0x97 , 0x00 ) ;
1301dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , 0x98 , 0x01 ) ;
1302dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , 0x9A , 0x02 ) ;
1303dfe64dd3Smacallan        XGINew_DDR1x_MRS_340( HwDeviceExtension , P3c4 , pVBInfo ) ;
1304dfe64dd3Smacallan    }
1305dfe64dd3Smacallan}
1306dfe64dd3Smacallan
1307dfe64dd3Smacallan
1308dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1309dfe64dd3Smacallan/* Function : XGINew_DDR2x_DefaultRegister */
1310dfe64dd3Smacallan/* Input : */
1311dfe64dd3Smacallan/* Output : */
1312dfe64dd3Smacallan/* Description : */
1313dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1314dfe64dd3Smacallanvoid XGINew_DDR2x_DefaultRegister(PXGI_HW_DEVICE_INFO HwDeviceExtension,
1315dfe64dd3Smacallan				  USHORT Port, PVB_DEVICE_INFO pVBInfo)
1316dfe64dd3Smacallan{
1317dfe64dd3Smacallan    USHORT P3d4 = Port ,
1318dfe64dd3Smacallan           P3c4 = Port - 0x10 ;
1319dfe64dd3Smacallan
1320dfe64dd3Smacallan#ifndef LINUX_XF86
1321dfe64dd3Smacallan    UCHAR  data ;
1322dfe64dd3Smacallan#endif
1323dfe64dd3Smacallan
1324dfe64dd3Smacallan    XGINew_SetMemoryClock( HwDeviceExtension , pVBInfo ) ;
1325dfe64dd3Smacallan
1326dfe64dd3Smacallan    /* 20040906 Hsuan modify CR82, CR85, CR86 for XG42 */
1327dfe64dd3Smacallan    switch( HwDeviceExtension->jChipType )
1328dfe64dd3Smacallan    {
1329dfe64dd3Smacallan       case XG41:
1330dfe64dd3Smacallan       case XG42:
1331dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) P3d4 , 0x82 , pVBInfo->CR40[ 11 ][ XGINew_RAMType ] ) ;	/* CR82 */
1332dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) P3d4 , 0x85 , pVBInfo->CR40[ 12 ][ XGINew_RAMType ] ) ;	/* CR85 */
1333dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) P3d4 , 0x86 , pVBInfo->CR40[ 13 ][ XGINew_RAMType ] ) ;	/* CR86 */
1334dfe64dd3Smacallan            break ;
1335dfe64dd3Smacallan       default:
1336dfe64dd3Smacallan         /* keep following setting sequence, each setting in the same reg insert idle */
1337dfe64dd3Smacallan         XGI_SetReg((XGIIOADDRESS) P3d4 , 0x82 , 0x88 ) ;
1338dfe64dd3Smacallan    	 XGI_SetReg((XGIIOADDRESS) P3d4 , 0x86 , 0x00 ) ;
1339dfe64dd3Smacallan    	 XGI_GetReg((XGIIOADDRESS) P3d4 , 0x86 ) ;				/* Insert read command for delay */
1340dfe64dd3Smacallan    	 XGI_SetReg((XGIIOADDRESS) P3d4 , 0x86 , 0x88 ) ;
1341dfe64dd3Smacallan    	 XGI_SetReg((XGIIOADDRESS) P3d4 , 0x82 , 0x77 ) ;
1342dfe64dd3Smacallan    	 XGI_SetReg((XGIIOADDRESS) P3d4 , 0x85 , 0x00 ) ;
1343dfe64dd3Smacallan    	 XGI_GetReg((XGIIOADDRESS) P3d4 , 0x85 ) ;				/* Insert read command for delay */
1344dfe64dd3Smacallan    	 XGI_SetReg((XGIIOADDRESS) P3d4 , 0x85 , 0x88 ) ;
1345dfe64dd3Smacallan    	 XGI_GetReg((XGIIOADDRESS) P3d4 , 0x85 ) ;				/* Insert read command for delay */
1346dfe64dd3Smacallan    	 XGI_SetReg((XGIIOADDRESS) P3d4 , 0x85 , pVBInfo->CR40[ 12 ][ XGINew_RAMType ] ) ;	/* CR85 */
1347dfe64dd3Smacallan    	 XGI_SetReg((XGIIOADDRESS) P3d4 , 0x82 , pVBInfo->CR40[ 11 ][ XGINew_RAMType ] ) ;	/* CR82 */
1348dfe64dd3Smacallan    }
1349dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x97 , 0x11 ) ;
1350dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType == XG42 )
1351dfe64dd3Smacallan    {
1352dfe64dd3Smacallan      XGI_SetReg((XGIIOADDRESS) P3d4 , 0x98 , 0x01 ) ;
1353dfe64dd3Smacallan    }
1354dfe64dd3Smacallan    else
1355dfe64dd3Smacallan    {
1356dfe64dd3Smacallan      XGI_SetReg((XGIIOADDRESS) P3d4 , 0x98 , 0x03 ) ;
1357dfe64dd3Smacallan    }
1358dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x9A , 0x02 ) ;
1359dfe64dd3Smacallan
1360dfe64dd3Smacallan    XGINew_DDR2x_MRS_340( HwDeviceExtension ,  P3c4 , pVBInfo ) ;
1361dfe64dd3Smacallan}
1362dfe64dd3Smacallan
1363dfe64dd3Smacallan
1364dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1365dfe64dd3Smacallan/* Function : XGINew_DDR2_DefaultRegister */
1366dfe64dd3Smacallan/* Input : */
1367dfe64dd3Smacallan/* Output : */
1368dfe64dd3Smacallan/* Description : */
1369dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1370dfe64dd3Smacallanvoid XGINew_DDR2_DefaultRegister(PXGI_HW_DEVICE_INFO HwDeviceExtension,
1371dfe64dd3Smacallan				 USHORT Port, PVB_DEVICE_INFO pVBInfo)
1372dfe64dd3Smacallan{
1373dfe64dd3Smacallan    USHORT P3d4 = Port ,
1374dfe64dd3Smacallan           P3c4 = Port - 0x10 ;
1375dfe64dd3Smacallan
1376dfe64dd3Smacallan    /* keep following setting sequence, each setting in the same reg insert idle */
1377dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x82 , 0x77 ) ;
1378dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x86 , 0x00 ) ;
1379dfe64dd3Smacallan    XGI_GetReg((XGIIOADDRESS) P3d4 , 0x86 ) ;				/* Insert read command for delay */
1380dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x86 , 0x88 ) ;
1381dfe64dd3Smacallan    XGI_GetReg((XGIIOADDRESS) P3d4 , 0x86 ) ;				/* Insert read command for delay */
1382dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x86 , pVBInfo->CR40[ 13 ][ XGINew_RAMType ] ) ;	/* CR86 */
1383dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x82 , 0x77 ) ;
1384dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x85 , 0x00 ) ;
1385dfe64dd3Smacallan    XGI_GetReg((XGIIOADDRESS) P3d4 , 0x85 ) ;				/* Insert read command for delay */
1386dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x85 , 0x88 ) ;
1387dfe64dd3Smacallan    XGI_GetReg((XGIIOADDRESS) P3d4 , 0x85 ) ;				/* Insert read command for delay */
1388dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x85 , pVBInfo->CR40[ 12 ][ XGINew_RAMType ] ) ;	/* CR85 */
1389dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x82 , pVBInfo->CR40[ 11 ][ XGINew_RAMType ] ) ;	/* CR82 */
1390dfe64dd3Smacallan
1391dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x98 , 0x03 ) ;
1392dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x9A , 0x02 ) ;
1393dfe64dd3Smacallan
1394dfe64dd3Smacallan    /* Jong 10/01/2007 */
1395dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType == XG27 )
1396dfe64dd3Smacallan       XGINew_DDRII_Bootup_XG27( HwDeviceExtension ,  P3c4 , pVBInfo) ;
1397dfe64dd3Smacallan    else if ( HwDeviceExtension->jChipType >= XG20 )
1398dfe64dd3Smacallan       XGINew_DDR2_MRS_XG20( HwDeviceExtension , P3c4, pVBInfo ) ;
1399dfe64dd3Smacallan    else
1400dfe64dd3Smacallan       XGINew_DDR2_MRS_340( HwDeviceExtension , P3c4, pVBInfo ) ;
1401dfe64dd3Smacallan}
1402dfe64dd3Smacallan
1403dfe64dd3Smacallan
1404dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1405dfe64dd3Smacallan/* Function : XGINew_SetDRAMDefaultRegister340 */
1406dfe64dd3Smacallan/* Input : */
1407dfe64dd3Smacallan/* Output : */
1408dfe64dd3Smacallan/* Description : */
1409dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1410dfe64dd3Smacallanvoid XGINew_SetDRAMDefaultRegister340( PXGI_HW_DEVICE_INFO HwDeviceExtension ,  USHORT Port , PVB_DEVICE_INFO pVBInfo)
1411dfe64dd3Smacallan{
1412dfe64dd3Smacallan    UCHAR temp , temp1 , temp2 , temp3 ,
1413dfe64dd3Smacallan          i , j , k ;
1414dfe64dd3Smacallan
1415dfe64dd3Smacallan    USHORT P3d4 = Port ,
1416dfe64dd3Smacallan           P3c4 = Port - 0x10 ;
1417dfe64dd3Smacallan
1418dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x6D , pVBInfo->CR40[ 8 ][ XGINew_RAMType ] ) ;
1419dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x68 , pVBInfo->CR40[ 5 ][ XGINew_RAMType ] ) ;
1420dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x69 , pVBInfo->CR40[ 6 ][ XGINew_RAMType ] ) ;
1421dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x6A , pVBInfo->CR40[ 7 ][ XGINew_RAMType ] ) ;
1422dfe64dd3Smacallan
1423dfe64dd3Smacallan    temp2 = 0 ;
1424dfe64dd3Smacallan    for( i = 0 ; i < 4 ; i++ )
1425dfe64dd3Smacallan    {
1426dfe64dd3Smacallan        temp = pVBInfo->CR6B[ XGINew_RAMType ][ i ] ;        		/* CR6B DQS fine tune delay */
1427dfe64dd3Smacallan        for( j = 0 ; j < 4 ; j++ )
1428dfe64dd3Smacallan        {
1429dfe64dd3Smacallan            temp1 = ( ( temp >> ( 2 * j ) ) & 0x03 ) << 2 ;
1430dfe64dd3Smacallan            temp2 |= temp1 ;
1431dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) P3d4 , 0x6B , temp2 ) ;
1432dfe64dd3Smacallan            XGI_GetReg((XGIIOADDRESS) P3d4 , 0x6B ) ;				/* Insert read command for delay */
1433dfe64dd3Smacallan            temp2 &= 0xF0 ;
1434dfe64dd3Smacallan            temp2 += 0x10 ;
1435dfe64dd3Smacallan        }
1436dfe64dd3Smacallan    }
1437dfe64dd3Smacallan
1438dfe64dd3Smacallan    temp2 = 0 ;
1439dfe64dd3Smacallan    for( i = 0 ; i < 4 ; i++ )
1440dfe64dd3Smacallan    {
1441dfe64dd3Smacallan        temp = pVBInfo->CR6E[ XGINew_RAMType ][ i ] ;        		/* CR6E DQM fine tune delay */
1442dfe64dd3Smacallan        for( j = 0 ; j < 4 ; j++ )
1443dfe64dd3Smacallan        {
1444dfe64dd3Smacallan            temp1 = ( ( temp >> ( 2 * j ) ) & 0x03 ) << 2 ;
1445dfe64dd3Smacallan            temp2 |= temp1 ;
1446dfe64dd3Smacallan            XGI_SetReg((XGIIOADDRESS) P3d4 , 0x6E , temp2 ) ;
1447dfe64dd3Smacallan            XGI_GetReg((XGIIOADDRESS) P3d4 , 0x6E ) ;				/* Insert read command for delay */
1448dfe64dd3Smacallan            temp2 &= 0xF0 ;
1449dfe64dd3Smacallan            temp2 += 0x10 ;
1450dfe64dd3Smacallan        }
1451dfe64dd3Smacallan    }
1452dfe64dd3Smacallan
1453dfe64dd3Smacallan    temp3 = 0 ;
1454dfe64dd3Smacallan    for( k = 0 ; k < 4 ; k++ )
1455dfe64dd3Smacallan    {
1456dfe64dd3Smacallan        XGI_SetRegANDOR((XGIIOADDRESS) P3d4 , 0x6E , 0xFC , temp3 ) ;		/* CR6E_D[1:0] select channel */
1457dfe64dd3Smacallan        temp2 = 0 ;
1458dfe64dd3Smacallan        for( i = 0 ; i < 8 ; i++ )
1459dfe64dd3Smacallan        {
1460dfe64dd3Smacallan            temp = pVBInfo->CR6F[ XGINew_RAMType ][ 8 * k + i ] ;   	/* CR6F DQ fine tune delay */
1461dfe64dd3Smacallan            for( j = 0 ; j < 4 ; j++ )
1462dfe64dd3Smacallan            {
1463dfe64dd3Smacallan                temp1 = ( temp >> ( 2 * j ) ) & 0x03 ;
1464dfe64dd3Smacallan                temp2 |= temp1 ;
1465dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) P3d4 , 0x6F , temp2 ) ;
1466dfe64dd3Smacallan                XGI_GetReg((XGIIOADDRESS) P3d4 , 0x6F ) ;				/* Insert read command for delay */
1467dfe64dd3Smacallan                temp2 &= 0xF8 ;
1468dfe64dd3Smacallan                temp2 += 0x08 ;
1469dfe64dd3Smacallan            }
1470dfe64dd3Smacallan        }
1471dfe64dd3Smacallan        temp3 += 0x01 ;
1472dfe64dd3Smacallan    }
1473dfe64dd3Smacallan
1474dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x80 , pVBInfo->CR40[ 9 ][ XGINew_RAMType ] ) ;	/* CR80 */
1475dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x81 , pVBInfo->CR40[ 10 ][ XGINew_RAMType ] ) ;	/* CR81 */
1476dfe64dd3Smacallan
1477dfe64dd3Smacallan    temp2 = 0x80 ;
1478dfe64dd3Smacallan    temp = pVBInfo->CR89[ XGINew_RAMType ][ 0 ] ;        		/* CR89 terminator type select */
1479dfe64dd3Smacallan    for( j = 0 ; j < 4 ; j++ )
1480dfe64dd3Smacallan    {
1481dfe64dd3Smacallan        temp1 = ( temp >> ( 2 * j ) ) & 0x03 ;
1482dfe64dd3Smacallan        temp2 |= temp1 ;
1483dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , 0x89 , temp2 ) ;
1484dfe64dd3Smacallan        XGI_GetReg((XGIIOADDRESS) P3d4 , 0x89 ) ;				/* Insert read command for delay */
1485dfe64dd3Smacallan        temp2 &= 0xF0 ;
1486dfe64dd3Smacallan        temp2 += 0x10 ;
1487dfe64dd3Smacallan    }
1488dfe64dd3Smacallan
1489dfe64dd3Smacallan    temp = pVBInfo->CR89[ XGINew_RAMType ][ 1 ] ;
1490dfe64dd3Smacallan    temp1 = temp & 0x03 ;
1491dfe64dd3Smacallan    temp2 |= temp1 ;
1492dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x89 , temp2 ) ;
1493dfe64dd3Smacallan
1494dfe64dd3Smacallan    temp = pVBInfo->CR40[ 3 ][ XGINew_RAMType ] ;
1495dfe64dd3Smacallan    temp1 = temp & 0x0F ;
1496dfe64dd3Smacallan    temp2 = ( temp >> 4 ) & 0x07 ;
1497dfe64dd3Smacallan    temp3 = temp & 0x80 ;
1498dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x45 , temp1 ) ;	/* CR45 */
1499dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x99 , temp2 ) ;	/* CR99 */
1500dfe64dd3Smacallan    XGI_SetRegOR((XGIIOADDRESS) P3d4 , 0x40 , temp3 ) ;	/* CR40_D[7] */
1501dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x41 , pVBInfo->CR40[ 0 ][ XGINew_RAMType ] ) ;	/* CR41 */
1502dfe64dd3Smacallan
1503dfe64dd3Smacallan    /* Jong 10/01/2007; */
1504dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType == XG27 )
1505dfe64dd3Smacallan      XGI_SetReg( (XGIIOADDRESS) P3d4 , 0x8F , *pVBInfo->pCR8F ) ;	/* CR8F */
1506dfe64dd3Smacallan
1507dfe64dd3Smacallan    for( j = 0 ; j <= 6 ; j++ )
1508dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , ( 0x90 + j ) , pVBInfo->CR40[ 14 + j ][ XGINew_RAMType ] ) ;	/* CR90 - CR96 */
1509dfe64dd3Smacallan
1510dfe64dd3Smacallan    for( j = 0 ; j <= 2 ; j++ )
1511dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , ( 0xC3 + j ) , pVBInfo->CR40[ 21 + j ][ XGINew_RAMType ] ) ;	/* CRC3 - CRC5 */
1512dfe64dd3Smacallan
1513dfe64dd3Smacallan    for( j = 0 ; j < 2 ; j++ )
1514dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , ( 0x8A + j ) , pVBInfo->CR40[ 1 + j ][ XGINew_RAMType ] ) ;	/* CR8A - CR8B */
1515dfe64dd3Smacallan
1516dfe64dd3Smacallan    if ( ( HwDeviceExtension->jChipType == XG41 ) || ( HwDeviceExtension->jChipType == XG42 ) )
1517dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , 0x8C , 0x87 ) ;
1518dfe64dd3Smacallan
1519dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x59 , pVBInfo->CR40[ 4 ][ XGINew_RAMType ] ) ;	/* CR59 */
1520dfe64dd3Smacallan
1521dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4, 0x83, 0x09);          /* CR83 */
1522dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4, 0x87, 0x00);          /* CR87 */
1523dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4, 0xCF, pVBInfo->CRCF); /* CRCF */
1524dfe64dd3Smacallan
1525dfe64dd3Smacallan    /* Jong 10/01/2007 */
1526dfe64dd3Smacallan    if ( XGINew_RAMType )
1527dfe64dd3Smacallan    {
1528dfe64dd3Smacallan      /*XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x17 , 0xC0 ) ;*/		/* SR17 DDRII */
1529dfe64dd3Smacallan      XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x17 , 0x80 ) ;		/* SR17 DDRII */
1530dfe64dd3Smacallan      if ( HwDeviceExtension->jChipType == XG27 )
1531dfe64dd3Smacallan        XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x17 , 0x02 ) ;		/* SR17 DDRII */
1532dfe64dd3Smacallan
1533dfe64dd3Smacallan    }
1534dfe64dd3Smacallan    else
1535dfe64dd3Smacallan      XGI_SetReg( (XGIIOADDRESS) P3c4 , 0x17 , 0x00 ) ;		/* SR17 DDR */
1536dfe64dd3Smacallan
1537dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4, 0x1A, 0x87);          /* SR1A */
1538dfe64dd3Smacallan
1539dfe64dd3Smacallan    temp = XGINew_Get340DRAMType( HwDeviceExtension, pVBInfo) ;
1540dfe64dd3Smacallan    if( temp == 0 )
1541dfe64dd3Smacallan        XGINew_DDR1x_DefaultRegister( HwDeviceExtension, P3d4, pVBInfo ) ;
1542dfe64dd3Smacallan    else if ( temp == 0x02 )
1543dfe64dd3Smacallan	XGINew_DDR2x_DefaultRegister( HwDeviceExtension, P3d4, pVBInfo ) ;
1544dfe64dd3Smacallan    else
1545dfe64dd3Smacallan   	XGINew_DDR2_DefaultRegister( HwDeviceExtension, P3d4, pVBInfo ) ;
1546dfe64dd3Smacallan
1547dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x1B , pVBInfo->SR15[ 3 ][ XGINew_RAMType ] ) ;	/* SR1B */
1548dfe64dd3Smacallan}
1549dfe64dd3Smacallan
1550dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1551dfe64dd3Smacallan/* Function : XGINew_SetDRAMDefaultRegisterXG45 */
1552dfe64dd3Smacallan/* Input : */
1553dfe64dd3Smacallan/* Output : */
1554dfe64dd3Smacallan/* Description : */
1555dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1556dfe64dd3Smacallanvoid XGINew_SetDRAMDefaultRegisterXG45( PXGI_HW_DEVICE_INFO HwDeviceExtension ,  USHORT Port , PVB_DEVICE_INFO pVBInfo)
1557dfe64dd3Smacallan{
1558dfe64dd3Smacallan    UCHAR temp , temp1 , temp2 ,
1559dfe64dd3Smacallan          i , j , k ;
1560dfe64dd3Smacallan
1561dfe64dd3Smacallan    USHORT P3d4 = Port ,
1562dfe64dd3Smacallan           P3c4 = Port - 0x10 ;
1563dfe64dd3Smacallan
1564dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x6D , pVBInfo->CR40[ 8 ][ XGINew_RAMType ] ) ;
1565dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x6E , pVBInfo->XG45CR6E[ XGINew_RAMType ] ) ;
1566dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x6F , pVBInfo->XG45CR6F[ XGINew_RAMType ] ) ;
1567dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x68 , pVBInfo->CR40[ 5 ][ XGINew_RAMType ] ) ;
1568dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x69 , pVBInfo->CR40[ 6 ][ XGINew_RAMType ] ) ;
1569dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x6A , pVBInfo->CR40[ 7 ][ XGINew_RAMType ] ) ;
1570dfe64dd3Smacallan
1571dfe64dd3Smacallan    temp = 0x00 ;
1572dfe64dd3Smacallan    for ( j = 0 ; j < 24 ; j ++ )
1573dfe64dd3Smacallan    {
1574dfe64dd3Smacallan    	XGI_SetReg((XGIIOADDRESS) P3d4 , 0x6B , temp );
1575dfe64dd3Smacallan        temp += 0x08 ;
1576dfe64dd3Smacallan    }
1577dfe64dd3Smacallan
1578dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x80 , pVBInfo->CR40[ 9 ][ XGINew_RAMType ] ) ;	/* CR80 */
1579dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x81 , pVBInfo->CR40[ 10 ][ XGINew_RAMType ] ) ;	/* CR81 */
1580dfe64dd3Smacallan
1581dfe64dd3Smacallan    temp2 = 0x80 ;
1582dfe64dd3Smacallan    temp = pVBInfo->CR89[ XGINew_RAMType ][ 0 ] ;        		/* CR89 terminator type select */
1583dfe64dd3Smacallan    for( j = 0 ; j < 4 ; j++ )
1584dfe64dd3Smacallan    {
1585dfe64dd3Smacallan        temp1 = ( temp >> ( 2 * j ) ) & 0x03 ;
1586dfe64dd3Smacallan        temp2 |= temp1 ;
1587dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , 0x89 , temp2 ) ;
1588dfe64dd3Smacallan        XGI_GetReg((XGIIOADDRESS) P3d4 , 0x89 ) ;				/* Insert read command for delay */
1589dfe64dd3Smacallan        temp2 &= 0xF0 ;
1590dfe64dd3Smacallan        temp2 += 0x10 ;
1591dfe64dd3Smacallan    }
1592dfe64dd3Smacallan
1593dfe64dd3Smacallan    temp = pVBInfo->CR89[ XGINew_RAMType ][ 1 ] ;
1594dfe64dd3Smacallan    temp1 = temp & 0x03 ;
1595dfe64dd3Smacallan    temp2 |= temp1 ;
1596dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x89 , temp2 ) ;
1597dfe64dd3Smacallan
1598dfe64dd3Smacallan    temp = 0x00 ;
1599dfe64dd3Smacallan    for ( j = 0 ; j < 3 ; j ++ )
1600dfe64dd3Smacallan    {
1601dfe64dd3Smacallan    	XGI_SetReg((XGIIOADDRESS) P3d4 , 0x40 , temp  );
1602dfe64dd3Smacallan    	temp += 0x40 ;
1603dfe64dd3Smacallan    }
1604dfe64dd3Smacallan
1605dfe64dd3Smacallan    temp = 0x00 ;
1606dfe64dd3Smacallan    for ( j = 0 ; j < 24 ; j ++ )
1607dfe64dd3Smacallan    {
1608dfe64dd3Smacallan    	XGI_SetReg((XGIIOADDRESS) P3d4 , 0x41 , temp );
1609dfe64dd3Smacallan        temp += 0x08 ;
1610dfe64dd3Smacallan    }
1611dfe64dd3Smacallan
1612dfe64dd3Smacallan    temp = 0x00 ;
1613dfe64dd3Smacallan    for ( j = 0 ; j < 24 ; j ++ )
1614dfe64dd3Smacallan    {
1615dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , 0x42 , temp );
1616dfe64dd3Smacallan        temp += 0x08 ;
1617dfe64dd3Smacallan    }
1618dfe64dd3Smacallan
1619dfe64dd3Smacallan    for ( k = 0 ; k < 2 ; k ++ )
1620dfe64dd3Smacallan    {
1621dfe64dd3Smacallan        XGI_SetRegANDOR((XGIIOADDRESS) P3d4 , 0x43 , ~0x04 , k * 0x04 );
1622dfe64dd3Smacallan
1623dfe64dd3Smacallan        for ( i = 0 ; i < 3 ; i ++ )
1624dfe64dd3Smacallan        {
1625dfe64dd3Smacallan
1626dfe64dd3Smacallan    	    XGI_SetRegANDOR((XGIIOADDRESS) P3d4 , 0x43 , ~0x03 , i * 0x01 );
1627dfe64dd3Smacallan
1628dfe64dd3Smacallan            for ( j = 0 ; j < 32 ; j ++ )
1629dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) P3d4 , 0x44 , j * 0x08 );
1630dfe64dd3Smacallan        }
1631dfe64dd3Smacallan    }
1632dfe64dd3Smacallan
1633dfe64dd3Smacallan    for ( j = 0 ; j < 3 ; j ++ )
1634dfe64dd3Smacallan    	XGI_SetReg((XGIIOADDRESS) P3d4 , 0x45 , j * 0x08 ) ;	/* CR45 */
1635dfe64dd3Smacallan
1636dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x97 , 0x84 ) ;
1637dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x98 , 0x01 ) ;
1638dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x99 , 0x22 ) ;
1639dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x9A , 0x02 ) ;
1640dfe64dd3Smacallan
1641dfe64dd3Smacallan    for( j = 0 ; j <= 6 ; j++ )
1642dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , ( 0x90 + j ) , pVBInfo->CR40[ 14 + j ][ XGINew_RAMType ] ) ;	/* CR90 - CR96 */
1643dfe64dd3Smacallan
1644dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x59 , pVBInfo->CR40[ 4 ][ XGINew_RAMType ] ) ;	/* CR59 */
1645dfe64dd3Smacallan
1646dfe64dd3Smacallan    for( j = 0 ; j <= 2 ; j++ )
1647dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , ( 0xC3 + j ) , pVBInfo->CR40[ 21 + j ][ XGINew_RAMType ] ) ;	/* CRC3 - CRC5 */
1648dfe64dd3Smacallan
1649dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0xC8 , 0x04 ) ;
1650dfe64dd3Smacallan
1651dfe64dd3Smacallan    for( j = 0 ; j < 2 ; j++ )
1652dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , ( 0x8A + j ) , pVBInfo->CR40[ 1 + j ][ XGINew_RAMType ] ) ;	/* CR8A - CR8B */
1653dfe64dd3Smacallan
1654dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4 , 0x8C , 0x40 ) ;
1655dfe64dd3Smacallan
1656dfe64dd3Smacallan    if ( ( HwDeviceExtension->jChipType == XG41 ) || ( HwDeviceExtension->jChipType == XG42 ) )
1657dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) P3d4 , 0x8C , 0x87 ) ;
1658dfe64dd3Smacallan
1659dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4, 0xCF, pVBInfo->CRCF); /* CRCF */
1660dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4, 0x83, 0x09);          /* CR83 */
1661dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4, 0x87, 0x00);          /* CR87 */
1662dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3d4, 0x8D, 0x87);          /* CR8D */
1663dfe64dd3Smacallan
1664dfe64dd3Smacallan    XGINew_DDR1x_DefaultRegister( HwDeviceExtension, P3d4, pVBInfo ) ;
1665dfe64dd3Smacallan
1666dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x1A , 0x87 ) ;	/* SR1A */
1667dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x1B , pVBInfo->SR15[ 3 ][ XGINew_RAMType ] ) ;	/* SR1B */
1668dfe64dd3Smacallan}
1669dfe64dd3Smacallan
1670dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1671dfe64dd3Smacallan/* Function : XGINew_DDR_MRS */
1672dfe64dd3Smacallan/* Input : */
1673dfe64dd3Smacallan/* Output : */
1674dfe64dd3Smacallan/* Description : */
1675dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1676dfe64dd3Smacallanvoid XGINew_DDR_MRS(PVB_DEVICE_INFO pVBInfo)
1677dfe64dd3Smacallan{
1678dfe64dd3Smacallan    USHORT data ;
1679dfe64dd3Smacallan
1680dfe64dd3Smacallan    PUCHAR volatile pVideoMemory = ( PUCHAR )pVBInfo->ROMAddr ;
1681dfe64dd3Smacallan
1682dfe64dd3Smacallan    /* SR16 <- 1F,DF,2F,AF */
1683dfe64dd3Smacallan    /* yriver modified SR16 <- 0F,DF,0F,AF */
1684dfe64dd3Smacallan    /* enable DLL of DDR SD/SGRAM , SR16 D4=1 */
1685dfe64dd3Smacallan    data = pVideoMemory[ 0xFB ] ;
1686dfe64dd3Smacallan    /* data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x16 ) ; */
1687dfe64dd3Smacallan
1688dfe64dd3Smacallan    data &= 0x0F ;
1689dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x16 , data ) ;
1690dfe64dd3Smacallan    data |= 0xC0 ;
1691dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x16 , data ) ;
1692dfe64dd3Smacallan    data &= 0x0F ;
1693dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x16 , data ) ;
1694dfe64dd3Smacallan    data |= 0x80 ;
1695dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x16 , data ) ;
1696dfe64dd3Smacallan    data &= 0x0F ;
1697dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x16 , data ) ;
1698dfe64dd3Smacallan    data |= 0xD0 ;
1699dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x16 , data ) ;
1700dfe64dd3Smacallan    data &= 0x0F ;
1701dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x16 , data ) ;
1702dfe64dd3Smacallan    data |= 0xA0 ;
1703dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x16 , data ) ;
1704dfe64dd3Smacallan/*
1705dfe64dd3Smacallan   else {
1706dfe64dd3Smacallan     data &= 0x0F;
1707dfe64dd3Smacallan     data |= 0x10;
1708dfe64dd3Smacallan     XGI_SetReg((XGIIOADDRESS)pVBInfo->P3c4,0x16,data);
1709dfe64dd3Smacallan
1710dfe64dd3Smacallan     if (!(pVBInfo->SR15[1][XGINew_RAMType] & 0x10))
1711dfe64dd3Smacallan     {
1712dfe64dd3Smacallan       data &= 0x0F;
1713dfe64dd3Smacallan     }
1714dfe64dd3Smacallan
1715dfe64dd3Smacallan     data |= 0xC0;
1716dfe64dd3Smacallan     XGI_SetReg((XGIIOADDRESS)pVBInfo->P3c4,0x16,data);
1717dfe64dd3Smacallan
1718dfe64dd3Smacallan
1719dfe64dd3Smacallan     data &= 0x0F;
1720dfe64dd3Smacallan     data |= 0x20;
1721dfe64dd3Smacallan     XGI_SetReg((XGIIOADDRESS)pVBInfo->P3c4,0x16,data);
1722dfe64dd3Smacallan     if (!(pVBInfo->SR15[1][XGINew_RAMType] & 0x10))
1723dfe64dd3Smacallan     {
1724dfe64dd3Smacallan       data &= 0x0F;
1725dfe64dd3Smacallan     }
1726dfe64dd3Smacallan
1727dfe64dd3Smacallan     data |= 0x80;
1728dfe64dd3Smacallan     XGI_SetReg((XGIIOADDRESS)pVBInfo->P3c4,0x16,data);
1729dfe64dd3Smacallan   }
1730dfe64dd3Smacallan*/
1731dfe64dd3Smacallan}
1732dfe64dd3Smacallan
1733dfe64dd3Smacallan
1734dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1735dfe64dd3Smacallan/* Function : XGINew_SetDRAMSize_340 */
1736dfe64dd3Smacallan/* Input : */
1737dfe64dd3Smacallan/* Output : */
1738dfe64dd3Smacallan/* Description : */
1739dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1740dfe64dd3Smacallanvoid XGINew_SetDRAMSize_340( PXGI_HW_DEVICE_INFO HwDeviceExtension , PVB_DEVICE_INFO pVBInfo)
1741dfe64dd3Smacallan{
1742dfe64dd3Smacallan    USHORT  data ;
1743dfe64dd3Smacallan
1744dfe64dd3Smacallan    pVBInfo->ROMAddr = HwDeviceExtension->pjVirtualRomBase ;
1745dfe64dd3Smacallan    pVBInfo->FBAddr = HwDeviceExtension->pjVideoMemoryAddress ;
1746dfe64dd3Smacallan    XGISetModeNew(HwDeviceExtension, pVBInfo, 0x2e);
1747dfe64dd3Smacallan
1748dfe64dd3Smacallan    data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x21 ) ;
1749dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x21 , ( USHORT )( data & 0xDF ) ) ;	/* disable read cache */
1750dfe64dd3Smacallan
1751dfe64dd3Smacallan    /* Jong 10/03/2007; add support for DVO, XG27, ...*/
1752dfe64dd3Smacallan    XGI_DisplayOff(HwDeviceExtension, pVBInfo );
1753dfe64dd3Smacallan    /* data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x1 ) ;
1754dfe64dd3Smacallan    data |= 0x20 ;
1755dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x01 , data ) ;	*/		/* Turn OFF Display */
1756dfe64dd3Smacallan
1757dfe64dd3Smacallan    XGINew_DDRSizing340( HwDeviceExtension, pVBInfo ) ;
1758dfe64dd3Smacallan
1759dfe64dd3Smacallan    data=XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x21 ) ;
1760dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x21 , ( USHORT )( data | 0x20 ) ) ;	/* enable read cache */
1761dfe64dd3Smacallan}
1762dfe64dd3Smacallan
1763dfe64dd3Smacallan
1764dfe64dd3Smacallan/*--------------------------------------------------------------------- */
1765dfe64dd3Smacallan/* Function    : XGINew_SetDRAMSize_XG45 */
1766dfe64dd3Smacallan/*Input       : */
1767dfe64dd3Smacallan/*Output      : */
1768dfe64dd3Smacallan/*Description : */
1769dfe64dd3Smacallan/*--------------------------------------------------------------------- */
1770dfe64dd3Smacallanvoid XGINew_SetDRAMSize_XG45( PXGI_HW_DEVICE_INFO HwDeviceExtension , PVB_DEVICE_INFO pVBInfo)
1771dfe64dd3Smacallan{
1772dfe64dd3Smacallan    USHORT  data ;
1773dfe64dd3Smacallan
1774dfe64dd3Smacallan    pVBInfo->ROMAddr = HwDeviceExtension->pjVirtualRomBase ;
1775dfe64dd3Smacallan    pVBInfo->FBAddr = HwDeviceExtension->pjVideoMemoryAddress ;
1776dfe64dd3Smacallan    XGISetModeNew(HwDeviceExtension, pVBInfo, 0x2e);
1777dfe64dd3Smacallan
1778dfe64dd3Smacallan    data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x21 ) ;
1779dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x21 , ( USHORT )( data & 0xDF ) ) ;	/*disable read cache*/
1780dfe64dd3Smacallan
1781dfe64dd3Smacallan    data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x1 ) ;
1782dfe64dd3Smacallan    data |= 0x20 ;
1783dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x01 , data ) ;			/*Turn OFF Display*/
1784dfe64dd3Smacallan
1785dfe64dd3Smacallan    XGINew_DDRSizingXG45( HwDeviceExtension, pVBInfo ) ;
1786dfe64dd3Smacallan
1787dfe64dd3Smacallan    data=XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x21 ) ;
1788dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x21 , ( USHORT )( data | 0x20 ) ) ;	/*enable read cache*/
1789dfe64dd3Smacallan}
1790dfe64dd3Smacallan
1791dfe64dd3Smacallan
1792dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1793dfe64dd3Smacallan/* Function : XGINew_SetDRAMModeRegister340 */
1794dfe64dd3Smacallan/* Input : */
1795dfe64dd3Smacallan/* Output : */
1796dfe64dd3Smacallan/* Description : */
1797dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1798dfe64dd3Smacallan
1799dfe64dd3Smacallanvoid XGINew_SetDRAMModeRegister340(PXGI_HW_DEVICE_INFO HwDeviceExtension,
1800dfe64dd3Smacallan				   PVB_DEVICE_INFO pVBInfo)
1801dfe64dd3Smacallan{
1802dfe64dd3Smacallan    UCHAR data ;
1803dfe64dd3Smacallan
1804dfe64dd3Smacallan    ReadVBIOSTablData( HwDeviceExtension->jChipType , pVBInfo) ;
1805dfe64dd3Smacallan
1806dfe64dd3Smacallan    if (HwDeviceExtension->jChipType == XG45)
1807dfe64dd3Smacallan        XGINew_DDR1x_MRS_340( HwDeviceExtension, pVBInfo->P3c4, pVBInfo ) ;
1808dfe64dd3Smacallan    else
1809dfe64dd3Smacallan    {
1810dfe64dd3Smacallan    if ( XGINew_Get340DRAMType( HwDeviceExtension, pVBInfo) == 0 )
1811dfe64dd3Smacallan    {
1812dfe64dd3Smacallan        data = ( XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x39 ) & 0x02 ) >> 1 ;
1813dfe64dd3Smacallan        if ( data == 0x01 )
1814dfe64dd3Smacallan            XGINew_DDR2x_MRS_340( HwDeviceExtension, pVBInfo->P3c4, pVBInfo ) ;
1815dfe64dd3Smacallan        else
1816dfe64dd3Smacallan            XGINew_DDR1x_MRS_340( HwDeviceExtension, pVBInfo->P3c4, pVBInfo ) ;
1817dfe64dd3Smacallan    }
1818dfe64dd3Smacallan    else
1819dfe64dd3Smacallan        XGINew_DDR2_MRS_340( HwDeviceExtension, pVBInfo->P3c4, pVBInfo);
1820dfe64dd3Smacallan    }
1821dfe64dd3Smacallan
1822dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x1B , 0x03 ) ;
1823dfe64dd3Smacallan}
1824dfe64dd3Smacallan
1825dfe64dd3Smacallan
1826dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1827dfe64dd3Smacallan/* Function : XGINew_DisableRefresh */
1828dfe64dd3Smacallan/* Input : */
1829dfe64dd3Smacallan/* Output : */
1830dfe64dd3Smacallan/* Description : */
1831dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1832dfe64dd3Smacallanvoid XGINew_DisableRefresh( PXGI_HW_DEVICE_INFO HwDeviceExtension , PVB_DEVICE_INFO pVBInfo)
1833dfe64dd3Smacallan{
1834dfe64dd3Smacallan    USHORT  data ;
1835dfe64dd3Smacallan
1836dfe64dd3Smacallan
1837dfe64dd3Smacallan    data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x1B ) ;
1838dfe64dd3Smacallan    data &= 0xF8 ;
1839dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x1B , data ) ;
1840dfe64dd3Smacallan
1841dfe64dd3Smacallan}
1842dfe64dd3Smacallan
1843dfe64dd3Smacallan
1844dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1845dfe64dd3Smacallan/* Function : XGINew_EnableRefresh */
1846dfe64dd3Smacallan/* Input : */
1847dfe64dd3Smacallan/* Output : */
1848dfe64dd3Smacallan/* Description : */
1849dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1850dfe64dd3Smacallanvoid XGINew_EnableRefresh( PXGI_HW_DEVICE_INFO HwDeviceExtension , PVB_DEVICE_INFO pVBInfo)
1851dfe64dd3Smacallan{
1852dfe64dd3Smacallan
1853dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x1B , pVBInfo->SR15[ 3 ][ XGINew_RAMType ] ) ;	/* SR1B */
1854dfe64dd3Smacallan
1855dfe64dd3Smacallan
1856dfe64dd3Smacallan}
1857dfe64dd3Smacallan
1858dfe64dd3Smacallan
1859dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1860dfe64dd3Smacallan/* Function : XGINew_DisableChannelInterleaving */
1861dfe64dd3Smacallan/* Input : */
1862dfe64dd3Smacallan/* Output : */
1863dfe64dd3Smacallan/* Description : */
1864dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1865dfe64dd3Smacallanvoid XGINew_DisableChannelInterleaving(int index,
1866dfe64dd3Smacallan				       const USHORT XGINew_DDRDRAM_TYPE[][5],
1867dfe64dd3Smacallan				       PVB_DEVICE_INFO pVBInfo)
1868dfe64dd3Smacallan{
1869dfe64dd3Smacallan    USHORT data ;
1870dfe64dd3Smacallan
1871dfe64dd3Smacallan    data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x15 ) ;
1872dfe64dd3Smacallan    data &= 0x1F ;
1873dfe64dd3Smacallan
1874dfe64dd3Smacallan    switch( XGINew_DDRDRAM_TYPE[ index ][ 3 ] )
1875dfe64dd3Smacallan    {
1876dfe64dd3Smacallan        case 64:
1877dfe64dd3Smacallan            data |= 0 ;
1878dfe64dd3Smacallan            break ;
1879dfe64dd3Smacallan        case 32:
1880dfe64dd3Smacallan            data |= 0x20 ;
1881dfe64dd3Smacallan            break ;
1882dfe64dd3Smacallan        case 16:
1883dfe64dd3Smacallan            data |= 0x40 ;
1884dfe64dd3Smacallan            break ;
1885dfe64dd3Smacallan        case 4:
1886dfe64dd3Smacallan            data |= 0x60 ;
1887dfe64dd3Smacallan            break ;
1888dfe64dd3Smacallan        default:
1889dfe64dd3Smacallan            break ;
1890dfe64dd3Smacallan    }
1891dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x15 , data ) ;
1892dfe64dd3Smacallan}
1893dfe64dd3Smacallan
1894dfe64dd3Smacallan
1895dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1896dfe64dd3Smacallan/* Function : XGINew_SetDRAMSizingType */
1897dfe64dd3Smacallan/* Input : */
1898dfe64dd3Smacallan/* Output : */
1899dfe64dd3Smacallan/* Description : */
1900dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1901dfe64dd3Smacallanvoid XGINew_SetDRAMSizingType(int index , const USHORT DRAMTYPE_TABLE[][5],
1902dfe64dd3Smacallan			      PVB_DEVICE_INFO pVBInfo)
1903dfe64dd3Smacallan{
1904dfe64dd3Smacallan    USHORT data ;
1905dfe64dd3Smacallan
1906dfe64dd3Smacallan    data = DRAMTYPE_TABLE[ index ][ 4 ] ;
1907dfe64dd3Smacallan    XGI_SetRegANDOR((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0x80 , data ) ;
1908dfe64dd3Smacallan   /* should delay 50 ns */
1909dfe64dd3Smacallan}
1910dfe64dd3Smacallan
1911dfe64dd3Smacallan
1912dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1913dfe64dd3Smacallan/* Function : XGINew_SetRank */
1914dfe64dd3Smacallan/* Input : */
1915dfe64dd3Smacallan/* Output : */
1916dfe64dd3Smacallan/* Description : */
1917dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1918dfe64dd3Smacallanint XGINew_SetRank(int index, UCHAR RankNo, UCHAR XGINew_ChannelAB,
1919dfe64dd3Smacallan		   const USHORT DRAMTYPE_TABLE[][5], PVB_DEVICE_INFO pVBInfo)
1920dfe64dd3Smacallan{
1921dfe64dd3Smacallan    USHORT data ;
1922dfe64dd3Smacallan    int RankSize ;
1923dfe64dd3Smacallan
1924dfe64dd3Smacallan    if ( ( RankNo == 2 ) && ( DRAMTYPE_TABLE[ index ][ 0 ] == 2 ) )
1925dfe64dd3Smacallan        return 0 ;
1926dfe64dd3Smacallan
1927dfe64dd3Smacallan    RankSize = DRAMTYPE_TABLE[ index ][ 3 ] / 2 * XGINew_DataBusWidth / 32 ;
1928dfe64dd3Smacallan
1929dfe64dd3Smacallan    if ( ( RankNo * RankSize ) <= 128 )
1930dfe64dd3Smacallan    {
1931dfe64dd3Smacallan        data = 0 ;
1932dfe64dd3Smacallan
1933dfe64dd3Smacallan        while( ( RankSize >>= 1 ) > 0 )
1934dfe64dd3Smacallan        {
1935dfe64dd3Smacallan            data += 0x10 ;
1936dfe64dd3Smacallan        }
1937dfe64dd3Smacallan        data |= ( RankNo - 1 ) << 2 ;
1938dfe64dd3Smacallan        data |= ( XGINew_DataBusWidth / 64 ) & 2 ;
1939dfe64dd3Smacallan        data |= XGINew_ChannelAB ;
1940dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , data ) ;
1941dfe64dd3Smacallan        /* should delay */
1942dfe64dd3Smacallan        XGINew_SDR_MRS( pVBInfo ) ;
1943dfe64dd3Smacallan        return( 1 ) ;
1944dfe64dd3Smacallan    }
1945dfe64dd3Smacallan    else
1946dfe64dd3Smacallan        return( 0 ) ;
1947dfe64dd3Smacallan}
1948dfe64dd3Smacallan
1949dfe64dd3Smacallan
1950dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1951dfe64dd3Smacallan/* Function : XGINew_SetDDRChannel */
1952dfe64dd3Smacallan/* Input : */
1953dfe64dd3Smacallan/* Output : */
1954dfe64dd3Smacallan/* Description : */
1955dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1956dfe64dd3Smacallanint XGINew_SetDDRChannel(int index, UCHAR ChannelNo, UCHAR XGINew_ChannelAB,
1957dfe64dd3Smacallan			 const USHORT DRAMTYPE_TABLE[][5],
1958dfe64dd3Smacallan			 PVB_DEVICE_INFO pVBInfo)
1959dfe64dd3Smacallan{
1960dfe64dd3Smacallan    USHORT  data ;
1961dfe64dd3Smacallan    int RankSize ;
1962dfe64dd3Smacallan
1963dfe64dd3Smacallan    RankSize = DRAMTYPE_TABLE[index][3]/2 * XGINew_DataBusWidth/32;
1964dfe64dd3Smacallan    /* RankSize = DRAMTYPE_TABLE[ index ][ 3 ] ; */
1965dfe64dd3Smacallan    if ( ChannelNo * RankSize <= 128 )
1966dfe64dd3Smacallan    {
1967dfe64dd3Smacallan        data = 0 ;
1968dfe64dd3Smacallan        while( ( RankSize >>= 1 ) > 0 )
1969dfe64dd3Smacallan        {
1970dfe64dd3Smacallan            data += 0x10 ;
1971dfe64dd3Smacallan        }
1972dfe64dd3Smacallan
1973dfe64dd3Smacallan        if ( ChannelNo == 2 )
1974dfe64dd3Smacallan            data |= 0x0C ;
1975dfe64dd3Smacallan
1976dfe64dd3Smacallan        data |= ( XGINew_DataBusWidth / 32 ) & 2 ;
1977dfe64dd3Smacallan        data |= XGINew_ChannelAB ;
1978dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , data ) ;
1979dfe64dd3Smacallan        /* should delay */
1980dfe64dd3Smacallan        XGINew_DDR_MRS( pVBInfo ) ;
1981dfe64dd3Smacallan        return( 1 ) ;
1982dfe64dd3Smacallan    }
1983dfe64dd3Smacallan    else
1984dfe64dd3Smacallan        return( 0 ) ;
1985dfe64dd3Smacallan}
1986dfe64dd3Smacallan
1987dfe64dd3Smacallan
1988dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1989dfe64dd3Smacallan/* Function : XGINew_CheckColumn */
1990dfe64dd3Smacallan/* Input : */
1991dfe64dd3Smacallan/* Output : */
1992dfe64dd3Smacallan/* Description : */
1993dfe64dd3Smacallan/* --------------------------------------------------------------------- */
1994dfe64dd3Smacallanint XGINew_CheckColumn(int index, const USHORT DRAMTYPE_TABLE[][5],
1995dfe64dd3Smacallan		       PVB_DEVICE_INFO pVBInfo)
1996dfe64dd3Smacallan{
1997dfe64dd3Smacallan    int i ;
1998dfe64dd3Smacallan    ULONG Increment , Position ;
1999dfe64dd3Smacallan
2000dfe64dd3Smacallan    /* Increment = 1 << ( DRAMTYPE_TABLE[ index ][ 2 ] + XGINew_DataBusWidth / 64 + 1 ) ; */
2001dfe64dd3Smacallan    Increment = 1 << ( 10 + XGINew_DataBusWidth / 64 ) ;
2002dfe64dd3Smacallan
2003dfe64dd3Smacallan    for( i = 0 , Position = 0 ; i < 2 ; i++ )
2004dfe64dd3Smacallan    {
2005dfe64dd3Smacallan        *( ( PULONG )( pVBInfo->FBAddr + Position ) ) = Position ;
2006dfe64dd3Smacallan        Position += Increment ;
2007dfe64dd3Smacallan    }
2008dfe64dd3Smacallan
2009dfe64dd3Smacallan    for( i = 0 , Position = 0 ; i < 2 ; i++ )
2010dfe64dd3Smacallan    {
2011dfe64dd3Smacallan        /* if ( pVBInfo->FBAddr[ Position ] != Position ) */
2012dfe64dd3Smacallan        if ( ( *( PULONG )( pVBInfo->FBAddr + Position ) ) != Position )
2013dfe64dd3Smacallan            return( 0 ) ;
2014dfe64dd3Smacallan        Position += Increment ;
2015dfe64dd3Smacallan    }
2016dfe64dd3Smacallan    return( 1 ) ;
2017dfe64dd3Smacallan}
2018dfe64dd3Smacallan
2019dfe64dd3Smacallan
2020dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2021dfe64dd3Smacallan/* Function : XGINew_CheckBanks */
2022dfe64dd3Smacallan/* Input : */
2023dfe64dd3Smacallan/* Output : */
2024dfe64dd3Smacallan/* Description : */
2025dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2026dfe64dd3Smacallanint XGINew_CheckBanks(int index, const USHORT DRAMTYPE_TABLE[][5],
2027dfe64dd3Smacallan		      PVB_DEVICE_INFO pVBInfo)
2028dfe64dd3Smacallan{
2029dfe64dd3Smacallan    int i ;
2030dfe64dd3Smacallan    ULONG Increment , Position ;
2031dfe64dd3Smacallan
2032dfe64dd3Smacallan    Increment = 1 << ( DRAMTYPE_TABLE[ index ][ 2 ] + XGINew_DataBusWidth / 64 + 2 ) ;
2033dfe64dd3Smacallan
2034dfe64dd3Smacallan    for( i = 0 , Position = 0 ; i < 4 ; i++ )
2035dfe64dd3Smacallan    {
2036dfe64dd3Smacallan        /* pVBInfo->FBAddr[ Position ] = Position ; */
2037dfe64dd3Smacallan        *( ( PULONG )( pVBInfo->FBAddr + Position ) ) = Position ;
2038dfe64dd3Smacallan        Position += Increment ;
2039dfe64dd3Smacallan    }
2040dfe64dd3Smacallan
2041dfe64dd3Smacallan    for( i = 0 , Position = 0 ; i < 4 ; i++ )
2042dfe64dd3Smacallan    {
2043dfe64dd3Smacallan        /* if (pVBInfo->FBAddr[ Position ] != Position ) */
2044dfe64dd3Smacallan        if ( ( *( PULONG )( pVBInfo->FBAddr + Position ) ) != Position )
2045dfe64dd3Smacallan            return( 0 ) ;
2046dfe64dd3Smacallan        Position += Increment ;
2047dfe64dd3Smacallan    }
2048dfe64dd3Smacallan    return( 1 ) ;
2049dfe64dd3Smacallan}
2050dfe64dd3Smacallan
2051dfe64dd3Smacallan
2052dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2053dfe64dd3Smacallan/* Function : XGINew_CheckRank */
2054dfe64dd3Smacallan/* Input : */
2055dfe64dd3Smacallan/* Output : */
2056dfe64dd3Smacallan/* Description : */
2057dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2058dfe64dd3Smacallanint XGINew_CheckRank(int RankNo, int index, const USHORT DRAMTYPE_TABLE[][5],
2059dfe64dd3Smacallan		     PVB_DEVICE_INFO pVBInfo)
2060dfe64dd3Smacallan{
2061dfe64dd3Smacallan    int i ;
2062dfe64dd3Smacallan    ULONG Increment , Position ;
2063dfe64dd3Smacallan
2064dfe64dd3Smacallan    Increment = 1 << ( DRAMTYPE_TABLE[ index ][ 2 ] + DRAMTYPE_TABLE[ index ][ 1 ] +
2065dfe64dd3Smacallan                  DRAMTYPE_TABLE[ index ][ 0 ] + XGINew_DataBusWidth / 64 + RankNo ) ;
2066dfe64dd3Smacallan
2067dfe64dd3Smacallan    for( i = 0 , Position = 0 ; i < 2 ; i++ )
2068dfe64dd3Smacallan    {
2069dfe64dd3Smacallan        /* pVBInfo->FBAddr[ Position ] = Position ; */
2070dfe64dd3Smacallan        /* *( ( PULONG )( pVBInfo->FBAddr ) ) = Position ; */
2071dfe64dd3Smacallan        *( ( PULONG )( pVBInfo->FBAddr + Position ) ) = Position ;
2072dfe64dd3Smacallan        Position += Increment ;
2073dfe64dd3Smacallan    }
2074dfe64dd3Smacallan
2075dfe64dd3Smacallan    for( i = 0 , Position = 0 ; i < 2 ; i++ )
2076dfe64dd3Smacallan    {
2077dfe64dd3Smacallan        /* if ( pVBInfo->FBAddr[ Position ] != Position ) */
2078dfe64dd3Smacallan        /* if ( ( *( PULONG )( pVBInfo->FBAddr ) ) != Position ) */
2079dfe64dd3Smacallan        if ( ( *( PULONG )( pVBInfo->FBAddr + Position ) ) != Position )
2080dfe64dd3Smacallan            return( 0 ) ;
2081dfe64dd3Smacallan        Position += Increment ;
2082dfe64dd3Smacallan    }
2083dfe64dd3Smacallan    return( 1 );
2084dfe64dd3Smacallan}
2085dfe64dd3Smacallan
2086dfe64dd3Smacallan
2087dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2088dfe64dd3Smacallan/* Function : XGINew_CheckDDRRank */
2089dfe64dd3Smacallan/* Input : */
2090dfe64dd3Smacallan/* Output : */
2091dfe64dd3Smacallan/* Description : */
2092dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2093dfe64dd3Smacallanint XGINew_CheckDDRRank(int RankNo, int index,
2094dfe64dd3Smacallan			const USHORT DRAMTYPE_TABLE[][5],
2095dfe64dd3Smacallan			PVB_DEVICE_INFO pVBInfo)
2096dfe64dd3Smacallan{
2097dfe64dd3Smacallan    ULONG Increment , Position ;
2098dfe64dd3Smacallan    USHORT data ;
2099dfe64dd3Smacallan
2100dfe64dd3Smacallan    Increment = 1 << ( DRAMTYPE_TABLE[ index ][ 2 ] + DRAMTYPE_TABLE[ index ][ 1 ] +
2101dfe64dd3Smacallan                       DRAMTYPE_TABLE[ index ][ 0 ] + XGINew_DataBusWidth / 64 + RankNo ) ;
2102dfe64dd3Smacallan
2103dfe64dd3Smacallan    Increment += Increment / 2 ;
2104dfe64dd3Smacallan
2105dfe64dd3Smacallan    Position = 0;
2106dfe64dd3Smacallan    *( ( PULONG )( pVBInfo->FBAddr + Position + 0 ) ) = 0x01234567 ;
2107dfe64dd3Smacallan    *( ( PULONG )( pVBInfo->FBAddr + Position + 1 ) ) = 0x456789AB ;
2108dfe64dd3Smacallan    *( ( PULONG )( pVBInfo->FBAddr + Position + 2 ) ) = 0x55555555 ;
2109dfe64dd3Smacallan    *( ( PULONG )( pVBInfo->FBAddr + Position + 3 ) ) = 0x55555555 ;
2110dfe64dd3Smacallan    *( ( PULONG )( pVBInfo->FBAddr + Position + 4 ) ) = 0xAAAAAAAA ;
2111dfe64dd3Smacallan    *( ( PULONG )( pVBInfo->FBAddr + Position + 5 ) ) = 0xAAAAAAAA ;
2112dfe64dd3Smacallan
2113dfe64dd3Smacallan    if ( ( *( PULONG )( pVBInfo->FBAddr + 1 ) ) == 0x456789AB )
2114dfe64dd3Smacallan        return( 1 ) ;
2115dfe64dd3Smacallan
2116dfe64dd3Smacallan    if ( ( *( PULONG )( pVBInfo->FBAddr + 0 ) ) == 0x01234567 )
2117dfe64dd3Smacallan        return( 0 ) ;
2118dfe64dd3Smacallan
2119dfe64dd3Smacallan    data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 ) ;
2120dfe64dd3Smacallan    data &= 0xF3 ;
2121dfe64dd3Smacallan    data |= 0x0E ;
2122dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , data ) ;
2123dfe64dd3Smacallan    data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x15 ) ;
2124dfe64dd3Smacallan    data += 0x20 ;
2125dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x15 , data ) ;
2126dfe64dd3Smacallan
2127dfe64dd3Smacallan    return( 1 ) ;
2128dfe64dd3Smacallan}
2129dfe64dd3Smacallan
2130dfe64dd3Smacallan
2131dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2132dfe64dd3Smacallan/* Function : XGINew_CheckRanks */
2133dfe64dd3Smacallan/* Input : */
2134dfe64dd3Smacallan/* Output : */
2135dfe64dd3Smacallan/* Description : */
2136dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2137dfe64dd3Smacallanint XGINew_CheckRanks(int RankNo, int index, const USHORT DRAMTYPE_TABLE[][5],
2138dfe64dd3Smacallan		      PVB_DEVICE_INFO pVBInfo)
2139dfe64dd3Smacallan{
2140dfe64dd3Smacallan    int r ;
2141dfe64dd3Smacallan
2142dfe64dd3Smacallan    for( r = RankNo ; r >= 1 ; r-- )
2143dfe64dd3Smacallan    {
2144dfe64dd3Smacallan        if ( !XGINew_CheckRank( r , index , DRAMTYPE_TABLE, pVBInfo ) )
2145dfe64dd3Smacallan            return( 0 ) ;
2146dfe64dd3Smacallan    }
2147dfe64dd3Smacallan
2148dfe64dd3Smacallan    if ( !XGINew_CheckBanks( index , DRAMTYPE_TABLE, pVBInfo ) )
2149dfe64dd3Smacallan        return( 0 ) ;
2150dfe64dd3Smacallan
2151dfe64dd3Smacallan    if ( !XGINew_CheckColumn( index , DRAMTYPE_TABLE, pVBInfo ) )
2152dfe64dd3Smacallan        return( 0 ) ;
2153dfe64dd3Smacallan
2154dfe64dd3Smacallan    return( 1 ) ;
2155dfe64dd3Smacallan}
2156dfe64dd3Smacallan
2157dfe64dd3Smacallan
2158dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2159dfe64dd3Smacallan/* Function : XGINew_CheckDDRRanks */
2160dfe64dd3Smacallan/* Input : */
2161dfe64dd3Smacallan/* Output : */
2162dfe64dd3Smacallan/* Description : */
2163dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2164dfe64dd3Smacallanint XGINew_CheckDDRRanks(int RankNo, int index,
2165dfe64dd3Smacallan			 const USHORT DRAMTYPE_TABLE[][5],
2166dfe64dd3Smacallan			 PVB_DEVICE_INFO pVBInfo)
2167dfe64dd3Smacallan{
2168dfe64dd3Smacallan    int r ;
2169dfe64dd3Smacallan
2170dfe64dd3Smacallan    for( r = RankNo ; r >= 1 ; r-- )
2171dfe64dd3Smacallan    {
2172dfe64dd3Smacallan        if ( !XGINew_CheckDDRRank( r , index , DRAMTYPE_TABLE, pVBInfo ) )
2173dfe64dd3Smacallan            return( 0 ) ;
2174dfe64dd3Smacallan    }
2175dfe64dd3Smacallan
2176dfe64dd3Smacallan    if ( !XGINew_CheckBanks( index , DRAMTYPE_TABLE, pVBInfo ) )
2177dfe64dd3Smacallan        return( 0 ) ;
2178dfe64dd3Smacallan
2179dfe64dd3Smacallan    if ( !XGINew_CheckColumn( index , DRAMTYPE_TABLE, pVBInfo ) )
2180dfe64dd3Smacallan        return( 0 ) ;
2181dfe64dd3Smacallan
2182dfe64dd3Smacallan    return( 1 ) ;
2183dfe64dd3Smacallan}
2184dfe64dd3Smacallan
2185dfe64dd3Smacallan
2186dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2187dfe64dd3Smacallan/* Function : */
2188dfe64dd3Smacallan/* Input : */
2189dfe64dd3Smacallan/* Output : */
2190dfe64dd3Smacallan/* Description : */
2191dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2192dfe64dd3Smacallanint XGINew_SDRSizing(PVB_DEVICE_INFO pVBInfo)
2193dfe64dd3Smacallan{
2194dfe64dd3Smacallan    int    i ;
2195dfe64dd3Smacallan    UCHAR  j ;
2196dfe64dd3Smacallan
2197dfe64dd3Smacallan    for( i = 0 ; i < 13 ; i++ )
2198dfe64dd3Smacallan    {
2199dfe64dd3Smacallan        XGINew_SetDRAMSizingType( i , XGINew_SDRDRAM_TYPE , pVBInfo) ;
2200dfe64dd3Smacallan
2201dfe64dd3Smacallan        for( j = 2 ; j > 0 ; j-- )
2202dfe64dd3Smacallan        {
2203dfe64dd3Smacallan            if ( !XGINew_SetRank( i , ( UCHAR )j , XGINew_ChannelAB , XGINew_SDRDRAM_TYPE , pVBInfo) )
2204dfe64dd3Smacallan                continue ;
2205dfe64dd3Smacallan            else
2206dfe64dd3Smacallan            {
2207dfe64dd3Smacallan                if ( XGINew_CheckRanks( j , i , XGINew_SDRDRAM_TYPE, pVBInfo) )
2208dfe64dd3Smacallan                    return( 1 ) ;
2209dfe64dd3Smacallan            }
2210dfe64dd3Smacallan        }
2211dfe64dd3Smacallan    }
2212dfe64dd3Smacallan    return( 0 ) ;
2213dfe64dd3Smacallan}
2214dfe64dd3Smacallan
2215dfe64dd3Smacallan
2216dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2217dfe64dd3Smacallan/* Function : XGINew_SetDRAMSizeReg */
2218dfe64dd3Smacallan/* Input : */
2219dfe64dd3Smacallan/* Output : */
2220dfe64dd3Smacallan/* Description : */
2221dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2222dfe64dd3SmacallanUSHORT XGINew_SetDRAMSizeReg(int index, const USHORT DRAMTYPE_TABLE[][5],
2223dfe64dd3Smacallan			     PVB_DEVICE_INFO pVBInfo)
2224dfe64dd3Smacallan{
2225dfe64dd3Smacallan    USHORT data = 0 , memsize = 0 ;
2226dfe64dd3Smacallan    int RankSize ;
2227dfe64dd3Smacallan    UCHAR ChannelNo ;
2228dfe64dd3Smacallan
2229dfe64dd3Smacallan    RankSize = DRAMTYPE_TABLE[ index ][ 3 ] * XGINew_DataBusWidth / 32 ;
2230dfe64dd3Smacallan    data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 ) ;
2231dfe64dd3Smacallan    data &= 0x80 ;
2232dfe64dd3Smacallan
2233dfe64dd3Smacallan    if ( data == 0x80 )
2234dfe64dd3Smacallan        RankSize *= 2 ;
2235dfe64dd3Smacallan
2236dfe64dd3Smacallan    data = 0 ;
2237dfe64dd3Smacallan
2238dfe64dd3Smacallan    if( XGINew_ChannelAB == 3 )
2239dfe64dd3Smacallan        ChannelNo = 4 ;
2240dfe64dd3Smacallan    else
2241dfe64dd3Smacallan        ChannelNo = XGINew_ChannelAB ;
2242dfe64dd3Smacallan
2243dfe64dd3Smacallan    if ( ChannelNo * RankSize <= 256 )
2244dfe64dd3Smacallan    {
2245dfe64dd3Smacallan        while( ( RankSize >>= 1 ) > 0 )
2246dfe64dd3Smacallan        {
2247dfe64dd3Smacallan            data += 0x10 ;
2248dfe64dd3Smacallan        }
2249dfe64dd3Smacallan
2250dfe64dd3Smacallan        memsize = data >> 4 ;
2251dfe64dd3Smacallan
2252dfe64dd3Smacallan        /* [2004/03/25] Vicent, Fix DRAM Sizing Error */
2253dfe64dd3Smacallan        XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , ( XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 ) & 0x0F ) | ( data & 0xF0 ) ) ;
2254dfe64dd3Smacallan
2255dfe64dd3Smacallan       /* data |= XGINew_ChannelAB << 2 ; */
2256dfe64dd3Smacallan       /* data |= ( XGINew_DataBusWidth / 64 ) << 1 ; */
2257dfe64dd3Smacallan       /* XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , data ) ; */
2258dfe64dd3Smacallan
2259dfe64dd3Smacallan        /* should delay */
2260dfe64dd3Smacallan        /* XGINew_SetDRAMModeRegister340( pVBInfo ) ; */
2261dfe64dd3Smacallan    }
2262dfe64dd3Smacallan    return( memsize ) ;
2263dfe64dd3Smacallan}
2264dfe64dd3Smacallan
2265dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2266dfe64dd3Smacallan/* Function : XGINew_SetDRAMSize20Reg */
2267dfe64dd3Smacallan/* Input : */
2268dfe64dd3Smacallan/* Output : */
2269dfe64dd3Smacallan/* Description : */
2270dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2271dfe64dd3SmacallanUSHORT XGINew_SetDRAMSize20Reg( int index , USHORT DRAMTYPE_TABLE[][ 5 ], PVB_DEVICE_INFO pVBInfo)
2272dfe64dd3Smacallan{
2273dfe64dd3Smacallan    USHORT data = 0 , memsize = 0 ;
2274dfe64dd3Smacallan    int RankSize ;
2275dfe64dd3Smacallan    UCHAR ChannelNo ;
2276dfe64dd3Smacallan
2277dfe64dd3Smacallan    RankSize = DRAMTYPE_TABLE[ index ][ 3 ] * XGINew_DataBusWidth / 8 ;
2278dfe64dd3Smacallan    data = XGI_GetReg( (XGIIOADDRESS) pVBInfo->P3c4 , 0x13 ) ;
2279dfe64dd3Smacallan    data &= 0x80 ;
2280dfe64dd3Smacallan
2281dfe64dd3Smacallan    if ( data == 0x80 )
2282dfe64dd3Smacallan        RankSize *= 2 ;
2283dfe64dd3Smacallan
2284dfe64dd3Smacallan    data = 0 ;
2285dfe64dd3Smacallan
2286dfe64dd3Smacallan    if( XGINew_ChannelAB == 3 )
2287dfe64dd3Smacallan        ChannelNo = 4 ;
2288dfe64dd3Smacallan    else
2289dfe64dd3Smacallan        ChannelNo = XGINew_ChannelAB ;
2290dfe64dd3Smacallan
2291dfe64dd3Smacallan    if ( ChannelNo * RankSize <= 256 )
2292dfe64dd3Smacallan    {
2293dfe64dd3Smacallan        while( ( RankSize >>= 1 ) > 0 )
2294dfe64dd3Smacallan        {
2295dfe64dd3Smacallan            data += 0x10 ;
2296dfe64dd3Smacallan        }
2297dfe64dd3Smacallan
2298dfe64dd3Smacallan        memsize = data >> 4 ;
2299dfe64dd3Smacallan
2300dfe64dd3Smacallan        /* [2004/03/25] Vicent, Fix DRAM Sizing Error */
2301dfe64dd3Smacallan        XGI_SetReg( (XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , ( XGI_GetReg( (XGIIOADDRESS) pVBInfo->P3c4 , 0x14 ) & 0x0F ) | ( data & 0xF0 ) ) ;
2302dfe64dd3Smacallan	DelayUS( 15 ) ;
2303dfe64dd3Smacallan
2304dfe64dd3Smacallan       /* data |= XGINew_ChannelAB << 2 ; */
2305dfe64dd3Smacallan       /* data |= ( XGINew_DataBusWidth / 64 ) << 1 ; */
2306dfe64dd3Smacallan       /* XGINew_SetReg1( pVBInfo->P3c4 , 0x14 , data ) ; */
2307dfe64dd3Smacallan
2308dfe64dd3Smacallan        /* should delay */
2309dfe64dd3Smacallan        /* XGINew_SetDRAMModeRegister340( pVBInfo ) ; */
2310dfe64dd3Smacallan    }
2311dfe64dd3Smacallan    return( memsize ) ;
2312dfe64dd3Smacallan}
2313dfe64dd3Smacallan
2314dfe64dd3Smacallan
2315dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2316dfe64dd3Smacallan/* Function : XGINew_ReadWriteRest */
2317dfe64dd3Smacallan/* Input : */
2318dfe64dd3Smacallan/* Output : */
2319dfe64dd3Smacallan/* Description : */
2320dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2321dfe64dd3Smacallanint XGINew_ReadWriteRest( USHORT StopAddr, USHORT StartAddr,
2322dfe64dd3Smacallan			  PVB_DEVICE_INFO pVBInfo)
2323dfe64dd3Smacallan{
2324dfe64dd3Smacallan    int i ;
2325dfe64dd3Smacallan    ULONG Position = 0 ;
2326dfe64dd3Smacallan
2327dfe64dd3Smacallan    *( ( PULONG )( pVBInfo->FBAddr + Position ) ) = Position ;
2328dfe64dd3Smacallan
2329dfe64dd3Smacallan    for( i = StartAddr ; i <= StopAddr ; i++ )
2330dfe64dd3Smacallan    {
2331dfe64dd3Smacallan        Position = 1 << i ;
2332dfe64dd3Smacallan        *( ( PULONG )( pVBInfo->FBAddr + Position ) ) = Position ;
2333dfe64dd3Smacallan    }
2334dfe64dd3Smacallan
2335dfe64dd3Smacallan    DelayUS( 500 ) ;	/* [Vicent] 2004/04/16. Fix #1759 Memory Size error in Multi-Adapter. */
2336dfe64dd3Smacallan
2337dfe64dd3Smacallan    Position = 0 ;
2338dfe64dd3Smacallan
2339dfe64dd3Smacallan    if ( ( *( PULONG )( pVBInfo->FBAddr + Position ) ) != Position )
2340dfe64dd3Smacallan        return( 0 ) ;
2341dfe64dd3Smacallan
2342dfe64dd3Smacallan    for( i = StartAddr ; i <= StopAddr ; i++ )
2343dfe64dd3Smacallan    {
2344dfe64dd3Smacallan        Position = 1 << i ;
2345dfe64dd3Smacallan        if ( ( *( PULONG )( pVBInfo->FBAddr + Position ) ) != Position )
2346dfe64dd3Smacallan            return( 0 ) ;
2347dfe64dd3Smacallan    }
2348dfe64dd3Smacallan    return( 1 ) ;
2349dfe64dd3Smacallan}
2350dfe64dd3Smacallan
2351dfe64dd3Smacallan
2352dfe64dd3Smacallan/*--------------------------------------------------------------------- */
2353dfe64dd3Smacallan/* Function    : XGI45New_ReadWriteRest */
2354dfe64dd3Smacallan/* Input       : */
2355dfe64dd3Smacallan/* Output      : */
2356dfe64dd3Smacallan/* Description : return 0 : fail, 1 : pass */
2357dfe64dd3Smacallan/*--------------------------------------------------------------------- */
2358dfe64dd3Smacallanint XGI45New_ReadWriteRest(USHORT StopAddr, USHORT StartAddr,
2359dfe64dd3Smacallan			   PVB_DEVICE_INFO pVBInfo)
2360dfe64dd3Smacallan{
2361dfe64dd3Smacallan    int i ;
2362dfe64dd3Smacallan    ULONG Position = 0 ;
2363dfe64dd3Smacallan
2364dfe64dd3Smacallan    *( ( PULONG )( pVBInfo->FBAddr + Position ) ) = Position ;
2365dfe64dd3Smacallan
2366dfe64dd3Smacallan    for( i = StartAddr ; i <= StopAddr ; i++ )
2367dfe64dd3Smacallan    {
2368dfe64dd3Smacallan        Position = 1 << i ;
2369dfe64dd3Smacallan        *( ( PULONG )( pVBInfo->FBAddr + Position ) ) = Position ;
2370dfe64dd3Smacallan    }
2371dfe64dd3Smacallan
2372dfe64dd3Smacallan    if ( XGINew_ChannelAB == 4 )
2373dfe64dd3Smacallan    {
2374dfe64dd3Smacallan        Position = ( 1 << StopAddr ) + ( 1 << ( StopAddr - 1 ) );
2375dfe64dd3Smacallan        *( ( PULONG )( pVBInfo->FBAddr + Position ) ) = Position ;
2376dfe64dd3Smacallan    }
2377dfe64dd3Smacallan
2378dfe64dd3Smacallan    DelayUS( 500 ) ;	/* [Vicent] 2004/04/16. Fix #1759 Memory Size error in Multi-Adapter. */
2379dfe64dd3Smacallan
2380dfe64dd3Smacallan    Position = 0 ;
2381dfe64dd3Smacallan
2382dfe64dd3Smacallan    if ( ( *( PULONG )( pVBInfo->FBAddr + Position ) ) != Position )
2383dfe64dd3Smacallan        return( 0 ) ;
2384dfe64dd3Smacallan
2385dfe64dd3Smacallan    for( i = StartAddr ; i <= StopAddr ; i++ )
2386dfe64dd3Smacallan    {
2387dfe64dd3Smacallan        Position = 1 << i ;
2388dfe64dd3Smacallan        if ( ( *( PULONG )( pVBInfo->FBAddr + Position ) ) != Position )
2389dfe64dd3Smacallan            return( 0 ) ;
2390dfe64dd3Smacallan    }
2391dfe64dd3Smacallan
2392dfe64dd3Smacallan    if ( XGINew_ChannelAB == 4 )
2393dfe64dd3Smacallan    {
2394dfe64dd3Smacallan        Position = ( 1 << StopAddr ) + ( 1 << ( StopAddr - 1 ) );
2395dfe64dd3Smacallan        if( ( *( PULONG )( pVBInfo->FBAddr + Position ) ) != Position );
2396dfe64dd3Smacallan        return( 0 ) ;
2397dfe64dd3Smacallan    }
2398dfe64dd3Smacallan    return( 1 ) ;
2399dfe64dd3Smacallan}
2400dfe64dd3Smacallan
2401dfe64dd3Smacallan
2402dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2403dfe64dd3Smacallan/* Function : XGINew_CheckFrequence */
2404dfe64dd3Smacallan/* Input : */
2405dfe64dd3Smacallan/* Output : */
2406dfe64dd3Smacallan/* Description : */
2407dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2408dfe64dd3SmacallanUCHAR XGINew_CheckFrequence(PVB_DEVICE_INFO pVBInfo)
2409dfe64dd3Smacallan{
2410dfe64dd3Smacallan    UCHAR data ;
2411dfe64dd3Smacallan
2412dfe64dd3Smacallan    data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x97 ) ;
2413dfe64dd3Smacallan
2414dfe64dd3Smacallan    if ( ( data & 0x10 ) == 0 )
2415dfe64dd3Smacallan    {
2416dfe64dd3Smacallan        data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x39 ) ;
2417dfe64dd3Smacallan        data = ( data & 0x02 ) >> 1 ;
2418dfe64dd3Smacallan        return( data ) ;
2419dfe64dd3Smacallan    }
2420dfe64dd3Smacallan    else
2421dfe64dd3Smacallan        return( data & 0x01 ) ;
2422dfe64dd3Smacallan}
2423dfe64dd3Smacallan
2424dfe64dd3Smacallan
2425dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2426dfe64dd3Smacallan/* Function : XGINew_CheckChannel */
2427dfe64dd3Smacallan/* Input : */
2428dfe64dd3Smacallan/* Output : */
2429dfe64dd3Smacallan/* Description : */
2430dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2431dfe64dd3Smacallanvoid XGINew_CheckChannel(PXGI_HW_DEVICE_INFO HwDeviceExtension,
2432dfe64dd3Smacallan			 PVB_DEVICE_INFO pVBInfo)
2433dfe64dd3Smacallan{
2434dfe64dd3Smacallan    UCHAR i, data ;
2435dfe64dd3Smacallan
2436dfe64dd3Smacallan    switch( HwDeviceExtension->jChipType )
2437dfe64dd3Smacallan    {
2438dfe64dd3Smacallan      case XG20:
2439dfe64dd3Smacallan      case XG21:
2440dfe64dd3Smacallan          data = XGI_GetReg( (XGIIOADDRESS) pVBInfo->P3d4 , 0x97 ) ;
2441dfe64dd3Smacallan          data = data & 0x01;
2442dfe64dd3Smacallan          XGINew_ChannelAB = 1 ;		/* XG20 "JUST" one channel */
2443dfe64dd3Smacallan
2444dfe64dd3Smacallan          if ( data == 0 )  /* Single_32_16 */
2445dfe64dd3Smacallan          {
2446dfe64dd3Smacallan            /* Jong 10/03/2007 */
2447dfe64dd3Smacallan	    if (( HwDeviceExtension->ulVideoMemorySize - 1 ) > 0x1000000)
2448dfe64dd3Smacallan	    {
2449dfe64dd3Smacallan
2450dfe64dd3Smacallan              XGINew_DataBusWidth = 32 ;	/* 32 bits */
2451dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0xB1 ) ;  /* 22bit + 2 rank + 32bit */
2452dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x52 ) ;
2453dfe64dd3Smacallan              DelayUS( 15 ) ;
2454dfe64dd3Smacallan
2455dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 24 , 23 , pVBInfo ) == 1 )
2456dfe64dd3Smacallan                  return ;
2457dfe64dd3Smacallan
2458dfe64dd3Smacallan              /* Jong 10/03/2007 */
2459dfe64dd3Smacallan	      if (( HwDeviceExtension->ulVideoMemorySize - 1 ) > 0x800000)
2460dfe64dd3Smacallan	      {
2461dfe64dd3Smacallan                  XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0x31 ) ;  /* 22bit + 1 rank + 32bit */
2462dfe64dd3Smacallan                  XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x42 ) ;
2463dfe64dd3Smacallan                  DelayUS( 15 ) ;
2464dfe64dd3Smacallan
2465dfe64dd3Smacallan                  if ( XGINew_ReadWriteRest( 23 , 23 , pVBInfo ) == 1 )
2466dfe64dd3Smacallan                       return ;
2467dfe64dd3Smacallan              }
2468dfe64dd3Smacallan            }
2469dfe64dd3Smacallan
2470dfe64dd3Smacallan            /* Jong 10/03/2007 */
2471dfe64dd3Smacallan	    if (( HwDeviceExtension->ulVideoMemorySize - 1 ) > 0x800000)
2472dfe64dd3Smacallan	    {
2473dfe64dd3Smacallan	        XGINew_DataBusWidth = 16 ;	/* 16 bits */
2474dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0xB1 ) ;  /* 22bit + 2 rank + 16bit */
2475dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x41 ) ;
2476dfe64dd3Smacallan                DelayUS( 15 ) ;
2477dfe64dd3Smacallan
2478dfe64dd3Smacallan                if ( XGINew_ReadWriteRest( 23 , 22 , pVBInfo ) == 1 )
2479dfe64dd3Smacallan                    return ;
2480dfe64dd3Smacallan                else
2481dfe64dd3Smacallan                    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0x31 ) ;
2482dfe64dd3Smacallan
2483dfe64dd3Smacallan                DelayUS( 15 ) ;
2484dfe64dd3Smacallan            }
2485dfe64dd3Smacallan          }
2486dfe64dd3Smacallan          else  /* Dual_16_8 */
2487dfe64dd3Smacallan          {
2488dfe64dd3Smacallan              if (( HwDeviceExtension->ulVideoMemorySize - 1 ) > 0x800000)
2489dfe64dd3Smacallan              {
2490dfe64dd3Smacallan
2491dfe64dd3Smacallan                XGINew_DataBusWidth = 16 ;	/* 16 bits */
2492dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0xB1 ) ;
2493dfe64dd3Smacallan                XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x41 ) ;
2494dfe64dd3Smacallan                DelayUS( 15 ) ;
2495dfe64dd3Smacallan
2496dfe64dd3Smacallan                if ( XGINew_ReadWriteRest( 23 , 22 , pVBInfo ) == 1 )
2497dfe64dd3Smacallan                  return ;
2498dfe64dd3Smacallan
2499dfe64dd3Smacallan		if (( HwDeviceExtension->ulVideoMemorySize - 1 ) > 0x400000)
2500dfe64dd3Smacallan		{
2501dfe64dd3Smacallan
2502dfe64dd3Smacallan                   XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0x31 ) ;
2503dfe64dd3Smacallan                   XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x31 ) ;
2504dfe64dd3Smacallan                   DelayUS( 15 ) ;
2505dfe64dd3Smacallan
2506dfe64dd3Smacallan                   if ( XGINew_ReadWriteRest( 22 , 22 , pVBInfo ) == 1 )
2507dfe64dd3Smacallan                      return ;
2508dfe64dd3Smacallan                }
2509dfe64dd3Smacallan	      }
2510dfe64dd3Smacallan
2511dfe64dd3Smacallan
2512dfe64dd3Smacallan	      if (( HwDeviceExtension->ulVideoMemorySize - 1 ) > 0x400000)
2513dfe64dd3Smacallan	      {
2514dfe64dd3Smacallan	          XGINew_DataBusWidth = 8 ;	/* 8 bits */
2515dfe64dd3Smacallan                  XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0xB1 ) ;
2516dfe64dd3Smacallan                  XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x30 ) ;
2517dfe64dd3Smacallan                  DelayUS( 15 ) ;
2518dfe64dd3Smacallan
2519dfe64dd3Smacallan                  if ( XGINew_ReadWriteRest( 22 , 21 , pVBInfo ) == 1 )
2520dfe64dd3Smacallan                      return ;
2521dfe64dd3Smacallan                  else
2522dfe64dd3Smacallan                      XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0x31 ) ;
2523dfe64dd3Smacallan                      DelayUS( 15 ) ;
2524dfe64dd3Smacallan              }
2525dfe64dd3Smacallan          }
2526dfe64dd3Smacallan          break ;
2527dfe64dd3Smacallan
2528dfe64dd3Smacallan      case XG27:
2529dfe64dd3Smacallan          XGINew_DataBusWidth = 16 ;	/* 16 bits */
2530dfe64dd3Smacallan          XGINew_ChannelAB = 1 ;		/* Single channel */
2531dfe64dd3Smacallan          XGI_SetReg( (XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x51 ) ;  /* 32Mx16 bit*/
2532dfe64dd3Smacallan          break ;
2533dfe64dd3Smacallan
2534dfe64dd3Smacallan      case XG41:
2535dfe64dd3Smacallan          if ( XGINew_CheckFrequence(pVBInfo) == 1 )
2536dfe64dd3Smacallan          {
2537dfe64dd3Smacallan              XGINew_DataBusWidth = 32 ;	/* 32 bits */
2538dfe64dd3Smacallan              XGINew_ChannelAB = 3 ;		/* Quad Channel */
2539dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0xA1 ) ;
2540dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x4C ) ;
2541dfe64dd3Smacallan
2542dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 25 , 23 , pVBInfo ) == 1 )
2543dfe64dd3Smacallan                  return ;
2544dfe64dd3Smacallan
2545dfe64dd3Smacallan              XGINew_ChannelAB = 2 ;		/* Dual channels */
2546dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x48 ) ;
2547dfe64dd3Smacallan
2548dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 24 , 23 , pVBInfo ) == 1 )
2549dfe64dd3Smacallan                  return ;
2550dfe64dd3Smacallan
2551dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x49 ) ;
2552dfe64dd3Smacallan
2553dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 24 , 23 , pVBInfo ) == 1 )
2554dfe64dd3Smacallan                  return ;
2555dfe64dd3Smacallan
2556dfe64dd3Smacallan              XGINew_ChannelAB = 3 ;
2557dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0x21 ) ;
2558dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x3C ) ;
2559dfe64dd3Smacallan
2560dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 24 , 23 , pVBInfo ) == 1 )
2561dfe64dd3Smacallan                  return ;
2562dfe64dd3Smacallan
2563dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x38 ) ;
2564dfe64dd3Smacallan
2565dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 8 , 4 , pVBInfo ) == 1 )
2566dfe64dd3Smacallan                  return ;
2567dfe64dd3Smacallan              else
2568dfe64dd3Smacallan                  XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x39 ) ;
2569dfe64dd3Smacallan          }
2570dfe64dd3Smacallan          else
2571dfe64dd3Smacallan          {					/* DDR */
2572dfe64dd3Smacallan              XGINew_DataBusWidth = 64 ;	/* 64 bits */
2573dfe64dd3Smacallan              XGINew_ChannelAB = 2 ;		/* Dual channels */
2574dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0xA1 ) ;
2575dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x5A ) ;
2576dfe64dd3Smacallan
2577dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 25 , 24 , pVBInfo ) == 1 )
2578dfe64dd3Smacallan                  return ;
2579dfe64dd3Smacallan
2580dfe64dd3Smacallan              XGINew_ChannelAB = 1 ;		/* Single channels */
2581dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x52 ) ;
2582dfe64dd3Smacallan
2583dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 24 , 23 , pVBInfo ) == 1 )
2584dfe64dd3Smacallan                  return ;
2585dfe64dd3Smacallan
2586dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x53 ) ;
2587dfe64dd3Smacallan
2588dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 24 , 23 , pVBInfo ) == 1 )
2589dfe64dd3Smacallan                  return ;
2590dfe64dd3Smacallan
2591dfe64dd3Smacallan              XGINew_ChannelAB = 2 ;		/* Dual channels */
2592dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0x21 ) ;
2593dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x4A ) ;
2594dfe64dd3Smacallan
2595dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 24 , 23 , pVBInfo ) == 1 )
2596dfe64dd3Smacallan                  return ;
2597dfe64dd3Smacallan
2598dfe64dd3Smacallan              XGINew_ChannelAB = 1 ;		/* Single channels */
2599dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x42 ) ;
2600dfe64dd3Smacallan
2601dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 8 , 4 , pVBInfo ) == 1 )
2602dfe64dd3Smacallan                  return ;
2603dfe64dd3Smacallan              else
2604dfe64dd3Smacallan                  XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x43 ) ;
2605dfe64dd3Smacallan          }
2606dfe64dd3Smacallan
2607dfe64dd3Smacallan          break ;
2608dfe64dd3Smacallan
2609dfe64dd3Smacallan      case XG42:
2610dfe64dd3Smacallan/*
2611dfe64dd3Smacallan      	  XG42 SR14 D[3] Reserve
2612dfe64dd3Smacallan      	  	    D[2] = 1, Dual Channel
2613dfe64dd3Smacallan      	  	         = 0, Single Channel
2614dfe64dd3Smacallan
2615dfe64dd3Smacallan      	  It's Different from Other XG40 Series.
2616dfe64dd3Smacallan*/
2617dfe64dd3Smacallan          if ( XGINew_CheckFrequence(pVBInfo) == 1 )	/* DDRII, DDR2x */
2618dfe64dd3Smacallan          {
2619dfe64dd3Smacallan              XGINew_DataBusWidth = 32 ;	/* 32 bits */
2620dfe64dd3Smacallan              XGINew_ChannelAB = 2 ;		/* 2 Channel */
2621dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0xA1 ) ;
2622dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x44 ) ;
2623dfe64dd3Smacallan
2624dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 24 , 23 , pVBInfo ) == 1 )
2625dfe64dd3Smacallan                  return ;
2626dfe64dd3Smacallan
2627dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0x21 ) ;
2628dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x34 ) ;
2629dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 23 , 22 , pVBInfo ) == 1 )
2630dfe64dd3Smacallan                  return ;
2631dfe64dd3Smacallan
2632dfe64dd3Smacallan              XGINew_ChannelAB = 1 ;		/* Single Channel */
2633dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0xA1 ) ;
2634dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x40 ) ;
2635dfe64dd3Smacallan
2636dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 23 , 22 , pVBInfo ) == 1 )
2637dfe64dd3Smacallan                  return ;
2638dfe64dd3Smacallan              else
2639dfe64dd3Smacallan              {
2640dfe64dd3Smacallan                  XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0x21 ) ;
2641dfe64dd3Smacallan                  XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x30 ) ;
2642dfe64dd3Smacallan              }
2643dfe64dd3Smacallan          }
2644dfe64dd3Smacallan          else
2645dfe64dd3Smacallan          {					/* DDR */
2646dfe64dd3Smacallan              XGINew_DataBusWidth = 64 ;	/* 64 bits */
2647dfe64dd3Smacallan              XGINew_ChannelAB = 1 ;		/* 1 channels */
2648dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0xA1 ) ;
2649dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x52 ) ;
2650dfe64dd3Smacallan
2651dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 24 , 23 , pVBInfo ) == 1 )
2652dfe64dd3Smacallan                  return ;
2653dfe64dd3Smacallan              else
2654dfe64dd3Smacallan              {
2655dfe64dd3Smacallan                  XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0x21 ) ;
2656dfe64dd3Smacallan                  XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x42 ) ;
2657dfe64dd3Smacallan              }
2658dfe64dd3Smacallan          }
2659dfe64dd3Smacallan
2660dfe64dd3Smacallan          break ;
2661dfe64dd3Smacallan
2662dfe64dd3Smacallan      case XG45:
2663dfe64dd3Smacallan
2664dfe64dd3Smacallan      	   XGINew_DataBusWidth = 64 ;	/* 64 bits */
2665dfe64dd3Smacallan           XGINew_ChannelAB = 4 ;		/* 3+1 Channel */
2666dfe64dd3Smacallan           XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0x21 ) ;
2667dfe64dd3Smacallan           XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x4C ) ;
2668dfe64dd3Smacallan
2669dfe64dd3Smacallan           if ( XGI45New_ReadWriteRest( 25 , 24 , pVBInfo ) == 1 )
2670dfe64dd3Smacallan               return ;
2671dfe64dd3Smacallan
2672dfe64dd3Smacallan           XGINew_ChannelAB = 3 ;		/* 3 Channel */
2673dfe64dd3Smacallan           XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0xA1 ) ;
2674dfe64dd3Smacallan           XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x58 ) ;
2675dfe64dd3Smacallan
2676dfe64dd3Smacallan           if ( XGI45New_ReadWriteRest( 26 , 24 , pVBInfo ) == 1 )
2677dfe64dd3Smacallan               return ;
2678dfe64dd3Smacallan
2679dfe64dd3Smacallan           XGINew_ChannelAB = 2 ;		/* 2 Channel */
2680dfe64dd3Smacallan           XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0xA1 ) ;
2681dfe64dd3Smacallan           XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x54 ) ;
2682dfe64dd3Smacallan
2683dfe64dd3Smacallan           if ( XGI45New_ReadWriteRest( 25 , 24 , pVBInfo ) == 1 )
2684dfe64dd3Smacallan               return ;
2685dfe64dd3Smacallan
2686dfe64dd3Smacallan           XGINew_ChannelAB = 1 ;		/* 1 Channel */
2687dfe64dd3Smacallan           for ( i = 0; i <= 2; i++)
2688dfe64dd3Smacallan           {
2689dfe64dd3Smacallan               XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0xA1 ) ;
2690dfe64dd3Smacallan               XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x50+i ) ;
2691dfe64dd3Smacallan
2692dfe64dd3Smacallan               if ( XGI45New_ReadWriteRest( 24 , 23 , pVBInfo ) == 1 )
2693dfe64dd3Smacallan                   return ;
2694dfe64dd3Smacallan           }
2695dfe64dd3Smacallan
2696dfe64dd3Smacallan           XGINew_ChannelAB = 3 ;		/* 3 Channel */
2697dfe64dd3Smacallan           XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0x21 ) ;
2698dfe64dd3Smacallan           XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x58 ) ;
2699dfe64dd3Smacallan
2700dfe64dd3Smacallan           if ( XGI45New_ReadWriteRest( 25 , 24 , pVBInfo ) == 1 )
2701dfe64dd3Smacallan               return ;
2702dfe64dd3Smacallan
2703dfe64dd3Smacallan           XGINew_ChannelAB = 2 ;		/* 2 Channel */
2704dfe64dd3Smacallan           XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0x21 ) ;
2705dfe64dd3Smacallan           XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x54 ) ;
2706dfe64dd3Smacallan
2707dfe64dd3Smacallan           if ( XGI45New_ReadWriteRest( 24 , 23 , pVBInfo ) == 1 )
2708dfe64dd3Smacallan               return ;
2709dfe64dd3Smacallan
2710dfe64dd3Smacallan           XGINew_ChannelAB = 1 ;		/* 1 Channel */
2711dfe64dd3Smacallan           for ( i = 0; i <= 2; i++)
2712dfe64dd3Smacallan           {
2713dfe64dd3Smacallan               XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0x21 ) ;
2714dfe64dd3Smacallan               XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x50+i ) ;
2715dfe64dd3Smacallan
2716dfe64dd3Smacallan               if ( XGI45New_ReadWriteRest( 23 , 22 , pVBInfo ) == 1 )
2717dfe64dd3Smacallan                   return ;
2718dfe64dd3Smacallan           }
2719dfe64dd3Smacallan           break ;
2720dfe64dd3Smacallan
2721dfe64dd3Smacallan      default:	/* XG40 */
2722dfe64dd3Smacallan
2723dfe64dd3Smacallan          if ( XGINew_CheckFrequence(pVBInfo) == 1 )	/* DDRII */
2724dfe64dd3Smacallan          {
2725dfe64dd3Smacallan              XGINew_DataBusWidth = 32 ;	/* 32 bits */
2726dfe64dd3Smacallan              XGINew_ChannelAB = 3 ;
2727dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0xA1 ) ;
2728dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x4C ) ;
2729dfe64dd3Smacallan
2730dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 25 , 23 , pVBInfo ) == 1 )
2731dfe64dd3Smacallan                  return ;
2732dfe64dd3Smacallan
2733dfe64dd3Smacallan              XGINew_ChannelAB = 2 ;		/* 2 channels */
2734dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x48 ) ;
2735dfe64dd3Smacallan
2736dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 24 , 23 , pVBInfo ) == 1 )
2737dfe64dd3Smacallan                  return ;
2738dfe64dd3Smacallan
2739dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0x21 ) ;
2740dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x3C ) ;
2741dfe64dd3Smacallan
2742dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 24 , 23 , pVBInfo ) == 1 )
2743dfe64dd3Smacallan                  XGINew_ChannelAB = 3 ;	/* 4 channels */
2744dfe64dd3Smacallan              else
2745dfe64dd3Smacallan              {
2746dfe64dd3Smacallan                  XGINew_ChannelAB = 2 ;	/* 2 channels */
2747dfe64dd3Smacallan                  XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x38 ) ;
2748dfe64dd3Smacallan              }
2749dfe64dd3Smacallan          }
2750dfe64dd3Smacallan          else
2751dfe64dd3Smacallan          {					/* DDR */
2752dfe64dd3Smacallan              XGINew_DataBusWidth = 64 ;	/* 64 bits */
2753dfe64dd3Smacallan              XGINew_ChannelAB = 2 ;		/* 2 channels */
2754dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0xA1 ) ;
2755dfe64dd3Smacallan              XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x5A ) ;
2756dfe64dd3Smacallan
2757dfe64dd3Smacallan              if ( XGINew_ReadWriteRest( 25 , 24 , pVBInfo ) == 1 )
2758dfe64dd3Smacallan                  return ;
2759dfe64dd3Smacallan              else
2760dfe64dd3Smacallan              {
2761dfe64dd3Smacallan                  XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x13 , 0x21 ) ;
2762dfe64dd3Smacallan                  XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x14 , 0x4A ) ;
2763dfe64dd3Smacallan              }
2764dfe64dd3Smacallan          }
2765dfe64dd3Smacallan      	  break ;
2766dfe64dd3Smacallan    }
2767dfe64dd3Smacallan}
2768dfe64dd3Smacallan
2769dfe64dd3Smacallan
2770dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2771dfe64dd3Smacallan/* Function : XGINew_DDRSizing340 */
2772dfe64dd3Smacallan/* Input : */
2773dfe64dd3Smacallan/* Output : */
2774dfe64dd3Smacallan/* Description : */
2775dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2776dfe64dd3Smacallanint XGINew_DDRSizing340( PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo)
2777dfe64dd3Smacallan{
2778dfe64dd3Smacallan    int i ;
2779dfe64dd3Smacallan    USHORT memsize , addr ;
2780dfe64dd3Smacallan
2781dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x15 , 0x00 ) ;	/* noninterleaving */
2782dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x1C , 0x00 ) ;	/* nontiling */
2783dfe64dd3Smacallan    XGINew_CheckChannel( HwDeviceExtension, pVBInfo ) ;
2784dfe64dd3Smacallan
2785dfe64dd3Smacallan    /* Jong 10/03/2007 */
2786dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType >= XG20 )
2787dfe64dd3Smacallan    {
2788dfe64dd3Smacallan      for( i = 0 ; i < 12 ; i++ )
2789dfe64dd3Smacallan      {
2790dfe64dd3Smacallan        XGINew_SetDRAMSizingType( i , XGINew_DDRDRAM_TYPE20, pVBInfo ) ;
2791dfe64dd3Smacallan        memsize = XGINew_SetDRAMSize20Reg( i , XGINew_DDRDRAM_TYPE20, pVBInfo ) ;
2792dfe64dd3Smacallan        if ( memsize == 0 )
2793dfe64dd3Smacallan            continue ;
2794dfe64dd3Smacallan
2795dfe64dd3Smacallan        addr = memsize + ( XGINew_ChannelAB - 2 ) + 20 ;
2796dfe64dd3Smacallan        if ( ( HwDeviceExtension->ulVideoMemorySize - 1 ) < ( ULONG )( 1 << addr ) )
2797dfe64dd3Smacallan            continue ;
2798dfe64dd3Smacallan
2799dfe64dd3Smacallan        if ( XGINew_ReadWriteRest( addr , 5, pVBInfo ) == 1 )
2800dfe64dd3Smacallan            return( 1 ) ;
2801dfe64dd3Smacallan      }
2802dfe64dd3Smacallan    }
2803dfe64dd3Smacallan    else
2804dfe64dd3Smacallan    {
2805dfe64dd3Smacallan      for( i = 0 ; i < 4 ; i++ )
2806dfe64dd3Smacallan      {
2807dfe64dd3Smacallan        XGINew_SetDRAMSizingType( i , XGINew_DDRDRAM_TYPE340, pVBInfo ) ;
2808dfe64dd3Smacallan        memsize = XGINew_SetDRAMSizeReg( i , XGINew_DDRDRAM_TYPE340, pVBInfo ) ;
2809dfe64dd3Smacallan        if ( memsize == 0 )
2810dfe64dd3Smacallan            continue ;
2811dfe64dd3Smacallan
2812dfe64dd3Smacallan        addr = memsize + ( XGINew_ChannelAB - 2 ) + 20 ;
2813dfe64dd3Smacallan        if ( ( HwDeviceExtension->ulVideoMemorySize - 1 ) < ( ULONG )( 1 << addr ) )
2814dfe64dd3Smacallan            continue ;
2815dfe64dd3Smacallan
2816dfe64dd3Smacallan        if ( XGINew_ReadWriteRest( addr , 9, pVBInfo ) == 1 )
2817dfe64dd3Smacallan            return( 1 ) ;
2818dfe64dd3Smacallan      }
2819dfe64dd3Smacallan    }
2820dfe64dd3Smacallan    return( 0 ) ;
2821dfe64dd3Smacallan}
2822dfe64dd3Smacallan
2823dfe64dd3Smacallan
2824dfe64dd3Smacallan/*--------------------------------------------------------------------- */
2825dfe64dd3Smacallan/* Function    : XGINew_DDRSizingXG45 */
2826dfe64dd3Smacallan/* Input       : */
2827dfe64dd3Smacallan/* Output      : */
2828dfe64dd3Smacallan/* Description : */
2829dfe64dd3Smacallan/*--------------------------------------------------------------------- */
2830dfe64dd3Smacallanint XGINew_DDRSizingXG45( PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo)
2831dfe64dd3Smacallan{
2832dfe64dd3Smacallan    int i ;
2833dfe64dd3Smacallan    USHORT memsize , addr ;
2834dfe64dd3Smacallan
2835dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x15 , 0x00 ) ;	/* noninterleaving */
2836dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x1C , 0x00 ) ;	/* nontiling */
2837dfe64dd3Smacallan    XGINew_CheckChannel( HwDeviceExtension, pVBInfo ) ;
2838dfe64dd3Smacallan
2839dfe64dd3Smacallan    for( i = 0 ; i < 4 ; i++ )
2840dfe64dd3Smacallan    {
2841dfe64dd3Smacallan        XGINew_SetDRAMSizingType( i , XGINew_DDRDRAM_TYPE340, pVBInfo ) ;
2842dfe64dd3Smacallan        memsize = XGINew_SetDRAMSizeReg( i , XGINew_DDRDRAM_TYPE340, pVBInfo ) ;
2843dfe64dd3Smacallan        if ( memsize == 0 )
2844dfe64dd3Smacallan            continue ;
2845dfe64dd3Smacallan
2846dfe64dd3Smacallan        addr = memsize + ( XGINew_ChannelAB - 2 ) + 20 ;
2847dfe64dd3Smacallan        if ( ( HwDeviceExtension->ulVideoMemorySize - 1 ) < ( ULONG )( 1 << addr ) )
2848dfe64dd3Smacallan            continue ;
2849dfe64dd3Smacallan
2850dfe64dd3Smacallan        if ( XGI45New_ReadWriteRest( addr , 9, pVBInfo ) == 1 )
2851dfe64dd3Smacallan            return( 1 ) ;
2852dfe64dd3Smacallan    }
2853dfe64dd3Smacallan    return( 0 ) ;
2854dfe64dd3Smacallan}
2855dfe64dd3Smacallan
2856dfe64dd3Smacallan
2857dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2858dfe64dd3Smacallan/* Function : XGINew_DDRSizing */
2859dfe64dd3Smacallan/* Input : */
2860dfe64dd3Smacallan/* Output : */
2861dfe64dd3Smacallan/* Description : */
2862dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2863dfe64dd3Smacallanint XGINew_DDRSizing(PVB_DEVICE_INFO pVBInfo)
2864dfe64dd3Smacallan{
2865dfe64dd3Smacallan    int    i ;
2866dfe64dd3Smacallan    UCHAR  j ;
2867dfe64dd3Smacallan
2868dfe64dd3Smacallan    for( i = 0 ; i < 4 ; i++ )
2869dfe64dd3Smacallan    {
2870dfe64dd3Smacallan        XGINew_SetDRAMSizingType( i , XGINew_DDRDRAM_TYPE, pVBInfo ) ;
2871dfe64dd3Smacallan        XGINew_DisableChannelInterleaving( i , XGINew_DDRDRAM_TYPE , pVBInfo) ;
2872dfe64dd3Smacallan        for( j = 2 ; j > 0 ; j-- )
2873dfe64dd3Smacallan        {
2874dfe64dd3Smacallan            XGINew_SetDDRChannel( i , j , XGINew_ChannelAB , XGINew_DDRDRAM_TYPE , pVBInfo ) ;
2875dfe64dd3Smacallan            if ( !XGINew_SetRank( i , ( UCHAR )j , XGINew_ChannelAB , XGINew_DDRDRAM_TYPE, pVBInfo ) )
2876dfe64dd3Smacallan                continue ;
2877dfe64dd3Smacallan            else
2878dfe64dd3Smacallan            {
2879dfe64dd3Smacallan                if ( XGINew_CheckDDRRanks( j , i , XGINew_DDRDRAM_TYPE,  pVBInfo ) )
2880dfe64dd3Smacallan                return( 1 ) ;
2881dfe64dd3Smacallan            }
2882dfe64dd3Smacallan        }
2883dfe64dd3Smacallan    }
2884dfe64dd3Smacallan    return( 0 ) ;
2885dfe64dd3Smacallan}
2886dfe64dd3Smacallan
2887dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2888dfe64dd3Smacallan/* Function : XGINew_SetMemoryClock */
2889dfe64dd3Smacallan/* Input : */
2890dfe64dd3Smacallan/* Output : */
2891dfe64dd3Smacallan/* Description : */
2892dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2893dfe64dd3Smacallanvoid XGINew_SetMemoryClock( PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo)
2894dfe64dd3Smacallan{
2895dfe64dd3Smacallan#ifndef LINUX_XF86
2896dfe64dd3Smacallan    UCHAR tempal ;
2897dfe64dd3Smacallan#endif
2898dfe64dd3Smacallan
2899dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x28 , pVBInfo->MCLKData[ XGINew_RAMType ].SR28 ) ;
2900dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x29 , pVBInfo->MCLKData[ XGINew_RAMType ].SR29 ) ;
2901dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x2A , pVBInfo->MCLKData[ XGINew_RAMType ].SR2A ) ;
2902dfe64dd3Smacallan
2903dfe64dd3Smacallan
2904dfe64dd3Smacallan
2905dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x2E , pVBInfo->ECLKData[ XGINew_RAMType ].SR2E ) ;
2906dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x2F , pVBInfo->ECLKData[ XGINew_RAMType ].SR2F ) ;
2907dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x30 , pVBInfo->ECLKData[ XGINew_RAMType ].SR30 ) ;
2908dfe64dd3Smacallan
2909dfe64dd3Smacallan    /* [Vicent] 2004/07/07, When XG42 ECLK = MCLK = 207MHz, Set SR32 D[1:0] = 10b */
2910dfe64dd3Smacallan    /* [Hsuan] 2004/08/20, Modify SR32 value, when MCLK=207MHZ, ELCK=250MHz, Set SR32 D[1:0] = 10b */
2911dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType == XG42 )
2912dfe64dd3Smacallan    {
2913dfe64dd3Smacallan      if ( ( pVBInfo->MCLKData[ XGINew_RAMType ].SR28 == 0x1C ) && ( pVBInfo->MCLKData[ XGINew_RAMType ].SR29 == 0x01 )
2914dfe64dd3Smacallan        && ( ( ( pVBInfo->ECLKData[ XGINew_RAMType ].SR2E == 0x1C ) && ( pVBInfo->ECLKData[ XGINew_RAMType ].SR2F == 0x01 ) )
2915dfe64dd3Smacallan        || ( ( pVBInfo->ECLKData[ XGINew_RAMType ].SR2E == 0x22 ) && ( pVBInfo->ECLKData[ XGINew_RAMType ].SR2F == 0x01 ) ) ) )
2916dfe64dd3Smacallan      {
2917dfe64dd3Smacallan      	XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x32 , ( ( UCHAR )XGI_GetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x32 ) & 0xFC ) | 0x02 ) ;
2918dfe64dd3Smacallan      }
2919dfe64dd3Smacallan    }
2920dfe64dd3Smacallan}
2921dfe64dd3Smacallan
2922dfe64dd3Smacallan
2923dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2924dfe64dd3Smacallan/* input : dx ,valid value : CR or second chip's CR */
2925dfe64dd3Smacallan/*  */
2926dfe64dd3Smacallan/* SetPowerConsume : */
2927dfe64dd3Smacallan/* Description: reduce 40/43 power consumption in first chip or */
2928dfe64dd3Smacallan/* in second chip, assume CR A1 D[6]="1" in this case */
2929dfe64dd3Smacallan/* output : none */
2930dfe64dd3Smacallan/* --------------------------------------------------------------------- */
2931dfe64dd3Smacallanvoid SetPowerConsume ( PXGI_HW_DEVICE_INFO HwDeviceExtension , USHORT XGI_P3d4Port )
2932dfe64dd3Smacallan{
2933dfe64dd3Smacallan    ULONG   lTemp ;
2934dfe64dd3Smacallan    UCHAR   bTemp;
2935dfe64dd3Smacallan
2936dfe64dd3Smacallan    HwDeviceExtension->pQueryVGAConfigSpace( HwDeviceExtension , 0x08 , 0 , &lTemp ) ; /* Get */
2937dfe64dd3Smacallan    if ((lTemp&0xFF)==0)
2938dfe64dd3Smacallan    {
2939dfe64dd3Smacallan        /* set CR58 D[5]=0 D[3]=0 */
2940dfe64dd3Smacallan        XGI_SetRegAND((XGIIOADDRESS) XGI_P3d4Port , 0x58 , 0xD7 ) ;
2941dfe64dd3Smacallan        bTemp = (UCHAR) XGI_GetReg((XGIIOADDRESS) XGI_P3d4Port , 0xCB ) ;
2942dfe64dd3Smacallan    	if (bTemp&0x20)
2943dfe64dd3Smacallan    	{
2944dfe64dd3Smacallan            if (!(bTemp&0x10))
2945dfe64dd3Smacallan            {
2946dfe64dd3Smacallan            	XGI_SetRegANDOR((XGIIOADDRESS) XGI_P3d4Port , 0x58 , 0xD7 , 0x20 ) ; /* CR58 D[5]=1 D[3]=0 */
2947dfe64dd3Smacallan            }
2948dfe64dd3Smacallan            else
2949dfe64dd3Smacallan            {
2950dfe64dd3Smacallan            	XGI_SetRegANDOR((XGIIOADDRESS) XGI_P3d4Port , 0x58 , 0xD7 , 0x08 ) ; /* CR58 D[5]=0 D[3]=1 */
2951dfe64dd3Smacallan            }
2952dfe64dd3Smacallan
2953dfe64dd3Smacallan    	}
2954dfe64dd3Smacallan
2955dfe64dd3Smacallan    }
2956dfe64dd3Smacallan}
2957dfe64dd3Smacallan
2958dfe64dd3Smacallan
2959dfe64dd3Smacallanvoid XGINew_InitVBIOSData(PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo)
2960dfe64dd3Smacallan{
2961dfe64dd3Smacallan
2962dfe64dd3Smacallan	/* ULONG ROMAddr = (ULONG)HwDeviceExtension->pjVirtualRomBase; */
2963dfe64dd3Smacallan    pVBInfo->ROMAddr = HwDeviceExtension->pjVirtualRomBase ;
2964dfe64dd3Smacallan    pVBInfo->FBAddr = HwDeviceExtension->pjVideoMemoryAddress ;
2965dfe64dd3Smacallan
2966dfe64dd3Smacallan    /* pVBInfo->BaseAddr = ( USHORT )HwDeviceExtension->pjIOAddress ; */
2967dfe64dd3Smacallan    pVBInfo->BaseAddr = ( ULONG )HwDeviceExtension->pjIOAddress ;
2968dfe64dd3Smacallan
2969dfe64dd3Smacallan    pVBInfo->RelIO = HwDeviceExtension->pjIOAddress - 0x30;
2970dfe64dd3Smacallan    pVBInfo->ISXPDOS = 0 ;
2971dfe64dd3Smacallan
2972dfe64dd3Smacallan    pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14 ;
2973dfe64dd3Smacallan    pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24 ;
2974dfe64dd3Smacallan    pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10 ;
2975dfe64dd3Smacallan
2976dfe64dd3Smacallan    pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1c ; /* Jong 07/31/2009 */
2977dfe64dd3Smacallan	PDEBUG(ErrorF("XGINew_InitVBIOSData()-pVBInfo->P3cc = %d\n", pVBInfo->P3cc));
2978dfe64dd3Smacallan
2979dfe64dd3Smacallan	pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e ;
2980dfe64dd3Smacallan    pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12 ;
2981dfe64dd3Smacallan    pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a ;
2982dfe64dd3Smacallan    pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16 ;
2983dfe64dd3Smacallan    pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17 ;
2984dfe64dd3Smacallan    pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18 ;
2985dfe64dd3Smacallan    pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19 ;
2986dfe64dd3Smacallan    pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A ;
2987dfe64dd3Smacallan    pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00 ;
2988dfe64dd3Smacallan    pVBInfo->Part1Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_04 ;
2989dfe64dd3Smacallan    pVBInfo->Part2Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_10 ;
2990dfe64dd3Smacallan    pVBInfo->Part3Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_12 ;
2991dfe64dd3Smacallan    pVBInfo->Part4Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 ;
2992dfe64dd3Smacallan    pVBInfo->Part5Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 + 2 ;
2993dfe64dd3Smacallan
2994dfe64dd3Smacallan    pVBInfo->IF_DEF_LCDA = 1 ;
2995dfe64dd3Smacallan    pVBInfo->IF_DEF_VideoCapture = 0 ;
2996dfe64dd3Smacallan    pVBInfo->IF_DEF_ScaleLCD = 0 ;
2997dfe64dd3Smacallan    pVBInfo->IF_DEF_OEMUtil = 0 ;
2998dfe64dd3Smacallan    pVBInfo->IF_DEF_PWD = 0 ;
2999dfe64dd3Smacallan
3000dfe64dd3Smacallan    if ( HwDeviceExtension->jChipType >= XG20 )			/* kuku 2004/06/25 */
3001dfe64dd3Smacallan    {
3002dfe64dd3Smacallan    	pVBInfo->IF_DEF_YPbPr = 0 ;
3003dfe64dd3Smacallan        pVBInfo->IF_DEF_HiVision = 0 ;
3004dfe64dd3Smacallan        pVBInfo->IF_DEF_CRT2Monitor = 0 ;
3005dfe64dd3Smacallan    }
3006dfe64dd3Smacallan    else if ( HwDeviceExtension->jChipType >= XG40 )
3007dfe64dd3Smacallan    {
3008dfe64dd3Smacallan        pVBInfo->IF_DEF_YPbPr = 1 ;
3009dfe64dd3Smacallan        pVBInfo->IF_DEF_HiVision = 1 ;
3010dfe64dd3Smacallan        pVBInfo->IF_DEF_CRT2Monitor = 1 ;
3011dfe64dd3Smacallan    }
3012dfe64dd3Smacallan    else
3013dfe64dd3Smacallan    {
3014dfe64dd3Smacallan        pVBInfo->IF_DEF_YPbPr = 1 ;
3015dfe64dd3Smacallan        pVBInfo->IF_DEF_HiVision = 1 ;
3016dfe64dd3Smacallan        pVBInfo->IF_DEF_CRT2Monitor = 0 ;
3017dfe64dd3Smacallan    }
3018dfe64dd3Smacallan
3019dfe64dd3Smacallan    if ( (HwDeviceExtension->jChipType != XG20) &&
3020dfe64dd3Smacallan		 (HwDeviceExtension->jChipType != XG21) &&
3021dfe64dd3Smacallan		 (HwDeviceExtension->jChipType != XG27)) {
3022dfe64dd3Smacallan		/* alan, disable VideoCapture */
3023dfe64dd3Smacallan		XGI_SetRegANDOR((XGIIOADDRESS) pVBInfo->Part0Port, 0x3F, 0xEF, 0x00);
3024dfe64dd3Smacallan    }
3025dfe64dd3Smacallan
3026dfe64dd3Smacallan    XGI_GetVBType( pVBInfo ) ;         /* Run XGI_GetVBType before InitTo330Pointer */
3027dfe64dd3Smacallan    InitTo330Pointer(HwDeviceExtension->jChipType,pVBInfo);
3028dfe64dd3Smacallan}
3029dfe64dd3Smacallan
3030dfe64dd3Smacallan
3031dfe64dd3Smacallan/* --------------------------------------------------------------------- */
3032dfe64dd3Smacallan/* Function : ReadVBIOSTablData */
3033dfe64dd3Smacallan/* Input : */
3034dfe64dd3Smacallan/* Output : */
3035dfe64dd3Smacallan/* Description : */
3036dfe64dd3Smacallan/* --------------------------------------------------------------------- */
3037dfe64dd3Smacallanvoid ReadVBIOSTablData( UCHAR ChipType , PVB_DEVICE_INFO pVBInfo)
3038dfe64dd3Smacallan{
3039dfe64dd3Smacallan#ifndef LINUX_XF86
3040dfe64dd3Smacallan    ULONG   ulOffset ;
3041dfe64dd3Smacallan    UCHAR   temp , index , l ;
3042dfe64dd3Smacallan#endif
3043dfe64dd3Smacallan    PUCHAR  volatile pVideoMemory = ( PUCHAR )pVBInfo->ROMAddr ;
3044dfe64dd3Smacallan    ULONG   i ;
3045dfe64dd3Smacallan    UCHAR   j , k ;
3046dfe64dd3Smacallan    ULONG   ii , jj ;
3047dfe64dd3Smacallan
3048dfe64dd3Smacallan	/* Jong@08212009; no valid address of VBIOS ROM */
3049dfe64dd3Smacallan	if(pVideoMemory == NULL)
3050dfe64dd3Smacallan	{
3051dfe64dd3Smacallan		ErrorF("XGI - No valid address of VBIOS ROM!\n");
3052dfe64dd3Smacallan		return;
3053dfe64dd3Smacallan	}
3054dfe64dd3Smacallan	else
3055dfe64dd3Smacallan		ErrorF("XGI - Read data from VBIOS ROM...\n");
3056dfe64dd3Smacallan
3057dfe64dd3Smacallan    i = pVideoMemory[ 0x1CF ] | ( pVideoMemory[ 0x1D0 ] << 8 ) ;		/* UniROM */
3058dfe64dd3Smacallan    if ( i != 0 )
3059dfe64dd3Smacallan        UNIROM = 1 ;
3060dfe64dd3Smacallan
3061dfe64dd3Smacallan    ii = 0x90 ;
3062dfe64dd3Smacallan    for( jj = 0x00 ; jj < 0x08 ; jj++ )
3063dfe64dd3Smacallan    {
3064dfe64dd3Smacallan        pVBInfo->MCLKData[ jj ].SR28 = pVideoMemory[ ii ] ;
3065dfe64dd3Smacallan        pVBInfo->MCLKData[ jj ].SR29 = pVideoMemory[ ii + 1] ;
3066dfe64dd3Smacallan        pVBInfo->MCLKData[ jj ].SR2A = pVideoMemory[ ii + 2] ;
3067dfe64dd3Smacallan        pVBInfo->MCLKData[ jj ].CLOCK = pVideoMemory[ ii + 3 ] | ( pVideoMemory[ ii + 4 ] << 8 ) ;
3068dfe64dd3Smacallan        ii += 0x05 ;
3069dfe64dd3Smacallan    }
3070dfe64dd3Smacallan
3071dfe64dd3Smacallan    ii = 0xB8 ;
3072dfe64dd3Smacallan    for( jj = 0x00 ; jj < 0x08 ; jj++ )
3073dfe64dd3Smacallan    {
3074dfe64dd3Smacallan        pVBInfo->ECLKData[ jj ].SR2E = pVideoMemory[ ii ] ;
3075dfe64dd3Smacallan        pVBInfo->ECLKData[ jj ].SR2F=pVideoMemory[ ii + 1 ] ;
3076dfe64dd3Smacallan        pVBInfo->ECLKData[ jj ].SR30= pVideoMemory[ ii + 2 ] ;
3077dfe64dd3Smacallan        pVBInfo->ECLKData[ jj ].CLOCK= pVideoMemory[ ii + 3 ] | ( pVideoMemory[ ii + 4 ] << 8 ) ;
3078dfe64dd3Smacallan        ii += 0x05 ;
3079dfe64dd3Smacallan    }
3080dfe64dd3Smacallan
3081dfe64dd3Smacallan    /* Volari customize data area start */
3082dfe64dd3Smacallan    /* if ( ChipType == XG40 ) */
3083dfe64dd3Smacallan    if ( ChipType >= XG40 )
3084dfe64dd3Smacallan    {
3085dfe64dd3Smacallan        ii = 0xE0 ;
3086dfe64dd3Smacallan        for( jj = 0x00 ; jj < 0x03 ; jj++ )
3087dfe64dd3Smacallan        {
3088dfe64dd3Smacallan            pVBInfo->SR15[ jj ][ 0 ] = pVideoMemory[ ii ] ;		/* SR13, SR14, and SR18 */
3089dfe64dd3Smacallan            pVBInfo->SR15[ jj ][ 1 ] = pVideoMemory[ ii + 1 ] ;
3090dfe64dd3Smacallan            pVBInfo->SR15[ jj ][ 2 ] = pVideoMemory[ ii + 2 ] ;
3091dfe64dd3Smacallan            pVBInfo->SR15[ jj ][ 3 ] = pVideoMemory[ ii + 3 ] ;
3092dfe64dd3Smacallan            pVBInfo->SR15[ jj ][ 4 ] = pVideoMemory[ ii + 4 ] ;
3093dfe64dd3Smacallan            pVBInfo->SR15[ jj ][ 5 ] = pVideoMemory[ ii + 5 ] ;
3094dfe64dd3Smacallan            pVBInfo->SR15[ jj ][ 6 ] = pVideoMemory[ ii + 6 ] ;
3095dfe64dd3Smacallan            pVBInfo->SR15[ jj ][ 7 ] = pVideoMemory[ ii + 7 ] ;
3096dfe64dd3Smacallan            ii += 0x08 ;
3097dfe64dd3Smacallan        }
3098dfe64dd3Smacallan        ii = 0x110 ;
3099dfe64dd3Smacallan        jj = 0x03 ;
3100dfe64dd3Smacallan        pVBInfo->SR15[ jj ][ 0 ] = pVideoMemory[ ii ] ;		/* SR1B */
3101dfe64dd3Smacallan        pVBInfo->SR15[ jj ][ 1 ] = pVideoMemory[ ii + 1 ] ;
3102dfe64dd3Smacallan        pVBInfo->SR15[ jj ][ 2 ] = pVideoMemory[ ii + 2 ] ;
3103dfe64dd3Smacallan        pVBInfo->SR15[ jj ][ 3 ] = pVideoMemory[ ii + 3 ] ;
3104dfe64dd3Smacallan        pVBInfo->SR15[ jj ][ 4 ] = pVideoMemory[ ii + 4 ] ;
3105dfe64dd3Smacallan        pVBInfo->SR15[ jj ][ 5 ] = pVideoMemory[ ii + 5 ] ;
3106dfe64dd3Smacallan        pVBInfo->SR15[ jj ][ 6 ] = pVideoMemory[ ii + 6 ] ;
3107dfe64dd3Smacallan        pVBInfo->SR15[ jj ][ 7 ] = pVideoMemory[ ii + 7 ] ;
3108dfe64dd3Smacallan
3109dfe64dd3Smacallan        pVBInfo->SR07 = pVideoMemory[0x74];
3110dfe64dd3Smacallan        pVBInfo->SR1F = pVideoMemory[0x75];
3111dfe64dd3Smacallan        pVBInfo->SR21 = pVideoMemory[0x76];
3112dfe64dd3Smacallan        pVBInfo->SR22 = pVideoMemory[0x77];
3113dfe64dd3Smacallan        pVBInfo->SR23 = pVideoMemory[0x78];
3114dfe64dd3Smacallan        pVBInfo->SR24 = pVideoMemory[0x79];
3115dfe64dd3Smacallan        pVBInfo->SR25[0] = pVideoMemory[0x7A];
3116dfe64dd3Smacallan        pVBInfo->SR31 = pVideoMemory[0x7B];
3117dfe64dd3Smacallan        pVBInfo->SR32 = pVideoMemory[0x7C];
3118dfe64dd3Smacallan        pVBInfo->SR33 = pVideoMemory[0x7D];
3119dfe64dd3Smacallan        ii = 0xF8 ;
3120dfe64dd3Smacallan
3121dfe64dd3Smacallan        for( jj = 0 ; jj < 3 ; jj++ )
3122dfe64dd3Smacallan        {
3123dfe64dd3Smacallan            pVBInfo->CR40[ jj ][ 0 ] = pVideoMemory[ ii ] ;
3124dfe64dd3Smacallan            pVBInfo->CR40[ jj ][ 1 ] = pVideoMemory[ ii + 1 ] ;
3125dfe64dd3Smacallan            pVBInfo->CR40[ jj ][ 2 ] = pVideoMemory[ ii + 2 ] ;
3126dfe64dd3Smacallan            pVBInfo->CR40[ jj ][ 3 ] = pVideoMemory[ ii + 3 ] ;
3127dfe64dd3Smacallan            pVBInfo->CR40[ jj ][ 4 ] = pVideoMemory[ ii + 4 ] ;
3128dfe64dd3Smacallan            pVBInfo->CR40[ jj ][ 5 ] = pVideoMemory[ ii + 5 ] ;
3129dfe64dd3Smacallan            pVBInfo->CR40[ jj ][ 6 ] = pVideoMemory[ ii + 6 ] ;
3130dfe64dd3Smacallan            pVBInfo->CR40[ jj ][ 7 ] = pVideoMemory[ ii + 7 ] ;
3131dfe64dd3Smacallan            ii += 0x08 ;
3132dfe64dd3Smacallan        }
3133dfe64dd3Smacallan
3134dfe64dd3Smacallan        ii = 0x118 ;
3135dfe64dd3Smacallan        for( j = 3 ; j < 24 ; j++ )
3136dfe64dd3Smacallan        {
3137dfe64dd3Smacallan            pVBInfo->CR40[ j ][ 0 ] = pVideoMemory[ ii ] ;
3138dfe64dd3Smacallan            pVBInfo->CR40[ j ][ 1 ] = pVideoMemory[ ii + 1 ] ;
3139dfe64dd3Smacallan            pVBInfo->CR40[ j ][ 2 ] = pVideoMemory[ ii + 2 ] ;
3140dfe64dd3Smacallan            pVBInfo->CR40[ j ][ 3 ] = pVideoMemory[ ii + 3 ] ;
3141dfe64dd3Smacallan            pVBInfo->CR40[ j ][ 4 ] = pVideoMemory[ ii + 4 ] ;
3142dfe64dd3Smacallan            pVBInfo->CR40[ j ][ 5 ] = pVideoMemory[ ii + 5 ] ;
3143dfe64dd3Smacallan            pVBInfo->CR40[ j ][ 6 ] = pVideoMemory[ ii + 6 ] ;
3144dfe64dd3Smacallan            pVBInfo->CR40[ j ][ 7 ] = pVideoMemory[ ii + 7 ] ;
3145dfe64dd3Smacallan            ii += 0x08 ;
3146dfe64dd3Smacallan        }
3147dfe64dd3Smacallan
3148dfe64dd3Smacallan        i = pVideoMemory[ 0x1C0 ] | ( pVideoMemory[ 0x1C1 ] << 8 ) ;
3149dfe64dd3Smacallan
3150dfe64dd3Smacallan        for( j = 0 ; j < 8 ; j++ )
3151dfe64dd3Smacallan        {
3152dfe64dd3Smacallan            for( k = 0 ; k < 4 ; k++ )
3153dfe64dd3Smacallan                pVBInfo->CR6B[ j ][ k ] = pVideoMemory[ i + 4 * j + k ] ;
3154dfe64dd3Smacallan        }
3155dfe64dd3Smacallan
3156dfe64dd3Smacallan        i = pVideoMemory[ 0x1C2 ] | ( pVideoMemory[ 0x1C3 ] << 8 ) ;
3157dfe64dd3Smacallan
3158dfe64dd3Smacallan        if (ChipType == XG45)
3159dfe64dd3Smacallan        {
3160dfe64dd3Smacallan        for( j = 0 ; j < 8 ; j++ )
3161dfe64dd3Smacallan        {
3162dfe64dd3Smacallan            pVBInfo->XG45CR6E[ j ] = pVideoMemory[i] ;
3163dfe64dd3Smacallan        }
3164dfe64dd3Smacallan        }
3165dfe64dd3Smacallan        else
3166dfe64dd3Smacallan        {
3167dfe64dd3Smacallan        for( j = 0 ; j < 8 ; j++ )
3168dfe64dd3Smacallan        {
3169dfe64dd3Smacallan            for( k = 0 ; k < 4 ; k++ )
3170dfe64dd3Smacallan                pVBInfo->CR6E[ j ][ k ] = pVideoMemory[ i + 4 * j + k ] ;
3171dfe64dd3Smacallan        }
3172dfe64dd3Smacallan	}
3173dfe64dd3Smacallan
3174dfe64dd3Smacallan        i = pVideoMemory[ 0x1C4 ] | ( pVideoMemory[ 0x1C5 ] << 8 ) ;
3175dfe64dd3Smacallan        if (ChipType == XG45)
3176dfe64dd3Smacallan        {
3177dfe64dd3Smacallan        for( j = 0 ; j < 8 ; j++ )
3178dfe64dd3Smacallan        {
3179dfe64dd3Smacallan            pVBInfo->XG45CR6F[ j ] = pVideoMemory[i] ;
3180dfe64dd3Smacallan        }
3181dfe64dd3Smacallan	}
3182dfe64dd3Smacallan	else
3183dfe64dd3Smacallan	{
3184dfe64dd3Smacallan        for( j = 0 ; j < 8 ; j++ )
3185dfe64dd3Smacallan        {
3186dfe64dd3Smacallan            for( k = 0 ; k < 32 ; k++ )
3187dfe64dd3Smacallan                pVBInfo->CR6F[ j ][ k ] = pVideoMemory[ i + 32 * j + k ] ;
3188dfe64dd3Smacallan        }
3189dfe64dd3Smacallan        }
3190dfe64dd3Smacallan
3191dfe64dd3Smacallan        i = pVideoMemory[ 0x1C6 ] | ( pVideoMemory[ 0x1C7 ] << 8 ) ;
3192dfe64dd3Smacallan
3193dfe64dd3Smacallan        for( j = 0 ; j < 8 ; j++ )
3194dfe64dd3Smacallan        {
3195dfe64dd3Smacallan            for( k = 0 ; k < 2 ; k++ )
3196dfe64dd3Smacallan                pVBInfo->CR89[ j ][ k ] = pVideoMemory[ i + 2 * j + k ] ;
3197dfe64dd3Smacallan        }
3198dfe64dd3Smacallan
3199dfe64dd3Smacallan        i = pVideoMemory[ 0x1C8 ] | ( pVideoMemory[ 0x1C9 ] << 8 ) ;
3200dfe64dd3Smacallan        for( j = 0 ; j < 12 ; j++ )
3201dfe64dd3Smacallan            pVBInfo->AGPReg[ j ] = pVideoMemory[ i + j ] ;
3202dfe64dd3Smacallan
3203dfe64dd3Smacallan        i = pVideoMemory[ 0x1CF ] | ( pVideoMemory[ 0x1D0 ] << 8 ) ;
3204dfe64dd3Smacallan        for( j = 0 ; j < 4 ; j++ )
3205dfe64dd3Smacallan            pVBInfo->SR16[ j ] = pVideoMemory[ i + j ] ;
3206dfe64dd3Smacallan
3207dfe64dd3Smacallan        /* Jong 10/03/2007 */
3208dfe64dd3Smacallan        /*
3209dfe64dd3Smacallan        pVBInfo->CRCF = pVideoMemory[0x1CA];
3210dfe64dd3Smacallan        pVBInfo->DRAMTypeDefinition = pVideoMemory[0x1CB];
3211dfe64dd3Smacallan        pVBInfo->I2CDefinition = pVideoMemory[0x1D1];
3212dfe64dd3Smacallan        if ( ChipType == XG20 )
3213dfe64dd3Smacallan           pVBInfo->CR97 = pVideoMemory[0x1D2]; */
3214dfe64dd3Smacallan        if ( ChipType == XG21 )
3215dfe64dd3Smacallan        {
3216dfe64dd3Smacallan            if (pVideoMemory[ 0x67 ] & 0x80)
3217dfe64dd3Smacallan            {
3218dfe64dd3Smacallan                *pVBInfo->pDVOSetting = pVideoMemory[ 0x67 ];
3219dfe64dd3Smacallan            }
3220dfe64dd3Smacallan            if ( (pVideoMemory[ 0x67 ] & 0xC0) == 0xC0 )
3221dfe64dd3Smacallan            {
3222dfe64dd3Smacallan                *pVBInfo->pCR2E = pVideoMemory[ i + 4 ] ;
3223dfe64dd3Smacallan                *pVBInfo->pCR2F = pVideoMemory[ i + 5 ] ;
3224dfe64dd3Smacallan                *pVBInfo->pCR46 = pVideoMemory[ i + 6 ] ;
3225dfe64dd3Smacallan                *pVBInfo->pCR47 = pVideoMemory[ i + 7 ] ;
3226dfe64dd3Smacallan            }
3227dfe64dd3Smacallan        }
3228dfe64dd3Smacallan
3229dfe64dd3Smacallan        if ( ChipType == XG27 )
3230dfe64dd3Smacallan        {
3231dfe64dd3Smacallan            jj = i+j;
3232dfe64dd3Smacallan            for( i = 0 ; i <= 0xB ; i++,jj++ )
3233dfe64dd3Smacallan              pVBInfo->pCRD0[i] = pVideoMemory[ jj ] ;
3234dfe64dd3Smacallan            for( i = 0x0 ; i <= 0x1 ; i++,jj++ )
3235dfe64dd3Smacallan              pVBInfo->pCRDE[i] = pVideoMemory[ jj ] ;
3236dfe64dd3Smacallan
3237dfe64dd3Smacallan            *pVBInfo->pSR40 = pVideoMemory[ jj ] ;
3238dfe64dd3Smacallan            jj++;
3239dfe64dd3Smacallan            *pVBInfo->pSR41 = pVideoMemory[ jj ] ;
3240dfe64dd3Smacallan
3241dfe64dd3Smacallan            if (pVideoMemory[ 0x67 ] & 0x80)
3242dfe64dd3Smacallan            {
3243dfe64dd3Smacallan                *pVBInfo->pDVOSetting = pVideoMemory[ 0x67 ];
3244dfe64dd3Smacallan            }
3245dfe64dd3Smacallan            if ( (pVideoMemory[ 0x67 ] & 0xC0) == 0xC0 )
3246dfe64dd3Smacallan            {
3247dfe64dd3Smacallan                jj++;
3248dfe64dd3Smacallan                *pVBInfo->pCR2E = pVideoMemory[ jj ] ;
3249dfe64dd3Smacallan                *pVBInfo->pCR2F = pVideoMemory[ jj + 1 ] ;
3250dfe64dd3Smacallan                *pVBInfo->pCR46 = pVideoMemory[ jj + 2 ] ;
3251dfe64dd3Smacallan                *pVBInfo->pCR47 = pVideoMemory[ jj + 3 ] ;
3252dfe64dd3Smacallan            }
3253dfe64dd3Smacallan
3254dfe64dd3Smacallan        }
3255dfe64dd3Smacallan
3256dfe64dd3Smacallan        pVBInfo->CRCF = pVideoMemory[ 0x1CA ] ;
3257dfe64dd3Smacallan        pVBInfo->DRAMTypeDefinition = pVideoMemory[ 0x1CB ] ;
3258dfe64dd3Smacallan        pVBInfo->I2CDefinition = pVideoMemory[ 0x1D1 ] ;
3259dfe64dd3Smacallan        if ( ChipType >= XG20 )
3260dfe64dd3Smacallan        {
3261dfe64dd3Smacallan           pVBInfo->CR97 = pVideoMemory[ 0x1D2 ] ;
3262dfe64dd3Smacallan           if ( ChipType == XG27 )
3263dfe64dd3Smacallan           {
3264dfe64dd3Smacallan             *pVBInfo->pSR36 = pVideoMemory[ 0x1D3 ] ;
3265dfe64dd3Smacallan             *pVBInfo->pCR8F = pVideoMemory[ 0x1D5 ] ;
3266dfe64dd3Smacallan           }
3267dfe64dd3Smacallan        }
3268dfe64dd3Smacallan    }
3269dfe64dd3Smacallan    /* Volari customize data area end */
3270dfe64dd3Smacallan
3271dfe64dd3Smacallan    if ( ChipType == XG21 )
3272dfe64dd3Smacallan    {
3273dfe64dd3Smacallan        pVBInfo->IF_DEF_LVDS = 0 ;
3274dfe64dd3Smacallan        if (pVideoMemory[ 0x65 ] & 0x1)
3275dfe64dd3Smacallan        {
3276dfe64dd3Smacallan            pVBInfo->IF_DEF_LVDS = 1 ;
3277dfe64dd3Smacallan            i = pVideoMemory[ 0x316 ] | ( pVideoMemory[ 0x317 ] << 8 );
3278dfe64dd3Smacallan            j = pVideoMemory[ i-1 ] ;
3279dfe64dd3Smacallan            if ( j != 0xff )
3280dfe64dd3Smacallan            {
3281dfe64dd3Smacallan              k = 0;
3282dfe64dd3Smacallan              do
3283dfe64dd3Smacallan              {
3284dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDS_Capability = pVideoMemory[ i ] | ( pVideoMemory[ i + 1 ] << 8 );
3285dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDSHT = pVideoMemory[ i + 2 ] | ( pVideoMemory[ i + 3 ] << 8 ) ;
3286dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDSVT = pVideoMemory[ i + 4 ] | ( pVideoMemory[ i + 5 ] << 8 );
3287dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDSHDE = pVideoMemory[ i + 6 ] | ( pVideoMemory[ i + 7 ] << 8 );
3288dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDSVDE = pVideoMemory[ i + 8 ] | ( pVideoMemory[ i + 9 ] << 8 );
3289dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDSHFP = pVideoMemory[ i + 10 ] | ( pVideoMemory[ i + 11 ] << 8 );
3290dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDSVFP = pVideoMemory[ i + 12 ] | ( pVideoMemory[ i + 13 ] << 8 );
3291dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDSHSYNC = pVideoMemory[ i + 14 ] | ( pVideoMemory[ i + 15 ] << 8 );
3292dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDSVSYNC = pVideoMemory[ i + 16 ] | ( pVideoMemory[ i + 17 ] << 8 );
3293dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].VCLKData1 = pVideoMemory[ i + 18 ] ;
3294dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].VCLKData2 = pVideoMemory[ i + 19 ] ;
3295dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].PSC_S1 = pVideoMemory[ i + 20 ] ;
3296dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].PSC_S2 = pVideoMemory[ i + 21 ] ;
3297dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].PSC_S3 = pVideoMemory[ i + 22 ] ;
3298dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].PSC_S4 = pVideoMemory[ i + 23 ] ;
3299dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].PSC_S5 = pVideoMemory[ i + 24 ] ;
3300dfe64dd3Smacallan                i += 25;
3301dfe64dd3Smacallan                j--;
3302dfe64dd3Smacallan                k++;
3303dfe64dd3Smacallan              } while ( (j>0) && ( k < (sizeof(XGI21_LCDCapList)/sizeof(XGI21_LVDSCapStruct)) ) );
3304dfe64dd3Smacallan            }
3305dfe64dd3Smacallan            else
3306dfe64dd3Smacallan            {
3307dfe64dd3Smacallan            pVBInfo->XG21_LVDSCapList[0].LVDS_Capability = pVideoMemory[ i ] | ( pVideoMemory[ i + 1 ] << 8 );
3308dfe64dd3Smacallan            pVBInfo->XG21_LVDSCapList[0].LVDSHT = pVideoMemory[ i + 2 ] | ( pVideoMemory[ i + 3 ] << 8 ) ;
3309dfe64dd3Smacallan            pVBInfo->XG21_LVDSCapList[0].LVDSVT = pVideoMemory[ i + 4 ] | ( pVideoMemory[ i + 5 ] << 8 );
3310dfe64dd3Smacallan            pVBInfo->XG21_LVDSCapList[0].LVDSHDE = pVideoMemory[ i + 6 ] | ( pVideoMemory[ i + 7 ] << 8 );
3311dfe64dd3Smacallan            pVBInfo->XG21_LVDSCapList[0].LVDSVDE = pVideoMemory[ i + 8 ] | ( pVideoMemory[ i + 9 ] << 8 );
3312dfe64dd3Smacallan            pVBInfo->XG21_LVDSCapList[0].LVDSHFP = pVideoMemory[ i + 10 ] | ( pVideoMemory[ i + 11 ] << 8 );
3313dfe64dd3Smacallan            pVBInfo->XG21_LVDSCapList[0].LVDSVFP = pVideoMemory[ i + 12 ] | ( pVideoMemory[ i + 13 ] << 8 );
3314dfe64dd3Smacallan            pVBInfo->XG21_LVDSCapList[0].LVDSHSYNC = pVideoMemory[ i + 14 ] | ( pVideoMemory[ i + 15 ] << 8 );
3315dfe64dd3Smacallan            pVBInfo->XG21_LVDSCapList[0].LVDSVSYNC = pVideoMemory[ i + 16 ] | ( pVideoMemory[ i + 17 ] << 8 );
3316dfe64dd3Smacallan            pVBInfo->XG21_LVDSCapList[0].VCLKData1 = pVideoMemory[ i + 18 ] ;
3317dfe64dd3Smacallan            pVBInfo->XG21_LVDSCapList[0].VCLKData2 = pVideoMemory[ i + 19 ] ;
3318dfe64dd3Smacallan            pVBInfo->XG21_LVDSCapList[0].PSC_S1 = pVideoMemory[ i + 20 ] ;
3319dfe64dd3Smacallan            pVBInfo->XG21_LVDSCapList[0].PSC_S2 = pVideoMemory[ i + 21 ] ;
3320dfe64dd3Smacallan            pVBInfo->XG21_LVDSCapList[0].PSC_S3 = pVideoMemory[ i + 22 ] ;
3321dfe64dd3Smacallan            pVBInfo->XG21_LVDSCapList[0].PSC_S4 = pVideoMemory[ i + 23 ] ;
3322dfe64dd3Smacallan            pVBInfo->XG21_LVDSCapList[0].PSC_S5 = pVideoMemory[ i + 24 ] ;
3323dfe64dd3Smacallan        }
3324dfe64dd3Smacallan        }
3325dfe64dd3Smacallan        pVBInfo->IF_DEF_CH7007 = 0 ;
3326dfe64dd3Smacallan        if ( ( pVideoMemory[ 0x65 ] & 0x02 ) )			/* For XG21 CH7007 */
3327dfe64dd3Smacallan        {
3328dfe64dd3Smacallan            /* VideoDebugPrint((0, "ReadVBIOSTablData: pVideoMemory[ 0x65 ] =%x\n",pVideoMemory[ 0x65 ])); */
3329dfe64dd3Smacallan            pVBInfo->IF_DEF_CH7007 = 1 ;                            /* [Billy] 07/05/03 */
3330dfe64dd3Smacallan        }
3331dfe64dd3Smacallan    }
3332dfe64dd3Smacallan
3333dfe64dd3Smacallan    if ( ChipType == XG27 )
3334dfe64dd3Smacallan    {
3335dfe64dd3Smacallan        if (pVideoMemory[ 0x65 ] & 0x1)
3336dfe64dd3Smacallan        {
3337dfe64dd3Smacallan            i = pVideoMemory[ 0x316 ] | ( pVideoMemory[ 0x317 ] << 8 );
3338dfe64dd3Smacallan            j = pVideoMemory[ i-1 ] ;
3339dfe64dd3Smacallan            if ( j != 0xff )
3340dfe64dd3Smacallan            {
3341dfe64dd3Smacallan              k = 0;
3342dfe64dd3Smacallan              do
3343dfe64dd3Smacallan              {
3344dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDS_Capability = pVideoMemory[ i ] | ( pVideoMemory[ i + 1 ] << 8 );
3345dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDSHT = pVideoMemory[ i + 2 ] | ( pVideoMemory[ i + 3 ] << 8 ) ;
3346dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDSVT = pVideoMemory[ i + 4 ] | ( pVideoMemory[ i + 5 ] << 8 );
3347dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDSHDE = pVideoMemory[ i + 6 ] | ( pVideoMemory[ i + 7 ] << 8 );
3348dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDSVDE = pVideoMemory[ i + 8 ] | ( pVideoMemory[ i + 9 ] << 8 );
3349dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDSHFP = pVideoMemory[ i + 10 ] | ( pVideoMemory[ i + 11 ] << 8 );
3350dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDSVFP = pVideoMemory[ i + 12 ] | ( pVideoMemory[ i + 13 ] << 8 );
3351dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDSHSYNC = pVideoMemory[ i + 14 ] | ( pVideoMemory[ i + 15 ] << 8 );
3352dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].LVDSVSYNC = pVideoMemory[ i + 16 ] | ( pVideoMemory[ i + 17 ] << 8 );
3353dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].VCLKData1 = pVideoMemory[ i + 18 ] ;
3354dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].VCLKData2 = pVideoMemory[ i + 19 ] ;
3355dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].PSC_S1 = pVideoMemory[ i + 20 ] ;
3356dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].PSC_S2 = pVideoMemory[ i + 21 ] ;
3357dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].PSC_S3 = pVideoMemory[ i + 22 ] ;
3358dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].PSC_S4 = pVideoMemory[ i + 23 ] ;
3359dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[k].PSC_S5 = pVideoMemory[ i + 24 ] ;
3360dfe64dd3Smacallan                i += 25;
3361dfe64dd3Smacallan                j--;
3362dfe64dd3Smacallan                k++;
3363dfe64dd3Smacallan              } while ( (j>0) && ( k < (sizeof(XGI21_LCDCapList)/sizeof(XGI21_LVDSCapStruct)) ) );
3364dfe64dd3Smacallan            }
3365dfe64dd3Smacallan            else
3366dfe64dd3Smacallan            {
3367dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[0].LVDS_Capability = pVideoMemory[ i ] | ( pVideoMemory[ i + 1 ] << 8 );
3368dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[0].LVDSHT = pVideoMemory[ i + 2 ] | ( pVideoMemory[ i + 3 ] << 8 ) ;
3369dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[0].LVDSVT = pVideoMemory[ i + 4 ] | ( pVideoMemory[ i + 5 ] << 8 );
3370dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[0].LVDSHDE = pVideoMemory[ i + 6 ] | ( pVideoMemory[ i + 7 ] << 8 );
3371dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[0].LVDSVDE = pVideoMemory[ i + 8 ] | ( pVideoMemory[ i + 9 ] << 8 );
3372dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[0].LVDSHFP = pVideoMemory[ i + 10 ] | ( pVideoMemory[ i + 11 ] << 8 );
3373dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[0].LVDSVFP = pVideoMemory[ i + 12 ] | ( pVideoMemory[ i + 13 ] << 8 );
3374dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[0].LVDSHSYNC = pVideoMemory[ i + 14 ] | ( pVideoMemory[ i + 15 ] << 8 );
3375dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[0].LVDSVSYNC = pVideoMemory[ i + 16 ] | ( pVideoMemory[ i + 17 ] << 8 );
3376dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[0].VCLKData1 = pVideoMemory[ i + 18 ] ;
3377dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[0].VCLKData2 = pVideoMemory[ i + 19 ] ;
3378dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[0].PSC_S1 = pVideoMemory[ i + 20 ] ;
3379dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[0].PSC_S2 = pVideoMemory[ i + 21 ] ;
3380dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[0].PSC_S3 = pVideoMemory[ i + 22 ] ;
3381dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[0].PSC_S4 = pVideoMemory[ i + 23 ] ;
3382dfe64dd3Smacallan                pVBInfo->XG21_LVDSCapList[0].PSC_S5 = pVideoMemory[ i + 24 ] ;
3383dfe64dd3Smacallan            }
3384dfe64dd3Smacallan        }
3385dfe64dd3Smacallan    }
3386dfe64dd3Smacallan
3387dfe64dd3Smacallan	ErrorF("XGI - Read data from VBIOS ROM...End\n");
3388dfe64dd3Smacallan}
3389dfe64dd3Smacallan
3390dfe64dd3Smacallan/* --------------------------------------------------------------------- */
3391dfe64dd3Smacallan/* Function : XGINew_DDR1x_MRS_XG20 */
3392dfe64dd3Smacallan/* Input : */
3393dfe64dd3Smacallan/* Output : */
3394dfe64dd3Smacallan/* Description : */
3395dfe64dd3Smacallan/* --------------------------------------------------------------------- */
3396dfe64dd3Smacallanvoid XGINew_DDR1x_MRS_XG20( USHORT P3c4 , PVB_DEVICE_INFO pVBInfo)
3397dfe64dd3Smacallan{
3398dfe64dd3Smacallan
3399dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , 0x01 ) ;
3400dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x40 ) ;
3401dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;
3402dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x80 ) ;
3403dfe64dd3Smacallan    DelayUS( 60 ) ;
3404dfe64dd3Smacallan
3405dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , 0x00 ) ;
3406dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x40 ) ;
3407dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x00 ) ;
3408dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x80 ) ;
3409dfe64dd3Smacallan    DelayUS( 60 ) ;
3410dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , pVBInfo->SR15[ 2 ][ XGINew_RAMType ] ) ;	/* SR18 */
3411dfe64dd3Smacallan    /* XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , 0x31 ) ; */
3412dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x01 ) ;
3413dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x03 ) ;
3414dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x83 ) ;
3415dfe64dd3Smacallan    DelayUS( 1000 ) ;
3416dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x1B , 0x03 ) ;
3417dfe64dd3Smacallan    DelayUS( 500 ) ;
3418dfe64dd3Smacallan    /* XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , 0x31 ) ; */
3419dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x18 , pVBInfo->SR15[ 2 ][ XGINew_RAMType ] ) ;	/* SR18 */
3420dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x19 , 0x00 ) ;
3421dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x03 ) ;
3422dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x16 , 0x83 ) ;
3423dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) P3c4 , 0x1B , 0x00 ) ;
3424dfe64dd3Smacallan}
3425dfe64dd3Smacallan
3426dfe64dd3Smacallan/* --------------------------------------------------------------------- */
3427dfe64dd3Smacallan/* Function : XGINew_SetDRAMModeRegister_XG20 */
3428dfe64dd3Smacallan/* Input : */
3429dfe64dd3Smacallan/* Output : */
3430dfe64dd3Smacallan/* Description : */
3431dfe64dd3Smacallan/* --------------------------------------------------------------------- */
3432dfe64dd3Smacallanvoid XGINew_SetDRAMModeRegister_XG20(PXGI_HW_DEVICE_INFO HwDeviceExtension,
3433dfe64dd3Smacallan				     PVB_DEVICE_INFO pVBInfo)
3434dfe64dd3Smacallan{
3435dfe64dd3Smacallan#ifndef LINUX_XF86
3436dfe64dd3Smacallan    UCHAR data ;
3437dfe64dd3Smacallan#endif
3438dfe64dd3Smacallan
3439dfe64dd3Smacallan    ReadVBIOSTablData( HwDeviceExtension->jChipType , pVBInfo) ;
3440dfe64dd3Smacallan
3441dfe64dd3Smacallan    if ( XGINew_Get340DRAMType( HwDeviceExtension, pVBInfo) == 0 )
3442dfe64dd3Smacallan        XGINew_DDR1x_MRS_XG20( pVBInfo->P3c4, pVBInfo ) ;
3443dfe64dd3Smacallan    else
3444dfe64dd3Smacallan        XGINew_DDR2x_MRS_340( HwDeviceExtension,  pVBInfo->P3c4, pVBInfo ) ;
3445dfe64dd3Smacallan
3446dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3c4 , 0x1B , 0x03 ) ;
3447dfe64dd3Smacallan}
3448dfe64dd3Smacallan
3449dfe64dd3Smacallanvoid XGINew_SetDRAMModeRegister_XG27( PXGI_HW_DEVICE_INFO HwDeviceExtension )
3450dfe64dd3Smacallan{
3451dfe64dd3Smacallan#ifndef LINUX_XF86
3452dfe64dd3Smacallan    UCHAR data ;
3453dfe64dd3Smacallan#endif
3454dfe64dd3Smacallan    VB_DEVICE_INFO VBINF;
3455dfe64dd3Smacallan    PVB_DEVICE_INFO pVBInfo = &VBINF;
3456dfe64dd3Smacallan    pVBInfo->ROMAddr = HwDeviceExtension->pjVirtualRomBase ;
3457dfe64dd3Smacallan    pVBInfo->FBAddr = HwDeviceExtension->pjVideoMemoryAddress ;
3458dfe64dd3Smacallan    pVBInfo->BaseAddr = ( USHORT )HwDeviceExtension->pjIOAddress ;
3459dfe64dd3Smacallan    pVBInfo->ISXPDOS = 0 ;
3460dfe64dd3Smacallan
3461dfe64dd3Smacallan    pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14 ;
3462dfe64dd3Smacallan    pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24 ;
3463dfe64dd3Smacallan    pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10 ;
3464dfe64dd3Smacallan    pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e ;
3465dfe64dd3Smacallan    pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12 ;
3466dfe64dd3Smacallan    pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a ;
3467dfe64dd3Smacallan    pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16 ;
3468dfe64dd3Smacallan    pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17 ;
3469dfe64dd3Smacallan    pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18 ;
3470dfe64dd3Smacallan    pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19 ;
3471dfe64dd3Smacallan
3472dfe64dd3Smacallan    pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1c ; /* Jong 07/31/2009 */
3473dfe64dd3Smacallan	PDEBUG(ErrorF("XGINew_SetDRAMModeRegister_XG27()-pVBInfo->P3cc = %d\n", pVBInfo->P3cc));
3474dfe64dd3Smacallan
3475dfe64dd3Smacallan    pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A ;
3476dfe64dd3Smacallan    pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00 ;
3477dfe64dd3Smacallan    pVBInfo->Part1Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_04 ;
3478dfe64dd3Smacallan    pVBInfo->Part2Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_10 ;
3479dfe64dd3Smacallan    pVBInfo->Part3Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_12 ;
3480dfe64dd3Smacallan    pVBInfo->Part4Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 ;
3481dfe64dd3Smacallan    pVBInfo->Part5Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 + 2 ;
3482dfe64dd3Smacallan
3483dfe64dd3Smacallan    InitTo330Pointer(HwDeviceExtension->jChipType,pVBInfo);
3484dfe64dd3Smacallan
3485dfe64dd3Smacallan    ReadVBIOSTablData( HwDeviceExtension->jChipType , pVBInfo) ;
3486dfe64dd3Smacallan
3487dfe64dd3Smacallan    if ( XGINew_GetXG20DRAMType( HwDeviceExtension, pVBInfo) == 0 )
3488dfe64dd3Smacallan        XGINew_DDR1x_MRS_XG20( pVBInfo->P3c4, pVBInfo ) ;
3489dfe64dd3Smacallan    else
3490dfe64dd3Smacallan        /*XGINew_DDR2_MRS_XG27( HwDeviceExtension , pVBInfo->P3c4 , pVBInfo ) ;*/
3491dfe64dd3Smacallan        XGINew_DDRII_Bootup_XG27( HwDeviceExtension , pVBInfo->P3c4 , pVBInfo) ;
3492dfe64dd3Smacallan
3493dfe64dd3Smacallan    /*XGINew_SetReg1( pVBInfo->P3c4 , 0x1B , 0x03 ) ;*/
3494dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) pVBInfo->P3c4 , 0x1B , pVBInfo->SR15[ 3 ][ XGINew_RAMType ] ) ;	/* SR1B */
3495dfe64dd3Smacallan
3496dfe64dd3Smacallan}
3497dfe64dd3Smacallan
3498dfe64dd3Smacallan/* -------------------------------------------------------- */
3499dfe64dd3Smacallan/* Function : XGINew_ChkSenseStatus */
3500dfe64dd3Smacallan/* Input : */
3501dfe64dd3Smacallan/* Output : */
3502dfe64dd3Smacallan/* Description : */
3503dfe64dd3Smacallan/* -------------------------------------------------------- */
3504dfe64dd3Smacallanvoid XGINew_ChkSenseStatus ( PXGI_HW_DEVICE_INFO HwDeviceExtension , PVB_DEVICE_INFO pVBInfo)
3505dfe64dd3Smacallan{
3506dfe64dd3Smacallan    USHORT tempbx=0 , temp , tempcx , CR3CData;
3507dfe64dd3Smacallan
3508dfe64dd3Smacallan    temp = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x32 ) ;
3509dfe64dd3Smacallan
3510dfe64dd3Smacallan    if ( temp & Monitor1Sense )
3511dfe64dd3Smacallan    	tempbx |= ActiveCRT1 ;
3512dfe64dd3Smacallan    if ( temp & LCDSense )
3513dfe64dd3Smacallan    	tempbx |= ActiveLCD ;
3514dfe64dd3Smacallan    if ( temp & Monitor2Sense )
3515dfe64dd3Smacallan    	tempbx |= ActiveCRT2 ;
3516dfe64dd3Smacallan    if ( temp & TVSense )
3517dfe64dd3Smacallan    {
3518dfe64dd3Smacallan    	tempbx |= ActiveTV ;
3519dfe64dd3Smacallan    	if ( temp & AVIDEOSense )
3520dfe64dd3Smacallan    	    tempbx |= ( ActiveAVideo << 8 );
3521dfe64dd3Smacallan    	if ( temp & SVIDEOSense )
3522dfe64dd3Smacallan    	    tempbx |= ( ActiveSVideo << 8 );
3523dfe64dd3Smacallan    	if ( temp & SCARTSense )
3524dfe64dd3Smacallan    	    tempbx |= ( ActiveSCART << 8 );
3525dfe64dd3Smacallan    	if ( temp & HiTVSense )
3526dfe64dd3Smacallan    	    tempbx |= ( ActiveHiTV << 8 );
3527dfe64dd3Smacallan    	if ( temp & YPbPrSense )
3528dfe64dd3Smacallan    	    tempbx |= ( ActiveYPbPr << 8 );
3529dfe64dd3Smacallan    }
3530dfe64dd3Smacallan
3531dfe64dd3Smacallan    tempcx = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x3d ) ;
3532dfe64dd3Smacallan    tempcx |= ( XGI_GetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x3e ) << 8 ) ;
3533dfe64dd3Smacallan
3534dfe64dd3Smacallan    if ( tempbx & tempcx )
3535dfe64dd3Smacallan    {
3536dfe64dd3Smacallan    	CR3CData = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x3c ) ;
3537dfe64dd3Smacallan    	if ( !( CR3CData & DisplayDeviceFromCMOS ) )
3538dfe64dd3Smacallan    	{
3539dfe64dd3Smacallan    	    tempcx = 0x1FF0 ;
3540dfe64dd3Smacallan    	    if (pVBInfo->SoftSetting & ModeSoftSetting) {
3541dfe64dd3Smacallan    	    	tempbx = 0x1FF0 ;
3542dfe64dd3Smacallan    	    }
3543dfe64dd3Smacallan    	}
3544dfe64dd3Smacallan    }
3545dfe64dd3Smacallan    else
3546dfe64dd3Smacallan    {
3547dfe64dd3Smacallan    	tempcx = 0x1FF0 ;
3548dfe64dd3Smacallan    	if (pVBInfo->SoftSetting & ModeSoftSetting) {
3549dfe64dd3Smacallan    	    tempbx = 0x1FF0 ;
3550dfe64dd3Smacallan    	}
3551dfe64dd3Smacallan    }
3552dfe64dd3Smacallan
3553dfe64dd3Smacallan    tempbx &= tempcx ;
3554dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4, 0x3d , ( tempbx & 0x00FF ) ) ;
3555dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4, 0x3e , ( ( tempbx & 0xFF00 ) >> 8 )) ;
3556dfe64dd3Smacallan}
3557dfe64dd3Smacallan/* -------------------------------------------------------- */
3558dfe64dd3Smacallan/* Function : XGINew_SetModeScratch */
3559dfe64dd3Smacallan/* Input : */
3560dfe64dd3Smacallan/* Output : */
3561dfe64dd3Smacallan/* Description : */
3562dfe64dd3Smacallan/* -------------------------------------------------------- */
3563dfe64dd3Smacallanvoid XGINew_SetModeScratch ( PXGI_HW_DEVICE_INFO HwDeviceExtension , PVB_DEVICE_INFO pVBInfo )
3564dfe64dd3Smacallan{
3565dfe64dd3Smacallan    USHORT temp , tempcl = 0 , tempch = 0 , CR31Data , CR38Data;
3566dfe64dd3Smacallan
3567dfe64dd3Smacallan    temp = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x3d ) ;
3568dfe64dd3Smacallan    temp |= XGI_GetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x3e ) << 8 ;
3569dfe64dd3Smacallan    temp |= ( XGI_GetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x31 ) & ( DriverMode >> 8) ) << 8 ;
3570dfe64dd3Smacallan
3571dfe64dd3Smacallan    if ( pVBInfo->IF_DEF_CRT2Monitor == 1)
3572dfe64dd3Smacallan    {
3573dfe64dd3Smacallan    	if ( temp & ActiveCRT2 )
3574dfe64dd3Smacallan    	   tempcl = SetCRT2ToRAMDAC ;
3575dfe64dd3Smacallan    }
3576dfe64dd3Smacallan
3577dfe64dd3Smacallan    if ( temp & ActiveLCD )
3578dfe64dd3Smacallan    {
3579dfe64dd3Smacallan    	tempcl |= SetCRT2ToLCD ;
3580dfe64dd3Smacallan    	if  ( temp & DriverMode )
3581dfe64dd3Smacallan    	{
3582dfe64dd3Smacallan    	    if ( temp & ActiveTV )
3583dfe64dd3Smacallan    	    {
3584dfe64dd3Smacallan    	    	tempch = SetToLCDA | EnableDualEdge ;
3585dfe64dd3Smacallan    	    	temp ^= SetCRT2ToLCD ;
3586dfe64dd3Smacallan
3587dfe64dd3Smacallan    	    	if ( ( temp >> 8 ) & ActiveAVideo )
3588dfe64dd3Smacallan    	    	    tempcl |= SetCRT2ToAVIDEO ;
3589dfe64dd3Smacallan    	    	if ( ( temp >> 8 ) & ActiveSVideo )
3590dfe64dd3Smacallan    	    	    tempcl |= SetCRT2ToSVIDEO ;
3591dfe64dd3Smacallan    	    	if ( ( temp >> 8 ) & ActiveSCART )
3592dfe64dd3Smacallan    	    	    tempcl |= SetCRT2ToSCART ;
3593dfe64dd3Smacallan
3594dfe64dd3Smacallan    	    	if ( pVBInfo->IF_DEF_HiVision == 1 )
3595dfe64dd3Smacallan    	    	{
3596dfe64dd3Smacallan    	    	    if ( ( temp >> 8 ) & ActiveHiTV )
3597dfe64dd3Smacallan    	    	    tempcl |= SetCRT2ToHiVisionTV ;
3598dfe64dd3Smacallan    	    	}
3599dfe64dd3Smacallan
3600dfe64dd3Smacallan    	    	if ( pVBInfo->IF_DEF_YPbPr == 1 )
3601dfe64dd3Smacallan    	    	{
3602dfe64dd3Smacallan    	    	    if ( ( temp >> 8 ) & ActiveYPbPr )
3603dfe64dd3Smacallan    	    	    tempch |= SetYPbPr ;
3604dfe64dd3Smacallan    	    	}
3605dfe64dd3Smacallan    	    }
3606dfe64dd3Smacallan    	}
3607dfe64dd3Smacallan    }
3608dfe64dd3Smacallan    else
3609dfe64dd3Smacallan    {
3610dfe64dd3Smacallan    	if ( ( temp >> 8 ) & ActiveAVideo )
3611dfe64dd3Smacallan    	   tempcl |= SetCRT2ToAVIDEO ;
3612dfe64dd3Smacallan    	if ( ( temp >> 8 ) & ActiveSVideo )
3613dfe64dd3Smacallan  	   tempcl |= SetCRT2ToSVIDEO ;
3614dfe64dd3Smacallan    	if ( ( temp >> 8 ) & ActiveSCART )
3615dfe64dd3Smacallan   	   tempcl |= SetCRT2ToSCART ;
3616dfe64dd3Smacallan
3617dfe64dd3Smacallan   	if ( pVBInfo->IF_DEF_HiVision == 1 )
3618dfe64dd3Smacallan    	{
3619dfe64dd3Smacallan    	   if ( ( temp >> 8 ) & ActiveHiTV )
3620dfe64dd3Smacallan    	   tempcl |= SetCRT2ToHiVisionTV ;
3621dfe64dd3Smacallan    	}
3622dfe64dd3Smacallan
3623dfe64dd3Smacallan    	if ( pVBInfo->IF_DEF_YPbPr == 1 )
3624dfe64dd3Smacallan    	{
3625dfe64dd3Smacallan    	   if ( ( temp >> 8 ) & ActiveYPbPr )
3626dfe64dd3Smacallan    	   tempch |= SetYPbPr ;
3627dfe64dd3Smacallan    	}
3628dfe64dd3Smacallan    }
3629dfe64dd3Smacallan
3630dfe64dd3Smacallan    tempcl |= SetSimuScanMode ;
3631dfe64dd3Smacallan    if ( (!( temp & ActiveCRT1 )) && ( ( temp & ActiveLCD ) || ( temp & ActiveTV ) || ( temp & ActiveCRT2 ) ) )
3632dfe64dd3Smacallan       tempcl ^= ( SetSimuScanMode | SwitchToCRT2 ) ;
3633dfe64dd3Smacallan    if ( ( temp & ActiveLCD ) && ( temp & ActiveTV ) )
3634dfe64dd3Smacallan       tempcl ^= ( SetSimuScanMode | SwitchToCRT2 ) ;
3635dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4, 0x30 , tempcl ) ;
3636dfe64dd3Smacallan
3637dfe64dd3Smacallan    CR31Data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x31 ) ;
3638dfe64dd3Smacallan    CR31Data &= ~( SetNotSimuMode >> 8 ) ;
3639dfe64dd3Smacallan    if ( !( temp & ActiveCRT1 ) )
3640dfe64dd3Smacallan        CR31Data |= ( SetNotSimuMode >> 8 ) ;
3641dfe64dd3Smacallan    CR31Data &= ~( DisableCRT2Display >> 8 ) ;
3642dfe64dd3Smacallan    if  (!( ( temp & ActiveLCD ) || ( temp & ActiveTV ) || ( temp & ActiveCRT2 ) ) )
3643dfe64dd3Smacallan        CR31Data |= ( DisableCRT2Display >> 8 ) ;
3644dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4, 0x31 , CR31Data ) ;
3645dfe64dd3Smacallan
3646dfe64dd3Smacallan    CR38Data = XGI_GetReg((XGIIOADDRESS) pVBInfo->P3d4 , 0x38 ) ;
3647dfe64dd3Smacallan    CR38Data &= ~SetYPbPr ;
3648dfe64dd3Smacallan    CR38Data |= tempch ;
3649dfe64dd3Smacallan    XGI_SetReg((XGIIOADDRESS) pVBInfo->P3d4, 0x38 , CR38Data ) ;
3650dfe64dd3Smacallan
3651dfe64dd3Smacallan}
3652dfe64dd3Smacallan
3653dfe64dd3Smacallan/* -------------------------------------------------------- */
3654dfe64dd3Smacallan/* Function : XGINew_GetXG21Sense */
3655dfe64dd3Smacallan/* Input : */
3656dfe64dd3Smacallan/* Output : */
3657dfe64dd3Smacallan/* Description : */
3658dfe64dd3Smacallan/* -------------------------------------------------------- */
3659dfe64dd3Smacallanvoid XGINew_GetXG21Sense(PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo)
3660dfe64dd3Smacallan{
3661dfe64dd3Smacallan    UCHAR Temp;
3662dfe64dd3Smacallan    PUCHAR  volatile pVideoMemory = ( PUCHAR )pVBInfo->ROMAddr ;
3663dfe64dd3Smacallan
3664dfe64dd3Smacallan    pVBInfo->IF_DEF_LVDS = 0 ;
3665dfe64dd3Smacallan
3666dfe64dd3Smacallan    if ( ( pVideoMemory[ 0x65 ] & 0x01 ) )			/* For XG21 LVDS */
3667dfe64dd3Smacallan    {
3668dfe64dd3Smacallan        pVBInfo->IF_DEF_LVDS = 1 ;
3669dfe64dd3Smacallan        XGI_SetRegOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x32 , LCDSense ) ;
3670dfe64dd3Smacallan        XGI_SetRegANDOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x38 , ~0xE0 , 0xC0 ) ; /* LVDS on chip */
3671dfe64dd3Smacallan    }
3672dfe64dd3Smacallan    else
3673dfe64dd3Smacallan    {
3674dfe64dd3Smacallan        XGI_SetRegANDOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x4A , ~0x03 , 0x03 ) ; /* Enable GPIOA/B read  */
3675dfe64dd3Smacallan        Temp = XGI_GetReg( (XGIIOADDRESS) pVBInfo->P3d4 , 0x48 ) & 0xC0;
3676dfe64dd3Smacallan        if ( Temp == 0xC0 )
3677dfe64dd3Smacallan        {								/* DVI & DVO GPIOA/B pull high */
3678dfe64dd3Smacallan          XGINew_SenseLCD( HwDeviceExtension, pVBInfo ) ;
3679dfe64dd3Smacallan          XGI_SetRegOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x32 , LCDSense ) ;
3680dfe64dd3Smacallan          XGI_SetRegANDOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x4A , ~0x20 , 0x20 ) ;   /* Enable read GPIOF */
3681dfe64dd3Smacallan          Temp = XGI_GetReg( (XGIIOADDRESS) pVBInfo->P3d4 , 0x48 ) & 0x04 ;
3682dfe64dd3Smacallan          if ( !Temp )
3683dfe64dd3Smacallan            XGI_SetRegANDOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x38 , ~0xE0 , 0x80 ) ; /* TMDS on chip */
3684dfe64dd3Smacallan          else
3685dfe64dd3Smacallan            XGI_SetRegANDOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x38 , ~0xE0 , 0xA0 ) ; /* Only DVO on chip */
3686dfe64dd3Smacallan
3687dfe64dd3Smacallan          XGI_SetRegAND( (XGIIOADDRESS)pVBInfo->P3d4 , 0x4A , ~0x20 ) ;	    /* Disable read GPIOF */
3688dfe64dd3Smacallan        }
3689dfe64dd3Smacallan    }
3690dfe64dd3Smacallan}
3691dfe64dd3Smacallan
3692dfe64dd3Smacallan/* -------------------------------------------------------- */
3693dfe64dd3Smacallan/* Function : XGINew_GetXG27Sense */
3694dfe64dd3Smacallan/* Input : */
3695dfe64dd3Smacallan/* Output : */
3696dfe64dd3Smacallan/* Description : */
3697dfe64dd3Smacallan/* -------------------------------------------------------- */
3698dfe64dd3Smacallanvoid XGINew_GetXG27Sense(PXGI_HW_DEVICE_INFO HwDeviceExtension, PVB_DEVICE_INFO pVBInfo)
3699dfe64dd3Smacallan{
3700dfe64dd3Smacallan    UCHAR Temp,bCR4A;
3701dfe64dd3Smacallan    PUCHAR  volatile pVideoMemory = ( PUCHAR )pVBInfo->ROMAddr ;
3702dfe64dd3Smacallan
3703dfe64dd3Smacallan    pVBInfo->IF_DEF_LVDS = 0 ;
3704dfe64dd3Smacallan    bCR4A = XGI_GetReg( (XGIIOADDRESS) pVBInfo->P3d4 , 0x4A ) ;
3705dfe64dd3Smacallan    XGI_SetRegANDOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x4A , ~0x07 , 0x07 ) ; /* Enable GPIOA/B/C read  */
3706dfe64dd3Smacallan    Temp = XGI_GetReg( (XGIIOADDRESS) pVBInfo->P3d4 , 0x48 ) & 0x07;
3707dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) pVBInfo->P3d4, 0x4A , bCR4A ) ;
3708dfe64dd3Smacallan
3709dfe64dd3Smacallan     if ( Temp <= 0x02 )
3710dfe64dd3Smacallan     {
3711dfe64dd3Smacallan            pVBInfo->IF_DEF_LVDS = 1 ;
3712dfe64dd3Smacallan            XGI_SetRegANDOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x38 , ~0xE0 , 0xC0 ) ; /* LVDS setting */
3713dfe64dd3Smacallan            XGI_SetReg( (XGIIOADDRESS) pVBInfo->P3d4, 0x30 , 0x21 ) ;
3714dfe64dd3Smacallan     }
3715dfe64dd3Smacallan     else
3716dfe64dd3Smacallan     {
3717dfe64dd3Smacallan            XGI_SetRegANDOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x38 , ~0xE0 , 0xA0 ) ; /* TMDS/DVO setting */
3718dfe64dd3Smacallan     }
3719dfe64dd3Smacallan
3720dfe64dd3Smacallan     XGI_SetRegOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x32 , LCDSense ) ;
3721dfe64dd3Smacallan}
3722dfe64dd3Smacallan
3723dfe64dd3SmacallanUCHAR GetXG21FPBits(PVB_DEVICE_INFO pVBInfo)
3724dfe64dd3Smacallan{
3725dfe64dd3Smacallan    UCHAR CR38,CR4A,temp;
3726dfe64dd3Smacallan
3727dfe64dd3Smacallan    CR4A = XGI_GetReg( (XGIIOADDRESS) pVBInfo->P3d4 , 0x4A ) ;
3728dfe64dd3Smacallan    XGI_SetRegANDOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x4A , ~0x10 , 0x10 ) ; /* enable GPIOE read */
3729dfe64dd3Smacallan    CR38 = XGI_GetReg( (XGIIOADDRESS) pVBInfo->P3d4 , 0x38 ) ;
3730dfe64dd3Smacallan    temp =0;
3731dfe64dd3Smacallan    if ( ( CR38 & 0xE0 ) > 0x80 )
3732dfe64dd3Smacallan    {
3733dfe64dd3Smacallan        temp = XGI_GetReg( (XGIIOADDRESS) pVBInfo->P3d4 , 0x48 ) ;
3734dfe64dd3Smacallan        temp &= 0x08;
3735dfe64dd3Smacallan        temp >>= 3;
3736dfe64dd3Smacallan    }
3737dfe64dd3Smacallan
3738dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) pVBInfo->P3d4, 0x4A , CR4A ) ;
3739dfe64dd3Smacallan
3740dfe64dd3Smacallan    return temp;
3741dfe64dd3Smacallan}
3742dfe64dd3Smacallan
3743dfe64dd3SmacallanUCHAR GetXG27FPBits(PVB_DEVICE_INFO pVBInfo)
3744dfe64dd3Smacallan{
3745dfe64dd3Smacallan    UCHAR CR38,CR4A,temp;
3746dfe64dd3Smacallan
3747dfe64dd3Smacallan    CR4A = XGI_GetReg( (XGIIOADDRESS) pVBInfo->P3d4 , 0x4A ) ;
3748dfe64dd3Smacallan    XGI_SetRegANDOR( (XGIIOADDRESS) pVBInfo->P3d4 , 0x4A , ~0x03 , 0x03 ) ; /* enable GPIOA/B/C read */
3749dfe64dd3Smacallan    temp = XGI_GetReg( (XGIIOADDRESS) pVBInfo->P3d4 , 0x48 ) ;
3750dfe64dd3Smacallan    if ( temp <= 2 )
3751dfe64dd3Smacallan    {
3752dfe64dd3Smacallan       temp &= 0x03;
3753dfe64dd3Smacallan    }
3754dfe64dd3Smacallan    else
3755dfe64dd3Smacallan    {
3756dfe64dd3Smacallan    	temp = ((temp&0x04)>>1) || ((~temp)&0x01);
3757dfe64dd3Smacallan    }
3758dfe64dd3Smacallan
3759dfe64dd3Smacallan    XGI_SetReg( (XGIIOADDRESS) pVBInfo->P3d4, 0x4A , CR4A ) ;
3760dfe64dd3Smacallan
3761dfe64dd3Smacallan    return temp;
3762dfe64dd3Smacallan}
3763dfe64dd3Smacallan
3764