blob: aebdf05eb64f4e958d993395dae5a8b056ea754d [file] [log] [blame]
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002#include <linux/io.h>
Aaro Koskinend80aaa02011-02-17 23:29:14 +02003#include <linux/delay.h>
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004#include <linux/types.h>
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005#include "XGIfb.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007
8#include "vb_def.h"
9#include "vgatypes.h"
10#include "vb_struct.h"
11#include "vb_util.h"
12#include "vb_table.h"
Aaro Koskinen5e60b972011-03-08 22:16:14 +020013#include "vb_setmode.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020014
15
16#define IndexMask 0xff
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020017
Randy Dunlap89229672010-08-10 08:46:44 -070018static unsigned short XGINew_MDA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040019 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
20 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
21 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
22 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
23 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
24 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
25 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
26 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020027
Randy Dunlap89229672010-08-10 08:46:44 -070028static unsigned short XGINew_CGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040029 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
30 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
31 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
32 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
33 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
34 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
35 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
36 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020037
Randy Dunlap89229672010-08-10 08:46:44 -070038static unsigned short XGINew_EGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040039 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x05, 0x15,
40 0x20, 0x30, 0x24, 0x34, 0x21, 0x31, 0x25, 0x35,
41 0x08, 0x18, 0x0C, 0x1C, 0x09, 0x19, 0x0D, 0x1D,
42 0x28, 0x38, 0x2C, 0x3C, 0x29, 0x39, 0x2D, 0x3D,
43 0x02, 0x12, 0x06, 0x16, 0x03, 0x13, 0x07, 0x17,
44 0x22, 0x32, 0x26, 0x36, 0x23, 0x33, 0x27, 0x37,
45 0x0A, 0x1A, 0x0E, 0x1E, 0x0B, 0x1B, 0x0F, 0x1F,
46 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020047
Randy Dunlap89229672010-08-10 08:46:44 -070048static unsigned short XGINew_VGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040049 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
50 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
51 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
52 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
53 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
54 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
55 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
56 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
57 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
58 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020059
Bill Pemberton80adad82010-06-17 13:10:51 -040060void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020061{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053062 pVBInfo->SModeIDTable = (struct XGI_StStruct *) XGI330_SModeIDTable;
63 pVBInfo->StandTable = (struct XGI_StandTableStruct *) XGI330_StandTable;
64 pVBInfo->EModeIDTable = (struct XGI_ExtStruct *) XGI330_EModeIDTable;
65 pVBInfo->RefIndex = (struct XGI_Ext2Struct *) XGI330_RefIndex;
66 pVBInfo->XGINEWUB_CRT1Table
67 = (struct XGI_CRT1TableStruct *) XGI_CRT1Table;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020068
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053069 /* add for new UNIVGABIOS */
Kenji Toyama1d7f6562011-04-23 19:36:49 +080070 /* XGINew_UBLCDDataTable =
71 * (struct XGI_LCDDataTablStruct *) XGI_LCDDataTable; */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053072 /* XGINew_UBTVDataTable = (XGI_TVDataTablStruct *) XGI_TVDataTable; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020073
Aaro Koskinen06587332011-03-13 12:26:10 +020074 pVBInfo->MCLKData = (struct XGI_MCLKDataStruct *) XGI340New_MCLKData;
75 pVBInfo->ECLKData = (struct XGI_ECLKDataStruct *) XGI340_ECLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053076 pVBInfo->VCLKData = (struct XGI_VCLKDataStruct *) XGI_VCLKData;
77 pVBInfo->VBVCLKData = (struct XGI_VBVCLKDataStruct *) XGI_VBVCLKData;
78 pVBInfo->ScreenOffset = XGI330_ScreenOffset;
79 pVBInfo->StResInfo = (struct XGI_StResInfoStruct *) XGI330_StResInfo;
80 pVBInfo->ModeResInfo
81 = (struct XGI_ModeResInfoStruct *) XGI330_ModeResInfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020082
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053083 pVBInfo->pOutputSelect = &XGI330_OutputSelect;
84 pVBInfo->pSoftSetting = &XGI330_SoftSetting;
85 pVBInfo->pSR07 = &XGI330_SR07;
86 pVBInfo->LCDResInfo = 0;
87 pVBInfo->LCDTypeInfo = 0;
88 pVBInfo->LCDInfo = 0;
89 pVBInfo->VBInfo = 0;
90 pVBInfo->TVInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020091
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053092 pVBInfo->SR15 = XGI340_SR13;
93 pVBInfo->CR40 = XGI340_cr41;
94 pVBInfo->SR25 = XGI330_sr25;
95 pVBInfo->pSR31 = &XGI330_sr31;
96 pVBInfo->pSR32 = &XGI330_sr32;
97 pVBInfo->CR6B = XGI340_CR6B;
98 pVBInfo->CR6E = XGI340_CR6E;
99 pVBInfo->CR6F = XGI340_CR6F;
100 pVBInfo->CR89 = XGI340_CR89;
101 pVBInfo->AGPReg = XGI340_AGPReg;
102 pVBInfo->SR16 = XGI340_SR16;
103 pVBInfo->pCRCF = &XG40_CRCF;
104 pVBInfo->pXGINew_DRAMTypeDefinition = &XG40_DRAMTypeDefinition;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530106 pVBInfo->CR49 = XGI330_CR49;
107 pVBInfo->pSR1F = &XGI330_SR1F;
108 pVBInfo->pSR21 = &XGI330_SR21;
109 pVBInfo->pSR22 = &XGI330_SR22;
110 pVBInfo->pSR23 = &XGI330_SR23;
111 pVBInfo->pSR24 = &XGI330_SR24;
112 pVBInfo->pSR33 = &XGI330_SR33;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530114 pVBInfo->pCRT2Data_1_2 = &XGI330_CRT2Data_1_2;
115 pVBInfo->pCRT2Data_4_D = &XGI330_CRT2Data_4_D;
116 pVBInfo->pCRT2Data_4_E = &XGI330_CRT2Data_4_E;
117 pVBInfo->pCRT2Data_4_10 = &XGI330_CRT2Data_4_10;
118 pVBInfo->pRGBSenseData = &XGI330_RGBSenseData;
119 pVBInfo->pVideoSenseData = &XGI330_VideoSenseData;
120 pVBInfo->pYCSenseData = &XGI330_YCSenseData;
121 pVBInfo->pRGBSenseData2 = &XGI330_RGBSenseData2;
122 pVBInfo->pVideoSenseData2 = &XGI330_VideoSenseData2;
123 pVBInfo->pYCSenseData2 = &XGI330_YCSenseData2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200124
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530125 pVBInfo->NTSCTiming = XGI330_NTSCTiming;
126 pVBInfo->PALTiming = XGI330_PALTiming;
127 pVBInfo->HiTVExtTiming = XGI330_HiTVExtTiming;
128 pVBInfo->HiTVSt1Timing = XGI330_HiTVSt1Timing;
129 pVBInfo->HiTVSt2Timing = XGI330_HiTVSt2Timing;
130 pVBInfo->HiTVTextTiming = XGI330_HiTVTextTiming;
131 pVBInfo->YPbPr750pTiming = XGI330_YPbPr750pTiming;
132 pVBInfo->YPbPr525pTiming = XGI330_YPbPr525pTiming;
133 pVBInfo->YPbPr525iTiming = XGI330_YPbPr525iTiming;
134 pVBInfo->HiTVGroup3Data = XGI330_HiTVGroup3Data;
135 pVBInfo->HiTVGroup3Simu = XGI330_HiTVGroup3Simu;
136 pVBInfo->HiTVGroup3Text = XGI330_HiTVGroup3Text;
137 pVBInfo->Ren525pGroup3 = XGI330_Ren525pGroup3;
138 pVBInfo->Ren750pGroup3 = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200139
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530140 pVBInfo->TimingH = (struct XGI_TimingHStruct *) XGI_TimingH;
141 pVBInfo->TimingV = (struct XGI_TimingVStruct *) XGI_TimingV;
142 pVBInfo->UpdateCRT1 = (struct XGI_XG21CRT1Struct *) XGI_UpdateCRT1Table;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200143
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530144 /* 310 customization related */
145 if ((pVBInfo->VBType & VB_XGI301LV) || (pVBInfo->VBType & VB_XGI302LV))
146 pVBInfo->LCDCapList = XGI_LCDDLCapList;
147 else
148 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200149
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530150 if ((ChipType == XG21) || (ChipType == XG27))
151 pVBInfo->XG21_LVDSCapList = XGI21_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200152
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530153 pVBInfo->XGI_TVDelayList = XGI301TVDelayList;
154 pVBInfo->XGI_TVDelayList2 = XGI301TVDelayList2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200155
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530156 pVBInfo->pXGINew_I2CDefinition = &XG40_I2CDefinition;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200157
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530158 if (ChipType >= XG20)
159 pVBInfo->pXGINew_CR97 = &XG20_CR97;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200160
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530161 if (ChipType == XG27) {
162 pVBInfo->MCLKData
163 = (struct XGI_MCLKDataStruct *) XGI27New_MCLKData;
164 pVBInfo->CR40 = XGI27_cr41;
165 pVBInfo->pXGINew_CR97 = &XG27_CR97;
166 pVBInfo->pSR36 = &XG27_SR36;
167 pVBInfo->pCR8F = &XG27_CR8F;
168 pVBInfo->pCRD0 = XG27_CRD0;
169 pVBInfo->pCRDE = XG27_CRDE;
170 pVBInfo->pSR40 = &XG27_SR40;
171 pVBInfo->pSR41 = &XG27_SR41;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200172
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530173 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200174
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530175 if (ChipType >= XG20) {
176 pVBInfo->pDVOSetting = &XG21_DVOSetting;
177 pVBInfo->pCR2E = &XG21_CR2E;
178 pVBInfo->pCR2F = &XG21_CR2F;
179 pVBInfo->pCR46 = &XG21_CR46;
180 pVBInfo->pCR47 = &XG21_CR47;
181 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200182
183}
184
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800185static unsigned char XGI_GetModePtr(unsigned short ModeNo,
186 unsigned short ModeIdIndex,
187 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200188{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530189 unsigned char index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200190
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530191 if (ModeNo <= 0x13)
192 index = pVBInfo->SModeIDTable[ModeIdIndex].St_StTableIndex;
193 else {
194 if (pVBInfo->ModeType <= 0x02)
195 index = 0x1B; /* 02 -> ModeEGA */
196 else
197 index = 0x0F;
198 }
199 return index; /* Get pVBInfo->StandTable index */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200200}
201
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800202static void XGI_SetSeqRegs(unsigned short ModeNo,
203 unsigned short StandTableIndex,
204 unsigned short ModeIdIndex,
205 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200206{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530207 unsigned char tempah, SRdata;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530208 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200209
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530210 if (ModeNo <= 0x13)
211 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
212 else
213 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200214
Aaro Koskinen8104e322011-03-13 12:26:22 +0200215 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530216 tempah = pVBInfo->StandTable[StandTableIndex].SR[0];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200217
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530218 i = SetCRT2ToLCDA;
219 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
220 tempah |= 0x01;
221 } else {
222 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
223 if (pVBInfo->VBInfo & SetInSlaveMode)
224 tempah |= 0x01;
225 }
226 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200227
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530228 tempah |= 0x20; /* screen off */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200229 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200230
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530231 for (i = 02; i <= 04; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800232 /* Get SR2,3,4 from file */
233 SRdata = pVBInfo->StandTable[StandTableIndex].SR[i - 1];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200234 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530235 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200236}
237
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200238static void XGI_SetMiscRegs(unsigned short StandTableIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800239 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200240{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530241 unsigned char Miscdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200242
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800243 /* Get Misc from file */
244 Miscdata = pVBInfo->StandTable[StandTableIndex].MISC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530245 /*
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800246 if (pVBInfo->VBType & (VB_XGI301B |
247 VB_XGI302B |
248 VB_XGI301LV |
249 VB_XGI302LV |
250 VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530251 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
252 Miscdata |= 0x0C;
253 }
254 }
255 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200256
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200257 outb(Miscdata, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200258}
259
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200260static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800261 unsigned short StandTableIndex,
262 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200263{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530264 unsigned char CRTCdata;
265 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200266
Aaro Koskinen58839b02011-03-13 12:26:23 +0200267 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530268 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200269 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200270
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530271 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800272 /* Get CRTC from file */
273 CRTCdata = pVBInfo->StandTable[StandTableIndex].CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200274 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530275 }
276 /*
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800277 if ((HwDeviceExtension->jChipType == XGI_630) &&
278 (HwDeviceExtension->jChipRevision == 0x30)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530279 if (pVBInfo->VBInfo & SetInSlaveMode) {
280 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200281 xgifb_reg_set(pVBInfo->P3d4, 0x18, 0xFE);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530282 }
283 }
284 }
285 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200286}
287
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800288static void XGI_SetATTRegs(unsigned short ModeNo,
289 unsigned short StandTableIndex,
290 unsigned short ModeIdIndex,
291 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200292{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530293 unsigned char ARdata;
294 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200295
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530296 if (ModeNo <= 0x13)
297 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
298 else
299 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200300
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530301 for (i = 0; i <= 0x13; i++) {
302 ARdata = pVBInfo->StandTable[StandTableIndex].ATTR[i];
303 if (modeflag & Charx8Dot) { /* ifndef Dot9 */
304 if (i == 0x13) {
305 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
306 ARdata = 0;
307 } else {
308 if (pVBInfo->VBInfo & (SetCRT2ToTV
309 | SetCRT2ToLCD)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800310 if (pVBInfo->VBInfo &
311 SetInSlaveMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530312 ARdata = 0;
313 }
314 }
315 }
316 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200317
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200318 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200319 outb(i, pVBInfo->P3c0); /* set index */
320 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530321 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200322
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200323 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200324 outb(0x14, pVBInfo->P3c0); /* set index */
325 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200326 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200327 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200328}
329
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200330static void XGI_SetGRCRegs(unsigned short StandTableIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800331 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200332{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530333 unsigned char GRdata;
334 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200335
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530336 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800337 /* Get GR from file */
338 GRdata = pVBInfo->StandTable[StandTableIndex].GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200339 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530340 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200341
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530342 if (pVBInfo->ModeType > ModeVGA) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200343 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530344 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200345 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530346 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200347}
348
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200349static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200350{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530351 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200352
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530353 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200354 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200355}
356
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200357static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200358{
359
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200360 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200361 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[0].SR2B);
362 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200363
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200364 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200365 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[1].SR2B);
366 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200367
Aaro Koskinendc505562011-03-13 12:26:26 +0200368 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530369 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200370}
371
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200372static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530373 unsigned short ModeIdIndex,
374 unsigned short RefreshRateTableIndex, unsigned short *i,
375 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200376{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530377 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200378
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530379 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800380 /* si+St_ModeFlag */
381 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530382 else
383 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200384
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530385 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
386 tempbx = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID;
387 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200388
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530389 if (pVBInfo->IF_DEF_LVDS == 0) {
390 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
391 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200392
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530393 if (pVBInfo->VBType & VB_XGI301C)
394 tempax |= SupportCRT2in301C;
395 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200396
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800397 /* 301b */
398 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530399 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200400
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530401 if (pVBInfo->LCDResInfo != Panel1280x1024) {
402 if (pVBInfo->LCDResInfo != Panel1280x960) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800403 if (pVBInfo->LCDInfo &
404 LCDNonExpanding) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530405 if (resinfo >= 9) {
406 tempax = 0;
407 return 0;
408 }
409 }
410 }
411 }
412 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200413
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530414 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) { /* for HiTV */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800415 if ((pVBInfo->VBType & VB_XGI301LV) &&
416 (pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530417 tempax |= SupportYPbPr;
418 if (pVBInfo->VBInfo & SetInSlaveMode) {
419 if (resinfo == 4)
420 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200421
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530422 if (resinfo == 3)
423 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200424
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530425 if (resinfo > 7)
426 return 0;
427 }
428 } else {
429 tempax |= SupportHiVisionTV;
430 if (pVBInfo->VBInfo & SetInSlaveMode) {
431 if (resinfo == 4)
432 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200433
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530434 if (resinfo == 3) {
435 if (pVBInfo->SetFlag
436 & TVSimuMode)
437 return 0;
438 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200439
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530440 if (resinfo > 7)
441 return 0;
442 }
443 }
444 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800445 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
446 SetCRT2ToSVIDEO |
447 SetCRT2ToSCART |
448 SetCRT2ToYPbPr |
449 SetCRT2ToHiVisionTV)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530450 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200451
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530452 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
453 | VB_XGI301LV | VB_XGI302LV
454 | VB_XGI301C)) {
455 tempax |= SupportTV1024;
456 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200457
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530458 if (!(pVBInfo->VBInfo & SetPALTV)) {
459 if (modeflag & NoSupportSimuTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800460 if (pVBInfo->VBInfo &
461 SetInSlaveMode) {
462 if (!(pVBInfo->VBInfo &
463 SetNotSimuMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530464 return 0;
465 }
466 }
467 }
468 }
469 }
470 }
471 } else { /* for LVDS */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530472 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
473 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200474
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530475 if (resinfo > 0x08)
476 return 0; /* 1024x768 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200477
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530478 if (pVBInfo->LCDResInfo < Panel1024x768) {
479 if (resinfo > 0x07)
480 return 0; /* 800x600 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200481
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530482 if (resinfo == 0x04)
483 return 0; /* 512x384 */
484 }
485 }
486 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200487
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800488 for (; pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
489 tempbx; (*i)--) {
490 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
491 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530492 if (infoflag & tempax)
493 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200494
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530495 if ((*i) == 0)
496 break;
497 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200498
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530499 for ((*i) = 0;; (*i)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800500 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
501 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530502 if (pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID
503 != tempbx) {
504 return 0;
505 }
506
507 if (infoflag & tempax)
508 return 1;
509 }
510 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200511}
512
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200513static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530514 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200515{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530516 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200517
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800518 /* di+0x00 */
519 sync = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530520 sync &= 0xC0;
521 temp = 0x2F;
522 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200523 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200524}
525
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200526static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530527 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200528{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530529 unsigned char data, data1, pushax;
530 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200531
Aaro Koskinen8104e322011-03-13 12:26:22 +0200532 /* xgifb_reg_set(pVBInfo->P3d4, 0x51, 0); */
533 /* xgifb_reg_set(pVBInfo->P3d4, 0x56, 0); */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200534 /* xgifb_reg_and_or(pVBInfo->P3d4, 0x11, 0x7f, 0x00); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200535
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800536 /* unlock cr0-7 */
537 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530538 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200539 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200540
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530541 data = pVBInfo->TimingH[0].data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200542 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200543
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530544 for (i = 0x01; i <= 0x04; i++) {
545 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200546 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530547 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200548
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530549 for (i = 0x05; i <= 0x06; i++) {
550 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200551 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530552 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200553
Aaro Koskinen58839b02011-03-13 12:26:23 +0200554 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530555 j &= 0x1F;
556 data = pVBInfo->TimingH[0].data[7];
557 data &= 0xE0;
558 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200559 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200560
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530561 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200562 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530563 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200564 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200565 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530566 data1 = data;
567 data1 &= 0xE0;
568 data &= 0x1F;
569 if (data == 0) {
570 pushax = data;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200571 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530572 0x0c);
573 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200574 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530575 data = pushax;
576 }
577 data = data - 1;
578 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200579 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200580 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530581 data = data >> 5;
582 data = data + 3;
583 if (data > 7)
584 data = data - 7;
585 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200586 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530587 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200588}
589
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800590static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
591 unsigned short ModeNo,
592 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200593{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530594 unsigned char data;
595 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200596
Aaro Koskinen8104e322011-03-13 12:26:22 +0200597 /* xgifb_reg_set(pVBInfo->P3d4, 0x51, 0); */
598 /* xgifb_reg_set(pVBInfo->P3d4, 0x56, 0); */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200599 /* xgifb_reg_and_or(pVBInfo->P3d4, 0x11, 0x7f, 0x00); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200600
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530601 for (i = 0x00; i <= 0x01; i++) {
602 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200603 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530604 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200605
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530606 for (i = 0x02; i <= 0x03; i++) {
607 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200608 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530609 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200610
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530611 for (i = 0x04; i <= 0x05; i++) {
612 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200613 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530614 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200615
Aaro Koskinen58839b02011-03-13 12:26:23 +0200616 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530617 j &= 0xC0;
618 data = pVBInfo->TimingV[0].data[6];
619 data &= 0x3F;
620 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200621 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200622
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530623 data = pVBInfo->TimingV[0].data[6];
624 data &= 0x80;
625 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200626
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530627 if (ModeNo <= 0x13)
628 i = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
629 else
630 i = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200631
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530632 i &= DoubleScanMode;
633 if (i)
634 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200635
Aaro Koskinen58839b02011-03-13 12:26:23 +0200636 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530637 j &= 0x5F;
638 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200639 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200640}
641
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200642static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
643 unsigned short RefreshRateTableIndex,
644 struct vb_device_info *pVBInfo,
645 struct xgi_hw_device_info *HwDeviceExtension)
646{
647 unsigned char index, data;
648 unsigned short i;
649
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800650 /* Get index */
651 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200652 index = index & IndexMask;
653
Aaro Koskinen58839b02011-03-13 12:26:23 +0200654 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200655 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200656 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200657
658 for (i = 0; i < 8; i++)
659 pVBInfo->TimingH[0].data[i]
660 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i];
661
662 for (i = 0; i < 7; i++)
663 pVBInfo->TimingV[0].data[i]
664 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i + 8];
665
666 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
667
668 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
669
670 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200671 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200672}
673
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200674/* --------------------------------------------------------------------- */
675/* Function : XGI_SetXG21CRTC */
676/* Input : Stand or enhance CRTC table */
677/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
678/* Description : Set LCD timing */
679/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200680static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530681 unsigned short RefreshRateTableIndex,
682 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200683{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530684 unsigned char StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
685 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200686
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530687 if (ModeNo <= 0x13) {
688 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800689 /* CR04 HRS */
690 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4];
691 /* SR2E [7:0]->HRS */
692 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
693 /* Tempbx: CR05 HRE */
694 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530695 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */
696 Tempcx = Tempax;
697 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */
698 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
699 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */
700 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */
701 Tempdx <<= 2; /* Tempdx << 2 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800702 /* SR2F [7:2]->HRE */
703 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200704 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200705
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800706 /* Tempax: CR16 VRS */
707 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530708 Tempbx = Tempax; /* Tempbx=Tempax */
709 Tempax &= 0x01; /* Tempax: VRS[0] */
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200710 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800711
712 /* Tempax: CR7 VRS */
713 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530714 Tempdx = Tempbx >> 1; /* Tempdx: VRS[7:1] */
715 Tempcx = Tempax & 0x04; /* Tempcx: CR7[2] */
716 Tempcx <<= 5; /* Tempcx[7]: VRS[8] */
717 Tempdx |= Tempcx; /* Tempdx: VRS[8:1] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800718 /* SR34[7:0]: VRS[8:1] */
719 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempdx);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200720
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800721 /* Temp1[8]: VRS[8] unsigned char -> unsigned short */
722 Temp1 = Tempcx << 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530723 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
724 Tempax &= 0x80; /* Tempax[7]: CR7[7] */
725 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
726 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200727
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800728 /* CR16 VRE */
729 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530730 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
731 Temp2 = Temp1 & 0x3F0; /* Temp2[9:4]: VRS[9:4] */
732 Temp2 |= Tempax; /* Temp2[9:0]: VRE[9:0] */
733 Temp3 = Temp1 & 0x0F; /* Temp3[3:0]: VRS[3:0] */
734 if (Tempax < Temp3) /* VRE[3:0]<VRS[3:0] */
735 Temp2 |= 0x10; /* Temp2: VRE + 0x10 */
736 Temp2 &= 0xFF; /* Temp2[7:0]: VRE[7:0] */
737 Tempax = (unsigned char) Temp2; /* Tempax[7:0]: VRE[7:0] */
738 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */
739 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
740 Temp1 >>= 9; /* [10:9]->[1:0] */
741 Tempbx = (unsigned char) Temp1; /* Tempbx[1:0]: VRS[10:9] */
742 Tempax |= Tempbx; /* VRE[5:0]VRS[10:9] */
743 Tempax &= 0x7F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800744 /* SR3F D[7:2]->VRE D[1:0]->VRS */
745 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530746 } else {
747 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800748 /* Tempax: CR4 HRS */
749 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530750 Tempcx = Tempax; /* Tempcx: HRS */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800751 /* SR2E[7:0]->HRS */
752 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200753
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530754 Tempdx = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SRB */
755 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
756 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
757 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
758 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200759
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530760 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
761 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200762
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530763 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
764 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
765 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
766 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200767
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530768 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
769 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200770
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530771 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
772 if (Tempax < Tempcx) /* HRE < HRS */
773 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200774
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530775 Temp2 &= 0xFF;
776 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
777 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
778 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
779 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800780 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
781 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200782 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200783
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800784 /* CR10 VRS */
785 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530786 Tempbx = Tempax; /* Tempbx: VRS */
787 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200788 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800789 /* CR7[2][7] VRE */
790 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530791 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
792 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
793 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
794 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200795 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530797 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
798 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
799 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
800 Tempax &= 0x80;
801 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
802 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800803 /* Tempax: SRA */
804 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530805 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
806 Temp2 = Tempax;
807 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
808 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200809
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800810 /* Tempax: CR11 VRE */
811 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530812 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800813 /* Tempbx: SRA */
814 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530815 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
816 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
817 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
818 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
819 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200820
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530821 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
822 if (Tempax < Temp3) /* VRE < VRS */
823 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200824
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530825 Temp2 &= 0xFF;
826 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
827 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
828 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
829 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
830 Tempbx = (unsigned char) Temp1;
831 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
832 Tempax &= 0x7F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800833 /* SR3F D[7:2]->VRE D[1:0]->VRS */
834 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530835 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200836}
837
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800838static void XGI_SetXG27CRTC(unsigned short ModeNo,
839 unsigned short ModeIdIndex,
840 unsigned short RefreshRateTableIndex,
841 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200842{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400843 unsigned short StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200844
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530845 if (ModeNo <= 0x13) {
846 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800847 /* CR04 HRS */
848 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4];
849 /* SR2E [7:0]->HRS */
850 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
851 /* Tempbx: CR05 HRE */
852 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530853 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */
854 Tempcx = Tempax;
855 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */
856 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
857 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */
858 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */
859 Tempdx <<= 2; /* Tempdx << 2 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800860 /* SR2F [7:2]->HRE */
861 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200862 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200863
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800864 /* Tempax: CR10 VRS */
865 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200866 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax); /* SR34[7:0]->VRS */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530867 Tempcx = Tempax; /* Tempcx=Tempax=VRS[7:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800868 /* Tempax[7][2]: CR7[7][2] VRS[9][8] */
869 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530870 Tempbx = Tempax; /* Tempbx=CR07 */
871 Tempax &= 0x04; /* Tempax[2]: CR07[2] VRS[8] */
872 Tempax >>= 2;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800873 /* SR35 D[0]->VRS D[8] */
874 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530875 Tempcx |= (Tempax << 8); /* Tempcx[8] |= VRS[8] */
876 Tempcx |= (Tempbx & 0x80) << 2; /* Tempcx[9] |= VRS[9] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200877
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800878 /* CR11 VRE */
879 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530880 Tempax &= 0x0F; /* Tempax: VRE[3:0] */
881 Tempbx = Tempcx; /* Tempbx=Tempcx=VRS[9:0] */
882 Tempbx &= 0x3F0; /* Tempbx[9:4]: VRS[9:4] */
883 Tempbx |= Tempax; /* Tempbx[9:0]: VRE[9:0] */
884 if (Tempax <= (Tempcx & 0x0F)) /* VRE[3:0]<=VRS[3:0] */
885 Tempbx |= 0x10; /* Tempbx: VRE + 0x10 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800886 /* Tempax[7:0]: VRE[7:0] */
887 Tempax = (unsigned char) Tempbx & 0xFF;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530888 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */
889 Tempcx = (Tempcx & 0x600) >> 8; /* Tempcx VRS[10:9] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800890 /* SR3F D[7:2]->VRE D[5:0] */
891 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
892 /* SR35 D[2:1]->VRS[10:9] */
893 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x06, Tempcx);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530894 } else {
895 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800896 /* Tempax: CR4 HRS */
897 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530898 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800899 /* SR2E[7:0]->HRS */
900 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200901
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800902 /* SR0B */
903 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530904 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
905 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200906
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530907 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
908 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
909 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200910
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530911 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
912 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
913 Tempax <<= 3; /* Tempax[5]: HRE[5] */
914 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200915
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530916 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
917 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200918
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800919 /* Tempax: CR4 HRS */
920 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530921 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
922 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
923 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200924
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530925 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SR0B */
926 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
927 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
928 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800929 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
930 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200931 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200932
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800933 /* CR10 VRS */
934 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
935 /* SR34[7:0]->VRS[7:0] */
936 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200937
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530938 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800939 /* CR7[7][2] VRS[9][8] */
940 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530941 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
942 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
943 Tempax >>= 2; /* Tempax[0]: VRS[8] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800944 /* SR35[0]: VRS[8] */
945 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530946 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
947 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800948 /* Tempax: SR0A */
949 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530950 Tempax &= 0x08; /* SR0A[3] VRS[10] */
951 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200952
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800953 /* Tempax: CR11 VRE */
954 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530955 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800956 /* Tempbx: SR0A */
957 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530958 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
959 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
960 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
961 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
962 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
963 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200964
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530965 if (Tempbx <= Tempcx) /* VRE <= VRS */
966 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200967
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800968 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
969 Tempax = (Tempbx << 2) & 0xFF;
970 /* SR3F[7:2]:VRE[5:0] */
971 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530972 Tempax = Tempcx >> 8;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800973 /* SR35[2:0]:VRS[10:8] */
974 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530975 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200976}
977
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300978static void xgifb_set_lcd(int chip_id,
979 struct vb_device_info *pVBInfo,
980 unsigned short RefreshRateTableIndex,
981 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200982{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400983 unsigned short Data, Temp, b3CC;
984 unsigned short XGI_P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200985
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530986 XGI_P3cc = pVBInfo->P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200987
Aaro Koskinen8104e322011-03-13 12:26:22 +0200988 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
989 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
990 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
991 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300992
993 if (chip_id == XG27) {
994 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
995 if ((Temp & 0x03) == 0) { /* dual 12 */
996 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
997 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
998 }
999 }
1000
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301001 if (((*pVBInfo->pDVOSetting) & 0xC0) == 0xC0) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001002 xgifb_reg_set(pVBInfo->P3d4, 0x2E, *pVBInfo->pCR2E);
1003 xgifb_reg_set(pVBInfo->P3d4, 0x2F, *pVBInfo->pCR2F);
1004 xgifb_reg_set(pVBInfo->P3d4, 0x46, *pVBInfo->pCR46);
1005 xgifb_reg_set(pVBInfo->P3d4, 0x47, *pVBInfo->pCR47);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301006 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001007
Aaro Koskinen105d8d02011-08-31 21:46:00 +03001008 if (chip_id == XG27) {
1009 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301010 } else {
Aaro Koskinen105d8d02011-08-31 21:46:00 +03001011 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
1012 if (Temp & 0x01) {
1013 /* 18 bits FP */
1014 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
1015 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
1016 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301017 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001018
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001019 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001020
Aaro Koskinendc505562011-03-13 12:26:26 +02001021 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
1022 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001023
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301024 if (ModeNo <= 0x13) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001025 b3CC = (unsigned char) inb(XGI_P3cc);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301026 if (b3CC & 0x40)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001027 /* Hsync polarity */
1028 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301029 if (b3CC & 0x80)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001030 /* Vsync polarity */
1031 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301032 } else {
1033 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1034 if (Data & 0x4000)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001035 /* Hsync polarity */
1036 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301037 if (Data & 0x8000)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001038 /* Vsync polarity */
1039 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301040 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001041}
1042
1043/* --------------------------------------------------------------------- */
1044/* Function : XGI_UpdateXG21CRTC */
1045/* Input : */
1046/* Output : CRT1 CRTC */
1047/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
1048/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001049static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
1050 struct vb_device_info *pVBInfo,
1051 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001052{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301053 int i, index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001054
Aaro Koskinendc505562011-03-13 12:26:26 +02001055 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301056 if (ModeNo <= 0x13) {
1057 for (i = 0; i < 12; i++) {
1058 if (ModeNo == pVBInfo->UpdateCRT1[i].ModeID)
1059 index = i;
1060 }
1061 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001062 if (ModeNo == 0x2E &&
1063 (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
1064 RES640x480x60))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301065 index = 12;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001066 else if (ModeNo == 0x2E &&
1067 (pVBInfo->RefIndex[RefreshRateTableIndex].
1068 Ext_CRT1CRTC == RES640x480x72))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301069 index = 13;
1070 else if (ModeNo == 0x2F)
1071 index = 14;
1072 else if (ModeNo == 0x50)
1073 index = 15;
1074 else if (ModeNo == 0x59)
1075 index = 16;
1076 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001077
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301078 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001079 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301080 pVBInfo->UpdateCRT1[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001081 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301082 pVBInfo->UpdateCRT1[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001083 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301084 pVBInfo->UpdateCRT1[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001085 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301086 pVBInfo->UpdateCRT1[index].CR16);
1087 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001088}
1089
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001090static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301091 unsigned short ModeNo, unsigned short ModeIdIndex,
1092 unsigned short RefreshRateTableIndex,
1093 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001094{
Bill Pemberton82d6eb52010-06-17 13:10:46 -04001095 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001096
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301097 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001098
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301099 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301101 if (ModeNo <= 0x13) {
1102 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1103 tempax = pVBInfo->StResInfo[resindex].HTotal;
1104 tempbx = pVBInfo->StResInfo[resindex].VTotal;
1105 } else {
1106 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1107 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
1108 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
1109 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001110
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301111 if (modeflag & HalfDCLK)
1112 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301114 if (ModeNo > 0x13) {
1115 if (modeflag & HalfDCLK)
1116 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001117
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301118 temp = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001119
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301120 if (temp & InterlaceMode)
1121 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301123 if (modeflag & DoubleScanMode)
1124 tempbx = tempbx << 1;
1125 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001126
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301127 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001128
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301129 /* if (!(modeflag & Charx8Dot)) */
1130 /* tempcx = 9; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001131
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301132 tempax /= tempcx;
1133 tempax -= 1;
1134 tempbx -= 1;
1135 tempcx = tempax;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001136 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
1137 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301138 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001139 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
1140 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001141 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301142 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +02001143 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301144 tempax = 0;
1145 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001146
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301147 if (tempbx & 0x01)
1148 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001149
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301150 if (tempbx & 0x02)
1151 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001152
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001153 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001154 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301155 data &= 0xFF;
1156 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001157
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301158 if (tempbx & 0x04)
1159 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001160
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001161 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001162 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001163}
1164
Bill Pemberton82d6eb52010-06-17 13:10:46 -04001165unsigned short XGI_GetResInfo(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301166 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001167{
Bill Pemberton82d6eb52010-06-17 13:10:46 -04001168 unsigned short resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001169
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301170 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001171 /* si+St_ResInfo */
1172 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301173 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001174 /* si+Ext_ResInfo */
1175 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301176 return resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001177}
1178
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001179static void XGI_SetCRT1Offset(unsigned short ModeNo,
1180 unsigned short ModeIdIndex,
1181 unsigned short RefreshRateTableIndex,
1182 struct xgi_hw_device_info *HwDeviceExtension,
1183 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001184{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301185 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001186
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301187 /* GetOffset */
1188 temp = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
1189 temp = temp >> 8;
1190 temp = pVBInfo->ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001191
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301192 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1193 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001194
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301195 if (temp2)
1196 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001197
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301198 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001199
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301200 switch (temp2) {
1201 case 0:
1202 temp2 = 1;
1203 break;
1204 case 1:
1205 temp2 = 2;
1206 break;
1207 case 2:
1208 temp2 = 4;
1209 break;
1210 case 3:
1211 temp2 = 4;
1212 break;
1213 case 4:
1214 temp2 = 6;
1215 break;
1216 case 5:
1217 temp2 = 8;
1218 break;
1219 default:
1220 break;
1221 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001222
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301223 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
1224 temp = temp * temp2 + temp2 / 2;
1225 else
1226 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001227
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301228 /* SetOffset */
1229 DisplayUnit = temp;
1230 temp2 = temp;
1231 temp = temp >> 8; /* ah */
1232 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001233 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301234 i &= 0xF0;
1235 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001236 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001237
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301238 temp = (unsigned char) temp2;
1239 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +02001240 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001241
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301242 /* SetDisplayUnit */
1243 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1244 temp2 &= InterlaceMode;
1245 if (temp2)
1246 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001247
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301248 DisplayUnit = DisplayUnit << 5;
1249 ah = (DisplayUnit & 0xff00) >> 8;
1250 al = DisplayUnit & 0x00ff;
1251 if (al == 0)
1252 ah += 1;
1253 else
1254 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001255
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301256 if (HwDeviceExtension->jChipType >= XG20)
1257 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
1258 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001259
Aaro Koskinen8104e322011-03-13 12:26:22 +02001260 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001261}
1262
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001263static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
1264 unsigned short ModeIdIndex,
1265 unsigned short RefreshRateTableIndex,
1266 struct xgi_hw_device_info *HwDeviceExtension,
1267 struct vb_device_info *pVBInfo)
1268{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001269 unsigned short LCDXlat1VCLK[4] = { VCLK65 + 2,
1270 VCLK65 + 2,
1271 VCLK65 + 2,
1272 VCLK65 + 2 };
1273 unsigned short LCDXlat2VCLK[4] = { VCLK108_2 + 5,
1274 VCLK108_2 + 5,
1275 VCLK108_2 + 5,
1276 VCLK108_2 + 5 };
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001277 unsigned short LVDSXlat1VCLK[4] = { VCLK40, VCLK40, VCLK40, VCLK40 };
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001278 unsigned short LVDSXlat2VCLK[4] = { VCLK65 + 2,
1279 VCLK65 + 2,
1280 VCLK65 + 2,
1281 VCLK65 + 2 };
1282 unsigned short LVDSXlat3VCLK[4] = { VCLK65 + 2,
1283 VCLK65 + 2,
1284 VCLK65 + 2,
1285 VCLK65 + 2 };
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001286
1287 unsigned short CRT2Index, VCLKIndex;
1288 unsigned short modeflag, resinfo;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001289
1290 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001291 /* si+St_ResInfo */
1292 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001293 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1294 CRT2Index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1295 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001296 /* si+Ext_ResInfo */
1297 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001298 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001299 CRT2Index = pVBInfo->RefIndex[RefreshRateTableIndex].
1300 Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001301 }
1302
1303 if (pVBInfo->IF_DEF_LVDS == 0) {
1304 CRT2Index = CRT2Index >> 6; /* for LCD */
1305 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /*301b*/
1306 if (pVBInfo->LCDResInfo != Panel1024x768)
1307 VCLKIndex = LCDXlat2VCLK[CRT2Index];
1308 else
1309 VCLKIndex = LCDXlat1VCLK[CRT2Index];
1310 } else { /* for TV */
1311 if (pVBInfo->VBInfo & SetCRT2ToTV) {
1312 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
1313 if (pVBInfo->SetFlag & RPLLDIV2XO) {
1314 VCLKIndex = HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001315 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001316 } else {
1317 VCLKIndex = HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001318 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001319 }
1320
1321 if (pVBInfo->SetFlag & TVSimuMode) {
1322 if (modeflag & Charx8Dot) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001323 VCLKIndex =
1324 HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001325 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001326 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001327 VCLKIndex =
1328 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001329 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001330 }
1331 }
1332
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001333 /* 301lv */
1334 if (pVBInfo->VBType & VB_XGI301LV) {
1335 if (!(pVBInfo->VBExtInfo ==
1336 VB_YPbPr1080i)) {
1337 VCLKIndex =
1338 YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001339 if (!(pVBInfo->VBExtInfo
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001340 ==
1341 VB_YPbPr750p)) {
1342 VCLKIndex =
1343 YPbPr525pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001344 if (!(pVBInfo->VBExtInfo
1345 == VB_YPbPr525p)) {
1346 VCLKIndex
1347 = YPbPr525iVCLK_2;
1348 if (!(pVBInfo->SetFlag
1349 & RPLLDIV2XO))
1350 VCLKIndex
1351 = YPbPr525iVCLK;
1352 }
1353 }
1354 }
1355 }
1356 } else {
1357 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001358 if (pVBInfo->SetFlag &
1359 RPLLDIV2XO) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001360 VCLKIndex = TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001361 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001362 } else {
1363 VCLKIndex = TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001364 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001365 }
1366 }
1367 }
1368 } else { /* for CRT2 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001369 /* Port 3cch */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001370 VCLKIndex = (unsigned char) inb(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001371 (pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001372 VCLKIndex = ((VCLKIndex >> 2) & 0x03);
1373 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001374 /* di+Ext_CRTVCLK */
1375 VCLKIndex =
1376 pVBInfo->RefIndex[
1377 RefreshRateTableIndex].
1378 Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001379 VCLKIndex &= IndexMask;
1380 }
1381 }
1382 }
1383 } else { /* LVDS */
1384 if (ModeNo <= 0x13)
1385 VCLKIndex = CRT2Index;
1386 else
1387 VCLKIndex = CRT2Index;
1388
Aaro Koskinen4c14bfd2011-08-31 21:45:57 +03001389 VCLKIndex = VCLKIndex >> 6;
1390 if ((pVBInfo->LCDResInfo == Panel800x600) ||
1391 (pVBInfo->LCDResInfo == Panel320x480))
1392 VCLKIndex = LVDSXlat1VCLK[VCLKIndex];
1393 else if ((pVBInfo->LCDResInfo == Panel1024x768) ||
1394 (pVBInfo->LCDResInfo == Panel1024x768x75))
1395 VCLKIndex = LVDSXlat2VCLK[VCLKIndex];
1396 else
1397 VCLKIndex = LVDSXlat3VCLK[VCLKIndex];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001398 }
1399 /* VCLKIndex = VCLKIndex&IndexMask; */
1400
1401 return VCLKIndex;
1402}
1403
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001404static void XGI_SetCRT1VCLK(unsigned short ModeNo,
1405 unsigned short ModeIdIndex,
1406 struct xgi_hw_device_info *HwDeviceExtension,
1407 unsigned short RefreshRateTableIndex,
1408 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001409{
Bill Pemberton108afbf2010-06-17 13:10:47 -04001410 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301411 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001412
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301413 if (pVBInfo->IF_DEF_LVDS == 1) {
1414 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001415 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001416 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1417 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301418 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001419 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301420 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001421 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301422 } else if ((pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
1423 | VB_XGI302LV | VB_XGI301C)) && (pVBInfo->VBInfo
1424 & SetCRT2ToLCDA)) {
1425 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
1426 RefreshRateTableIndex, HwDeviceExtension,
1427 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001428 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001429 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301430 data = pVBInfo->VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001431 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301432 data = pVBInfo->VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001433 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1434 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301435 } else {
1436 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001437 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001438 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1439 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301440 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001441 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301442 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001443 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301444 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001445
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301446 if (HwDeviceExtension->jChipType >= XG20) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001447 if (pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag &
1448 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001449 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001450 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001451 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301452 index = data;
1453 index &= 0xE0;
1454 data &= 0x1F;
1455 data = data << 1;
1456 data += 1;
1457 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001458 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301459 }
1460 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001461}
1462
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001463static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301464 struct xgi_hw_device_info *HwDeviceExtension,
1465 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001466{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301467 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001468
Aaro Koskinen58839b02011-03-13 12:26:23 +02001469 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301470 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001471 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001472
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301473 if (ModeNo > 0x13) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001474 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001475 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301476 data &= 0xC0;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001477 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001478 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301479 data |= 0x01;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001480 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301481 } else {
1482 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001483 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x0E);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001484 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301485 data &= 0xC0;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001486 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301487 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001488 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0xAE);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001489 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301490 data &= 0xF0;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001491 xgifb_reg_set(pVBInfo->P3c4, 0x09, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301492 }
1493 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001494
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301495 if (HwDeviceExtension->jChipType == XG21)
1496 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001497}
1498
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001499static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1500 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1501 struct vb_device_info *pVBInfo)
1502{
1503 unsigned short data, data2 = 0;
1504 short VCLK;
1505
1506 unsigned char index;
1507
1508 if (ModeNo <= 0x13)
1509 VCLK = 0;
1510 else {
1511 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1512 index &= IndexMask;
1513 VCLK = pVBInfo->VCLKData[index].CLOCK;
1514 }
1515
Aaro Koskinen58839b02011-03-13 12:26:23 +02001516 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001517 data &= 0xf3;
1518 if (VCLK >= 200)
1519 data |= 0x0c; /* VCLK > 200 */
1520
1521 if (HwDeviceExtension->jChipType >= XG20)
1522 data &= ~0x04; /* 2 pixel mode */
1523
Aaro Koskinen8104e322011-03-13 12:26:22 +02001524 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001525
1526 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001527 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001528 data &= 0xE7;
1529 if (VCLK < 200)
1530 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001531 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001532 }
1533
1534 /* Jong for Adavantech LCD ripple issue
1535 if ((VCLK >= 0) && (VCLK < 135))
1536 data2 = 0x03;
1537 else if ((VCLK >= 135) && (VCLK < 160))
1538 data2 = 0x02;
1539 else if ((VCLK >= 160) && (VCLK < 260))
1540 data2 = 0x01;
1541 else if (VCLK > 260)
1542 data2 = 0x00;
1543 */
1544 data2 = 0x00;
1545
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001546 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001547 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001548 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001549
1550}
1551
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001552static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301553 unsigned short ModeNo, unsigned short ModeIdIndex,
1554 unsigned short RefreshRateTableIndex,
1555 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001556{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301557 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1558 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001559
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301560 if (ModeNo > 0x13) {
1561 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001562 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].
1563 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301564 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001565 /* si+St_ModeFlag */
1566 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001567
Aaro Koskinen58839b02011-03-13 12:26:23 +02001568 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001569 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001570
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301571 if (ModeNo > 0x13)
1572 data = infoflag;
1573 else
1574 data = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001575
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301576 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001577
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301578 if (ModeNo > 0x13) {
1579 if (pVBInfo->ModeType > 0x02) {
1580 data2 |= 0x02;
1581 data3 = pVBInfo->ModeType - ModeVGA;
1582 data3 = data3 << 2;
1583 data2 |= data3;
1584 }
1585 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001586
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301587 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001588
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301589 if (data)
1590 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001591
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001592 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001593 /* xgifb_reg_set(pVBInfo->P3c4,0x06,data2); */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301594 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
1595 if (ModeNo <= 0x13)
1596 xres = pVBInfo->StResInfo[resindex].HTotal;
1597 else
1598 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001599
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301600 data = 0x0000;
1601 if (infoflag & InterlaceMode) {
1602 if (xres == 1024)
1603 data = 0x0035;
1604 else if (xres == 1280)
1605 data = 0x0048;
1606 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001607
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301608 data2 = data & 0x00FF;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001609 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301610 data2 = (data & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001611 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001612
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301613 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001614 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001615
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301616 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001617
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301618 if (modeflag & LineCompareOff)
1619 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001620
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301621 if (ModeNo > 0x13) {
1622 if (pVBInfo->ModeType == ModeEGA)
1623 data2 |= 0x40;
1624 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001625
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001626 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301627 data = 0x60;
1628 if (pVBInfo->ModeType != ModeText) {
1629 data = data ^ 0x60;
1630 if (pVBInfo->ModeType != ModeEGA)
1631 data = data ^ 0xA0;
1632 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001633 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001634
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301635 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1636 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001637
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301638 /* if (modeflag&HalfDCLK) //030305 fix lowresolution bug */
1639 /* if (XGINew_IF_DEF_NEW_LOWRES) */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001640 /* XGI_VesaLowResolution(ModeNo, ModeIdIndex);
1641 * //030305 fix lowresolution bug */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001642
Aaro Koskinen58839b02011-03-13 12:26:23 +02001643 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001644
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301645 if (HwDeviceExtension->jChipType == XG27) {
1646 if (data & 0x40)
1647 data = 0x2c;
1648 else
1649 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001650 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001651 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301652 } else if (HwDeviceExtension->jChipType >= XG20) {
1653 if (data & 0x40)
1654 data = 0x33;
1655 else
1656 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001657 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1658 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301659 } else {
1660 if (data & 0x40)
1661 data = 0x2c;
1662 else
1663 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001664 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301665 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001666
1667}
1668
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001669static void XGI_WriteDAC(unsigned short dl,
1670 unsigned short ah,
1671 unsigned short al,
1672 unsigned short dh,
1673 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001674{
1675 unsigned short temp, bh, bl;
1676
1677 bh = ah;
1678 bl = al;
1679
1680 if (dl != 0) {
1681 temp = bh;
1682 bh = dh;
1683 dh = temp;
1684 if (dl == 1) {
1685 temp = bl;
1686 bl = dh;
1687 dh = temp;
1688 } else {
1689 temp = bl;
1690 bl = bh;
1691 bh = temp;
1692 }
1693 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001694 outb((unsigned short) dh, pVBInfo->P3c9);
1695 outb((unsigned short) bh, pVBInfo->P3c9);
1696 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001697}
1698
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001699static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301700 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001701{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301702 unsigned short data, data2, time, i, j, k, m, n, o, si, di, bx, dl, al,
1703 ah, dh, *table = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001704
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301705 if (ModeNo <= 0x13)
1706 data = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1707 else
1708 data = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001709
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301710 data &= DACInfoFlag;
1711 time = 64;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001712
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301713 if (data == 0x00)
1714 table = XGINew_MDA_DAC;
1715 else if (data == 0x08)
1716 table = XGINew_CGA_DAC;
1717 else if (data == 0x10)
1718 table = XGINew_EGA_DAC;
1719 else if (data == 0x18) {
1720 time = 256;
1721 table = XGINew_VGA_DAC;
1722 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001723
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301724 if (time == 256)
1725 j = 16;
1726 else
1727 j = time;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001728
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001729 outb(0xFF, pVBInfo->P3c6);
1730 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001731
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301732 for (i = 0; i < j; i++) {
1733 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001734
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301735 for (k = 0; k < 3; k++) {
1736 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001737
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301738 if (data & 0x01)
1739 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001740
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301741 if (data & 0x02)
1742 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001743
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001744 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301745 data = data >> 2;
1746 }
1747 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001748
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301749 if (time == 256) {
1750 for (i = 16; i < 32; i++) {
1751 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001752
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301753 for (k = 0; k < 3; k++)
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001754 outb(data, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301755 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001756
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301757 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001758
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301759 for (m = 0; m < 9; m++) {
1760 di = si;
1761 bx = si + 0x04;
1762 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001763
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301764 for (n = 0; n < 3; n++) {
1765 for (o = 0; o < 5; o++) {
1766 dh = table[si];
1767 ah = table[di];
1768 al = table[bx];
1769 si++;
1770 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1771 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001772
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301773 si -= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001774
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301775 for (o = 0; o < 3; o++) {
1776 dh = table[bx];
1777 ah = table[di];
1778 al = table[si];
1779 si--;
1780 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1781 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001782
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301783 dl++;
1784 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001785
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301786 si += 5;
1787 }
1788 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001789}
1790
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001791static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1792 unsigned short ModeIdIndex,
1793 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001794{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301795 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301797 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001798 /* si+St_ResInfo */
1799 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301800 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001801 /* si+Ext_ResInfo */
1802 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001803
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301804 /* if (ModeNo > 0x13) */
1805 /* modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag; */
1806 /* else */
1807 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001808
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301809 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001810 /* si+St_ResInfo */
1811 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301812 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001813 /* si+Ext_ResInfo */
1814 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001815
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301816 /* resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001817
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301818 if (ModeNo <= 0x13) {
1819 xres = pVBInfo->StResInfo[resindex].HTotal;
1820 yres = pVBInfo->StResInfo[resindex].VTotal;
1821 } else {
1822 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1823 yres = pVBInfo->ModeResInfo[resindex].VTotal;
1824 }
1825 if (ModeNo > 0x13) {
1826 if (modeflag & HalfDCLK)
1827 xres = xres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001828
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301829 if (modeflag & DoubleScanMode)
1830 yres = yres << 1;
1831 }
1832 /* if (modeflag & Charx8Dot) */
1833 /* { */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001834
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301835 if (xres == 720)
1836 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001837
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301838 /* } */
1839 pVBInfo->VGAHDE = xres;
1840 pVBInfo->HDE = xres;
1841 pVBInfo->VGAVDE = yres;
1842 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001843}
1844
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001845static void *XGI_GetLcdPtr(unsigned short BX, unsigned short ModeNo,
1846 unsigned short ModeIdIndex,
1847 unsigned short RefreshRateTableIndex,
1848 struct vb_device_info *pVBInfo)
1849{
1850 unsigned short i, tempdx, tempcx, tempbx, tempal, modeflag, table;
1851
1852 struct XGI330_LCDDataTablStruct *tempdi = NULL;
1853
1854 tempbx = BX;
1855
1856 if (ModeNo <= 0x13) {
1857 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1858 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1859 } else {
1860 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1861 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1862 }
1863
1864 tempal = tempal & 0x0f;
1865
1866 if (tempbx <= 1) { /* ExpLink */
1867 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001868 /* find no Ext_CRT2CRTC2 */
1869 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001870 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001871 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].
1872 Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001873 }
1874
1875 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
1876 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001877 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
1878 St_CRT2CRTC2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001879 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001880 tempal = pVBInfo->RefIndex[
1881 RefreshRateTableIndex].
1882 Ext_CRT2CRTC2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001883 }
1884
1885 if (tempbx & 0x01)
1886 tempal = (tempal >> 4);
1887
1888 tempal = (tempal & 0x0f);
1889 }
1890
1891 tempcx = LCDLenList[tempbx]; /* mov cl,byte ptr cs:LCDLenList[bx] */
1892
1893 if (pVBInfo->LCDInfo & EnableScalingLCD) { /* ScaleLCD */
1894 if ((tempbx == 5) || (tempbx) == 7)
1895 tempcx = LCDDesDataLen2;
1896 else if ((tempbx == 3) || (tempbx == 8))
1897 tempcx = LVDSDesDataLen2;
1898 }
1899 /* mov di, word ptr cs:LCDDataList[bx] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001900 /* tempdi = pVideoMemory[LCDDataList + tempbx * 2] |
1901 (pVideoMemory[LCDDataList + tempbx * 2 + 1] << 8); */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001902
1903 switch (tempbx) {
1904 case 0:
1905 tempdi = XGI_EPLLCDCRT1Ptr_H;
1906 break;
1907 case 1:
1908 tempdi = XGI_EPLLCDCRT1Ptr_V;
1909 break;
1910 case 2:
1911 tempdi = XGI_EPLLCDDataPtr;
1912 break;
1913 case 3:
1914 tempdi = XGI_EPLLCDDesDataPtr;
1915 break;
1916 case 4:
1917 tempdi = XGI_LCDDataTable;
1918 break;
1919 case 5:
1920 tempdi = XGI_LCDDesDataTable;
1921 break;
1922 case 6:
1923 tempdi = XGI_EPLCHLCDRegPtr;
1924 break;
1925 case 7:
1926 case 8:
1927 case 9:
1928 tempdi = NULL;
1929 break;
1930 default:
1931 break;
1932 }
1933
1934 if (tempdi == NULL) /* OEMUtil */
1935 return NULL;
1936
1937 table = tempbx;
1938 i = 0;
1939
1940 while (tempdi[i].PANELID != 0xff) {
1941 tempdx = pVBInfo->LCDResInfo;
1942 if (tempbx & 0x0080) { /* OEMUtil */
1943 tempbx &= (~0x0080);
1944 tempdx = pVBInfo->LCDTypeInfo;
1945 }
1946
1947 if (pVBInfo->LCDInfo & EnableScalingLCD)
1948 tempdx &= (~PanelResInfo);
1949
1950 if (tempdi[i].PANELID == tempdx) {
1951 tempbx = tempdi[i].MASK;
1952 tempdx = pVBInfo->LCDInfo;
1953
1954 if (ModeNo <= 0x13) /* alan 09/10/2003 */
1955 tempdx |= SetLCDStdMode;
1956
1957 if (modeflag & HalfDCLK)
1958 tempdx |= SetLCDLowResolution;
1959
1960 tempbx &= tempdx;
1961 if (tempbx == tempdi[i].CAP)
1962 break;
1963 }
1964 i++;
1965 }
1966
1967 if (table == 0) {
1968 switch (tempdi[i].DATAPTR) {
1969 case 0:
1970 return &XGI_LVDSCRT11024x768_1_H[tempal];
1971 break;
1972 case 1:
1973 return &XGI_LVDSCRT11024x768_2_H[tempal];
1974 break;
1975 case 2:
1976 return &XGI_LVDSCRT11280x1024_1_H[tempal];
1977 break;
1978 case 3:
1979 return &XGI_LVDSCRT11280x1024_2_H[tempal];
1980 break;
1981 case 4:
1982 return &XGI_LVDSCRT11400x1050_1_H[tempal];
1983 break;
1984 case 5:
1985 return &XGI_LVDSCRT11400x1050_2_H[tempal];
1986 break;
1987 case 6:
1988 return &XGI_LVDSCRT11600x1200_1_H[tempal];
1989 break;
1990 case 7:
1991 return &XGI_LVDSCRT11024x768_1_Hx75[tempal];
1992 break;
1993 case 8:
1994 return &XGI_LVDSCRT11024x768_2_Hx75[tempal];
1995 break;
1996 case 9:
1997 return &XGI_LVDSCRT11280x1024_1_Hx75[tempal];
1998 break;
1999 case 10:
2000 return &XGI_LVDSCRT11280x1024_2_Hx75[tempal];
2001 break;
2002 default:
2003 break;
2004 }
2005 } else if (table == 1) {
2006 switch (tempdi[i].DATAPTR) {
2007 case 0:
2008 return &XGI_LVDSCRT11024x768_1_V[tempal];
2009 break;
2010 case 1:
2011 return &XGI_LVDSCRT11024x768_2_V[tempal];
2012 break;
2013 case 2:
2014 return &XGI_LVDSCRT11280x1024_1_V[tempal];
2015 break;
2016 case 3:
2017 return &XGI_LVDSCRT11280x1024_2_V[tempal];
2018 break;
2019 case 4:
2020 return &XGI_LVDSCRT11400x1050_1_V[tempal];
2021 break;
2022 case 5:
2023 return &XGI_LVDSCRT11400x1050_2_V[tempal];
2024 break;
2025 case 6:
2026 return &XGI_LVDSCRT11600x1200_1_V[tempal];
2027 break;
2028 case 7:
2029 return &XGI_LVDSCRT11024x768_1_Vx75[tempal];
2030 break;
2031 case 8:
2032 return &XGI_LVDSCRT11024x768_2_Vx75[tempal];
2033 break;
2034 case 9:
2035 return &XGI_LVDSCRT11280x1024_1_Vx75[tempal];
2036 break;
2037 case 10:
2038 return &XGI_LVDSCRT11280x1024_2_Vx75[tempal];
2039 break;
2040 default:
2041 break;
2042 }
2043 } else if (table == 2) {
2044 switch (tempdi[i].DATAPTR) {
2045 case 0:
2046 return &XGI_LVDS1024x768Data_1[tempal];
2047 break;
2048 case 1:
2049 return &XGI_LVDS1024x768Data_2[tempal];
2050 break;
2051 case 2:
2052 return &XGI_LVDS1280x1024Data_1[tempal];
2053 break;
2054 case 3:
2055 return &XGI_LVDS1280x1024Data_2[tempal];
2056 break;
2057 case 4:
2058 return &XGI_LVDS1400x1050Data_1[tempal];
2059 break;
2060 case 5:
2061 return &XGI_LVDS1400x1050Data_2[tempal];
2062 break;
2063 case 6:
2064 return &XGI_LVDS1600x1200Data_1[tempal];
2065 break;
2066 case 7:
2067 return &XGI_LVDSNoScalingData[tempal];
2068 break;
2069 case 8:
2070 return &XGI_LVDS1024x768Data_1x75[tempal];
2071 break;
2072 case 9:
2073 return &XGI_LVDS1024x768Data_2x75[tempal];
2074 break;
2075 case 10:
2076 return &XGI_LVDS1280x1024Data_1x75[tempal];
2077 break;
2078 case 11:
2079 return &XGI_LVDS1280x1024Data_2x75[tempal];
2080 break;
2081 case 12:
2082 return &XGI_LVDSNoScalingDatax75[tempal];
2083 break;
2084 default:
2085 break;
2086 }
2087 } else if (table == 3) {
2088 switch (tempdi[i].DATAPTR) {
2089 case 0:
2090 return &XGI_LVDS1024x768Des_1[tempal];
2091 break;
2092 case 1:
2093 return &XGI_LVDS1024x768Des_3[tempal];
2094 break;
2095 case 2:
2096 return &XGI_LVDS1024x768Des_2[tempal];
2097 break;
2098 case 3:
2099 return &XGI_LVDS1280x1024Des_1[tempal];
2100 break;
2101 case 4:
2102 return &XGI_LVDS1280x1024Des_2[tempal];
2103 break;
2104 case 5:
2105 return &XGI_LVDS1400x1050Des_1[tempal];
2106 break;
2107 case 6:
2108 return &XGI_LVDS1400x1050Des_2[tempal];
2109 break;
2110 case 7:
2111 return &XGI_LVDS1600x1200Des_1[tempal];
2112 break;
2113 case 8:
2114 return &XGI_LVDSNoScalingDesData[tempal];
2115 break;
2116 case 9:
2117 return &XGI_LVDS1024x768Des_1x75[tempal];
2118 break;
2119 case 10:
2120 return &XGI_LVDS1024x768Des_3x75[tempal];
2121 break;
2122 case 11:
2123 return &XGI_LVDS1024x768Des_2x75[tempal];
2124 break;
2125 case 12:
2126 return &XGI_LVDS1280x1024Des_1x75[tempal];
2127 break;
2128 case 13:
2129 return &XGI_LVDS1280x1024Des_2x75[tempal];
2130 break;
2131 case 14:
2132 return &XGI_LVDSNoScalingDesDatax75[tempal];
2133 break;
2134 default:
2135 break;
2136 }
2137 } else if (table == 4) {
2138 switch (tempdi[i].DATAPTR) {
2139 case 0:
2140 return &XGI_ExtLCD1024x768Data[tempal];
2141 break;
2142 case 1:
2143 return &XGI_StLCD1024x768Data[tempal];
2144 break;
2145 case 2:
2146 return &XGI_CetLCD1024x768Data[tempal];
2147 break;
2148 case 3:
2149 return &XGI_ExtLCD1280x1024Data[tempal];
2150 break;
2151 case 4:
2152 return &XGI_StLCD1280x1024Data[tempal];
2153 break;
2154 case 5:
2155 return &XGI_CetLCD1280x1024Data[tempal];
2156 break;
2157 case 6:
2158 return &XGI_ExtLCD1400x1050Data[tempal];
2159 break;
2160 case 7:
2161 return &XGI_StLCD1400x1050Data[tempal];
2162 break;
2163 case 8:
2164 return &XGI_CetLCD1400x1050Data[tempal];
2165 break;
2166 case 9:
2167 return &XGI_ExtLCD1600x1200Data[tempal];
2168 break;
2169 case 10:
2170 return &XGI_StLCD1600x1200Data[tempal];
2171 break;
2172 case 11:
2173 return &XGI_NoScalingData[tempal];
2174 break;
2175 case 12:
2176 return &XGI_ExtLCD1024x768x75Data[tempal];
2177 break;
2178 case 13:
2179 return &XGI_ExtLCD1024x768x75Data[tempal];
2180 break;
2181 case 14:
2182 return &XGI_CetLCD1024x768x75Data[tempal];
2183 break;
2184 case 15:
2185 return &XGI_ExtLCD1280x1024x75Data[tempal];
2186 break;
2187 case 16:
2188 return &XGI_StLCD1280x1024x75Data[tempal];
2189 break;
2190 case 17:
2191 return &XGI_CetLCD1280x1024x75Data[tempal];
2192 break;
2193 case 18:
2194 return &XGI_NoScalingDatax75[tempal];
2195 break;
2196 default:
2197 break;
2198 }
2199 } else if (table == 5) {
2200 switch (tempdi[i].DATAPTR) {
2201 case 0:
2202 return &XGI_ExtLCDDes1024x768Data[tempal];
2203 break;
2204 case 1:
2205 return &XGI_StLCDDes1024x768Data[tempal];
2206 break;
2207 case 2:
2208 return &XGI_CetLCDDes1024x768Data[tempal];
2209 break;
2210 case 3:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002211 if ((pVBInfo->VBType & VB_XGI301LV) ||
2212 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002213 return &XGI_ExtLCDDLDes1280x1024Data[tempal];
2214 else
2215 return &XGI_ExtLCDDes1280x1024Data[tempal];
2216 break;
2217 case 4:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002218 if ((pVBInfo->VBType & VB_XGI301LV) ||
2219 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002220 return &XGI_StLCDDLDes1280x1024Data[tempal];
2221 else
2222 return &XGI_StLCDDes1280x1024Data[tempal];
2223 break;
2224 case 5:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002225 if ((pVBInfo->VBType & VB_XGI301LV) ||
2226 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002227 return &XGI_CetLCDDLDes1280x1024Data[tempal];
2228 else
2229 return &XGI_CetLCDDes1280x1024Data[tempal];
2230 break;
2231 case 6:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002232 if ((pVBInfo->VBType & VB_XGI301LV) ||
2233 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002234 return &XGI_ExtLCDDLDes1400x1050Data[tempal];
2235 else
2236 return &XGI_ExtLCDDes1400x1050Data[tempal];
2237 break;
2238 case 7:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002239 if ((pVBInfo->VBType & VB_XGI301LV) ||
2240 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002241 return &XGI_StLCDDLDes1400x1050Data[tempal];
2242 else
2243 return &XGI_StLCDDes1400x1050Data[tempal];
2244 break;
2245 case 8:
2246 return &XGI_CetLCDDes1400x1050Data[tempal];
2247 break;
2248 case 9:
2249 return &XGI_CetLCDDes1400x1050Data2[tempal];
2250 break;
2251 case 10:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002252 if ((pVBInfo->VBType & VB_XGI301LV) ||
2253 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002254 return &XGI_ExtLCDDLDes1600x1200Data[tempal];
2255 else
2256 return &XGI_ExtLCDDes1600x1200Data[tempal];
2257 break;
2258 case 11:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002259 if ((pVBInfo->VBType & VB_XGI301LV) ||
2260 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002261 return &XGI_StLCDDLDes1600x1200Data[tempal];
2262 else
2263 return &XGI_StLCDDes1600x1200Data[tempal];
2264 break;
2265 case 12:
2266 return &XGI_NoScalingDesData[tempal];
2267 break;
2268 case 13:
2269 return &XGI_ExtLCDDes1024x768x75Data[tempal];
2270 break;
2271 case 14:
2272 return &XGI_StLCDDes1024x768x75Data[tempal];
2273 break;
2274 case 15:
2275 return &XGI_CetLCDDes1024x768x75Data[tempal];
2276 break;
2277 case 16:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002278 if ((pVBInfo->VBType & VB_XGI301LV) ||
2279 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002280 return &XGI_ExtLCDDLDes1280x1024x75Data[tempal];
2281 else
2282 return &XGI_ExtLCDDes1280x1024x75Data[tempal];
2283 break;
2284 case 17:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002285 if ((pVBInfo->VBType & VB_XGI301LV) ||
2286 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002287 return &XGI_StLCDDLDes1280x1024x75Data[tempal];
2288 else
2289 return &XGI_StLCDDes1280x1024x75Data[tempal];
2290 break;
2291 case 18:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002292 if ((pVBInfo->VBType & VB_XGI301LV) ||
2293 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002294 return &XGI_CetLCDDLDes1280x1024x75Data[tempal];
2295 else
2296 return &XGI_CetLCDDes1280x1024x75Data[tempal];
2297 break;
2298 case 19:
2299 return &XGI_NoScalingDesDatax75[tempal];
2300 break;
2301 default:
2302 break;
2303 }
2304 } else if (table == 6) {
2305 switch (tempdi[i].DATAPTR) {
2306 case 0:
2307 return &XGI_CH7017LV1024x768[tempal];
2308 break;
2309 case 1:
2310 return &XGI_CH7017LV1400x1050[tempal];
2311 break;
2312 default:
2313 break;
2314 }
2315 }
2316 return NULL;
2317}
2318
2319static void *XGI_GetTVPtr(unsigned short BX, unsigned short ModeNo,
2320 unsigned short ModeIdIndex,
2321 unsigned short RefreshRateTableIndex,
2322 struct vb_device_info *pVBInfo)
2323{
2324 unsigned short i, tempdx, tempbx, tempal, modeflag, table;
2325 struct XGI330_TVDataTablStruct *tempdi = NULL;
2326
2327 tempbx = BX;
2328
2329 if (ModeNo <= 0x13) {
2330 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2331 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2332 } else {
2333 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2334 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2335 }
2336
2337 tempal = tempal & 0x3f;
2338 table = tempbx;
2339
2340 switch (tempbx) {
2341 case 0:
2342 tempdi = NULL; /*EPLCHTVCRT1Ptr_H;*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002343 break;
2344 case 1:
2345 tempdi = NULL; /*EPLCHTVCRT1Ptr_V;*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002346 break;
2347 case 2:
2348 tempdi = XGI_EPLCHTVDataPtr;
2349 break;
2350 case 3:
2351 tempdi = NULL;
2352 break;
2353 case 4:
2354 tempdi = XGI_TVDataTable;
2355 break;
2356 case 5:
2357 tempdi = NULL;
2358 break;
2359 case 6:
2360 tempdi = XGI_EPLCHTVRegPtr;
2361 break;
2362 default:
2363 break;
2364 }
2365
2366 if (tempdi == NULL) /* OEMUtil */
2367 return NULL;
2368
2369 tempdx = pVBInfo->TVInfo;
2370
2371 if (pVBInfo->VBInfo & SetInSlaveMode)
2372 tempdx = tempdx | SetTVLockMode;
2373
2374 if (modeflag & HalfDCLK)
2375 tempdx = tempdx | SetTVLowResolution;
2376
2377 i = 0;
2378
2379 while (tempdi[i].MASK != 0xffff) {
2380 if ((tempdx & tempdi[i].MASK) == tempdi[i].CAP)
2381 break;
2382 i++;
2383 }
2384
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002385 /* 07/05/22 */
2386 if (table == 0x00) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002387 } else if (table == 0x01) {
2388 } else if (table == 0x04) {
2389 switch (tempdi[i].DATAPTR) {
2390 case 0:
2391 return &XGI_ExtPALData[tempal];
2392 break;
2393 case 1:
2394 return &XGI_ExtNTSCData[tempal];
2395 break;
2396 case 2:
2397 return &XGI_StPALData[tempal];
2398 break;
2399 case 3:
2400 return &XGI_StNTSCData[tempal];
2401 break;
2402 case 4:
2403 return &XGI_ExtHiTVData[tempal];
2404 break;
2405 case 5:
2406 return &XGI_St2HiTVData[tempal];
2407 break;
2408 case 6:
2409 return &XGI_ExtYPbPr525iData[tempal];
2410 break;
2411 case 7:
2412 return &XGI_ExtYPbPr525pData[tempal];
2413 break;
2414 case 8:
2415 return &XGI_ExtYPbPr750pData[tempal];
2416 break;
2417 case 9:
2418 return &XGI_StYPbPr525iData[tempal];
2419 break;
2420 case 10:
2421 return &XGI_StYPbPr525pData[tempal];
2422 break;
2423 case 11:
2424 return &XGI_StYPbPr750pData[tempal];
2425 break;
2426 case 12: /* avoid system hang */
2427 return &XGI_ExtNTSCData[tempal];
2428 break;
2429 case 13:
2430 return &XGI_St1HiTVData[tempal];
2431 break;
2432 default:
2433 break;
2434 }
2435 } else if (table == 0x02) {
2436 switch (tempdi[i].DATAPTR) {
2437 case 0:
2438 return &XGI_CHTVUNTSCData[tempal];
2439 break;
2440 case 1:
2441 return &XGI_CHTVONTSCData[tempal];
2442 break;
2443 case 2:
2444 return &XGI_CHTVUPALData[tempal];
2445 break;
2446 case 3:
2447 return &XGI_CHTVOPALData[tempal];
2448 break;
2449 default:
2450 break;
2451 }
2452 } else if (table == 0x06) {
2453 }
2454 return NULL;
2455}
2456
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002457static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302458 unsigned short RefreshRateTableIndex,
2459 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002460{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302461 unsigned short tempbx;
2462 struct XGI330_LVDSDataStruct *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002463
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302464 tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002465
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302466 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2467 LCDPtr = (struct XGI330_LVDSDataStruct *) XGI_GetLcdPtr(tempbx,
2468 ModeNo, ModeIdIndex, RefreshRateTableIndex,
2469 pVBInfo);
2470 pVBInfo->VGAHT = LCDPtr->VGAHT;
2471 pVBInfo->VGAVT = LCDPtr->VGAVT;
2472 pVBInfo->HT = LCDPtr->LCDHT;
2473 pVBInfo->VT = LCDPtr->LCDVT;
2474 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002475
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302476 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2477 if (!(pVBInfo->LCDInfo & (SetLCDtoNonExpanding
2478 | EnableScalingLCD))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002479 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2480 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302481 pVBInfo->HDE = 1024;
2482 pVBInfo->VDE = 768;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002483 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2484 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302485 pVBInfo->HDE = 1280;
2486 pVBInfo->VDE = 1024;
2487 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2488 pVBInfo->HDE = 1400;
2489 pVBInfo->VDE = 1050;
2490 } else {
2491 pVBInfo->HDE = 1600;
2492 pVBInfo->VDE = 1200;
2493 }
2494 }
2495 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002496}
2497
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002498static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302499 unsigned short RefreshRateTableIndex,
2500 struct xgi_hw_device_info *HwDeviceExtension,
2501 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002502{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302503 unsigned char index;
2504 unsigned short tempbx, i;
2505 struct XGI_LVDSCRT1HDataStruct *LCDPtr = NULL;
2506 struct XGI_LVDSCRT1VDataStruct *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002507
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302508 if (ModeNo <= 0x13)
2509 index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2510 else
2511 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002512
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302513 index = index & IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002514
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002515 if ((pVBInfo->IF_DEF_ScaleLCD == 0) ||
2516 ((pVBInfo->IF_DEF_ScaleLCD == 1) &&
2517 (!(pVBInfo->LCDInfo & EnableScalingLCD)))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302518 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002519
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302520 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002521 LCDPtr = (struct XGI_LVDSCRT1HDataStruct *)
2522 XGI_GetLcdPtr(tempbx, ModeNo,
2523 ModeIdIndex,
2524 RefreshRateTableIndex,
2525 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002526
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302527 for (i = 0; i < 8; i++)
2528 pVBInfo->TimingH[0].data[i] = LCDPtr[0].Reg[i];
2529 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002530
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302531 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002532
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302533 tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002534
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302535 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002536 LCDPtr1 = (struct XGI_LVDSCRT1VDataStruct *)
2537 XGI_GetLcdPtr(
2538 tempbx,
2539 ModeNo,
2540 ModeIdIndex,
2541 RefreshRateTableIndex,
2542 pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302543 for (i = 0; i < 7; i++)
2544 pVBInfo->TimingV[0].data[i] = LCDPtr1[0].Reg[i];
2545 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002546
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302547 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302548 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002549}
2550
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002551static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
2552{
2553 unsigned char tempal, tempah, tempbl, i;
2554
Aaro Koskinen58839b02011-03-13 12:26:23 +02002555 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002556 tempal = tempah & 0x0F;
2557 tempah = tempah & 0xF0;
2558 i = 0;
2559 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2560
2561 while (tempbl != 0xFF) {
2562 if (tempbl & 0x80) { /* OEMUtil */
2563 tempal = tempah;
2564 tempbl = tempbl & ~(0x80);
2565 }
2566
2567 if (tempal == tempbl)
2568 break;
2569
2570 i++;
2571
2572 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2573 }
2574
2575 return i;
2576}
2577
2578static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
2579{
2580 unsigned short tempah, tempal, tempbl, i;
2581
2582 tempal = pVBInfo->LCDResInfo;
2583 tempah = pVBInfo->LCDTypeInfo;
2584
2585 i = 0;
2586 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2587
2588 while (tempbl != 0xFF) {
2589 if ((tempbl & 0x80) && (tempbl != 0x80)) {
2590 tempal = tempah;
2591 tempbl &= ~0x80;
2592 }
2593
2594 if (tempal == tempbl)
2595 break;
2596
2597 i++;
2598 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2599 }
2600
2601 if (tempbl == 0xFF) {
2602 pVBInfo->LCDResInfo = Panel1024x768;
2603 pVBInfo->LCDTypeInfo = 0;
2604 i = 0;
2605 }
2606
2607 return i;
2608}
2609
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002610static void XGI_GetLCDSync(unsigned short *HSyncWidth,
2611 unsigned short *VSyncWidth,
2612 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002613{
2614 unsigned short Index;
2615
2616 Index = XGI_GetLCDCapPtr(pVBInfo);
2617 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
2618 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
2619
2620 return;
2621}
2622
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002623static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302624 unsigned short RefreshRateTableIndex,
2625 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002626{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302627 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
2628 unsigned long temp, temp1, temp2, temp3, push3;
2629 struct XGI330_LCDDataDesStruct *LCDPtr = NULL;
2630 struct XGI330_LCDDataDesStruct2 *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002631
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302632 if (ModeNo > 0x13)
2633 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2634 else
2635 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002636
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302637 if (!(pVBInfo->SetFlag & Win9xDOSMode)) {
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002638 if (pVBInfo->IF_DEF_OEMUtil == 1) {
2639 tempbx = 8;
2640 LCDPtr = (struct XGI330_LCDDataDesStruct *)
2641 XGI_GetLcdPtr(tempbx,
2642 ModeNo,
2643 ModeIdIndex,
2644 RefreshRateTableIndex,
2645 pVBInfo);
2646 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002647
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002648 if ((pVBInfo->IF_DEF_OEMUtil == 0) ||
2649 (LCDPtr == NULL)) {
2650 tempbx = 3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302651 if (pVBInfo->LCDInfo & EnableScalingLCD)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002652 LCDPtr1 =
2653 (struct XGI330_LCDDataDesStruct2 *)
2654 XGI_GetLcdPtr(
2655 tempbx,
2656 ModeNo,
2657 ModeIdIndex,
2658 RefreshRateTableIndex,
2659 pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302660 else
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002661 LCDPtr =
2662 (struct XGI330_LCDDataDesStruct *)
2663 XGI_GetLcdPtr(
2664 tempbx,
2665 ModeNo,
2666 ModeIdIndex,
2667 RefreshRateTableIndex,
2668 pVBInfo);
2669 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002670
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002671 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
2672 push1 = tempbx;
2673 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002674
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002675 /* GetLCDResInfo */
2676 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2677 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
2678 tempax = 1024;
2679 tempbx = 768;
2680 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2681 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
2682 tempax = 1280;
2683 tempbx = 1024;
2684 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2685 tempax = 1400;
2686 tempbx = 1050;
2687 } else {
2688 tempax = 1600;
2689 tempbx = 1200;
2690 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002691
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002692 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
2693 pVBInfo->HDE = tempax;
2694 pVBInfo->VDE = tempbx;
2695 pVBInfo->VGAHDE = tempax;
2696 pVBInfo->VGAVDE = tempbx;
2697 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002698
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002699 if ((pVBInfo->IF_DEF_ScaleLCD == 1) &&
2700 (pVBInfo->LCDInfo & EnableScalingLCD)) {
2701 tempax = pVBInfo->HDE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302702 tempbx = pVBInfo->VDE;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002703 }
2704
2705 tempax = pVBInfo->HT;
2706
2707 if (pVBInfo->LCDInfo & EnableScalingLCD)
2708 tempbx = LCDPtr1->LCDHDES;
2709 else
2710 tempbx = LCDPtr->LCDHDES;
2711
2712 tempcx = pVBInfo->HDE;
2713 tempbx = tempbx & 0x0fff;
2714 tempcx += tempbx;
2715
2716 if (tempcx >= tempax)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302717 tempcx -= tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002718
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002719 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002720
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002721 tempcx = tempcx >> 3;
2722 tempbx = tempbx >> 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002723
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002724 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
2725 (unsigned short) (tempbx & 0xff));
2726 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
2727 (unsigned short) (tempcx & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002728
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002729 tempax = pVBInfo->HT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002730
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002731 if (pVBInfo->LCDInfo & EnableScalingLCD)
2732 tempbx = LCDPtr1->LCDHRS;
2733 else
2734 tempbx = LCDPtr->LCDHRS;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002735
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002736 tempcx = push2;
2737
2738 if (pVBInfo->LCDInfo & EnableScalingLCD)
2739 tempcx = LCDPtr1->LCDHSync;
2740
2741 tempcx += tempbx;
2742
2743 if (tempcx >= tempax)
2744 tempcx -= tempax;
2745
2746 tempax = tempbx & 0x07;
2747 tempax = tempax >> 5;
2748 tempcx = tempcx >> 3;
2749 tempbx = tempbx >> 3;
2750
2751 tempcx &= 0x1f;
2752 tempax |= tempcx;
2753
2754 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
2755 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
2756 (unsigned short) (tempbx & 0xff));
2757
2758 tempax = pVBInfo->VT;
2759 if (pVBInfo->LCDInfo & EnableScalingLCD)
2760 tempbx = LCDPtr1->LCDVDES;
2761 else
2762 tempbx = LCDPtr->LCDVDES;
2763 tempcx = pVBInfo->VDE;
2764
2765 tempbx = tempbx & 0x0fff;
2766 tempcx += tempbx;
2767 if (tempcx >= tempax)
2768 tempcx -= tempax;
2769
2770 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
2771 (unsigned short) (tempbx & 0xff));
2772 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
2773 (unsigned short) (tempcx & 0xff));
2774
2775 tempbx = (tempbx >> 8) & 0x07;
2776 tempcx = (tempcx >> 8) & 0x07;
2777
2778 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
2779 (unsigned short) ((tempcx << 3)
2780 | tempbx));
2781
2782 tempax = pVBInfo->VT;
2783 if (pVBInfo->LCDInfo & EnableScalingLCD)
2784 tempbx = LCDPtr1->LCDVRS;
2785 else
2786 tempbx = LCDPtr->LCDVRS;
2787
2788 /* tempbx = tempbx >> 4; */
2789 tempcx = push1;
2790
2791 if (pVBInfo->LCDInfo & EnableScalingLCD)
2792 tempcx = LCDPtr1->LCDVSync;
2793
2794 tempcx += tempbx;
2795 if (tempcx >= tempax)
2796 tempcx -= tempax;
2797
2798 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
2799 (unsigned short) (tempbx & 0xff));
2800 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
2801 (unsigned short) (tempcx & 0x0f));
2802
2803 tempax = ((tempbx >> 8) & 0x07) << 3;
2804
2805 tempbx = pVBInfo->VGAVDE;
2806 if (tempbx != pVBInfo->VDE)
2807 tempax |= 0x40;
2808
2809 if (pVBInfo->LCDInfo & EnableLVDSDDA)
2810 tempax |= 0x40;
2811
2812 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
2813 tempax);
2814
2815 tempcx = pVBInfo->VGAVT;
2816 tempbx = pVBInfo->VDE;
2817 tempax = pVBInfo->VGAVDE;
2818 tempcx -= tempax;
2819
2820 temp = tempax; /* 0430 ylshieh */
2821 temp1 = (temp << 18) / tempbx;
2822
2823 tempdx = (unsigned short) ((temp << 18) % tempbx);
2824
2825 if (tempdx != 0)
2826 temp1 += 1;
2827
2828 temp2 = temp1;
2829 push3 = temp2;
2830
2831 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
2832 (unsigned short) (temp2 & 0xff));
2833 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
2834 (unsigned short) ((temp2 >> 8) & 0xff));
2835
2836 tempbx = (unsigned short) (temp2 >> 16);
2837 tempax = tempbx & 0x03;
2838
2839 tempbx = pVBInfo->VGAVDE;
2840 if (tempbx == pVBInfo->VDE)
2841 tempax |= 0x04;
2842
2843 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
2844
2845 if (pVBInfo->VBType & VB_XGI301C) {
2846 temp2 = push3;
2847 xgifb_reg_set(pVBInfo->Part4Port,
2848 0x3c,
2849 (unsigned short) (temp2 & 0xff));
2850 xgifb_reg_set(pVBInfo->Part4Port,
2851 0x3b,
2852 (unsigned short) ((temp2 >> 8) &
2853 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302854 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002855 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
2856 ~0xc0,
2857 (unsigned short) ((tempbx &
2858 0xff) << 6));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002859
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002860 tempcx = pVBInfo->VGAVDE;
2861 if (tempcx == pVBInfo->VDE)
2862 xgifb_reg_and_or(pVBInfo->Part4Port,
2863 0x30, ~0x0c, 0x00);
2864 else
2865 xgifb_reg_and_or(pVBInfo->Part4Port,
2866 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302867 }
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002868
2869 tempcx = pVBInfo->VGAHDE;
2870 tempbx = pVBInfo->HDE;
2871
2872 temp1 = tempcx << 16;
2873
2874 tempax = (unsigned short) (temp1 / tempbx);
2875
2876 if ((tempbx & 0xffff) == (tempcx & 0xffff))
2877 tempax = 65535;
2878
2879 temp3 = tempax;
2880 temp1 = pVBInfo->VGAHDE << 16;
2881
2882 temp1 /= temp3;
2883 temp3 = temp3 << 16;
2884 temp1 -= 1;
2885
2886 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
2887
2888 tempax = (unsigned short) (temp3 & 0xff);
2889 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
2890
2891 temp1 = pVBInfo->VGAVDE << 18;
2892 temp1 = temp1 / push3;
2893 tempbx = (unsigned short) (temp1 & 0xffff);
2894
2895 if (pVBInfo->LCDResInfo == Panel1024x768)
2896 tempbx -= 1;
2897
2898 tempax = ((tempbx >> 8) & 0xff) << 3;
2899 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
2900 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
2901 (unsigned short) (tempax & 0xff));
2902 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
2903 (unsigned short) (tempbx & 0xff));
2904
2905 temp3 = temp3 >> 16;
2906
2907 if (modeflag & HalfDCLK)
2908 temp3 = temp3 >> 1;
2909
2910 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
2911 (unsigned short) ((temp3 >> 8) & 0xff));
2912 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
2913 (unsigned short) (temp3 & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302914 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002915}
2916
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002917/* --------------------------------------------------------------------- */
2918/* Function : XGI_GETLCDVCLKPtr */
2919/* Input : */
2920/* Output : al -> VCLK Index */
2921/* Description : */
2922/* --------------------------------------------------------------------- */
2923static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
2924 struct vb_device_info *pVBInfo)
2925{
2926 unsigned short index;
2927
2928 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2929 if (pVBInfo->IF_DEF_ScaleLCD == 1) {
2930 if (pVBInfo->LCDInfo & EnableScalingLCD)
2931 return;
2932 }
2933
2934 /* index = XGI_GetLCDCapPtr(pVBInfo); */
2935 index = XGI_GetLCDCapPtr1(pVBInfo);
2936
2937 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
2938 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
2939 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
2940 } else { /* LCDA */
2941 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
2942 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
2943 }
2944 }
2945 return;
2946}
2947
2948static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
2949 unsigned short ModeNo, unsigned short ModeIdIndex,
2950 struct vb_device_info *pVBInfo)
2951{
2952
2953 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002954 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002955
2956 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002957 /* si+St_ResInfo */
2958 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002959 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002960 /* si+Ext_ResInfo */
2961 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002962
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002963 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
2964 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002965 index = XGI_GetLCDCapPtr(pVBInfo);
2966 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
2967
2968 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
2969 return tempal;
2970
2971 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002972 if (pVBInfo->VBType &
2973 (VB_XGI301B |
2974 VB_XGI302B |
2975 VB_XGI301LV |
2976 VB_XGI302LV |
2977 VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002978 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
2979 tempal = HiTVVCLKDIV2;
2980 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2981 tempal = HiTVVCLK;
2982 if (pVBInfo->TVInfo & TVSimuMode) {
2983 tempal = HiTVSimuVCLK;
2984 if (!(modeflag & Charx8Dot))
2985 tempal = HiTVTextVCLK;
2986
2987 }
2988 return tempal;
2989 }
2990
2991 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
2992 tempal = YPbPr750pVCLK;
2993 return tempal;
2994 }
2995
2996 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
2997 tempal = YPbPr525pVCLK;
2998 return tempal;
2999 }
3000
3001 tempal = NTSC1024VCLK;
3002
3003 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
3004 tempal = TVVCLKDIV2;
3005 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
3006 tempal = TVVCLK;
3007 }
3008
3009 if (pVBInfo->VBInfo & SetCRT2ToTV)
3010 return tempal;
3011 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003012 } /* {End of VB} */
3013
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003014 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003015 tempal = tempal >> 2;
3016 tempal &= 0x03;
3017
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003018 /* for Dot8 Scaling LCD */
3019 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003020 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
3021
3022 if (ModeNo <= 0x13)
3023 return tempal;
3024
3025 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
3026 return tempal;
3027}
3028
3029static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
3030 unsigned char *di_1, struct vb_device_info *pVBInfo)
3031{
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003032 if (pVBInfo->VBType & (VB_XGI301 | VB_XGI301B | VB_XGI302B
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003033 | VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
3034 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) && (pVBInfo->SetFlag
3035 & ProgrammingCRT2)) {
3036 *di_0 = (unsigned char) XGI_VBVCLKData[tempal].SR2B;
3037 *di_1 = XGI_VBVCLKData[tempal].SR2C;
3038 }
3039 } else {
3040 *di_0 = XGI_VCLKData[tempal].SR2B;
3041 *di_1 = XGI_VCLKData[tempal].SR2C;
3042 }
3043}
3044
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003045static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303046 unsigned short RefreshRateTableIndex,
3047 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003048{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303049 unsigned char di_0, di_1, tempal;
3050 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303052 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
3053 pVBInfo);
3054 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
3055 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003056
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303057 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003058 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303059 (unsigned short) (0x10 * i));
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003060 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303061 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003062 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
3063 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303064 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003065 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
3066 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303067 }
3068 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003069}
3070
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003071static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303072 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003073{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303074 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003075
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303076 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
3077 | VB_XGI302LV | VB_XGI301C)) {
3078 tempcl = 0;
3079 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003080 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003081
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303082 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003083 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303084 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003085 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303086 if (!(temp & 0x40))
3087 tempcl |= ActiveCRT1;
3088 }
3089 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003090
Aaro Koskinen58839b02011-03-13 12:26:23 +02003091 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303092 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003093
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303094 if (!(temp == 0x08)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003095 /* Check ChannelA by Part1_13 [2003/10/03] */
3096 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303097 if (tempax & 0x04)
3098 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003099
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303100 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003101
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303102 if (!(tempcl & ActiveLCD))
3103 if (temp == 0x01)
3104 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303106 if (temp == 0x04)
3107 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003108
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303109 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003110 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003111
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303112 if (!(temp & 0x08))
3113 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003114
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303115 if (!(temp & 0x04))
3116 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003117
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303118 if (temp & 0x02)
3119 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003120
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303121 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3122 if (temp & 0x01)
3123 tempch |= ActiveHiTV;
3124 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003125
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303126 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003127 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303128 pVBInfo->Part2Port,
3129 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003130
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303131 if (temp & 0x10)
3132 tempch |= ActiveYPbPr;
3133 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303135 if (tempch != 0)
3136 tempcl |= ActiveTV;
3137 }
3138 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003139
Aaro Koskinen58839b02011-03-13 12:26:23 +02003140 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303141 if (tempcl & ActiveLCD) {
3142 if ((pVBInfo->SetFlag & ReserveTVOption)) {
3143 if (temp & ActiveTV)
3144 tempcl |= ActiveTV;
3145 }
3146 }
3147 temp = tempcl;
3148 tempbl = ~ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003149 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003150
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303151 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003152 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303153 } else {
3154 return;
3155 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003156}
3157
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303158void XGI_GetVGAType(struct xgi_hw_device_info *HwDeviceExtension,
3159 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003160{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303161 /*
3162 if ( HwDeviceExtension->jChipType >= XG20 ) {
3163 pVBInfo->Set_VGAType = XG20;
Aaro Koskinen06587332011-03-13 12:26:10 +02003164 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303165 pVBInfo->Set_VGAType = VGA_XGI340;
3166 }
3167 */
3168 pVBInfo->Set_VGAType = HwDeviceExtension->jChipType;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003169}
3170
Bill Pemberton80adad82010-06-17 13:10:51 -04003171void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003172{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303173 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003174
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303175 if (pVBInfo->IF_DEF_LVDS == 0) {
3176 tempbx = VB_XGI302B;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003177 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303178 if (flag != 0x02) {
3179 tempbx = VB_XGI301;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003180 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303181 if (flag >= 0xB0) {
3182 tempbx = VB_XGI301B;
3183 if (flag >= 0xC0) {
3184 tempbx = VB_XGI301C;
3185 if (flag >= 0xD0) {
3186 tempbx = VB_XGI301LV;
3187 if (flag >= 0xE0) {
3188 tempbx = VB_XGI302LV;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003189 tempah = xgifb_reg_get(
3190 pVBInfo->Part4Port,
3191 0x39);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303192 if (tempah != 0xFF)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003193 tempbx =
3194 VB_XGI301C;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303195 }
3196 }
3197 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003198
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303199 if (tempbx & (VB_XGI301B | VB_XGI302B)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003200 flag = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303201 pVBInfo->Part4Port,
3202 0x23);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003203
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303204 if (!(flag & 0x02))
3205 tempbx = tempbx | VB_NoLCD;
3206 }
3207 }
3208 }
3209 pVBInfo->VBType = tempbx;
3210 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003211}
3212
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303213void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3214 struct xgi_hw_device_info *HwDeviceExtension,
3215 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003216{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303217 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003218
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303219 if (ModeNo <= 0x13)
3220 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3221 else
3222 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003223
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303224 pVBInfo->SetFlag = 0;
3225 pVBInfo->ModeType = modeflag & ModeInfoFlag;
3226 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003227
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303228 if (pVBInfo->VBType & 0xFFFF) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003229 /* Check Display Device */
3230 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303231 tempbx = tempbx | temp;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003232 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303233 push = temp;
3234 push = push << 8;
3235 tempax = temp << 8;
3236 tempbx = tempbx | tempax;
3237 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr | SetCRT2ToLCDA
3238 | SetInSlaveMode | DisableCRT2Display);
3239 temp = 0xFFFF ^ temp;
3240 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003241
Aaro Koskinen58839b02011-03-13 12:26:23 +02003242 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003243
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303244 if (pVBInfo->IF_DEF_LCDA == 1) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003245
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303246 if ((pVBInfo->Set_VGAType >= XG20)
3247 || (pVBInfo->Set_VGAType >= XG40)) {
3248 if (pVBInfo->IF_DEF_LVDS == 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003249 /* if ((pVBInfo->VBType & VB_XGI302B)
3250 || (pVBInfo->VBType & VB_XGI301LV)
3251 || (pVBInfo->VBType & VB_XGI302LV)
3252 || (pVBInfo->VBType & VB_XGI301C))
3253 */
3254 if (pVBInfo->VBType &
3255 (VB_XGI302B |
3256 VB_XGI301LV |
3257 VB_XGI302LV |
3258 VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303259 if (temp & EnableDualEdge) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003260 tempbx |=
3261 SetCRT2ToDualEdge;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003262
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303263 if (temp & SetToLCDA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003264 tempbx |=
3265 SetCRT2ToLCDA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303266 }
3267 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303268 }
3269 }
3270 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003271
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303272 if (pVBInfo->IF_DEF_YPbPr == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003273 /* [Billy] 07/05/04 */
3274 if (((pVBInfo->IF_DEF_LVDS == 0) &&
3275 ((pVBInfo->VBType & VB_XGI301LV) ||
3276 (pVBInfo->VBType & VB_XGI302LV) ||
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003277 (pVBInfo->VBType & VB_XGI301C)))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303278 if (temp & SetYPbPr) { /* temp = CR38 */
3279 if (pVBInfo->IF_DEF_HiVision == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003280 /* shampoo add for new
3281 * scratch */
Aaro Koskinen58839b02011-03-13 12:26:23 +02003282 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303283 pVBInfo->P3d4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003284 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303285 temp &= YPbPrMode;
3286 tempbx |= SetCRT2ToHiVisionTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003287
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303288 if (temp != YPbPrMode1080i) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003289 tempbx &=
3290 (~SetCRT2ToHiVisionTV);
3291 tempbx |=
3292 SetCRT2ToYPbPr;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303293 }
3294 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003295
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303296 /* tempbx |= SetCRT2ToYPbPr; */
3297 }
3298 }
3299 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003300
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303301 tempax = push; /* restore CR31 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003302
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303303 if (pVBInfo->IF_DEF_LVDS == 0) {
3304 if (pVBInfo->IF_DEF_YPbPr == 1) {
3305 if (pVBInfo->IF_DEF_HiVision == 1)
3306 temp = 0x09FC;
3307 else
3308 temp = 0x097C;
3309 } else {
3310 if (pVBInfo->IF_DEF_HiVision == 1)
3311 temp = 0x01FC;
3312 else
3313 temp = 0x017C;
3314 }
3315 } else { /* 3nd party chip */
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003316 temp = SetCRT2ToLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303317 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003318
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303319 if (!(tempbx & temp)) {
3320 tempax |= DisableCRT2Display;
3321 tempbx = 0;
3322 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003323
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303324 if (pVBInfo->IF_DEF_LCDA == 1) { /* Select Display Device */
3325 if (!(pVBInfo->VBType & VB_NoLCD)) {
3326 if (tempbx & SetCRT2ToLCDA) {
3327 if (tempbx & SetSimuScanMode)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003328 tempbx &= (~(SetCRT2ToLCD |
3329 SetCRT2ToRAMDAC |
3330 SwitchToCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303331 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003332 tempbx &= (~(SetCRT2ToLCD |
3333 SetCRT2ToRAMDAC |
3334 SetCRT2ToTV |
3335 SwitchToCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303336 }
3337 }
3338 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003339
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303340 /* shampoo add */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003341 /* for driver abnormal */
3342 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303343 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
3344 if (tempbx & SetCRT2ToRAMDAC) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003345 tempbx &= (0xFF00 |
3346 SetCRT2ToRAMDAC |
3347 SwitchToCRT2 |
3348 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303349 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3350 }
3351 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003352 tempbx &= (~(SetCRT2ToRAMDAC |
3353 SetCRT2ToLCD |
3354 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303355 }
3356 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003357
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303358 if (!(pVBInfo->VBType & VB_NoLCD)) {
3359 if (tempbx & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003360 tempbx &= (0xFF00 |
3361 SetCRT2ToLCD |
3362 SwitchToCRT2 |
3363 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303364 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3365 }
3366 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003367
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303368 if (tempbx & SetCRT2ToSCART) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003369 tempbx &= (0xFF00 |
3370 SetCRT2ToSCART |
3371 SwitchToCRT2 |
3372 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303373 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3374 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003375
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303376 if (pVBInfo->IF_DEF_YPbPr == 1) {
3377 if (tempbx & SetCRT2ToYPbPr)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003378 tempbx &= (0xFF00 |
3379 SwitchToCRT2 |
3380 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303381 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003382
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303383 if (pVBInfo->IF_DEF_HiVision == 1) {
3384 if (tempbx & SetCRT2ToHiVisionTV)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003385 tempbx &= (0xFF00 |
3386 SetCRT2ToHiVisionTV |
3387 SwitchToCRT2 |
3388 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303389 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003390
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303391 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
3392 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode)))
3393 tempbx = DisableCRT2Display;
3394 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003395
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303396 if (!(tempbx & DisableCRT2Display)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003397 if ((!(tempbx & DriverMode)) ||
3398 (!(modeflag & CRT2Mode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303399 if (pVBInfo->IF_DEF_LCDA == 1) {
3400 if (!(tempbx & SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003401 tempbx |= (SetInSlaveMode |
3402 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303403 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003404
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303405 if (pVBInfo->IF_DEF_VideoCapture == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003406 if (((HwDeviceExtension->jChipType ==
3407 XG40) &&
3408 (pVBInfo->Set_VGAType == XG40)) ||
3409 ((HwDeviceExtension->jChipType ==
3410 XG41) &&
3411 (pVBInfo->Set_VGAType == XG41)) ||
3412 ((HwDeviceExtension->jChipType ==
3413 XG42) &&
3414 (pVBInfo->Set_VGAType == XG42)) ||
3415 ((HwDeviceExtension->jChipType ==
3416 XG45) &&
3417 (pVBInfo->Set_VGAType == XG45))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303418 if (ModeNo <= 13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003419 if (!(tempbx &
3420 SetCRT2ToRAMDAC)) {
3421 /*CRT2 not need
3422 * to support*/
3423 tempbx &=
3424 (0x00FF |
3425 (~SetInSlaveMode));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303426 pVBInfo->SetFlag
3427 |= EnableVCMode;
3428 }
3429 }
3430 }
3431 }
3432 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003433
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003434 /* LCD+TV can't support in slave mode
3435 * (Force LCDA+TV->LCDB) */
3436 if ((tempbx & SetInSlaveMode) &&
3437 (tempbx & SetCRT2ToLCDA)) {
3438 tempbx ^= (SetCRT2ToLCD |
3439 SetCRT2ToLCDA |
3440 SetCRT2ToDualEdge);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303441 pVBInfo->SetFlag |= ReserveTVOption;
3442 }
3443 }
3444 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003445
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303446 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003447}
3448
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303449void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3450 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003451{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303452 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003453
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303454 tempbx = 0;
3455 resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003456
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303457 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3458 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003459 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].
3460 St_ModeFlag; /* si+St_ModeFlag */
3461 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].
3462 St_ResInfo; /* si+St_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303463 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003464 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].
3465 Ext_ModeFlag;
3466 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].
3467 Ext_RESINFO; /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303468 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003469
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303470 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003471 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303472 tempbx = temp;
3473 if (tempbx & SetPALTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003474 tempbx &= (SetCHTVOverScan |
3475 SetPALMTV |
3476 SetPALNTV |
3477 SetPALTV);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303478 if (tempbx & SetPALMTV)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003479 /* set to NTSC if PAL-M */
3480 tempbx &= ~SetPALTV;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303481 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003482 tempbx &= (SetCHTVOverScan |
3483 SetNTSCJ |
3484 SetPALTV);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303485 /*
3486 if (pVBInfo->IF_DEF_LVDS == 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003487 //PAL-M/PAL-N Info
3488 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x38);
3489 //00:PAL, 01:PAL-M, 10:PAL-N
3490 temp2 = (index1 & 0xC0) >> 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303491 tempbx |= temp2;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003492 if (temp2 & 0x02) //PAL-M
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303493 tempbx &= (~SetPALTV);
3494 }
3495 */
3496 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003497
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303498 if (pVBInfo->IF_DEF_LVDS == 0) {
3499 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3500 tempbx |= SetPALTV;
3501 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003502
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303503 if (pVBInfo->IF_DEF_YPbPr == 1) {
3504 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003505 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303506 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003507
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303508 if (index1 == YPbPrMode525i)
3509 tempbx |= SetYPbPrMode525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003510
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303511 if (index1 == YPbPrMode525p)
3512 tempbx = tempbx | SetYPbPrMode525p;
3513 if (index1 == YPbPrMode750p)
3514 tempbx = tempbx | SetYPbPrMode750p;
3515 }
3516 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003517
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303518 if (pVBInfo->IF_DEF_HiVision == 1) {
3519 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
3520 tempbx = tempbx | SetYPbPrMode1080i | SetPALTV;
3521 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003522
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303523 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003524 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
3525 (!(pVBInfo->VBInfo & SetNotSimuMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303526 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003527
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003528 if (!(tempbx & SetPALTV) &&
3529 (modeflag > 13) &&
3530 (resinfo == 8)) /* NTSC 1024x768, */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303531 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003532
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303533 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003534
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303535 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3536 if (pVBInfo->VBInfo & SetInSlaveMode)
3537 tempbx &= (~RPLLDIV2XO);
3538 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003539 if (tempbx &
3540 (SetYPbPrMode525p | SetYPbPrMode750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303541 tempbx &= (~RPLLDIV2XO);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003542 else if (!(pVBInfo->VBType &
3543 (VB_XGI301B |
3544 VB_XGI302B |
3545 VB_XGI301LV |
3546 VB_XGI302LV |
3547 VB_XGI301C))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303548 if (tempbx & TVSimuMode)
3549 tempbx &= (~RPLLDIV2XO);
3550 }
3551 }
3552 }
3553 }
3554 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003555}
3556
Bill Pemberton108afbf2010-06-17 13:10:47 -04003557unsigned char XGI_GetLCDInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303558 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003559{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303560 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003561
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303562 pVBInfo->LCDResInfo = 0;
3563 pVBInfo->LCDTypeInfo = 0;
3564 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003565
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303566 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003567 /* si+St_ModeFlag // */
3568 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303569 } else {
3570 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003571 /* si+Ext_ResInfo // */
3572 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303573 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003574
Aaro Koskinen58839b02011-03-13 12:26:23 +02003575 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303576 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003577
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303578 if (tempbx == 0)
3579 tempbx = Panel1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003580
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303581 /* LCD75 [2003/8/22] Vicent */
3582 if ((tempbx == Panel1024x768) || (tempbx == Panel1280x1024)) {
3583 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003584 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303585 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
3586 tempax &= 0x0F;
3587 else
3588 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003589
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303590 if ((resinfo == 6) || (resinfo == 9)) {
3591 if (tempax >= 3)
3592 tempbx |= PanelRef75Hz;
3593 } else if ((resinfo == 7) || (resinfo == 8)) {
3594 if (tempax >= 4)
3595 tempbx |= PanelRef75Hz;
3596 }
3597 }
3598 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003599
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303600 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003601
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303602 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003603
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303604 if (pVBInfo->IF_DEF_OEMUtil == 1)
3605 pVBInfo->LCDTypeInfo = (temp & 0xf0) >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003606
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303607 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
3608 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003609
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303610 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003611
Aaro Koskinen58839b02011-03-13 12:26:23 +02003612 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003613
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303614 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003615
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303616 if ((pVBInfo->IF_DEF_ScaleLCD == 1) && (temp & LCDNonExpanding))
3617 temp &= ~EnableScalingLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003618
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303619 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003620
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303621 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003622
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303623 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003624
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303625 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
3626 if (((pVBInfo->VBType & VB_XGI302LV) || (pVBInfo->VBType
3627 & VB_XGI301C)) && (tempax & LCDDualLink)) {
3628 tempbx |= SetLCDDualLink;
3629 }
3630 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003631
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303632 if (pVBInfo->IF_DEF_LVDS == 0) {
3633 if ((pVBInfo->LCDResInfo == Panel1400x1050) && (pVBInfo->VBInfo
3634 & SetCRT2ToLCD) && (ModeNo > 0x13) && (resinfo
3635 == 9) && (!(tempbx & EnableScalingLCD)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003636 /* set to center in 1280x1024 LCDB for Panel1400x1050 */
3637 tempbx |= SetLCDtoNonExpanding;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303638 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003639
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303640 /*
3641 if (tempax & LCDBToA) {
3642 tempbx |= SetLCDBToA;
3643 }
3644 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003645
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303646 if (pVBInfo->IF_DEF_ExpLink == 1) {
3647 if (modeflag & HalfDCLK) {
3648 /* if (!(pVBInfo->LCDInfo&LCDNonExpanding)) */
3649 if (!(tempbx & SetLCDtoNonExpanding)) {
3650 tempbx |= EnableLVDSDDA;
3651 } else {
3652 if (ModeNo > 0x13) {
3653 if (pVBInfo->LCDResInfo
3654 == Panel1024x768) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003655 if (resinfo == 4) {/* 512x384 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303656 tempbx |= EnableLVDSDDA;
3657 }
3658 }
3659 }
3660 }
3661 }
3662 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003663
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303664 if (pVBInfo->VBInfo & SetInSlaveMode) {
3665 if (pVBInfo->VBInfo & SetNotSimuMode)
3666 tempbx |= LCDVESATiming;
3667 } else {
3668 tempbx |= LCDVESATiming;
3669 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003670
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303671 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003672
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303673 if (pVBInfo->IF_DEF_PWD == 1) {
3674 if (pVBInfo->LCDInfo & SetPWDEnable) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003675 if ((pVBInfo->VBType & VB_XGI302LV) ||
3676 (pVBInfo->VBType & VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303677 if (!(tempax & PWDEnable))
3678 pVBInfo->LCDInfo &= ~SetPWDEnable;
3679 }
3680 }
3681 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003682
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303683 if (pVBInfo->IF_DEF_LVDS == 0) {
3684 if (tempax & (LockLCDBToA | StLCDBToA)) {
3685 if (pVBInfo->VBInfo & SetInSlaveMode) {
3686 if (!(tempax & LockLCDBToA)) {
3687 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003688 pVBInfo->VBInfo &=
3689 ~(SetSimuScanMode |
3690 SetInSlaveMode |
3691 SetCRT2ToLCD);
3692 pVBInfo->VBInfo |=
3693 SetCRT2ToLCDA |
3694 SetCRT2ToDualEdge;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303695 }
3696 }
3697 }
3698 }
3699 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003700
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303701 /*
3702 if (pVBInfo->IF_DEF_LVDS == 0) {
3703 if (tempax & (LockLCDBToA | StLCDBToA)) {
3704 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003705 if (!((!(tempax & LockLCDBToA)) &&
3706 (ModeNo > 0x13))) {
3707 pVBInfo->VBInfo &=
3708 ~(SetSimuScanMode |
3709 SetInSlaveMode |
3710 SetCRT2ToLCD);
3711 pVBInfo->VBInfo |=
3712 SetCRT2ToLCDA |
3713 SetCRT2ToDualEdge;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303714 }
3715 }
3716 }
3717 }
3718 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003719
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303720 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003721}
3722
Bill Pemberton108afbf2010-06-17 13:10:47 -04003723unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303724 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003725{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303726 if (ModeNo <= 5)
3727 ModeNo |= 1;
3728 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003729 /* for (*ModeIdIndex=0;
3730 *ModeIdIndex < sizeof(pVBInfo->SModeIDTable)
3731 / sizeof(struct XGI_StStruct);
3732 (*ModeIdIndex)++) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303733 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003734 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3735 ModeNo)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303736 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003737 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3738 0xFF)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303739 return 0;
3740 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003741
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303742 if (ModeNo == 0x07)
3743 (*ModeIdIndex)++; /* 400 lines */
3744 if (ModeNo <= 3)
3745 (*ModeIdIndex) += 2; /* 400 lines */
3746 /* else 350 lines */
3747 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003748 /* for (*ModeIdIndex=0;
3749 *ModeIdIndex < sizeof(pVBInfo->EModeIDTable)
3750 / sizeof(struct XGI_ExtStruct);
3751 (*ModeIdIndex)++) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303752 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003753 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3754 ModeNo)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303755 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003756 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3757 0xFF)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303758 return 0;
3759 }
3760 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003761
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303762 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003763}
3764
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003765static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
3766{
3767 unsigned char ujRet = 0;
3768 unsigned char i = 0;
3769
3770 for (i = 0; i < 8; i++) {
3771 ujRet = ujRet << 1;
3772 /* ujRet |= GETBITS(ujDate >> i, 0:0); */
3773 ujRet |= (ujDate >> i) & 1;
3774 }
3775
3776 return ujRet;
3777}
3778
3779/*----------------------------------------------------------------------------*/
3780/* output */
3781/* bl[5] : LVDS signal */
3782/* bl[1] : LVDS backlight */
3783/* bl[0] : LVDS VDD */
3784/*----------------------------------------------------------------------------*/
3785static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
3786{
3787 unsigned char CR4A, temp;
3788
Aaro Koskinen58839b02011-03-13 12:26:23 +02003789 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02003790 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003791
Aaro Koskinen58839b02011-03-13 12:26:23 +02003792 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003793
3794 temp = XG21GPIODataTransfer(temp);
3795 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003796 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003797 return temp;
3798}
3799
3800/*----------------------------------------------------------------------------*/
3801/* output */
3802/* bl[5] : LVDS signal */
3803/* bl[1] : LVDS backlight */
3804/* bl[0] : LVDS VDD */
3805/*----------------------------------------------------------------------------*/
3806static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
3807{
3808 unsigned char CR4A, CRB4, temp;
3809
Aaro Koskinen58839b02011-03-13 12:26:23 +02003810 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02003811 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003812
Aaro Koskinen58839b02011-03-13 12:26:23 +02003813 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003814
3815 temp &= 0x0C;
3816 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003817 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003818 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003819 temp |= ((CRB4 & 0x04) << 3);
3820 return temp;
3821}
3822
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303823void XGI_DisplayOn(struct xgi_hw_device_info *pXGIHWDE,
3824 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003825{
3826
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003827 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303828 if (pXGIHWDE->jChipType == XG21) {
3829 if (pVBInfo->IF_DEF_LVDS == 1) {
3830 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003831 /* LVDS VDD on */
3832 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303833 XGI_XG21SetPanelDelay(2, pVBInfo);
3834 }
3835 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003836 /* LVDS signal on */
3837 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303838 XGI_XG21SetPanelDelay(3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003839 /* LVDS backlight on */
3840 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303841 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003842 /* DVO/DVI signal on */
3843 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303844 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003845
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303846 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003847
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303848 if (pXGIHWDE->jChipType == XG27) {
3849 if (pVBInfo->IF_DEF_LVDS == 1) {
3850 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003851 /* LVDS VDD on */
3852 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303853 XGI_XG21SetPanelDelay(2, pVBInfo);
3854 }
3855 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003856 /* LVDS signal on */
3857 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303858 XGI_XG21SetPanelDelay(3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003859 /* LVDS backlight on */
3860 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303861 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003862 /* DVO/DVI signal on */
3863 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303864 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003865
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303866 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003867}
3868
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303869void XGI_DisplayOff(struct xgi_hw_device_info *pXGIHWDE,
3870 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003871{
3872
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303873 if (pXGIHWDE->jChipType == XG21) {
3874 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003875 /* LVDS backlight off */
3876 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303877 XGI_XG21SetPanelDelay(3, pVBInfo);
3878 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003879 /* DVO/DVI signal off */
3880 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303881 }
3882 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003883
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303884 if (pXGIHWDE->jChipType == XG27) {
3885 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003886 /* LVDS backlight off */
3887 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303888 XGI_XG21SetPanelDelay(3, pVBInfo);
3889 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003890
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303891 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003892 /* DVO/DVI signal off */
3893 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303894 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003895
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003896 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003897}
3898
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003899static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003900{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003901 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303902 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003903
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003904 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303905 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003906}
3907
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003908static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003909{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303910 if (!(pVBInfo->SetFlag & Win9xDOSMode))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02003911 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003912}
3913
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003914static void XGI_SaveCRT2Info(unsigned short ModeNo,
3915 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003916{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303917 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003918
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003919 /* reserve CR34 for CRT1 Mode No */
3920 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303921 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
3922 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003923 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003924}
3925
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003926static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
3927 unsigned short ModeIdIndex,
3928 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003929{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303930 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003931
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303932 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
3933 if (ModeNo <= 0x13) {
3934 xres = pVBInfo->StResInfo[resindex].HTotal;
3935 yres = pVBInfo->StResInfo[resindex].VTotal;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003936 /* si+St_ResInfo */
3937 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;*/
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303938 } else {
3939 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
3940 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003941 /* si+St_ModeFlag */
3942 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003943
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303944 /*
3945 if (pVBInfo->IF_DEF_FSTN) {
3946 xres *= 2;
3947 yres *= 2;
3948 } else {
3949 */
3950 if (modeflag & HalfDCLK)
3951 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003952
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303953 if (modeflag & DoubleScanMode)
3954 yres *= 2;
3955 /* } */
3956 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003957
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303958 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
3959 if (pVBInfo->IF_DEF_LVDS == 0) {
3960 if (pVBInfo->LCDResInfo == Panel1600x1200) {
3961 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
3962 if (yres == 1024)
3963 yres = 1056;
3964 }
3965 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003966
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303967 if (pVBInfo->LCDResInfo == Panel1280x1024) {
3968 if (yres == 400)
3969 yres = 405;
3970 else if (yres == 350)
3971 yres = 360;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003972
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303973 if (pVBInfo->LCDInfo & LCDVESATiming) {
3974 if (yres == 360)
3975 yres = 375;
3976 }
3977 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003978
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303979 if (pVBInfo->LCDResInfo == Panel1024x768) {
3980 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
3981 if (!(pVBInfo->LCDInfo
3982 & LCDNonExpanding)) {
3983 if (yres == 350)
3984 yres = 357;
3985 else if (yres == 400)
3986 yres = 420;
3987 else if (yres == 480)
3988 yres = 525;
3989 }
3990 }
3991 }
3992 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003993
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303994 if (xres == 720)
3995 xres = 640;
3996 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003997
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303998 pVBInfo->VGAHDE = xres;
3999 pVBInfo->HDE = xres;
4000 pVBInfo->VGAVDE = yres;
4001 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004002}
4003
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004004static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004005{
4006
Dan Carpentera65fd092011-01-04 09:02:27 +03004007 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
4008 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304009 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004010
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304011 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004012}
4013
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004014static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
4015 unsigned short ModeIdIndex,
4016 unsigned short RefreshRateTableIndex,
4017 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004018{
4019 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
4020 StandTableIndex, CRT1Index;
4021
4022 pVBInfo->RVBHCMAX = 1;
4023 pVBInfo->RVBHCFACT = 1;
4024
4025 if (ModeNo <= 0x13) {
4026 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4027 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
4028 tempax = pVBInfo->StandTable[StandTableIndex].CRTC[0];
4029 tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[6];
4030 temp1 = pVBInfo->StandTable[StandTableIndex].CRTC[7];
4031 } else {
4032 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004033 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
4034 Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004035 CRT1Index &= IndexMask;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004036 temp1 = (unsigned short) pVBInfo->
4037 XGINEWUB_CRT1Table[CRT1Index].CR[0];
4038 temp2 = (unsigned short) pVBInfo->
4039 XGINEWUB_CRT1Table[CRT1Index].CR[5];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004040 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004041 tempbx = (unsigned short) pVBInfo->
4042 XGINEWUB_CRT1Table[CRT1Index].CR[8];
4043 tempcx = (unsigned short) pVBInfo->
4044 XGINEWUB_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004045 tempcx &= 0x0100;
4046 tempcx = tempcx << 2;
4047 tempbx |= tempcx;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004048 temp1 = (unsigned short) pVBInfo->
4049 XGINEWUB_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004050 }
4051
4052 if (temp1 & 0x01)
4053 tempbx |= 0x0100;
4054
4055 if (temp1 & 0x20)
4056 tempbx |= 0x0200;
4057 tempax += 5;
4058
4059 if (modeflag & Charx8Dot)
4060 tempax *= 8;
4061 else
4062 tempax *= 9;
4063
4064 pVBInfo->VGAHT = tempax;
4065 pVBInfo->HT = tempax;
4066 tempbx++;
4067 pVBInfo->VGAVT = tempbx;
4068 pVBInfo->VT = tempbx;
4069}
4070
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004071static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304072 unsigned short RefreshRateTableIndex,
4073 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004074{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304075 unsigned short tempax = 0, tempbx, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004076
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304077 struct XGI_LCDDataStruct *LCDPtr = NULL;
4078 struct XGI_TVDataStruct *TVPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004079
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304080 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004081 /* si+St_ResInfo */
4082 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304083 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4084 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004085 /* si+Ext_ResInfo */
4086 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304087 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4088 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304090 pVBInfo->NewFlickerMode = 0;
4091 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004092
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304093 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4094 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4095 pVBInfo);
4096 return;
4097 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004098
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304099 tempbx = 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304101 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
4102 LCDPtr = (struct XGI_LCDDataStruct *) XGI_GetLcdPtr(tempbx,
4103 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4104 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304106 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
4107 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
4108 pVBInfo->VGAHT = LCDPtr->VGAHT;
4109 pVBInfo->VGAVT = LCDPtr->VGAVT;
4110 pVBInfo->HT = LCDPtr->LCDHT;
4111 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004112
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304113 if (pVBInfo->LCDResInfo == Panel1024x768) {
4114 tempax = 1024;
4115 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004116
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304117 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4118 if (pVBInfo->VGAVDE == 357)
4119 tempbx = 527;
4120 else if (pVBInfo->VGAVDE == 420)
4121 tempbx = 620;
4122 else if (pVBInfo->VGAVDE == 525)
4123 tempbx = 775;
4124 else if (pVBInfo->VGAVDE == 600)
4125 tempbx = 775;
4126 /* else if (pVBInfo->VGAVDE==350) tempbx=560; */
4127 /* else if (pVBInfo->VGAVDE==400) tempbx=640; */
4128 else
4129 tempbx = 768;
4130 } else
4131 tempbx = 768;
4132 } else if (pVBInfo->LCDResInfo == Panel1024x768x75) {
4133 tempax = 1024;
4134 tempbx = 768;
4135 } else if (pVBInfo->LCDResInfo == Panel1280x1024) {
4136 tempax = 1280;
4137 if (pVBInfo->VGAVDE == 360)
4138 tempbx = 768;
4139 else if (pVBInfo->VGAVDE == 375)
4140 tempbx = 800;
4141 else if (pVBInfo->VGAVDE == 405)
4142 tempbx = 864;
4143 else
4144 tempbx = 1024;
4145 } else if (pVBInfo->LCDResInfo == Panel1280x1024x75) {
4146 tempax = 1280;
4147 tempbx = 1024;
4148 } else if (pVBInfo->LCDResInfo == Panel1280x960) {
4149 tempax = 1280;
4150 if (pVBInfo->VGAVDE == 350)
4151 tempbx = 700;
4152 else if (pVBInfo->VGAVDE == 400)
4153 tempbx = 800;
4154 else if (pVBInfo->VGAVDE == 1024)
4155 tempbx = 960;
4156 else
4157 tempbx = 960;
4158 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
4159 tempax = 1400;
4160 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004161
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304162 if (pVBInfo->VGAVDE == 1024) {
4163 tempax = 1280;
4164 tempbx = 1024;
4165 }
4166 } else if (pVBInfo->LCDResInfo == Panel1600x1200) {
4167 tempax = 1600;
4168 tempbx = 1200; /* alan 10/14/2003 */
4169 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4170 if (pVBInfo->VGAVDE == 350)
4171 tempbx = 875;
4172 else if (pVBInfo->VGAVDE == 400)
4173 tempbx = 1000;
4174 }
4175 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004176
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304177 if (pVBInfo->LCDInfo & LCDNonExpanding) {
4178 tempax = pVBInfo->VGAHDE;
4179 tempbx = pVBInfo->VGAVDE;
4180 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004181
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304182 pVBInfo->HDE = tempax;
4183 pVBInfo->VDE = tempbx;
4184 return;
4185 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004186
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304187 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
4188 tempbx = 4;
4189 TVPtr = (struct XGI_TVDataStruct *) XGI_GetTVPtr(tempbx,
4190 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4191 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004192
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304193 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
4194 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
4195 pVBInfo->VGAHT = TVPtr->VGAHT;
4196 pVBInfo->VGAVT = TVPtr->VGAVT;
4197 pVBInfo->HDE = TVPtr->TVHDE;
4198 pVBInfo->VDE = TVPtr->TVVDE;
4199 pVBInfo->RVBHRS = TVPtr->RVBHRS;
4200 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004201
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304202 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4203 if (resinfo == 0x08)
4204 pVBInfo->NewFlickerMode = 0x40;
4205 else if (resinfo == 0x09)
4206 pVBInfo->NewFlickerMode = 0x40;
4207 else if (resinfo == 0x12)
4208 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004209
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304210 if (pVBInfo->VGAVDE == 350)
4211 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004212
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304213 tempax = ExtHiTVHT;
4214 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004215
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304216 if (pVBInfo->VBInfo & SetInSlaveMode) {
4217 if (pVBInfo->TVInfo & TVSimuMode) {
4218 tempax = StHiTVHT;
4219 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004220
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304221 if (!(modeflag & Charx8Dot)) {
4222 tempax = StHiTextTVHT;
4223 tempbx = StHiTextTVVT;
4224 }
4225 }
4226 }
4227 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
4228 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
4229 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
4230 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
4231 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004232
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304233 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
4234 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
4235 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
4236 } else if (pVBInfo->TVInfo & SetYPbPrMode525i) {
4237 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
4238 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
4239 if (pVBInfo->TVInfo & NTSC1024x768)
4240 tempax = NTSC1024x768HT;
4241 }
4242 } else {
4243 tempax = PALHT;
4244 tempbx = PALVT;
4245 if (!(pVBInfo->TVInfo & SetPALTV)) {
4246 tempax = NTSCHT;
4247 tempbx = NTSCVT;
4248 if (pVBInfo->TVInfo & NTSC1024x768)
4249 tempax = NTSC1024x768HT;
4250 }
4251 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004252
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304253 pVBInfo->HT = tempax;
4254 pVBInfo->VT = tempbx;
4255 return;
4256 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004257}
4258
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004259static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304260 unsigned short RefreshRateTableIndex,
4261 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004262{
Bill Pemberton108afbf2010-06-17 13:10:47 -04004263 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004264
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304265 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
4266 pVBInfo);
4267 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
4268 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004269
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304270 if (pVBInfo->VBType & VB_XGI301) { /* shampoo 0129 */
4271 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004272 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
4273 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
4274 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304275 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004276 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
4277 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304278 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004279
Aaro Koskinen8104e322011-03-13 12:26:22 +02004280 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004281
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304282 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004283 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304284 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004285 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004286}
4287
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004288static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
4289 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004290{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004291 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
4292 short index;
4293 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304294
4295 if (ModeNo <= 0x13)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004296 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304297 else
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004298 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304299
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004300 index = (modeflag & ModeInfoFlag) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304301
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004302 if (index < 0)
4303 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304304
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004305 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304306}
4307
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004308static unsigned short XGI_GetOffset(unsigned short ModeNo,
4309 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304310 unsigned short RefreshRateTableIndex,
4311 struct xgi_hw_device_info *HwDeviceExtension,
4312 struct vb_device_info *pVBInfo)
4313{
4314 unsigned short temp, colordepth, modeinfo, index, infoflag,
4315 ColorDepth[] = { 0x01, 0x02, 0x04 };
4316
4317 modeinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
4318 if (ModeNo <= 0x14)
4319 infoflag = 0;
4320 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004321 infoflag = pVBInfo->
4322 RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304323
4324 index = (modeinfo >> 8) & 0xFF;
4325
4326 temp = pVBInfo->ScreenOffset[index];
4327
4328 if (infoflag & InterlaceMode)
4329 temp = temp << 1;
4330
4331 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4332
4333 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
4334 temp = ModeNo - 0x7C;
4335 colordepth = ColorDepth[temp];
4336 temp = 0x6B;
4337 if (infoflag & InterlaceMode)
4338 temp = temp << 1;
4339 return temp * colordepth;
4340 } else {
4341 return temp * colordepth;
4342 }
4343}
4344
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004345static void XGI_SetCRT2Offset(unsigned short ModeNo,
4346 unsigned short ModeIdIndex,
4347 unsigned short RefreshRateTableIndex,
4348 struct xgi_hw_device_info *HwDeviceExtension,
4349 struct vb_device_info *pVBInfo)
4350{
4351 unsigned short offset;
4352 unsigned char temp;
4353
4354 if (pVBInfo->VBInfo & SetInSlaveMode)
4355 return;
4356
4357 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4358 HwDeviceExtension, pVBInfo);
4359 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004360 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004361 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004362 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004363 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004364 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004365}
4366
Randy Dunlap89229672010-08-10 08:46:44 -07004367static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004368{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004369 /* threshold high ,disable auto threshold */
4370 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
4371 /* threshold low default 04h */
4372 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004373}
4374
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004375static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304376 struct xgi_hw_device_info *HwDeviceExtension,
4377 unsigned short RefreshRateTableIndex,
4378 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004379{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304380 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004381
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304382 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004383 CRT1Index = pVBInfo->
4384 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304385 CRT1Index &= IndexMask;
4386 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4387 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004388
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304389 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4390 HwDeviceExtension, pVBInfo);
4391 XGI_SetCRT2FIFO(pVBInfo);
4392 /* XGI_SetCRT2Sync(ModeNo,RefreshRateTableIndex); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004393
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304394 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004395 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004396
Aaro Koskinen8104e322011-03-13 12:26:22 +02004397 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
4398 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004399}
4400
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004401static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304402 struct xgi_hw_device_info *HwDeviceExtension,
4403 unsigned short RefreshRateTableIndex,
4404 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004405{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304406 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
4407 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004408
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304409 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004410 CRT1Index = pVBInfo->
4411 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304412 CRT1Index &= IndexMask;
4413 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004414 }
4415
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304416 if (ModeNo <= 0x13)
4417 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4418 else
4419 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004420
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304421 /* bainy change table name */
4422 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004423 /* BTVGA2HT 0x08,0x09 */
4424 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004425 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304426 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004427 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004428 /* BTVGA2HDEE 0x0A,0x0C */
4429 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004430 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304431 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
4432 pushbx = pVBInfo->VGAHDE / 2 + 16;
4433 tempcx = tempcx >> 1;
4434 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4435 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004436
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304437 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4438 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004439 tempbx |= ((pVBInfo->
4440 XGINEWUB_CRT1Table[CRT1Index].CR[14] &
4441 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304442 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4443 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
4444 tempcx &= 0x1F;
4445 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[15];
4446 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4447 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4448 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004449
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304450 tempbx += 4;
4451 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004452
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304453 if (tempcx > (pVBInfo->VGAHT / 2))
4454 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004455
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304456 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004457
Aaro Koskinen8104e322011-03-13 12:26:22 +02004458 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304459 } else {
4460 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004461 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304462 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004463 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004464 /* BTVGA2HDEE 0x0A,0x0C */
4465 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004466 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304467 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
4468 pushbx = pVBInfo->VGAHDE + 16;
4469 tempcx = tempcx >> 1;
4470 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4471 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004472
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304473 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4474 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[3];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004475 tempbx |= ((pVBInfo->
4476 XGINEWUB_CRT1Table[CRT1Index].CR[5] &
4477 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304478 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4479 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
4480 tempcx &= 0x1F;
4481 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[6];
4482 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4483 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4484 tempbx += 16;
4485 tempcx += 16;
4486 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004487
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304488 if (tempcx > pVBInfo->VGAHT)
4489 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004490
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304491 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004492 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304493 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004494
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304495 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
4496 tempbx = pushbx;
4497 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
4498 tempax |= (tempbx & 0xFF00);
4499 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004500 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304501 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004502 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304503 tempcx = (pVBInfo->VGAVT - 1);
4504 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004505
Aaro Koskinen8104e322011-03-13 12:26:22 +02004506 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304507 tempbx = pVBInfo->VGAVDE - 1;
4508 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004509 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304510 temp = ((tempbx & 0xFF00) << 3) >> 8;
4511 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004512 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004513
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304514 tempax = pVBInfo->VGAVDE;
4515 tempbx = pVBInfo->VGAVDE;
4516 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004517 /* BTVGA2VRS 0x10,0x11 */
4518 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
4519 /* BTVGA2VRE 0x11 */
4520 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004521
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304522 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4523 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[10];
4524 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004525
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304526 if (temp & 0x04)
4527 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004528
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304529 if (temp & 0x080)
4530 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004531
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304532 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004533
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304534 if (temp & 0x08)
4535 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004536
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304537 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[11];
4538 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
4539 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004540
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304541 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004542 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304543 temp = ((tempbx & 0xFF00) >> 8) << 4;
4544 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004545 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304546 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004547
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304548 if (modeflag & DoubleScanMode)
4549 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004550
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304551 if (modeflag & HalfDCLK)
4552 tempax |= 0x40;
4553
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004554 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004555}
4556
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004557static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
4558{
4559 unsigned long tempax, tempbx;
4560
4561 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
4562 & 0xFFFF;
4563 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
4564 tempax = (tempax * pVBInfo->HT) / tempbx;
4565
4566 return (unsigned short) tempax;
4567}
4568
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004569static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304570 struct xgi_hw_device_info *HwDeviceExtension,
4571 unsigned short RefreshRateTableIndex,
4572 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004573{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304574 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
4575 modeflag, CRT1Index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004576
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304577 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004578 /* si+St_ResInfo */
4579 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304580 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4581 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004582 /* si+Ext_ResInfo */
4583 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304584 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004585 CRT1Index = pVBInfo->
4586 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304587 CRT1Index &= IndexMask;
4588 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004589
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304590 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4591 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004592
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304593 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004594 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304595 /* if (modeflag & Charx8Dot) */
4596 /* tempcx = 0x08; */
4597 /* else */
4598 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004599
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304600 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4601 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004602
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304603 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004604
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304605 if (modeflag & HalfDCLK)
4606 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004607
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304608 tempax = (tempax / tempcx) - 1;
4609 tempbx |= ((tempax & 0x00FF) << 8);
4610 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004611 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004612
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304613 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004614
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304615 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4616 if (!(pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4617 | VB_XGI302LV | VB_XGI301C)))
4618 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004619
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304620 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4621 if (pVBInfo->VBType & VB_XGI301LV) {
4622 if (pVBInfo->VBExtInfo == VB_YPbPr1080i) {
4623 if (resinfo == 7)
4624 temp -= 2;
4625 }
4626 } else if (resinfo == 7) {
4627 temp -= 2;
4628 }
4629 }
4630 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004631
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004632 /* 0x05 Horizontal Display Start */
4633 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
4634 /* 0x06 Horizontal Blank end */
4635 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004636
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304637 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
4638 if (pVBInfo->VBInfo & SetCRT2ToTV)
4639 tempax = pVBInfo->VGAHT;
4640 else
4641 tempax = XGI_GetVGAHT2(pVBInfo);
4642 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004643
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304644 if (tempax >= pVBInfo->VGAHT)
4645 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004646
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304647 if (modeflag & HalfDCLK)
4648 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004649
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304650 tempax = (tempax / tempcx) - 5;
4651 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
4652 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4653 temp = (tempbx & 0x00FF) - 1;
4654 if (!(modeflag & HalfDCLK)) {
4655 temp -= 6;
4656 if (pVBInfo->TVInfo & TVSimuMode) {
4657 temp -= 4;
4658 if (ModeNo > 0x13)
4659 temp -= 10;
4660 }
4661 }
4662 } else {
4663 /* tempcx = tempbx & 0x00FF ; */
4664 tempbx = (tempbx & 0xFF00) >> 8;
4665 tempcx = (tempcx + tempbx) >> 1;
4666 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004667
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304668 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4669 temp -= 1;
4670 if (!(modeflag & HalfDCLK)) {
4671 if ((modeflag & Charx8Dot)) {
4672 temp += 4;
4673 if (pVBInfo->VGAHDE >= 800)
4674 temp -= 6;
4675 }
4676 }
4677 } else {
4678 if (!(modeflag & HalfDCLK)) {
4679 temp -= 4;
4680 if (pVBInfo->LCDResInfo != Panel1280x960) {
4681 if (pVBInfo->VGAHDE >= 800) {
4682 temp -= 7;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004683 if (pVBInfo->ModeType ==
4684 ModeEGA) {
4685 if (pVBInfo->VGAVDE ==
4686 1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304687 temp += 15;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004688 if (pVBInfo->LCDResInfo != Panel1280x1024) {
4689 temp +=
4690 7;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304691 }
4692 }
4693 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004694
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304695 if (pVBInfo->VGAHDE >= 1280) {
4696 if (pVBInfo->LCDResInfo
4697 != Panel1280x960) {
4698 if (pVBInfo->LCDInfo
4699 & LCDNonExpanding) {
4700 temp
4701 += 28;
4702 }
4703 }
4704 }
4705 }
4706 }
4707 }
4708 }
4709 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004710
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004711 /* 0x07 Horizontal Retrace Start */
4712 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4713 /* 0x08 Horizontal Retrace End */
4714 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004715
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304716 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4717 if (pVBInfo->TVInfo & TVSimuMode) {
4718 if ((ModeNo == 0x06) || (ModeNo == 0x10) || (ModeNo
4719 == 0x11) || (ModeNo == 0x13) || (ModeNo
4720 == 0x0F)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004721 xgifb_reg_set(pVBInfo->Part1Port, 0x07, 0x5b);
4722 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0x03);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304723 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004724
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304725 if ((ModeNo == 0x00) || (ModeNo == 0x01)) {
4726 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004727 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304728 0x07, 0x2A);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004729 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304730 0x08, 0x61);
4731 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004732 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304733 0x07, 0x2A);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004734 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304735 0x08, 0x41);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004736 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304737 0x0C, 0xF0);
4738 }
4739 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004740
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304741 if ((ModeNo == 0x02) || (ModeNo == 0x03) || (ModeNo
4742 == 0x07)) {
4743 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004744 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304745 0x07, 0x54);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004746 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304747 0x08, 0x00);
4748 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004749 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304750 0x07, 0x55);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004751 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304752 0x08, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004753 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304754 0x0C, 0xF0);
4755 }
4756 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004757
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304758 if ((ModeNo == 0x04) || (ModeNo == 0x05) || (ModeNo
4759 == 0x0D) || (ModeNo == 0x50)) {
4760 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004761 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304762 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004763 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304764 0x08, 0x03);
4765 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004766 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304767 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004768 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304769 0x08, 0x02);
4770 }
4771 }
4772 }
4773 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004774
Aaro Koskinen8104e322011-03-13 12:26:22 +02004775 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004776 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004777 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004778
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304779 tempbx = pVBInfo->VGAVT;
4780 push1 = tempbx;
4781 tempcx = 0x121;
4782 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004783
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304784 if (tempbx == 357)
4785 tempbx = 350;
4786 if (tempbx == 360)
4787 tempbx = 350;
4788 if (tempbx == 375)
4789 tempbx = 350;
4790 if (tempbx == 405)
4791 tempbx = 400;
4792 if (tempbx == 525)
4793 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004794
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304795 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304797 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4798 if (pVBInfo->LCDResInfo == Panel1024x768) {
4799 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4800 if (tempbx == 350)
4801 tempbx += 5;
4802 if (tempbx == 480)
4803 tempbx += 5;
4804 }
4805 }
4806 }
4807 tempbx--;
4808 temp = tempbx & 0x00FF;
4809 tempbx--;
4810 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004811 /* 0x10 vertical Blank Start */
4812 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304813 tempbx = push2;
4814 tempbx--;
4815 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004816 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004817
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304818 if (tempbx & 0x0100)
4819 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004820
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304821 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004822
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304823 if (modeflag & DoubleScanMode)
4824 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004825
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304826 if (tempbx & 0x0200)
4827 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004828
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304829 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004830 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004831
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304832 if (tempbx & 0x0400)
4833 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004834
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004835 /* 0x11 Vertival Blank End */
4836 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304837
4838 tempax = push1;
4839 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
4840 tempax = tempax >> 2;
4841 push1 = tempax; /* push ax */
4842
4843 if (resinfo != 0x09) {
4844 tempax = tempax << 1;
4845 tempbx += tempax;
4846 }
4847
4848 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4849 if (pVBInfo->VBType & VB_XGI301LV) {
4850 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
4851 tempbx -= 10;
4852 } else {
4853 if (pVBInfo->TVInfo & TVSimuMode) {
4854 if (pVBInfo->TVInfo & SetPALTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004855 if (pVBInfo->VBType &
4856 VB_XGI301LV) {
4857 if (!(pVBInfo->TVInfo &
4858 (SetYPbPrMode525p |
4859 SetYPbPrMode750p |
4860 SetYPbPrMode1080i)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304861 tempbx += 40;
4862 } else {
4863 tempbx += 40;
4864 }
4865 }
4866 }
4867 }
4868 } else {
4869 tempbx -= 10;
4870 }
4871 } else {
4872 if (pVBInfo->TVInfo & TVSimuMode) {
4873 if (pVBInfo->TVInfo & SetPALTV) {
4874 if (pVBInfo->VBType & VB_XGI301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004875 if (!(pVBInfo->TVInfo &
4876 (SetYPbPrMode525p |
4877 SetYPbPrMode750p |
4878 SetYPbPrMode1080i)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304879 tempbx += 40;
4880 } else {
4881 tempbx += 40;
4882 }
4883 }
4884 }
4885 }
4886 tempax = push1;
4887 tempax = tempax >> 2;
4888 tempax++;
4889 tempax += tempbx;
4890 push1 = tempax; /* push ax */
4891
4892 if ((pVBInfo->TVInfo & SetPALTV)) {
4893 if (tempbx <= 513) {
4894 if (tempax >= 513)
4895 tempbx = 513;
4896 }
4897 }
4898
4899 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004900 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304901 tempbx--;
4902 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004903 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304904
4905 if (tempbx & 0x0100)
4906 tempcx |= 0x0008;
4907
4908 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004909 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304910
4911 tempbx++;
4912
4913 if (tempbx & 0x0100)
4914 tempcx |= 0x0004;
4915
4916 if (tempbx & 0x0200)
4917 tempcx |= 0x0080;
4918
4919 if (tempbx & 0x0400)
4920 tempcx |= 0x0C00;
4921
4922 tempbx = push1; /* pop ax */
4923 temp = tempbx & 0x00FF;
4924 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004925 /* 0x0D vertical Retrace End */
4926 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304927
4928 if (tempbx & 0x0010)
4929 tempcx |= 0x2000;
4930
4931 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004932 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304933 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004934 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304935 tempax = modeflag;
4936 temp = (tempax & 0xFF00) >> 8;
4937
4938 temp = (temp >> 1) & 0x09;
4939
4940 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4941 temp |= 0x01;
4942
Aaro Koskinen8104e322011-03-13 12:26:22 +02004943 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
4944 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
4945 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304946
4947 if (pVBInfo->LCDInfo & LCDRGB18Bit)
4948 temp = 0x80;
4949 else
4950 temp = 0x00;
4951
Aaro Koskinen8104e322011-03-13 12:26:22 +02004952 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304953
4954 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004955}
4956
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004957static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304958 unsigned short RefreshRateTableIndex,
4959 struct xgi_hw_device_info *HwDeviceExtension,
4960 struct vb_device_info *pVBInfo)
4961{
4962 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
4963 modeflag, resinfo, crt2crtc;
4964 unsigned char *TimingPoint;
4965
4966 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
4967
4968 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004969 /* si+St_ResInfo */
4970 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304971 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4972 crt2crtc = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
4973 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004974 /* si+Ext_ResInfo */
4975 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304976 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004977 crt2crtc = pVBInfo->RefIndex[RefreshRateTableIndex].
4978 Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304979 }
4980
4981 tempax = 0;
4982
4983 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
4984 tempax |= 0x0800;
4985
4986 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4987 tempax |= 0x0400;
4988
4989 if (pVBInfo->VBInfo & SetCRT2ToSCART)
4990 tempax |= 0x0200;
4991
4992 if (!(pVBInfo->TVInfo & SetPALTV))
4993 tempax |= 0x1000;
4994
4995 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
4996 tempax |= 0x0100;
4997
4998 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
4999 tempax &= 0xfe00;
5000
5001 tempax = (tempax & 0xff00) >> 8;
5002
Aaro Koskinen8104e322011-03-13 12:26:22 +02005003 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305004 TimingPoint = pVBInfo->NTSCTiming;
5005
5006 if (pVBInfo->TVInfo & SetPALTV)
5007 TimingPoint = pVBInfo->PALTiming;
5008
5009 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5010 TimingPoint = pVBInfo->HiTVExtTiming;
5011
5012 if (pVBInfo->VBInfo & SetInSlaveMode)
5013 TimingPoint = pVBInfo->HiTVSt2Timing;
5014
5015 if (pVBInfo->SetFlag & TVSimuMode)
5016 TimingPoint = pVBInfo->HiTVSt1Timing;
5017
5018 if (!(modeflag & Charx8Dot))
5019 TimingPoint = pVBInfo->HiTVTextTiming;
5020 }
5021
5022 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5023 if (pVBInfo->TVInfo & SetYPbPrMode525i)
5024 TimingPoint = pVBInfo->YPbPr525iTiming;
5025
5026 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5027 TimingPoint = pVBInfo->YPbPr525pTiming;
5028
5029 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5030 TimingPoint = pVBInfo->YPbPr750pTiming;
5031 }
5032
5033 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005034 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305035
5036 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005037 /* di->temp2[j] */
5038 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305039
5040 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005041 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305042
5043 temp = pVBInfo->NewFlickerMode;
5044 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005045 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305046
5047 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5048 tempax = 950;
5049
5050 if (pVBInfo->TVInfo & SetPALTV)
5051 tempax = 520;
5052 else
5053 tempax = 440;
5054
5055 if (pVBInfo->VDE <= tempax) {
5056 tempax -= pVBInfo->VDE;
5057 tempax = tempax >> 2;
5058 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
5059 push1 = tempax;
5060 temp = (tempax & 0xFF00) >> 8;
5061 temp += (unsigned short) TimingPoint[0];
5062
5063 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5064 | VB_XGI302LV | VB_XGI301C)) {
5065 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
5066 | SetCRT2ToSVIDEO | SetCRT2ToSCART
5067 | SetCRT2ToYPbPr)) {
5068 tempcx = pVBInfo->VGAHDE;
5069 if (tempcx >= 1024) {
5070 temp = 0x17; /* NTSC */
5071 if (pVBInfo->TVInfo & SetPALTV)
5072 temp = 0x19; /* PAL */
5073 }
5074 }
5075 }
5076
Aaro Koskinen8104e322011-03-13 12:26:22 +02005077 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305078 tempax = push1;
5079 temp = (tempax & 0xFF00) >> 8;
5080 temp += TimingPoint[1];
5081
5082 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5083 | VB_XGI302LV | VB_XGI301C)) {
5084 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
5085 | SetCRT2ToSVIDEO | SetCRT2ToSCART
5086 | SetCRT2ToYPbPr))) {
5087 tempcx = pVBInfo->VGAHDE;
5088 if (tempcx >= 1024) {
5089 temp = 0x1D; /* NTSC */
5090 if (pVBInfo->TVInfo & SetPALTV)
5091 temp = 0x52; /* PAL */
5092 }
5093 }
5094 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005095 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305096 }
5097
5098 /* 301b */
5099 tempcx = pVBInfo->HT;
5100
5101 if (XGI_IsLCDDualLink(pVBInfo))
5102 tempcx = tempcx >> 1;
5103
5104 tempcx -= 2;
5105 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005106 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305107
5108 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005109 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305110
5111 tempcx = pVBInfo->HT >> 1;
5112 push1 = tempcx; /* push cx */
5113 tempcx += 7;
5114
5115 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5116 tempcx -= 4;
5117
5118 temp = tempcx & 0x00FF;
5119 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005120 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305121
5122 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5123 tempbx += tempcx;
5124 push2 = tempbx;
5125 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005126 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305127 temp = (tempbx & 0xFF00) >> 8;
5128 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005129 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305130
5131 tempbx = push2;
5132 tempbx = tempbx + 8;
5133 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5134 tempbx = tempbx - 4;
5135 tempcx = tempbx;
5136 }
5137
5138 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005139 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305140
5141 j += 2;
5142 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
5143 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005144 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305145 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005146 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305147
5148 tempcx += 8;
5149 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5150 tempcx -= 4;
5151
5152 temp = tempcx & 0xFF;
5153 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005154 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305155
5156 tempcx = push1; /* pop cx */
5157 j += 2;
5158 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5159 tempcx -= temp;
5160 temp = tempcx & 0x00FF;
5161 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005162 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305163
5164 tempcx -= 11;
5165
5166 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
5167 tempax = XGI_GetVGAHT2(pVBInfo);
5168 tempcx = tempax - 1;
5169 }
5170 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005171 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305172
5173 tempbx = pVBInfo->VDE;
5174
5175 if (pVBInfo->VGAVDE == 360)
5176 tempbx = 746;
5177 if (pVBInfo->VGAVDE == 375)
5178 tempbx = 746;
5179 if (pVBInfo->VGAVDE == 405)
5180 tempbx = 853;
5181
5182 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005183 if (pVBInfo->VBType &
5184 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
5185 if (!(pVBInfo->TVInfo &
5186 (SetYPbPrMode525p | SetYPbPrMode750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305187 tempbx = tempbx >> 1;
5188 } else
5189 tempbx = tempbx >> 1;
5190 }
5191
5192 tempbx -= 2;
5193 temp = tempbx & 0x00FF;
5194
5195 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5196 if (pVBInfo->VBType & VB_XGI301LV) {
5197 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5198 if (pVBInfo->VBInfo & SetInSlaveMode) {
5199 if (ModeNo == 0x2f)
5200 temp += 1;
5201 }
5202 }
5203 } else {
5204 if (pVBInfo->VBInfo & SetInSlaveMode) {
5205 if (ModeNo == 0x2f)
5206 temp += 1;
5207 }
5208 }
5209 }
5210
Aaro Koskinen8104e322011-03-13 12:26:22 +02005211 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305212
5213 temp = (tempcx & 0xFF00) >> 8;
5214 temp |= ((tempbx & 0xFF00) >> 8) << 6;
5215
5216 if (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) {
5217 if (pVBInfo->VBType & VB_XGI301LV) {
5218 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5219 temp |= 0x10;
5220
5221 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5222 temp |= 0x20;
5223 }
5224 } else {
5225 temp |= 0x10;
5226 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5227 temp |= 0x20;
5228 }
5229 }
5230
Aaro Koskinen8104e322011-03-13 12:26:22 +02005231 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305232
5233 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5234 | VB_XGI302LV | VB_XGI301C)) { /* TV gatingno */
5235 tempbx = pVBInfo->VDE;
5236 tempcx = tempbx - 2;
5237
5238 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5239 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p
5240 | SetYPbPrMode750p)))
5241 tempbx = tempbx >> 1;
5242 }
5243
5244 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
5245 temp = 0;
5246 if (tempcx & 0x0400)
5247 temp |= 0x20;
5248
5249 if (tempbx & 0x0400)
5250 temp |= 0x40;
5251
Aaro Koskinen8104e322011-03-13 12:26:22 +02005252 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305253 }
5254
5255 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005256 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305257 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005258 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305259 }
5260
5261 tempbx = tempbx & 0x00FF;
5262
5263 if (!(modeflag & HalfDCLK)) {
5264 tempcx = pVBInfo->VGAHDE;
5265 if (tempcx >= pVBInfo->HDE) {
5266 tempbx |= 0x2000;
5267 tempax &= 0x00FF;
5268 }
5269 }
5270
5271 tempcx = 0x0101;
5272
5273 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
5274 if (pVBInfo->VGAHDE >= 1024) {
5275 tempcx = 0x1920;
5276 if (pVBInfo->VGAHDE >= 1280) {
5277 tempcx = 0x1420;
5278 tempbx = tempbx & 0xDFFF;
5279 }
5280 }
5281 }
5282
5283 if (!(tempbx & 0x2000)) {
5284 if (modeflag & HalfDCLK)
5285 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
5286
5287 push1 = tempbx;
5288 tempeax = pVBInfo->VGAHDE;
5289 tempebx = (tempcx & 0xFF00) >> 8;
5290 longtemp = tempeax * tempebx;
5291 tempecx = tempcx & 0x00FF;
5292 longtemp = longtemp / tempecx;
5293
5294 /* 301b */
5295 tempecx = 8 * 1024;
5296
5297 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5298 | VB_XGI302LV | VB_XGI301C)) {
5299 tempecx = tempecx * 8;
5300 }
5301
5302 longtemp = longtemp * tempecx;
5303 tempecx = pVBInfo->HDE;
5304 temp2 = longtemp % tempecx;
5305 tempeax = longtemp / tempecx;
5306 if (temp2 != 0)
5307 tempeax += 1;
5308
5309 tempax = (unsigned short) tempeax;
5310
5311 /* 301b */
5312 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5313 | VB_XGI302LV | VB_XGI301C)) {
5314 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
5315 }
5316 /* end 301b */
5317
5318 tempbx = push1;
5319 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
5320 | (tempbx & 0x00FF));
5321 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
5322 | (tempax & 0x00FF));
5323 temp = (tempax & 0xFF00) >> 8;
5324 } else {
5325 temp = (tempax & 0x00FF) >> 8;
5326 }
5327
Aaro Koskinen8104e322011-03-13 12:26:22 +02005328 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305329 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005330 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305331 temp = tempcx & 0x00FF;
5332
5333 if (tempbx & 0x2000)
5334 temp = 0;
5335
5336 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5337 temp |= 0x18;
5338
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005339 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305340 if (pVBInfo->TVInfo & SetPALTV) {
5341 tempbx = 0x0382;
5342 tempcx = 0x007e;
5343 } else {
5344 tempbx = 0x0369;
5345 tempcx = 0x0061;
5346 }
5347
5348 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005349 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305350 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005351 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305352
5353 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
5354 temp = temp << 2;
5355 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
5356
5357 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5358 temp |= 0x10;
5359
5360 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5361 temp |= 0x20;
5362
5363 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5364 temp |= 0x60;
5365 }
5366
Aaro Koskinen8104e322011-03-13 12:26:22 +02005367 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005368 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005369 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305370
5371 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))) {
5372 if (pVBInfo->TVInfo & NTSC1024x768) {
5373 TimingPoint = XGI_NTSC1024AdjTime;
5374 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005375 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305376 TimingPoint[j]);
5377 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005378 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305379 }
5380 }
5381
5382 /* [ycchen] 01/14/03 Modify for 301C PALM Support */
5383 if (pVBInfo->VBType & VB_XGI301C) {
5384 if (pVBInfo->TVInfo & SetPALMTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005385 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305386 0x08); /* PALM Mode */
5387 }
5388
5389 if (pVBInfo->TVInfo & SetPALMTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005390 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305391 0x01);
5392 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02005393 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305394
5395 /* if ( !( pVBInfo->VBType & VB_XGI301C ) ) */
Aaro Koskinendc505562011-03-13 12:26:26 +02005396 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305397 }
5398
5399 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5400 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02005401 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305402 }
5403
5404 if (pVBInfo->VBInfo & SetCRT2ToTV)
5405 return;
5406}
5407
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005408static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305409 struct xgi_hw_device_info *HwDeviceExtension,
5410 unsigned short RefreshRateTableIndex,
5411 struct vb_device_info *pVBInfo)
5412{
5413 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
5414 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
5415
5416 struct XGI_LCDDesStruct *LCDBDesPtr = NULL;
5417
5418 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005419 /* si+St_ResInfo */
5420 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305421 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
5422 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005423 /* si+Ext_ResInfo */
5424 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305425 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005426 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
5427 Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305428 CRT1Index &= IndexMask;
5429 }
5430
5431 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5432 return;
5433
5434 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
5435
5436 if (XGI_IsLCDDualLink(pVBInfo))
5437 tempbx = tempbx >> 1;
5438
5439 tempbx -= 1;
5440 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005441 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305442 temp = (tempbx & 0xFF00) >> 8;
5443 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005444 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305445 temp = 0x01;
5446
5447 if (pVBInfo->LCDResInfo == Panel1280x1024) {
5448 if (pVBInfo->ModeType == ModeEGA) {
5449 if (pVBInfo->VGAHDE >= 1024) {
5450 temp = 0x02;
5451 if (pVBInfo->LCDInfo & LCDVESATiming)
5452 temp = 0x01;
5453 }
5454 }
5455 }
5456
Aaro Koskinen8104e322011-03-13 12:26:22 +02005457 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305458 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
5459 push1 = tempbx;
5460 tempbx--;
5461 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005462 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305463 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005464 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305465
5466 tempcx = pVBInfo->VT - 1;
5467 push2 = tempcx + 1;
5468 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005469 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305470 temp = (tempcx & 0xFF00) >> 8;
5471 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005472 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005473 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
5474 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
5475 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
5476 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305477
5478 /* Customized LCDB Des no add */
5479 tempbx = 5;
5480 LCDBDesPtr = (struct XGI_LCDDesStruct *) XGI_GetLcdPtr(tempbx, ModeNo,
5481 ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5482 tempah = pVBInfo->LCDResInfo;
5483 tempah &= PanelResInfo;
5484
5485 if ((tempah == Panel1024x768) || (tempah == Panel1024x768x75)) {
5486 tempbx = 1024;
5487 tempcx = 768;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005488 } else if ((tempah == Panel1280x1024) ||
5489 (tempah == Panel1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305490 tempbx = 1280;
5491 tempcx = 1024;
5492 } else if (tempah == Panel1400x1050) {
5493 tempbx = 1400;
5494 tempcx = 1050;
5495 } else {
5496 tempbx = 1600;
5497 tempcx = 1200;
5498 }
5499
5500 if (pVBInfo->LCDInfo & EnableScalingLCD) {
5501 tempbx = pVBInfo->HDE;
5502 tempcx = pVBInfo->VDE;
5503 }
5504
5505 pushbx = tempbx;
5506 tempax = pVBInfo->VT;
5507 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
5508 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
5509 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
5510 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
5511 tempbx = pVBInfo->LCDVDES;
5512 tempcx += tempbx;
5513
5514 if (tempcx >= tempax)
5515 tempcx -= tempax; /* lcdvdes */
5516
5517 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005518 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305519 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005520 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305521 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
5522 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
5523 tempah = tempch;
5524 tempah = tempah << 3;
5525 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005526 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305527
5528 /* getlcdsync() */
5529 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5530 tempcx = tempbx;
5531 tempax = pVBInfo->VT;
5532 tempbx = pVBInfo->LCDVRS;
5533
5534 /* if (SetLCD_Info & EnableScalingLCD) */
5535 tempcx += tempbx;
5536 if (tempcx >= tempax)
5537 tempcx -= tempax;
5538
5539 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005540 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305541 temp = (tempbx & 0xFF00) >> 8;
5542 temp = temp << 4;
5543 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005544 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305545 tempcx = pushbx;
5546 tempax = pVBInfo->HT;
5547 tempbx = pVBInfo->LCDHDES;
5548 tempbx &= 0x0FFF;
5549
5550 if (XGI_IsLCDDualLink(pVBInfo)) {
5551 tempax = tempax >> 1;
5552 tempbx = tempbx >> 1;
5553 tempcx = tempcx >> 1;
5554 }
5555
5556 if (pVBInfo->VBType & VB_XGI302LV)
5557 tempbx += 1;
5558
5559 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
5560 tempbx += 1;
5561
5562 tempcx += tempbx;
5563
5564 if (tempcx >= tempax)
5565 tempcx -= tempax;
5566
5567 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005568 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305569 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005570 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305571 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005572 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305573 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005574 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305575
5576 /* getlcdsync() */
5577 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5578 tempcx = tempax;
5579 tempax = pVBInfo->HT;
5580 tempbx = pVBInfo->LCDHRS;
5581 /* if ( SetLCD_Info & EnableScalingLCD) */
5582 if (XGI_IsLCDDualLink(pVBInfo)) {
5583 tempax = tempax >> 1;
5584 tempbx = tempbx >> 1;
5585 tempcx = tempcx >> 1;
5586 }
5587
5588 if (pVBInfo->VBType & VB_XGI302LV)
5589 tempbx += 1;
5590
5591 tempcx += tempbx;
5592
5593 if (tempcx >= tempax)
5594 tempcx -= tempax;
5595
5596 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005597 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305598
5599 temp = (tempbx & 0xFF00) >> 8;
5600 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005601 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305602 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005603 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305604
5605 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
5606 if (pVBInfo->VGAVDE == 525) {
5607 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5608 | VB_XGI301LV | VB_XGI302LV
5609 | VB_XGI301C)) {
5610 temp = 0xC6;
5611 } else
5612 temp = 0xC4;
5613
Aaro Koskinen8104e322011-03-13 12:26:22 +02005614 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
5615 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305616 }
5617
5618 if (pVBInfo->VGAVDE == 420) {
5619 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5620 | VB_XGI301LV | VB_XGI302LV
5621 | VB_XGI301C)) {
5622 temp = 0x4F;
5623 } else
5624 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005625 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305626 }
5627 }
5628}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005629
5630/* --------------------------------------------------------------------- */
5631/* Function : XGI_GetTap4Ptr */
5632/* Input : */
5633/* Output : di -> Tap4 Reg. Setting Pointer */
5634/* Description : */
5635/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005636static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305637 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005638{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305639 unsigned short tempax, tempbx, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005640
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305641 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005642
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305643 if (tempcx == 0) {
5644 tempax = pVBInfo->VGAHDE;
5645 tempbx = pVBInfo->HDE;
5646 } else {
5647 tempax = pVBInfo->VGAVDE;
5648 tempbx = pVBInfo->VDE;
5649 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005650
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305651 if (tempax < tempbx)
5652 return &EnlargeTap4Timing[0];
5653 else if (tempax == tempbx)
5654 return &NoScaleTap4Timing[0]; /* 1:1 */
5655 else
5656 Tap4TimingPtr = NTSCTap4Timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005657
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305658 if (pVBInfo->TVInfo & SetPALTV)
5659 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005660
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305661 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5662 if (pVBInfo->TVInfo & SetYPbPrMode525i)
5663 Tap4TimingPtr = YPbPr525iTap4Timing;
5664 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5665 Tap4TimingPtr = YPbPr525pTap4Timing;
5666 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5667 Tap4TimingPtr = YPbPr750pTap4Timing;
5668 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005669
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305670 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5671 Tap4TimingPtr = HiTVTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005672
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305673 i = 0;
5674 while (Tap4TimingPtr[i].DE != 0xFFFF) {
5675 if (Tap4TimingPtr[i].DE == tempax)
5676 break;
5677 i++;
5678 }
5679 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005680}
5681
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005682static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005683{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305684 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005685
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305686 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005687
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305688 if (!(pVBInfo->VBType & VB_XGI301C))
5689 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005690
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305691 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
5692 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005693 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005694
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005695 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5696 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV))) {
5697 /* Set Vertical Scaling */
5698 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305699 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005700 xgifb_reg_set(pVBInfo->Part2Port,
5701 i,
5702 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305703 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005704
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005705 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5706 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)))
5707 /* Enable V.Scaling */
5708 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305709 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005710 /* Enable H.Scaling */
5711 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005712}
5713
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005714static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305715 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005716{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305717 unsigned short i;
5718 unsigned char *tempdi;
5719 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005720
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305721 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005722 /* si+St_ResInfo */
5723 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305724 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005725 /* si+Ext_ResInfo */
5726 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005727
Aaro Koskinen8104e322011-03-13 12:26:22 +02005728 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305729 if (pVBInfo->TVInfo & SetPALTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005730 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5731 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305732 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005733 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
5734 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305735 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005736
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305737 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5738 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005739
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305740 if (pVBInfo->TVInfo & SetPALMTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005741 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5742 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
5743 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305744 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005745
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305746 if ((pVBInfo->VBInfo & SetCRT2ToHiVisionTV) || (pVBInfo->VBInfo
5747 & SetCRT2ToYPbPr)) {
5748 if (pVBInfo->TVInfo & SetYPbPrMode525i)
5749 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005750
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305751 tempdi = pVBInfo->HiTVGroup3Data;
5752 if (pVBInfo->SetFlag & TVSimuMode) {
5753 tempdi = pVBInfo->HiTVGroup3Simu;
5754 if (!(modeflag & Charx8Dot))
5755 tempdi = pVBInfo->HiTVGroup3Text;
5756 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005757
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305758 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5759 tempdi = pVBInfo->Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005760
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305761 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5762 tempdi = pVBInfo->Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005763
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305764 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005765 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005766
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305767 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
5768 if (pVBInfo->TVInfo & SetYPbPrMode525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005769 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305770 }
5771 }
5772 return;
5773} /* {end of XGI_SetGroup3} */
5774
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005775static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305776 unsigned short RefreshRateTableIndex,
5777 struct xgi_hw_device_info *HwDeviceExtension,
5778 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005779{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305780 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005781
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305782 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005783
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305784 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005785 /* si+St_ResInfo */
5786 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305787 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005788 /* si+Ext_ResInfo */
5789 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005790
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305791 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005792 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005793
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305794 tempbx = pVBInfo->RVBHCMAX;
5795 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005796 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305797 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
5798 tempcx = pVBInfo->VGAHT - 1;
5799 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005800 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005801
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305802 temp = ((tempcx & 0xFF00) >> 8) << 3;
5803 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005804
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305805 tempcx = pVBInfo->VGAVT - 1;
5806 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5807 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005808
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305809 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005810 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305811 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005812 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005813 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305814 tempcx = pVBInfo->VBInfo;
5815 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005816
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305817 if (modeflag & HalfDCLK)
5818 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005819
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305820 if (XGI_IsLCDDualLink(pVBInfo))
5821 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005822
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305823 if (tempcx & SetCRT2ToHiVisionTV) {
5824 temp = 0;
5825 if (tempbx <= 1024)
5826 temp = 0xA0;
5827 if (tempbx == 1280)
5828 temp = 0xC0;
5829 } else if (tempcx & SetCRT2ToTV) {
5830 temp = 0xA0;
5831 if (tempbx <= 800)
5832 temp = 0x80;
5833 } else {
5834 temp = 0x80;
5835 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5836 temp = 0;
5837 if (tempbx > 800)
5838 temp = 0x60;
5839 }
5840 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005841
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305842 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p)) {
5843 temp = 0x00;
5844 if (pVBInfo->VGAHDE == 1280)
5845 temp = 0x40;
5846 if (pVBInfo->VGAHDE == 1024)
5847 temp = 0x20;
5848 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005849 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005850
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305851 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005852
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305853 if (tempcx & SetCRT2ToHiVisionTV) {
5854 if (!(temp & 0xE000))
5855 tempbx = tempbx >> 1;
5856 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005857
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305858 tempcx = pVBInfo->RVBHRS;
5859 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005860 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005861
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305862 tempeax = pVBInfo->VGAVDE;
5863 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005864
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305865 if (tempeax <= tempebx) {
5866 tempcx = (tempcx & (~0x4000));
5867 tempeax = pVBInfo->VGAVDE;
5868 } else {
5869 tempeax -= tempebx;
5870 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005871
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305872 templong = (tempeax * 256 * 1024) % tempebx;
5873 tempeax = (tempeax * 256 * 1024) / tempebx;
5874 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005875
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305876 if (templong != 0)
5877 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005878
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305879 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005880 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005881
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305882 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005883 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305884 tempbx = (unsigned short) (tempebx >> 16);
5885 temp = tempbx & 0x00FF;
5886 temp = temp << 4;
5887 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005888 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005889
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305890 /* 301b */
5891 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5892 | VB_XGI302LV | VB_XGI301C)) {
5893 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005894 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305895 tempax = pVBInfo->VGAHDE;
5896 if (modeflag & HalfDCLK)
5897 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005898
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305899 if (XGI_IsLCDDualLink(pVBInfo))
5900 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005901
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005902 /* if((pVBInfo->VBInfo&(SetCRT2ToLCD)) ||
5903 ((pVBInfo->TVInfo&SetYPbPrMode525p) ||
5904 (pVBInfo->TVInfo&SetYPbPrMode750p))) { */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305905 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5906 if (tempax > 800)
5907 tempax -= 800;
5908 } else {
5909 if (pVBInfo->VGAHDE > 800) {
5910 if (pVBInfo->VGAHDE == 1024)
5911 tempax = (tempax * 25 / 32) - 1;
5912 else
5913 tempax = (tempax * 20 / 32) - 1;
5914 }
5915 }
5916 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005917
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305918 /*
5919 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
5920 if (pVBInfo->VBType & VB_XGI301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005921 if (!(pVBInfo->TVInfo &
5922 (SetYPbPrMode525p |
5923 SetYPbPrMode750p |
5924 SetYPbPrMode1080i))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305925 if (pVBInfo->VGAHDE > 800) {
5926 if (pVBInfo->VGAHDE == 1024)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005927 tempax =(tempax * 25 /
5928 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305929 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005930 tempax = (tempax * 20 /
5931 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305932 }
5933 }
5934 } else {
5935 if (pVBInfo->VGAHDE > 800) {
5936 if (pVBInfo->VGAHDE == 1024)
5937 tempax = (tempax * 25 / 32) - 1;
5938 else
5939 tempax = (tempax * 20 / 32) - 1;
5940 }
5941 }
5942 }
5943 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005944
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305945 temp = (tempax & 0xFF00) >> 8;
5946 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005947 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305948 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005949 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005950
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305951 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
5952 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005953 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005954
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305955 }
5956 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005957
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305958 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5959 if (!(pVBInfo->TVInfo & (NTSC1024x768
5960 | SetYPbPrMode525p | SetYPbPrMode750p
5961 | SetYPbPrMode1080i))) {
5962 temp |= 0x0001;
5963 if ((pVBInfo->VBInfo & SetInSlaveMode)
5964 && (!(pVBInfo->TVInfo
5965 & TVSimuMode)))
5966 temp &= (~0x0001);
5967 }
5968 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005969
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005970 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305971 tempbx = pVBInfo->HT;
5972 if (XGI_IsLCDDualLink(pVBInfo))
5973 tempbx = tempbx >> 1;
5974 tempbx = (tempbx >> 1) - 2;
5975 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005976 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305977 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005978 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305979 }
5980 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005981
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305982 if (pVBInfo->ISXPDOS == 0)
5983 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5984 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005985}
5986
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005987static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
5988{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005989 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005990}
5991
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005992static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305993 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005994{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305995 unsigned short Pindex, Pdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005996
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305997 Pindex = pVBInfo->Part5Port;
5998 Pdata = pVBInfo->Part5Port + 1;
5999 if (pVBInfo->ModeType == ModeVGA) {
6000 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
6001 | CRT2DisplayFlag))) {
6002 XGINew_EnableCRT2(pVBInfo);
6003 /* LoadDAC2(pVBInfo->Part5Port, ModeNo, ModeIdIndex); */
6004 }
6005 }
6006 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006007}
6008
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006009static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306010 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006011{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006012 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006013}
6014
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006015static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306016 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006017{
6018
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006019 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006020}
6021
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006022/*----------------------------------------------------------------------------*/
6023/* input */
6024/* bl[5] : 1;LVDS signal on */
6025/* bl[1] : 1;LVDS backlight on */
6026/* bl[0] : 1:LVDS VDD on */
6027/* bh: 100000b : clear bit 5, to set bit5 */
6028/* 000010b : clear bit 1, to set bit1 */
6029/* 000001b : clear bit 0, to set bit0 */
6030/*----------------------------------------------------------------------------*/
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306031void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
6032 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006033{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306034 unsigned char CR4A, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006035
Aaro Koskinen58839b02011-03-13 12:26:23 +02006036 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306037 tempbh &= 0x23;
6038 tempbl &= 0x23;
Aaro Koskinendc505562011-03-13 12:26:26 +02006039 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006040
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306041 if (tempbh & 0x20) {
6042 temp = (tempbl >> 4) & 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006043
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006044 /* CR B4[1] */
6045 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006046
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306047 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006048
Aaro Koskinen58839b02011-03-13 12:26:23 +02006049 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006050
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306051 temp = XG21GPIODataTransfer(temp);
6052 temp &= ~tempbh;
6053 temp |= tempbl;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006054 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006055}
6056
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306057void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
6058 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006059{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306060 unsigned char CR4A, temp;
6061 unsigned short tempbh0, tempbl0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006062
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306063 tempbh0 = tempbh;
6064 tempbl0 = tempbl;
6065 tempbh0 &= 0x20;
6066 tempbl0 &= 0x20;
6067 tempbh0 >>= 3;
6068 tempbl0 >>= 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006069
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306070 if (tempbh & 0x20) {
6071 temp = (tempbl >> 4) & 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006072
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006073 /* CR B4[1] */
6074 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006075
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306076 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006077 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006078
Aaro Koskinen58839b02011-03-13 12:26:23 +02006079 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306080 tempbh &= 0x03;
6081 tempbl &= 0x03;
6082 tempbh <<= 2;
6083 tempbl <<= 2; /* GPIOC,GPIOD */
Aaro Koskinendc505562011-03-13 12:26:26 +02006084 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006085 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006086}
6087
6088/* --------------------------------------------------------------------- */
Bill Pemberton80adad82010-06-17 13:10:51 -04006089unsigned short XGI_GetLVDSOEMTableIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006090{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306091 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006092
Aaro Koskinen58839b02011-03-13 12:26:23 +02006093 index = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306094 if (index < sizeof(XGI21_LCDCapList)
6095 / sizeof(struct XGI21_LVDSCapStruct))
6096 return index;
6097 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006098}
6099
6100/* --------------------------------------------------------------------- */
6101/* Function : XGI_XG21SetPanelDelay */
6102/* Input : */
6103/* Output : */
6104/* Description : */
6105/* I/P : bl : 1 ; T1 : the duration between CPL on and signal on */
6106/* : bl : 2 ; T2 : the duration signal on and Vdd on */
6107/* : bl : 3 ; T3 : the duration between CPL off and signal off */
6108/* : bl : 4 ; T4 : the duration signal off and Vdd off */
6109/* --------------------------------------------------------------------- */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306110void XGI_XG21SetPanelDelay(unsigned short tempbl,
6111 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006112{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306113 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006114
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306115 index = XGI_GetLVDSOEMTableIndex(pVBInfo);
6116 if (tempbl == 1)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006117 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006118
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306119 if (tempbl == 2)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006120 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006121
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306122 if (tempbl == 3)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006123 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S3);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006124
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306125 if (tempbl == 4)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006126 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S4);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006127}
6128
Bill Pemberton82d6eb52010-06-17 13:10:46 -04006129unsigned char XGI_XG21CheckLVDSMode(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306130 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006131{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306132 unsigned short xres, yres, colordepth, modeflag, resindex,
6133 lvdstableindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306135 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6136 if (ModeNo <= 0x13) {
6137 xres = pVBInfo->StResInfo[resindex].HTotal;
6138 yres = pVBInfo->StResInfo[resindex].VTotal;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006139 /* si+St_ResInfo */
6140 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306141 } else {
6142 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6143 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006144 /* si+St_ModeFlag */
6145 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306146 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006147
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306148 if (!(modeflag & Charx8Dot)) {
6149 xres /= 9;
6150 xres *= 8;
6151 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006152
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306153 if (ModeNo > 0x13) {
6154 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
6155 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006156
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306157 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6158 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006159
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306160 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006161
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306162 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
6163 if (xres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE))
6164 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04006165
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306166 if (yres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE))
6167 return 0;
6168
6169 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006170 if ((xres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6171 LVDSHDE)) ||
6172 (yres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6173 LVDSVDE))) {
6174 colordepth = XGI_GetColorDepth(ModeNo,
6175 ModeIdIndex,
6176 pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306177 if (colordepth > 2)
6178 return 0;
6179
6180 }
6181 }
6182 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006183}
6184
Bill Pemberton80adad82010-06-17 13:10:51 -04006185void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006186{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306187 unsigned char temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006188
Aaro Koskinen58839b02011-03-13 12:26:23 +02006189 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306190 temp = (temp & 1) << 6;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006191 /* SR06[6] 18bit Dither */
6192 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
6193 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
6194 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006195
6196}
6197
Bill Pemberton80adad82010-06-17 13:10:51 -04006198void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006199{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306200 unsigned char temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006201
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006202 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
6203 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306204 temp = (temp & 3) << 6;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006205 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
6206 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
6207 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
6208 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006209
6210}
6211
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006212static void xgifb_set_lvds(int chip_id,
6213 unsigned short ModeNo,
6214 unsigned short ModeIdIndex,
6215 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006216{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306217 unsigned char temp, Miscdata;
6218 unsigned short xres, yres, modeflag, resindex, lvdstableindex;
6219 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
6220 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
6221 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006222
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306223 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006224 temp = (unsigned char) ((pVBInfo->XG21_LVDSCapList[lvdstableindex].
6225 LVDS_Capability &
6226 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306227 temp &= LCDPolarity;
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006228 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006229
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006230 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006231
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006232 temp = (unsigned char) (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6233 LVDS_Capability & LCDPolarity);
6234 /* SR35[7] FP VSync polarity */
6235 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
6236 /* SR30[5] FP HSync polarity */
6237 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006238
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006239 if (chip_id == XG27)
6240 XGI_SetXG27FPBits(pVBInfo);
6241 else
6242 XGI_SetXG21FPBits(pVBInfo);
6243
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306244 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6245 if (ModeNo <= 0x13) {
6246 xres = pVBInfo->StResInfo[resindex].HTotal;
6247 yres = pVBInfo->StResInfo[resindex].VTotal;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006248 /* si+St_ResInfo */
6249 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306250 } else {
6251 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6252 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006253 /* si+St_ModeFlag */
6254 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306255 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006256
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306257 if (!(modeflag & Charx8Dot))
6258 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006259
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306260 LVDSHT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006261
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306262 LVDSHBS = xres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE
6263 - xres) / 2;
6264 if ((ModeNo <= 0x13) && (modeflag & HalfDCLK))
6265 LVDSHBS -= xres / 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006266
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306267 if (LVDSHBS > LVDSHT)
6268 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006269
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306270 LVDSHRS = LVDSHBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHFP;
6271 if (LVDSHRS > LVDSHT)
6272 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006273
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306274 LVDSHRE = LVDSHRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHSYNC;
6275 if (LVDSHRE > LVDSHT)
6276 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006277
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306278 LVDSHBE = LVDSHBS + LVDSHT
6279 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006280
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306281 LVDSVT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006282
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306283 LVDSVBS = yres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE
6284 - yres) / 2;
6285 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6286 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006287
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306288 if (LVDSVBS > LVDSVT)
6289 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006290
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306291 LVDSVRS = LVDSVBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVFP;
6292 if (LVDSVRS > LVDSVT)
6293 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006294
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006295 LVDSVRE = LVDSVRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].
6296 LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306297 if (LVDSVRE > LVDSVT)
6298 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006299
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306300 LVDSVBE = LVDSVBS + LVDSVT
6301 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006302
Aaro Koskinen58839b02011-03-13 12:26:23 +02006303 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006304 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006305
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306306 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006307 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006308
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306309 /* HT SR0B[1:0] CR00 */
6310 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006311 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006312 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006313
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306314 /* HBS SR0B[5:4] CR02 */
6315 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006316 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006317 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006318
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306319 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
6320 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006321 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
6322 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
6323 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006324
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306325 /* HRS SR0B[7:6] CR04 */
6326 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006327 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006328 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006329
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306330 /* Panel HRS SR2F[1:0] SR2E[7:0] */
6331 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006332 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006333 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006334
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306335 /* HRE SR0C[2] CR05[4:0] */
6336 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006337 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
6338 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006339
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306340 /* Panel HRE SR2F[7:2] */
6341 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006342 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006343
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306344 /* VT SR0A[0] CR07[5][0] CR06 */
6345 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006346 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
6347 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
6348 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006349 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006350
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306351 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
6352 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006353 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
6354 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
6355 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006356 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006357
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306358 /* VBE SR0A[4] CR16 */
6359 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006360 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006361 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006362
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306363 /* VRS SR0A[3] CR7[7][2] CR10 */
6364 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006365 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
6366 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
6367 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006368 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006369
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006370 if (chip_id == XG27) {
6371 /* Panel VRS SR35[2:0] SR34[7:0] */
6372 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
6373 (value & 0x700) >> 8);
6374 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
6375 } else {
6376 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
6377 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
6378 (value & 0x600) >> 9);
6379 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
6380 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
6381 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006382
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306383 /* VRE SR0A[5] CR11[3:0] */
6384 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006385 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
6386 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006387
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306388 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006389 if (chip_id == XG27)
6390 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6391 (value << 2) & 0xFC);
6392 else
6393 /* SR3F[7] has to be 0, h/w bug */
6394 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6395 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006396
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306397 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006398
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006399 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006400 xgifb_reg_set(pVBInfo->P3c4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006401 0x2B,
6402 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6403 VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006404 xgifb_reg_set(pVBInfo->P3c4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006405 0x2C,
6406 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6407 VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306408 value += 0x10;
6409 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006410
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306411 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006412 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006413 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006414 /* set data, panning = 0, shift left 1 dot*/
6415 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006416
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006417 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006418 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306419
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006420 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306421 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006422
6423}
6424
6425/* --------------------------------------------------------------------- */
6426/* Function : XGI_IsLCDON */
6427/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04006428/* Output : 0 : Skip PSC Control */
6429/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006430/* Description : */
6431/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006432static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006433{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306434 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006435
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306436 tempax = pVBInfo->VBInfo;
6437 if (tempax & SetCRT2ToDualEdge)
6438 return 0;
6439 else if (tempax & (DisableCRT2Display | SwitchToCRT2 | SetSimuScanMode))
6440 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006441
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306442 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006443}
6444
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006445/* --------------------------------------------------------------------- */
6446/* Function : XGI_DisableChISLCD */
6447/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04006448/* Output : 0 -> Not LCD Mode */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006449/* Description : */
6450/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006451static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006452{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306453 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006454
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306455 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02006456 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006457
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306458 if (tempbx & (EnableChA | DisableChA)) {
6459 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6460 return 0;
6461 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006462
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306463 if (!(tempbx & (EnableChB | DisableChB)))
6464 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006465
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306466 if (tempah & 0x01) /* Chk LCDB Mode */
6467 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006468
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306469 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006470}
6471
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006472/* --------------------------------------------------------------------- */
6473/* Function : XGI_EnableChISLCD */
6474/* Input : */
6475/* Output : 0 -> Not LCD mode */
6476/* Description : */
6477/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006478static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006479{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306480 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006481
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306482 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02006483 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006484
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306485 if (tempbx & (EnableChA | DisableChA)) {
6486 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6487 return 0;
6488 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006489
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306490 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04006491 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006492
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306493 if (tempah & 0x01) /* Chk LCDB Mode */
6494 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006495
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306496 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006497}
6498
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306499void XGI_DisableBridge(struct xgi_hw_device_info *HwDeviceExtension,
6500 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006501{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02006502 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006503
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306504 if (pVBInfo->SetFlag == Win9xDOSMode)
6505 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006506
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306507 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6508 | VB_XGI302LV | VB_XGI301C)) {
6509 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006510 if (!(pVBInfo->VBInfo &
6511 (DisableCRT2Display | SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306512 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6513 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6514 tempah = 0x7F; /* Disable Channel A */
6515 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006516 /* Disable Channel B */
6517 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006518
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306519 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006520 /* force to disable Cahnnel */
6521 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006522
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306523 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006524 /* Force to disable Channel B */
6525 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306526 }
6527 }
6528 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006529
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006530 /* disable part4_1f */
6531 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006532
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306533 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6534 if (((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
6535 || (XGI_DisableChISLCD(pVBInfo))
6536 || (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006537 /* LVDS Driver power down */
6538 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306539 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006540
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306541 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6542 & (DisableCRT2Display | SetCRT2ToLCDA
6543 | SetSimuScanMode))) {
6544 if (pVBInfo->SetFlag & GatingCRT)
6545 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
6546 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6547 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006548
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306549 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6550 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6551 & SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006552 /* Power down */
6553 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306554 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006555
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006556 /* disable TV as primary VGA swap */
6557 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006558
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306559 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02006560 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006561
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006562 if ((pVBInfo->SetFlag & DisableChB) ||
6563 (pVBInfo->VBInfo &
6564 (DisableCRT2Display | SetSimuScanMode)) ||
6565 ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) &&
6566 (pVBInfo->VBInfo &
6567 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
6568 /* BScreenOff=1 */
6569 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006570
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006571 if ((pVBInfo->SetFlag & DisableChB) ||
6572 (pVBInfo->VBInfo &
6573 (DisableCRT2Display | SetSimuScanMode)) ||
6574 (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) ||
6575 (pVBInfo->VBInfo &
6576 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
6577 /* save Part1 index 0 */
6578 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
6579 /* BTDAC = 1, avoid VB reset */
6580 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
6581 /* disable CRT2 */
6582 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6583 /* restore Part1 index 0 */
6584 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306585 }
6586 } else { /* {301} */
6587 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006588 /* BScreenOff=1 */
6589 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
6590 /* Disable CRT2 */
6591 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6592 /* Disable TV asPrimary VGA swap */
6593 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306594 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006595
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306596 if (pVBInfo->VBInfo & (DisableCRT2Display | SetCRT2ToLCDA
6597 | SetSimuScanMode))
6598 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6599 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006600}
6601
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006602/* --------------------------------------------------------------------- */
6603/* Function : XGI_GetTVPtrIndex */
6604/* Input : */
6605/* Output : */
6606/* Description : bx 0 : ExtNTSC */
6607/* 1 : StNTSC */
6608/* 2 : ExtPAL */
6609/* 3 : StPAL */
6610/* 4 : ExtHiTV */
6611/* 5 : StHiTV */
6612/* 6 : Ext525i */
6613/* 7 : St525i */
6614/* 8 : Ext525p */
6615/* 9 : St525p */
6616/* A : Ext750p */
6617/* B : St750p */
6618/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006619static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006620{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306621 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006622
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306623 if (pVBInfo->TVInfo & SetPALTV)
6624 tempbx = 2;
6625 if (pVBInfo->TVInfo & SetYPbPrMode1080i)
6626 tempbx = 4;
6627 if (pVBInfo->TVInfo & SetYPbPrMode525i)
6628 tempbx = 6;
6629 if (pVBInfo->TVInfo & SetYPbPrMode525p)
6630 tempbx = 8;
6631 if (pVBInfo->TVInfo & SetYPbPrMode750p)
6632 tempbx = 10;
6633 if (pVBInfo->TVInfo & TVSimuMode)
6634 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006635
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306636 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006637}
6638
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006639/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006640/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006641/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006642/* Output : bx 0 : NTSC */
6643/* 1 : PAL */
6644/* 2 : PALM */
6645/* 3 : PALN */
6646/* 4 : NTSC1024x768 */
6647/* 5 : PAL-M 1024x768 */
6648/* 6-7: reserved */
6649/* cl 0 : YFilter1 */
6650/* 1 : YFilter2 */
6651/* ch 0 : 301A */
6652/* 1 : 301B/302B/301LV/302LV */
6653/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006654/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006655static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
6656 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006657{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006658 *tempbx = 0;
6659 *tempcl = 0;
6660 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006661
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006662 if (pVBInfo->TVInfo & SetPALTV)
6663 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006664
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006665 if (pVBInfo->TVInfo & SetPALMTV)
6666 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006667
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006668 if (pVBInfo->TVInfo & SetPALNTV)
6669 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006670
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006671 if (pVBInfo->TVInfo & NTSC1024x768) {
6672 *tempbx = 4;
6673 if (pVBInfo->TVInfo & SetPALMTV)
6674 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306675 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006676
6677 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6678 | VB_XGI302LV | VB_XGI301C)) {
6679 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
6680 & TVSimuMode)) {
6681 *tempbx += 8;
6682 *tempcl += 1;
6683 }
6684 }
6685
6686 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6687 | VB_XGI302LV | VB_XGI301C))
6688 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006689}
6690
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006691static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006692{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306693 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006694
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306695 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006696
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306697 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6698 | VB_XGI302LV | VB_XGI301C)) {
6699 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA
6700 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
6701 tempbl = 0;
6702 tempbh = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006703
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306704 index = XGI_GetTVPtrIndex(pVBInfo); /* Get TV Delay */
6705 tempbl = pVBInfo->XGI_TVDelayList[index];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006706
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306707 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
6708 | VB_XGI301LV | VB_XGI302LV
6709 | VB_XGI301C))
6710 tempbl = pVBInfo->XGI_TVDelayList2[index];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006711
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306712 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6713 tempbl = tempbl >> 4;
6714 /*
6715 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
6716 tempbl = CRT2Delay1; // Get CRT2 Delay
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006717 if (pVBInfo->VBType &
6718 (VB_XGI301B |
6719 VB_XGI302B |
6720 VB_XGI301LV |
6721 VB_XGI302LV |
6722 VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306723 tempbl = CRT2Delay2;
6724 */
6725 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006726 /* Get LCD Delay */
6727 index = XGI_GetLCDCapPtr(pVBInfo);
6728 tempbh = pVBInfo->LCDCapList[index].
6729 LCD_DelayCompensation;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006730
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306731 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
6732 tempbl = tempbh;
6733 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006734
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306735 tempbl &= 0x0F;
6736 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02006737 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006738
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306739 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
6740 | SetCRT2ToTV)) { /* Channel B */
6741 tempah &= 0xF0;
6742 tempah |= tempbl;
6743 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006744
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306745 if (pVBInfo->VBInfo & SetCRT2ToLCDA) { /* Channel A */
6746 tempah &= 0x0F;
6747 tempah |= tempbh;
6748 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02006749 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306750 }
6751 } else if (pVBInfo->IF_DEF_LVDS == 1) {
6752 tempbl = 0;
6753 tempbh = 0;
6754 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006755 /* / Get LCD Delay */
6756 tempah = pVBInfo->LCDCapList[
6757 XGI_GetLCDCapPtr(pVBInfo)].
6758 LCD_DelayCompensation;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306759 tempah &= 0x0f;
6760 tempah = tempah << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006761 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306762 tempah);
6763 }
6764 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006765}
6766
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006767static void XGI_SetLCDCap_A(unsigned short tempcx,
6768 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006769{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306770 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006771
Aaro Koskinen58839b02011-03-13 12:26:23 +02006772 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006773
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306774 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006775 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006776 /* Enable Dither */
6777 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006778 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306779 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006780 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306781 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006782 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306783 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006784
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306785 /*
6786 if (tempcx & EnableLCD24bpp) { // 24bits
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006787 xgifb_reg_and_or(pVBInfo->Part1Port,
6788 0x19,
6789 0x0F,
6790 (unsigned short)(0x30 | (tempcx&0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006791 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306792 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006793 xgifb_reg_and_or(pVBInfo->Part1Port,
6794 0x19,
6795 0x0F,
6796 // Enable Dither
6797 (unsigned short)(0x20 | (tempcx&0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006798 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306799 }
6800 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006801}
6802
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006803/* --------------------------------------------------------------------- */
6804/* Function : XGI_SetLCDCap_B */
6805/* Input : cx -> LCD Capability */
6806/* Output : */
6807/* Description : */
6808/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006809static void XGI_SetLCDCap_B(unsigned short tempcx,
6810 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006811{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306812 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006813 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306814 (unsigned short) (((tempcx & 0x00ff) >> 6)
6815 | 0x0c));
6816 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006817 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306818 (unsigned short) (((tempcx & 0x00ff) >> 6)
6819 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006820}
6821
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006822static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006823{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306824 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006825
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306826 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006827
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006828 /* disable down spectrum D[4] */
6829 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306830 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006831 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306832 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006833
Aaro Koskinen8104e322011-03-13 12:26:22 +02006834 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306835 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006836 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306837 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006838 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306839 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006840 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306841 pVBInfo->LCDCapList[index].Spectrum_34);
6842 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006843 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006844}
6845
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006846static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
6847{
6848 unsigned short tempcx;
6849
6850 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
6851
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006852 if (pVBInfo->VBType &
6853 (VB_XGI301B |
6854 VB_XGI302B |
6855 VB_XGI301LV |
6856 VB_XGI302LV |
6857 VB_XGI301C)) { /* 301LV/302LV only */
6858 if (pVBInfo->VBType &
6859 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006860 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02006861 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006862 (unsigned char) (tempcx & 0x1F));
6863 }
6864 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006865 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006866 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
6867 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
6868 | EnablePLLSPLOW)) >> 8));
6869 }
6870
6871 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6872 | VB_XGI302LV | VB_XGI301C)) {
6873 if (pVBInfo->VBInfo & SetCRT2ToLCD)
6874 XGI_SetLCDCap_B(tempcx, pVBInfo);
6875 else if (pVBInfo->VBInfo & SetCRT2ToLCDA)
6876 XGI_SetLCDCap_A(tempcx, pVBInfo);
6877
6878 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6879 if (tempcx & EnableSpectrum)
6880 SetSpectrum(pVBInfo);
6881 }
6882 } else {
6883 /* LVDS,CH7017 */
6884 XGI_SetLCDCap_A(tempcx, pVBInfo);
6885 }
6886}
6887
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006888/* --------------------------------------------------------------------- */
6889/* Function : XGI_SetAntiFlicker */
6890/* Input : */
6891/* Output : */
6892/* Description : Set TV Customized Param. */
6893/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006894static void XGI_SetAntiFlicker(unsigned short ModeNo,
6895 unsigned short ModeIdIndex,
6896 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006897{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306898 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006899
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306900 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006901
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306902 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
6903 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006904
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306905 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6906 tempbx &= 0xFE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006907
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306908 if (ModeNo <= 0x13)
6909 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
6910 else
6911 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006912
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306913 tempbx += index;
6914 tempah = TVAntiFlickList[tempbx];
6915 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006916
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006917 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006918}
6919
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006920static void XGI_SetEdgeEnhance(unsigned short ModeNo,
6921 unsigned short ModeIdIndex,
6922 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006923{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306924 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006925
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306926 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006927
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306928 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6929 tempbx &= 0xFE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006930
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306931 if (ModeNo <= 0x13)
6932 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
6933 else
6934 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006935
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306936 tempbx += index;
6937 tempah = TVEdgeList[tempbx];
6938 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006939
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006940 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006941}
6942
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006943static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006944{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306945 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006946
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306947 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006948
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306949 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006950
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306951 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
6952 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006953
Aaro Koskinen8104e322011-03-13 12:26:22 +02006954 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306955 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006956 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306957 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006958 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306959 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006960 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306961 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006962}
6963
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006964static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306965 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006966{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306967 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006968
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306969 unsigned char tempcl, tempch, tempal, *filterPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006970
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306971 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006972
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306973 switch (tempbx) {
6974 case 0x00:
6975 case 0x04:
6976 filterPtr = NTSCYFilter1;
6977 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006978
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306979 case 0x01:
6980 filterPtr = PALYFilter1;
6981 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006982
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306983 case 0x02:
6984 case 0x05:
6985 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306986 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03006987 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306988 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006989
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306990 case 0x08:
6991 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306992 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306993 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306994 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03006995 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306996 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006997
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306998 default:
6999 return;
7000 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007001
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307002 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007003 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
7004 VB_StTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307005 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007006 tempal = pVBInfo->EModeIDTable[ModeIdIndex].
7007 VB_ExtTVYFilterIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007008
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307009 if (tempcl == 0)
7010 index = tempal * 4;
7011 else
7012 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007013
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307014 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02007015 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
7016 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
7017 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
7018 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307019 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02007020 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
7021 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
7022 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
7023 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307024 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007025
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307026 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7027 | VB_XGI302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02007028 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
7029 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
7030 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307031 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007032}
7033
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007034/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007035/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007036/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007037/* Output : */
7038/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007039/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007040static void XGI_OEM310Setting(unsigned short ModeNo,
7041 unsigned short ModeIdIndex,
7042 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007043{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007044 if (pVBInfo->SetFlag & Win9xDOSMode)
7045 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007046
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007047 /* GetPart1IO(); */
7048 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007049
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007050 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
7051 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007052
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007053 if (pVBInfo->VBInfo & SetCRT2ToTV) {
7054 /* GetPart2IO() */
7055 XGI_SetPhaseIncr(pVBInfo);
7056 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
7057 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007058
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007059 if (pVBInfo->VBType & VB_XGI301)
7060 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307061 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007062}
7063
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007064/* --------------------------------------------------------------------- */
7065/* Function : XGI_SetCRT2ModeRegs */
7066/* Input : */
7067/* Output : */
7068/* Description : Origin code for crt2group */
7069/* --------------------------------------------------------------------- */
Bill Pemberton82d6eb52010-06-17 13:10:46 -04007070void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307071 struct xgi_hw_device_info *HwDeviceExtension,
7072 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007073{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307074 unsigned short tempbl;
7075 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007076
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307077 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007078
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007079 /* // fix write part1 index 0 BTDRAM bit Bug
7080 * xgifb_reg_set(pVBInfo->Part1Port, 0x03, 0x00); */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307081 tempah = 0;
7082 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007083 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307084 tempah &= ~0x10; /* BTRAMDAC */
7085 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007086
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307087 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
7088 | SetCRT2ToLCD)) {
7089 tempah = 0x40; /* BTDRAM */
7090 if (ModeNo > 0x13) {
7091 tempcl = pVBInfo->ModeType;
7092 tempcl -= ModeVGA;
7093 if (tempcl >= 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007094 /* BT Color */
7095 tempah = (0x008 >> tempcl);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307096 if (tempah == 0)
7097 tempah = 1;
7098 tempah |= 0x040;
7099 }
7100 }
7101 if (pVBInfo->VBInfo & SetInSlaveMode)
7102 tempah ^= 0x50; /* BTDAC */
7103 }
7104 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307106 /* 0210 shampoo
7107 if (pVBInfo->VBInfo & DisableCRT2Display) {
7108 tempah = 0;
7109 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007110
Aaro Koskinen8104e322011-03-13 12:26:22 +02007111 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307112 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)) {
7113 tempcl = pVBInfo->ModeType;
7114 if (ModeNo > 0x13) {
7115 tempcl -= ModeVGA;
7116 if ((tempcl > 0) || (tempcl == 0)) {
7117 tempah=(0x008>>tempcl) ;
7118 if (tempah == 0)
7119 tempah = 1;
7120 tempah |= 0x040;
7121 }
7122 } else {
7123 tempah = 0x040;
7124 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007125
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307126 if (pVBInfo->VBInfo & SetInSlaveMode) {
7127 tempah = (tempah ^ 0x050);
7128 }
7129 }
7130 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007131
Aaro Koskinen8104e322011-03-13 12:26:22 +02007132 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307133 tempah = 0x08;
7134 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007135
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307136 if (pVBInfo->VBInfo & DisableCRT2Display) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007137 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307138 } else {
7139 tempah = 0x00;
7140 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007141
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307142 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
7143 | SetCRT2ToLCD | SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007144 if ((pVBInfo->VBInfo & SetCRT2ToLCDA) &&
7145 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307146 tempbl &= 0xf7;
7147 tempah |= 0x01;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007148 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307149 tempbl, tempah);
7150 } else {
7151 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7152 tempbl &= 0xf7;
7153 tempah |= 0x01;
7154 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007155
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007156 if (pVBInfo->VBInfo &
7157 (SetCRT2ToRAMDAC |
7158 SetCRT2ToTV |
7159 SetCRT2ToLCD)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307160 tempbl &= 0xf8;
7161 tempah = 0x01;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007162
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307163 if (!(pVBInfo->VBInfo & SetInSlaveMode))
7164 tempah |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007165
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007166 if (!(pVBInfo->VBInfo &
7167 SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307168 tempah = tempah ^ 0x05;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007169 if (!(pVBInfo->VBInfo &
7170 SetCRT2ToLCD))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307171 tempah = tempah ^ 0x01;
7172 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007173
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007174 if (!(pVBInfo->VBInfo &
7175 SetCRT2ToDualEdge))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307176 tempah |= 0x08;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007177 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307178 0x2e, tempbl, tempah);
7179 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007180 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307181 0x2e, tempbl, tempah);
7182 }
7183 }
7184 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007185 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307186 tempah);
7187 }
7188 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007189
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307190 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
7191 | SetCRT2ToLCDA)) {
7192 tempah &= (~0x08);
7193 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
7194 & SetInSlaveMode))) {
7195 tempah |= 0x010;
7196 }
7197 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007198
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307199 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007200 /* if (!(pVBInfo->TVInfo &
7201 (SetYPbPrMode525p | SetYPbPrMode750p))) { */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307202 tempah |= 0x020;
7203 if (ModeNo > 0x13) {
7204 if (pVBInfo->VBInfo & DriverMode)
7205 tempah = tempah ^ 0x20;
7206 }
7207 /* } */
7208 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007209
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007210 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307211 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007212
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307213 if (pVBInfo->LCDInfo & SetLCDDualLink)
7214 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007215
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307216 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007217 /* if ((!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) &&
7218 (!(pVBInfo->TVInfo &
7219 (SetYPbPrMode525p | SetYPbPrMode750p)))) { */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307220 if (pVBInfo->TVInfo & RPLLDIV2XO)
7221 tempah |= 0x40;
7222 /* } */
7223 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007224
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307225 if ((pVBInfo->LCDResInfo == Panel1280x1024)
7226 || (pVBInfo->LCDResInfo == Panel1280x1024x75))
7227 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007228
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307229 if (pVBInfo->LCDResInfo == Panel1280x960)
7230 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007231
Aaro Koskinen8104e322011-03-13 12:26:22 +02007232 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307233 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007234
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307235 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7236 | VB_XGI302LV | VB_XGI301C)) {
7237 tempah = 0;
7238 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007239
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307240 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7241 tempbl = 0xff;
7242 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7243 tempah |= 0x04; /* shampoo 0129 */
7244 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007245
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007246 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307247 tempah = 0x00;
7248 tempbl = 0xcf;
7249 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7250 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7251 tempah |= 0x30;
7252 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007253
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007254 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307255 tempah = 0;
7256 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007257
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307258 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7259 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7260 tempah |= 0xc0;
7261 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007262 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307263 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007264
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307265 tempah = 0;
7266 tempbl = 0x7f;
7267 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) {
7268 tempbl = 0xff;
7269 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
7270 tempah |= 0x80;
7271 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007272
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007273 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007274
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307275 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7276 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02007277 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
7278 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307279 }
7280 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007281}
7282
Aaro Koskinen063b9c42011-03-08 22:16:13 +02007283static void XGI_CloseCRTC(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307284 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007285{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307286 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007287
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307288 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007289
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307290 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7291 tempbx = 0x08A0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007292
7293}
7294
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307295void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
7296 struct vb_device_info *pVBInfo)
7297{
7298
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007299 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007300
7301}
7302
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307303void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
7304 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007305{
7306
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007307 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007308
7309}
7310
Bill Pemberton80adad82010-06-17 13:10:51 -04007311unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007312{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307313 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007314
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307315 if (pVBInfo->IF_DEF_LVDS == 1) {
7316 return 1;
7317 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007318 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307319 if ((flag == 1) || (flag == 2))
7320 return 1; /* 301b */
7321 else
7322 return 0;
7323 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007324}
7325
Bill Pemberton80adad82010-06-17 13:10:51 -04007326void XGI_LongWait(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007327{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307328 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007329
Aaro Koskinen58839b02011-03-13 12:26:23 +02007330 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007331
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307332 if (!(i & 0xC0)) {
7333 for (i = 0; i < 0xFFFF; i++) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007334 if (!(inb(pVBInfo->P3da) & 0x08))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307335 break;
7336 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007337
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307338 for (i = 0; i < 0xFFFF; i++) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007339 if ((inb(pVBInfo->P3da) & 0x08))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307340 break;
7341 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007342 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007343}
7344
Aaro Koskinen063b9c42011-03-08 22:16:13 +02007345static void XGI_VBLongWait(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007346{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307347 unsigned short tempal, temp, i, j;
7348 return;
7349 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
7350 temp = 0;
7351 for (i = 0; i < 3; i++) {
7352 for (j = 0; j < 100; j++) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007353 tempal = inb(pVBInfo->P3da);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307354 if (temp & 0x01) { /* VBWaitMode2 */
7355 if ((tempal & 0x08))
7356 continue;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007357
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307358 if (!(tempal & 0x08))
7359 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007360
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307361 } else { /* VBWaitMode1 */
7362 if (!(tempal & 0x08))
7363 continue;
7364
7365 if ((tempal & 0x08))
7366 break;
7367 }
7368 }
7369 temp = temp ^ 0x01;
7370 }
7371 } else {
7372 XGI_LongWait(pVBInfo);
7373 }
7374 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007375}
7376
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007377unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
7378 unsigned short ModeNo, unsigned short ModeIdIndex,
7379 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007380{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007381 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
7382 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
7383 0x01, 0x01 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007384
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007385 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007386
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007387 if (ModeNo <= 0x13)
7388 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
7389 else
7390 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
7391
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007392 if (ModeNo < 0x14)
7393 return 0xFFFF;
7394
Aaro Koskinen58839b02011-03-13 12:26:23 +02007395 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007396 index = index >> pVBInfo->SelectCRT2Rate;
7397 index &= 0x0F;
7398
7399 if (pVBInfo->LCDInfo & LCDNonExpanding)
7400 index = 0;
7401
7402 if (index > 0)
7403 index--;
7404
7405 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007406 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
7407 if (pVBInfo->IF_DEF_LVDS == 0) {
7408 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
7409 | VB_XGI301LV | VB_XGI302LV
7410 | VB_XGI301C))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007411 /* 301b */
7412 temp = LCDARefreshIndex[
7413 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007414 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007415 temp = LCDRefreshIndex[
7416 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007417
7418 if (index > temp)
7419 index = temp;
7420 } else {
7421 index = 0;
7422 }
7423 }
7424 }
7425
7426 RefreshRateTableIndex = pVBInfo->EModeIDTable[ModeIdIndex].REFindex;
7427 ModeNo = pVBInfo->RefIndex[RefreshRateTableIndex].ModeID;
7428 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
7429 /*
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007430 if (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag &
7431 XG2xNotSupport) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007432 index++;
7433 }
7434 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007435 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 800) &&
7436 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007437 index++;
7438 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007439 /* Alan 10/19/2007;
7440 * do the similar adjustment like XGISearchCRT1Rate() */
7441 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1024) &&
7442 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007443 index++;
7444 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007445 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1280) &&
7446 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007447 index++;
7448 }
7449 }
7450
7451 i = 0;
7452 do {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007453 if (pVBInfo->RefIndex[RefreshRateTableIndex + i].
7454 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007455 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007456 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i].
7457 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007458 temp &= ModeInfoFlag;
7459 if (temp < pVBInfo->ModeType)
7460 break;
7461 i++;
7462 index--;
7463
7464 } while (index != 0xFFFF);
7465 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
7466 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007467 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i - 1].
7468 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007469 if (temp & InterlaceMode)
7470 i++;
7471 }
7472 }
7473 i--;
7474 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
7475 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
7476 RefreshRateTableIndex, &i, pVBInfo);
7477 }
7478 return RefreshRateTableIndex + i; /* return (0x01 | (temp1<<1)); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007479}
7480
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007481static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307482 struct xgi_hw_device_info *HwDeviceExtension,
7483 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007484{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007485 unsigned short RefreshRateTableIndex;
7486 /* unsigned short temp ; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007487
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007488 /* pVBInfo->SelectCRT2Rate = 0; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007489
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007490 pVBInfo->SetFlag |= ProgrammingCRT2;
7491 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7492 ModeIdIndex, pVBInfo);
7493 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
7494 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7495 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7496 HwDeviceExtension, pVBInfo);
7497 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7498 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007499}
7500
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007501unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
7502 struct xgi_hw_device_info *HwDeviceExtension,
7503 struct vb_device_info *pVBInfo)
7504{
7505 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
7506
7507 tempbx = pVBInfo->VBInfo;
7508 pVBInfo->SetFlag |= ProgrammingCRT2;
7509 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7510 pVBInfo->SelectCRT2Rate = 4;
7511 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7512 ModeIdIndex, pVBInfo);
7513 XGI_SaveCRT2Info(ModeNo, pVBInfo);
7514 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
7515 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7516 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7517 RefreshRateTableIndex, pVBInfo);
7518 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7519 RefreshRateTableIndex, pVBInfo);
7520 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7521 RefreshRateTableIndex, pVBInfo);
7522 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7523 HwDeviceExtension, pVBInfo);
7524 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7525 RefreshRateTableIndex, pVBInfo);
7526 XGI_SetTap4Regs(pVBInfo);
7527 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
7528 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7529 HwDeviceExtension, pVBInfo);
7530 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7531 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
7532 XGI_AutoThreshold(pVBInfo);
7533 return 1;
7534}
7535
7536void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
7537{
7538 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
7539 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
7540 0x05, 0x00 };
7541
7542 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
7543
7544 unsigned char CR17, CR63, SR31;
7545 unsigned short temp;
7546 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
7547
7548 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02007549 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007550
7551 /* [2004/05/06] Vicent to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02007552 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02007553 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007554 pVBInfo->P3d4, 0x53) | 0x02));
7555
Aaro Koskinen58839b02011-03-13 12:26:23 +02007556 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
7557 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
7558 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007559
Aaro Koskinen8104e322011-03-13 12:26:22 +02007560 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
7561 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007562
Aaro Koskinen58839b02011-03-13 12:26:23 +02007563 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007564 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007565
Aaro Koskinen58839b02011-03-13 12:26:23 +02007566 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007567 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007568
Aaro Koskinen58839b02011-03-13 12:26:23 +02007569 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007570 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Aaro Koskinen58839b02011-03-13 12:26:23 +02007571 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007572 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007573
Aaro Koskinen8104e322011-03-13 12:26:22 +02007574 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007575
7576 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007577 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007578
7579 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007580 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007581 CRTCData[i]);
7582
7583 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007584 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007585 CRTCData[i]);
7586
7587 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007588 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007589 CRTCData[i]);
7590
Aaro Koskinen8104e322011-03-13 12:26:22 +02007591 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007592 & 0xE0));
7593
Aaro Koskinen8104e322011-03-13 12:26:22 +02007594 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
7595 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7596 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007597
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007598 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007599
7600 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007601 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
7602 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
7603 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007604 }
7605
7606 XGI_VBLongWait(pVBInfo);
7607 XGI_VBLongWait(pVBInfo);
7608 XGI_VBLongWait(pVBInfo);
7609
7610 mdelay(1);
7611
7612 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007613 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007614
7615 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007616 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007617 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007618 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007619
7620 /* alan, avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007621 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007622
7623 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007624 outb(0, (pVBInfo->P3c8 + 1));
7625 outb(0, (pVBInfo->P3c8 + 1));
7626 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007627 }
7628
Aaro Koskinen8104e322011-03-13 12:26:22 +02007629 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
7630 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
7631 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007632
7633 /* [2004/05/11] Vicent */
Aaro Koskinen58839b02011-03-13 12:26:23 +02007634 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007635 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02007636 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007637}
7638
7639void XGI_EnableBridge(struct xgi_hw_device_info *HwDeviceExtension,
7640 struct vb_device_info *pVBInfo)
7641{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02007642 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007643
7644 if (pVBInfo->SetFlag == Win9xDOSMode) {
7645 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7646 | VB_XGI302LV | VB_XGI301C)) {
7647 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7648 return;
7649 } else
7650 /* LVDS or CH7017 */
7651 return;
7652 }
7653
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007654 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7655 | VB_XGI302LV | VB_XGI301C)) {
7656 if (!(pVBInfo->SetFlag & DisableChA)) {
7657 if (pVBInfo->SetFlag & EnableChA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007658 /* Power on */
7659 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007660 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007661 /* SetCRT2ToLCDA ) */
7662 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7663 /* Power on */
Aaro Koskinen8104e322011-03-13 12:26:22 +02007664 xgifb_reg_set(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007665 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007666 }
7667 }
7668 }
7669
7670 if (!(pVBInfo->SetFlag & DisableChB)) {
7671 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
7672 & (SetCRT2ToLCD | SetCRT2ToTV
7673 | SetCRT2ToRAMDAC))) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007674 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007675 pVBInfo->P3c4, 0x32);
7676 tempah &= 0xDF;
7677 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007678 if (!(pVBInfo->VBInfo &
7679 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007680 tempah |= 0x20;
7681 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02007682 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02007683 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007684
Aaro Koskinen58839b02011-03-13 12:26:23 +02007685 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007686 pVBInfo->Part1Port, 0x2E);
7687
7688 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007689 /* BVBDOENABLE = 1 */
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02007690 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007691 0x2E, 0x80);
7692 /* BScreenOFF = 0 */
7693 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007694 }
7695 }
7696
7697 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
7698 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007699 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007700 0x20); /* shampoo 0129 */
7701 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7702 if (!XGI_DisableChISLCD(pVBInfo)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007703 if (XGI_EnableChISLCD(pVBInfo) ||
7704 (pVBInfo->VBInfo &
7705 (SetCRT2ToLCD | SetCRT2ToLCDA)))
7706 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02007707 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007708 pVBInfo->Part4Port,
7709 0x2A,
7710 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007711 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007712 /* LVDS Driver power on */
7713 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007714 }
7715 }
7716
7717 tempah = 0x00;
7718
7719 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7720 tempah = 0xc0;
7721
7722 if (!(pVBInfo->VBInfo & SetSimuScanMode)) {
7723 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007724 if (pVBInfo->VBInfo &
7725 SetCRT2ToDualEdge) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007726 tempah = tempah & 0x40;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007727 if (pVBInfo->VBInfo &
7728 SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007729 tempah = tempah ^ 0xC0;
7730
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007731 if (pVBInfo->SetFlag &
7732 DisableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007733 tempah &= 0xBF;
7734
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007735 if (pVBInfo->SetFlag &
7736 DisableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007737 tempah &= 0x7F;
7738
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007739 if (pVBInfo->SetFlag &
7740 EnableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007741 tempah |= 0x40;
7742
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007743 if (pVBInfo->SetFlag &
7744 EnableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007745 tempah |= 0x80;
7746 }
7747 }
7748 }
7749 }
7750
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007751 /* EnablePart4_1F */
7752 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007753
7754 if (pVBInfo->SetFlag & Win9xDOSMode) {
7755 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7756 return;
7757 }
7758
7759 if (!(pVBInfo->SetFlag & DisableChA)) {
7760 XGI_VBLongWait(pVBInfo);
7761 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007762 XGI_DisableGatingCRT(HwDeviceExtension,
7763 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007764 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7765 XGI_VBLongWait(pVBInfo);
7766 }
7767 }
7768 } /* 301 */
7769 else { /* LVDS */
7770 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
7771 | SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007772 /* enable CRT2 */
7773 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007774
Aaro Koskinen58839b02011-03-13 12:26:23 +02007775 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007776 0x2E);
7777 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007778 /* BVBDOENABLE = 1 */
7779 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007780
Aaro Koskinendc505562011-03-13 12:26:26 +02007781 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007782 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7783 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007784}
7785
7786static void XGI_SetCRT1Group(struct xgi_hw_device_info *HwDeviceExtension,
7787 unsigned short ModeNo, unsigned short ModeIdIndex,
7788 struct vb_device_info *pVBInfo)
7789{
7790 unsigned short StandTableIndex, RefreshRateTableIndex, b3CC, temp;
7791
7792 unsigned short XGINew_P3cc = pVBInfo->P3cc;
7793
7794 /* XGINew_CRT1Mode = ModeNo; // SaveModeID */
7795 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
7796 /* XGI_SetBIOSData(ModeNo, ModeIdIndex); */
7797 /* XGI_ClearBankRegs(ModeNo, ModeIdIndex); */
7798 XGI_SetSeqRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7799 XGI_SetMiscRegs(StandTableIndex, pVBInfo);
7800 XGI_SetCRTCRegs(HwDeviceExtension, StandTableIndex, pVBInfo);
7801 XGI_SetATTRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7802 XGI_SetGRCRegs(StandTableIndex, pVBInfo);
7803 XGI_ClearExt1Regs(pVBInfo);
7804
7805 /* if (pVBInfo->IF_DEF_ExpLink) */
7806 if (HwDeviceExtension->jChipType == XG27) {
7807 if (pVBInfo->IF_DEF_LVDS == 0)
7808 XGI_SetDefaultVCLK(pVBInfo);
7809 }
7810
7811 temp = ~ProgrammingCRT2;
7812 pVBInfo->SetFlag &= temp;
7813 pVBInfo->SelectCRT2Rate = 0;
7814
7815 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7816 | VB_XGI302LV | VB_XGI301C)) {
7817 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA
7818 | SetInSlaveMode)) {
7819 pVBInfo->SetFlag |= ProgrammingCRT2;
7820 }
7821 }
7822
7823 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7824 ModeIdIndex, pVBInfo);
7825 if (RefreshRateTableIndex != 0xFFFF) {
7826 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
7827 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7828 pVBInfo, HwDeviceExtension);
7829 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
7830 RefreshRateTableIndex, pVBInfo);
7831 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7832 HwDeviceExtension, pVBInfo);
7833 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
7834 RefreshRateTableIndex, pVBInfo);
7835 }
7836
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007837 if ((HwDeviceExtension->jChipType >= XG20) &&
7838 (HwDeviceExtension->jChipType < XG27)) { /* fix H/W DCLK/2 bug */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007839 if ((ModeNo == 0x00) | (ModeNo == 0x01)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02007840 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x4E);
7841 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE9);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007842 b3CC = (unsigned char) inb(XGINew_P3cc);
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007843 outb((b3CC |= 0x0C), XGINew_P3cc);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007844 } else if ((ModeNo == 0x04) | (ModeNo == 0x05) | (ModeNo
7845 == 0x0D)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02007846 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7847 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE3);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007848 b3CC = (unsigned char) inb(XGINew_P3cc);
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007849 outb((b3CC |= 0x0C), XGINew_P3cc);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007850 }
7851 }
7852
7853 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007854 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007855 if (temp & 0xA0) {
7856
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007857 /* Enable write GPIOF */
7858 /* xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x20); */
7859 /* P. DWN */
7860 /* xgifb_reg_and(pVBInfo->P3d4, 0x48, ~0x20); */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007861 /* XG21 CRT1 Timing */
7862 if (HwDeviceExtension->jChipType == XG27)
7863 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
7864 RefreshRateTableIndex, pVBInfo);
7865 else
7866 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
7867 RefreshRateTableIndex, pVBInfo);
7868
7869 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
7870 RefreshRateTableIndex);
7871
Aaro Koskinen105d8d02011-08-31 21:46:00 +03007872 xgifb_set_lcd(HwDeviceExtension->jChipType,
7873 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007874
Aaro Koskinen64db29f2011-08-31 21:46:01 +03007875 if (pVBInfo->IF_DEF_LVDS == 1)
7876 xgifb_set_lvds(HwDeviceExtension->jChipType,
7877 ModeNo, ModeIdIndex, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007878 /* P. ON */
7879 /* xgifb_reg_or(pVBInfo->P3d4, 0x48, 0x20); */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007880 }
7881 }
7882
7883 pVBInfo->SetFlag &= (~ProgrammingCRT2);
7884 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
7885 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
7886 RefreshRateTableIndex, pVBInfo);
7887
7888 /* XGI_LoadCharacter(); //dif ifdef TVFont */
7889
7890 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
7891 /* XGI_ClearBuffer(HwDeviceExtension, ModeNo, pVBInfo); */
7892}
7893
7894unsigned char XGISetModeNew(struct xgi_hw_device_info *HwDeviceExtension,
7895 unsigned short ModeNo)
7896{
7897 unsigned short ModeIdIndex;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007898 /* unsigned char *pVBInfo->FBAddr =
7899 HwDeviceExtension->pjVideoMemoryAddress; */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007900 struct vb_device_info VBINF;
7901 struct vb_device_info *pVBInfo = &VBINF;
7902 pVBInfo->ROMAddr = HwDeviceExtension->pjVirtualRomBase;
7903 pVBInfo->BaseAddr = (unsigned long) HwDeviceExtension->pjIOAddress;
7904 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007905 pVBInfo->IF_DEF_LCDA = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007906 pVBInfo->IF_DEF_VideoCapture = 0;
7907 pVBInfo->IF_DEF_ScaleLCD = 0;
7908 pVBInfo->IF_DEF_OEMUtil = 0;
7909 pVBInfo->IF_DEF_PWD = 0;
7910
7911 if (HwDeviceExtension->jChipType >= XG20) { /* kuku 2004/06/25 */
7912 pVBInfo->IF_DEF_YPbPr = 0;
7913 pVBInfo->IF_DEF_HiVision = 0;
7914 pVBInfo->IF_DEF_CRT2Monitor = 0;
7915 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007916 } else {
7917 pVBInfo->IF_DEF_YPbPr = 1;
7918 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02007919 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007920 }
7921
7922 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
7923 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
7924 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
7925 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
7926 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
7927 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
7928 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
7929 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
7930 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
7931 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
7932 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
7933 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
7934 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
7935 pVBInfo->Part1Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_04;
7936 pVBInfo->Part2Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_10;
7937 pVBInfo->Part3Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_12;
7938 pVBInfo->Part4Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14;
7939 pVBInfo->Part5Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 + 2;
7940
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007941 /* for x86 Linux, XG21 LVDS */
7942 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007943 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007944 pVBInfo->IF_DEF_LVDS = 1;
7945 }
7946 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007947 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
7948 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007949 pVBInfo->IF_DEF_LVDS = 1;
7950 }
7951 }
7952
7953 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 */
7954 XGI_GetVBType(pVBInfo);
7955
7956 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
7957 if (ModeNo & 0x80) {
7958 ModeNo = ModeNo & 0x7F;
7959 /* XGINew_flag_clearbuffer = 0; */
7960 }
7961 /* else {
7962 XGINew_flag_clearbuffer = 1;
7963 }
7964 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02007965 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007966
7967 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 1.Openkey */
7968 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
7969
7970 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7971
7972 XGI_GetVGAType(HwDeviceExtension, pVBInfo);
7973
7974 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
7975 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
7976 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
7977 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
7978 XGI_DisableBridge(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007979
7980 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) {
7981 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
7982 ModeIdIndex, pVBInfo);
7983
7984 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7985 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7986 HwDeviceExtension, pVBInfo);
7987 }
7988 } else {
7989 if (!(pVBInfo->VBInfo & SwitchToCRT2)) {
7990 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
7991 ModeIdIndex, pVBInfo);
7992 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7993 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7994 HwDeviceExtension,
7995 pVBInfo);
7996 }
7997 }
7998 }
7999
8000 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchToCRT2)) {
8001 switch (HwDeviceExtension->ujVBChipID) {
8002 case VB_CHIP_301:
8003 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
8004 pVBInfo); /*add for CRT2 */
8005 break;
8006
8007 case VB_CHIP_302:
8008 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
8009 pVBInfo); /*add for CRT2 */
8010 break;
8011
8012 default:
8013 break;
8014 }
8015 }
8016
8017 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
8018 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
8019 XGI_CloseCRTC(HwDeviceExtension, pVBInfo);
8020 XGI_EnableBridge(HwDeviceExtension, pVBInfo);
8021 } /* !XG20 */
8022 else {
8023 if (pVBInfo->IF_DEF_LVDS == 1)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008024 if (!XGI_XG21CheckLVDSMode(ModeNo,
8025 ModeIdIndex,
8026 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008027 return 0;
8028
8029 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008030 pVBInfo->ModeType = pVBInfo->SModeIDTable[ModeIdIndex].
8031 St_ModeFlag & ModeInfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008032 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008033 pVBInfo->ModeType = pVBInfo->EModeIDTable[ModeIdIndex].
8034 Ext_ModeFlag & ModeInfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008035 }
8036
8037 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03008038 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008039
8040 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
8041
8042 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex,
8043 pVBInfo);
8044
8045 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
8046 /*
8047 if (HwDeviceExtension->jChipType == XG21)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02008048 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0x80, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008049 */
8050 }
8051
8052 /*
8053 if (ModeNo <= 0x13) {
8054 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
8055 } else {
8056 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
8057 }
8058 pVBInfo->ModeType = modeflag&ModeInfoFlag;
8059 pVBInfo->SetFlag = 0x00;
8060 pVBInfo->VBInfo = DisableCRT2Display;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008061 temp = XGINew_CheckMemorySize(HwDeviceExtension,
8062 ModeNo,
8063 ModeIdIndex,
8064 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008065
8066 if (temp == 0)
8067 return (0);
8068
8069 XGI_DisplayOff(HwDeviceExtension, pVBInfo) ;
8070 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex, pVBInfo);
8071 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
8072 */
8073
8074 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
8075
8076 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
8077 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
8078 }
8079
8080 return 1;
8081}