staging: xgifb: vb_setmode: eliminate GetVGAType/Set_VGAType
[deliverable/linux.git] / drivers / staging / xgifb / vb_setmode.c
CommitLineData
d7636e0b 1
1d7f656d 2#include <linux/io.h>
d80aaa01 3#include <linux/delay.h>
d7636e0b 4#include <linux/types.h>
d7636e0b 5#include "XGIfb.h"
d7636e0b 6
d7636e0b 7
8#include "vb_def.h"
9#include "vgatypes.h"
10#include "vb_struct.h"
09d1cad1 11#include "vb_init.h"
d7636e0b 12#include "vb_util.h"
13#include "vb_table.h"
5e60b97c 14#include "vb_setmode.h"
d7636e0b 15
16
17#define IndexMask 0xff
d7636e0b 18
624554da 19static const unsigned short XGINew_MDA_DAC[] = {
82d6eb5b
BP
20 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
22 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
23 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
24 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
25 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
26 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
27 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F};
28
624554da 29static const unsigned short XGINew_CGA_DAC[] = {
82d6eb5b
BP
30 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
31 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
32 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
33 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
34 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
35 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
36 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
37 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
38
624554da 39static const unsigned short XGINew_EGA_DAC[] = {
82d6eb5b
BP
40 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x05, 0x15,
41 0x20, 0x30, 0x24, 0x34, 0x21, 0x31, 0x25, 0x35,
42 0x08, 0x18, 0x0C, 0x1C, 0x09, 0x19, 0x0D, 0x1D,
43 0x28, 0x38, 0x2C, 0x3C, 0x29, 0x39, 0x2D, 0x3D,
44 0x02, 0x12, 0x06, 0x16, 0x03, 0x13, 0x07, 0x17,
45 0x22, 0x32, 0x26, 0x36, 0x23, 0x33, 0x27, 0x37,
46 0x0A, 0x1A, 0x0E, 0x1E, 0x0B, 0x1B, 0x0F, 0x1F,
47 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
48
624554da 49static const unsigned short XGINew_VGA_DAC[] = {
82d6eb5b
BP
50 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
51 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
52 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
53 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
54 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
55 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
56 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
57 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
58 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
59 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
d7636e0b 60
80adad85 61void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
d7636e0b 62{
21df8fc8
PS
63 pVBInfo->SModeIDTable = (struct XGI_StStruct *) XGI330_SModeIDTable;
64 pVBInfo->StandTable = (struct XGI_StandTableStruct *) XGI330_StandTable;
65 pVBInfo->EModeIDTable = (struct XGI_ExtStruct *) XGI330_EModeIDTable;
66 pVBInfo->RefIndex = (struct XGI_Ext2Struct *) XGI330_RefIndex;
67 pVBInfo->XGINEWUB_CRT1Table
68 = (struct XGI_CRT1TableStruct *) XGI_CRT1Table;
69
70 /* add for new UNIVGABIOS */
1d7f656d
KT
71 /* XGINew_UBLCDDataTable =
72 * (struct XGI_LCDDataTablStruct *) XGI_LCDDataTable; */
21df8fc8
PS
73 /* XGINew_UBTVDataTable = (XGI_TVDataTablStruct *) XGI_TVDataTable; */
74
06587335
AK
75 pVBInfo->MCLKData = (struct XGI_MCLKDataStruct *) XGI340New_MCLKData;
76 pVBInfo->ECLKData = (struct XGI_ECLKDataStruct *) XGI340_ECLKData;
21df8fc8
PS
77 pVBInfo->VCLKData = (struct XGI_VCLKDataStruct *) XGI_VCLKData;
78 pVBInfo->VBVCLKData = (struct XGI_VBVCLKDataStruct *) XGI_VBVCLKData;
79 pVBInfo->ScreenOffset = XGI330_ScreenOffset;
80 pVBInfo->StResInfo = (struct XGI_StResInfoStruct *) XGI330_StResInfo;
81 pVBInfo->ModeResInfo
82 = (struct XGI_ModeResInfoStruct *) XGI330_ModeResInfo;
83
84 pVBInfo->pOutputSelect = &XGI330_OutputSelect;
85 pVBInfo->pSoftSetting = &XGI330_SoftSetting;
86 pVBInfo->pSR07 = &XGI330_SR07;
87 pVBInfo->LCDResInfo = 0;
88 pVBInfo->LCDTypeInfo = 0;
89 pVBInfo->LCDInfo = 0;
90 pVBInfo->VBInfo = 0;
91 pVBInfo->TVInfo = 0;
92
93 pVBInfo->SR15 = XGI340_SR13;
94 pVBInfo->CR40 = XGI340_cr41;
95 pVBInfo->SR25 = XGI330_sr25;
96 pVBInfo->pSR31 = &XGI330_sr31;
97 pVBInfo->pSR32 = &XGI330_sr32;
98 pVBInfo->CR6B = XGI340_CR6B;
99 pVBInfo->CR6E = XGI340_CR6E;
100 pVBInfo->CR6F = XGI340_CR6F;
101 pVBInfo->CR89 = XGI340_CR89;
102 pVBInfo->AGPReg = XGI340_AGPReg;
103 pVBInfo->SR16 = XGI340_SR16;
104 pVBInfo->pCRCF = &XG40_CRCF;
105 pVBInfo->pXGINew_DRAMTypeDefinition = &XG40_DRAMTypeDefinition;
106
107 pVBInfo->CR49 = XGI330_CR49;
108 pVBInfo->pSR1F = &XGI330_SR1F;
109 pVBInfo->pSR21 = &XGI330_SR21;
110 pVBInfo->pSR22 = &XGI330_SR22;
111 pVBInfo->pSR23 = &XGI330_SR23;
112 pVBInfo->pSR24 = &XGI330_SR24;
113 pVBInfo->pSR33 = &XGI330_SR33;
114
115 pVBInfo->pCRT2Data_1_2 = &XGI330_CRT2Data_1_2;
116 pVBInfo->pCRT2Data_4_D = &XGI330_CRT2Data_4_D;
117 pVBInfo->pCRT2Data_4_E = &XGI330_CRT2Data_4_E;
118 pVBInfo->pCRT2Data_4_10 = &XGI330_CRT2Data_4_10;
119 pVBInfo->pRGBSenseData = &XGI330_RGBSenseData;
120 pVBInfo->pVideoSenseData = &XGI330_VideoSenseData;
121 pVBInfo->pYCSenseData = &XGI330_YCSenseData;
122 pVBInfo->pRGBSenseData2 = &XGI330_RGBSenseData2;
123 pVBInfo->pVideoSenseData2 = &XGI330_VideoSenseData2;
124 pVBInfo->pYCSenseData2 = &XGI330_YCSenseData2;
125
126 pVBInfo->NTSCTiming = XGI330_NTSCTiming;
127 pVBInfo->PALTiming = XGI330_PALTiming;
128 pVBInfo->HiTVExtTiming = XGI330_HiTVExtTiming;
129 pVBInfo->HiTVSt1Timing = XGI330_HiTVSt1Timing;
130 pVBInfo->HiTVSt2Timing = XGI330_HiTVSt2Timing;
131 pVBInfo->HiTVTextTiming = XGI330_HiTVTextTiming;
132 pVBInfo->YPbPr750pTiming = XGI330_YPbPr750pTiming;
133 pVBInfo->YPbPr525pTiming = XGI330_YPbPr525pTiming;
134 pVBInfo->YPbPr525iTiming = XGI330_YPbPr525iTiming;
135 pVBInfo->HiTVGroup3Data = XGI330_HiTVGroup3Data;
136 pVBInfo->HiTVGroup3Simu = XGI330_HiTVGroup3Simu;
137 pVBInfo->HiTVGroup3Text = XGI330_HiTVGroup3Text;
138 pVBInfo->Ren525pGroup3 = XGI330_Ren525pGroup3;
139 pVBInfo->Ren750pGroup3 = XGI330_Ren750pGroup3;
140
141 pVBInfo->TimingH = (struct XGI_TimingHStruct *) XGI_TimingH;
142 pVBInfo->TimingV = (struct XGI_TimingVStruct *) XGI_TimingV;
143 pVBInfo->UpdateCRT1 = (struct XGI_XG21CRT1Struct *) XGI_UpdateCRT1Table;
144
21df8fc8
PS
145 /* 310 customization related */
146 if ((pVBInfo->VBType & VB_XGI301LV) || (pVBInfo->VBType & VB_XGI302LV))
147 pVBInfo->LCDCapList = XGI_LCDDLCapList;
148 else
149 pVBInfo->LCDCapList = XGI_LCDCapList;
d7636e0b 150
21df8fc8
PS
151 if ((ChipType == XG21) || (ChipType == XG27))
152 pVBInfo->XG21_LVDSCapList = XGI21_LCDCapList;
d7636e0b 153
21df8fc8
PS
154 pVBInfo->XGI_TVDelayList = XGI301TVDelayList;
155 pVBInfo->XGI_TVDelayList2 = XGI301TVDelayList2;
d7636e0b 156
21df8fc8 157 pVBInfo->pXGINew_I2CDefinition = &XG40_I2CDefinition;
d7636e0b 158
21df8fc8
PS
159 if (ChipType >= XG20)
160 pVBInfo->pXGINew_CR97 = &XG20_CR97;
d7636e0b 161
21df8fc8
PS
162 if (ChipType == XG27) {
163 pVBInfo->MCLKData
164 = (struct XGI_MCLKDataStruct *) XGI27New_MCLKData;
165 pVBInfo->CR40 = XGI27_cr41;
166 pVBInfo->pXGINew_CR97 = &XG27_CR97;
167 pVBInfo->pSR36 = &XG27_SR36;
168 pVBInfo->pCR8F = &XG27_CR8F;
169 pVBInfo->pCRD0 = XG27_CRD0;
170 pVBInfo->pCRDE = XG27_CRDE;
171 pVBInfo->pSR40 = &XG27_SR40;
172 pVBInfo->pSR41 = &XG27_SR41;
173
174 }
175
176 if (ChipType >= XG20) {
177 pVBInfo->pDVOSetting = &XG21_DVOSetting;
178 pVBInfo->pCR2E = &XG21_CR2E;
179 pVBInfo->pCR2F = &XG21_CR2F;
180 pVBInfo->pCR46 = &XG21_CR46;
181 pVBInfo->pCR47 = &XG21_CR47;
182 }
183
184}
d7636e0b 185
1d7f656d
KT
186static unsigned char XGI_GetModePtr(unsigned short ModeNo,
187 unsigned short ModeIdIndex,
188 struct vb_device_info *pVBInfo)
21df8fc8 189{
cc1e2398 190 unsigned char index;
21df8fc8 191
cc1e2398
AK
192 if (ModeNo <= 0x13)
193 index = pVBInfo->SModeIDTable[ModeIdIndex].St_StTableIndex;
194 else {
195 if (pVBInfo->ModeType <= 0x02)
196 index = 0x1B; /* 02 -> ModeEGA */
197 else
198 index = 0x0F;
21df8fc8 199 }
cc1e2398
AK
200 return index; /* Get pVBInfo->StandTable index */
201}
d7636e0b 202
1d7f656d
KT
203static void XGI_SetSeqRegs(unsigned short ModeNo,
204 unsigned short StandTableIndex,
205 unsigned short ModeIdIndex,
206 struct vb_device_info *pVBInfo)
cc1e2398
AK
207{
208 unsigned char tempah, SRdata;
cc1e2398
AK
209 unsigned short i, modeflag;
210
211 if (ModeNo <= 0x13)
212 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
213 else
214 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
215
8104e329 216 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
cc1e2398
AK
217 tempah = pVBInfo->StandTable[StandTableIndex].SR[0];
218
219 i = SetCRT2ToLCDA;
220 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
221 tempah |= 0x01;
222 } else {
223 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
224 if (pVBInfo->VBInfo & SetInSlaveMode)
225 tempah |= 0x01;
21df8fc8
PS
226 }
227 }
d7636e0b 228
cc1e2398 229 tempah |= 0x20; /* screen off */
8104e329 230 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
d7636e0b 231
cc1e2398 232 for (i = 02; i <= 04; i++) {
1d7f656d
KT
233 /* Get SR2,3,4 from file */
234 SRdata = pVBInfo->StandTable[StandTableIndex].SR[i - 1];
8104e329 235 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
21df8fc8 236 }
cc1e2398
AK
237}
238
239static void XGI_SetMiscRegs(unsigned short StandTableIndex,
1d7f656d 240 struct vb_device_info *pVBInfo)
cc1e2398
AK
241{
242 unsigned char Miscdata;
243
1d7f656d
KT
244 /* Get Misc from file */
245 Miscdata = pVBInfo->StandTable[StandTableIndex].MISC;
cc1e2398 246 /*
1d7f656d
KT
247 if (pVBInfo->VBType & (VB_XGI301B |
248 VB_XGI302B |
249 VB_XGI301LV |
250 VB_XGI302LV |
251 VB_XGI301C)) {
cc1e2398
AK
252 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
253 Miscdata |= 0x0C;
254 }
21df8fc8
PS
255 }
256 */
21df8fc8 257
efdf4ee7 258 outb(Miscdata, pVBInfo->P3c2); /* Set Misc(3c2) */
cc1e2398 259}
21df8fc8 260
cc1e2398 261static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
1d7f656d
KT
262 unsigned short StandTableIndex,
263 struct vb_device_info *pVBInfo)
cc1e2398
AK
264{
265 unsigned char CRTCdata;
266 unsigned short i;
21df8fc8 267
58839b01 268 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
cc1e2398 269 CRTCdata &= 0x7f;
8104e329 270 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
21df8fc8 271
cc1e2398 272 for (i = 0; i <= 0x18; i++) {
1d7f656d
KT
273 /* Get CRTC from file */
274 CRTCdata = pVBInfo->StandTable[StandTableIndex].CRTC[i];
8104e329 275 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
cc1e2398
AK
276 }
277 /*
1d7f656d
KT
278 if ((HwDeviceExtension->jChipType == XGI_630) &&
279 (HwDeviceExtension->jChipRevision == 0x30)) {
cc1e2398
AK
280 if (pVBInfo->VBInfo & SetInSlaveMode) {
281 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
8104e329 282 xgifb_reg_set(pVBInfo->P3d4, 0x18, 0xFE);
cc1e2398
AK
283 }
284 }
285 }
286 */
287}
21df8fc8 288
1d7f656d
KT
289static void XGI_SetATTRegs(unsigned short ModeNo,
290 unsigned short StandTableIndex,
291 unsigned short ModeIdIndex,
292 struct vb_device_info *pVBInfo)
cc1e2398
AK
293{
294 unsigned char ARdata;
295 unsigned short i, modeflag;
21df8fc8 296
cc1e2398
AK
297 if (ModeNo <= 0x13)
298 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
299 else
300 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
301
302 for (i = 0; i <= 0x13; i++) {
303 ARdata = pVBInfo->StandTable[StandTableIndex].ATTR[i];
304 if (modeflag & Charx8Dot) { /* ifndef Dot9 */
305 if (i == 0x13) {
21df8fc8 306 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
cc1e2398
AK
307 ARdata = 0;
308 } else {
309 if (pVBInfo->VBInfo & (SetCRT2ToTV
310 | SetCRT2ToLCD)) {
1d7f656d
KT
311 if (pVBInfo->VBInfo &
312 SetInSlaveMode)
cc1e2398
AK
313 ARdata = 0;
314 }
21df8fc8
PS
315 }
316 }
317 }
318
d8ad0a6d 319 inb(pVBInfo->P3da); /* reset 3da */
efdf4ee7
AK
320 outb(i, pVBInfo->P3c0); /* set index */
321 outb(ARdata, pVBInfo->P3c0); /* set data */
cc1e2398 322 }
21df8fc8 323
d8ad0a6d 324 inb(pVBInfo->P3da); /* reset 3da */
efdf4ee7
AK
325 outb(0x14, pVBInfo->P3c0); /* set index */
326 outb(0x00, pVBInfo->P3c0); /* set data */
d8ad0a6d 327 inb(pVBInfo->P3da); /* Enable Attribute */
efdf4ee7 328 outb(0x20, pVBInfo->P3c0);
cc1e2398 329}
21df8fc8 330
cc1e2398 331static void XGI_SetGRCRegs(unsigned short StandTableIndex,
1d7f656d 332 struct vb_device_info *pVBInfo)
cc1e2398
AK
333{
334 unsigned char GRdata;
335 unsigned short i;
21df8fc8 336
cc1e2398 337 for (i = 0; i <= 0x08; i++) {
1d7f656d
KT
338 /* Get GR from file */
339 GRdata = pVBInfo->StandTable[StandTableIndex].GRC[i];
8104e329 340 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
cc1e2398 341 }
21df8fc8 342
cc1e2398 343 if (pVBInfo->ModeType > ModeVGA) {
58839b01 344 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
cc1e2398 345 GRdata &= 0xBF; /* 256 color disable */
8104e329 346 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
21df8fc8 347 }
cc1e2398 348}
d7636e0b 349
cc1e2398
AK
350static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
351{
352 unsigned short i;
d7636e0b 353
cc1e2398 354 for (i = 0x0A; i <= 0x0E; i++)
8104e329 355 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
cc1e2398 356}
d7636e0b 357
cc1e2398
AK
358static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
359{
d7636e0b 360
ec9e5d3e 361 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
8104e329
AK
362 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[0].SR2B);
363 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[0].SR2C);
21df8fc8 364
ec9e5d3e 365 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
8104e329
AK
366 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[1].SR2B);
367 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[1].SR2C);
21df8fc8 368
dc50556b 369 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
cc1e2398 370 return 0;
d7636e0b 371}
372
cc1e2398
AK
373static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
374 unsigned short ModeIdIndex,
375 unsigned short RefreshRateTableIndex, unsigned short *i,
21df8fc8
PS
376 struct vb_device_info *pVBInfo)
377{
cc1e2398 378 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
21df8fc8 379
cc1e2398 380 if (ModeNo <= 0x13)
1d7f656d
KT
381 /* si+St_ModeFlag */
382 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
cc1e2398
AK
383 else
384 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
21df8fc8 385
cc1e2398
AK
386 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
387 tempbx = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID;
388 tempax = 0;
21df8fc8 389
cc1e2398
AK
390 if (pVBInfo->IF_DEF_LVDS == 0) {
391 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
392 tempax |= SupportRAMDAC2;
21df8fc8 393
cc1e2398
AK
394 if (pVBInfo->VBType & VB_XGI301C)
395 tempax |= SupportCRT2in301C;
21df8fc8 396 }
21df8fc8 397
1d7f656d
KT
398 /* 301b */
399 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
cc1e2398 400 tempax |= SupportLCD;
21df8fc8 401
cc1e2398
AK
402 if (pVBInfo->LCDResInfo != Panel1280x1024) {
403 if (pVBInfo->LCDResInfo != Panel1280x960) {
1d7f656d
KT
404 if (pVBInfo->LCDInfo &
405 LCDNonExpanding) {
cc1e2398
AK
406 if (resinfo >= 9) {
407 tempax = 0;
408 return 0;
409 }
410 }
411 }
412 }
21df8fc8 413 }
21df8fc8 414
cc1e2398 415 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) { /* for HiTV */
1d7f656d
KT
416 if ((pVBInfo->VBType & VB_XGI301LV) &&
417 (pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
cc1e2398
AK
418 tempax |= SupportYPbPr;
419 if (pVBInfo->VBInfo & SetInSlaveMode) {
420 if (resinfo == 4)
421 return 0;
21df8fc8 422
cc1e2398
AK
423 if (resinfo == 3)
424 return 0;
21df8fc8 425
cc1e2398
AK
426 if (resinfo > 7)
427 return 0;
428 }
429 } else {
430 tempax |= SupportHiVisionTV;
431 if (pVBInfo->VBInfo & SetInSlaveMode) {
432 if (resinfo == 4)
433 return 0;
21df8fc8 434
cc1e2398
AK
435 if (resinfo == 3) {
436 if (pVBInfo->SetFlag
437 & TVSimuMode)
438 return 0;
439 }
21df8fc8 440
cc1e2398
AK
441 if (resinfo > 7)
442 return 0;
443 }
21df8fc8 444 }
cc1e2398 445 } else {
1d7f656d
KT
446 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
447 SetCRT2ToSVIDEO |
448 SetCRT2ToSCART |
449 SetCRT2ToYPbPr |
450 SetCRT2ToHiVisionTV)) {
cc1e2398 451 tempax |= SupportTV;
21df8fc8 452
cc1e2398
AK
453 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
454 | VB_XGI301LV | VB_XGI302LV
455 | VB_XGI301C)) {
456 tempax |= SupportTV1024;
457 }
21df8fc8 458
cc1e2398
AK
459 if (!(pVBInfo->VBInfo & SetPALTV)) {
460 if (modeflag & NoSupportSimuTV) {
1d7f656d
KT
461 if (pVBInfo->VBInfo &
462 SetInSlaveMode) {
463 if (!(pVBInfo->VBInfo &
464 SetNotSimuMode)) {
cc1e2398
AK
465 return 0;
466 }
467 }
468 }
469 }
470 }
471 }
472 } else { /* for LVDS */
cc1e2398
AK
473 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
474 tempax |= SupportLCD;
d7636e0b 475
cc1e2398
AK
476 if (resinfo > 0x08)
477 return 0; /* 1024x768 */
d7636e0b 478
cc1e2398
AK
479 if (pVBInfo->LCDResInfo < Panel1024x768) {
480 if (resinfo > 0x07)
481 return 0; /* 800x600 */
d7636e0b 482
cc1e2398
AK
483 if (resinfo == 0x04)
484 return 0; /* 512x384 */
485 }
486 }
487 }
21df8fc8 488
1d7f656d
KT
489 for (; pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
490 tempbx; (*i)--) {
491 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
492 Ext_InfoFlag;
cc1e2398
AK
493 if (infoflag & tempax)
494 return 1;
21df8fc8 495
cc1e2398
AK
496 if ((*i) == 0)
497 break;
21df8fc8 498 }
d7636e0b 499
cc1e2398 500 for ((*i) = 0;; (*i)++) {
1d7f656d
KT
501 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
502 Ext_InfoFlag;
cc1e2398
AK
503 if (pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID
504 != tempbx) {
505 return 0;
506 }
d7636e0b 507
cc1e2398
AK
508 if (infoflag & tempax)
509 return 1;
21df8fc8 510 }
cc1e2398 511 return 1;
d7636e0b 512}
513
cc1e2398 514static void XGI_SetSync(unsigned short RefreshRateTableIndex,
21df8fc8 515 struct vb_device_info *pVBInfo)
d7636e0b 516{
cc1e2398 517 unsigned short sync, temp;
d7636e0b 518
1d7f656d
KT
519 /* di+0x00 */
520 sync = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
cc1e2398
AK
521 sync &= 0xC0;
522 temp = 0x2F;
523 temp |= sync;
efdf4ee7 524 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
d7636e0b 525}
526
cc1e2398
AK
527static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
528 struct xgi_hw_device_info *HwDeviceExtension)
d7636e0b 529{
cc1e2398
AK
530 unsigned char data, data1, pushax;
531 unsigned short i, j;
d7636e0b 532
8104e329
AK
533 /* xgifb_reg_set(pVBInfo->P3d4, 0x51, 0); */
534 /* xgifb_reg_set(pVBInfo->P3d4, 0x56, 0); */
ec9e5d3e 535 /* xgifb_reg_and_or(pVBInfo->P3d4, 0x11, 0x7f, 0x00); */
d7636e0b 536
1d7f656d
KT
537 /* unlock cr0-7 */
538 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
cc1e2398 539 data &= 0x7F;
8104e329 540 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
cc1e2398
AK
541
542 data = pVBInfo->TimingH[0].data[0];
8104e329 543 xgifb_reg_set(pVBInfo->P3d4, 0, data);
cc1e2398
AK
544
545 for (i = 0x01; i <= 0x04; i++) {
546 data = pVBInfo->TimingH[0].data[i];
8104e329 547 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
21df8fc8 548 }
d7636e0b 549
cc1e2398
AK
550 for (i = 0x05; i <= 0x06; i++) {
551 data = pVBInfo->TimingH[0].data[i];
8104e329 552 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
cc1e2398 553 }
d7636e0b 554
58839b01 555 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
cc1e2398
AK
556 j &= 0x1F;
557 data = pVBInfo->TimingH[0].data[7];
558 data &= 0xE0;
559 data |= j;
8104e329 560 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
21df8fc8 561
cc1e2398 562 if (HwDeviceExtension->jChipType >= XG20) {
58839b01 563 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
cc1e2398 564 data = data - 1;
8104e329 565 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
58839b01 566 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
cc1e2398
AK
567 data1 = data;
568 data1 &= 0xE0;
569 data &= 0x1F;
570 if (data == 0) {
571 pushax = data;
58839b01 572 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
cc1e2398
AK
573 0x0c);
574 data &= 0xFB;
8104e329 575 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
cc1e2398 576 data = pushax;
21df8fc8 577 }
cc1e2398
AK
578 data = data - 1;
579 data |= data1;
8104e329 580 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
58839b01 581 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
cc1e2398
AK
582 data = data >> 5;
583 data = data + 3;
584 if (data > 7)
585 data = data - 7;
586 data = data << 5;
ec9e5d3e 587 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
21df8fc8 588 }
21df8fc8
PS
589}
590
1d7f656d
KT
591static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
592 unsigned short ModeNo,
593 struct vb_device_info *pVBInfo)
d7636e0b 594{
cc1e2398
AK
595 unsigned char data;
596 unsigned short i, j;
d7636e0b 597
8104e329
AK
598 /* xgifb_reg_set(pVBInfo->P3d4, 0x51, 0); */
599 /* xgifb_reg_set(pVBInfo->P3d4, 0x56, 0); */
ec9e5d3e 600 /* xgifb_reg_and_or(pVBInfo->P3d4, 0x11, 0x7f, 0x00); */
cc1e2398
AK
601
602 for (i = 0x00; i <= 0x01; i++) {
603 data = pVBInfo->TimingV[0].data[i];
8104e329 604 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
21df8fc8 605 }
d7636e0b 606
cc1e2398
AK
607 for (i = 0x02; i <= 0x03; i++) {
608 data = pVBInfo->TimingV[0].data[i];
8104e329 609 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
21df8fc8 610 }
d7636e0b 611
cc1e2398
AK
612 for (i = 0x04; i <= 0x05; i++) {
613 data = pVBInfo->TimingV[0].data[i];
8104e329 614 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
cc1e2398 615 }
d7636e0b 616
58839b01 617 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
cc1e2398
AK
618 j &= 0xC0;
619 data = pVBInfo->TimingV[0].data[6];
620 data &= 0x3F;
621 data |= j;
8104e329 622 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
d7636e0b 623
cc1e2398
AK
624 data = pVBInfo->TimingV[0].data[6];
625 data &= 0x80;
626 data = data >> 2;
d7636e0b 627
cc1e2398
AK
628 if (ModeNo <= 0x13)
629 i = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
630 else
631 i = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
d7636e0b 632
cc1e2398
AK
633 i &= DoubleScanMode;
634 if (i)
635 data |= 0x80;
d7636e0b 636
58839b01 637 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
cc1e2398
AK
638 j &= 0x5F;
639 data |= j;
8104e329 640 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
d7636e0b 641}
642
cc1e2398
AK
643static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
644 unsigned short RefreshRateTableIndex,
645 struct vb_device_info *pVBInfo,
646 struct xgi_hw_device_info *HwDeviceExtension)
21df8fc8 647{
cc1e2398
AK
648 unsigned char index, data;
649 unsigned short i;
21df8fc8 650
1d7f656d
KT
651 /* Get index */
652 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
cc1e2398 653 index = index & IndexMask;
21df8fc8 654
58839b01 655 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
cc1e2398 656 data &= 0x7F;
8104e329 657 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
21df8fc8 658
cc1e2398
AK
659 for (i = 0; i < 8; i++)
660 pVBInfo->TimingH[0].data[i]
661 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i];
21df8fc8 662
cc1e2398
AK
663 for (i = 0; i < 7; i++)
664 pVBInfo->TimingV[0].data[i]
665 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i + 8];
21df8fc8 666
cc1e2398 667 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
21df8fc8 668
cc1e2398 669 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
21df8fc8 670
cc1e2398 671 if (pVBInfo->ModeType > 0x03)
8104e329 672 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
21df8fc8
PS
673}
674
cc1e2398
AK
675/* --------------------------------------------------------------------- */
676/* Function : XGI_SetXG21CRTC */
677/* Input : Stand or enhance CRTC table */
678/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
679/* Description : Set LCD timing */
680/* --------------------------------------------------------------------- */
681static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
682 unsigned short RefreshRateTableIndex,
21df8fc8 683 struct vb_device_info *pVBInfo)
d7636e0b 684{
cc1e2398
AK
685 unsigned char StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
686 unsigned short Temp1, Temp2, Temp3;
21df8fc8 687
cc1e2398
AK
688 if (ModeNo <= 0x13) {
689 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
1d7f656d
KT
690 /* CR04 HRS */
691 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4];
692 /* SR2E [7:0]->HRS */
693 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
694 /* Tempbx: CR05 HRE */
695 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5];
cc1e2398
AK
696 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */
697 Tempcx = Tempax;
698 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */
699 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
700 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */
701 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */
702 Tempdx <<= 2; /* Tempdx << 2 */
1d7f656d
KT
703 /* SR2F [7:2]->HRE */
704 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx);
ec9e5d3e 705 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
21df8fc8 706
1d7f656d
KT
707 /* Tempax: CR16 VRS */
708 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16];
cc1e2398
AK
709 Tempbx = Tempax; /* Tempbx=Tempax */
710 Tempax &= 0x01; /* Tempax: VRS[0] */
b9bf6e4e 711 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS */
1d7f656d
KT
712
713 /* Tempax: CR7 VRS */
714 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7];
cc1e2398
AK
715 Tempdx = Tempbx >> 1; /* Tempdx: VRS[7:1] */
716 Tempcx = Tempax & 0x04; /* Tempcx: CR7[2] */
717 Tempcx <<= 5; /* Tempcx[7]: VRS[8] */
718 Tempdx |= Tempcx; /* Tempdx: VRS[8:1] */
1d7f656d
KT
719 /* SR34[7:0]: VRS[8:1] */
720 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempdx);
21df8fc8 721
1d7f656d
KT
722 /* Temp1[8]: VRS[8] unsigned char -> unsigned short */
723 Temp1 = Tempcx << 1;
cc1e2398
AK
724 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
725 Tempax &= 0x80; /* Tempax[7]: CR7[7] */
726 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
727 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
21df8fc8 728
1d7f656d
KT
729 /* CR16 VRE */
730 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17];
cc1e2398
AK
731 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
732 Temp2 = Temp1 & 0x3F0; /* Temp2[9:4]: VRS[9:4] */
733 Temp2 |= Tempax; /* Temp2[9:0]: VRE[9:0] */
734 Temp3 = Temp1 & 0x0F; /* Temp3[3:0]: VRS[3:0] */
735 if (Tempax < Temp3) /* VRE[3:0]<VRS[3:0] */
736 Temp2 |= 0x10; /* Temp2: VRE + 0x10 */
737 Temp2 &= 0xFF; /* Temp2[7:0]: VRE[7:0] */
738 Tempax = (unsigned char) Temp2; /* Tempax[7:0]: VRE[7:0] */
739 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */
740 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
741 Temp1 >>= 9; /* [10:9]->[1:0] */
742 Tempbx = (unsigned char) Temp1; /* Tempbx[1:0]: VRS[10:9] */
743 Tempax |= Tempbx; /* VRE[5:0]VRS[10:9] */
744 Tempax &= 0x7F;
1d7f656d
KT
745 /* SR3F D[7:2]->VRE D[1:0]->VRS */
746 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
cc1e2398
AK
747 } else {
748 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
1d7f656d
KT
749 /* Tempax: CR4 HRS */
750 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
cc1e2398 751 Tempcx = Tempax; /* Tempcx: HRS */
1d7f656d
KT
752 /* SR2E[7:0]->HRS */
753 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
21df8fc8 754
cc1e2398
AK
755 Tempdx = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SRB */
756 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
757 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
758 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
759 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
21df8fc8 760
cc1e2398
AK
761 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
762 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
21df8fc8 763
cc1e2398
AK
764 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
765 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
766 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
767 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
21df8fc8 768
cc1e2398
AK
769 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
770 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
21df8fc8 771
cc1e2398
AK
772 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
773 if (Tempax < Tempcx) /* HRE < HRS */
774 Temp2 |= 0x40; /* Temp2 + 0x40 */
21df8fc8 775
cc1e2398
AK
776 Temp2 &= 0xFF;
777 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
778 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
779 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
780 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
1d7f656d
KT
781 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
782 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
ec9e5d3e 783 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
21df8fc8 784
1d7f656d
KT
785 /* CR10 VRS */
786 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
cc1e2398
AK
787 Tempbx = Tempax; /* Tempbx: VRS */
788 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
b9bf6e4e 789 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
1d7f656d
KT
790 /* CR7[2][7] VRE */
791 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
cc1e2398
AK
792 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
793 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
794 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
795 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
8104e329 796 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
21df8fc8 797
cc1e2398
AK
798 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
799 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
800 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
801 Tempax &= 0x80;
802 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
803 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
1d7f656d
KT
804 /* Tempax: SRA */
805 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
cc1e2398
AK
806 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
807 Temp2 = Tempax;
808 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
809 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
21df8fc8 810
1d7f656d
KT
811 /* Tempax: CR11 VRE */
812 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
cc1e2398 813 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
1d7f656d
KT
814 /* Tempbx: SRA */
815 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
cc1e2398
AK
816 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
817 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
818 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
819 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
820 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
21df8fc8 821
cc1e2398
AK
822 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
823 if (Tempax < Temp3) /* VRE < VRS */
824 Temp2 |= 0x20; /* VRE + 0x20 */
d7636e0b 825
cc1e2398
AK
826 Temp2 &= 0xFF;
827 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
828 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
829 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
830 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
831 Tempbx = (unsigned char) Temp1;
832 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
833 Tempax &= 0x7F;
1d7f656d
KT
834 /* SR3F D[7:2]->VRE D[1:0]->VRS */
835 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
21df8fc8 836 }
d7636e0b 837}
838
1d7f656d
KT
839static void XGI_SetXG27CRTC(unsigned short ModeNo,
840 unsigned short ModeIdIndex,
841 unsigned short RefreshRateTableIndex,
842 struct vb_device_info *pVBInfo)
21df8fc8 843{
cc1e2398 844 unsigned short StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
21df8fc8 845
cc1e2398
AK
846 if (ModeNo <= 0x13) {
847 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
1d7f656d
KT
848 /* CR04 HRS */
849 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4];
850 /* SR2E [7:0]->HRS */
851 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
852 /* Tempbx: CR05 HRE */
853 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5];
cc1e2398
AK
854 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */
855 Tempcx = Tempax;
856 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */
857 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
858 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */
859 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */
860 Tempdx <<= 2; /* Tempdx << 2 */
1d7f656d
KT
861 /* SR2F [7:2]->HRE */
862 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx);
ec9e5d3e 863 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
d7636e0b 864
1d7f656d
KT
865 /* Tempax: CR10 VRS */
866 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16];
8104e329 867 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax); /* SR34[7:0]->VRS */
cc1e2398 868 Tempcx = Tempax; /* Tempcx=Tempax=VRS[7:0] */
1d7f656d
KT
869 /* Tempax[7][2]: CR7[7][2] VRS[9][8] */
870 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7];
cc1e2398
AK
871 Tempbx = Tempax; /* Tempbx=CR07 */
872 Tempax &= 0x04; /* Tempax[2]: CR07[2] VRS[8] */
873 Tempax >>= 2;
1d7f656d
KT
874 /* SR35 D[0]->VRS D[8] */
875 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
cc1e2398
AK
876 Tempcx |= (Tempax << 8); /* Tempcx[8] |= VRS[8] */
877 Tempcx |= (Tempbx & 0x80) << 2; /* Tempcx[9] |= VRS[9] */
d7636e0b 878
1d7f656d
KT
879 /* CR11 VRE */
880 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17];
cc1e2398
AK
881 Tempax &= 0x0F; /* Tempax: VRE[3:0] */
882 Tempbx = Tempcx; /* Tempbx=Tempcx=VRS[9:0] */
883 Tempbx &= 0x3F0; /* Tempbx[9:4]: VRS[9:4] */
884 Tempbx |= Tempax; /* Tempbx[9:0]: VRE[9:0] */
885 if (Tempax <= (Tempcx & 0x0F)) /* VRE[3:0]<=VRS[3:0] */
886 Tempbx |= 0x10; /* Tempbx: VRE + 0x10 */
1d7f656d
KT
887 /* Tempax[7:0]: VRE[7:0] */
888 Tempax = (unsigned char) Tempbx & 0xFF;
cc1e2398
AK
889 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */
890 Tempcx = (Tempcx & 0x600) >> 8; /* Tempcx VRS[10:9] */
1d7f656d
KT
891 /* SR3F D[7:2]->VRE D[5:0] */
892 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
893 /* SR35 D[2:1]->VRS[10:9] */
894 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x06, Tempcx);
cc1e2398
AK
895 } else {
896 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
1d7f656d
KT
897 /* Tempax: CR4 HRS */
898 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
cc1e2398 899 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
1d7f656d
KT
900 /* SR2E[7:0]->HRS */
901 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
d7636e0b 902
1d7f656d
KT
903 /* SR0B */
904 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5];
cc1e2398
AK
905 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
906 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
d7636e0b 907
cc1e2398
AK
908 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
909 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
910 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
d7636e0b 911
cc1e2398
AK
912 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
913 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
914 Tempax <<= 3; /* Tempax[5]: HRE[5] */
915 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
d7636e0b 916
cc1e2398
AK
917 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
918 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
d7636e0b 919
1d7f656d
KT
920 /* Tempax: CR4 HRS */
921 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
cc1e2398
AK
922 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
923 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
924 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
d7636e0b 925
cc1e2398
AK
926 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SR0B */
927 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
928 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
929 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
1d7f656d
KT
930 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
931 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
ec9e5d3e 932 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
d7636e0b 933
1d7f656d
KT
934 /* CR10 VRS */
935 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
936 /* SR34[7:0]->VRS[7:0] */
937 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
d7636e0b 938
cc1e2398 939 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
1d7f656d
KT
940 /* CR7[7][2] VRS[9][8] */
941 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
cc1e2398
AK
942 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
943 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
944 Tempax >>= 2; /* Tempax[0]: VRS[8] */
1d7f656d
KT
945 /* SR35[0]: VRS[8] */
946 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
cc1e2398
AK
947 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
948 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
1d7f656d
KT
949 /* Tempax: SR0A */
950 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
cc1e2398
AK
951 Tempax &= 0x08; /* SR0A[3] VRS[10] */
952 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
d7636e0b 953
1d7f656d
KT
954 /* Tempax: CR11 VRE */
955 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
cc1e2398 956 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
1d7f656d
KT
957 /* Tempbx: SR0A */
958 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
cc1e2398
AK
959 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
960 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
961 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
962 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
963 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
964 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
d7636e0b 965
cc1e2398
AK
966 if (Tempbx <= Tempcx) /* VRE <= VRS */
967 Tempbx |= 0x20; /* VRE + 0x20 */
d7636e0b 968
1d7f656d
KT
969 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
970 Tempax = (Tempbx << 2) & 0xFF;
971 /* SR3F[7:2]:VRE[5:0] */
972 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
cc1e2398 973 Tempax = Tempcx >> 8;
1d7f656d
KT
974 /* SR35[2:0]:VRS[10:8] */
975 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
21df8fc8 976 }
cc1e2398 977}
d7636e0b 978
a2d08cf3
AK
979static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
980{
981 unsigned char temp;
982
983 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
984 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
985 temp = (temp & 3) << 6;
986 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
987 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
988 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
989 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
990
991}
992
105d8d0d
AK
993static void xgifb_set_lcd(int chip_id,
994 struct vb_device_info *pVBInfo,
995 unsigned short RefreshRateTableIndex,
996 unsigned short ModeNo)
21df8fc8 997{
cc1e2398
AK
998 unsigned short Data, Temp, b3CC;
999 unsigned short XGI_P3cc;
21df8fc8 1000
cc1e2398 1001 XGI_P3cc = pVBInfo->P3cc;
21df8fc8 1002
8104e329
AK
1003 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
1004 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
1005 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
1006 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
21df8fc8 1007
105d8d0d
AK
1008 if (chip_id == XG27) {
1009 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
1010 if ((Temp & 0x03) == 0) { /* dual 12 */
1011 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
1012 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
1013 }
21df8fc8
PS
1014 }
1015
cc1e2398 1016 if (((*pVBInfo->pDVOSetting) & 0xC0) == 0xC0) {
8104e329
AK
1017 xgifb_reg_set(pVBInfo->P3d4, 0x2E, *pVBInfo->pCR2E);
1018 xgifb_reg_set(pVBInfo->P3d4, 0x2F, *pVBInfo->pCR2F);
1019 xgifb_reg_set(pVBInfo->P3d4, 0x46, *pVBInfo->pCR46);
1020 xgifb_reg_set(pVBInfo->P3d4, 0x47, *pVBInfo->pCR47);
21df8fc8
PS
1021 }
1022
105d8d0d
AK
1023 if (chip_id == XG27) {
1024 XGI_SetXG27FPBits(pVBInfo);
1025 } else {
1026 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
1027 if (Temp & 0x01) {
1028 /* 18 bits FP */
1029 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
1030 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
1031 }
1032 }
21df8fc8 1033
b9bf6e4e 1034 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
21df8fc8 1035
dc50556b
AK
1036 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
1037 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
21df8fc8 1038
cc1e2398 1039 if (ModeNo <= 0x13) {
d8ad0a6d 1040 b3CC = (unsigned char) inb(XGI_P3cc);
cc1e2398 1041 if (b3CC & 0x40)
1d7f656d
KT
1042 /* Hsync polarity */
1043 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
cc1e2398 1044 if (b3CC & 0x80)
1d7f656d
KT
1045 /* Vsync polarity */
1046 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
cc1e2398
AK
1047 } else {
1048 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1049 if (Data & 0x4000)
1d7f656d
KT
1050 /* Hsync polarity */
1051 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
cc1e2398 1052 if (Data & 0x8000)
1d7f656d
KT
1053 /* Vsync polarity */
1054 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
cc1e2398 1055 }
21df8fc8 1056}
d7636e0b 1057
1058/* --------------------------------------------------------------------- */
cc1e2398
AK
1059/* Function : XGI_UpdateXG21CRTC */
1060/* Input : */
1061/* Output : CRT1 CRTC */
1062/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
d7636e0b 1063/* --------------------------------------------------------------------- */
1d7f656d
KT
1064static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
1065 struct vb_device_info *pVBInfo,
1066 unsigned short RefreshRateTableIndex)
cc1e2398
AK
1067{
1068 int i, index = -1;
1069
dc50556b 1070 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
cc1e2398
AK
1071 if (ModeNo <= 0x13) {
1072 for (i = 0; i < 12; i++) {
1073 if (ModeNo == pVBInfo->UpdateCRT1[i].ModeID)
1074 index = i;
1075 }
1076 } else {
1d7f656d
KT
1077 if (ModeNo == 0x2E &&
1078 (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
1079 RES640x480x60))
cc1e2398 1080 index = 12;
1d7f656d
KT
1081 else if (ModeNo == 0x2E &&
1082 (pVBInfo->RefIndex[RefreshRateTableIndex].
1083 Ext_CRT1CRTC == RES640x480x72))
cc1e2398
AK
1084 index = 13;
1085 else if (ModeNo == 0x2F)
1086 index = 14;
1087 else if (ModeNo == 0x50)
1088 index = 15;
1089 else if (ModeNo == 0x59)
1090 index = 16;
1091 }
1092
1093 if (index != -1) {
8104e329 1094 xgifb_reg_set(pVBInfo->P3d4, 0x02,
cc1e2398 1095 pVBInfo->UpdateCRT1[index].CR02);
8104e329 1096 xgifb_reg_set(pVBInfo->P3d4, 0x03,
cc1e2398 1097 pVBInfo->UpdateCRT1[index].CR03);
8104e329 1098 xgifb_reg_set(pVBInfo->P3d4, 0x15,
cc1e2398 1099 pVBInfo->UpdateCRT1[index].CR15);
8104e329 1100 xgifb_reg_set(pVBInfo->P3d4, 0x16,
cc1e2398
AK
1101 pVBInfo->UpdateCRT1[index].CR16);
1102 }
1103}
1104
0646596c
AK
1105static unsigned short XGI_GetResInfo(unsigned short ModeNo,
1106 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
1107{
1108 unsigned short resindex;
1109
1110 if (ModeNo <= 0x13)
1111 /* si+St_ResInfo */
1112 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1113 else
1114 /* si+Ext_ResInfo */
1115 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1116 return resindex;
1117}
1118
cc1e2398
AK
1119static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
1120 unsigned short ModeNo, unsigned short ModeIdIndex,
21df8fc8
PS
1121 unsigned short RefreshRateTableIndex,
1122 struct vb_device_info *pVBInfo)
1123{
cc1e2398
AK
1124 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
1125
1126 unsigned char data;
1127
1128 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
21df8fc8
PS
1129
1130 if (ModeNo <= 0x13) {
cc1e2398
AK
1131 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1132 tempax = pVBInfo->StResInfo[resindex].HTotal;
1133 tempbx = pVBInfo->StResInfo[resindex].VTotal;
1134 } else {
1135 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1136 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
1137 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
1138 }
21df8fc8 1139
cc1e2398
AK
1140 if (modeflag & HalfDCLK)
1141 tempax = tempax >> 1;
21df8fc8 1142
cc1e2398
AK
1143 if (ModeNo > 0x13) {
1144 if (modeflag & HalfDCLK)
1145 tempax = tempax << 1;
21df8fc8 1146
cc1e2398 1147 temp = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
21df8fc8 1148
cc1e2398
AK
1149 if (temp & InterlaceMode)
1150 tempbx = tempbx >> 1;
21df8fc8 1151
cc1e2398
AK
1152 if (modeflag & DoubleScanMode)
1153 tempbx = tempbx << 1;
1154 }
21df8fc8 1155
cc1e2398 1156 tempcx = 8;
21df8fc8 1157
cc1e2398
AK
1158 /* if (!(modeflag & Charx8Dot)) */
1159 /* tempcx = 9; */
21df8fc8 1160
cc1e2398
AK
1161 tempax /= tempcx;
1162 tempax -= 1;
1163 tempbx -= 1;
1164 tempcx = tempax;
58839b01
AK
1165 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
1166 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
cc1e2398 1167 data &= 0x7F;
8104e329
AK
1168 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
1169 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
ec9e5d3e 1170 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
cc1e2398 1171 (unsigned short) ((tempcx & 0x0ff00) >> 10));
8104e329 1172 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
cc1e2398
AK
1173 tempax = 0;
1174 tempbx = tempbx >> 8;
21df8fc8 1175
cc1e2398
AK
1176 if (tempbx & 0x01)
1177 tempax |= 0x02;
21df8fc8 1178
cc1e2398
AK
1179 if (tempbx & 0x02)
1180 tempax |= 0x40;
21df8fc8 1181
ec9e5d3e 1182 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
58839b01 1183 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
cc1e2398
AK
1184 data &= 0xFF;
1185 tempax = 0;
21df8fc8 1186
cc1e2398
AK
1187 if (tempbx & 0x04)
1188 tempax |= 0x02;
21df8fc8 1189
ec9e5d3e 1190 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
8104e329 1191 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
cc1e2398 1192}
21df8fc8 1193
1d7f656d
KT
1194static void XGI_SetCRT1Offset(unsigned short ModeNo,
1195 unsigned short ModeIdIndex,
1196 unsigned short RefreshRateTableIndex,
1197 struct xgi_hw_device_info *HwDeviceExtension,
1198 struct vb_device_info *pVBInfo)
d7636e0b 1199{
cc1e2398 1200 unsigned short temp, ah, al, temp2, i, DisplayUnit;
21df8fc8 1201
cc1e2398
AK
1202 /* GetOffset */
1203 temp = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
1204 temp = temp >> 8;
1205 temp = pVBInfo->ScreenOffset[temp];
21df8fc8 1206
cc1e2398
AK
1207 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1208 temp2 &= InterlaceMode;
21df8fc8 1209
cc1e2398
AK
1210 if (temp2)
1211 temp = temp << 1;
21df8fc8 1212
cc1e2398 1213 temp2 = pVBInfo->ModeType - ModeEGA;
21df8fc8 1214
cc1e2398
AK
1215 switch (temp2) {
1216 case 0:
1217 temp2 = 1;
1218 break;
1219 case 1:
1220 temp2 = 2;
1221 break;
1222 case 2:
1223 temp2 = 4;
1224 break;
1225 case 3:
1226 temp2 = 4;
1227 break;
1228 case 4:
1229 temp2 = 6;
1230 break;
1231 case 5:
1232 temp2 = 8;
1233 break;
1234 default:
1235 break;
1236 }
21df8fc8 1237
cc1e2398
AK
1238 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
1239 temp = temp * temp2 + temp2 / 2;
1240 else
1241 temp *= temp2;
21df8fc8 1242
cc1e2398
AK
1243 /* SetOffset */
1244 DisplayUnit = temp;
1245 temp2 = temp;
1246 temp = temp >> 8; /* ah */
1247 temp &= 0x0F;
58839b01 1248 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
cc1e2398
AK
1249 i &= 0xF0;
1250 i |= temp;
8104e329 1251 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
21df8fc8 1252
cc1e2398
AK
1253 temp = (unsigned char) temp2;
1254 temp &= 0xFF; /* al */
8104e329 1255 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
21df8fc8 1256
cc1e2398
AK
1257 /* SetDisplayUnit */
1258 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1259 temp2 &= InterlaceMode;
1260 if (temp2)
1261 DisplayUnit >>= 1;
21df8fc8 1262
cc1e2398
AK
1263 DisplayUnit = DisplayUnit << 5;
1264 ah = (DisplayUnit & 0xff00) >> 8;
1265 al = DisplayUnit & 0x00ff;
1266 if (al == 0)
1267 ah += 1;
1268 else
1269 ah += 2;
21df8fc8 1270
cc1e2398
AK
1271 if (HwDeviceExtension->jChipType >= XG20)
1272 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
1273 ah -= 1;
21df8fc8 1274
8104e329 1275 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
d7636e0b 1276}
1277
cc1e2398
AK
1278static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
1279 unsigned short ModeIdIndex,
1280 unsigned short RefreshRateTableIndex,
1281 struct xgi_hw_device_info *HwDeviceExtension,
1282 struct vb_device_info *pVBInfo)
d7636e0b 1283{
1d7f656d
KT
1284 unsigned short LCDXlat1VCLK[4] = { VCLK65 + 2,
1285 VCLK65 + 2,
1286 VCLK65 + 2,
1287 VCLK65 + 2 };
1288 unsigned short LCDXlat2VCLK[4] = { VCLK108_2 + 5,
1289 VCLK108_2 + 5,
1290 VCLK108_2 + 5,
1291 VCLK108_2 + 5 };
cc1e2398 1292 unsigned short LVDSXlat1VCLK[4] = { VCLK40, VCLK40, VCLK40, VCLK40 };
1d7f656d
KT
1293 unsigned short LVDSXlat2VCLK[4] = { VCLK65 + 2,
1294 VCLK65 + 2,
1295 VCLK65 + 2,
1296 VCLK65 + 2 };
1297 unsigned short LVDSXlat3VCLK[4] = { VCLK65 + 2,
1298 VCLK65 + 2,
1299 VCLK65 + 2,
1300 VCLK65 + 2 };
21df8fc8 1301
cc1e2398
AK
1302 unsigned short CRT2Index, VCLKIndex;
1303 unsigned short modeflag, resinfo;
21df8fc8
PS
1304
1305 if (ModeNo <= 0x13) {
1d7f656d
KT
1306 /* si+St_ResInfo */
1307 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
cc1e2398
AK
1308 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1309 CRT2Index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
21df8fc8 1310 } else {
1d7f656d
KT
1311 /* si+Ext_ResInfo */
1312 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
cc1e2398 1313 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1d7f656d
KT
1314 CRT2Index = pVBInfo->RefIndex[RefreshRateTableIndex].
1315 Ext_CRT2CRTC;
21df8fc8 1316 }
21df8fc8 1317
cc1e2398
AK
1318 if (pVBInfo->IF_DEF_LVDS == 0) {
1319 CRT2Index = CRT2Index >> 6; /* for LCD */
1320 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /*301b*/
1321 if (pVBInfo->LCDResInfo != Panel1024x768)
1322 VCLKIndex = LCDXlat2VCLK[CRT2Index];
1323 else
1324 VCLKIndex = LCDXlat1VCLK[CRT2Index];
1325 } else { /* for TV */
1326 if (pVBInfo->VBInfo & SetCRT2ToTV) {
1327 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
1328 if (pVBInfo->SetFlag & RPLLDIV2XO) {
1329 VCLKIndex = HiTVVCLKDIV2;
cc1e2398 1330 VCLKIndex += 25;
cc1e2398
AK
1331 } else {
1332 VCLKIndex = HiTVVCLK;
cc1e2398 1333 VCLKIndex += 25;
cc1e2398 1334 }
21df8fc8 1335
cc1e2398
AK
1336 if (pVBInfo->SetFlag & TVSimuMode) {
1337 if (modeflag & Charx8Dot) {
1d7f656d
KT
1338 VCLKIndex =
1339 HiTVSimuVCLK;
cc1e2398 1340 VCLKIndex += 25;
cc1e2398 1341 } else {
1d7f656d
KT
1342 VCLKIndex =
1343 HiTVTextVCLK;
cc1e2398 1344 VCLKIndex += 25;
cc1e2398
AK
1345 }
1346 }
21df8fc8 1347
1d7f656d
KT
1348 /* 301lv */
1349 if (pVBInfo->VBType & VB_XGI301LV) {
1350 if (!(pVBInfo->VBExtInfo ==
1351 VB_YPbPr1080i)) {
1352 VCLKIndex =
1353 YPbPr750pVCLK;
cc1e2398 1354 if (!(pVBInfo->VBExtInfo
1d7f656d
KT
1355 ==
1356 VB_YPbPr750p)) {
1357 VCLKIndex =
1358 YPbPr525pVCLK;
cc1e2398
AK
1359 if (!(pVBInfo->VBExtInfo
1360 == VB_YPbPr525p)) {
1361 VCLKIndex
1362 = YPbPr525iVCLK_2;
1363 if (!(pVBInfo->SetFlag
1364 & RPLLDIV2XO))
1365 VCLKIndex
1366 = YPbPr525iVCLK;
1367 }
1368 }
1369 }
1370 }
1371 } else {
1372 if (pVBInfo->VBInfo & SetCRT2ToTV) {
1d7f656d
KT
1373 if (pVBInfo->SetFlag &
1374 RPLLDIV2XO) {
cc1e2398 1375 VCLKIndex = TVVCLKDIV2;
cc1e2398 1376 VCLKIndex += 25;
cc1e2398
AK
1377 } else {
1378 VCLKIndex = TVVCLK;
cc1e2398 1379 VCLKIndex += 25;
cc1e2398
AK
1380 }
1381 }
1382 }
1383 } else { /* for CRT2 */
1d7f656d 1384 /* Port 3cch */
d8ad0a6d 1385 VCLKIndex = (unsigned char) inb(
1d7f656d 1386 (pVBInfo->P3ca + 0x02));
cc1e2398
AK
1387 VCLKIndex = ((VCLKIndex >> 2) & 0x03);
1388 if (ModeNo > 0x13) {
1d7f656d
KT
1389 /* di+Ext_CRTVCLK */
1390 VCLKIndex =
1391 pVBInfo->RefIndex[
1392 RefreshRateTableIndex].
1393 Ext_CRTVCLK;
cc1e2398
AK
1394 VCLKIndex &= IndexMask;
1395 }
1396 }
1397 }
1398 } else { /* LVDS */
1399 if (ModeNo <= 0x13)
1400 VCLKIndex = CRT2Index;
1401 else
1402 VCLKIndex = CRT2Index;
21df8fc8 1403
4c14bfd4
AK
1404 VCLKIndex = VCLKIndex >> 6;
1405 if ((pVBInfo->LCDResInfo == Panel800x600) ||
1406 (pVBInfo->LCDResInfo == Panel320x480))
1407 VCLKIndex = LVDSXlat1VCLK[VCLKIndex];
1408 else if ((pVBInfo->LCDResInfo == Panel1024x768) ||
1409 (pVBInfo->LCDResInfo == Panel1024x768x75))
1410 VCLKIndex = LVDSXlat2VCLK[VCLKIndex];
1411 else
1412 VCLKIndex = LVDSXlat3VCLK[VCLKIndex];
21df8fc8 1413 }
cc1e2398 1414 /* VCLKIndex = VCLKIndex&IndexMask; */
d7636e0b 1415
cc1e2398 1416 return VCLKIndex;
21df8fc8 1417}
d7636e0b 1418
1d7f656d
KT
1419static void XGI_SetCRT1VCLK(unsigned short ModeNo,
1420 unsigned short ModeIdIndex,
1421 struct xgi_hw_device_info *HwDeviceExtension,
1422 unsigned short RefreshRateTableIndex,
1423 struct vb_device_info *pVBInfo)
d7636e0b 1424{
108afbf8 1425 unsigned char index, data;
21df8fc8
PS
1426 unsigned short vclkindex;
1427
1428 if (pVBInfo->IF_DEF_LVDS == 1) {
1429 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
58839b01 1430 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
8104e329
AK
1431 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1432 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
21df8fc8 1433 pVBInfo->VCLKData[index].SR2B);
8104e329 1434 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
21df8fc8 1435 pVBInfo->VCLKData[index].SR2C);
8104e329 1436 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
21df8fc8
PS
1437 } else if ((pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
1438 | VB_XGI302LV | VB_XGI301C)) && (pVBInfo->VBInfo
1439 & SetCRT2ToLCDA)) {
1440 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
1441 RefreshRateTableIndex, HwDeviceExtension,
1442 pVBInfo);
58839b01 1443 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
8104e329 1444 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
21df8fc8 1445 data = pVBInfo->VBVCLKData[vclkindex].Part4_A;
8104e329 1446 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
21df8fc8 1447 data = pVBInfo->VBVCLKData[vclkindex].Part4_B;
8104e329
AK
1448 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1449 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
21df8fc8
PS
1450 } else {
1451 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
58839b01 1452 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
8104e329
AK
1453 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1454 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
21df8fc8 1455 pVBInfo->VCLKData[index].SR2B);
8104e329 1456 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
21df8fc8 1457 pVBInfo->VCLKData[index].SR2C);
8104e329 1458 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
21df8fc8 1459 }
d7636e0b 1460
21df8fc8 1461 if (HwDeviceExtension->jChipType >= XG20) {
1d7f656d
KT
1462 if (pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag &
1463 HalfDCLK) {
58839b01 1464 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
8104e329 1465 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
58839b01 1466 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
21df8fc8
PS
1467 index = data;
1468 index &= 0xE0;
1469 data &= 0x1F;
1470 data = data << 1;
1471 data += 1;
1472 data |= index;
8104e329 1473 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
21df8fc8
PS
1474 }
1475 }
1476}
d7636e0b 1477
e85f2036
AK
1478static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
1479{
1480 unsigned char temp;
1481
1482 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
1483 temp = (temp & 1) << 6;
1484 /* SR06[6] 18bit Dither */
1485 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
1486 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
1487 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
1488
1489}
1490
063b9c4b 1491static void XGI_SetCRT1FIFO(unsigned short ModeNo,
21df8fc8
PS
1492 struct xgi_hw_device_info *HwDeviceExtension,
1493 struct vb_device_info *pVBInfo)
1494{
1495 unsigned short data;
1496
58839b01 1497 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
21df8fc8 1498 data &= 0xfe;
8104e329 1499 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
21df8fc8
PS
1500
1501 if (ModeNo > 0x13) {
8104e329 1502 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
58839b01 1503 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
21df8fc8 1504 data &= 0xC0;
8104e329 1505 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
58839b01 1506 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
21df8fc8 1507 data |= 0x01;
8104e329 1508 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
21df8fc8
PS
1509 } else {
1510 if (HwDeviceExtension->jChipType == XG27) {
8104e329 1511 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x0E);
58839b01 1512 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
21df8fc8 1513 data &= 0xC0;
8104e329 1514 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x20);
21df8fc8 1515 } else {
8104e329 1516 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0xAE);
58839b01 1517 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
21df8fc8 1518 data &= 0xF0;
8104e329 1519 xgifb_reg_set(pVBInfo->P3c4, 0x09, data);
21df8fc8
PS
1520 }
1521 }
d7636e0b 1522
21df8fc8
PS
1523 if (HwDeviceExtension->jChipType == XG21)
1524 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
1525}
d7636e0b 1526
cc1e2398
AK
1527static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1528 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
21df8fc8
PS
1529 struct vb_device_info *pVBInfo)
1530{
cc1e2398
AK
1531 unsigned short data, data2 = 0;
1532 short VCLK;
d7636e0b 1533
cc1e2398 1534 unsigned char index;
d7636e0b 1535
cc1e2398
AK
1536 if (ModeNo <= 0x13)
1537 VCLK = 0;
1538 else {
1539 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1540 index &= IndexMask;
1541 VCLK = pVBInfo->VCLKData[index].CLOCK;
1542 }
d7636e0b 1543
58839b01 1544 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
cc1e2398
AK
1545 data &= 0xf3;
1546 if (VCLK >= 200)
1547 data |= 0x0c; /* VCLK > 200 */
d7636e0b 1548
cc1e2398
AK
1549 if (HwDeviceExtension->jChipType >= XG20)
1550 data &= ~0x04; /* 2 pixel mode */
d7636e0b 1551
8104e329 1552 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
cc1e2398
AK
1553
1554 if (HwDeviceExtension->jChipType < XG20) {
58839b01 1555 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
cc1e2398
AK
1556 data &= 0xE7;
1557 if (VCLK < 200)
1558 data |= 0x10;
8104e329 1559 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
cc1e2398
AK
1560 }
1561
1562 /* Jong for Adavantech LCD ripple issue
1563 if ((VCLK >= 0) && (VCLK < 135))
1564 data2 = 0x03;
1565 else if ((VCLK >= 135) && (VCLK < 160))
1566 data2 = 0x02;
1567 else if ((VCLK >= 160) && (VCLK < 260))
1568 data2 = 0x01;
1569 else if (VCLK > 260)
1570 data2 = 0x00;
1571 */
1572 data2 = 0x00;
1573
ec9e5d3e 1574 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
cc1e2398 1575 if (HwDeviceExtension->jChipType >= XG27)
ec9e5d3e 1576 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
cc1e2398
AK
1577
1578}
1579
1580static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
1581 unsigned short ModeNo, unsigned short ModeIdIndex,
1582 unsigned short RefreshRateTableIndex,
1583 struct vb_device_info *pVBInfo)
1584{
1585 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1586 xres;
1587
1588 if (ModeNo > 0x13) {
1589 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1d7f656d
KT
1590 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].
1591 Ext_InfoFlag;
cc1e2398 1592 } else
1d7f656d
KT
1593 /* si+St_ModeFlag */
1594 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
cc1e2398 1595
58839b01 1596 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
ec9e5d3e 1597 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
cc1e2398
AK
1598
1599 if (ModeNo > 0x13)
1600 data = infoflag;
1601 else
1602 data = 0;
1603
1604 data2 = 0;
1605
1606 if (ModeNo > 0x13) {
1607 if (pVBInfo->ModeType > 0x02) {
1608 data2 |= 0x02;
1609 data3 = pVBInfo->ModeType - ModeVGA;
1610 data3 = data3 << 2;
1611 data2 |= data3;
1612 }
21df8fc8 1613 }
d7636e0b 1614
21df8fc8 1615 data &= InterlaceMode;
d7636e0b 1616
21df8fc8
PS
1617 if (data)
1618 data2 |= 0x20;
d7636e0b 1619
ec9e5d3e 1620 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
8104e329 1621 /* xgifb_reg_set(pVBInfo->P3c4,0x06,data2); */
21df8fc8
PS
1622 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
1623 if (ModeNo <= 0x13)
1624 xres = pVBInfo->StResInfo[resindex].HTotal;
1625 else
1626 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
1627
1628 data = 0x0000;
1629 if (infoflag & InterlaceMode) {
1630 if (xres == 1024)
1631 data = 0x0035;
1632 else if (xres == 1280)
1633 data = 0x0048;
1634 }
d7636e0b 1635
21df8fc8 1636 data2 = data & 0x00FF;
ec9e5d3e 1637 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
21df8fc8 1638 data2 = (data & 0xFF00) >> 8;
ec9e5d3e 1639 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
d7636e0b 1640
21df8fc8 1641 if (modeflag & HalfDCLK)
ec9e5d3e 1642 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
21df8fc8
PS
1643
1644 data2 = 0;
1645
1646 if (modeflag & LineCompareOff)
1647 data2 |= 0x08;
1648
1649 if (ModeNo > 0x13) {
1650 if (pVBInfo->ModeType == ModeEGA)
1651 data2 |= 0x40;
1652 }
1653
ec9e5d3e 1654 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
21df8fc8
PS
1655 data = 0x60;
1656 if (pVBInfo->ModeType != ModeText) {
1657 data = data ^ 0x60;
1658 if (pVBInfo->ModeType != ModeEGA)
1659 data = data ^ 0xA0;
1660 }
ec9e5d3e 1661 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
21df8fc8
PS
1662
1663 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1664 pVBInfo);
1665
1666 /* if (modeflag&HalfDCLK) //030305 fix lowresolution bug */
1667 /* if (XGINew_IF_DEF_NEW_LOWRES) */
1d7f656d
KT
1668 /* XGI_VesaLowResolution(ModeNo, ModeIdIndex);
1669 * //030305 fix lowresolution bug */
21df8fc8 1670
58839b01 1671 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
21df8fc8
PS
1672
1673 if (HwDeviceExtension->jChipType == XG27) {
1674 if (data & 0x40)
1675 data = 0x2c;
1676 else
1677 data = 0x6c;
8104e329 1678 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
b9bf6e4e 1679 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
21df8fc8
PS
1680 } else if (HwDeviceExtension->jChipType >= XG20) {
1681 if (data & 0x40)
1682 data = 0x33;
1683 else
1684 data = 0x73;
8104e329
AK
1685 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1686 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
21df8fc8
PS
1687 } else {
1688 if (data & 0x40)
1689 data = 0x2c;
1690 else
1691 data = 0x6c;
8104e329 1692 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
21df8fc8 1693 }
d7636e0b 1694
d7636e0b 1695}
1696
1d7f656d
KT
1697static void XGI_WriteDAC(unsigned short dl,
1698 unsigned short ah,
1699 unsigned short al,
1700 unsigned short dh,
1701 struct vb_device_info *pVBInfo)
cc1e2398
AK
1702{
1703 unsigned short temp, bh, bl;
1704
1705 bh = ah;
1706 bl = al;
1707
1708 if (dl != 0) {
1709 temp = bh;
1710 bh = dh;
1711 dh = temp;
1712 if (dl == 1) {
1713 temp = bl;
1714 bl = dh;
1715 dh = temp;
1716 } else {
1717 temp = bl;
1718 bl = bh;
1719 bh = temp;
1720 }
1721 }
efdf4ee7
AK
1722 outb((unsigned short) dh, pVBInfo->P3c9);
1723 outb((unsigned short) bh, pVBInfo->P3c9);
1724 outb((unsigned short) bl, pVBInfo->P3c9);
cc1e2398
AK
1725}
1726
063b9c4b 1727static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
21df8fc8
PS
1728 struct vb_device_info *pVBInfo)
1729{
1730 unsigned short data, data2, time, i, j, k, m, n, o, si, di, bx, dl, al,
624554da
AK
1731 ah, dh;
1732 const unsigned short *table = NULL;
d7636e0b 1733
21df8fc8
PS
1734 if (ModeNo <= 0x13)
1735 data = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1736 else
1737 data = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1738
1739 data &= DACInfoFlag;
1740 time = 64;
1741
1742 if (data == 0x00)
1743 table = XGINew_MDA_DAC;
1744 else if (data == 0x08)
1745 table = XGINew_CGA_DAC;
1746 else if (data == 0x10)
1747 table = XGINew_EGA_DAC;
1748 else if (data == 0x18) {
1749 time = 256;
1750 table = XGINew_VGA_DAC;
1751 }
d7636e0b 1752
21df8fc8
PS
1753 if (time == 256)
1754 j = 16;
1755 else
1756 j = time;
d7636e0b 1757
efdf4ee7
AK
1758 outb(0xFF, pVBInfo->P3c6);
1759 outb(0x00, pVBInfo->P3c8);
d7636e0b 1760
21df8fc8
PS
1761 for (i = 0; i < j; i++) {
1762 data = table[i];
d7636e0b 1763
21df8fc8
PS
1764 for (k = 0; k < 3; k++) {
1765 data2 = 0;
d7636e0b 1766
21df8fc8
PS
1767 if (data & 0x01)
1768 data2 = 0x2A;
d7636e0b 1769
21df8fc8
PS
1770 if (data & 0x02)
1771 data2 += 0x15;
d7636e0b 1772
efdf4ee7 1773 outb(data2, pVBInfo->P3c9);
21df8fc8
PS
1774 data = data >> 2;
1775 }
1776 }
d7636e0b 1777
21df8fc8
PS
1778 if (time == 256) {
1779 for (i = 16; i < 32; i++) {
1780 data = table[i];
1781
1782 for (k = 0; k < 3; k++)
efdf4ee7 1783 outb(data, pVBInfo->P3c9);
21df8fc8
PS
1784 }
1785
1786 si = 32;
1787
1788 for (m = 0; m < 9; m++) {
1789 di = si;
1790 bx = si + 0x04;
1791 dl = 0;
1792
1793 for (n = 0; n < 3; n++) {
1794 for (o = 0; o < 5; o++) {
1795 dh = table[si];
1796 ah = table[di];
1797 al = table[bx];
1798 si++;
1799 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1800 }
1801
1802 si -= 2;
1803
1804 for (o = 0; o < 3; o++) {
1805 dh = table[bx];
1806 ah = table[di];
1807 al = table[si];
1808 si--;
1809 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1810 }
1811
1812 dl++;
1813 }
1814
1815 si += 5;
1816 }
1817 }
1818}
d7636e0b 1819
1d7f656d
KT
1820static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1821 unsigned short ModeIdIndex,
1822 struct vb_device_info *pVBInfo)
21df8fc8
PS
1823{
1824 unsigned short resindex, xres, yres, modeflag;
d7636e0b 1825
21df8fc8 1826 if (ModeNo <= 0x13)
1d7f656d
KT
1827 /* si+St_ResInfo */
1828 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
21df8fc8 1829 else
1d7f656d
KT
1830 /* si+Ext_ResInfo */
1831 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
d7636e0b 1832
21df8fc8
PS
1833 /* if (ModeNo > 0x13) */
1834 /* modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag; */
1835 /* else */
1836 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; */
d7636e0b 1837
21df8fc8 1838 if (ModeNo <= 0x13)
1d7f656d
KT
1839 /* si+St_ResInfo */
1840 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
21df8fc8 1841 else
1d7f656d
KT
1842 /* si+Ext_ResInfo */
1843 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
d7636e0b 1844
21df8fc8 1845 /* resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo); */
d7636e0b 1846
21df8fc8
PS
1847 if (ModeNo <= 0x13) {
1848 xres = pVBInfo->StResInfo[resindex].HTotal;
1849 yres = pVBInfo->StResInfo[resindex].VTotal;
1850 } else {
1851 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1852 yres = pVBInfo->ModeResInfo[resindex].VTotal;
1853 }
1854 if (ModeNo > 0x13) {
1855 if (modeflag & HalfDCLK)
1856 xres = xres << 1;
d7636e0b 1857
21df8fc8
PS
1858 if (modeflag & DoubleScanMode)
1859 yres = yres << 1;
1860 }
1861 /* if (modeflag & Charx8Dot) */
1862 /* { */
d7636e0b 1863
21df8fc8
PS
1864 if (xres == 720)
1865 xres = 640;
d7636e0b 1866
21df8fc8
PS
1867 /* } */
1868 pVBInfo->VGAHDE = xres;
1869 pVBInfo->HDE = xres;
1870 pVBInfo->VGAVDE = yres;
1871 pVBInfo->VDE = yres;
1872}
d7636e0b 1873
cc1e2398
AK
1874static void *XGI_GetLcdPtr(unsigned short BX, unsigned short ModeNo,
1875 unsigned short ModeIdIndex,
21df8fc8
PS
1876 unsigned short RefreshRateTableIndex,
1877 struct vb_device_info *pVBInfo)
1878{
cc1e2398 1879 unsigned short i, tempdx, tempcx, tempbx, tempal, modeflag, table;
d7636e0b 1880
cc1e2398 1881 struct XGI330_LCDDataTablStruct *tempdi = NULL;
d7636e0b 1882
cc1e2398
AK
1883 tempbx = BX;
1884
1885 if (ModeNo <= 0x13) {
1886 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1887 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1888 } else {
1889 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1890 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
21df8fc8 1891 }
cc1e2398
AK
1892
1893 tempal = tempal & 0x0f;
1894
1895 if (tempbx <= 1) { /* ExpLink */
1896 if (ModeNo <= 0x13) {
1d7f656d
KT
1897 /* find no Ext_CRT2CRTC2 */
1898 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
cc1e2398 1899 } else {
1d7f656d
KT
1900 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].
1901 Ext_CRT2CRTC;
21df8fc8 1902 }
d7636e0b 1903
cc1e2398
AK
1904 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
1905 if (ModeNo <= 0x13)
1d7f656d
KT
1906 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
1907 St_CRT2CRTC2;
cc1e2398 1908 else
1d7f656d
KT
1909 tempal = pVBInfo->RefIndex[
1910 RefreshRateTableIndex].
1911 Ext_CRT2CRTC2;
21df8fc8 1912 }
d7636e0b 1913
cc1e2398
AK
1914 if (tempbx & 0x01)
1915 tempal = (tempal >> 4);
21df8fc8 1916
cc1e2398
AK
1917 tempal = (tempal & 0x0f);
1918 }
21df8fc8 1919
cc1e2398 1920 tempcx = LCDLenList[tempbx]; /* mov cl,byte ptr cs:LCDLenList[bx] */
21df8fc8 1921
cc1e2398
AK
1922 if (pVBInfo->LCDInfo & EnableScalingLCD) { /* ScaleLCD */
1923 if ((tempbx == 5) || (tempbx) == 7)
1924 tempcx = LCDDesDataLen2;
1925 else if ((tempbx == 3) || (tempbx == 8))
1926 tempcx = LVDSDesDataLen2;
1927 }
1928 /* mov di, word ptr cs:LCDDataList[bx] */
1d7f656d
KT
1929 /* tempdi = pVideoMemory[LCDDataList + tempbx * 2] |
1930 (pVideoMemory[LCDDataList + tempbx * 2 + 1] << 8); */
21df8fc8 1931
cc1e2398
AK
1932 switch (tempbx) {
1933 case 0:
cc1e2398 1934 case 1:
cc5c2aeb 1935 tempdi = xgifb_epllcd_crt1;
cc1e2398
AK
1936 break;
1937 case 2:
1938 tempdi = XGI_EPLLCDDataPtr;
1939 break;
1940 case 3:
1941 tempdi = XGI_EPLLCDDesDataPtr;
1942 break;
1943 case 4:
1944 tempdi = XGI_LCDDataTable;
1945 break;
1946 case 5:
1947 tempdi = XGI_LCDDesDataTable;
1948 break;
1949 case 6:
1950 tempdi = XGI_EPLCHLCDRegPtr;
1951 break;
1952 case 7:
1953 case 8:
1954 case 9:
1955 tempdi = NULL;
1956 break;
1957 default:
1958 break;
1959 }
21df8fc8 1960
cc1e2398
AK
1961 if (tempdi == NULL) /* OEMUtil */
1962 return NULL;
21df8fc8 1963
cc1e2398
AK
1964 table = tempbx;
1965 i = 0;
21df8fc8 1966
cc1e2398
AK
1967 while (tempdi[i].PANELID != 0xff) {
1968 tempdx = pVBInfo->LCDResInfo;
1969 if (tempbx & 0x0080) { /* OEMUtil */
1970 tempbx &= (~0x0080);
1971 tempdx = pVBInfo->LCDTypeInfo;
21df8fc8
PS
1972 }
1973
cc1e2398
AK
1974 if (pVBInfo->LCDInfo & EnableScalingLCD)
1975 tempdx &= (~PanelResInfo);
21df8fc8 1976
cc1e2398
AK
1977 if (tempdi[i].PANELID == tempdx) {
1978 tempbx = tempdi[i].MASK;
1979 tempdx = pVBInfo->LCDInfo;
21df8fc8 1980
cc1e2398
AK
1981 if (ModeNo <= 0x13) /* alan 09/10/2003 */
1982 tempdx |= SetLCDStdMode;
21df8fc8 1983
cc1e2398
AK
1984 if (modeflag & HalfDCLK)
1985 tempdx |= SetLCDLowResolution;
21df8fc8 1986
cc1e2398
AK
1987 tempbx &= tempdx;
1988 if (tempbx == tempdi[i].CAP)
1989 break;
21df8fc8 1990 }
cc1e2398
AK
1991 i++;
1992 }
21df8fc8 1993
cc1e2398
AK
1994 if (table == 0) {
1995 switch (tempdi[i].DATAPTR) {
1996 case 0:
1997 return &XGI_LVDSCRT11024x768_1_H[tempal];
1998 break;
1999 case 1:
2000 return &XGI_LVDSCRT11024x768_2_H[tempal];
2001 break;
2002 case 2:
2003 return &XGI_LVDSCRT11280x1024_1_H[tempal];
2004 break;
2005 case 3:
2006 return &XGI_LVDSCRT11280x1024_2_H[tempal];
2007 break;
2008 case 4:
2009 return &XGI_LVDSCRT11400x1050_1_H[tempal];
2010 break;
2011 case 5:
2012 return &XGI_LVDSCRT11400x1050_2_H[tempal];
2013 break;
2014 case 6:
2015 return &XGI_LVDSCRT11600x1200_1_H[tempal];
2016 break;
2017 case 7:
2018 return &XGI_LVDSCRT11024x768_1_Hx75[tempal];
2019 break;
2020 case 8:
2021 return &XGI_LVDSCRT11024x768_2_Hx75[tempal];
2022 break;
2023 case 9:
2024 return &XGI_LVDSCRT11280x1024_1_Hx75[tempal];
2025 break;
2026 case 10:
2027 return &XGI_LVDSCRT11280x1024_2_Hx75[tempal];
2028 break;
2029 default:
2030 break;
21df8fc8 2031 }
cc1e2398
AK
2032 } else if (table == 1) {
2033 switch (tempdi[i].DATAPTR) {
2034 case 0:
2035 return &XGI_LVDSCRT11024x768_1_V[tempal];
2036 break;
2037 case 1:
2038 return &XGI_LVDSCRT11024x768_2_V[tempal];
2039 break;
2040 case 2:
2041 return &XGI_LVDSCRT11280x1024_1_V[tempal];
2042 break;
2043 case 3:
2044 return &XGI_LVDSCRT11280x1024_2_V[tempal];
2045 break;
2046 case 4:
2047 return &XGI_LVDSCRT11400x1050_1_V[tempal];
2048 break;
2049 case 5:
2050 return &XGI_LVDSCRT11400x1050_2_V[tempal];
2051 break;
2052 case 6:
2053 return &XGI_LVDSCRT11600x1200_1_V[tempal];
2054 break;
2055 case 7:
2056 return &XGI_LVDSCRT11024x768_1_Vx75[tempal];
2057 break;
2058 case 8:
2059 return &XGI_LVDSCRT11024x768_2_Vx75[tempal];
2060 break;
2061 case 9:
2062 return &XGI_LVDSCRT11280x1024_1_Vx75[tempal];
2063 break;
2064 case 10:
2065 return &XGI_LVDSCRT11280x1024_2_Vx75[tempal];
2066 break;
2067 default:
2068 break;
21df8fc8 2069 }
cc1e2398
AK
2070 } else if (table == 2) {
2071 switch (tempdi[i].DATAPTR) {
2072 case 0:
2073 return &XGI_LVDS1024x768Data_1[tempal];
2074 break;
2075 case 1:
2076 return &XGI_LVDS1024x768Data_2[tempal];
2077 break;
2078 case 2:
2079 return &XGI_LVDS1280x1024Data_1[tempal];
2080 break;
2081 case 3:
2082 return &XGI_LVDS1280x1024Data_2[tempal];
2083 break;
2084 case 4:
2085 return &XGI_LVDS1400x1050Data_1[tempal];
2086 break;
2087 case 5:
2088 return &XGI_LVDS1400x1050Data_2[tempal];
2089 break;
2090 case 6:
2091 return &XGI_LVDS1600x1200Data_1[tempal];
2092 break;
2093 case 7:
2094 return &XGI_LVDSNoScalingData[tempal];
2095 break;
2096 case 8:
2097 return &XGI_LVDS1024x768Data_1x75[tempal];
2098 break;
2099 case 9:
2100 return &XGI_LVDS1024x768Data_2x75[tempal];
2101 break;
2102 case 10:
2103 return &XGI_LVDS1280x1024Data_1x75[tempal];
2104 break;
2105 case 11:
2106 return &XGI_LVDS1280x1024Data_2x75[tempal];
2107 break;
2108 case 12:
2109 return &XGI_LVDSNoScalingDatax75[tempal];
2110 break;
2111 default:
2112 break;
2113 }
2114 } else if (table == 3) {
2115 switch (tempdi[i].DATAPTR) {
2116 case 0:
2117 return &XGI_LVDS1024x768Des_1[tempal];
2118 break;
2119 case 1:
2120 return &XGI_LVDS1024x768Des_3[tempal];
2121 break;
2122 case 2:
2123 return &XGI_LVDS1024x768Des_2[tempal];
2124 break;
2125 case 3:
2126 return &XGI_LVDS1280x1024Des_1[tempal];
2127 break;
2128 case 4:
2129 return &XGI_LVDS1280x1024Des_2[tempal];
2130 break;
2131 case 5:
2132 return &XGI_LVDS1400x1050Des_1[tempal];
2133 break;
2134 case 6:
2135 return &XGI_LVDS1400x1050Des_2[tempal];
2136 break;
2137 case 7:
2138 return &XGI_LVDS1600x1200Des_1[tempal];
2139 break;
2140 case 8:
2141 return &XGI_LVDSNoScalingDesData[tempal];
2142 break;
2143 case 9:
2144 return &XGI_LVDS1024x768Des_1x75[tempal];
2145 break;
2146 case 10:
2147 return &XGI_LVDS1024x768Des_3x75[tempal];
2148 break;
2149 case 11:
2150 return &XGI_LVDS1024x768Des_2x75[tempal];
2151 break;
2152 case 12:
2153 return &XGI_LVDS1280x1024Des_1x75[tempal];
2154 break;
2155 case 13:
2156 return &XGI_LVDS1280x1024Des_2x75[tempal];
2157 break;
2158 case 14:
2159 return &XGI_LVDSNoScalingDesDatax75[tempal];
2160 break;
2161 default:
2162 break;
2163 }
2164 } else if (table == 4) {
2165 switch (tempdi[i].DATAPTR) {
2166 case 0:
2167 return &XGI_ExtLCD1024x768Data[tempal];
2168 break;
2169 case 1:
2170 return &XGI_StLCD1024x768Data[tempal];
2171 break;
2172 case 2:
2173 return &XGI_CetLCD1024x768Data[tempal];
2174 break;
2175 case 3:
2176 return &XGI_ExtLCD1280x1024Data[tempal];
2177 break;
2178 case 4:
2179 return &XGI_StLCD1280x1024Data[tempal];
2180 break;
2181 case 5:
2182 return &XGI_CetLCD1280x1024Data[tempal];
2183 break;
2184 case 6:
cc1e2398 2185 case 7:
ada2bda1 2186 return &xgifb_lcd_1400x1050[tempal];
cc1e2398
AK
2187 break;
2188 case 8:
2189 return &XGI_CetLCD1400x1050Data[tempal];
2190 break;
2191 case 9:
2192 return &XGI_ExtLCD1600x1200Data[tempal];
2193 break;
2194 case 10:
2195 return &XGI_StLCD1600x1200Data[tempal];
2196 break;
2197 case 11:
2198 return &XGI_NoScalingData[tempal];
2199 break;
2200 case 12:
2201 return &XGI_ExtLCD1024x768x75Data[tempal];
2202 break;
2203 case 13:
2204 return &XGI_ExtLCD1024x768x75Data[tempal];
2205 break;
2206 case 14:
2207 return &XGI_CetLCD1024x768x75Data[tempal];
2208 break;
2209 case 15:
cc1e2398 2210 case 16:
ada2bda1 2211 return &xgifb_lcd_1280x1024x75[tempal];
cc1e2398
AK
2212 break;
2213 case 17:
2214 return &XGI_CetLCD1280x1024x75Data[tempal];
2215 break;
2216 case 18:
2217 return &XGI_NoScalingDatax75[tempal];
2218 break;
2219 default:
2220 break;
2221 }
2222 } else if (table == 5) {
2223 switch (tempdi[i].DATAPTR) {
2224 case 0:
2225 return &XGI_ExtLCDDes1024x768Data[tempal];
2226 break;
2227 case 1:
2228 return &XGI_StLCDDes1024x768Data[tempal];
2229 break;
2230 case 2:
2231 return &XGI_CetLCDDes1024x768Data[tempal];
2232 break;
2233 case 3:
1d7f656d
KT
2234 if ((pVBInfo->VBType & VB_XGI301LV) ||
2235 (pVBInfo->VBType & VB_XGI302LV))
cc1e2398 2236 return &XGI_ExtLCDDLDes1280x1024Data[tempal];
21df8fc8 2237 else
cc1e2398
AK
2238 return &XGI_ExtLCDDes1280x1024Data[tempal];
2239 break;
2240 case 4:
1d7f656d
KT
2241 if ((pVBInfo->VBType & VB_XGI301LV) ||
2242 (pVBInfo->VBType & VB_XGI302LV))
cc1e2398 2243 return &XGI_StLCDDLDes1280x1024Data[tempal];
21df8fc8 2244 else
cc1e2398
AK
2245 return &XGI_StLCDDes1280x1024Data[tempal];
2246 break;
2247 case 5:
1d7f656d
KT
2248 if ((pVBInfo->VBType & VB_XGI301LV) ||
2249 (pVBInfo->VBType & VB_XGI302LV))
cc1e2398
AK
2250 return &XGI_CetLCDDLDes1280x1024Data[tempal];
2251 else
2252 return &XGI_CetLCDDes1280x1024Data[tempal];
2253 break;
2254 case 6:
cc1e2398 2255 case 7:
1d7f656d
KT
2256 if ((pVBInfo->VBType & VB_XGI301LV) ||
2257 (pVBInfo->VBType & VB_XGI302LV))
ada2bda1 2258 return &xgifb_lcddldes_1400x1050[tempal];
cc1e2398 2259 else
ada2bda1 2260 return &xgifb_lcddes_1400x1050[tempal];
cc1e2398
AK
2261 break;
2262 case 8:
2263 return &XGI_CetLCDDes1400x1050Data[tempal];
2264 break;
2265 case 9:
2266 return &XGI_CetLCDDes1400x1050Data2[tempal];
2267 break;
2268 case 10:
1d7f656d
KT
2269 if ((pVBInfo->VBType & VB_XGI301LV) ||
2270 (pVBInfo->VBType & VB_XGI302LV))
cc1e2398
AK
2271 return &XGI_ExtLCDDLDes1600x1200Data[tempal];
2272 else
2273 return &XGI_ExtLCDDes1600x1200Data[tempal];
2274 break;
2275 case 11:
1d7f656d
KT
2276 if ((pVBInfo->VBType & VB_XGI301LV) ||
2277 (pVBInfo->VBType & VB_XGI302LV))
cc1e2398
AK
2278 return &XGI_StLCDDLDes1600x1200Data[tempal];
2279 else
2280 return &XGI_StLCDDes1600x1200Data[tempal];
2281 break;
2282 case 12:
2283 return &XGI_NoScalingDesData[tempal];
2284 break;
2285 case 13:
cc1e2398 2286 case 14:
ada2bda1 2287 return &xgifb_lcddes_1024x768x75[tempal];
cc1e2398
AK
2288 break;
2289 case 15:
2290 return &XGI_CetLCDDes1024x768x75Data[tempal];
2291 break;
2292 case 16:
cc1e2398 2293 case 17:
1d7f656d
KT
2294 if ((pVBInfo->VBType & VB_XGI301LV) ||
2295 (pVBInfo->VBType & VB_XGI302LV))
ada2bda1 2296 return &xgifb_lcddldes_1280x1024x75[tempal];
21df8fc8 2297 else
ada2bda1 2298 return &xgifb_lcddes_1280x1024x75[tempal];
cc1e2398
AK
2299 break;
2300 case 18:
1d7f656d
KT
2301 if ((pVBInfo->VBType & VB_XGI301LV) ||
2302 (pVBInfo->VBType & VB_XGI302LV))
cc1e2398
AK
2303 return &XGI_CetLCDDLDes1280x1024x75Data[tempal];
2304 else
2305 return &XGI_CetLCDDes1280x1024x75Data[tempal];
2306 break;
2307 case 19:
2308 return &XGI_NoScalingDesDatax75[tempal];
2309 break;
2310 default:
2311 break;
21df8fc8 2312 }
cc1e2398
AK
2313 } else if (table == 6) {
2314 switch (tempdi[i].DATAPTR) {
2315 case 0:
2316 return &XGI_CH7017LV1024x768[tempal];
2317 break;
2318 case 1:
2319 return &XGI_CH7017LV1400x1050[tempal];
2320 break;
2321 default:
2322 break;
21df8fc8
PS
2323 }
2324 }
cc1e2398 2325 return NULL;
d7636e0b 2326}
2327
cc1e2398
AK
2328static void *XGI_GetTVPtr(unsigned short BX, unsigned short ModeNo,
2329 unsigned short ModeIdIndex,
2330 unsigned short RefreshRateTableIndex,
21df8fc8
PS
2331 struct vb_device_info *pVBInfo)
2332{
cc1e2398
AK
2333 unsigned short i, tempdx, tempbx, tempal, modeflag, table;
2334 struct XGI330_TVDataTablStruct *tempdi = NULL;
21df8fc8 2335
cc1e2398 2336 tempbx = BX;
21df8fc8 2337
cc1e2398
AK
2338 if (ModeNo <= 0x13) {
2339 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2340 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2341 } else {
2342 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2343 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2344 }
21df8fc8 2345
cc1e2398
AK
2346 tempal = tempal & 0x3f;
2347 table = tempbx;
21df8fc8 2348
cc1e2398
AK
2349 switch (tempbx) {
2350 case 0:
2351 tempdi = NULL; /*EPLCHTVCRT1Ptr_H;*/
cc1e2398
AK
2352 break;
2353 case 1:
2354 tempdi = NULL; /*EPLCHTVCRT1Ptr_V;*/
cc1e2398
AK
2355 break;
2356 case 2:
0c23b6d2
AK
2357 case 6:
2358 tempdi = xgifb_chrontel_tv;
cc1e2398
AK
2359 break;
2360 case 3:
2361 tempdi = NULL;
2362 break;
2363 case 4:
2364 tempdi = XGI_TVDataTable;
2365 break;
2366 case 5:
2367 tempdi = NULL;
2368 break;
cc1e2398
AK
2369 default:
2370 break;
2371 }
21df8fc8 2372
cc1e2398
AK
2373 if (tempdi == NULL) /* OEMUtil */
2374 return NULL;
21df8fc8 2375
cc1e2398 2376 tempdx = pVBInfo->TVInfo;
21df8fc8 2377
cc1e2398
AK
2378 if (pVBInfo->VBInfo & SetInSlaveMode)
2379 tempdx = tempdx | SetTVLockMode;
21df8fc8 2380
cc1e2398
AK
2381 if (modeflag & HalfDCLK)
2382 tempdx = tempdx | SetTVLowResolution;
21df8fc8 2383
cc1e2398 2384 i = 0;
21df8fc8 2385
cc1e2398
AK
2386 while (tempdi[i].MASK != 0xffff) {
2387 if ((tempdx & tempdi[i].MASK) == tempdi[i].CAP)
2388 break;
2389 i++;
2390 }
21df8fc8 2391
1d7f656d
KT
2392 /* 07/05/22 */
2393 if (table == 0x00) {
cc1e2398
AK
2394 } else if (table == 0x01) {
2395 } else if (table == 0x04) {
2396 switch (tempdi[i].DATAPTR) {
2397 case 0:
2398 return &XGI_ExtPALData[tempal];
2399 break;
2400 case 1:
2401 return &XGI_ExtNTSCData[tempal];
2402 break;
2403 case 2:
2404 return &XGI_StPALData[tempal];
2405 break;
2406 case 3:
2407 return &XGI_StNTSCData[tempal];
2408 break;
2409 case 4:
2410 return &XGI_ExtHiTVData[tempal];
2411 break;
2412 case 5:
2413 return &XGI_St2HiTVData[tempal];
2414 break;
2415 case 6:
2416 return &XGI_ExtYPbPr525iData[tempal];
2417 break;
2418 case 7:
2419 return &XGI_ExtYPbPr525pData[tempal];
2420 break;
2421 case 8:
2422 return &XGI_ExtYPbPr750pData[tempal];
2423 break;
2424 case 9:
2425 return &XGI_StYPbPr525iData[tempal];
2426 break;
2427 case 10:
2428 return &XGI_StYPbPr525pData[tempal];
2429 break;
2430 case 11:
2431 return &XGI_StYPbPr750pData[tempal];
2432 break;
2433 case 12: /* avoid system hang */
2434 return &XGI_ExtNTSCData[tempal];
2435 break;
2436 case 13:
2437 return &XGI_St1HiTVData[tempal];
2438 break;
2439 default:
2440 break;
21df8fc8 2441 }
cc1e2398
AK
2442 } else if (table == 0x02) {
2443 switch (tempdi[i].DATAPTR) {
2444 case 0:
2445 return &XGI_CHTVUNTSCData[tempal];
2446 break;
2447 case 1:
2448 return &XGI_CHTVONTSCData[tempal];
2449 break;
2450 case 2:
2451 return &XGI_CHTVUPALData[tempal];
2452 break;
2453 case 3:
2454 return &XGI_CHTVOPALData[tempal];
2455 break;
2456 default:
2457 break;
21df8fc8 2458 }
cc1e2398 2459 } else if (table == 0x06) {
21df8fc8 2460 }
cc1e2398 2461 return NULL;
21df8fc8 2462}
d7636e0b 2463
cc1e2398
AK
2464static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
2465 unsigned short RefreshRateTableIndex,
21df8fc8
PS
2466 struct vb_device_info *pVBInfo)
2467{
cc1e2398
AK
2468 unsigned short tempbx;
2469 struct XGI330_LVDSDataStruct *LCDPtr = NULL;
d7636e0b 2470
cc1e2398 2471 tempbx = 2;
21df8fc8 2472
cc1e2398
AK
2473 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2474 LCDPtr = (struct XGI330_LVDSDataStruct *) XGI_GetLcdPtr(tempbx,
2475 ModeNo, ModeIdIndex, RefreshRateTableIndex,
2476 pVBInfo);
2477 pVBInfo->VGAHT = LCDPtr->VGAHT;
2478 pVBInfo->VGAVT = LCDPtr->VGAVT;
2479 pVBInfo->HT = LCDPtr->LCDHT;
2480 pVBInfo->VT = LCDPtr->LCDVT;
2481 }
21df8fc8 2482
cc1e2398
AK
2483 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2484 if (!(pVBInfo->LCDInfo & (SetLCDtoNonExpanding
2485 | EnableScalingLCD))) {
1d7f656d
KT
2486 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2487 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
cc1e2398
AK
2488 pVBInfo->HDE = 1024;
2489 pVBInfo->VDE = 768;
1d7f656d
KT
2490 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2491 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
cc1e2398
AK
2492 pVBInfo->HDE = 1280;
2493 pVBInfo->VDE = 1024;
2494 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2495 pVBInfo->HDE = 1400;
2496 pVBInfo->VDE = 1050;
2497 } else {
2498 pVBInfo->HDE = 1600;
2499 pVBInfo->VDE = 1200;
21df8fc8
PS
2500 }
2501 }
21df8fc8 2502 }
21df8fc8
PS
2503}
2504
cc1e2398
AK
2505static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
2506 unsigned short RefreshRateTableIndex,
21df8fc8
PS
2507 struct xgi_hw_device_info *HwDeviceExtension,
2508 struct vb_device_info *pVBInfo)
2509{
cc1e2398
AK
2510 unsigned char index;
2511 unsigned short tempbx, i;
2512 struct XGI_LVDSCRT1HDataStruct *LCDPtr = NULL;
2513 struct XGI_LVDSCRT1VDataStruct *LCDPtr1 = NULL;
21df8fc8
PS
2514
2515 if (ModeNo <= 0x13)
cc1e2398 2516 index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
21df8fc8 2517 else
cc1e2398 2518 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
21df8fc8 2519
cc1e2398 2520 index = index & IndexMask;
21df8fc8 2521
aef6bc74 2522 tempbx = 0;
21df8fc8 2523
aef6bc74
AK
2524 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2525 LCDPtr = (struct XGI_LVDSCRT1HDataStruct *)
2526 XGI_GetLcdPtr(tempbx, ModeNo,
2527 ModeIdIndex,
2528 RefreshRateTableIndex,
2529 pVBInfo);
21df8fc8 2530
aef6bc74
AK
2531 for (i = 0; i < 8; i++)
2532 pVBInfo->TimingH[0].data[i] = LCDPtr[0].Reg[i];
2533 }
21df8fc8 2534
aef6bc74 2535 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
21df8fc8 2536
aef6bc74 2537 tempbx = 1;
21df8fc8 2538
aef6bc74
AK
2539 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2540 LCDPtr1 = (struct XGI_LVDSCRT1VDataStruct *)
2541 XGI_GetLcdPtr(
2542 tempbx,
2543 ModeNo,
2544 ModeIdIndex,
2545 RefreshRateTableIndex,
2546 pVBInfo);
2547 for (i = 0; i < 7; i++)
2548 pVBInfo->TimingV[0].data[i] = LCDPtr1[0].Reg[i];
cc1e2398 2549 }
aef6bc74
AK
2550
2551 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
cc1e2398 2552}
21df8fc8 2553
cc1e2398
AK
2554static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
2555{
2556 unsigned char tempal, tempah, tempbl, i;
2557
58839b01 2558 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
cc1e2398
AK
2559 tempal = tempah & 0x0F;
2560 tempah = tempah & 0xF0;
2561 i = 0;
2562 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
21df8fc8 2563
cc1e2398
AK
2564 while (tempbl != 0xFF) {
2565 if (tempbl & 0x80) { /* OEMUtil */
2566 tempal = tempah;
2567 tempbl = tempbl & ~(0x80);
21df8fc8
PS
2568 }
2569
cc1e2398
AK
2570 if (tempal == tempbl)
2571 break;
21df8fc8 2572
cc1e2398 2573 i++;
21df8fc8 2574
cc1e2398 2575 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
21df8fc8
PS
2576 }
2577
cc1e2398 2578 return i;
21df8fc8
PS
2579}
2580
cc1e2398 2581static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
21df8fc8 2582{
cc1e2398 2583 unsigned short tempah, tempal, tempbl, i;
21df8fc8 2584
cc1e2398
AK
2585 tempal = pVBInfo->LCDResInfo;
2586 tempah = pVBInfo->LCDTypeInfo;
21df8fc8 2587
cc1e2398
AK
2588 i = 0;
2589 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
21df8fc8 2590
cc1e2398
AK
2591 while (tempbl != 0xFF) {
2592 if ((tempbl & 0x80) && (tempbl != 0x80)) {
2593 tempal = tempah;
2594 tempbl &= ~0x80;
21df8fc8
PS
2595 }
2596
cc1e2398
AK
2597 if (tempal == tempbl)
2598 break;
21df8fc8 2599
cc1e2398
AK
2600 i++;
2601 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2602 }
21df8fc8 2603
cc1e2398
AK
2604 if (tempbl == 0xFF) {
2605 pVBInfo->LCDResInfo = Panel1024x768;
2606 pVBInfo->LCDTypeInfo = 0;
2607 i = 0;
2608 }
21df8fc8 2609
cc1e2398
AK
2610 return i;
2611}
21df8fc8 2612
1d7f656d
KT
2613static void XGI_GetLCDSync(unsigned short *HSyncWidth,
2614 unsigned short *VSyncWidth,
2615 struct vb_device_info *pVBInfo)
cc1e2398
AK
2616{
2617 unsigned short Index;
21df8fc8 2618
cc1e2398
AK
2619 Index = XGI_GetLCDCapPtr(pVBInfo);
2620 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
2621 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
21df8fc8 2622
cc1e2398
AK
2623 return;
2624}
21df8fc8 2625
cc1e2398
AK
2626static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
2627 unsigned short RefreshRateTableIndex,
2628 struct vb_device_info *pVBInfo)
2629{
2630 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
2631 unsigned long temp, temp1, temp2, temp3, push3;
2632 struct XGI330_LCDDataDesStruct *LCDPtr = NULL;
2633 struct XGI330_LCDDataDesStruct2 *LCDPtr1 = NULL;
21df8fc8 2634
cc1e2398
AK
2635 if (ModeNo > 0x13)
2636 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2637 else
2638 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
21df8fc8 2639
66cfacec
AK
2640 tempbx = 3;
2641 if (pVBInfo->LCDInfo & EnableScalingLCD)
2642 LCDPtr1 =
2643 (struct XGI330_LCDDataDesStruct2 *)
2644 XGI_GetLcdPtr(
2645 tempbx,
2646 ModeNo,
2647 ModeIdIndex,
2648 RefreshRateTableIndex,
2649 pVBInfo);
2650 else
2651 LCDPtr =
2652 (struct XGI330_LCDDataDesStruct *)
2653 XGI_GetLcdPtr(
09cb8e50
AK
2654 tempbx,
2655 ModeNo,
2656 ModeIdIndex,
2657 RefreshRateTableIndex,
2658 pVBInfo);
21df8fc8 2659
09cb8e50
AK
2660 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
2661 push1 = tempbx;
2662 push2 = tempax;
2663
2664 /* GetLCDResInfo */
2665 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2666 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
2667 tempax = 1024;
2668 tempbx = 768;
2669 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2670 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
2671 tempax = 1280;
2672 tempbx = 1024;
2673 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2674 tempax = 1400;
2675 tempbx = 1050;
2676 } else {
2677 tempax = 1600;
2678 tempbx = 1200;
2679 }
21df8fc8 2680
09cb8e50
AK
2681 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
2682 pVBInfo->HDE = tempax;
2683 pVBInfo->VDE = tempbx;
2684 pVBInfo->VGAHDE = tempax;
2685 pVBInfo->VGAVDE = tempbx;
2686 }
cc1e2398 2687
09cb8e50 2688 tempax = pVBInfo->HT;
21df8fc8 2689
09cb8e50
AK
2690 if (pVBInfo->LCDInfo & EnableScalingLCD)
2691 tempbx = LCDPtr1->LCDHDES;
2692 else
2693 tempbx = LCDPtr->LCDHDES;
21df8fc8 2694
09cb8e50
AK
2695 tempcx = pVBInfo->HDE;
2696 tempbx = tempbx & 0x0fff;
2697 tempcx += tempbx;
21df8fc8 2698
09cb8e50
AK
2699 if (tempcx >= tempax)
2700 tempcx -= tempax;
21df8fc8 2701
09cb8e50 2702 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
21df8fc8 2703
09cb8e50
AK
2704 tempcx = tempcx >> 3;
2705 tempbx = tempbx >> 3;
21df8fc8 2706
09cb8e50
AK
2707 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
2708 (unsigned short) (tempbx & 0xff));
2709 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
2710 (unsigned short) (tempcx & 0xff));
cc1e2398 2711
09cb8e50 2712 tempax = pVBInfo->HT;
cc1e2398 2713
09cb8e50
AK
2714 if (pVBInfo->LCDInfo & EnableScalingLCD)
2715 tempbx = LCDPtr1->LCDHRS;
2716 else
2717 tempbx = LCDPtr->LCDHRS;
cc1e2398 2718
09cb8e50 2719 tempcx = push2;
21df8fc8 2720
09cb8e50
AK
2721 if (pVBInfo->LCDInfo & EnableScalingLCD)
2722 tempcx = LCDPtr1->LCDHSync;
21df8fc8 2723
09cb8e50 2724 tempcx += tempbx;
21df8fc8 2725
09cb8e50
AK
2726 if (tempcx >= tempax)
2727 tempcx -= tempax;
21df8fc8 2728
09cb8e50
AK
2729 tempax = tempbx & 0x07;
2730 tempax = tempax >> 5;
2731 tempcx = tempcx >> 3;
2732 tempbx = tempbx >> 3;
21df8fc8 2733
09cb8e50
AK
2734 tempcx &= 0x1f;
2735 tempax |= tempcx;
21df8fc8 2736
09cb8e50
AK
2737 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
2738 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
2739 (unsigned short) (tempbx & 0xff));
21df8fc8 2740
09cb8e50
AK
2741 tempax = pVBInfo->VT;
2742 if (pVBInfo->LCDInfo & EnableScalingLCD)
2743 tempbx = LCDPtr1->LCDVDES;
2744 else
2745 tempbx = LCDPtr->LCDVDES;
2746 tempcx = pVBInfo->VDE;
21df8fc8 2747
09cb8e50
AK
2748 tempbx = tempbx & 0x0fff;
2749 tempcx += tempbx;
2750 if (tempcx >= tempax)
2751 tempcx -= tempax;
21df8fc8 2752
09cb8e50
AK
2753 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
2754 (unsigned short) (tempbx & 0xff));
2755 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
2756 (unsigned short) (tempcx & 0xff));
21df8fc8 2757
09cb8e50
AK
2758 tempbx = (tempbx >> 8) & 0x07;
2759 tempcx = (tempcx >> 8) & 0x07;
21df8fc8 2760
09cb8e50
AK
2761 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
2762 (unsigned short) ((tempcx << 3)
2763 | tempbx));
21df8fc8 2764
09cb8e50
AK
2765 tempax = pVBInfo->VT;
2766 if (pVBInfo->LCDInfo & EnableScalingLCD)
2767 tempbx = LCDPtr1->LCDVRS;
2768 else
2769 tempbx = LCDPtr->LCDVRS;
21df8fc8 2770
09cb8e50
AK
2771 /* tempbx = tempbx >> 4; */
2772 tempcx = push1;
21df8fc8 2773
09cb8e50
AK
2774 if (pVBInfo->LCDInfo & EnableScalingLCD)
2775 tempcx = LCDPtr1->LCDVSync;
21df8fc8 2776
09cb8e50
AK
2777 tempcx += tempbx;
2778 if (tempcx >= tempax)
2779 tempcx -= tempax;
21df8fc8 2780
09cb8e50
AK
2781 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
2782 (unsigned short) (tempbx & 0xff));
2783 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
2784 (unsigned short) (tempcx & 0x0f));
21df8fc8 2785
09cb8e50 2786 tempax = ((tempbx >> 8) & 0x07) << 3;
21df8fc8 2787
09cb8e50
AK
2788 tempbx = pVBInfo->VGAVDE;
2789 if (tempbx != pVBInfo->VDE)
2790 tempax |= 0x40;
21df8fc8 2791
09cb8e50
AK
2792 if (pVBInfo->LCDInfo & EnableLVDSDDA)
2793 tempax |= 0x40;
21df8fc8 2794
09cb8e50
AK
2795 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
2796 tempax);
21df8fc8 2797
09cb8e50
AK
2798 tempcx = pVBInfo->VGAVT;
2799 tempbx = pVBInfo->VDE;
2800 tempax = pVBInfo->VGAVDE;
2801 tempcx -= tempax;
21df8fc8 2802
09cb8e50
AK
2803 temp = tempax; /* 0430 ylshieh */
2804 temp1 = (temp << 18) / tempbx;
21df8fc8 2805
09cb8e50 2806 tempdx = (unsigned short) ((temp << 18) % tempbx);
21df8fc8 2807
09cb8e50
AK
2808 if (tempdx != 0)
2809 temp1 += 1;
21df8fc8 2810
09cb8e50
AK
2811 temp2 = temp1;
2812 push3 = temp2;
cc1e2398 2813
09cb8e50
AK
2814 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
2815 (unsigned short) (temp2 & 0xff));
2816 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
2817 (unsigned short) ((temp2 >> 8) & 0xff));
cc1e2398 2818
09cb8e50
AK
2819 tempbx = (unsigned short) (temp2 >> 16);
2820 tempax = tempbx & 0x03;
21df8fc8 2821
09cb8e50
AK
2822 tempbx = pVBInfo->VGAVDE;
2823 if (tempbx == pVBInfo->VDE)
2824 tempax |= 0x04;
2825
2826 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
2827
2828 if (pVBInfo->VBType & VB_XGI301C) {
2829 temp2 = push3;
2830 xgifb_reg_set(pVBInfo->Part4Port,
2831 0x3c,
2832 (unsigned short) (temp2 & 0xff));
2833 xgifb_reg_set(pVBInfo->Part4Port,
2834 0x3b,
2835 (unsigned short) ((temp2 >> 8) &
2836 0xff));
a35cd0ba 2837 tempbx = (unsigned short) (temp2 >> 16);
09cb8e50
AK
2838 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
2839 ~0xc0,
2840 (unsigned short) ((tempbx &
2841 0xff) << 6));
2842
2843 tempcx = pVBInfo->VGAVDE;
2844 if (tempcx == pVBInfo->VDE)
2845 xgifb_reg_and_or(pVBInfo->Part4Port,
2846 0x30, ~0x0c, 0x00);
2847 else
2848 xgifb_reg_and_or(pVBInfo->Part4Port,
2849 0x30, ~0x0c, 0x08);
2850 }
21df8fc8 2851
09cb8e50
AK
2852 tempcx = pVBInfo->VGAHDE;
2853 tempbx = pVBInfo->HDE;
21df8fc8 2854
09cb8e50 2855 temp1 = tempcx << 16;
d7636e0b 2856
09cb8e50 2857 tempax = (unsigned short) (temp1 / tempbx);
21df8fc8 2858
09cb8e50
AK
2859 if ((tempbx & 0xffff) == (tempcx & 0xffff))
2860 tempax = 65535;
21df8fc8 2861
09cb8e50
AK
2862 temp3 = tempax;
2863 temp1 = pVBInfo->VGAHDE << 16;
d7636e0b 2864
09cb8e50
AK
2865 temp1 /= temp3;
2866 temp3 = temp3 << 16;
2867 temp1 -= 1;
21df8fc8 2868
09cb8e50 2869 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
d7636e0b 2870
09cb8e50
AK
2871 tempax = (unsigned short) (temp3 & 0xff);
2872 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
d7636e0b 2873
09cb8e50
AK
2874 temp1 = pVBInfo->VGAVDE << 18;
2875 temp1 = temp1 / push3;
2876 tempbx = (unsigned short) (temp1 & 0xffff);
21df8fc8 2877
09cb8e50
AK
2878 if (pVBInfo->LCDResInfo == Panel1024x768)
2879 tempbx -= 1;
21df8fc8 2880
09cb8e50
AK
2881 tempax = ((tempbx >> 8) & 0xff) << 3;
2882 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
2883 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
2884 (unsigned short) (tempax & 0xff));
2885 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
2886 (unsigned short) (tempbx & 0xff));
21df8fc8 2887
09cb8e50 2888 temp3 = temp3 >> 16;
a35cd0ba 2889
09cb8e50
AK
2890 if (modeflag & HalfDCLK)
2891 temp3 = temp3 >> 1;
a35cd0ba 2892
09cb8e50
AK
2893 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
2894 (unsigned short) ((temp3 >> 8) & 0xff));
2895 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
2896 (unsigned short) (temp3 & 0xff));
21df8fc8 2897}
d7636e0b 2898
cc1e2398
AK
2899/* --------------------------------------------------------------------- */
2900/* Function : XGI_GETLCDVCLKPtr */
2901/* Input : */
2902/* Output : al -> VCLK Index */
2903/* Description : */
2904/* --------------------------------------------------------------------- */
2905static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
21df8fc8
PS
2906 struct vb_device_info *pVBInfo)
2907{
cc1e2398 2908 unsigned short index;
d7636e0b 2909
cc1e2398 2910 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
cc1e2398
AK
2911 /* index = XGI_GetLCDCapPtr(pVBInfo); */
2912 index = XGI_GetLCDCapPtr1(pVBInfo);
d7636e0b 2913
cc1e2398
AK
2914 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
2915 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
2916 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
2917 } else { /* LCDA */
2918 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
2919 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
21df8fc8 2920 }
21df8fc8 2921 }
cc1e2398 2922 return;
d7636e0b 2923}
2924
cc1e2398
AK
2925static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
2926 unsigned short ModeNo, unsigned short ModeIdIndex,
2927 struct vb_device_info *pVBInfo)
d7636e0b 2928{
d7636e0b 2929
cc1e2398 2930 unsigned short index, modeflag;
cc1e2398 2931 unsigned char tempal;
d7636e0b 2932
cc1e2398 2933 if (ModeNo <= 0x13)
1d7f656d
KT
2934 /* si+St_ResInfo */
2935 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
cc1e2398 2936 else
1d7f656d
KT
2937 /* si+Ext_ResInfo */
2938 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
d7636e0b 2939
1d7f656d
KT
2940 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
2941 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
cc1e2398
AK
2942 index = XGI_GetLCDCapPtr(pVBInfo);
2943 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
d7636e0b 2944
cc1e2398
AK
2945 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
2946 return tempal;
d7636e0b 2947
cc1e2398 2948 /* {TV} */
1d7f656d
KT
2949 if (pVBInfo->VBType &
2950 (VB_XGI301B |
2951 VB_XGI302B |
2952 VB_XGI301LV |
2953 VB_XGI302LV |
2954 VB_XGI301C)) {
cc1e2398
AK
2955 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
2956 tempal = HiTVVCLKDIV2;
2957 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2958 tempal = HiTVVCLK;
2959 if (pVBInfo->TVInfo & TVSimuMode) {
2960 tempal = HiTVSimuVCLK;
2961 if (!(modeflag & Charx8Dot))
2962 tempal = HiTVTextVCLK;
d7636e0b 2963
cc1e2398
AK
2964 }
2965 return tempal;
2966 }
d7636e0b 2967
cc1e2398
AK
2968 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
2969 tempal = YPbPr750pVCLK;
2970 return tempal;
2971 }
d7636e0b 2972
cc1e2398
AK
2973 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
2974 tempal = YPbPr525pVCLK;
2975 return tempal;
2976 }
d7636e0b 2977
cc1e2398 2978 tempal = NTSC1024VCLK;
d7636e0b 2979
cc1e2398
AK
2980 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
2981 tempal = TVVCLKDIV2;
2982 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2983 tempal = TVVCLK;
2984 }
d7636e0b 2985
cc1e2398
AK
2986 if (pVBInfo->VBInfo & SetCRT2ToTV)
2987 return tempal;
2988 }
cc1e2398 2989 } /* {End of VB} */
d7636e0b 2990
d8ad0a6d 2991 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
cc1e2398
AK
2992 tempal = tempal >> 2;
2993 tempal &= 0x03;
d7636e0b 2994
1d7f656d
KT
2995 /* for Dot8 Scaling LCD */
2996 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
cc1e2398
AK
2997 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
2998
2999 if (ModeNo <= 0x13)
3000 return tempal;
3001
3002 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
3003 return tempal;
d7636e0b 3004}
3005
cc1e2398
AK
3006static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
3007 unsigned char *di_1, struct vb_device_info *pVBInfo)
d7636e0b 3008{
83f76a9d 3009 if (pVBInfo->VBType & (VB_XGI301 | VB_XGI301B | VB_XGI302B
cc1e2398
AK
3010 | VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
3011 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) && (pVBInfo->SetFlag
3012 & ProgrammingCRT2)) {
3013 *di_0 = (unsigned char) XGI_VBVCLKData[tempal].SR2B;
3014 *di_1 = XGI_VBVCLKData[tempal].SR2C;
3015 }
3016 } else {
3017 *di_0 = XGI_VCLKData[tempal].SR2B;
3018 *di_1 = XGI_VCLKData[tempal].SR2C;
3019 }
d7636e0b 3020}
d7636e0b 3021
cc1e2398
AK
3022static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
3023 unsigned short RefreshRateTableIndex,
21df8fc8
PS
3024 struct vb_device_info *pVBInfo)
3025{
cc1e2398
AK
3026 unsigned char di_0, di_1, tempal;
3027 int i;
21df8fc8 3028
cc1e2398
AK
3029 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
3030 pVBInfo);
3031 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
3032 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
3033
3034 for (i = 0; i < 4; i++) {
ec9e5d3e 3035 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
cc1e2398 3036 (unsigned short) (0x10 * i));
83f76a9d 3037 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA))
cc1e2398 3038 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
8104e329
AK
3039 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
3040 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
cc1e2398 3041 } else {
8104e329
AK
3042 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
3043 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
cc1e2398
AK
3044 }
3045 }
d7636e0b 3046}
3047
cc1e2398
AK
3048static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
3049 struct vb_device_info *pVBInfo)
d7636e0b 3050{
cc1e2398 3051 unsigned short tempcl, tempch, temp, tempbl, tempax;
d7636e0b 3052
cc1e2398
AK
3053 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
3054 | VB_XGI302LV | VB_XGI301C)) {
3055 tempcl = 0;
3056 tempch = 0;
58839b01 3057 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
21df8fc8 3058
cc1e2398 3059 if (!(temp & 0x20)) {
58839b01 3060 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
cc1e2398 3061 if (temp & 0x80) {
58839b01 3062 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
cc1e2398
AK
3063 if (!(temp & 0x40))
3064 tempcl |= ActiveCRT1;
3065 }
3066 }
21df8fc8 3067
58839b01 3068 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
cc1e2398 3069 temp &= 0x0f;
21df8fc8 3070
cc1e2398 3071 if (!(temp == 0x08)) {
1d7f656d
KT
3072 /* Check ChannelA by Part1_13 [2003/10/03] */
3073 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
cc1e2398
AK
3074 if (tempax & 0x04)
3075 tempcl = tempcl | ActiveLCD;
21df8fc8 3076
cc1e2398 3077 temp &= 0x05;
d7636e0b 3078
cc1e2398
AK
3079 if (!(tempcl & ActiveLCD))
3080 if (temp == 0x01)
3081 tempcl |= ActiveCRT2;
3082
3083 if (temp == 0x04)
3084 tempcl |= ActiveLCD;
3085
3086 if (temp == 0x05) {
58839b01 3087 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
cc1e2398
AK
3088
3089 if (!(temp & 0x08))
3090 tempch |= ActiveAVideo;
3091
3092 if (!(temp & 0x04))
3093 tempch |= ActiveSVideo;
3094
3095 if (temp & 0x02)
3096 tempch |= ActiveSCART;
3097
3098 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3099 if (temp & 0x01)
3100 tempch |= ActiveHiTV;
21df8fc8 3101 }
21df8fc8 3102
cc1e2398 3103 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
58839b01 3104 temp = xgifb_reg_get(
cc1e2398
AK
3105 pVBInfo->Part2Port,
3106 0x4d);
21df8fc8 3107
cc1e2398
AK
3108 if (temp & 0x10)
3109 tempch |= ActiveYPbPr;
21df8fc8 3110 }
cc1e2398
AK
3111
3112 if (tempch != 0)
3113 tempcl |= ActiveTV;
21df8fc8 3114 }
cc1e2398 3115 }
21df8fc8 3116
58839b01 3117 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
cc1e2398
AK
3118 if (tempcl & ActiveLCD) {
3119 if ((pVBInfo->SetFlag & ReserveTVOption)) {
3120 if (temp & ActiveTV)
3121 tempcl |= ActiveTV;
21df8fc8
PS
3122 }
3123 }
cc1e2398
AK
3124 temp = tempcl;
3125 tempbl = ~ModeSwitchStatus;
ec9e5d3e 3126 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
21df8fc8 3127
cc1e2398 3128 if (!(pVBInfo->SetFlag & ReserveTVOption))
8104e329 3129 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
cc1e2398
AK
3130 } else {
3131 return;
21df8fc8 3132 }
cc1e2398 3133}
d7636e0b 3134
cc1e2398 3135void XGI_GetVBType(struct vb_device_info *pVBInfo)
d7636e0b 3136{
cc1e2398 3137 unsigned short flag, tempbx, tempah;
d7636e0b 3138
cc1e2398
AK
3139 if (pVBInfo->IF_DEF_LVDS == 0) {
3140 tempbx = VB_XGI302B;
58839b01 3141 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
cc1e2398
AK
3142 if (flag != 0x02) {
3143 tempbx = VB_XGI301;
58839b01 3144 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
cc1e2398
AK
3145 if (flag >= 0xB0) {
3146 tempbx = VB_XGI301B;
3147 if (flag >= 0xC0) {
3148 tempbx = VB_XGI301C;
3149 if (flag >= 0xD0) {
3150 tempbx = VB_XGI301LV;
3151 if (flag >= 0xE0) {
3152 tempbx = VB_XGI302LV;
1d7f656d
KT
3153 tempah = xgifb_reg_get(
3154 pVBInfo->Part4Port,
3155 0x39);
cc1e2398 3156 if (tempah != 0xFF)
1d7f656d
KT
3157 tempbx =
3158 VB_XGI301C;
cc1e2398
AK
3159 }
3160 }
3161 }
3162
3163 if (tempbx & (VB_XGI301B | VB_XGI302B)) {
58839b01 3164 flag = xgifb_reg_get(
cc1e2398
AK
3165 pVBInfo->Part4Port,
3166 0x23);
3167
3168 if (!(flag & 0x02))
3169 tempbx = tempbx | VB_NoLCD;
3170 }
3171 }
3172 }
3173 pVBInfo->VBType = tempbx;
3174 }
d7636e0b 3175}
3176
fac2cc92 3177static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
cc1e2398 3178 struct xgi_hw_device_info *HwDeviceExtension,
21df8fc8
PS
3179 struct vb_device_info *pVBInfo)
3180{
cc1e2398 3181 unsigned short tempax, push, tempbx, temp, modeflag;
d7636e0b 3182
cc1e2398
AK
3183 if (ModeNo <= 0x13)
3184 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3185 else
3186 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
d7636e0b 3187
cc1e2398
AK
3188 pVBInfo->SetFlag = 0;
3189 pVBInfo->ModeType = modeflag & ModeInfoFlag;
3190 tempbx = 0;
3191
3192 if (pVBInfo->VBType & 0xFFFF) {
1d7f656d
KT
3193 /* Check Display Device */
3194 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
cc1e2398 3195 tempbx = tempbx | temp;
58839b01 3196 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
cc1e2398
AK
3197 push = temp;
3198 push = push << 8;
3199 tempax = temp << 8;
3200 tempbx = tempbx | tempax;
3201 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr | SetCRT2ToLCDA
3202 | SetInSlaveMode | DisableCRT2Display);
3203 temp = 0xFFFF ^ temp;
3204 tempbx &= temp;
3205
58839b01 3206 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
cc1e2398
AK
3207
3208 if (pVBInfo->IF_DEF_LCDA == 1) {
3209
9ffc7e9f
AK
3210 if ((HwDeviceExtension->jChipType >= XG20) ||
3211 (HwDeviceExtension->jChipType >= XG40)) {
cc1e2398 3212 if (pVBInfo->IF_DEF_LVDS == 0) {
1d7f656d
KT
3213 /* if ((pVBInfo->VBType & VB_XGI302B)
3214 || (pVBInfo->VBType & VB_XGI301LV)
3215 || (pVBInfo->VBType & VB_XGI302LV)
3216 || (pVBInfo->VBType & VB_XGI301C))
3217 */
3218 if (pVBInfo->VBType &
3219 (VB_XGI302B |
3220 VB_XGI301LV |
3221 VB_XGI302LV |
3222 VB_XGI301C)) {
cc1e2398 3223 if (temp & EnableDualEdge) {
1d7f656d
KT
3224 tempbx |=
3225 SetCRT2ToDualEdge;
d7636e0b 3226
cc1e2398 3227 if (temp & SetToLCDA)
1d7f656d
KT
3228 tempbx |=
3229 SetCRT2ToLCDA;
cc1e2398
AK
3230 }
3231 }
cc1e2398
AK
3232 }
3233 }
3234 }
21df8fc8 3235
cc1e2398 3236 if (pVBInfo->IF_DEF_YPbPr == 1) {
1d7f656d
KT
3237 /* [Billy] 07/05/04 */
3238 if (((pVBInfo->IF_DEF_LVDS == 0) &&
3239 ((pVBInfo->VBType & VB_XGI301LV) ||
3240 (pVBInfo->VBType & VB_XGI302LV) ||
83f76a9d 3241 (pVBInfo->VBType & VB_XGI301C)))) {
cc1e2398
AK
3242 if (temp & SetYPbPr) { /* temp = CR38 */
3243 if (pVBInfo->IF_DEF_HiVision == 1) {
1d7f656d
KT
3244 /* shampoo add for new
3245 * scratch */
58839b01 3246 temp = xgifb_reg_get(
cc1e2398 3247 pVBInfo->P3d4,
1d7f656d 3248 0x35);
cc1e2398
AK
3249 temp &= YPbPrMode;
3250 tempbx |= SetCRT2ToHiVisionTV;
21df8fc8 3251
cc1e2398 3252 if (temp != YPbPrMode1080i) {
1d7f656d
KT
3253 tempbx &=
3254 (~SetCRT2ToHiVisionTV);
3255 tempbx |=
3256 SetCRT2ToYPbPr;
cc1e2398
AK
3257 }
3258 }
21df8fc8 3259
cc1e2398
AK
3260 /* tempbx |= SetCRT2ToYPbPr; */
3261 }
3262 }
3263 }
21df8fc8 3264
cc1e2398 3265 tempax = push; /* restore CR31 */
21df8fc8 3266
cc1e2398
AK
3267 if (pVBInfo->IF_DEF_LVDS == 0) {
3268 if (pVBInfo->IF_DEF_YPbPr == 1) {
3269 if (pVBInfo->IF_DEF_HiVision == 1)
3270 temp = 0x09FC;
21df8fc8 3271 else
cc1e2398
AK
3272 temp = 0x097C;
3273 } else {
3274 if (pVBInfo->IF_DEF_HiVision == 1)
3275 temp = 0x01FC;
3276 else
3277 temp = 0x017C;
3278 }
3279 } else { /* 3nd party chip */
83f76a9d 3280 temp = SetCRT2ToLCD;
cc1e2398 3281 }
21df8fc8 3282
cc1e2398
AK
3283 if (!(tempbx & temp)) {
3284 tempax |= DisableCRT2Display;
3285 tempbx = 0;
21df8fc8
PS
3286 }
3287
cc1e2398
AK
3288 if (pVBInfo->IF_DEF_LCDA == 1) { /* Select Display Device */
3289 if (!(pVBInfo->VBType & VB_NoLCD)) {
3290 if (tempbx & SetCRT2ToLCDA) {
3291 if (tempbx & SetSimuScanMode)
1d7f656d
KT
3292 tempbx &= (~(SetCRT2ToLCD |
3293 SetCRT2ToRAMDAC |
3294 SwitchToCRT2));
cc1e2398 3295 else
1d7f656d
KT
3296 tempbx &= (~(SetCRT2ToLCD |
3297 SetCRT2ToRAMDAC |
3298 SetCRT2ToTV |
3299 SwitchToCRT2));
cc1e2398
AK
3300 }
3301 }
21df8fc8
PS
3302 }
3303
cc1e2398 3304 /* shampoo add */
1d7f656d
KT
3305 /* for driver abnormal */
3306 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode))) {
cc1e2398
AK
3307 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
3308 if (tempbx & SetCRT2ToRAMDAC) {
1d7f656d
KT
3309 tempbx &= (0xFF00 |
3310 SetCRT2ToRAMDAC |
3311 SwitchToCRT2 |
3312 SetSimuScanMode);
cc1e2398
AK
3313 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3314 }
3315 } else {
1d7f656d
KT
3316 tempbx &= (~(SetCRT2ToRAMDAC |
3317 SetCRT2ToLCD |
3318 SetCRT2ToTV));
cc1e2398
AK
3319 }
3320 }
21df8fc8 3321
cc1e2398
AK
3322 if (!(pVBInfo->VBType & VB_NoLCD)) {
3323 if (tempbx & SetCRT2ToLCD) {
1d7f656d
KT
3324 tempbx &= (0xFF00 |
3325 SetCRT2ToLCD |
3326 SwitchToCRT2 |
3327 SetSimuScanMode);
cc1e2398
AK
3328 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3329 }
3330 }
21df8fc8 3331
cc1e2398 3332 if (tempbx & SetCRT2ToSCART) {
1d7f656d
KT
3333 tempbx &= (0xFF00 |
3334 SetCRT2ToSCART |
3335 SwitchToCRT2 |
3336 SetSimuScanMode);
cc1e2398
AK
3337 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3338 }
21df8fc8 3339
cc1e2398
AK
3340 if (pVBInfo->IF_DEF_YPbPr == 1) {
3341 if (tempbx & SetCRT2ToYPbPr)
1d7f656d
KT
3342 tempbx &= (0xFF00 |
3343 SwitchToCRT2 |
3344 SetSimuScanMode);
cc1e2398 3345 }
21df8fc8 3346
cc1e2398
AK
3347 if (pVBInfo->IF_DEF_HiVision == 1) {
3348 if (tempbx & SetCRT2ToHiVisionTV)
1d7f656d
KT
3349 tempbx &= (0xFF00 |
3350 SetCRT2ToHiVisionTV |
3351 SwitchToCRT2 |
3352 SetSimuScanMode);
cc1e2398 3353 }
21df8fc8 3354
cc1e2398
AK
3355 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
3356 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode)))
3357 tempbx = DisableCRT2Display;
3358 }
21df8fc8 3359
cc1e2398 3360 if (!(tempbx & DisableCRT2Display)) {
1d7f656d
KT
3361 if ((!(tempbx & DriverMode)) ||
3362 (!(modeflag & CRT2Mode))) {
cc1e2398
AK
3363 if (pVBInfo->IF_DEF_LCDA == 1) {
3364 if (!(tempbx & SetCRT2ToLCDA))
1d7f656d
KT
3365 tempbx |= (SetInSlaveMode |
3366 SetSimuScanMode);
cc1e2398 3367 }
21df8fc8 3368 }
21df8fc8 3369
1d7f656d
KT
3370 /* LCD+TV can't support in slave mode
3371 * (Force LCDA+TV->LCDB) */
3372 if ((tempbx & SetInSlaveMode) &&
3373 (tempbx & SetCRT2ToLCDA)) {
3374 tempbx ^= (SetCRT2ToLCD |
3375 SetCRT2ToLCDA |
3376 SetCRT2ToDualEdge);
cc1e2398 3377 pVBInfo->SetFlag |= ReserveTVOption;
21df8fc8
PS
3378 }
3379 }
21df8fc8 3380 }
cc1e2398
AK
3381
3382 pVBInfo->VBInfo = tempbx;
21df8fc8
PS
3383}
3384
fac2cc92 3385static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
21df8fc8 3386 struct vb_device_info *pVBInfo)
d7636e0b 3387{
cc1e2398 3388 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
21df8fc8 3389
cc1e2398
AK
3390 tempbx = 0;
3391 resinfo = 0;
d7636e0b 3392
cc1e2398
AK
3393 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3394 if (ModeNo <= 0x13) {
1d7f656d
KT
3395 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].
3396 St_ModeFlag; /* si+St_ModeFlag */
3397 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].
3398 St_ResInfo; /* si+St_ResInfo */
cc1e2398 3399 } else {
1d7f656d
KT
3400 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].
3401 Ext_ModeFlag;
3402 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].
3403 Ext_RESINFO; /* si+Ext_ResInfo */
cc1e2398 3404 }
d7636e0b 3405
cc1e2398 3406 if (pVBInfo->VBInfo & SetCRT2ToTV) {
58839b01 3407 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
cc1e2398
AK
3408 tempbx = temp;
3409 if (tempbx & SetPALTV) {
1d7f656d
KT
3410 tempbx &= (SetCHTVOverScan |
3411 SetPALMTV |
3412 SetPALNTV |
3413 SetPALTV);
cc1e2398 3414 if (tempbx & SetPALMTV)
1d7f656d
KT
3415 /* set to NTSC if PAL-M */
3416 tempbx &= ~SetPALTV;
cc1e2398 3417 } else
1d7f656d
KT
3418 tempbx &= (SetCHTVOverScan |
3419 SetNTSCJ |
3420 SetPALTV);
cc1e2398
AK
3421 /*
3422 if (pVBInfo->IF_DEF_LVDS == 0) {
1d7f656d
KT
3423 //PAL-M/PAL-N Info
3424 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x38);
3425 //00:PAL, 01:PAL-M, 10:PAL-N
3426 temp2 = (index1 & 0xC0) >> 5;
cc1e2398 3427 tempbx |= temp2;
1d7f656d 3428 if (temp2 & 0x02) //PAL-M
cc1e2398
AK
3429 tempbx &= (~SetPALTV);
3430 }
3431 */
3432 }
d7636e0b 3433
cc1e2398
AK
3434 if (pVBInfo->IF_DEF_LVDS == 0) {
3435 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3436 tempbx |= SetPALTV;
3437 }
d7636e0b 3438
cc1e2398
AK
3439 if (pVBInfo->IF_DEF_YPbPr == 1) {
3440 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
58839b01 3441 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
cc1e2398 3442 index1 &= YPbPrMode;
d7636e0b 3443
cc1e2398
AK
3444 if (index1 == YPbPrMode525i)
3445 tempbx |= SetYPbPrMode525i;
21df8fc8 3446
cc1e2398
AK
3447 if (index1 == YPbPrMode525p)
3448 tempbx = tempbx | SetYPbPrMode525p;
3449 if (index1 == YPbPrMode750p)
3450 tempbx = tempbx | SetYPbPrMode750p;
3451 }
3452 }
21df8fc8 3453
cc1e2398
AK
3454 if (pVBInfo->IF_DEF_HiVision == 1) {
3455 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
3456 tempbx = tempbx | SetYPbPrMode1080i | SetPALTV;
3457 }
21df8fc8 3458
cc1e2398 3459 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
1d7f656d
KT
3460 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
3461 (!(pVBInfo->VBInfo & SetNotSimuMode)))
cc1e2398
AK
3462 tempbx |= TVSimuMode;
3463
1d7f656d
KT
3464 if (!(tempbx & SetPALTV) &&
3465 (modeflag > 13) &&
3466 (resinfo == 8)) /* NTSC 1024x768, */
cc1e2398
AK
3467 tempbx |= NTSC1024x768;
3468
3469 tempbx |= RPLLDIV2XO;
21df8fc8 3470
cc1e2398
AK
3471 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3472 if (pVBInfo->VBInfo & SetInSlaveMode)
3473 tempbx &= (~RPLLDIV2XO);
3474 } else {
1d7f656d
KT
3475 if (tempbx &
3476 (SetYPbPrMode525p | SetYPbPrMode750p))
cc1e2398 3477 tempbx &= (~RPLLDIV2XO);
1d7f656d
KT
3478 else if (!(pVBInfo->VBType &
3479 (VB_XGI301B |
3480 VB_XGI302B |
3481 VB_XGI301LV |
3482 VB_XGI302LV |
3483 VB_XGI301C))) {
cc1e2398
AK
3484 if (tempbx & TVSimuMode)
3485 tempbx &= (~RPLLDIV2XO);
21df8fc8 3486 }
21df8fc8 3487 }
cc1e2398
AK
3488 }
3489 }
3490 pVBInfo->TVInfo = tempbx;
3491}
21df8fc8 3492
fac2cc92
AK
3493static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
3494 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
cc1e2398
AK
3495{
3496 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
21df8fc8 3497
cc1e2398
AK
3498 pVBInfo->LCDResInfo = 0;
3499 pVBInfo->LCDTypeInfo = 0;
3500 pVBInfo->LCDInfo = 0;
21df8fc8 3501
cc1e2398 3502 if (ModeNo <= 0x13) {
1d7f656d
KT
3503 /* si+St_ModeFlag // */
3504 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
cc1e2398
AK
3505 } else {
3506 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1d7f656d
KT
3507 /* si+Ext_ResInfo // */
3508 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
cc1e2398 3509 }
21df8fc8 3510
58839b01 3511 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
cc1e2398 3512 tempbx = temp & 0x0F;
21df8fc8 3513
cc1e2398
AK
3514 if (tempbx == 0)
3515 tempbx = Panel1024x768; /* default */
3516
3517 /* LCD75 [2003/8/22] Vicent */
3518 if ((tempbx == Panel1024x768) || (tempbx == Panel1280x1024)) {
3519 if (pVBInfo->VBInfo & DriverMode) {
58839b01 3520 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
cc1e2398
AK
3521 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
3522 tempax &= 0x0F;
21df8fc8 3523 else
cc1e2398 3524 tempax = tempax >> 4;
21df8fc8 3525
cc1e2398
AK
3526 if ((resinfo == 6) || (resinfo == 9)) {
3527 if (tempax >= 3)
3528 tempbx |= PanelRef75Hz;
3529 } else if ((resinfo == 7) || (resinfo == 8)) {
3530 if (tempax >= 4)
3531 tempbx |= PanelRef75Hz;
21df8fc8 3532 }
cc1e2398
AK
3533 }
3534 }
21df8fc8 3535
cc1e2398 3536 pVBInfo->LCDResInfo = tempbx;
21df8fc8 3537
cc1e2398 3538 /* End of LCD75 */
21df8fc8 3539
cc1e2398
AK
3540 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
3541 return 0;
21df8fc8 3542
cc1e2398 3543 tempbx = 0;
21df8fc8 3544
58839b01 3545 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
d7636e0b 3546
cc1e2398 3547 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
d7636e0b 3548
cc1e2398 3549 tempbx |= temp;
d7636e0b 3550
cc1e2398 3551 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
d7636e0b 3552
cc1e2398 3553 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
d7636e0b 3554
cc1e2398
AK
3555 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
3556 if (((pVBInfo->VBType & VB_XGI302LV) || (pVBInfo->VBType
3557 & VB_XGI301C)) && (tempax & LCDDualLink)) {
3558 tempbx |= SetLCDDualLink;
21df8fc8 3559 }
21df8fc8 3560 }
21df8fc8 3561
cc1e2398
AK
3562 if (pVBInfo->IF_DEF_LVDS == 0) {
3563 if ((pVBInfo->LCDResInfo == Panel1400x1050) && (pVBInfo->VBInfo
3564 & SetCRT2ToLCD) && (ModeNo > 0x13) && (resinfo
3565 == 9) && (!(tempbx & EnableScalingLCD)))
1d7f656d
KT
3566 /* set to center in 1280x1024 LCDB for Panel1400x1050 */
3567 tempbx |= SetLCDtoNonExpanding;
cc1e2398 3568 }
21df8fc8 3569
cc1e2398
AK
3570 /*
3571 if (tempax & LCDBToA) {
3572 tempbx |= SetLCDBToA;
3573 }
3574 */
21df8fc8 3575
cc1e2398
AK
3576 if (pVBInfo->IF_DEF_ExpLink == 1) {
3577 if (modeflag & HalfDCLK) {
3578 /* if (!(pVBInfo->LCDInfo&LCDNonExpanding)) */
3579 if (!(tempbx & SetLCDtoNonExpanding)) {
3580 tempbx |= EnableLVDSDDA;
3581 } else {
3582 if (ModeNo > 0x13) {
3583 if (pVBInfo->LCDResInfo
3584 == Panel1024x768) {
1d7f656d 3585 if (resinfo == 4) {/* 512x384 */
cc1e2398
AK
3586 tempbx |= EnableLVDSDDA;
3587 }
3588 }
3589 }
3590 }
3591 }
3592 }
21df8fc8 3593
cc1e2398
AK
3594 if (pVBInfo->VBInfo & SetInSlaveMode) {
3595 if (pVBInfo->VBInfo & SetNotSimuMode)
3596 tempbx |= LCDVESATiming;
3597 } else {
3598 tempbx |= LCDVESATiming;
3599 }
21df8fc8 3600
cc1e2398 3601 pVBInfo->LCDInfo = tempbx;
d7636e0b 3602
cc1e2398
AK
3603 if (pVBInfo->IF_DEF_LVDS == 0) {
3604 if (tempax & (LockLCDBToA | StLCDBToA)) {
3605 if (pVBInfo->VBInfo & SetInSlaveMode) {
3606 if (!(tempax & LockLCDBToA)) {
3607 if (ModeNo <= 0x13) {
1d7f656d
KT
3608 pVBInfo->VBInfo &=
3609 ~(SetSimuScanMode |
3610 SetInSlaveMode |
3611 SetCRT2ToLCD);
3612 pVBInfo->VBInfo |=
3613 SetCRT2ToLCDA |
3614 SetCRT2ToDualEdge;
cc1e2398
AK
3615 }
3616 }
3617 }
3618 }
3619 }
21df8fc8 3620
cc1e2398
AK
3621 /*
3622 if (pVBInfo->IF_DEF_LVDS == 0) {
3623 if (tempax & (LockLCDBToA | StLCDBToA)) {
3624 if (pVBInfo->VBInfo & SetInSlaveMode) {
1d7f656d
KT
3625 if (!((!(tempax & LockLCDBToA)) &&
3626 (ModeNo > 0x13))) {
3627 pVBInfo->VBInfo &=
3628 ~(SetSimuScanMode |
3629 SetInSlaveMode |
3630 SetCRT2ToLCD);
3631 pVBInfo->VBInfo |=
3632 SetCRT2ToLCDA |
3633 SetCRT2ToDualEdge;
cc1e2398
AK
3634 }
3635 }
3636 }
21df8fc8 3637 }
cc1e2398 3638 */
d7636e0b 3639
cc1e2398 3640 return 1;
21df8fc8 3641}
d7636e0b 3642
cc1e2398
AK
3643unsigned char XGI_SearchModeID(unsigned short ModeNo,
3644 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
d7636e0b 3645{
cc1e2398
AK
3646 if (ModeNo <= 5)
3647 ModeNo |= 1;
3648 if (ModeNo <= 0x13) {
1d7f656d
KT
3649 /* for (*ModeIdIndex=0;
3650 *ModeIdIndex < sizeof(pVBInfo->SModeIDTable)
3651 / sizeof(struct XGI_StStruct);
3652 (*ModeIdIndex)++) */
cc1e2398 3653 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
1d7f656d
KT
3654 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3655 ModeNo)
cc1e2398 3656 break;
1d7f656d
KT
3657 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3658 0xFF)
cc1e2398
AK
3659 return 0;
3660 }
d7636e0b 3661
cc1e2398
AK
3662 if (ModeNo == 0x07)
3663 (*ModeIdIndex)++; /* 400 lines */
3664 if (ModeNo <= 3)
3665 (*ModeIdIndex) += 2; /* 400 lines */
3666 /* else 350 lines */
3667 } else {
1d7f656d
KT
3668 /* for (*ModeIdIndex=0;
3669 *ModeIdIndex < sizeof(pVBInfo->EModeIDTable)
3670 / sizeof(struct XGI_ExtStruct);
3671 (*ModeIdIndex)++) */
cc1e2398 3672 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
1d7f656d
KT
3673 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3674 ModeNo)
cc1e2398 3675 break;
1d7f656d
KT
3676 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3677 0xFF)
cc1e2398
AK
3678 return 0;
3679 }
21df8fc8 3680 }
d7636e0b 3681
cc1e2398 3682 return 1;
21df8fc8 3683}
d7636e0b 3684
cc1e2398
AK
3685static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
3686{
3687 unsigned char ujRet = 0;
3688 unsigned char i = 0;
21df8fc8 3689
cc1e2398
AK
3690 for (i = 0; i < 8; i++) {
3691 ujRet = ujRet << 1;
3692 /* ujRet |= GETBITS(ujDate >> i, 0:0); */
3693 ujRet |= (ujDate >> i) & 1;
21df8fc8 3694 }
d7636e0b 3695
cc1e2398
AK
3696 return ujRet;
3697}
21df8fc8 3698
cc1e2398
AK
3699/*----------------------------------------------------------------------------*/
3700/* output */
3701/* bl[5] : LVDS signal */
3702/* bl[1] : LVDS backlight */
3703/* bl[0] : LVDS VDD */
3704/*----------------------------------------------------------------------------*/
3705static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
3706{
3707 unsigned char CR4A, temp;
21df8fc8 3708
58839b01 3709 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
dc50556b 3710 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
21df8fc8 3711
58839b01 3712 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
21df8fc8 3713
cc1e2398
AK
3714 temp = XG21GPIODataTransfer(temp);
3715 temp &= 0x23;
8104e329 3716 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
cc1e2398
AK
3717 return temp;
3718}
3719
3720/*----------------------------------------------------------------------------*/
3721/* output */
3722/* bl[5] : LVDS signal */
3723/* bl[1] : LVDS backlight */
3724/* bl[0] : LVDS VDD */
3725/*----------------------------------------------------------------------------*/
3726static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
3727{
3728 unsigned char CR4A, CRB4, temp;
21df8fc8 3729
58839b01 3730 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
dc50556b 3731 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
21df8fc8 3732
58839b01 3733 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
21df8fc8 3734
cc1e2398
AK
3735 temp &= 0x0C;
3736 temp >>= 2;
8104e329 3737 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
58839b01 3738 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
cc1e2398
AK
3739 temp |= ((CRB4 & 0x04) << 3);
3740 return temp;
3741}
21df8fc8 3742
0ebf538b
AK
3743/*----------------------------------------------------------------------------*/
3744/* input */
3745/* bl[5] : 1;LVDS signal on */
3746/* bl[1] : 1;LVDS backlight on */
3747/* bl[0] : 1:LVDS VDD on */
3748/* bh: 100000b : clear bit 5, to set bit5 */
3749/* 000010b : clear bit 1, to set bit1 */
3750/* 000001b : clear bit 0, to set bit0 */
3751/*----------------------------------------------------------------------------*/
3752static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
3753 struct vb_device_info *pVBInfo)
3754{
3755 unsigned char CR4A, temp;
3756
3757 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3758 tempbh &= 0x23;
3759 tempbl &= 0x23;
3760 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
3761
3762 if (tempbh & 0x20) {
3763 temp = (tempbl >> 4) & 0x02;
3764
3765 /* CR B4[1] */
3766 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
3767
3768 }
3769
3770 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3771
3772 temp = XG21GPIODataTransfer(temp);
3773 temp &= ~tempbh;
3774 temp |= tempbl;
3775 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
3776}
3777
776115a0
AK
3778static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
3779 struct vb_device_info *pVBInfo)
3780{
3781 unsigned char CR4A, temp;
3782 unsigned short tempbh0, tempbl0;
3783
3784 tempbh0 = tempbh;
3785 tempbl0 = tempbl;
3786 tempbh0 &= 0x20;
3787 tempbl0 &= 0x20;
3788 tempbh0 >>= 3;
3789 tempbl0 >>= 3;
3790
3791 if (tempbh & 0x20) {
3792 temp = (tempbl >> 4) & 0x02;
3793
3794 /* CR B4[1] */
3795 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
3796
3797 }
3798 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
3799
3800 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3801 tempbh &= 0x03;
3802 tempbl &= 0x03;
3803 tempbh <<= 2;
3804 tempbl <<= 2; /* GPIOC,GPIOD */
3805 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
3806 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
3807}
3808
ed2e7203
AK
3809static unsigned short XGI_GetLVDSOEMTableIndex(struct vb_device_info *pVBInfo)
3810{
3811 unsigned short index;
3812
3813 index = xgifb_reg_get(pVBInfo->P3d4, 0x36);
3814 if (index < sizeof(XGI21_LCDCapList)
3815 / sizeof(struct XGI21_LVDSCapStruct))
3816 return index;
3817 return 0;
3818}
3819
9913b6c0
AK
3820/* --------------------------------------------------------------------- */
3821/* Function : XGI_XG21SetPanelDelay */
3822/* Input : */
3823/* Output : */
3824/* Description : */
3825/* I/P : bl : 1 ; T1 : the duration between CPL on and signal on */
3826/* : bl : 2 ; T2 : the duration signal on and Vdd on */
3827/* : bl : 3 ; T3 : the duration between CPL off and signal off */
3828/* : bl : 4 ; T4 : the duration signal off and Vdd off */
3829/* --------------------------------------------------------------------- */
3830static void XGI_XG21SetPanelDelay(unsigned short tempbl,
3831 struct vb_device_info *pVBInfo)
3832{
3833 unsigned short index;
3834
3835 index = XGI_GetLVDSOEMTableIndex(pVBInfo);
3836 if (tempbl == 1)
3837 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S1);
3838
3839 if (tempbl == 2)
3840 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S2);
3841
3842 if (tempbl == 3)
3843 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S3);
3844
3845 if (tempbl == 4)
3846 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S4);
3847}
3848
fac2cc92 3849static void XGI_DisplayOn(struct xgi_hw_device_info *pXGIHWDE,
cc1e2398
AK
3850 struct vb_device_info *pVBInfo)
3851{
3852
ec9e5d3e 3853 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
cc1e2398
AK
3854 if (pXGIHWDE->jChipType == XG21) {
3855 if (pVBInfo->IF_DEF_LVDS == 1) {
3856 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
1d7f656d
KT
3857 /* LVDS VDD on */
3858 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
cc1e2398
AK
3859 XGI_XG21SetPanelDelay(2, pVBInfo);
3860 }
3861 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
1d7f656d
KT
3862 /* LVDS signal on */
3863 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
cc1e2398 3864 XGI_XG21SetPanelDelay(3, pVBInfo);
1d7f656d
KT
3865 /* LVDS backlight on */
3866 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
cc1e2398 3867 } else {
1d7f656d
KT
3868 /* DVO/DVI signal on */
3869 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
cc1e2398 3870 }
21df8fc8 3871
21df8fc8
PS
3872 }
3873
cc1e2398
AK
3874 if (pXGIHWDE->jChipType == XG27) {
3875 if (pVBInfo->IF_DEF_LVDS == 1) {
3876 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
1d7f656d
KT
3877 /* LVDS VDD on */
3878 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
cc1e2398
AK
3879 XGI_XG21SetPanelDelay(2, pVBInfo);
3880 }
3881 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
1d7f656d
KT
3882 /* LVDS signal on */
3883 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
cc1e2398 3884 XGI_XG21SetPanelDelay(3, pVBInfo);
1d7f656d
KT
3885 /* LVDS backlight on */
3886 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
cc1e2398 3887 } else {
1d7f656d
KT
3888 /* DVO/DVI signal on */
3889 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
cc1e2398 3890 }
21df8fc8 3891
cc1e2398 3892 }
d7636e0b 3893}
3894
cc1e2398 3895void XGI_DisplayOff(struct xgi_hw_device_info *pXGIHWDE,
21df8fc8
PS
3896 struct vb_device_info *pVBInfo)
3897{
d7636e0b 3898
cc1e2398
AK
3899 if (pXGIHWDE->jChipType == XG21) {
3900 if (pVBInfo->IF_DEF_LVDS == 1) {
1d7f656d
KT
3901 /* LVDS backlight off */
3902 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
cc1e2398
AK
3903 XGI_XG21SetPanelDelay(3, pVBInfo);
3904 } else {
1d7f656d
KT
3905 /* DVO/DVI signal off */
3906 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
cc1e2398 3907 }
21df8fc8
PS
3908 }
3909
cc1e2398
AK
3910 if (pXGIHWDE->jChipType == XG27) {
3911 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
1d7f656d
KT
3912 /* LVDS backlight off */
3913 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
cc1e2398
AK
3914 XGI_XG21SetPanelDelay(3, pVBInfo);
3915 }
21df8fc8 3916
cc1e2398 3917 if (pVBInfo->IF_DEF_LVDS == 0)
1d7f656d
KT
3918 /* DVO/DVI signal off */
3919 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
cc1e2398 3920 }
21df8fc8 3921
ec9e5d3e 3922 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
cc1e2398 3923}
21df8fc8 3924
cc1e2398
AK
3925static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
3926{
d8ad0a6d 3927 while ((inb(pVBInfo->P3da) & 0x01))
cc1e2398 3928 break;
21df8fc8 3929
d8ad0a6d 3930 while (!(inb(pVBInfo->P3da) & 0x01))
cc1e2398
AK
3931 break;
3932}
21df8fc8 3933
cc1e2398
AK
3934static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
3935{
09cb8e50 3936 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
cc1e2398 3937}
21df8fc8 3938
1d7f656d
KT
3939static void XGI_SaveCRT2Info(unsigned short ModeNo,
3940 struct vb_device_info *pVBInfo)
cc1e2398
AK
3941{
3942 unsigned short temp1, temp2;
21df8fc8 3943
1d7f656d
KT
3944 /* reserve CR34 for CRT1 Mode No */
3945 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
cc1e2398
AK
3946 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
3947 temp2 = ~(SetInSlaveMode >> 8);
ec9e5d3e 3948 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
cc1e2398 3949}
21df8fc8 3950
1d7f656d
KT
3951static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
3952 unsigned short ModeIdIndex,
3953 struct vb_device_info *pVBInfo)
cc1e2398
AK
3954{
3955 unsigned short xres, yres, modeflag, resindex;
21df8fc8 3956
cc1e2398
AK
3957 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
3958 if (ModeNo <= 0x13) {
3959 xres = pVBInfo->StResInfo[resindex].HTotal;
3960 yres = pVBInfo->StResInfo[resindex].VTotal;
1d7f656d
KT
3961 /* si+St_ResInfo */
3962 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;*/
21df8fc8 3963 } else {
cc1e2398
AK
3964 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
3965 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
1d7f656d
KT
3966 /* si+St_ModeFlag */
3967 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
21df8fc8 3968
cc1e2398
AK
3969 /*
3970 if (pVBInfo->IF_DEF_FSTN) {
3971 xres *= 2;
3972 yres *= 2;
3973 } else {
3974 */
3975 if (modeflag & HalfDCLK)
3976 xres *= 2;
21df8fc8 3977
cc1e2398
AK
3978 if (modeflag & DoubleScanMode)
3979 yres *= 2;
3980 /* } */
3981 }
21df8fc8 3982
cc1e2398
AK
3983 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
3984 if (pVBInfo->IF_DEF_LVDS == 0) {
3985 if (pVBInfo->LCDResInfo == Panel1600x1200) {
3986 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
3987 if (yres == 1024)
3988 yres = 1056;
21df8fc8
PS
3989 }
3990 }
3991
cc1e2398
AK
3992 if (pVBInfo->LCDResInfo == Panel1280x1024) {
3993 if (yres == 400)
3994 yres = 405;
3995 else if (yres == 350)
3996 yres = 360;
3997
3998 if (pVBInfo->LCDInfo & LCDVESATiming) {
3999 if (yres == 360)
4000 yres = 375;
21df8fc8
PS
4001 }
4002 }
4003
cc1e2398
AK
4004 if (pVBInfo->LCDResInfo == Panel1024x768) {
4005 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4006 if (!(pVBInfo->LCDInfo
4007 & LCDNonExpanding)) {
4008 if (yres == 350)
4009 yres = 357;
4010 else if (yres == 400)
4011 yres = 420;
4012 else if (yres == 480)
4013 yres = 525;
4014 }
21df8fc8
PS
4015 }
4016 }
4017 }
cc1e2398
AK
4018
4019 if (xres == 720)
4020 xres = 640;
21df8fc8
PS
4021 }
4022
cc1e2398
AK
4023 pVBInfo->VGAHDE = xres;
4024 pVBInfo->HDE = xres;
4025 pVBInfo->VGAVDE = yres;
4026 pVBInfo->VDE = yres;
4027}
21df8fc8 4028
cc1e2398
AK
4029static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
4030{
21df8fc8 4031
cc1e2398
AK
4032 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
4033 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
4034 return 1;
21df8fc8 4035
cc1e2398
AK
4036 return 0;
4037}
4038
1d7f656d
KT
4039static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
4040 unsigned short ModeIdIndex,
4041 unsigned short RefreshRateTableIndex,
4042 struct vb_device_info *pVBInfo)
cc1e2398
AK
4043{
4044 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
4045 StandTableIndex, CRT1Index;
4046
4047 pVBInfo->RVBHCMAX = 1;
4048 pVBInfo->RVBHCFACT = 1;
4049
4050 if (ModeNo <= 0x13) {
4051 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4052 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
4053 tempax = pVBInfo->StandTable[StandTableIndex].CRTC[0];
4054 tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[6];
4055 temp1 = pVBInfo->StandTable[StandTableIndex].CRTC[7];
4056 } else {
4057 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1d7f656d
KT
4058 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
4059 Ext_CRT1CRTC;
cc1e2398 4060 CRT1Index &= IndexMask;
1d7f656d
KT
4061 temp1 = (unsigned short) pVBInfo->
4062 XGINEWUB_CRT1Table[CRT1Index].CR[0];
4063 temp2 = (unsigned short) pVBInfo->
4064 XGINEWUB_CRT1Table[CRT1Index].CR[5];
cc1e2398 4065 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
1d7f656d
KT
4066 tempbx = (unsigned short) pVBInfo->
4067 XGINEWUB_CRT1Table[CRT1Index].CR[8];
4068 tempcx = (unsigned short) pVBInfo->
4069 XGINEWUB_CRT1Table[CRT1Index].CR[14] << 8;
cc1e2398
AK
4070 tempcx &= 0x0100;
4071 tempcx = tempcx << 2;
4072 tempbx |= tempcx;
1d7f656d
KT
4073 temp1 = (unsigned short) pVBInfo->
4074 XGINEWUB_CRT1Table[CRT1Index].CR[9];
cc1e2398
AK
4075 }
4076
4077 if (temp1 & 0x01)
4078 tempbx |= 0x0100;
4079
4080 if (temp1 & 0x20)
4081 tempbx |= 0x0200;
4082 tempax += 5;
4083
4084 if (modeflag & Charx8Dot)
4085 tempax *= 8;
4086 else
4087 tempax *= 9;
4088
4089 pVBInfo->VGAHT = tempax;
4090 pVBInfo->HT = tempax;
4091 tempbx++;
4092 pVBInfo->VGAVT = tempbx;
4093 pVBInfo->VT = tempbx;
4094}
4095
4096static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
4097 unsigned short RefreshRateTableIndex,
4098 struct vb_device_info *pVBInfo)
4099{
4100 unsigned short tempax = 0, tempbx, modeflag, resinfo;
4101
4102 struct XGI_LCDDataStruct *LCDPtr = NULL;
4103 struct XGI_TVDataStruct *TVPtr = NULL;
4104
4105 if (ModeNo <= 0x13) {
1d7f656d
KT
4106 /* si+St_ResInfo */
4107 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
cc1e2398
AK
4108 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4109 } else {
1d7f656d
KT
4110 /* si+Ext_ResInfo */
4111 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
cc1e2398
AK
4112 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4113 }
4114
4115 pVBInfo->NewFlickerMode = 0;
4116 pVBInfo->RVBHRS = 50;
4117
4118 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4119 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4120 pVBInfo);
4121 return;
4122 }
4123
4124 tempbx = 4;
4125
4126 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
4127 LCDPtr = (struct XGI_LCDDataStruct *) XGI_GetLcdPtr(tempbx,
4128 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4129 pVBInfo);
4130
4131 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
4132 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
4133 pVBInfo->VGAHT = LCDPtr->VGAHT;
4134 pVBInfo->VGAVT = LCDPtr->VGAVT;
4135 pVBInfo->HT = LCDPtr->LCDHT;
4136 pVBInfo->VT = LCDPtr->LCDVT;
21df8fc8 4137
21df8fc8 4138 if (pVBInfo->LCDResInfo == Panel1024x768) {
cc1e2398
AK
4139 tempax = 1024;
4140 tempbx = 768;
4141
4142 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4143 if (pVBInfo->VGAVDE == 357)
4144 tempbx = 527;
4145 else if (pVBInfo->VGAVDE == 420)
4146 tempbx = 620;
4147 else if (pVBInfo->VGAVDE == 525)
4148 tempbx = 775;
4149 else if (pVBInfo->VGAVDE == 600)
4150 tempbx = 775;
4151 /* else if (pVBInfo->VGAVDE==350) tempbx=560; */
4152 /* else if (pVBInfo->VGAVDE==400) tempbx=640; */
4153 else
4154 tempbx = 768;
4155 } else
4156 tempbx = 768;
4157 } else if (pVBInfo->LCDResInfo == Panel1024x768x75) {
4158 tempax = 1024;
4159 tempbx = 768;
4160 } else if (pVBInfo->LCDResInfo == Panel1280x1024) {
4161 tempax = 1280;
4162 if (pVBInfo->VGAVDE == 360)
4163 tempbx = 768;
4164 else if (pVBInfo->VGAVDE == 375)
4165 tempbx = 800;
4166 else if (pVBInfo->VGAVDE == 405)
4167 tempbx = 864;
4168 else
4169 tempbx = 1024;
4170 } else if (pVBInfo->LCDResInfo == Panel1280x1024x75) {
4171 tempax = 1280;
4172 tempbx = 1024;
4173 } else if (pVBInfo->LCDResInfo == Panel1280x960) {
4174 tempax = 1280;
4175 if (pVBInfo->VGAVDE == 350)
4176 tempbx = 700;
4177 else if (pVBInfo->VGAVDE == 400)
4178 tempbx = 800;
4179 else if (pVBInfo->VGAVDE == 1024)
4180 tempbx = 960;
4181 else
4182 tempbx = 960;
4183 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
4184 tempax = 1400;
4185 tempbx = 1050;
4186
4187 if (pVBInfo->VGAVDE == 1024) {
4188 tempax = 1280;
4189 tempbx = 1024;
4190 }
4191 } else if (pVBInfo->LCDResInfo == Panel1600x1200) {
4192 tempax = 1600;
4193 tempbx = 1200; /* alan 10/14/2003 */
21df8fc8 4194 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
cc1e2398
AK
4195 if (pVBInfo->VGAVDE == 350)
4196 tempbx = 875;
4197 else if (pVBInfo->VGAVDE == 400)
4198 tempbx = 1000;
21df8fc8
PS
4199 }
4200 }
21df8fc8 4201
cc1e2398
AK
4202 if (pVBInfo->LCDInfo & LCDNonExpanding) {
4203 tempax = pVBInfo->VGAHDE;
4204 tempbx = pVBInfo->VGAVDE;
4205 }
21df8fc8 4206
cc1e2398
AK
4207 pVBInfo->HDE = tempax;
4208 pVBInfo->VDE = tempbx;
4209 return;
4210 }
21df8fc8 4211
cc1e2398
AK
4212 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
4213 tempbx = 4;
4214 TVPtr = (struct XGI_TVDataStruct *) XGI_GetTVPtr(tempbx,
4215 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4216 pVBInfo);
21df8fc8 4217
cc1e2398
AK
4218 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
4219 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
4220 pVBInfo->VGAHT = TVPtr->VGAHT;
4221 pVBInfo->VGAVT = TVPtr->VGAVT;
4222 pVBInfo->HDE = TVPtr->TVHDE;
4223 pVBInfo->VDE = TVPtr->TVVDE;
4224 pVBInfo->RVBHRS = TVPtr->RVBHRS;
4225 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
21df8fc8 4226
cc1e2398
AK
4227 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4228 if (resinfo == 0x08)
4229 pVBInfo->NewFlickerMode = 0x40;
4230 else if (resinfo == 0x09)
4231 pVBInfo->NewFlickerMode = 0x40;
4232 else if (resinfo == 0x12)
4233 pVBInfo->NewFlickerMode = 0x40;
21df8fc8 4234
cc1e2398
AK
4235 if (pVBInfo->VGAVDE == 350)
4236 pVBInfo->TVInfo |= TVSimuMode;
21df8fc8 4237
cc1e2398
AK
4238 tempax = ExtHiTVHT;
4239 tempbx = ExtHiTVVT;
21df8fc8 4240
cc1e2398 4241 if (pVBInfo->VBInfo & SetInSlaveMode) {
21df8fc8 4242 if (pVBInfo->TVInfo & TVSimuMode) {
cc1e2398
AK
4243 tempax = StHiTVHT;
4244 tempbx = StHiTVVT;
4245
4246 if (!(modeflag & Charx8Dot)) {
4247 tempax = StHiTextTVHT;
4248 tempbx = StHiTextTVVT;
21df8fc8
PS
4249 }
4250 }
4251 }
cc1e2398
AK
4252 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
4253 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
4254 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
4255 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
4256 }
4257
4258 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
4259 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
4260 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
4261 } else if (pVBInfo->TVInfo & SetYPbPrMode525i) {
4262 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
4263 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
4264 if (pVBInfo->TVInfo & NTSC1024x768)
4265 tempax = NTSC1024x768HT;
4266 }
21df8fc8 4267 } else {
cc1e2398
AK
4268 tempax = PALHT;
4269 tempbx = PALVT;
4270 if (!(pVBInfo->TVInfo & SetPALTV)) {
4271 tempax = NTSCHT;
4272 tempbx = NTSCVT;
4273 if (pVBInfo->TVInfo & NTSC1024x768)
4274 tempax = NTSC1024x768HT;
21df8fc8
PS
4275 }
4276 }
21df8fc8 4277
cc1e2398
AK
4278 pVBInfo->HT = tempax;
4279 pVBInfo->VT = tempbx;
4280 return;
21df8fc8 4281 }
21df8fc8
PS
4282}
4283
cc1e2398 4284static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
21df8fc8 4285 unsigned short RefreshRateTableIndex,
21df8fc8 4286 struct vb_device_info *pVBInfo)
d7636e0b 4287{
cc1e2398 4288 unsigned char di_0, di_1, tempal;
21df8fc8 4289
cc1e2398
AK
4290 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
4291 pVBInfo);
4292 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
4293 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
21df8fc8 4294
cc1e2398
AK
4295 if (pVBInfo->VBType & VB_XGI301) { /* shampoo 0129 */
4296 /* 301 */
8104e329
AK
4297 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
4298 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
4299 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
cc1e2398 4300 } else { /* 301b/302b/301lv/302lv */
8104e329
AK
4301 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
4302 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
21df8fc8
PS
4303 }
4304
8104e329 4305 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
21df8fc8 4306
cc1e2398 4307 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
b9bf6e4e 4308 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
cc1e2398 4309 else
b9bf6e4e 4310 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
cc1e2398 4311}
21df8fc8 4312
cc1e2398
AK
4313static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
4314 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
4315{
4316 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
4317 short index;
4318 unsigned short modeflag;
21df8fc8 4319
cc1e2398
AK
4320 if (ModeNo <= 0x13)
4321 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4322 else
4323 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
21df8fc8 4324
cc1e2398 4325 index = (modeflag & ModeInfoFlag) - ModeEGA;
21df8fc8 4326
cc1e2398
AK
4327 if (index < 0)
4328 index = 0;
21df8fc8 4329
cc1e2398
AK
4330 return ColorDepth[index];
4331}
21df8fc8 4332
1d7f656d
KT
4333static unsigned short XGI_GetOffset(unsigned short ModeNo,
4334 unsigned short ModeIdIndex,
cc1e2398
AK
4335 unsigned short RefreshRateTableIndex,
4336 struct xgi_hw_device_info *HwDeviceExtension,
4337 struct vb_device_info *pVBInfo)
4338{
4339 unsigned short temp, colordepth, modeinfo, index, infoflag,
4340 ColorDepth[] = { 0x01, 0x02, 0x04 };
21df8fc8 4341
cc1e2398
AK
4342 modeinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
4343 if (ModeNo <= 0x14)
4344 infoflag = 0;
4345 else
1d7f656d
KT
4346 infoflag = pVBInfo->
4347 RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
21df8fc8 4348
cc1e2398 4349 index = (modeinfo >> 8) & 0xFF;
21df8fc8 4350
cc1e2398 4351 temp = pVBInfo->ScreenOffset[index];
21df8fc8 4352
cc1e2398
AK
4353 if (infoflag & InterlaceMode)
4354 temp = temp << 1;
21df8fc8 4355
cc1e2398 4356 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
21df8fc8 4357
cc1e2398
AK
4358 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
4359 temp = ModeNo - 0x7C;
4360 colordepth = ColorDepth[temp];
4361 temp = 0x6B;
4362 if (infoflag & InterlaceMode)
4363 temp = temp << 1;
4364 return temp * colordepth;
4365 } else {
4366 return temp * colordepth;
21df8fc8 4367 }
cc1e2398 4368}
21df8fc8 4369
cc1e2398
AK
4370static void XGI_SetCRT2Offset(unsigned short ModeNo,
4371 unsigned short ModeIdIndex,
4372 unsigned short RefreshRateTableIndex,
4373 struct xgi_hw_device_info *HwDeviceExtension,
4374 struct vb_device_info *pVBInfo)
4375{
4376 unsigned short offset;
4377 unsigned char temp;
21df8fc8 4378
cc1e2398
AK
4379 if (pVBInfo->VBInfo & SetInSlaveMode)
4380 return;
21df8fc8 4381
cc1e2398
AK
4382 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4383 HwDeviceExtension, pVBInfo);
4384 temp = (unsigned char) (offset & 0xFF);
8104e329 4385 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
cc1e2398 4386 temp = (unsigned char) ((offset & 0xFF00) >> 8);
8104e329 4387 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
cc1e2398 4388 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
8104e329 4389 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
cc1e2398 4390}
21df8fc8 4391
cc1e2398
AK
4392static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
4393{
1d7f656d
KT
4394 /* threshold high ,disable auto threshold */
4395 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
4396 /* threshold low default 04h */
4397 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
cc1e2398 4398}
21df8fc8 4399
cc1e2398
AK
4400static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
4401 struct xgi_hw_device_info *HwDeviceExtension,
4402 unsigned short RefreshRateTableIndex,
4403 struct vb_device_info *pVBInfo)
4404{
4405 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
21df8fc8 4406
cc1e2398 4407 if (ModeNo > 0x13) {
1d7f656d
KT
4408 CRT1Index = pVBInfo->
4409 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
cc1e2398
AK
4410 CRT1Index &= IndexMask;
4411 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4412 }
21df8fc8 4413
cc1e2398
AK
4414 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4415 HwDeviceExtension, pVBInfo);
4416 XGI_SetCRT2FIFO(pVBInfo);
4417 /* XGI_SetCRT2Sync(ModeNo,RefreshRateTableIndex); */
21df8fc8 4418
cc1e2398 4419 for (tempcx = 4; tempcx < 7; tempcx++)
8104e329 4420 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
21df8fc8 4421
8104e329
AK
4422 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
4423 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
cc1e2398 4424}
21df8fc8 4425
cc1e2398
AK
4426static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
4427 struct xgi_hw_device_info *HwDeviceExtension,
4428 unsigned short RefreshRateTableIndex,
4429 struct vb_device_info *pVBInfo)
4430{
4431 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
4432 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
4433
4434 if (ModeNo > 0x13) {
1d7f656d
KT
4435 CRT1Index = pVBInfo->
4436 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
cc1e2398
AK
4437 CRT1Index &= IndexMask;
4438 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
21df8fc8
PS
4439 }
4440
cc1e2398
AK
4441 if (ModeNo <= 0x13)
4442 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4443 else
4444 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
21df8fc8 4445
cc1e2398
AK
4446 /* bainy change table name */
4447 if (modeflag & HalfDCLK) {
1d7f656d
KT
4448 /* BTVGA2HT 0x08,0x09 */
4449 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
8104e329 4450 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
cc1e2398 4451 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
ec9e5d3e 4452 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
1d7f656d
KT
4453 /* BTVGA2HDEE 0x0A,0x0C */
4454 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
8104e329 4455 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
cc1e2398
AK
4456 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
4457 pushbx = pVBInfo->VGAHDE / 2 + 16;
21df8fc8 4458 tempcx = tempcx >> 1;
cc1e2398
AK
4459 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4460 tempcx += tempbx;
21df8fc8 4461
cc1e2398
AK
4462 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4463 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
1d7f656d
KT
4464 tempbx |= ((pVBInfo->
4465 XGINEWUB_CRT1Table[CRT1Index].CR[14] &
4466 0xC0) << 2);
cc1e2398
AK
4467 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4468 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
4469 tempcx &= 0x1F;
4470 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[15];
4471 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4472 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4473 }
21df8fc8 4474
cc1e2398
AK
4475 tempbx += 4;
4476 tempcx += 4;
21df8fc8 4477
cc1e2398
AK
4478 if (tempcx > (pVBInfo->VGAHT / 2))
4479 tempcx = pVBInfo->VGAHT / 2;
21df8fc8 4480
cc1e2398 4481 temp = tempbx & 0x00FF;
21df8fc8 4482
8104e329 4483 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
cc1e2398
AK
4484 } else {
4485 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
8104e329 4486 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
cc1e2398 4487 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
ec9e5d3e 4488 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
1d7f656d
KT
4489 /* BTVGA2HDEE 0x0A,0x0C */
4490 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
8104e329 4491 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
cc1e2398
AK
4492 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
4493 pushbx = pVBInfo->VGAHDE + 16;
4494 tempcx = tempcx >> 1;
4495 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4496 tempcx += tempbx;
21df8fc8 4497
cc1e2398
AK
4498 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4499 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[3];
1d7f656d
KT
4500 tempbx |= ((pVBInfo->
4501 XGINEWUB_CRT1Table[CRT1Index].CR[5] &
4502 0xC0) << 2);
cc1e2398
AK
4503 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4504 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
4505 tempcx &= 0x1F;
4506 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[6];
4507 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4508 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4509 tempbx += 16;
4510 tempcx += 16;
4511 }
21df8fc8 4512
cc1e2398
AK
4513 if (tempcx > pVBInfo->VGAHT)
4514 tempcx = pVBInfo->VGAHT;
21df8fc8 4515
cc1e2398 4516 temp = tempbx & 0x00FF;
8104e329 4517 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
cc1e2398 4518 }
21df8fc8 4519
cc1e2398
AK
4520 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
4521 tempbx = pushbx;
4522 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
4523 tempax |= (tempbx & 0xFF00);
4524 temp = (tempax & 0xFF00) >> 8;
8104e329 4525 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
21df8fc8 4526 temp = tempcx & 0x00FF;
8104e329 4527 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
cc1e2398 4528 tempcx = (pVBInfo->VGAVT - 1);
21df8fc8 4529 temp = tempcx & 0x00FF;
21df8fc8 4530
8104e329 4531 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
cc1e2398
AK
4532 tempbx = pVBInfo->VGAVDE - 1;
4533 temp = tempbx & 0x00FF;
8104e329 4534 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
cc1e2398
AK
4535 temp = ((tempbx & 0xFF00) << 3) >> 8;
4536 temp |= ((tempcx & 0xFF00) >> 8);
8104e329 4537 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
21df8fc8 4538
cc1e2398
AK
4539 tempax = pVBInfo->VGAVDE;
4540 tempbx = pVBInfo->VGAVDE;
4541 tempcx = pVBInfo->VGAVT;
1d7f656d
KT
4542 /* BTVGA2VRS 0x10,0x11 */
4543 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
4544 /* BTVGA2VRE 0x11 */
4545 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
21df8fc8 4546
cc1e2398
AK
4547 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4548 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[10];
4549 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
21df8fc8 4550
cc1e2398
AK
4551 if (temp & 0x04)
4552 tempbx |= 0x0100;
21df8fc8 4553
cc1e2398
AK
4554 if (temp & 0x080)
4555 tempbx |= 0x0200;
21df8fc8 4556
cc1e2398 4557 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14];
21df8fc8 4558
cc1e2398
AK
4559 if (temp & 0x08)
4560 tempbx |= 0x0400;
21df8fc8 4561
cc1e2398
AK
4562 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[11];
4563 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
21df8fc8
PS
4564 }
4565
cc1e2398 4566 temp = tempbx & 0x00FF;
8104e329 4567 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
cc1e2398
AK
4568 temp = ((tempbx & 0xFF00) >> 8) << 4;
4569 temp = ((tempcx & 0x000F) | (temp));
8104e329 4570 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
cc1e2398 4571 tempax = 0;
21df8fc8 4572
cc1e2398
AK
4573 if (modeflag & DoubleScanMode)
4574 tempax |= 0x80;
21df8fc8 4575
cc1e2398
AK
4576 if (modeflag & HalfDCLK)
4577 tempax |= 0x40;
21df8fc8 4578
ec9e5d3e 4579 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
cc1e2398 4580}
21df8fc8 4581
cc1e2398
AK
4582static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
4583{
4584 unsigned long tempax, tempbx;
21df8fc8 4585
cc1e2398
AK
4586 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
4587 & 0xFFFF;
4588 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
4589 tempax = (tempax * pVBInfo->HT) / tempbx;
21df8fc8 4590
cc1e2398
AK
4591 return (unsigned short) tempax;
4592}
21df8fc8 4593
cc1e2398
AK
4594static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
4595 struct xgi_hw_device_info *HwDeviceExtension,
4596 unsigned short RefreshRateTableIndex,
4597 struct vb_device_info *pVBInfo)
4598{
4599 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
4600 modeflag, CRT1Index;
21df8fc8 4601
cc1e2398 4602 if (ModeNo <= 0x13) {
1d7f656d
KT
4603 /* si+St_ResInfo */
4604 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
cc1e2398
AK
4605 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4606 } else {
1d7f656d
KT
4607 /* si+Ext_ResInfo */
4608 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
cc1e2398 4609 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1d7f656d
KT
4610 CRT1Index = pVBInfo->
4611 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
cc1e2398 4612 CRT1Index &= IndexMask;
21df8fc8
PS
4613 }
4614
cc1e2398
AK
4615 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4616 return;
21df8fc8 4617
cc1e2398 4618 temp = 0xFF; /* set MAX HT */
8104e329 4619 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
cc1e2398
AK
4620 /* if (modeflag & Charx8Dot) */
4621 /* tempcx = 0x08; */
4622 /* else */
4623 tempcx = 0x08;
21df8fc8 4624
cc1e2398
AK
4625 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4626 modeflag |= Charx8Dot;
21df8fc8 4627
cc1e2398 4628 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
21df8fc8 4629
cc1e2398
AK
4630 if (modeflag & HalfDCLK)
4631 tempax = tempax >> 1;
21df8fc8 4632
cc1e2398
AK
4633 tempax = (tempax / tempcx) - 1;
4634 tempbx |= ((tempax & 0x00FF) << 8);
4635 temp = tempax & 0x00FF;
8104e329 4636 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
21df8fc8 4637
cc1e2398 4638 temp = (tempbx & 0xFF00) >> 8;
21df8fc8 4639
cc1e2398
AK
4640 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4641 if (!(pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4642 | VB_XGI302LV | VB_XGI301C)))
4643 temp += 2;
21df8fc8 4644
cc1e2398
AK
4645 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4646 if (pVBInfo->VBType & VB_XGI301LV) {
4647 if (pVBInfo->VBExtInfo == VB_YPbPr1080i) {
4648 if (resinfo == 7)
4649 temp -= 2;
4650 }
4651 } else if (resinfo == 7) {
4652 temp -= 2;
4653 }
21df8fc8 4654 }
21df8fc8
PS
4655 }
4656
1d7f656d
KT
4657 /* 0x05 Horizontal Display Start */
4658 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
4659 /* 0x06 Horizontal Blank end */
4660 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
21df8fc8 4661
cc1e2398
AK
4662 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
4663 if (pVBInfo->VBInfo & SetCRT2ToTV)
4664 tempax = pVBInfo->VGAHT;
4665 else
4666 tempax = XGI_GetVGAHT2(pVBInfo);
4667 }
21df8fc8 4668
cc1e2398
AK
4669 if (tempax >= pVBInfo->VGAHT)
4670 tempax = pVBInfo->VGAHT;
21df8fc8 4671
cc1e2398
AK
4672 if (modeflag & HalfDCLK)
4673 tempax = tempax >> 1;
4674
4675 tempax = (tempax / tempcx) - 5;
4676 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
4677 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4678 temp = (tempbx & 0x00FF) - 1;
4679 if (!(modeflag & HalfDCLK)) {
4680 temp -= 6;
4681 if (pVBInfo->TVInfo & TVSimuMode) {
4682 temp -= 4;
4683 if (ModeNo > 0x13)
4684 temp -= 10;
4685 }
4686 }
21df8fc8 4687 } else {
cc1e2398
AK
4688 /* tempcx = tempbx & 0x00FF ; */
4689 tempbx = (tempbx & 0xFF00) >> 8;
4690 tempcx = (tempcx + tempbx) >> 1;
4691 temp = (tempcx & 0x00FF) + 2;
21df8fc8 4692
cc1e2398
AK
4693 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4694 temp -= 1;
4695 if (!(modeflag & HalfDCLK)) {
4696 if ((modeflag & Charx8Dot)) {
4697 temp += 4;
4698 if (pVBInfo->VGAHDE >= 800)
4699 temp -= 6;
4700 }
4701 }
4702 } else {
4703 if (!(modeflag & HalfDCLK)) {
4704 temp -= 4;
4705 if (pVBInfo->LCDResInfo != Panel1280x960) {
4706 if (pVBInfo->VGAHDE >= 800) {
4707 temp -= 7;
1d7f656d
KT
4708 if (pVBInfo->ModeType ==
4709 ModeEGA) {
4710 if (pVBInfo->VGAVDE ==
4711 1024) {
cc1e2398 4712 temp += 15;
1d7f656d
KT
4713 if (pVBInfo->LCDResInfo != Panel1280x1024) {
4714 temp +=
4715 7;
cc1e2398
AK
4716 }
4717 }
4718 }
21df8fc8 4719
cc1e2398
AK
4720 if (pVBInfo->VGAHDE >= 1280) {
4721 if (pVBInfo->LCDResInfo
4722 != Panel1280x960) {
4723 if (pVBInfo->LCDInfo
4724 & LCDNonExpanding) {
4725 temp
4726 += 28;
4727 }
4728 }
4729 }
4730 }
4731 }
4732 }
4733 }
4734 }
21df8fc8 4735
1d7f656d
KT
4736 /* 0x07 Horizontal Retrace Start */
4737 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4738 /* 0x08 Horizontal Retrace End */
4739 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
21df8fc8 4740
cc1e2398
AK
4741 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4742 if (pVBInfo->TVInfo & TVSimuMode) {
4743 if ((ModeNo == 0x06) || (ModeNo == 0x10) || (ModeNo
4744 == 0x11) || (ModeNo == 0x13) || (ModeNo
4745 == 0x0F)) {
8104e329
AK
4746 xgifb_reg_set(pVBInfo->Part1Port, 0x07, 0x5b);
4747 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0x03);
cc1e2398 4748 }
21df8fc8 4749
cc1e2398
AK
4750 if ((ModeNo == 0x00) || (ModeNo == 0x01)) {
4751 if (pVBInfo->TVInfo & SetNTSCTV) {
8104e329 4752 xgifb_reg_set(pVBInfo->Part1Port,
cc1e2398 4753 0x07, 0x2A);
8104e329 4754 xgifb_reg_set(pVBInfo->Part1Port,
cc1e2398
AK
4755 0x08, 0x61);
4756 } else {
8104e329 4757 xgifb_reg_set(pVBInfo->Part1Port,
cc1e2398 4758 0x07, 0x2A);
8104e329 4759 xgifb_reg_set(pVBInfo->Part1Port,
cc1e2398 4760 0x08, 0x41);
8104e329 4761 xgifb_reg_set(pVBInfo->Part1Port,
cc1e2398
AK
4762 0x0C, 0xF0);
4763 }
4764 }
21df8fc8 4765
cc1e2398
AK
4766 if ((ModeNo == 0x02) || (ModeNo == 0x03) || (ModeNo
4767 == 0x07)) {
4768 if (pVBInfo->TVInfo & SetNTSCTV) {
8104e329 4769 xgifb_reg_set(pVBInfo->Part1Port,
cc1e2398 4770 0x07, 0x54);
8104e329 4771 xgifb_reg_set(pVBInfo->Part1Port,
cc1e2398
AK
4772 0x08, 0x00);
4773 } else {
8104e329 4774 xgifb_reg_set(pVBInfo->Part1Port,
cc1e2398 4775 0x07, 0x55);
8104e329 4776 xgifb_reg_set(pVBInfo->Part1Port,
cc1e2398 4777 0x08, 0x00);
8104e329 4778 xgifb_reg_set(pVBInfo->Part1Port,
cc1e2398
AK
4779 0x0C, 0xF0);
4780 }
4781 }
21df8fc8 4782
cc1e2398
AK
4783 if ((ModeNo == 0x04) || (ModeNo == 0x05) || (ModeNo
4784 == 0x0D) || (ModeNo == 0x50)) {
4785 if (pVBInfo->TVInfo & SetNTSCTV) {
8104e329 4786 xgifb_reg_set(pVBInfo->Part1Port,
cc1e2398 4787 0x07, 0x30);
8104e329 4788 xgifb_reg_set(pVBInfo->Part1Port,
cc1e2398
AK
4789 0x08, 0x03);
4790 } else {
8104e329 4791 xgifb_reg_set(pVBInfo->Part1Port,
cc1e2398 4792 0x07, 0x2f);
8104e329 4793 xgifb_reg_set(pVBInfo->Part1Port,
cc1e2398
AK
4794 0x08, 0x02);
4795 }
21df8fc8 4796 }
21df8fc8
PS
4797 }
4798 }
4799
8104e329 4800 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
ec9e5d3e 4801 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
8104e329 4802 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
21df8fc8 4803
cc1e2398
AK
4804 tempbx = pVBInfo->VGAVT;
4805 push1 = tempbx;
4806 tempcx = 0x121;
4807 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
21df8fc8 4808
cc1e2398
AK
4809 if (tempbx == 357)
4810 tempbx = 350;
4811 if (tempbx == 360)
4812 tempbx = 350;
4813 if (tempbx == 375)
4814 tempbx = 350;
4815 if (tempbx == 405)
4816 tempbx = 400;
4817 if (tempbx == 525)
4818 tempbx = 480;
21df8fc8 4819
cc1e2398 4820 push2 = tempbx;
21df8fc8 4821
cc1e2398
AK
4822 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4823 if (pVBInfo->LCDResInfo == Panel1024x768) {
4824 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4825 if (tempbx == 350)
4826 tempbx += 5;
4827 if (tempbx == 480)
4828 tempbx += 5;
4829 }
4830 }
4831 }
4832 tempbx--;
4833 temp = tempbx & 0x00FF;
4834 tempbx--;
4835 temp = tempbx & 0x00FF;
1d7f656d
KT
4836 /* 0x10 vertical Blank Start */
4837 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
cc1e2398
AK
4838 tempbx = push2;
4839 tempbx--;
4840 temp = tempbx & 0x00FF;
8104e329 4841 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
d7636e0b 4842
cc1e2398
AK
4843 if (tempbx & 0x0100)
4844 tempcx |= 0x0002;
21df8fc8 4845
cc1e2398 4846 tempax = 0x000B;
21df8fc8 4847
cc1e2398
AK
4848 if (modeflag & DoubleScanMode)
4849 tempax |= 0x08000;
21df8fc8 4850
cc1e2398
AK
4851 if (tempbx & 0x0200)
4852 tempcx |= 0x0040;
21df8fc8 4853
cc1e2398 4854 temp = (tempax & 0xFF00) >> 8;
8104e329 4855 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
21df8fc8 4856
cc1e2398
AK
4857 if (tempbx & 0x0400)
4858 tempcx |= 0x0600;
21df8fc8 4859
1d7f656d
KT
4860 /* 0x11 Vertival Blank End */
4861 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
21df8fc8 4862
cc1e2398
AK
4863 tempax = push1;
4864 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
4865 tempax = tempax >> 2;
4866 push1 = tempax; /* push ax */
4867
4868 if (resinfo != 0x09) {
4869 tempax = tempax << 1;
4870 tempbx += tempax;
4871 }
4872
4873 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4874 if (pVBInfo->VBType & VB_XGI301LV) {
4875 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
4876 tempbx -= 10;
4877 } else {
4878 if (pVBInfo->TVInfo & TVSimuMode) {
4879 if (pVBInfo->TVInfo & SetPALTV) {
1d7f656d
KT
4880 if (pVBInfo->VBType &
4881 VB_XGI301LV) {
4882 if (!(pVBInfo->TVInfo &
4883 (SetYPbPrMode525p |
4884 SetYPbPrMode750p |
4885 SetYPbPrMode1080i)))
cc1e2398
AK
4886 tempbx += 40;
4887 } else {
4888 tempbx += 40;
4889 }
4890 }
4891 }
4892 }
4893 } else {
4894 tempbx -= 10;
4895 }
4896 } else {
4897 if (pVBInfo->TVInfo & TVSimuMode) {
4898 if (pVBInfo->TVInfo & SetPALTV) {
4899 if (pVBInfo->VBType & VB_XGI301LV) {
1d7f656d
KT
4900 if (!(pVBInfo->TVInfo &
4901 (SetYPbPrMode525p |
4902 SetYPbPrMode750p |
4903 SetYPbPrMode1080i)))
cc1e2398
AK
4904 tempbx += 40;
4905 } else {
4906 tempbx += 40;
4907 }
21df8fc8
PS
4908 }
4909 }
4910 }
cc1e2398
AK
4911 tempax = push1;
4912 tempax = tempax >> 2;
4913 tempax++;
4914 tempax += tempbx;
4915 push1 = tempax; /* push ax */
21df8fc8 4916
cc1e2398
AK
4917 if ((pVBInfo->TVInfo & SetPALTV)) {
4918 if (tempbx <= 513) {
4919 if (tempax >= 513)
4920 tempbx = 513;
4921 }
4922 }
4923
4924 temp = tempbx & 0x00FF;
8104e329 4925 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
21df8fc8
PS
4926 tempbx--;
4927 temp = tempbx & 0x00FF;
8104e329 4928 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
21df8fc8 4929
cc1e2398
AK
4930 if (tempbx & 0x0100)
4931 tempcx |= 0x0008;
21df8fc8 4932
cc1e2398 4933 if (tempbx & 0x0200)
ec9e5d3e 4934 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
21df8fc8 4935
cc1e2398 4936 tempbx++;
21df8fc8 4937
cc1e2398
AK
4938 if (tempbx & 0x0100)
4939 tempcx |= 0x0004;
21df8fc8 4940
cc1e2398
AK
4941 if (tempbx & 0x0200)
4942 tempcx |= 0x0080;
21df8fc8 4943
cc1e2398
AK
4944 if (tempbx & 0x0400)
4945 tempcx |= 0x0C00;
21df8fc8 4946
cc1e2398
AK
4947 tempbx = push1; /* pop ax */
4948 temp = tempbx & 0x00FF;
4949 temp &= 0x0F;
1d7f656d
KT
4950 /* 0x0D vertical Retrace End */
4951 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
21df8fc8 4952
cc1e2398
AK
4953 if (tempbx & 0x0010)
4954 tempcx |= 0x2000;
21df8fc8 4955
cc1e2398 4956 temp = tempcx & 0x00FF;
8104e329 4957 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
cc1e2398 4958 temp = (tempcx & 0x0FF00) >> 8;
8104e329 4959 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
cc1e2398
AK
4960 tempax = modeflag;
4961 temp = (tempax & 0xFF00) >> 8;
21df8fc8 4962
cc1e2398 4963 temp = (temp >> 1) & 0x09;
21df8fc8 4964
cc1e2398
AK
4965 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4966 temp |= 0x01;
21df8fc8 4967
8104e329
AK
4968 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
4969 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
4970 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
21df8fc8 4971
cc1e2398
AK
4972 if (pVBInfo->LCDInfo & LCDRGB18Bit)
4973 temp = 0x80;
4974 else
4975 temp = 0x00;
21df8fc8 4976
8104e329 4977 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
21df8fc8 4978
cc1e2398
AK
4979 return;
4980}
21df8fc8 4981
cc1e2398
AK
4982static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
4983 unsigned short RefreshRateTableIndex,
4984 struct xgi_hw_device_info *HwDeviceExtension,
4985 struct vb_device_info *pVBInfo)
4986{
4987 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
4988 modeflag, resinfo, crt2crtc;
4989 unsigned char *TimingPoint;
21df8fc8 4990
cc1e2398
AK
4991 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
4992
4993 if (ModeNo <= 0x13) {
1d7f656d
KT
4994 /* si+St_ResInfo */
4995 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
cc1e2398
AK
4996 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4997 crt2crtc = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
4998 } else {
1d7f656d
KT
4999 /* si+Ext_ResInfo */
5000 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
cc1e2398 5001 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1d7f656d
KT
5002 crt2crtc = pVBInfo->RefIndex[RefreshRateTableIndex].
5003 Ext_CRT2CRTC;
21df8fc8
PS
5004 }
5005
cc1e2398
AK
5006 tempax = 0;
5007
5008 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
5009 tempax |= 0x0800;
21df8fc8 5010
cc1e2398
AK
5011 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5012 tempax |= 0x0400;
21df8fc8 5013
cc1e2398
AK
5014 if (pVBInfo->VBInfo & SetCRT2ToSCART)
5015 tempax |= 0x0200;
21df8fc8 5016
cc1e2398
AK
5017 if (!(pVBInfo->TVInfo & SetPALTV))
5018 tempax |= 0x1000;
21df8fc8 5019
cc1e2398
AK
5020 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5021 tempax |= 0x0100;
21df8fc8 5022
cc1e2398
AK
5023 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
5024 tempax &= 0xfe00;
21df8fc8 5025
cc1e2398 5026 tempax = (tempax & 0xff00) >> 8;
21df8fc8 5027
8104e329 5028 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
cc1e2398 5029 TimingPoint = pVBInfo->NTSCTiming;
d7636e0b 5030
cc1e2398
AK
5031 if (pVBInfo->TVInfo & SetPALTV)
5032 TimingPoint = pVBInfo->PALTiming;
d7636e0b 5033
cc1e2398
AK
5034 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5035 TimingPoint = pVBInfo->HiTVExtTiming;
d7636e0b 5036
cc1e2398
AK
5037 if (pVBInfo->VBInfo & SetInSlaveMode)
5038 TimingPoint = pVBInfo->HiTVSt2Timing;
d7636e0b 5039
cc1e2398
AK
5040 if (pVBInfo->SetFlag & TVSimuMode)
5041 TimingPoint = pVBInfo->HiTVSt1Timing;
21df8fc8 5042
cc1e2398
AK
5043 if (!(modeflag & Charx8Dot))
5044 TimingPoint = pVBInfo->HiTVTextTiming;
5045 }
21df8fc8
PS
5046
5047 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5048 if (pVBInfo->TVInfo & SetYPbPrMode525i)
cc1e2398
AK
5049 TimingPoint = pVBInfo->YPbPr525iTiming;
5050
21df8fc8 5051 if (pVBInfo->TVInfo & SetYPbPrMode525p)
cc1e2398
AK
5052 TimingPoint = pVBInfo->YPbPr525pTiming;
5053
21df8fc8 5054 if (pVBInfo->TVInfo & SetYPbPrMode750p)
cc1e2398 5055 TimingPoint = pVBInfo->YPbPr750pTiming;
21df8fc8 5056 }
d7636e0b 5057
cc1e2398 5058 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
8104e329 5059 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
cc1e2398
AK
5060
5061 for (i = 0x39; i <= 0x45; i++, j++)
1d7f656d
KT
5062 /* di->temp2[j] */
5063 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
cc1e2398
AK
5064
5065 if (pVBInfo->VBInfo & SetCRT2ToTV)
ec9e5d3e 5066 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
cc1e2398
AK
5067
5068 temp = pVBInfo->NewFlickerMode;
5069 temp &= 0x80;
ec9e5d3e 5070 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
cc1e2398 5071
21df8fc8 5072 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
cc1e2398 5073 tempax = 950;
21df8fc8 5074
cc1e2398
AK
5075 if (pVBInfo->TVInfo & SetPALTV)
5076 tempax = 520;
5077 else
5078 tempax = 440;
5079
5080 if (pVBInfo->VDE <= tempax) {
5081 tempax -= pVBInfo->VDE;
5082 tempax = tempax >> 2;
5083 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
5084 push1 = tempax;
5085 temp = (tempax & 0xFF00) >> 8;
5086 temp += (unsigned short) TimingPoint[0];
5087
5088 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5089 | VB_XGI302LV | VB_XGI301C)) {
5090 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
5091 | SetCRT2ToSVIDEO | SetCRT2ToSCART
5092 | SetCRT2ToYPbPr)) {
5093 tempcx = pVBInfo->VGAHDE;
5094 if (tempcx >= 1024) {
5095 temp = 0x17; /* NTSC */
5096 if (pVBInfo->TVInfo & SetPALTV)
5097 temp = 0x19; /* PAL */
5098 }
5099 }
5100 }
5101
8104e329 5102 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
cc1e2398
AK
5103 tempax = push1;
5104 temp = (tempax & 0xFF00) >> 8;
5105 temp += TimingPoint[1];
5106
5107 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5108 | VB_XGI302LV | VB_XGI301C)) {
5109 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
5110 | SetCRT2ToSVIDEO | SetCRT2ToSCART
5111 | SetCRT2ToYPbPr))) {
5112 tempcx = pVBInfo->VGAHDE;
5113 if (tempcx >= 1024) {
5114 temp = 0x1D; /* NTSC */
5115 if (pVBInfo->TVInfo & SetPALTV)
5116 temp = 0x52; /* PAL */
5117 }
5118 }
5119 }
8104e329 5120 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
21df8fc8 5121 }
d7636e0b 5122
cc1e2398
AK
5123 /* 301b */
5124 tempcx = pVBInfo->HT;
d7636e0b 5125
cc1e2398
AK
5126 if (XGI_IsLCDDualLink(pVBInfo))
5127 tempcx = tempcx >> 1;
21df8fc8 5128
cc1e2398
AK
5129 tempcx -= 2;
5130 temp = tempcx & 0x00FF;
8104e329 5131 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
21df8fc8 5132
cc1e2398 5133 temp = (tempcx & 0xFF00) >> 8;
ec9e5d3e 5134 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
21df8fc8 5135
cc1e2398
AK
5136 tempcx = pVBInfo->HT >> 1;
5137 push1 = tempcx; /* push cx */
5138 tempcx += 7;
21df8fc8 5139
cc1e2398
AK
5140 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5141 tempcx -= 4;
5142
5143 temp = tempcx & 0x00FF;
5144 temp = temp << 4;
ec9e5d3e 5145 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
cc1e2398
AK
5146
5147 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5148 tempbx += tempcx;
5149 push2 = tempbx;
5150 temp = tempbx & 0x00FF;
8104e329 5151 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
cc1e2398
AK
5152 temp = (tempbx & 0xFF00) >> 8;
5153 temp = temp << 4;
ec9e5d3e 5154 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
cc1e2398
AK
5155
5156 tempbx = push2;
5157 tempbx = tempbx + 8;
5158 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5159 tempbx = tempbx - 4;
5160 tempcx = tempbx;
21df8fc8
PS
5161 }
5162
cc1e2398 5163 temp = (tempbx & 0x00FF) << 4;
ec9e5d3e 5164 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
d7636e0b 5165
cc1e2398
AK
5166 j += 2;
5167 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
5168 temp = tempcx & 0x00FF;
8104e329 5169 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
cc1e2398 5170 temp = ((tempcx & 0xFF00) >> 8) << 4;
ec9e5d3e 5171 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
21df8fc8 5172
cc1e2398
AK
5173 tempcx += 8;
5174 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5175 tempcx -= 4;
21df8fc8 5176
cc1e2398
AK
5177 temp = tempcx & 0xFF;
5178 temp = temp << 4;
ec9e5d3e 5179 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
cc1e2398
AK
5180
5181 tempcx = push1; /* pop cx */
5182 j += 2;
5183 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5184 tempcx -= temp;
5185 temp = tempcx & 0x00FF;
5186 temp = temp << 4;
ec9e5d3e 5187 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
cc1e2398
AK
5188
5189 tempcx -= 11;
5190
5191 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
5192 tempax = XGI_GetVGAHT2(pVBInfo);
5193 tempcx = tempax - 1;
21df8fc8 5194 }
cc1e2398 5195 temp = tempcx & 0x00FF;
8104e329 5196 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
d7636e0b 5197
cc1e2398 5198 tempbx = pVBInfo->VDE;
21df8fc8 5199
cc1e2398
AK
5200 if (pVBInfo->VGAVDE == 360)
5201 tempbx = 746;
5202 if (pVBInfo->VGAVDE == 375)
5203 tempbx = 746;
5204 if (pVBInfo->VGAVDE == 405)
5205 tempbx = 853;
5206
5207 if (pVBInfo->VBInfo & SetCRT2ToTV) {
1d7f656d
KT
5208 if (pVBInfo->VBType &
5209 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
5210 if (!(pVBInfo->TVInfo &
5211 (SetYPbPrMode525p | SetYPbPrMode750p)))
cc1e2398
AK
5212 tempbx = tempbx >> 1;
5213 } else
5214 tempbx = tempbx >> 1;
21df8fc8
PS
5215 }
5216
cc1e2398
AK
5217 tempbx -= 2;
5218 temp = tempbx & 0x00FF;
21df8fc8 5219
cc1e2398
AK
5220 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5221 if (pVBInfo->VBType & VB_XGI301LV) {
5222 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5223 if (pVBInfo->VBInfo & SetInSlaveMode) {
5224 if (ModeNo == 0x2f)
5225 temp += 1;
5226 }
5227 }
5228 } else {
5229 if (pVBInfo->VBInfo & SetInSlaveMode) {
5230 if (ModeNo == 0x2f)
5231 temp += 1;
5232 }
21df8fc8 5233 }
cc1e2398 5234 }
21df8fc8 5235
8104e329 5236 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
21df8fc8 5237
cc1e2398
AK
5238 temp = (tempcx & 0xFF00) >> 8;
5239 temp |= ((tempbx & 0xFF00) >> 8) << 6;
21df8fc8 5240
cc1e2398
AK
5241 if (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) {
5242 if (pVBInfo->VBType & VB_XGI301LV) {
5243 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5244 temp |= 0x10;
21df8fc8 5245
cc1e2398
AK
5246 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5247 temp |= 0x20;
5248 }
5249 } else {
5250 temp |= 0x10;
5251 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5252 temp |= 0x20;
21df8fc8
PS
5253 }
5254 }
21df8fc8 5255
8104e329 5256 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
21df8fc8 5257
cc1e2398
AK
5258 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5259 | VB_XGI302LV | VB_XGI301C)) { /* TV gatingno */
5260 tempbx = pVBInfo->VDE;
5261 tempcx = tempbx - 2;
21df8fc8 5262
cc1e2398
AK
5263 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5264 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p
5265 | SetYPbPrMode750p)))
5266 tempbx = tempbx >> 1;
5267 }
21df8fc8 5268
cc1e2398
AK
5269 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
5270 temp = 0;
5271 if (tempcx & 0x0400)
5272 temp |= 0x20;
21df8fc8 5273
cc1e2398
AK
5274 if (tempbx & 0x0400)
5275 temp |= 0x40;
21df8fc8 5276
8104e329 5277 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
cc1e2398 5278 }
21df8fc8 5279
cc1e2398 5280 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
8104e329 5281 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
cc1e2398 5282 temp = (tempbx - 3) & 0x00FF;
8104e329 5283 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
cc1e2398 5284 }
21df8fc8 5285
cc1e2398 5286 tempbx = tempbx & 0x00FF;
21df8fc8 5287
cc1e2398
AK
5288 if (!(modeflag & HalfDCLK)) {
5289 tempcx = pVBInfo->VGAHDE;
5290 if (tempcx >= pVBInfo->HDE) {
5291 tempbx |= 0x2000;
5292 tempax &= 0x00FF;
5293 }
5294 }
21df8fc8 5295
cc1e2398 5296 tempcx = 0x0101;
21df8fc8 5297
cc1e2398
AK
5298 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
5299 if (pVBInfo->VGAHDE >= 1024) {
5300 tempcx = 0x1920;
5301 if (pVBInfo->VGAHDE >= 1280) {
5302 tempcx = 0x1420;
5303 tempbx = tempbx & 0xDFFF;
5304 }
21df8fc8
PS
5305 }
5306 }
5307
cc1e2398
AK
5308 if (!(tempbx & 0x2000)) {
5309 if (modeflag & HalfDCLK)
5310 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
21df8fc8 5311
cc1e2398
AK
5312 push1 = tempbx;
5313 tempeax = pVBInfo->VGAHDE;
5314 tempebx = (tempcx & 0xFF00) >> 8;
5315 longtemp = tempeax * tempebx;
5316 tempecx = tempcx & 0x00FF;
5317 longtemp = longtemp / tempecx;
21df8fc8 5318
cc1e2398
AK
5319 /* 301b */
5320 tempecx = 8 * 1024;
21df8fc8 5321
cc1e2398
AK
5322 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5323 | VB_XGI302LV | VB_XGI301C)) {
5324 tempecx = tempecx * 8;
5325 }
21df8fc8 5326
cc1e2398
AK
5327 longtemp = longtemp * tempecx;
5328 tempecx = pVBInfo->HDE;
5329 temp2 = longtemp % tempecx;
5330 tempeax = longtemp / tempecx;
5331 if (temp2 != 0)
5332 tempeax += 1;
21df8fc8 5333
cc1e2398 5334 tempax = (unsigned short) tempeax;
21df8fc8 5335
cc1e2398
AK
5336 /* 301b */
5337 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5338 | VB_XGI302LV | VB_XGI301C)) {
5339 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
5340 }
5341 /* end 301b */
21df8fc8 5342
cc1e2398
AK
5343 tempbx = push1;
5344 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
5345 | (tempbx & 0x00FF));
5346 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
5347 | (tempax & 0x00FF));
5348 temp = (tempax & 0xFF00) >> 8;
5349 } else {
5350 temp = (tempax & 0x00FF) >> 8;
5351 }
21df8fc8 5352
8104e329 5353 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
cc1e2398 5354 temp = (tempbx & 0xFF00) >> 8;
ec9e5d3e 5355 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
cc1e2398 5356 temp = tempcx & 0x00FF;
21df8fc8 5357
cc1e2398
AK
5358 if (tempbx & 0x2000)
5359 temp = 0;
21df8fc8 5360
cc1e2398
AK
5361 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5362 temp |= 0x18;
21df8fc8 5363
ec9e5d3e 5364 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
cc1e2398
AK
5365 if (pVBInfo->TVInfo & SetPALTV) {
5366 tempbx = 0x0382;
5367 tempcx = 0x007e;
5368 } else {
5369 tempbx = 0x0369;
5370 tempcx = 0x0061;
5371 }
21df8fc8 5372
cc1e2398 5373 temp = tempbx & 0x00FF;
8104e329 5374 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
cc1e2398 5375 temp = tempcx & 0x00FF;
8104e329 5376 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
21df8fc8 5377
cc1e2398
AK
5378 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
5379 temp = temp << 2;
5380 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
21df8fc8 5381
cc1e2398
AK
5382 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5383 temp |= 0x10;
21df8fc8 5384
cc1e2398
AK
5385 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5386 temp |= 0x20;
21df8fc8 5387
cc1e2398
AK
5388 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5389 temp |= 0x60;
5390 }
21df8fc8 5391
8104e329 5392 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
58839b01 5393 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
8104e329 5394 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
cc1e2398
AK
5395
5396 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))) {
5397 if (pVBInfo->TVInfo & NTSC1024x768) {
5398 TimingPoint = XGI_NTSC1024AdjTime;
5399 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
8104e329 5400 xgifb_reg_set(pVBInfo->Part2Port, i,
cc1e2398 5401 TimingPoint[j]);
21df8fc8 5402 }
8104e329 5403 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
21df8fc8 5404 }
cc1e2398 5405 }
21df8fc8 5406
cc1e2398
AK
5407 /* [ycchen] 01/14/03 Modify for 301C PALM Support */
5408 if (pVBInfo->VBType & VB_XGI301C) {
5409 if (pVBInfo->TVInfo & SetPALMTV)
ec9e5d3e 5410 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
cc1e2398 5411 0x08); /* PALM Mode */
21df8fc8 5412 }
21df8fc8 5413
cc1e2398 5414 if (pVBInfo->TVInfo & SetPALMTV) {
58839b01 5415 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
cc1e2398
AK
5416 0x01);
5417 tempax--;
dc50556b 5418 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
d7636e0b 5419
cc1e2398 5420 /* if ( !( pVBInfo->VBType & VB_XGI301C ) ) */
dc50556b 5421 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
cc1e2398 5422 }
21df8fc8 5423
cc1e2398
AK
5424 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5425 if (!(pVBInfo->VBInfo & SetInSlaveMode))
8104e329 5426 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
21df8fc8 5427 }
cc1e2398
AK
5428
5429 if (pVBInfo->VBInfo & SetCRT2ToTV)
5430 return;
21df8fc8 5431}
d7636e0b 5432
cc1e2398
AK
5433static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
5434 struct xgi_hw_device_info *HwDeviceExtension,
21df8fc8
PS
5435 unsigned short RefreshRateTableIndex,
5436 struct vb_device_info *pVBInfo)
5437{
cc1e2398
AK
5438 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
5439 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
d7636e0b 5440
cc1e2398 5441 struct XGI_LCDDesStruct *LCDBDesPtr = NULL;
d7636e0b 5442
21df8fc8 5443 if (ModeNo <= 0x13) {
1d7f656d
KT
5444 /* si+St_ResInfo */
5445 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
cc1e2398 5446 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
21df8fc8 5447 } else {
1d7f656d
KT
5448 /* si+Ext_ResInfo */
5449 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
cc1e2398 5450 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1d7f656d
KT
5451 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
5452 Ext_CRT1CRTC;
cc1e2398 5453 CRT1Index &= IndexMask;
21df8fc8 5454 }
d7636e0b 5455
cc1e2398
AK
5456 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5457 return;
21df8fc8 5458
cc1e2398 5459 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
21df8fc8 5460
cc1e2398
AK
5461 if (XGI_IsLCDDualLink(pVBInfo))
5462 tempbx = tempbx >> 1;
21df8fc8 5463
cc1e2398
AK
5464 tempbx -= 1;
5465 temp = tempbx & 0x00FF;
8104e329 5466 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
cc1e2398
AK
5467 temp = (tempbx & 0xFF00) >> 8;
5468 temp = temp << 4;
ec9e5d3e 5469 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
cc1e2398 5470 temp = 0x01;
21df8fc8 5471
cc1e2398
AK
5472 if (pVBInfo->LCDResInfo == Panel1280x1024) {
5473 if (pVBInfo->ModeType == ModeEGA) {
5474 if (pVBInfo->VGAHDE >= 1024) {
5475 temp = 0x02;
5476 if (pVBInfo->LCDInfo & LCDVESATiming)
5477 temp = 0x01;
5478 }
5479 }
21df8fc8 5480 }
d7636e0b 5481
8104e329 5482 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
cc1e2398
AK
5483 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
5484 push1 = tempbx;
5485 tempbx--;
5486 temp = tempbx & 0x00FF;
8104e329 5487 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
cc1e2398 5488 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
ec9e5d3e 5489 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
21df8fc8 5490
cc1e2398
AK
5491 tempcx = pVBInfo->VT - 1;
5492 push2 = tempcx + 1;
5493 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
8104e329 5494 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
cc1e2398
AK
5495 temp = (tempcx & 0xFF00) >> 8;
5496 temp = temp << 5;
8104e329 5497 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
ec9e5d3e
AK
5498 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
5499 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
5500 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
5501 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
d7636e0b 5502
cc1e2398
AK
5503 /* Customized LCDB Des no add */
5504 tempbx = 5;
5505 LCDBDesPtr = (struct XGI_LCDDesStruct *) XGI_GetLcdPtr(tempbx, ModeNo,
5506 ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5507 tempah = pVBInfo->LCDResInfo;
5508 tempah &= PanelResInfo;
d7636e0b 5509
cc1e2398
AK
5510 if ((tempah == Panel1024x768) || (tempah == Panel1024x768x75)) {
5511 tempbx = 1024;
5512 tempcx = 768;
1d7f656d
KT
5513 } else if ((tempah == Panel1280x1024) ||
5514 (tempah == Panel1280x1024x75)) {
cc1e2398
AK
5515 tempbx = 1280;
5516 tempcx = 1024;
5517 } else if (tempah == Panel1400x1050) {
5518 tempbx = 1400;
5519 tempcx = 1050;
5520 } else {
5521 tempbx = 1600;
5522 tempcx = 1200;
5523 }
d7636e0b 5524
cc1e2398
AK
5525 if (pVBInfo->LCDInfo & EnableScalingLCD) {
5526 tempbx = pVBInfo->HDE;
5527 tempcx = pVBInfo->VDE;
5528 }
d7636e0b 5529
cc1e2398
AK
5530 pushbx = tempbx;
5531 tempax = pVBInfo->VT;
5532 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
5533 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
5534 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
5535 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
5536 tempbx = pVBInfo->LCDVDES;
5537 tempcx += tempbx;
d7636e0b 5538
cc1e2398
AK
5539 if (tempcx >= tempax)
5540 tempcx -= tempax; /* lcdvdes */
d7636e0b 5541
cc1e2398 5542 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
8104e329 5543 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
cc1e2398 5544 temp = tempcx & 0x00FF;
8104e329 5545 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
cc1e2398
AK
5546 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
5547 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
5548 tempah = tempch;
5549 tempah = tempah << 3;
5550 tempah |= tempbh;
8104e329 5551 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
d7636e0b 5552
cc1e2398
AK
5553 /* getlcdsync() */
5554 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5555 tempcx = tempbx;
5556 tempax = pVBInfo->VT;
5557 tempbx = pVBInfo->LCDVRS;
d7636e0b 5558
cc1e2398
AK
5559 /* if (SetLCD_Info & EnableScalingLCD) */
5560 tempcx += tempbx;
5561 if (tempcx >= tempax)
5562 tempcx -= tempax;
d7636e0b 5563
cc1e2398 5564 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
8104e329 5565 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
cc1e2398
AK
5566 temp = (tempbx & 0xFF00) >> 8;
5567 temp = temp << 4;
5568 temp |= (tempcx & 0x000F);
8104e329 5569 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
cc1e2398
AK
5570 tempcx = pushbx;
5571 tempax = pVBInfo->HT;
5572 tempbx = pVBInfo->LCDHDES;
5573 tempbx &= 0x0FFF;
5574
5575 if (XGI_IsLCDDualLink(pVBInfo)) {
5576 tempax = tempax >> 1;
5577 tempbx = tempbx >> 1;
5578 tempcx = tempcx >> 1;
5579 }
5580
5581 if (pVBInfo->VBType & VB_XGI302LV)
5582 tempbx += 1;
5583
5584 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
5585 tempbx += 1;
5586
5587 tempcx += tempbx;
5588
5589 if (tempcx >= tempax)
5590 tempcx -= tempax;
5591
5592 temp = tempbx & 0x00FF;
8104e329 5593 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
cc1e2398 5594 temp = ((tempbx & 0xFF00) >> 8) << 4;
8104e329 5595 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
cc1e2398 5596 temp = tempcx & 0x00FF;
8104e329 5597 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
cc1e2398 5598 temp = (tempcx & 0xFF00) >> 8;
8104e329 5599 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
cc1e2398
AK
5600
5601 /* getlcdsync() */
5602 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5603 tempcx = tempax;
5604 tempax = pVBInfo->HT;
5605 tempbx = pVBInfo->LCDHRS;
5606 /* if ( SetLCD_Info & EnableScalingLCD) */
5607 if (XGI_IsLCDDualLink(pVBInfo)) {
5608 tempax = tempax >> 1;
5609 tempbx = tempbx >> 1;
5610 tempcx = tempcx >> 1;
5611 }
5612
5613 if (pVBInfo->VBType & VB_XGI302LV)
5614 tempbx += 1;
5615
5616 tempcx += tempbx;
5617
5618 if (tempcx >= tempax)
5619 tempcx -= tempax;
5620
5621 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
8104e329 5622 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
cc1e2398
AK
5623
5624 temp = (tempbx & 0xFF00) >> 8;
5625 temp = temp << 4;
ec9e5d3e 5626 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
cc1e2398 5627 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
8104e329 5628 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
cc1e2398
AK
5629
5630 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
5631 if (pVBInfo->VGAVDE == 525) {
5632 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5633 | VB_XGI301LV | VB_XGI302LV
5634 | VB_XGI301C)) {
5635 temp = 0xC6;
5636 } else
5637 temp = 0xC4;
5638
8104e329
AK
5639 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
5640 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
21df8fc8 5641 }
cc1e2398
AK
5642
5643 if (pVBInfo->VGAVDE == 420) {
5644 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5645 | VB_XGI301LV | VB_XGI302LV
5646 | VB_XGI301C)) {
5647 temp = 0x4F;
5648 } else
5649 temp = 0x4E;
8104e329 5650 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
21df8fc8 5651 }
cc1e2398
AK
5652 }
5653}
5654
5655/* --------------------------------------------------------------------- */
5656/* Function : XGI_GetTap4Ptr */
5657/* Input : */
5658/* Output : di -> Tap4 Reg. Setting Pointer */
5659/* Description : */
5660/* --------------------------------------------------------------------- */
5661static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
5662 struct vb_device_info *pVBInfo)
5663{
5664 unsigned short tempax, tempbx, i;
5665
5666 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
5667
5668 if (tempcx == 0) {
5669 tempax = pVBInfo->VGAHDE;
5670 tempbx = pVBInfo->HDE;
5671 } else {
5672 tempax = pVBInfo->VGAVDE;
5673 tempbx = pVBInfo->VDE;
5674 }
5675
11fbdcde
AK
5676 if (tempax <= tempbx)
5677 return &xgifb_tap4_timing[0];
cc1e2398 5678 else
11fbdcde 5679 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
cc1e2398
AK
5680
5681 if (pVBInfo->TVInfo & SetPALTV)
5682 Tap4TimingPtr = PALTap4Timing;
5683
5684 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
11fbdcde
AK
5685 if ((pVBInfo->TVInfo & SetYPbPrMode525i) ||
5686 (pVBInfo->TVInfo & SetYPbPrMode525p))
5687 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
cc1e2398
AK
5688 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5689 Tap4TimingPtr = YPbPr750pTap4Timing;
5690 }
5691
5692 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
11fbdcde 5693 Tap4TimingPtr = xgifb_tap4_timing;
cc1e2398
AK
5694
5695 i = 0;
5696 while (Tap4TimingPtr[i].DE != 0xFFFF) {
5697 if (Tap4TimingPtr[i].DE == tempax)
21df8fc8 5698 break;
cc1e2398
AK
5699 i++;
5700 }
5701 return &Tap4TimingPtr[i];
5702}
5703
5704static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
5705{
5706 unsigned short i, j;
5707
5708 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
5709
5710 if (!(pVBInfo->VBType & VB_XGI301C))
5711 return;
5712
cc1e2398
AK
5713 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
5714 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
8104e329 5715 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
cc1e2398 5716
1d7f656d
KT
5717 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5718 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV))) {
5719 /* Set Vertical Scaling */
5720 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
cc1e2398 5721 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
1d7f656d
KT
5722 xgifb_reg_set(pVBInfo->Part2Port,
5723 i,
5724 Tap4TimingPtr->Reg[j]);
cc1e2398
AK
5725 }
5726
1d7f656d
KT
5727 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5728 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)))
5729 /* Enable V.Scaling */
5730 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
cc1e2398 5731 else
1d7f656d
KT
5732 /* Enable H.Scaling */
5733 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
cc1e2398
AK
5734}
5735
5736static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
5737 struct vb_device_info *pVBInfo)
5738{
5739 unsigned short i;
5740 unsigned char *tempdi;
5741 unsigned short modeflag;
5742
5743 if (ModeNo <= 0x13)
1d7f656d
KT
5744 /* si+St_ResInfo */
5745 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
cc1e2398 5746 else
1d7f656d
KT
5747 /* si+Ext_ResInfo */
5748 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
cc1e2398 5749
8104e329 5750 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
cc1e2398 5751 if (pVBInfo->TVInfo & SetPALTV) {
8104e329
AK
5752 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5753 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
cc1e2398 5754 } else {
8104e329
AK
5755 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
5756 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
cc1e2398
AK
5757 }
5758
5759 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5760 return;
5761
5762 if (pVBInfo->TVInfo & SetPALMTV) {
8104e329
AK
5763 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5764 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
5765 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
cc1e2398
AK
5766 }
5767
5768 if ((pVBInfo->VBInfo & SetCRT2ToHiVisionTV) || (pVBInfo->VBInfo
5769 & SetCRT2ToYPbPr)) {
5770 if (pVBInfo->TVInfo & SetYPbPrMode525i)
5771 return;
5772
5773 tempdi = pVBInfo->HiTVGroup3Data;
5774 if (pVBInfo->SetFlag & TVSimuMode) {
5775 tempdi = pVBInfo->HiTVGroup3Simu;
5776 if (!(modeflag & Charx8Dot))
5777 tempdi = pVBInfo->HiTVGroup3Text;
21df8fc8 5778 }
cc1e2398
AK
5779
5780 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5781 tempdi = pVBInfo->Ren525pGroup3;
5782
5783 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5784 tempdi = pVBInfo->Ren750pGroup3;
5785
5786 for (i = 0; i <= 0x3E; i++)
8104e329 5787 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
cc1e2398
AK
5788
5789 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
5790 if (pVBInfo->TVInfo & SetYPbPrMode525p)
8104e329 5791 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
21df8fc8
PS
5792 }
5793 }
cc1e2398
AK
5794 return;
5795} /* {end of XGI_SetGroup3} */
d7636e0b 5796
cc1e2398 5797static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
21df8fc8 5798 unsigned short RefreshRateTableIndex,
cc1e2398 5799 struct xgi_hw_device_info *HwDeviceExtension,
21df8fc8
PS
5800 struct vb_device_info *pVBInfo)
5801{
cc1e2398 5802 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
d7636e0b 5803
cc1e2398
AK
5804 unsigned long tempebx, tempeax, templong;
5805
5806 if (ModeNo <= 0x13)
1d7f656d
KT
5807 /* si+St_ResInfo */
5808 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
cc1e2398 5809 else
1d7f656d
KT
5810 /* si+Ext_ResInfo */
5811 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
cc1e2398
AK
5812
5813 temp = pVBInfo->RVBHCFACT;
8104e329 5814 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
cc1e2398
AK
5815
5816 tempbx = pVBInfo->RVBHCMAX;
5817 temp = tempbx & 0x00FF;
8104e329 5818 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
cc1e2398
AK
5819 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
5820 tempcx = pVBInfo->VGAHT - 1;
5821 temp = tempcx & 0x00FF;
8104e329 5822 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
cc1e2398
AK
5823
5824 temp = ((tempcx & 0xFF00) >> 8) << 3;
5825 temp2 |= temp;
5826
5827 tempcx = pVBInfo->VGAVT - 1;
5828 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5829 tempcx -= 5;
5830
5831 temp = tempcx & 0x00FF;
8104e329 5832 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
cc1e2398 5833 temp = temp2 | ((tempcx & 0xFF00) >> 8);
8104e329 5834 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
b9bf6e4e 5835 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
cc1e2398
AK
5836 tempcx = pVBInfo->VBInfo;
5837 tempbx = pVBInfo->VGAHDE;
5838
5839 if (modeflag & HalfDCLK)
5840 tempbx = tempbx >> 1;
5841
5842 if (XGI_IsLCDDualLink(pVBInfo))
5843 tempbx = tempbx >> 1;
5844
5845 if (tempcx & SetCRT2ToHiVisionTV) {
5846 temp = 0;
5847 if (tempbx <= 1024)
5848 temp = 0xA0;
5849 if (tempbx == 1280)
5850 temp = 0xC0;
5851 } else if (tempcx & SetCRT2ToTV) {
5852 temp = 0xA0;
5853 if (tempbx <= 800)
5854 temp = 0x80;
5855 } else {
5856 temp = 0x80;
5857 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5858 temp = 0;
5859 if (tempbx > 800)
5860 temp = 0x60;
5861 }
5862 }
5863
5864 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p)) {
5865 temp = 0x00;
5866 if (pVBInfo->VGAHDE == 1280)
5867 temp = 0x40;
5868 if (pVBInfo->VGAHDE == 1024)
5869 temp = 0x20;
5870 }
ec9e5d3e 5871 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
cc1e2398
AK
5872
5873 tempebx = pVBInfo->VDE;
5874
5875 if (tempcx & SetCRT2ToHiVisionTV) {
5876 if (!(temp & 0xE000))
5877 tempbx = tempbx >> 1;
5878 }
5879
5880 tempcx = pVBInfo->RVBHRS;
5881 temp = tempcx & 0x00FF;
8104e329 5882 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
cc1e2398
AK
5883
5884 tempeax = pVBInfo->VGAVDE;
5885 tempcx |= 0x04000;
5886
5887 if (tempeax <= tempebx) {
5888 tempcx = (tempcx & (~0x4000));
5889 tempeax = pVBInfo->VGAVDE;
5890 } else {
5891 tempeax -= tempebx;
5892 }
5893
5894 templong = (tempeax * 256 * 1024) % tempebx;
5895 tempeax = (tempeax * 256 * 1024) / tempebx;
5896 tempebx = tempeax;
5897
5898 if (templong != 0)
5899 tempebx++;
5900
5901 temp = (unsigned short) (tempebx & 0x000000FF);
8104e329 5902 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
cc1e2398
AK
5903
5904 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
8104e329 5905 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
cc1e2398
AK
5906 tempbx = (unsigned short) (tempebx >> 16);
5907 temp = tempbx & 0x00FF;
5908 temp = temp << 4;
5909 temp |= ((tempcx & 0xFF00) >> 8);
8104e329 5910 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
cc1e2398
AK
5911
5912 /* 301b */
5913 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5914 | VB_XGI302LV | VB_XGI301C)) {
5915 temp = 0x0028;
8104e329 5916 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
cc1e2398
AK
5917 tempax = pVBInfo->VGAHDE;
5918 if (modeflag & HalfDCLK)
5919 tempax = tempax >> 1;
d7636e0b 5920
cc1e2398
AK
5921 if (XGI_IsLCDDualLink(pVBInfo))
5922 tempax = tempax >> 1;
d7636e0b 5923
1d7f656d
KT
5924 /* if((pVBInfo->VBInfo&(SetCRT2ToLCD)) ||
5925 ((pVBInfo->TVInfo&SetYPbPrMode525p) ||
5926 (pVBInfo->TVInfo&SetYPbPrMode750p))) { */
cc1e2398
AK
5927 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5928 if (tempax > 800)
5929 tempax -= 800;
5930 } else {
5931 if (pVBInfo->VGAHDE > 800) {
5932 if (pVBInfo->VGAHDE == 1024)
5933 tempax = (tempax * 25 / 32) - 1;
5934 else
5935 tempax = (tempax * 20 / 32) - 1;
5936 }
5937 }
5938 tempax -= 1;
21df8fc8 5939
cc1e2398
AK
5940 /*
5941 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
5942 if (pVBInfo->VBType & VB_XGI301LV) {
1d7f656d
KT
5943 if (!(pVBInfo->TVInfo &
5944 (SetYPbPrMode525p |
5945 SetYPbPrMode750p |
5946 SetYPbPrMode1080i))) {
cc1e2398
AK
5947 if (pVBInfo->VGAHDE > 800) {
5948 if (pVBInfo->VGAHDE == 1024)
1d7f656d
KT
5949 tempax =(tempax * 25 /
5950 32) - 1;
cc1e2398 5951 else
1d7f656d
KT
5952 tempax = (tempax * 20 /
5953 32) - 1;
cc1e2398
AK
5954 }
5955 }
5956 } else {
5957 if (pVBInfo->VGAHDE > 800) {
5958 if (pVBInfo->VGAHDE == 1024)
5959 tempax = (tempax * 25 / 32) - 1;
5960 else
5961 tempax = (tempax * 20 / 32) - 1;
5962 }
5963 }
5964 }
5965 */
21df8fc8 5966
cc1e2398
AK
5967 temp = (tempax & 0xFF00) >> 8;
5968 temp = ((temp & 0x0003) << 4);
8104e329 5969 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
cc1e2398 5970 temp = (tempax & 0x00FF);
8104e329 5971 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
21df8fc8 5972
cc1e2398
AK
5973 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
5974 if (pVBInfo->VGAHDE > 800)
b9bf6e4e 5975 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
d7636e0b 5976
cc1e2398
AK
5977 }
5978 temp = 0x0036;
d7636e0b 5979
cc1e2398
AK
5980 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5981 if (!(pVBInfo->TVInfo & (NTSC1024x768
5982 | SetYPbPrMode525p | SetYPbPrMode750p
5983 | SetYPbPrMode1080i))) {
5984 temp |= 0x0001;
5985 if ((pVBInfo->VBInfo & SetInSlaveMode)
5986 && (!(pVBInfo->TVInfo
5987 & TVSimuMode)))
5988 temp &= (~0x0001);
5989 }
5990 }
d7636e0b 5991
ec9e5d3e 5992 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
cc1e2398
AK
5993 tempbx = pVBInfo->HT;
5994 if (XGI_IsLCDDualLink(pVBInfo))
5995 tempbx = tempbx >> 1;
5996 tempbx = (tempbx >> 1) - 2;
5997 temp = ((tempbx & 0x0700) >> 8) << 3;
ec9e5d3e 5998 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
cc1e2398 5999 temp = tempbx & 0x00FF;
8104e329 6000 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
cc1e2398
AK
6001 }
6002 /* end 301b */
d7636e0b 6003
cc1e2398
AK
6004 if (pVBInfo->ISXPDOS == 0)
6005 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6006 pVBInfo);
6007}
d7636e0b 6008
cc1e2398
AK
6009static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
6010{
ec9e5d3e 6011 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
cc1e2398 6012}
d7636e0b 6013
cc1e2398
AK
6014static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
6015 struct vb_device_info *pVBInfo)
6016{
6017 unsigned short Pindex, Pdata;
d7636e0b 6018
cc1e2398
AK
6019 Pindex = pVBInfo->Part5Port;
6020 Pdata = pVBInfo->Part5Port + 1;
6021 if (pVBInfo->ModeType == ModeVGA) {
6022 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
6023 | CRT2DisplayFlag))) {
6024 XGINew_EnableCRT2(pVBInfo);
6025 /* LoadDAC2(pVBInfo->Part5Port, ModeNo, ModeIdIndex); */
21df8fc8 6026 }
21df8fc8 6027 }
cc1e2398 6028 return;
d7636e0b 6029}
6030
063b9c4b 6031static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
21df8fc8 6032 struct vb_device_info *pVBInfo)
d7636e0b 6033{
ec9e5d3e 6034 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
d7636e0b 6035}
6036
063b9c4b 6037static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
21df8fc8 6038 struct vb_device_info *pVBInfo)
d7636e0b 6039{
6040
ec9e5d3e 6041 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
d7636e0b 6042}
6043
fac2cc92 6044static unsigned char XGI_XG21CheckLVDSMode(unsigned short ModeNo,
21df8fc8
PS
6045 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
6046{
6047 unsigned short xres, yres, colordepth, modeflag, resindex,
6048 lvdstableindex;
6049
6050 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6051 if (ModeNo <= 0x13) {
6052 xres = pVBInfo->StResInfo[resindex].HTotal;
6053 yres = pVBInfo->StResInfo[resindex].VTotal;
1d7f656d
KT
6054 /* si+St_ResInfo */
6055 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
21df8fc8
PS
6056 } else {
6057 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6058 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
1d7f656d
KT
6059 /* si+St_ModeFlag */
6060 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
21df8fc8
PS
6061 }
6062
6063 if (!(modeflag & Charx8Dot)) {
6064 xres /= 9;
6065 xres *= 8;
6066 }
6067
6068 if (ModeNo > 0x13) {
6069 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
6070 xres *= 2;
6071
6072 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6073 yres *= 2;
6074
6075 }
6076
6077 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
6078 if (xres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE))
6079 return 0;
6080
6081 if (yres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE))
6082 return 0;
6083
6084 if (ModeNo > 0x13) {
1d7f656d
KT
6085 if ((xres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6086 LVDSHDE)) ||
6087 (yres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6088 LVDSVDE))) {
6089 colordepth = XGI_GetColorDepth(ModeNo,
6090 ModeIdIndex,
6091 pVBInfo);
21df8fc8
PS
6092 if (colordepth > 2)
6093 return 0;
6094
6095 }
6096 }
6097 return 1;
d7636e0b 6098}
6099
64db29f5
AK
6100static void xgifb_set_lvds(int chip_id,
6101 unsigned short ModeNo,
6102 unsigned short ModeIdIndex,
6103 struct vb_device_info *pVBInfo)
21df8fc8
PS
6104{
6105 unsigned char temp, Miscdata;
6106 unsigned short xres, yres, modeflag, resindex, lvdstableindex;
6107 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
6108 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
6109 unsigned short value;
6110
6111 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
1d7f656d
KT
6112 temp = (unsigned char) ((pVBInfo->XG21_LVDSCapList[lvdstableindex].
6113 LVDS_Capability &
6114 (LCDPolarity << 8)) >> 8);
21df8fc8 6115 temp &= LCDPolarity;
d8ad0a6d 6116 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
21df8fc8 6117
efdf4ee7 6118 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
21df8fc8 6119
1d7f656d
KT
6120 temp = (unsigned char) (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6121 LVDS_Capability & LCDPolarity);
6122 /* SR35[7] FP VSync polarity */
6123 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
6124 /* SR30[5] FP HSync polarity */
6125 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
21df8fc8 6126
64db29f5
AK
6127 if (chip_id == XG27)
6128 XGI_SetXG27FPBits(pVBInfo);
6129 else
6130 XGI_SetXG21FPBits(pVBInfo);
6131
21df8fc8
PS
6132 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6133 if (ModeNo <= 0x13) {
6134 xres = pVBInfo->StResInfo[resindex].HTotal;
6135 yres = pVBInfo->StResInfo[resindex].VTotal;
1d7f656d
KT
6136 /* si+St_ResInfo */
6137 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
21df8fc8
PS
6138 } else {
6139 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6140 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
1d7f656d
KT
6141 /* si+St_ModeFlag */
6142 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
21df8fc8
PS
6143 }
6144
6145 if (!(modeflag & Charx8Dot))
6146 xres = xres * 8 / 9;
6147
6148 LVDSHT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHT;
d7636e0b 6149
21df8fc8
PS
6150 LVDSHBS = xres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE
6151 - xres) / 2;
6152 if ((ModeNo <= 0x13) && (modeflag & HalfDCLK))
6153 LVDSHBS -= xres / 4;
6154
6155 if (LVDSHBS > LVDSHT)
6156 LVDSHBS -= LVDSHT;
6157
6158 LVDSHRS = LVDSHBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHFP;
6159 if (LVDSHRS > LVDSHT)
6160 LVDSHRS -= LVDSHT;
6161
6162 LVDSHRE = LVDSHRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHSYNC;
6163 if (LVDSHRE > LVDSHT)
6164 LVDSHRE -= LVDSHT;
6165
6166 LVDSHBE = LVDSHBS + LVDSHT
6167 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE;
6168
6169 LVDSVT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVT;
d7636e0b 6170
21df8fc8
PS
6171 LVDSVBS = yres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE
6172 - yres) / 2;
6173 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6174 LVDSVBS += yres / 2;
6175
6176 if (LVDSVBS > LVDSVT)
6177 LVDSVBS -= LVDSVT;
6178
6179 LVDSVRS = LVDSVBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVFP;
6180 if (LVDSVRS > LVDSVT)
6181 LVDSVRS -= LVDSVT;
6182
1d7f656d
KT
6183 LVDSVRE = LVDSVRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].
6184 LVDSVSYNC;
21df8fc8
PS
6185 if (LVDSVRE > LVDSVT)
6186 LVDSVRE -= LVDSVT;
6187
6188 LVDSVBE = LVDSVBS + LVDSVT
6189 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE;
6190
58839b01 6191 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
8104e329 6192 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
21df8fc8
PS
6193
6194 if (!(modeflag & Charx8Dot))
b9bf6e4e 6195 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
21df8fc8
PS
6196
6197 /* HT SR0B[1:0] CR00 */
6198 value = (LVDSHT >> 3) - 5;
ec9e5d3e 6199 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
8104e329 6200 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
21df8fc8
PS
6201
6202 /* HBS SR0B[5:4] CR02 */
6203 value = (LVDSHBS >> 3) - 1;
ec9e5d3e 6204 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
8104e329 6205 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
21df8fc8
PS
6206
6207 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
6208 value = (LVDSHBE >> 3) - 1;
ec9e5d3e
AK
6209 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
6210 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
6211 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
21df8fc8
PS
6212
6213 /* HRS SR0B[7:6] CR04 */
6214 value = (LVDSHRS >> 3) + 2;
ec9e5d3e 6215 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
8104e329 6216 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
21df8fc8
PS
6217
6218 /* Panel HRS SR2F[1:0] SR2E[7:0] */
6219 value--;
ec9e5d3e 6220 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
8104e329 6221 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
21df8fc8
PS
6222
6223 /* HRE SR0C[2] CR05[4:0] */
6224 value = (LVDSHRE >> 3) + 2;
ec9e5d3e
AK
6225 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
6226 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
21df8fc8
PS
6227
6228 /* Panel HRE SR2F[7:2] */
6229 value--;
ec9e5d3e 6230 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
21df8fc8
PS
6231
6232 /* VT SR0A[0] CR07[5][0] CR06 */
6233 value = LVDSVT - 2;
ec9e5d3e
AK
6234 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
6235 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
6236 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
8104e329 6237 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
21df8fc8
PS
6238
6239 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
6240 value = LVDSVBS - 1;
ec9e5d3e
AK
6241 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
6242 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
6243 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
8104e329 6244 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
21df8fc8
PS
6245
6246 /* VBE SR0A[4] CR16 */
6247 value = LVDSVBE - 1;
ec9e5d3e 6248 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
8104e329 6249 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
21df8fc8
PS
6250
6251 /* VRS SR0A[3] CR7[7][2] CR10 */
6252 value = LVDSVRS - 1;
ec9e5d3e
AK
6253 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
6254 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
6255 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
8104e329 6256 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
21df8fc8 6257
64db29f5
AK
6258 if (chip_id == XG27) {
6259 /* Panel VRS SR35[2:0] SR34[7:0] */
6260 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
6261 (value & 0x700) >> 8);
6262 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
6263 } else {
6264 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
6265 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
6266 (value & 0x600) >> 9);
6267 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
6268 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
6269 }
21df8fc8
PS
6270
6271 /* VRE SR0A[5] CR11[3:0] */
6272 value = LVDSVRE - 1;
ec9e5d3e
AK
6273 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
6274 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
21df8fc8
PS
6275
6276 /* Panel VRE SR3F[7:2] */
64db29f5
AK
6277 if (chip_id == XG27)
6278 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6279 (value << 2) & 0xFC);
6280 else
6281 /* SR3F[7] has to be 0, h/w bug */
6282 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6283 (value << 2) & 0x7C);
21df8fc8
PS
6284
6285 for (temp = 0, value = 0; temp < 3; temp++) {
6286
ec9e5d3e 6287 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
8104e329 6288 xgifb_reg_set(pVBInfo->P3c4,
1d7f656d
KT
6289 0x2B,
6290 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6291 VCLKData1);
8104e329 6292 xgifb_reg_set(pVBInfo->P3c4,
1d7f656d
KT
6293 0x2C,
6294 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6295 VCLKData2);
21df8fc8
PS
6296 value += 0x10;
6297 }
d7636e0b 6298
21df8fc8 6299 if (!(modeflag & Charx8Dot)) {
d8ad0a6d 6300 inb(pVBInfo->P3da); /* reset 3da */
efdf4ee7 6301 outb(0x13, pVBInfo->P3c0); /* set index */
1d7f656d
KT
6302 /* set data, panning = 0, shift left 1 dot*/
6303 outb(0x00, pVBInfo->P3c0);
d7636e0b 6304
d8ad0a6d 6305 inb(pVBInfo->P3da); /* Enable Attribute */
efdf4ee7 6306 outb(0x20, pVBInfo->P3c0);
d7636e0b 6307
d8ad0a6d 6308 inb(pVBInfo->P3da); /* reset 3da */
21df8fc8 6309 }
d7636e0b 6310
6311}
6312
6313/* --------------------------------------------------------------------- */
6314/* Function : XGI_IsLCDON */
6315/* Input : */
dda08c59
BP
6316/* Output : 0 : Skip PSC Control */
6317/* 1: Disable PSC */
d7636e0b 6318/* Description : */
6319/* --------------------------------------------------------------------- */
063b9c4b 6320static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
d7636e0b 6321{
21df8fc8 6322 unsigned short tempax;
d7636e0b 6323
21df8fc8
PS
6324 tempax = pVBInfo->VBInfo;
6325 if (tempax & SetCRT2ToDualEdge)
6326 return 0;
6327 else if (tempax & (DisableCRT2Display | SwitchToCRT2 | SetSimuScanMode))
6328 return 1;
d7636e0b 6329
21df8fc8 6330 return 0;
d7636e0b 6331}
6332
d7636e0b 6333/* --------------------------------------------------------------------- */
6334/* Function : XGI_DisableChISLCD */
6335/* Input : */
dda08c59 6336/* Output : 0 -> Not LCD Mode */
d7636e0b 6337/* Description : */
6338/* --------------------------------------------------------------------- */
063b9c4b 6339static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
d7636e0b 6340{
21df8fc8 6341 unsigned short tempbx, tempah;
d7636e0b 6342
21df8fc8 6343 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
58839b01 6344 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
d7636e0b 6345
21df8fc8
PS
6346 if (tempbx & (EnableChA | DisableChA)) {
6347 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6348 return 0;
6349 }
d7636e0b 6350
21df8fc8
PS
6351 if (!(tempbx & (EnableChB | DisableChB)))
6352 return 0;
d7636e0b 6353
21df8fc8
PS
6354 if (tempah & 0x01) /* Chk LCDB Mode */
6355 return 1;
d7636e0b 6356
21df8fc8 6357 return 0;
d7636e0b 6358}
6359
d7636e0b 6360/* --------------------------------------------------------------------- */
6361/* Function : XGI_EnableChISLCD */
6362/* Input : */
6363/* Output : 0 -> Not LCD mode */
6364/* Description : */
6365/* --------------------------------------------------------------------- */
063b9c4b 6366static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
d7636e0b 6367{
21df8fc8 6368 unsigned short tempbx, tempah;
d7636e0b 6369
21df8fc8 6370 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
58839b01 6371 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
d7636e0b 6372
21df8fc8
PS
6373 if (tempbx & (EnableChA | DisableChA)) {
6374 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6375 return 0;
6376 }
d7636e0b 6377
21df8fc8 6378 if (!(tempbx & (EnableChB | DisableChB)))
dda08c59 6379 return 0;
d7636e0b 6380
21df8fc8
PS
6381 if (tempah & 0x01) /* Chk LCDB Mode */
6382 return 1;
d7636e0b 6383
cc1e2398
AK
6384 return 0;
6385}
6386
fac2cc92 6387static void XGI_DisableBridge(struct xgi_hw_device_info *HwDeviceExtension,
cc1e2398
AK
6388 struct vb_device_info *pVBInfo)
6389{
fd0ad470 6390 unsigned short tempah = 0;
cc1e2398 6391
cc1e2398
AK
6392 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6393 | VB_XGI302LV | VB_XGI301C)) {
6394 tempah = 0x3F;
1d7f656d
KT
6395 if (!(pVBInfo->VBInfo &
6396 (DisableCRT2Display | SetSimuScanMode))) {
cc1e2398
AK
6397 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6398 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6399 tempah = 0x7F; /* Disable Channel A */
6400 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
1d7f656d
KT
6401 /* Disable Channel B */
6402 tempah = 0xBF;
cc1e2398
AK
6403
6404 if (pVBInfo->SetFlag & DisableChB)
1d7f656d
KT
6405 /* force to disable Cahnnel */
6406 tempah &= 0xBF;
cc1e2398
AK
6407
6408 if (pVBInfo->SetFlag & DisableChA)
1d7f656d
KT
6409 /* Force to disable Channel B */
6410 tempah &= 0x7F;
cc1e2398
AK
6411 }
6412 }
6413 }
6414
1d7f656d
KT
6415 /* disable part4_1f */
6416 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
cc1e2398
AK
6417
6418 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6419 if (((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
6420 || (XGI_DisableChISLCD(pVBInfo))
6421 || (XGI_IsLCDON(pVBInfo)))
1d7f656d
KT
6422 /* LVDS Driver power down */
6423 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
cc1e2398
AK
6424 }
6425
6426 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6427 & (DisableCRT2Display | SetCRT2ToLCDA
6428 | SetSimuScanMode))) {
6429 if (pVBInfo->SetFlag & GatingCRT)
6430 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
6431 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6432 }
6433
6434 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6435 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6436 & SetCRT2ToLCDA))
1d7f656d
KT
6437 /* Power down */
6438 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
cc1e2398
AK
6439 }
6440
1d7f656d
KT
6441 /* disable TV as primary VGA swap */
6442 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
cc1e2398
AK
6443
6444 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
dc50556b 6445 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
cc1e2398 6446
1d7f656d
KT
6447 if ((pVBInfo->SetFlag & DisableChB) ||
6448 (pVBInfo->VBInfo &
6449 (DisableCRT2Display | SetSimuScanMode)) ||
6450 ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) &&
6451 (pVBInfo->VBInfo &
6452 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
6453 /* BScreenOff=1 */
6454 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
6455
6456 if ((pVBInfo->SetFlag & DisableChB) ||
6457 (pVBInfo->VBInfo &
6458 (DisableCRT2Display | SetSimuScanMode)) ||
6459 (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) ||
6460 (pVBInfo->VBInfo &
6461 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
6462 /* save Part1 index 0 */
6463 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
6464 /* BTDAC = 1, avoid VB reset */
6465 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
6466 /* disable CRT2 */
6467 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6468 /* restore Part1 index 0 */
6469 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
cc1e2398
AK
6470 }
6471 } else { /* {301} */
6472 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
1d7f656d
KT
6473 /* BScreenOff=1 */
6474 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
6475 /* Disable CRT2 */
6476 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6477 /* Disable TV asPrimary VGA swap */
6478 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
cc1e2398
AK
6479 }
6480
6481 if (pVBInfo->VBInfo & (DisableCRT2Display | SetCRT2ToLCDA
6482 | SetSimuScanMode))
6483 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6484 }
cc1e2398
AK
6485}
6486
6487/* --------------------------------------------------------------------- */
6488/* Function : XGI_GetTVPtrIndex */
6489/* Input : */
6490/* Output : */
6491/* Description : bx 0 : ExtNTSC */
6492/* 1 : StNTSC */
6493/* 2 : ExtPAL */
6494/* 3 : StPAL */
6495/* 4 : ExtHiTV */
6496/* 5 : StHiTV */
6497/* 6 : Ext525i */
6498/* 7 : St525i */
6499/* 8 : Ext525p */
6500/* 9 : St525p */
6501/* A : Ext750p */
6502/* B : St750p */
6503/* --------------------------------------------------------------------- */
6504static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
6505{
6506 unsigned short tempbx = 0;
6507
6508 if (pVBInfo->TVInfo & SetPALTV)
6509 tempbx = 2;
6510 if (pVBInfo->TVInfo & SetYPbPrMode1080i)
6511 tempbx = 4;
6512 if (pVBInfo->TVInfo & SetYPbPrMode525i)
6513 tempbx = 6;
6514 if (pVBInfo->TVInfo & SetYPbPrMode525p)
6515 tempbx = 8;
6516 if (pVBInfo->TVInfo & SetYPbPrMode750p)
6517 tempbx = 10;
6518 if (pVBInfo->TVInfo & TVSimuMode)
6519 tempbx++;
6520
6521 return tempbx;
6522}
6523
6524/* --------------------------------------------------------------------- */
6525/* Function : XGI_GetTVPtrIndex2 */
6526/* Input : */
6527/* Output : bx 0 : NTSC */
6528/* 1 : PAL */
6529/* 2 : PALM */
6530/* 3 : PALN */
6531/* 4 : NTSC1024x768 */
6532/* 5 : PAL-M 1024x768 */
6533/* 6-7: reserved */
6534/* cl 0 : YFilter1 */
6535/* 1 : YFilter2 */
6536/* ch 0 : 301A */
6537/* 1 : 301B/302B/301LV/302LV */
6538/* Description : */
6539/* --------------------------------------------------------------------- */
6540static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
6541 unsigned char *tempch, struct vb_device_info *pVBInfo)
6542{
6543 *tempbx = 0;
6544 *tempcl = 0;
6545 *tempch = 0;
6546
6547 if (pVBInfo->TVInfo & SetPALTV)
6548 *tempbx = 1;
6549
6550 if (pVBInfo->TVInfo & SetPALMTV)
6551 *tempbx = 2;
6552
6553 if (pVBInfo->TVInfo & SetPALNTV)
6554 *tempbx = 3;
6555
6556 if (pVBInfo->TVInfo & NTSC1024x768) {
6557 *tempbx = 4;
6558 if (pVBInfo->TVInfo & SetPALMTV)
6559 *tempbx = 5;
6560 }
6561
6562 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6563 | VB_XGI302LV | VB_XGI301C)) {
6564 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
6565 & TVSimuMode)) {
6566 *tempbx += 8;
6567 *tempcl += 1;
6568 }
6569 }
6570
6571 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6572 | VB_XGI302LV | VB_XGI301C))
6573 (*tempch)++;
d7636e0b 6574}
6575
cc1e2398 6576static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
d7636e0b 6577{
cc1e2398 6578 unsigned short index;
d7636e0b 6579
cc1e2398 6580 unsigned char tempah, tempbl, tempbh;
d7636e0b 6581
cc1e2398
AK
6582 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6583 | VB_XGI302LV | VB_XGI301C)) {
6584 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA
6585 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
6586 tempbl = 0;
6587 tempbh = 0;
d7636e0b 6588
cc1e2398
AK
6589 index = XGI_GetTVPtrIndex(pVBInfo); /* Get TV Delay */
6590 tempbl = pVBInfo->XGI_TVDelayList[index];
d7636e0b 6591
cc1e2398
AK
6592 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
6593 | VB_XGI301LV | VB_XGI302LV
6594 | VB_XGI301C))
6595 tempbl = pVBInfo->XGI_TVDelayList2[index];
d7636e0b 6596
cc1e2398
AK
6597 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6598 tempbl = tempbl >> 4;
6599 /*
6600 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
6601 tempbl = CRT2Delay1; // Get CRT2 Delay
1d7f656d
KT
6602 if (pVBInfo->VBType &
6603 (VB_XGI301B |
6604 VB_XGI302B |
6605 VB_XGI301LV |
6606 VB_XGI302LV |
6607 VB_XGI301C))
cc1e2398
AK
6608 tempbl = CRT2Delay2;
6609 */
6610 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
1d7f656d
KT
6611 /* Get LCD Delay */
6612 index = XGI_GetLCDCapPtr(pVBInfo);
6613 tempbh = pVBInfo->LCDCapList[index].
6614 LCD_DelayCompensation;
d7636e0b 6615
cc1e2398
AK
6616 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
6617 tempbl = tempbh;
6618 }
d7636e0b 6619
cc1e2398
AK
6620 tempbl &= 0x0F;
6621 tempbh &= 0xF0;
58839b01 6622 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
d7636e0b 6623
cc1e2398
AK
6624 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
6625 | SetCRT2ToTV)) { /* Channel B */
6626 tempah &= 0xF0;
6627 tempah |= tempbl;
6628 }
d7636e0b 6629
cc1e2398
AK
6630 if (pVBInfo->VBInfo & SetCRT2ToLCDA) { /* Channel A */
6631 tempah &= 0x0F;
6632 tempah |= tempbh;
6633 }
8104e329 6634 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
cc1e2398
AK
6635 }
6636 } else if (pVBInfo->IF_DEF_LVDS == 1) {
6637 tempbl = 0;
6638 tempbh = 0;
6639 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
1d7f656d
KT
6640 /* / Get LCD Delay */
6641 tempah = pVBInfo->LCDCapList[
6642 XGI_GetLCDCapPtr(pVBInfo)].
6643 LCD_DelayCompensation;
cc1e2398
AK
6644 tempah &= 0x0f;
6645 tempah = tempah << 4;
ec9e5d3e 6646 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
cc1e2398 6647 tempah);
21df8fc8 6648 }
cc1e2398
AK
6649 }
6650}
d7636e0b 6651
1d7f656d
KT
6652static void XGI_SetLCDCap_A(unsigned short tempcx,
6653 struct vb_device_info *pVBInfo)
cc1e2398
AK
6654{
6655 unsigned short temp;
d7636e0b 6656
58839b01 6657 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
cc1e2398
AK
6658
6659 if (temp & LCDRGB18Bit) {
ec9e5d3e 6660 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
1d7f656d
KT
6661 /* Enable Dither */
6662 (unsigned short) (0x20 | (tempcx & 0x00C0)));
ec9e5d3e 6663 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
cc1e2398 6664 } else {
ec9e5d3e 6665 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
cc1e2398 6666 (unsigned short) (0x30 | (tempcx & 0x00C0)));
ec9e5d3e 6667 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
21df8fc8 6668 }
d7636e0b 6669
cc1e2398
AK
6670 /*
6671 if (tempcx & EnableLCD24bpp) { // 24bits
1d7f656d
KT
6672 xgifb_reg_and_or(pVBInfo->Part1Port,
6673 0x19,
6674 0x0F,
6675 (unsigned short)(0x30 | (tempcx&0x00C0)));
ec9e5d3e 6676 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
cc1e2398 6677 } else {
1d7f656d
KT
6678 xgifb_reg_and_or(pVBInfo->Part1Port,
6679 0x19,
6680 0x0F,
6681 // Enable Dither
6682 (unsigned short)(0x20 | (tempcx&0x00C0)));
ec9e5d3e 6683 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
21df8fc8 6684 }
cc1e2398
AK
6685 */
6686}
d7636e0b 6687
cc1e2398
AK
6688/* --------------------------------------------------------------------- */
6689/* Function : XGI_SetLCDCap_B */
6690/* Input : cx -> LCD Capability */
6691/* Output : */
6692/* Description : */
6693/* --------------------------------------------------------------------- */
1d7f656d
KT
6694static void XGI_SetLCDCap_B(unsigned short tempcx,
6695 struct vb_device_info *pVBInfo)
cc1e2398
AK
6696{
6697 if (tempcx & EnableLCD24bpp) /* 24bits */
ec9e5d3e 6698 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
cc1e2398
AK
6699 (unsigned short) (((tempcx & 0x00ff) >> 6)
6700 | 0x0c));
6701 else
ec9e5d3e 6702 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
cc1e2398
AK
6703 (unsigned short) (((tempcx & 0x00ff) >> 6)
6704 | 0x18)); /* Enable Dither */
d7636e0b 6705}
6706
7f04ec30
AK
6707static void XGI_LongWait(struct vb_device_info *pVBInfo)
6708{
6709 unsigned short i;
6710
6711 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
6712
6713 if (!(i & 0xC0)) {
6714 for (i = 0; i < 0xFFFF; i++) {
6715 if (!(inb(pVBInfo->P3da) & 0x08))
6716 break;
6717 }
6718
6719 for (i = 0; i < 0xFFFF; i++) {
6720 if ((inb(pVBInfo->P3da) & 0x08))
6721 break;
6722 }
6723 }
6724}
6725
cc1e2398 6726static void SetSpectrum(struct vb_device_info *pVBInfo)
d7636e0b 6727{
cc1e2398 6728 unsigned short index;
d7636e0b 6729
cc1e2398 6730 index = XGI_GetLCDCapPtr(pVBInfo);
d7636e0b 6731
1d7f656d
KT
6732 /* disable down spectrum D[4] */
6733 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
cc1e2398 6734 XGI_LongWait(pVBInfo);
b9bf6e4e 6735 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
cc1e2398
AK
6736 XGI_LongWait(pVBInfo);
6737
8104e329 6738 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
cc1e2398 6739 pVBInfo->LCDCapList[index].Spectrum_31);
8104e329 6740 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
cc1e2398 6741 pVBInfo->LCDCapList[index].Spectrum_32);
8104e329 6742 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
cc1e2398 6743 pVBInfo->LCDCapList[index].Spectrum_33);
8104e329 6744 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
cc1e2398
AK
6745 pVBInfo->LCDCapList[index].Spectrum_34);
6746 XGI_LongWait(pVBInfo);
b9bf6e4e 6747 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
d7636e0b 6748}
6749
cc1e2398 6750static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
21df8fc8 6751{
cc1e2398 6752 unsigned short tempcx;
21df8fc8 6753
cc1e2398 6754 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
21df8fc8 6755
1d7f656d
KT
6756 if (pVBInfo->VBType &
6757 (VB_XGI301B |
6758 VB_XGI302B |
6759 VB_XGI301LV |
6760 VB_XGI302LV |
6761 VB_XGI301C)) { /* 301LV/302LV only */
6762 if (pVBInfo->VBType &
6763 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
cc1e2398 6764 /* Set 301LV Capability */
8104e329 6765 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
cc1e2398 6766 (unsigned char) (tempcx & 0x1F));
21df8fc8 6767 }
cc1e2398 6768 /* VB Driving */
ec9e5d3e 6769 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
cc1e2398
AK
6770 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
6771 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
6772 | EnablePLLSPLOW)) >> 8));
6773 }
21df8fc8 6774
cc1e2398
AK
6775 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6776 | VB_XGI302LV | VB_XGI301C)) {
6777 if (pVBInfo->VBInfo & SetCRT2ToLCD)
6778 XGI_SetLCDCap_B(tempcx, pVBInfo);
6779 else if (pVBInfo->VBInfo & SetCRT2ToLCDA)
6780 XGI_SetLCDCap_A(tempcx, pVBInfo);
21df8fc8 6781
cc1e2398
AK
6782 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6783 if (tempcx & EnableSpectrum)
6784 SetSpectrum(pVBInfo);
6785 }
6786 } else {
6787 /* LVDS,CH7017 */
6788 XGI_SetLCDCap_A(tempcx, pVBInfo);
6789 }
6790}
21df8fc8 6791
cc1e2398
AK
6792/* --------------------------------------------------------------------- */
6793/* Function : XGI_SetAntiFlicker */
6794/* Input : */
6795/* Output : */
6796/* Description : Set TV Customized Param. */
6797/* --------------------------------------------------------------------- */
1d7f656d
KT
6798static void XGI_SetAntiFlicker(unsigned short ModeNo,
6799 unsigned short ModeIdIndex,
6800 struct vb_device_info *pVBInfo)
cc1e2398
AK
6801{
6802 unsigned short tempbx, index;
21df8fc8 6803
cc1e2398 6804 unsigned char tempah;
21df8fc8 6805
cc1e2398
AK
6806 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
6807 return;
21df8fc8 6808
cc1e2398
AK
6809 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6810 tempbx &= 0xFE;
21df8fc8 6811
cc1e2398
AK
6812 if (ModeNo <= 0x13)
6813 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
6814 else
6815 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
21df8fc8 6816
cc1e2398
AK
6817 tempbx += index;
6818 tempah = TVAntiFlickList[tempbx];
6819 tempah = tempah << 4;
21df8fc8 6820
ec9e5d3e 6821 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
cc1e2398 6822}
21df8fc8 6823
1d7f656d
KT
6824static void XGI_SetEdgeEnhance(unsigned short ModeNo,
6825 unsigned short ModeIdIndex,
6826 struct vb_device_info *pVBInfo)
cc1e2398
AK
6827{
6828 unsigned short tempbx, index;
21df8fc8 6829
cc1e2398 6830 unsigned char tempah;
21df8fc8 6831
cc1e2398
AK
6832 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6833 tempbx &= 0xFE;
21df8fc8 6834
cc1e2398
AK
6835 if (ModeNo <= 0x13)
6836 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
6837 else
6838 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
21df8fc8 6839
cc1e2398
AK
6840 tempbx += index;
6841 tempah = TVEdgeList[tempbx];
6842 tempah = tempah << 5;
21df8fc8 6843
ec9e5d3e 6844 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
d7636e0b 6845}
6846
cc1e2398 6847static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
21df8fc8 6848{
cc1e2398 6849 unsigned short tempbx;
21df8fc8 6850
cc1e2398 6851 unsigned char tempcl, tempch;
21df8fc8 6852
cc1e2398 6853 unsigned long tempData;
d7636e0b 6854
cc1e2398
AK
6855 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
6856 tempData = TVPhaseList[tempbx];
21df8fc8 6857
8104e329 6858 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
cc1e2398 6859 & 0x000000FF));
8104e329 6860 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
cc1e2398 6861 & 0x0000FF00) >> 8));
8104e329 6862 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
cc1e2398 6863 & 0x00FF0000) >> 16));
8104e329 6864 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
cc1e2398
AK
6865 & 0xFF000000) >> 24));
6866}
21df8fc8 6867
cc1e2398
AK
6868static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
6869 struct vb_device_info *pVBInfo)
6870{
6871 unsigned short tempbx, index;
21df8fc8 6872
cc1e2398 6873 unsigned char tempcl, tempch, tempal, *filterPtr;
21df8fc8 6874
cc1e2398 6875 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
21df8fc8 6876
cc1e2398
AK
6877 switch (tempbx) {
6878 case 0x00:
6879 case 0x04:
6880 filterPtr = NTSCYFilter1;
6881 break;
21df8fc8 6882
cc1e2398
AK
6883 case 0x01:
6884 filterPtr = PALYFilter1;
6885 break;
21df8fc8 6886
cc1e2398
AK
6887 case 0x02:
6888 case 0x05:
6889 case 0x0D:
cc1e2398 6890 case 0x03:
2555e945 6891 filterPtr = xgifb_palmn_yfilter1;
cc1e2398 6892 break;
21df8fc8 6893
cc1e2398
AK
6894 case 0x08:
6895 case 0x0C:
cc1e2398 6896 case 0x0A:
cc1e2398 6897 case 0x0B:
cc1e2398 6898 case 0x09:
80f86f8f 6899 filterPtr = xgifb_yfilter2;
cc1e2398 6900 break;
21df8fc8 6901
cc1e2398
AK
6902 default:
6903 return;
21df8fc8 6904 }
d7636e0b 6905
cc1e2398 6906 if (ModeNo <= 0x13)
1d7f656d
KT
6907 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
6908 VB_StTVYFilterIndex;
cc1e2398 6909 else
1d7f656d
KT
6910 tempal = pVBInfo->EModeIDTable[ModeIdIndex].
6911 VB_ExtTVYFilterIndex;
d7636e0b 6912
cc1e2398
AK
6913 if (tempcl == 0)
6914 index = tempal * 4;
6915 else
6916 index = tempal * 7;
d7636e0b 6917
cc1e2398 6918 if ((tempcl == 0) && (tempch == 1)) {
8104e329
AK
6919 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
6920 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
6921 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
6922 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
cc1e2398 6923 } else {
8104e329
AK
6924 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
6925 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
6926 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
6927 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
cc1e2398 6928 }
d7636e0b 6929
cc1e2398
AK
6930 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6931 | VB_XGI302LV | VB_XGI301C)) {
8104e329
AK
6932 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
6933 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
6934 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
cc1e2398 6935 }
d7636e0b 6936}
6937
d7636e0b 6938/* --------------------------------------------------------------------- */
6939/* Function : XGI_OEM310Setting */
6940/* Input : */
6941/* Output : */
6942/* Description : Customized Param. for 301 */
6943/* --------------------------------------------------------------------- */
1d7f656d
KT
6944static void XGI_OEM310Setting(unsigned short ModeNo,
6945 unsigned short ModeIdIndex,
6946 struct vb_device_info *pVBInfo)
d7636e0b 6947{
21df8fc8
PS
6948 /* GetPart1IO(); */
6949 XGI_SetDelayComp(pVBInfo);
d7636e0b 6950
21df8fc8
PS
6951 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
6952 XGI_SetLCDCap(pVBInfo);
d7636e0b 6953
21df8fc8
PS
6954 if (pVBInfo->VBInfo & SetCRT2ToTV) {
6955 /* GetPart2IO() */
6956 XGI_SetPhaseIncr(pVBInfo);
6957 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
6958 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
d7636e0b 6959
21df8fc8
PS
6960 if (pVBInfo->VBType & VB_XGI301)
6961 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
6962 }
d7636e0b 6963}
6964
cc1e2398
AK
6965/* --------------------------------------------------------------------- */
6966/* Function : XGI_SetCRT2ModeRegs */
6967/* Input : */
6968/* Output : */
6969/* Description : Origin code for crt2group */
6970/* --------------------------------------------------------------------- */
fac2cc92 6971static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
cc1e2398
AK
6972 struct xgi_hw_device_info *HwDeviceExtension,
6973 struct vb_device_info *pVBInfo)
d7636e0b 6974{
cc1e2398
AK
6975 unsigned short tempbl;
6976 short tempcl;
21df8fc8 6977
cc1e2398 6978 unsigned char tempah;
21df8fc8 6979
1d7f656d
KT
6980 /* // fix write part1 index 0 BTDRAM bit Bug
6981 * xgifb_reg_set(pVBInfo->Part1Port, 0x03, 0x00); */
cc1e2398
AK
6982 tempah = 0;
6983 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
58839b01 6984 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
cc1e2398
AK
6985 tempah &= ~0x10; /* BTRAMDAC */
6986 tempah |= 0x40; /* BTRAM */
21df8fc8 6987
cc1e2398
AK
6988 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
6989 | SetCRT2ToLCD)) {
6990 tempah = 0x40; /* BTDRAM */
6991 if (ModeNo > 0x13) {
6992 tempcl = pVBInfo->ModeType;
6993 tempcl -= ModeVGA;
6994 if (tempcl >= 0) {
1d7f656d
KT
6995 /* BT Color */
6996 tempah = (0x008 >> tempcl);
cc1e2398
AK
6997 if (tempah == 0)
6998 tempah = 1;
6999 tempah |= 0x040;
7000 }
7001 }
7002 if (pVBInfo->VBInfo & SetInSlaveMode)
7003 tempah ^= 0x50; /* BTDAC */
7004 }
7005 }
21df8fc8 7006
cc1e2398
AK
7007 /* 0210 shampoo
7008 if (pVBInfo->VBInfo & DisableCRT2Display) {
7009 tempah = 0;
7010 }
21df8fc8 7011
8104e329 7012 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
cc1e2398
AK
7013 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)) {
7014 tempcl = pVBInfo->ModeType;
7015 if (ModeNo > 0x13) {
7016 tempcl -= ModeVGA;
7017 if ((tempcl > 0) || (tempcl == 0)) {
7018 tempah=(0x008>>tempcl) ;
7019 if (tempah == 0)
7020 tempah = 1;
7021 tempah |= 0x040;
21df8fc8 7022 }
cc1e2398
AK
7023 } else {
7024 tempah = 0x040;
7025 }
21df8fc8 7026
cc1e2398
AK
7027 if (pVBInfo->VBInfo & SetInSlaveMode) {
7028 tempah = (tempah ^ 0x050);
7029 }
7030 }
7031 */
21df8fc8 7032
8104e329 7033 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
cc1e2398
AK
7034 tempah = 0x08;
7035 tempbl = 0xf0;
7036
7037 if (pVBInfo->VBInfo & DisableCRT2Display) {
ec9e5d3e 7038 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
cc1e2398
AK
7039 } else {
7040 tempah = 0x00;
7041 tempbl = 0xff;
7042
7043 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
7044 | SetCRT2ToLCD | SetCRT2ToLCDA)) {
1d7f656d
KT
7045 if ((pVBInfo->VBInfo & SetCRT2ToLCDA) &&
7046 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
cc1e2398
AK
7047 tempbl &= 0xf7;
7048 tempah |= 0x01;
ec9e5d3e 7049 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e,
cc1e2398
AK
7050 tempbl, tempah);
7051 } else {
7052 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7053 tempbl &= 0xf7;
7054 tempah |= 0x01;
7055 }
7056
1d7f656d
KT
7057 if (pVBInfo->VBInfo &
7058 (SetCRT2ToRAMDAC |
7059 SetCRT2ToTV |
7060 SetCRT2ToLCD)) {
cc1e2398
AK
7061 tempbl &= 0xf8;
7062 tempah = 0x01;
7063
7064 if (!(pVBInfo->VBInfo & SetInSlaveMode))
7065 tempah |= 0x02;
7066
1d7f656d
KT
7067 if (!(pVBInfo->VBInfo &
7068 SetCRT2ToRAMDAC)) {
cc1e2398 7069 tempah = tempah ^ 0x05;
1d7f656d
KT
7070 if (!(pVBInfo->VBInfo &
7071 SetCRT2ToLCD))
cc1e2398
AK
7072 tempah = tempah ^ 0x01;
7073 }
21df8fc8 7074
1d7f656d
KT
7075 if (!(pVBInfo->VBInfo &
7076 SetCRT2ToDualEdge))
cc1e2398 7077 tempah |= 0x08;
ec9e5d3e 7078 xgifb_reg_and_or(pVBInfo->Part1Port,
cc1e2398
AK
7079 0x2e, tempbl, tempah);
7080 } else {
ec9e5d3e 7081 xgifb_reg_and_or(pVBInfo->Part1Port,
cc1e2398
AK
7082 0x2e, tempbl, tempah);
7083 }
21df8fc8 7084 }
cc1e2398 7085 } else {
ec9e5d3e 7086 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl,
21df8fc8
PS
7087 tempah);
7088 }
7089 }
d7636e0b 7090
cc1e2398
AK
7091 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
7092 | SetCRT2ToLCDA)) {
7093 tempah &= (~0x08);
7094 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
7095 & SetInSlaveMode))) {
7096 tempah |= 0x010;
7097 }
7098 tempah |= 0x080;
21df8fc8 7099
cc1e2398 7100 if (pVBInfo->VBInfo & SetCRT2ToTV) {
1d7f656d
KT
7101 /* if (!(pVBInfo->TVInfo &
7102 (SetYPbPrMode525p | SetYPbPrMode750p))) { */
cc1e2398
AK
7103 tempah |= 0x020;
7104 if (ModeNo > 0x13) {
7105 if (pVBInfo->VBInfo & DriverMode)
7106 tempah = tempah ^ 0x20;
7107 }
7108 /* } */
7109 }
21df8fc8 7110
ec9e5d3e 7111 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
cc1e2398
AK
7112 tempah = 0;
7113
7114 if (pVBInfo->LCDInfo & SetLCDDualLink)
7115 tempah |= 0x40;
7116
7117 if (pVBInfo->VBInfo & SetCRT2ToTV) {
1d7f656d
KT
7118 /* if ((!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) &&
7119 (!(pVBInfo->TVInfo &
7120 (SetYPbPrMode525p | SetYPbPrMode750p)))) { */
cc1e2398
AK
7121 if (pVBInfo->TVInfo & RPLLDIV2XO)
7122 tempah |= 0x40;
7123 /* } */
21df8fc8 7124 }
cc1e2398
AK
7125
7126 if ((pVBInfo->LCDResInfo == Panel1280x1024)
7127 || (pVBInfo->LCDResInfo == Panel1280x1024x75))
7128 tempah |= 0x80;
7129
7130 if (pVBInfo->LCDResInfo == Panel1280x960)
7131 tempah |= 0x80;
7132
8104e329 7133 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
d7636e0b 7134 }
d7636e0b 7135
21df8fc8
PS
7136 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7137 | VB_XGI302LV | VB_XGI301C)) {
cc1e2398
AK
7138 tempah = 0;
7139 tempbl = 0xfb;
21df8fc8 7140
cc1e2398
AK
7141 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7142 tempbl = 0xff;
7143 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7144 tempah |= 0x04; /* shampoo 0129 */
21df8fc8 7145 }
d7636e0b 7146
ec9e5d3e 7147 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
cc1e2398
AK
7148 tempah = 0x00;
7149 tempbl = 0xcf;
7150 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7151 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7152 tempah |= 0x30;
7153 }
d7636e0b 7154
ec9e5d3e 7155 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
cc1e2398
AK
7156 tempah = 0;
7157 tempbl = 0x3f;
d7636e0b 7158
cc1e2398
AK
7159 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7160 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7161 tempah |= 0xc0;
7162 }
ec9e5d3e 7163 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
21df8fc8 7164 }
d7636e0b 7165
cc1e2398
AK
7166 tempah = 0;
7167 tempbl = 0x7f;
7168 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) {
7169 tempbl = 0xff;
7170 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
7171 tempah |= 0x80;
21df8fc8 7172 }
d7636e0b 7173
ec9e5d3e 7174 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
d7636e0b 7175
cc1e2398
AK
7176 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7177 if (pVBInfo->LCDInfo & SetLCDDualLink) {
b9bf6e4e
AK
7178 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
7179 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
cc1e2398
AK
7180 }
7181 }
d7636e0b 7182}
7183
cc1e2398 7184static void XGI_CloseCRTC(struct xgi_hw_device_info *HwDeviceExtension,
21df8fc8 7185 struct vb_device_info *pVBInfo)
d7636e0b 7186{
cc1e2398 7187 unsigned short tempbx;
d7636e0b 7188
cc1e2398 7189 tempbx = 0;
d7636e0b 7190
cc1e2398
AK
7191 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7192 tempbx = 0x08A0;
d7636e0b 7193
d7636e0b 7194}
7195
cc1e2398
AK
7196void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
7197 struct vb_device_info *pVBInfo)
d7636e0b 7198{
d7636e0b 7199
ec9e5d3e 7200 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
cc1e2398 7201
d7636e0b 7202}
7203
cc1e2398 7204void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
21df8fc8
PS
7205 struct vb_device_info *pVBInfo)
7206{
21df8fc8 7207
ec9e5d3e 7208 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
21df8fc8 7209
cc1e2398 7210}
21df8fc8 7211
cc1e2398
AK
7212unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
7213{
7214 unsigned short flag;
21df8fc8 7215
cc1e2398
AK
7216 if (pVBInfo->IF_DEF_LVDS == 1) {
7217 return 1;
7218 } else {
58839b01 7219 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
cc1e2398
AK
7220 if ((flag == 1) || (flag == 2))
7221 return 1; /* 301b */
7222 else
7223 return 0;
7224 }
7225}
21df8fc8 7226
cc1e2398
AK
7227static void XGI_VBLongWait(struct vb_device_info *pVBInfo)
7228{
7229 unsigned short tempal, temp, i, j;
7230 return;
7231 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
7232 temp = 0;
7233 for (i = 0; i < 3; i++) {
7234 for (j = 0; j < 100; j++) {
d8ad0a6d 7235 tempal = inb(pVBInfo->P3da);
cc1e2398
AK
7236 if (temp & 0x01) { /* VBWaitMode2 */
7237 if ((tempal & 0x08))
7238 continue;
21df8fc8 7239
cc1e2398
AK
7240 if (!(tempal & 0x08))
7241 break;
d7636e0b 7242
cc1e2398
AK
7243 } else { /* VBWaitMode1 */
7244 if (!(tempal & 0x08))
7245 continue;
7246
7247 if ((tempal & 0x08))
7248 break;
7249 }
7250 }
7251 temp = temp ^ 0x01;
7252 }
7253 } else {
7254 XGI_LongWait(pVBInfo);
21df8fc8 7255 }
cc1e2398
AK
7256 return;
7257}
21df8fc8 7258
cc1e2398
AK
7259unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
7260 unsigned short ModeNo, unsigned short ModeIdIndex,
7261 struct vb_device_info *pVBInfo)
7262{
7263 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
7264 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
7265 0x01, 0x01 };
21df8fc8 7266
cc1e2398
AK
7267 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
7268
7269 if (ModeNo <= 0x13)
7270 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
21df8fc8 7271 else
cc1e2398 7272 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
21df8fc8 7273
cc1e2398
AK
7274 if (ModeNo < 0x14)
7275 return 0xFFFF;
d7636e0b 7276
58839b01 7277 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
cc1e2398
AK
7278 index = index >> pVBInfo->SelectCRT2Rate;
7279 index &= 0x0F;
d7636e0b 7280
cc1e2398
AK
7281 if (pVBInfo->LCDInfo & LCDNonExpanding)
7282 index = 0;
d7636e0b 7283
cc1e2398
AK
7284 if (index > 0)
7285 index--;
d7636e0b 7286
cc1e2398 7287 if (pVBInfo->SetFlag & ProgrammingCRT2) {
cc1e2398
AK
7288 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
7289 if (pVBInfo->IF_DEF_LVDS == 0) {
7290 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
7291 | VB_XGI301LV | VB_XGI302LV
7292 | VB_XGI301C))
1d7f656d
KT
7293 /* 301b */
7294 temp = LCDARefreshIndex[
7295 pVBInfo->LCDResInfo & 0x0F];
cc1e2398 7296 else
1d7f656d
KT
7297 temp = LCDRefreshIndex[
7298 pVBInfo->LCDResInfo & 0x0F];
cc1e2398
AK
7299
7300 if (index > temp)
7301 index = temp;
7302 } else {
7303 index = 0;
7304 }
7305 }
21df8fc8 7306 }
d7636e0b 7307
cc1e2398
AK
7308 RefreshRateTableIndex = pVBInfo->EModeIDTable[ModeIdIndex].REFindex;
7309 ModeNo = pVBInfo->RefIndex[RefreshRateTableIndex].ModeID;
7310 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
7311 /*
1d7f656d
KT
7312 if (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag &
7313 XG2xNotSupport) {
cc1e2398
AK
7314 index++;
7315 }
7316 */
1d7f656d
KT
7317 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 800) &&
7318 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 600)) {
cc1e2398
AK
7319 index++;
7320 }
1d7f656d
KT
7321 /* Alan 10/19/2007;
7322 * do the similar adjustment like XGISearchCRT1Rate() */
7323 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1024) &&
7324 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 768)) {
cc1e2398
AK
7325 index++;
7326 }
1d7f656d
KT
7327 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1280) &&
7328 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 1024)) {
cc1e2398
AK
7329 index++;
7330 }
7331 }
7332
7333 i = 0;
7334 do {
1d7f656d
KT
7335 if (pVBInfo->RefIndex[RefreshRateTableIndex + i].
7336 ModeID != ModeNo)
cc1e2398 7337 break;
1d7f656d
KT
7338 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i].
7339 Ext_InfoFlag;
cc1e2398
AK
7340 temp &= ModeInfoFlag;
7341 if (temp < pVBInfo->ModeType)
7342 break;
7343 i++;
7344 index--;
7345
7346 } while (index != 0xFFFF);
7347 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
7348 if (pVBInfo->VBInfo & SetInSlaveMode) {
1d7f656d
KT
7349 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i - 1].
7350 Ext_InfoFlag;
cc1e2398
AK
7351 if (temp & InterlaceMode)
7352 i++;
21df8fc8
PS
7353 }
7354 }
cc1e2398
AK
7355 i--;
7356 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
7357 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
7358 RefreshRateTableIndex, &i, pVBInfo);
7359 }
7360 return RefreshRateTableIndex + i; /* return (0x01 | (temp1<<1)); */
7361}
d7636e0b 7362
cc1e2398
AK
7363static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
7364 struct xgi_hw_device_info *HwDeviceExtension,
7365 struct vb_device_info *pVBInfo)
7366{
7367 unsigned short RefreshRateTableIndex;
7368 /* unsigned short temp ; */
7369
7370 /* pVBInfo->SelectCRT2Rate = 0; */
7371
7372 pVBInfo->SetFlag |= ProgrammingCRT2;
7373 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7374 ModeIdIndex, pVBInfo);
7375 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
7376 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7377 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7378 HwDeviceExtension, pVBInfo);
7379 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7380 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
d7636e0b 7381}
7382
fac2cc92 7383static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
21df8fc8
PS
7384 struct xgi_hw_device_info *HwDeviceExtension,
7385 struct vb_device_info *pVBInfo)
7386{
cc1e2398 7387 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
21df8fc8 7388
cc1e2398
AK
7389 tempbx = pVBInfo->VBInfo;
7390 pVBInfo->SetFlag |= ProgrammingCRT2;
7391 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7392 pVBInfo->SelectCRT2Rate = 4;
7393 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7394 ModeIdIndex, pVBInfo);
7395 XGI_SaveCRT2Info(ModeNo, pVBInfo);
7396 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
7397 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7398 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7399 RefreshRateTableIndex, pVBInfo);
7400 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7401 RefreshRateTableIndex, pVBInfo);
7402 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7403 RefreshRateTableIndex, pVBInfo);
7404 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7405 HwDeviceExtension, pVBInfo);
7406 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7407 RefreshRateTableIndex, pVBInfo);
7408 XGI_SetTap4Regs(pVBInfo);
7409 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
7410 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7411 HwDeviceExtension, pVBInfo);
7412 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7413 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
7414 XGI_AutoThreshold(pVBInfo);
7415 return 1;
7416}
21df8fc8 7417
cc1e2398
AK
7418void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
7419{
7420 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
7421 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
7422 0x05, 0x00 };
21df8fc8 7423
cc1e2398 7424 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
d7636e0b 7425
cc1e2398
AK
7426 unsigned char CR17, CR63, SR31;
7427 unsigned short temp;
7428 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
d7636e0b 7429
cc1e2398 7430 int i;
8104e329 7431 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
21df8fc8 7432
cc1e2398 7433 /* [2004/05/06] Vicent to fix XG42 single LCD sense to CRT+LCD */
8104e329 7434 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
58839b01 7435 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
cc1e2398 7436 pVBInfo->P3d4, 0x53) | 0x02));
21df8fc8 7437
58839b01
AK
7438 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
7439 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
7440 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
21df8fc8 7441
8104e329
AK
7442 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
7443 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
21df8fc8 7444
58839b01 7445 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
8104e329 7446 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
21df8fc8 7447
58839b01 7448 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
8104e329 7449 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
21df8fc8 7450
58839b01 7451 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
8104e329 7452 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
58839b01 7453 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
8104e329 7454 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
21df8fc8 7455
8104e329 7456 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
21df8fc8 7457
cc1e2398 7458 for (i = 0; i < 8; i++)
8104e329 7459 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
d7636e0b 7460
cc1e2398 7461 for (i = 8; i < 11; i++)
8104e329 7462 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
cc1e2398 7463 CRTCData[i]);
21df8fc8 7464
cc1e2398 7465 for (i = 11; i < 13; i++)
8104e329 7466 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
cc1e2398 7467 CRTCData[i]);
21df8fc8 7468
cc1e2398 7469 for (i = 13; i < 16; i++)
8104e329 7470 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
cc1e2398 7471 CRTCData[i]);
21df8fc8 7472
8104e329 7473 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
cc1e2398 7474 & 0xE0));
21df8fc8 7475
8104e329
AK
7476 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
7477 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7478 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
21df8fc8 7479
efdf4ee7 7480 outb(0x00, pVBInfo->P3c8);
cc1e2398
AK
7481
7482 for (i = 0; i < 256; i++) {
efdf4ee7
AK
7483 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
7484 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
7485 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
cc1e2398
AK
7486 }
7487
7488 XGI_VBLongWait(pVBInfo);
7489 XGI_VBLongWait(pVBInfo);
7490 XGI_VBLongWait(pVBInfo);
7491
7492 mdelay(1);
7493
7494 XGI_WaitDisply(pVBInfo);
d8ad0a6d 7495 temp = inb(pVBInfo->P3c2);
cc1e2398
AK
7496
7497 if (temp & 0x10)
ec9e5d3e 7498 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
cc1e2398 7499 else
ec9e5d3e 7500 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
21df8fc8 7501
cc1e2398 7502 /* alan, avoid display something, set BLACK DAC if not restore DAC */
efdf4ee7 7503 outb(0x00, pVBInfo->P3c8);
21df8fc8 7504
cc1e2398 7505 for (i = 0; i < 256; i++) {
efdf4ee7
AK
7506 outb(0, (pVBInfo->P3c8 + 1));
7507 outb(0, (pVBInfo->P3c8 + 1));
7508 outb(0, (pVBInfo->P3c8 + 1));
21df8fc8 7509 }
d7636e0b 7510
8104e329
AK
7511 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
7512 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
7513 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
21df8fc8 7514
cc1e2398 7515 /* [2004/05/11] Vicent */
58839b01 7516 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
cc1e2398 7517 pVBInfo->P3d4, 0x53) & 0xFD));
8104e329 7518 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
cc1e2398 7519}
21df8fc8 7520
fac2cc92 7521static void XGI_EnableBridge(struct xgi_hw_device_info *HwDeviceExtension,
cc1e2398
AK
7522 struct vb_device_info *pVBInfo)
7523{
fd0ad470 7524 unsigned short tempah;
21df8fc8 7525
cc1e2398
AK
7526 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7527 | VB_XGI302LV | VB_XGI301C)) {
7528 if (!(pVBInfo->SetFlag & DisableChA)) {
7529 if (pVBInfo->SetFlag & EnableChA) {
1d7f656d
KT
7530 /* Power on */
7531 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
cc1e2398 7532 } else {
1d7f656d
KT
7533 /* SetCRT2ToLCDA ) */
7534 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7535 /* Power on */
8104e329 7536 xgifb_reg_set(pVBInfo->Part1Port,
1d7f656d 7537 0x1E, 0x20);
cc1e2398
AK
7538 }
7539 }
21df8fc8 7540 }
d7636e0b 7541
cc1e2398
AK
7542 if (!(pVBInfo->SetFlag & DisableChB)) {
7543 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
7544 & (SetCRT2ToLCD | SetCRT2ToTV
7545 | SetCRT2ToRAMDAC))) {
58839b01 7546 tempah = (unsigned char) xgifb_reg_get(
cc1e2398
AK
7547 pVBInfo->P3c4, 0x32);
7548 tempah &= 0xDF;
7549 if (pVBInfo->VBInfo & SetInSlaveMode) {
1d7f656d
KT
7550 if (!(pVBInfo->VBInfo &
7551 SetCRT2ToRAMDAC))
cc1e2398
AK
7552 tempah |= 0x20;
7553 }
8104e329 7554 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
b9bf6e4e 7555 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
d7636e0b 7556
58839b01 7557 tempah = (unsigned char) xgifb_reg_get(
cc1e2398 7558 pVBInfo->Part1Port, 0x2E);
d7636e0b 7559
cc1e2398 7560 if (!(tempah & 0x80))
1d7f656d 7561 /* BVBDOENABLE = 1 */
b9bf6e4e 7562 xgifb_reg_or(pVBInfo->Part1Port,
1d7f656d
KT
7563 0x2E, 0x80);
7564 /* BScreenOFF = 0 */
7565 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
cc1e2398
AK
7566 }
7567 }
d7636e0b 7568
cc1e2398
AK
7569 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
7570 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
ec9e5d3e 7571 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
cc1e2398
AK
7572 0x20); /* shampoo 0129 */
7573 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7574 if (!XGI_DisableChISLCD(pVBInfo)) {
1d7f656d
KT
7575 if (XGI_EnableChISLCD(pVBInfo) ||
7576 (pVBInfo->VBInfo &
7577 (SetCRT2ToLCD | SetCRT2ToLCDA)))
7578 /* LVDS PLL power on */
dc50556b 7579 xgifb_reg_and(
1d7f656d
KT
7580 pVBInfo->Part4Port,
7581 0x2A,
7582 0x7F);
cc1e2398 7583 }
1d7f656d
KT
7584 /* LVDS Driver power on */
7585 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
cc1e2398
AK
7586 }
7587 }
d7636e0b 7588
cc1e2398 7589 tempah = 0x00;
d7636e0b 7590
cc1e2398
AK
7591 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7592 tempah = 0xc0;
d7636e0b 7593
cc1e2398
AK
7594 if (!(pVBInfo->VBInfo & SetSimuScanMode)) {
7595 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
1d7f656d
KT
7596 if (pVBInfo->VBInfo &
7597 SetCRT2ToDualEdge) {
cc1e2398 7598 tempah = tempah & 0x40;
1d7f656d
KT
7599 if (pVBInfo->VBInfo &
7600 SetCRT2ToLCDA)
cc1e2398 7601 tempah = tempah ^ 0xC0;
d7636e0b 7602
1d7f656d
KT
7603 if (pVBInfo->SetFlag &
7604 DisableChB)
cc1e2398 7605 tempah &= 0xBF;
d7636e0b 7606
1d7f656d
KT
7607 if (pVBInfo->SetFlag &
7608 DisableChA)
cc1e2398 7609 tempah &= 0x7F;
d7636e0b 7610
1d7f656d
KT
7611 if (pVBInfo->SetFlag &
7612 EnableChB)
cc1e2398 7613 tempah |= 0x40;
d7636e0b 7614
1d7f656d
KT
7615 if (pVBInfo->SetFlag &
7616 EnableChA)
cc1e2398
AK
7617 tempah |= 0x80;
7618 }
7619 }
7620 }
7621 }
d7636e0b 7622
1d7f656d
KT
7623 /* EnablePart4_1F */
7624 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
d7636e0b 7625
cc1e2398
AK
7626 if (!(pVBInfo->SetFlag & DisableChA)) {
7627 XGI_VBLongWait(pVBInfo);
7628 if (!(pVBInfo->SetFlag & GatingCRT)) {
1d7f656d
KT
7629 XGI_DisableGatingCRT(HwDeviceExtension,
7630 pVBInfo);
cc1e2398
AK
7631 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7632 XGI_VBLongWait(pVBInfo);
7633 }
7634 }
7635 } /* 301 */
7636 else { /* LVDS */
7637 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
7638 | SetCRT2ToLCDA))
1d7f656d
KT
7639 /* enable CRT2 */
7640 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
d7636e0b 7641
58839b01 7642 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
cc1e2398
AK
7643 0x2E);
7644 if (!(tempah & 0x80))
1d7f656d
KT
7645 /* BVBDOENABLE = 1 */
7646 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
d7636e0b 7647
dc50556b 7648 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
cc1e2398
AK
7649 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7650 } /* End of VB */
d7636e0b 7651}
7652
cc1e2398
AK
7653static void XGI_SetCRT1Group(struct xgi_hw_device_info *HwDeviceExtension,
7654 unsigned short ModeNo, unsigned short ModeIdIndex,
21df8fc8 7655 struct vb_device_info *pVBInfo)
d7636e0b 7656{
cc1e2398 7657 unsigned short StandTableIndex, RefreshRateTableIndex, b3CC, temp;
d7636e0b 7658
cc1e2398 7659 unsigned short XGINew_P3cc = pVBInfo->P3cc;
d7636e0b 7660
cc1e2398
AK
7661 /* XGINew_CRT1Mode = ModeNo; // SaveModeID */
7662 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
7663 /* XGI_SetBIOSData(ModeNo, ModeIdIndex); */
7664 /* XGI_ClearBankRegs(ModeNo, ModeIdIndex); */
7665 XGI_SetSeqRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7666 XGI_SetMiscRegs(StandTableIndex, pVBInfo);
7667 XGI_SetCRTCRegs(HwDeviceExtension, StandTableIndex, pVBInfo);
7668 XGI_SetATTRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7669 XGI_SetGRCRegs(StandTableIndex, pVBInfo);
7670 XGI_ClearExt1Regs(pVBInfo);
d7636e0b 7671
cc1e2398
AK
7672 /* if (pVBInfo->IF_DEF_ExpLink) */
7673 if (HwDeviceExtension->jChipType == XG27) {
7674 if (pVBInfo->IF_DEF_LVDS == 0)
7675 XGI_SetDefaultVCLK(pVBInfo);
21df8fc8 7676 }
d7636e0b 7677
cc1e2398
AK
7678 temp = ~ProgrammingCRT2;
7679 pVBInfo->SetFlag &= temp;
7680 pVBInfo->SelectCRT2Rate = 0;
d7636e0b 7681
cc1e2398
AK
7682 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7683 | VB_XGI302LV | VB_XGI301C)) {
7684 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA
7685 | SetInSlaveMode)) {
7686 pVBInfo->SetFlag |= ProgrammingCRT2;
21df8fc8 7687 }
cc1e2398 7688 }
d7636e0b 7689
cc1e2398
AK
7690 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7691 ModeIdIndex, pVBInfo);
7692 if (RefreshRateTableIndex != 0xFFFF) {
7693 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
7694 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7695 pVBInfo, HwDeviceExtension);
7696 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
7697 RefreshRateTableIndex, pVBInfo);
7698 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7699 HwDeviceExtension, pVBInfo);
7700 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
7701 RefreshRateTableIndex, pVBInfo);
7702 }
7703
1d7f656d
KT
7704 if ((HwDeviceExtension->jChipType >= XG20) &&
7705 (HwDeviceExtension->jChipType < XG27)) { /* fix H/W DCLK/2 bug */
cc1e2398 7706 if ((ModeNo == 0x00) | (ModeNo == 0x01)) {
8104e329
AK
7707 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x4E);
7708 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE9);
d8ad0a6d 7709 b3CC = (unsigned char) inb(XGINew_P3cc);
efdf4ee7 7710 outb((b3CC |= 0x0C), XGINew_P3cc);
cc1e2398
AK
7711 } else if ((ModeNo == 0x04) | (ModeNo == 0x05) | (ModeNo
7712 == 0x0D)) {
8104e329
AK
7713 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7714 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE3);
d8ad0a6d 7715 b3CC = (unsigned char) inb(XGINew_P3cc);
efdf4ee7 7716 outb((b3CC |= 0x0C), XGINew_P3cc);
21df8fc8 7717 }
d7636e0b 7718 }
d7636e0b 7719
cc1e2398 7720 if (HwDeviceExtension->jChipType >= XG21) {
58839b01 7721 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
cc1e2398 7722 if (temp & 0xA0) {
21df8fc8 7723
1d7f656d
KT
7724 /* Enable write GPIOF */
7725 /* xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x20); */
7726 /* P. DWN */
7727 /* xgifb_reg_and(pVBInfo->P3d4, 0x48, ~0x20); */
cc1e2398
AK
7728 /* XG21 CRT1 Timing */
7729 if (HwDeviceExtension->jChipType == XG27)
7730 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
7731 RefreshRateTableIndex, pVBInfo);
7732 else
7733 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
7734 RefreshRateTableIndex, pVBInfo);
21df8fc8 7735
cc1e2398
AK
7736 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
7737 RefreshRateTableIndex);
21df8fc8 7738
105d8d0d
AK
7739 xgifb_set_lcd(HwDeviceExtension->jChipType,
7740 pVBInfo, RefreshRateTableIndex, ModeNo);
cc1e2398 7741
64db29f5
AK
7742 if (pVBInfo->IF_DEF_LVDS == 1)
7743 xgifb_set_lvds(HwDeviceExtension->jChipType,
7744 ModeNo, ModeIdIndex, pVBInfo);
1d7f656d
KT
7745 /* P. ON */
7746 /* xgifb_reg_or(pVBInfo->P3d4, 0x48, 0x20); */
21df8fc8 7747 }
21df8fc8 7748 }
d7636e0b 7749
cc1e2398
AK
7750 pVBInfo->SetFlag &= (~ProgrammingCRT2);
7751 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
7752 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
7753 RefreshRateTableIndex, pVBInfo);
d7636e0b 7754
cc1e2398 7755 /* XGI_LoadCharacter(); //dif ifdef TVFont */
d7636e0b 7756
cc1e2398
AK
7757 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
7758 /* XGI_ClearBuffer(HwDeviceExtension, ModeNo, pVBInfo); */
d7636e0b 7759}
7760
cc1e2398
AK
7761unsigned char XGISetModeNew(struct xgi_hw_device_info *HwDeviceExtension,
7762 unsigned short ModeNo)
21df8fc8 7763{
cc1e2398 7764 unsigned short ModeIdIndex;
1d7f656d
KT
7765 /* unsigned char *pVBInfo->FBAddr =
7766 HwDeviceExtension->pjVideoMemoryAddress; */
cc1e2398
AK
7767 struct vb_device_info VBINF;
7768 struct vb_device_info *pVBInfo = &VBINF;
7769 pVBInfo->ROMAddr = HwDeviceExtension->pjVirtualRomBase;
7770 pVBInfo->BaseAddr = (unsigned long) HwDeviceExtension->pjIOAddress;
7771 pVBInfo->IF_DEF_LVDS = 0;
cc1e2398 7772 pVBInfo->IF_DEF_LCDA = 1;
cc1e2398
AK
7773
7774 if (HwDeviceExtension->jChipType >= XG20) { /* kuku 2004/06/25 */
7775 pVBInfo->IF_DEF_YPbPr = 0;
7776 pVBInfo->IF_DEF_HiVision = 0;
7777 pVBInfo->IF_DEF_CRT2Monitor = 0;
7778 pVBInfo->VBType = 0; /*set VBType default 0*/
cc1e2398
AK
7779 } else {
7780 pVBInfo->IF_DEF_YPbPr = 1;
7781 pVBInfo->IF_DEF_HiVision = 1;
06587335 7782 pVBInfo->IF_DEF_CRT2Monitor = 1;
cc1e2398
AK
7783 }
7784
7785 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
7786 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
7787 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
7788 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
7789 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
7790 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
7791 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
7792 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
7793 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
7794 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
7795 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
7796 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
7797 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
7798 pVBInfo->Part1Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_04;
7799 pVBInfo->Part2Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_10;
7800 pVBInfo->Part3Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_12;
7801 pVBInfo->Part4Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14;
7802 pVBInfo->Part5Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 + 2;
21df8fc8 7803
1d7f656d
KT
7804 /* for x86 Linux, XG21 LVDS */
7805 if (HwDeviceExtension->jChipType == XG21) {
58839b01 7806 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
cc1e2398
AK
7807 pVBInfo->IF_DEF_LVDS = 1;
7808 }
7809 if (HwDeviceExtension->jChipType == XG27) {
58839b01
AK
7810 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
7811 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
cc1e2398
AK
7812 pVBInfo->IF_DEF_LVDS = 1;
7813 }
7814 }
21df8fc8 7815
cc1e2398
AK
7816 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 */
7817 XGI_GetVBType(pVBInfo);
21df8fc8 7818
cc1e2398
AK
7819 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
7820 if (ModeNo & 0x80) {
7821 ModeNo = ModeNo & 0x7F;
7822 /* XGINew_flag_clearbuffer = 0; */
7823 }
7824 /* else {
7825 XGINew_flag_clearbuffer = 1;
21df8fc8 7826 }
cc1e2398 7827 */
8104e329 7828 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
21df8fc8 7829
cc1e2398
AK
7830 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 1.Openkey */
7831 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
21df8fc8 7832
cc1e2398 7833 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
21df8fc8 7834
cc1e2398
AK
7835 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
7836 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
7837 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
7838 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
7839 XGI_DisableBridge(HwDeviceExtension, pVBInfo);
21df8fc8 7840
cc1e2398
AK
7841 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) {
7842 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
7843 ModeIdIndex, pVBInfo);
21df8fc8 7844
cc1e2398
AK
7845 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7846 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7847 HwDeviceExtension, pVBInfo);
7848 }
7849 } else {
7850 if (!(pVBInfo->VBInfo & SwitchToCRT2)) {
7851 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
7852 ModeIdIndex, pVBInfo);
7853 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7854 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7855 HwDeviceExtension,
7856 pVBInfo);
7857 }
7858 }
7859 }
21df8fc8 7860
cc1e2398
AK
7861 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchToCRT2)) {
7862 switch (HwDeviceExtension->ujVBChipID) {
7863 case VB_CHIP_301:
7864 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
7865 pVBInfo); /*add for CRT2 */
7866 break;
21df8fc8 7867
cc1e2398
AK
7868 case VB_CHIP_302:
7869 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
7870 pVBInfo); /*add for CRT2 */
7871 break;
21df8fc8 7872
cc1e2398
AK
7873 default:
7874 break;
7875 }
7876 }
21df8fc8 7877
cc1e2398
AK
7878 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
7879 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
7880 XGI_CloseCRTC(HwDeviceExtension, pVBInfo);
7881 XGI_EnableBridge(HwDeviceExtension, pVBInfo);
7882 } /* !XG20 */
7883 else {
7884 if (pVBInfo->IF_DEF_LVDS == 1)
1d7f656d
KT
7885 if (!XGI_XG21CheckLVDSMode(ModeNo,
7886 ModeIdIndex,
7887 pVBInfo))
cc1e2398 7888 return 0;
21df8fc8 7889
cc1e2398 7890 if (ModeNo <= 0x13) {
1d7f656d
KT
7891 pVBInfo->ModeType = pVBInfo->SModeIDTable[ModeIdIndex].
7892 St_ModeFlag & ModeInfoFlag;
cc1e2398 7893 } else {
1d7f656d
KT
7894 pVBInfo->ModeType = pVBInfo->EModeIDTable[ModeIdIndex].
7895 Ext_ModeFlag & ModeInfoFlag;
cc1e2398 7896 }
21df8fc8 7897
cc1e2398 7898 pVBInfo->SetFlag = 0;
83f76a9d 7899 pVBInfo->VBInfo = DisableCRT2Display;
21df8fc8 7900
cc1e2398 7901 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
21df8fc8 7902
cc1e2398
AK
7903 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex,
7904 pVBInfo);
21df8fc8 7905
cc1e2398
AK
7906 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7907 /*
7908 if (HwDeviceExtension->jChipType == XG21)
ec9e5d3e 7909 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0x80, 0x80);
cc1e2398
AK
7910 */
7911 }
21df8fc8 7912
cc1e2398
AK
7913 /*
7914 if (ModeNo <= 0x13) {
7915 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
7916 } else {
7917 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
7918 }
7919 pVBInfo->ModeType = modeflag&ModeInfoFlag;
7920 pVBInfo->SetFlag = 0x00;
7921 pVBInfo->VBInfo = DisableCRT2Display;
1d7f656d
KT
7922 temp = XGINew_CheckMemorySize(HwDeviceExtension,
7923 ModeNo,
7924 ModeIdIndex,
7925 pVBInfo);
21df8fc8 7926
cc1e2398
AK
7927 if (temp == 0)
7928 return (0);
21df8fc8 7929
cc1e2398
AK
7930 XGI_DisplayOff(HwDeviceExtension, pVBInfo) ;
7931 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex, pVBInfo);
7932 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7933 */
21df8fc8 7934
cc1e2398 7935 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
21df8fc8 7936
cc1e2398
AK
7937 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
7938 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
21df8fc8 7939 }
21df8fc8 7940
cc1e2398 7941 return 1;
d7636e0b 7942}
This page took 0.75146 seconds and 5 git commands to generate.