blob: 910d8d9afc4c826d82ff5046a4c5c801d05c91f5 [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
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530202/*
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800203unsigned char XGI_SetBIOSData(unsigned short ModeNo,
204 unsigned short ModeIdIndex) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530205 return (0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200206}
207*/
208
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800209/* unsigned char XGI_ClearBankRegs(unsigned short ModeNo,
210 unsigned short ModeIdIndex) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530211 return( 0 ) ;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200212}
213*/
214
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800215static void XGI_SetSeqRegs(unsigned short ModeNo,
216 unsigned short StandTableIndex,
217 unsigned short ModeIdIndex,
218 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200219{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530220 unsigned char tempah, SRdata;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530221 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200222
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530223 if (ModeNo <= 0x13)
224 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
225 else
226 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200227
Aaro Koskinen8104e322011-03-13 12:26:22 +0200228 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530229 tempah = pVBInfo->StandTable[StandTableIndex].SR[0];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200230
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530231 i = SetCRT2ToLCDA;
232 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
233 tempah |= 0x01;
234 } else {
235 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
236 if (pVBInfo->VBInfo & SetInSlaveMode)
237 tempah |= 0x01;
238 }
239 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200240
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530241 tempah |= 0x20; /* screen off */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200242 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200243
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530244 for (i = 02; i <= 04; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800245 /* Get SR2,3,4 from file */
246 SRdata = pVBInfo->StandTable[StandTableIndex].SR[i - 1];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200247 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530248 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200249}
250
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200251static void XGI_SetMiscRegs(unsigned short StandTableIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800252 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200253{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530254 unsigned char Miscdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200255
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800256 /* Get Misc from file */
257 Miscdata = pVBInfo->StandTable[StandTableIndex].MISC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530258 /*
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800259 if (pVBInfo->VBType & (VB_XGI301B |
260 VB_XGI302B |
261 VB_XGI301LV |
262 VB_XGI302LV |
263 VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530264 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
265 Miscdata |= 0x0C;
266 }
267 }
268 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200269
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200270 outb(Miscdata, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200271}
272
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200273static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800274 unsigned short StandTableIndex,
275 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200276{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530277 unsigned char CRTCdata;
278 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200279
Aaro Koskinen58839b02011-03-13 12:26:23 +0200280 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530281 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200282 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200283
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530284 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800285 /* Get CRTC from file */
286 CRTCdata = pVBInfo->StandTable[StandTableIndex].CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200287 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530288 }
289 /*
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800290 if ((HwDeviceExtension->jChipType == XGI_630) &&
291 (HwDeviceExtension->jChipRevision == 0x30)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530292 if (pVBInfo->VBInfo & SetInSlaveMode) {
293 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200294 xgifb_reg_set(pVBInfo->P3d4, 0x18, 0xFE);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530295 }
296 }
297 }
298 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200299}
300
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800301static void XGI_SetATTRegs(unsigned short ModeNo,
302 unsigned short StandTableIndex,
303 unsigned short ModeIdIndex,
304 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200305{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530306 unsigned char ARdata;
307 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200308
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530309 if (ModeNo <= 0x13)
310 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
311 else
312 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200313
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530314 for (i = 0; i <= 0x13; i++) {
315 ARdata = pVBInfo->StandTable[StandTableIndex].ATTR[i];
316 if (modeflag & Charx8Dot) { /* ifndef Dot9 */
317 if (i == 0x13) {
318 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
319 ARdata = 0;
320 } else {
321 if (pVBInfo->VBInfo & (SetCRT2ToTV
322 | SetCRT2ToLCD)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800323 if (pVBInfo->VBInfo &
324 SetInSlaveMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530325 ARdata = 0;
326 }
327 }
328 }
329 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200330
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200331 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200332 outb(i, pVBInfo->P3c0); /* set index */
333 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530334 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200335
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200336 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200337 outb(0x14, pVBInfo->P3c0); /* set index */
338 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200339 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200340 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200341}
342
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200343static void XGI_SetGRCRegs(unsigned short StandTableIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800344 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200345{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530346 unsigned char GRdata;
347 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200348
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530349 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800350 /* Get GR from file */
351 GRdata = pVBInfo->StandTable[StandTableIndex].GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200352 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530353 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200354
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530355 if (pVBInfo->ModeType > ModeVGA) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200356 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530357 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200358 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530359 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200360}
361
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200362static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200363{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530364 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200365
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530366 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200367 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200368}
369
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200370static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200371{
372
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200373 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200374 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[0].SR2B);
375 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200376
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200377 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200378 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[1].SR2B);
379 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200380
Aaro Koskinendc505562011-03-13 12:26:26 +0200381 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530382 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200383}
384
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200385static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530386 unsigned short ModeIdIndex,
387 unsigned short RefreshRateTableIndex, unsigned short *i,
388 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200389{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530390 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200391
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530392 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800393 /* si+St_ModeFlag */
394 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530395 else
396 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200397
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530398 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
399 tempbx = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID;
400 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200401
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530402 if (pVBInfo->IF_DEF_LVDS == 0) {
403 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
404 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200405
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530406 if (pVBInfo->VBType & VB_XGI301C)
407 tempax |= SupportCRT2in301C;
408 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200409
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800410 /* 301b */
411 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530412 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200413
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530414 if (pVBInfo->LCDResInfo != Panel1280x1024) {
415 if (pVBInfo->LCDResInfo != Panel1280x960) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800416 if (pVBInfo->LCDInfo &
417 LCDNonExpanding) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530418 if (resinfo >= 9) {
419 tempax = 0;
420 return 0;
421 }
422 }
423 }
424 }
425 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200426
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530427 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) { /* for HiTV */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800428 if ((pVBInfo->VBType & VB_XGI301LV) &&
429 (pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530430 tempax |= SupportYPbPr;
431 if (pVBInfo->VBInfo & SetInSlaveMode) {
432 if (resinfo == 4)
433 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200434
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530435 if (resinfo == 3)
436 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200437
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530438 if (resinfo > 7)
439 return 0;
440 }
441 } else {
442 tempax |= SupportHiVisionTV;
443 if (pVBInfo->VBInfo & SetInSlaveMode) {
444 if (resinfo == 4)
445 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200446
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530447 if (resinfo == 3) {
448 if (pVBInfo->SetFlag
449 & TVSimuMode)
450 return 0;
451 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200452
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530453 if (resinfo > 7)
454 return 0;
455 }
456 }
457 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800458 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
459 SetCRT2ToSVIDEO |
460 SetCRT2ToSCART |
461 SetCRT2ToYPbPr |
462 SetCRT2ToHiVisionTV)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530463 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200464
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530465 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
466 | VB_XGI301LV | VB_XGI302LV
467 | VB_XGI301C)) {
468 tempax |= SupportTV1024;
469 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200470
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530471 if (!(pVBInfo->VBInfo & SetPALTV)) {
472 if (modeflag & NoSupportSimuTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800473 if (pVBInfo->VBInfo &
474 SetInSlaveMode) {
475 if (!(pVBInfo->VBInfo &
476 SetNotSimuMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530477 return 0;
478 }
479 }
480 }
481 }
482 }
483 }
484 } else { /* for LVDS */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530485 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
486 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200487
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530488 if (resinfo > 0x08)
489 return 0; /* 1024x768 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200490
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530491 if (pVBInfo->LCDResInfo < Panel1024x768) {
492 if (resinfo > 0x07)
493 return 0; /* 800x600 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200494
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530495 if (resinfo == 0x04)
496 return 0; /* 512x384 */
497 }
498 }
499 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200500
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800501 for (; pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
502 tempbx; (*i)--) {
503 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
504 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530505 if (infoflag & tempax)
506 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200507
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530508 if ((*i) == 0)
509 break;
510 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200511
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530512 for ((*i) = 0;; (*i)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800513 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
514 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530515 if (pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID
516 != tempbx) {
517 return 0;
518 }
519
520 if (infoflag & tempax)
521 return 1;
522 }
523 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200524}
525
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200526static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530527 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200528{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530529 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200530
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800531 /* di+0x00 */
532 sync = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530533 sync &= 0xC0;
534 temp = 0x2F;
535 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200536 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200537}
538
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200539static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530540 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200541{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530542 unsigned char data, data1, pushax;
543 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200544
Aaro Koskinen8104e322011-03-13 12:26:22 +0200545 /* xgifb_reg_set(pVBInfo->P3d4, 0x51, 0); */
546 /* xgifb_reg_set(pVBInfo->P3d4, 0x56, 0); */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200547 /* xgifb_reg_and_or(pVBInfo->P3d4, 0x11, 0x7f, 0x00); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200548
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800549 /* unlock cr0-7 */
550 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530551 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200552 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200553
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530554 data = pVBInfo->TimingH[0].data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200555 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200556
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530557 for (i = 0x01; i <= 0x04; i++) {
558 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200559 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530560 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200561
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530562 for (i = 0x05; i <= 0x06; i++) {
563 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200564 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530565 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200566
Aaro Koskinen58839b02011-03-13 12:26:23 +0200567 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530568 j &= 0x1F;
569 data = pVBInfo->TimingH[0].data[7];
570 data &= 0xE0;
571 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200572 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200573
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530574 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200575 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530576 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200577 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200578 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530579 data1 = data;
580 data1 &= 0xE0;
581 data &= 0x1F;
582 if (data == 0) {
583 pushax = data;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200584 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530585 0x0c);
586 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200587 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530588 data = pushax;
589 }
590 data = data - 1;
591 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200592 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200593 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530594 data = data >> 5;
595 data = data + 3;
596 if (data > 7)
597 data = data - 7;
598 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200599 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530600 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200601}
602
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800603static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
604 unsigned short ModeNo,
605 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200606{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530607 unsigned char data;
608 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200609
Aaro Koskinen8104e322011-03-13 12:26:22 +0200610 /* xgifb_reg_set(pVBInfo->P3d4, 0x51, 0); */
611 /* xgifb_reg_set(pVBInfo->P3d4, 0x56, 0); */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200612 /* xgifb_reg_and_or(pVBInfo->P3d4, 0x11, 0x7f, 0x00); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200613
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530614 for (i = 0x00; i <= 0x01; i++) {
615 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200616 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530617 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200618
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530619 for (i = 0x02; i <= 0x03; i++) {
620 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200621 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530622 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200623
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530624 for (i = 0x04; i <= 0x05; i++) {
625 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200626 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530627 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200628
Aaro Koskinen58839b02011-03-13 12:26:23 +0200629 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530630 j &= 0xC0;
631 data = pVBInfo->TimingV[0].data[6];
632 data &= 0x3F;
633 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200634 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200635
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530636 data = pVBInfo->TimingV[0].data[6];
637 data &= 0x80;
638 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200639
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530640 if (ModeNo <= 0x13)
641 i = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
642 else
643 i = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200644
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530645 i &= DoubleScanMode;
646 if (i)
647 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200648
Aaro Koskinen58839b02011-03-13 12:26:23 +0200649 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530650 j &= 0x5F;
651 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200652 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200653}
654
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200655static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
656 unsigned short RefreshRateTableIndex,
657 struct vb_device_info *pVBInfo,
658 struct xgi_hw_device_info *HwDeviceExtension)
659{
660 unsigned char index, data;
661 unsigned short i;
662
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800663 /* Get index */
664 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200665 index = index & IndexMask;
666
Aaro Koskinen58839b02011-03-13 12:26:23 +0200667 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200668 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200669 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200670
671 for (i = 0; i < 8; i++)
672 pVBInfo->TimingH[0].data[i]
673 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i];
674
675 for (i = 0; i < 7; i++)
676 pVBInfo->TimingV[0].data[i]
677 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i + 8];
678
679 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
680
681 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
682
683 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200684 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200685}
686
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200687/* --------------------------------------------------------------------- */
688/* Function : XGI_SetXG21CRTC */
689/* Input : Stand or enhance CRTC table */
690/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
691/* Description : Set LCD timing */
692/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200693static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530694 unsigned short RefreshRateTableIndex,
695 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200696{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530697 unsigned char StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
698 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200699
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530700 if (ModeNo <= 0x13) {
701 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800702 /* CR04 HRS */
703 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4];
704 /* SR2E [7:0]->HRS */
705 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
706 /* Tempbx: CR05 HRE */
707 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530708 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */
709 Tempcx = Tempax;
710 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */
711 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
712 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */
713 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */
714 Tempdx <<= 2; /* Tempdx << 2 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800715 /* SR2F [7:2]->HRE */
716 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200717 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200718
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800719 /* Tempax: CR16 VRS */
720 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530721 Tempbx = Tempax; /* Tempbx=Tempax */
722 Tempax &= 0x01; /* Tempax: VRS[0] */
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200723 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800724
725 /* Tempax: CR7 VRS */
726 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530727 Tempdx = Tempbx >> 1; /* Tempdx: VRS[7:1] */
728 Tempcx = Tempax & 0x04; /* Tempcx: CR7[2] */
729 Tempcx <<= 5; /* Tempcx[7]: VRS[8] */
730 Tempdx |= Tempcx; /* Tempdx: VRS[8:1] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800731 /* SR34[7:0]: VRS[8:1] */
732 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempdx);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200733
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800734 /* Temp1[8]: VRS[8] unsigned char -> unsigned short */
735 Temp1 = Tempcx << 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530736 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
737 Tempax &= 0x80; /* Tempax[7]: CR7[7] */
738 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
739 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200740
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800741 /* CR16 VRE */
742 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530743 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
744 Temp2 = Temp1 & 0x3F0; /* Temp2[9:4]: VRS[9:4] */
745 Temp2 |= Tempax; /* Temp2[9:0]: VRE[9:0] */
746 Temp3 = Temp1 & 0x0F; /* Temp3[3:0]: VRS[3:0] */
747 if (Tempax < Temp3) /* VRE[3:0]<VRS[3:0] */
748 Temp2 |= 0x10; /* Temp2: VRE + 0x10 */
749 Temp2 &= 0xFF; /* Temp2[7:0]: VRE[7:0] */
750 Tempax = (unsigned char) Temp2; /* Tempax[7:0]: VRE[7:0] */
751 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */
752 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
753 Temp1 >>= 9; /* [10:9]->[1:0] */
754 Tempbx = (unsigned char) Temp1; /* Tempbx[1:0]: VRS[10:9] */
755 Tempax |= Tempbx; /* VRE[5:0]VRS[10:9] */
756 Tempax &= 0x7F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800757 /* SR3F D[7:2]->VRE D[1:0]->VRS */
758 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530759 } else {
760 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800761 /* Tempax: CR4 HRS */
762 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530763 Tempcx = Tempax; /* Tempcx: HRS */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800764 /* SR2E[7:0]->HRS */
765 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200766
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530767 Tempdx = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SRB */
768 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
769 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
770 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
771 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200772
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530773 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
774 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200775
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530776 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
777 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
778 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
779 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200780
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530781 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
782 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200783
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530784 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
785 if (Tempax < Tempcx) /* HRE < HRS */
786 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200787
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530788 Temp2 &= 0xFF;
789 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
790 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
791 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
792 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800793 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
794 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200795 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200796
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800797 /* CR10 VRS */
798 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530799 Tempbx = Tempax; /* Tempbx: VRS */
800 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200801 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800802 /* CR7[2][7] VRE */
803 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530804 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
805 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
806 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
807 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200808 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200809
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530810 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
811 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
812 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
813 Tempax &= 0x80;
814 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
815 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800816 /* Tempax: SRA */
817 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530818 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
819 Temp2 = Tempax;
820 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
821 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200822
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800823 /* Tempax: CR11 VRE */
824 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530825 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800826 /* Tempbx: SRA */
827 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530828 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
829 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
830 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
831 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
832 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200833
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530834 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
835 if (Tempax < Temp3) /* VRE < VRS */
836 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200837
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530838 Temp2 &= 0xFF;
839 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
840 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
841 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
842 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
843 Tempbx = (unsigned char) Temp1;
844 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
845 Tempax &= 0x7F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800846 /* SR3F D[7:2]->VRE D[1:0]->VRS */
847 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530848 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200849}
850
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800851static void XGI_SetXG27CRTC(unsigned short ModeNo,
852 unsigned short ModeIdIndex,
853 unsigned short RefreshRateTableIndex,
854 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200855{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400856 unsigned short StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200857
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530858 if (ModeNo <= 0x13) {
859 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800860 /* CR04 HRS */
861 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4];
862 /* SR2E [7:0]->HRS */
863 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
864 /* Tempbx: CR05 HRE */
865 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530866 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */
867 Tempcx = Tempax;
868 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */
869 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
870 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */
871 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */
872 Tempdx <<= 2; /* Tempdx << 2 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800873 /* SR2F [7:2]->HRE */
874 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200875 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200876
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800877 /* Tempax: CR10 VRS */
878 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200879 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax); /* SR34[7:0]->VRS */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530880 Tempcx = Tempax; /* Tempcx=Tempax=VRS[7:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800881 /* Tempax[7][2]: CR7[7][2] VRS[9][8] */
882 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530883 Tempbx = Tempax; /* Tempbx=CR07 */
884 Tempax &= 0x04; /* Tempax[2]: CR07[2] VRS[8] */
885 Tempax >>= 2;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800886 /* SR35 D[0]->VRS D[8] */
887 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530888 Tempcx |= (Tempax << 8); /* Tempcx[8] |= VRS[8] */
889 Tempcx |= (Tempbx & 0x80) << 2; /* Tempcx[9] |= VRS[9] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200890
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800891 /* CR11 VRE */
892 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530893 Tempax &= 0x0F; /* Tempax: VRE[3:0] */
894 Tempbx = Tempcx; /* Tempbx=Tempcx=VRS[9:0] */
895 Tempbx &= 0x3F0; /* Tempbx[9:4]: VRS[9:4] */
896 Tempbx |= Tempax; /* Tempbx[9:0]: VRE[9:0] */
897 if (Tempax <= (Tempcx & 0x0F)) /* VRE[3:0]<=VRS[3:0] */
898 Tempbx |= 0x10; /* Tempbx: VRE + 0x10 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800899 /* Tempax[7:0]: VRE[7:0] */
900 Tempax = (unsigned char) Tempbx & 0xFF;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530901 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */
902 Tempcx = (Tempcx & 0x600) >> 8; /* Tempcx VRS[10:9] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800903 /* SR3F D[7:2]->VRE D[5:0] */
904 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
905 /* SR35 D[2:1]->VRS[10:9] */
906 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x06, Tempcx);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530907 } else {
908 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800909 /* Tempax: CR4 HRS */
910 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530911 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800912 /* SR2E[7:0]->HRS */
913 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200914
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800915 /* SR0B */
916 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530917 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
918 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200919
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530920 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
921 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
922 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200923
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530924 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
925 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
926 Tempax <<= 3; /* Tempax[5]: HRE[5] */
927 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200928
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530929 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
930 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200931
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800932 /* Tempax: CR4 HRS */
933 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530934 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
935 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
936 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200937
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530938 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SR0B */
939 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
940 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
941 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800942 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
943 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200944 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200945
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800946 /* CR10 VRS */
947 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
948 /* SR34[7:0]->VRS[7:0] */
949 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200950
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530951 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800952 /* CR7[7][2] VRS[9][8] */
953 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530954 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
955 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
956 Tempax >>= 2; /* Tempax[0]: VRS[8] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800957 /* SR35[0]: VRS[8] */
958 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530959 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
960 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800961 /* Tempax: SR0A */
962 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530963 Tempax &= 0x08; /* SR0A[3] VRS[10] */
964 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200965
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800966 /* Tempax: CR11 VRE */
967 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530968 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800969 /* Tempbx: SR0A */
970 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530971 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
972 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
973 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
974 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
975 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
976 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200977
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530978 if (Tempbx <= Tempcx) /* VRE <= VRS */
979 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200980
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800981 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
982 Tempax = (Tempbx << 2) & 0xFF;
983 /* SR3F[7:2]:VRE[5:0] */
984 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530985 Tempax = Tempcx >> 8;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800986 /* SR35[2:0]:VRS[10:8] */
987 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530988 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200989}
990
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200991/* --------------------------------------------------------------------- */
992/* Function : XGI_SetXG21LCD */
993/* Input : */
994/* Output : FCLK duty cycle, FCLK delay compensation */
995/* Description : All values set zero */
996/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200997static void XGI_SetXG21LCD(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530998 unsigned short RefreshRateTableIndex, unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200999{
Bill Pemberton82d6eb52010-06-17 13:10:46 -04001000 unsigned short Data, Temp, b3CC;
1001 unsigned short XGI_P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001002
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301003 XGI_P3cc = pVBInfo->P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001004
Aaro Koskinen8104e322011-03-13 12:26:22 +02001005 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
1006 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
1007 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
1008 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301009 if (((*pVBInfo->pDVOSetting) & 0xC0) == 0xC0) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001010 xgifb_reg_set(pVBInfo->P3d4, 0x2E, *pVBInfo->pCR2E);
1011 xgifb_reg_set(pVBInfo->P3d4, 0x2F, *pVBInfo->pCR2F);
1012 xgifb_reg_set(pVBInfo->P3d4, 0x46, *pVBInfo->pCR46);
1013 xgifb_reg_set(pVBInfo->P3d4, 0x47, *pVBInfo->pCR47);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301014 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001015
Aaro Koskinen58839b02011-03-13 12:26:23 +02001016 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001017
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301018 if (Temp & 0x01) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001019 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40); /* 18 bits FP */
1020 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301021 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001022
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001023 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001024
Aaro Koskinendc505562011-03-13 12:26:26 +02001025 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20);
1026 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001027
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301028 if (ModeNo <= 0x13) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001029 b3CC = (unsigned char) inb(XGI_P3cc);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301030 if (b3CC & 0x40)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001031 /* Hsync polarity */
1032 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301033 if (b3CC & 0x80)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001034 /* Vsync polarity */
1035 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301036 } else {
1037 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1038 if (Data & 0x4000)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001039 /* Hsync polarity */
1040 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301041 if (Data & 0x8000)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001042 /* Vsync polarity */
1043 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301044 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001045}
1046
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001047static void XGI_SetXG27LCD(struct vb_device_info *pVBInfo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001048 unsigned short RefreshRateTableIndex,
1049 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001050{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301051 unsigned short Data, Temp, b3CC;
1052 unsigned short XGI_P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001053
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301054 XGI_P3cc = pVBInfo->P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001055
Aaro Koskinen8104e322011-03-13 12:26:22 +02001056 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
1057 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
1058 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
1059 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001060
Aaro Koskinen58839b02011-03-13 12:26:23 +02001061 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301062 if ((Temp & 0x03) == 0) { /* dual 12 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02001063 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
1064 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301065 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001066
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301067 if (((*pVBInfo->pDVOSetting) & 0xC0) == 0xC0) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001068 xgifb_reg_set(pVBInfo->P3d4, 0x2E, *pVBInfo->pCR2E);
1069 xgifb_reg_set(pVBInfo->P3d4, 0x2F, *pVBInfo->pCR2F);
1070 xgifb_reg_set(pVBInfo->P3d4, 0x46, *pVBInfo->pCR46);
1071 xgifb_reg_set(pVBInfo->P3d4, 0x47, *pVBInfo->pCR47);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301072 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001073
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301074 XGI_SetXG27FPBits(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001075
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001076 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001077
Aaro Koskinendc505562011-03-13 12:26:26 +02001078 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
1079 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001080
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301081 if (ModeNo <= 0x13) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001082 b3CC = (unsigned char) inb(XGI_P3cc);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301083 if (b3CC & 0x40)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001084 /* Hsync polarity */
1085 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301086 if (b3CC & 0x80)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001087 /* Vsync polarity */
1088 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301089 } else {
1090 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1091 if (Data & 0x4000)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001092 /* Hsync polarity */
1093 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301094 if (Data & 0x8000)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001095 /* Vsync polarity */
1096 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301097 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001098}
1099
1100/* --------------------------------------------------------------------- */
1101/* Function : XGI_UpdateXG21CRTC */
1102/* Input : */
1103/* Output : CRT1 CRTC */
1104/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
1105/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001106static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
1107 struct vb_device_info *pVBInfo,
1108 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001109{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301110 int i, index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001111
Aaro Koskinendc505562011-03-13 12:26:26 +02001112 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301113 if (ModeNo <= 0x13) {
1114 for (i = 0; i < 12; i++) {
1115 if (ModeNo == pVBInfo->UpdateCRT1[i].ModeID)
1116 index = i;
1117 }
1118 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001119 if (ModeNo == 0x2E &&
1120 (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
1121 RES640x480x60))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301122 index = 12;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001123 else if (ModeNo == 0x2E &&
1124 (pVBInfo->RefIndex[RefreshRateTableIndex].
1125 Ext_CRT1CRTC == RES640x480x72))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301126 index = 13;
1127 else if (ModeNo == 0x2F)
1128 index = 14;
1129 else if (ModeNo == 0x50)
1130 index = 15;
1131 else if (ModeNo == 0x59)
1132 index = 16;
1133 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301135 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001136 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301137 pVBInfo->UpdateCRT1[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001138 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301139 pVBInfo->UpdateCRT1[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001140 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301141 pVBInfo->UpdateCRT1[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001142 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301143 pVBInfo->UpdateCRT1[index].CR16);
1144 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001145}
1146
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001147static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301148 unsigned short ModeNo, unsigned short ModeIdIndex,
1149 unsigned short RefreshRateTableIndex,
1150 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001151{
Bill Pemberton82d6eb52010-06-17 13:10:46 -04001152 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001153
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301154 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001155
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301156 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001157
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301158 if (ModeNo <= 0x13) {
1159 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1160 tempax = pVBInfo->StResInfo[resindex].HTotal;
1161 tempbx = pVBInfo->StResInfo[resindex].VTotal;
1162 } else {
1163 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1164 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
1165 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
1166 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001167
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301168 if (modeflag & HalfDCLK)
1169 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001170
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301171 if (ModeNo > 0x13) {
1172 if (modeflag & HalfDCLK)
1173 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001174
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301175 temp = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001176
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301177 if (temp & InterlaceMode)
1178 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301180 if (modeflag & DoubleScanMode)
1181 tempbx = tempbx << 1;
1182 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001183
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301184 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001185
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301186 /* if (!(modeflag & Charx8Dot)) */
1187 /* tempcx = 9; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001188
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301189 tempax /= tempcx;
1190 tempax -= 1;
1191 tempbx -= 1;
1192 tempcx = tempax;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001193 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
1194 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301195 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001196 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
1197 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001198 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301199 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +02001200 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301201 tempax = 0;
1202 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001203
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301204 if (tempbx & 0x01)
1205 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001206
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301207 if (tempbx & 0x02)
1208 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001209
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001210 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001211 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301212 data &= 0xFF;
1213 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001214
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301215 if (tempbx & 0x04)
1216 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001217
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001218 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001219 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001220}
1221
Bill Pemberton82d6eb52010-06-17 13:10:46 -04001222unsigned short XGI_GetResInfo(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301223 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001224{
Bill Pemberton82d6eb52010-06-17 13:10:46 -04001225 unsigned short resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001226
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301227 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001228 /* si+St_ResInfo */
1229 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301230 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001231 /* si+Ext_ResInfo */
1232 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301233 return resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001234}
1235
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001236static void XGI_SetCRT1Offset(unsigned short ModeNo,
1237 unsigned short ModeIdIndex,
1238 unsigned short RefreshRateTableIndex,
1239 struct xgi_hw_device_info *HwDeviceExtension,
1240 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001241{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301242 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001243
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301244 /* GetOffset */
1245 temp = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
1246 temp = temp >> 8;
1247 temp = pVBInfo->ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001248
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301249 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1250 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001251
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301252 if (temp2)
1253 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001254
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301255 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001256
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301257 switch (temp2) {
1258 case 0:
1259 temp2 = 1;
1260 break;
1261 case 1:
1262 temp2 = 2;
1263 break;
1264 case 2:
1265 temp2 = 4;
1266 break;
1267 case 3:
1268 temp2 = 4;
1269 break;
1270 case 4:
1271 temp2 = 6;
1272 break;
1273 case 5:
1274 temp2 = 8;
1275 break;
1276 default:
1277 break;
1278 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001279
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301280 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
1281 temp = temp * temp2 + temp2 / 2;
1282 else
1283 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001284
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301285 /* SetOffset */
1286 DisplayUnit = temp;
1287 temp2 = temp;
1288 temp = temp >> 8; /* ah */
1289 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001290 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301291 i &= 0xF0;
1292 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001293 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001294
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301295 temp = (unsigned char) temp2;
1296 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +02001297 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001298
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301299 /* SetDisplayUnit */
1300 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1301 temp2 &= InterlaceMode;
1302 if (temp2)
1303 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001304
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301305 DisplayUnit = DisplayUnit << 5;
1306 ah = (DisplayUnit & 0xff00) >> 8;
1307 al = DisplayUnit & 0x00ff;
1308 if (al == 0)
1309 ah += 1;
1310 else
1311 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001312
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301313 if (HwDeviceExtension->jChipType >= XG20)
1314 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
1315 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001316
Aaro Koskinen8104e322011-03-13 12:26:22 +02001317 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001318}
1319
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001320static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
1321 unsigned short ModeIdIndex,
1322 unsigned short RefreshRateTableIndex,
1323 struct xgi_hw_device_info *HwDeviceExtension,
1324 struct vb_device_info *pVBInfo)
1325{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001326 unsigned short LCDXlat1VCLK[4] = { VCLK65 + 2,
1327 VCLK65 + 2,
1328 VCLK65 + 2,
1329 VCLK65 + 2 };
1330 unsigned short LCDXlat2VCLK[4] = { VCLK108_2 + 5,
1331 VCLK108_2 + 5,
1332 VCLK108_2 + 5,
1333 VCLK108_2 + 5 };
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001334 unsigned short LVDSXlat1VCLK[4] = { VCLK40, VCLK40, VCLK40, VCLK40 };
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001335 unsigned short LVDSXlat2VCLK[4] = { VCLK65 + 2,
1336 VCLK65 + 2,
1337 VCLK65 + 2,
1338 VCLK65 + 2 };
1339 unsigned short LVDSXlat3VCLK[4] = { VCLK65 + 2,
1340 VCLK65 + 2,
1341 VCLK65 + 2,
1342 VCLK65 + 2 };
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001343
1344 unsigned short CRT2Index, VCLKIndex;
1345 unsigned short modeflag, resinfo;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001346
1347 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001348 /* si+St_ResInfo */
1349 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001350 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1351 CRT2Index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1352 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001353 /* si+Ext_ResInfo */
1354 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001355 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001356 CRT2Index = pVBInfo->RefIndex[RefreshRateTableIndex].
1357 Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001358 }
1359
1360 if (pVBInfo->IF_DEF_LVDS == 0) {
1361 CRT2Index = CRT2Index >> 6; /* for LCD */
1362 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /*301b*/
1363 if (pVBInfo->LCDResInfo != Panel1024x768)
1364 VCLKIndex = LCDXlat2VCLK[CRT2Index];
1365 else
1366 VCLKIndex = LCDXlat1VCLK[CRT2Index];
1367 } else { /* for TV */
1368 if (pVBInfo->VBInfo & SetCRT2ToTV) {
1369 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
1370 if (pVBInfo->SetFlag & RPLLDIV2XO) {
1371 VCLKIndex = HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001372 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001373 } else {
1374 VCLKIndex = HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001375 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001376 }
1377
1378 if (pVBInfo->SetFlag & TVSimuMode) {
1379 if (modeflag & Charx8Dot) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001380 VCLKIndex =
1381 HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001382 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001383 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001384 VCLKIndex =
1385 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001386 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001387 }
1388 }
1389
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001390 /* 301lv */
1391 if (pVBInfo->VBType & VB_XGI301LV) {
1392 if (!(pVBInfo->VBExtInfo ==
1393 VB_YPbPr1080i)) {
1394 VCLKIndex =
1395 YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001396 if (!(pVBInfo->VBExtInfo
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001397 ==
1398 VB_YPbPr750p)) {
1399 VCLKIndex =
1400 YPbPr525pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001401 if (!(pVBInfo->VBExtInfo
1402 == VB_YPbPr525p)) {
1403 VCLKIndex
1404 = YPbPr525iVCLK_2;
1405 if (!(pVBInfo->SetFlag
1406 & RPLLDIV2XO))
1407 VCLKIndex
1408 = YPbPr525iVCLK;
1409 }
1410 }
1411 }
1412 }
1413 } else {
1414 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001415 if (pVBInfo->SetFlag &
1416 RPLLDIV2XO) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001417 VCLKIndex = TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001418 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001419 } else {
1420 VCLKIndex = TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001421 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001422 }
1423 }
1424 }
1425 } else { /* for CRT2 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001426 /* Port 3cch */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001427 VCLKIndex = (unsigned char) inb(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001428 (pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001429 VCLKIndex = ((VCLKIndex >> 2) & 0x03);
1430 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001431 /* di+Ext_CRTVCLK */
1432 VCLKIndex =
1433 pVBInfo->RefIndex[
1434 RefreshRateTableIndex].
1435 Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001436 VCLKIndex &= IndexMask;
1437 }
1438 }
1439 }
1440 } else { /* LVDS */
1441 if (ModeNo <= 0x13)
1442 VCLKIndex = CRT2Index;
1443 else
1444 VCLKIndex = CRT2Index;
1445
Aaro Koskinen4c14bfd2011-08-31 21:45:57 +03001446 VCLKIndex = VCLKIndex >> 6;
1447 if ((pVBInfo->LCDResInfo == Panel800x600) ||
1448 (pVBInfo->LCDResInfo == Panel320x480))
1449 VCLKIndex = LVDSXlat1VCLK[VCLKIndex];
1450 else if ((pVBInfo->LCDResInfo == Panel1024x768) ||
1451 (pVBInfo->LCDResInfo == Panel1024x768x75))
1452 VCLKIndex = LVDSXlat2VCLK[VCLKIndex];
1453 else
1454 VCLKIndex = LVDSXlat3VCLK[VCLKIndex];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001455 }
1456 /* VCLKIndex = VCLKIndex&IndexMask; */
1457
1458 return VCLKIndex;
1459}
1460
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001461static void XGI_SetCRT1VCLK(unsigned short ModeNo,
1462 unsigned short ModeIdIndex,
1463 struct xgi_hw_device_info *HwDeviceExtension,
1464 unsigned short RefreshRateTableIndex,
1465 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001466{
Bill Pemberton108afbf2010-06-17 13:10:47 -04001467 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301468 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001469
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301470 if (pVBInfo->IF_DEF_LVDS == 1) {
1471 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001472 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001473 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1474 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301475 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001476 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301477 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001478 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301479 } else if ((pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
1480 | VB_XGI302LV | VB_XGI301C)) && (pVBInfo->VBInfo
1481 & SetCRT2ToLCDA)) {
1482 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
1483 RefreshRateTableIndex, HwDeviceExtension,
1484 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001485 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001486 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301487 data = pVBInfo->VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001488 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301489 data = pVBInfo->VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001490 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1491 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301492 } else {
1493 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001494 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001495 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1496 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301497 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001498 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301499 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001500 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301501 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001502
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301503 if (HwDeviceExtension->jChipType >= XG20) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001504 if (pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag &
1505 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001506 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001507 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001508 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301509 index = data;
1510 index &= 0xE0;
1511 data &= 0x1F;
1512 data = data << 1;
1513 data += 1;
1514 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001515 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301516 }
1517 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001518}
1519
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001520static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301521 struct xgi_hw_device_info *HwDeviceExtension,
1522 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001523{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301524 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001525
Aaro Koskinen58839b02011-03-13 12:26:23 +02001526 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301527 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001528 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001529
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301530 if (ModeNo > 0x13) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001531 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001532 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301533 data &= 0xC0;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001534 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001535 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301536 data |= 0x01;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001537 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301538 } else {
1539 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001540 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x0E);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001541 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301542 data &= 0xC0;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001543 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301544 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001545 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0xAE);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001546 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301547 data &= 0xF0;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001548 xgifb_reg_set(pVBInfo->P3c4, 0x09, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301549 }
1550 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001551
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301552 if (HwDeviceExtension->jChipType == XG21)
1553 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001554}
1555
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001556static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1557 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1558 struct vb_device_info *pVBInfo)
1559{
1560 unsigned short data, data2 = 0;
1561 short VCLK;
1562
1563 unsigned char index;
1564
1565 if (ModeNo <= 0x13)
1566 VCLK = 0;
1567 else {
1568 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1569 index &= IndexMask;
1570 VCLK = pVBInfo->VCLKData[index].CLOCK;
1571 }
1572
Aaro Koskinen58839b02011-03-13 12:26:23 +02001573 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001574 data &= 0xf3;
1575 if (VCLK >= 200)
1576 data |= 0x0c; /* VCLK > 200 */
1577
1578 if (HwDeviceExtension->jChipType >= XG20)
1579 data &= ~0x04; /* 2 pixel mode */
1580
Aaro Koskinen8104e322011-03-13 12:26:22 +02001581 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001582
1583 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001584 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001585 data &= 0xE7;
1586 if (VCLK < 200)
1587 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001588 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001589 }
1590
1591 /* Jong for Adavantech LCD ripple issue
1592 if ((VCLK >= 0) && (VCLK < 135))
1593 data2 = 0x03;
1594 else if ((VCLK >= 135) && (VCLK < 160))
1595 data2 = 0x02;
1596 else if ((VCLK >= 160) && (VCLK < 260))
1597 data2 = 0x01;
1598 else if (VCLK > 260)
1599 data2 = 0x00;
1600 */
1601 data2 = 0x00;
1602
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001603 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001604 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001605 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001606
1607}
1608
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001609static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301610 unsigned short ModeNo, unsigned short ModeIdIndex,
1611 unsigned short RefreshRateTableIndex,
1612 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001613{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301614 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1615 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001616
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301617 if (ModeNo > 0x13) {
1618 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001619 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].
1620 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301621 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001622 /* si+St_ModeFlag */
1623 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001624
Aaro Koskinen58839b02011-03-13 12:26:23 +02001625 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001626 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001627
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301628 if (ModeNo > 0x13)
1629 data = infoflag;
1630 else
1631 data = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001632
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301633 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001634
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301635 if (ModeNo > 0x13) {
1636 if (pVBInfo->ModeType > 0x02) {
1637 data2 |= 0x02;
1638 data3 = pVBInfo->ModeType - ModeVGA;
1639 data3 = data3 << 2;
1640 data2 |= data3;
1641 }
1642 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001643
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301644 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001645
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301646 if (data)
1647 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001648
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001649 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001650 /* xgifb_reg_set(pVBInfo->P3c4,0x06,data2); */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301651 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
1652 if (ModeNo <= 0x13)
1653 xres = pVBInfo->StResInfo[resindex].HTotal;
1654 else
1655 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001656
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301657 data = 0x0000;
1658 if (infoflag & InterlaceMode) {
1659 if (xres == 1024)
1660 data = 0x0035;
1661 else if (xres == 1280)
1662 data = 0x0048;
1663 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001664
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301665 data2 = data & 0x00FF;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001666 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301667 data2 = (data & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001668 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001669
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301670 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001671 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001672
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301673 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001674
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301675 if (modeflag & LineCompareOff)
1676 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001677
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301678 if (ModeNo > 0x13) {
1679 if (pVBInfo->ModeType == ModeEGA)
1680 data2 |= 0x40;
1681 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001682
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001683 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301684 data = 0x60;
1685 if (pVBInfo->ModeType != ModeText) {
1686 data = data ^ 0x60;
1687 if (pVBInfo->ModeType != ModeEGA)
1688 data = data ^ 0xA0;
1689 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001690 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001691
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301692 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1693 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001694
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301695 /* if (modeflag&HalfDCLK) //030305 fix lowresolution bug */
1696 /* if (XGINew_IF_DEF_NEW_LOWRES) */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001697 /* XGI_VesaLowResolution(ModeNo, ModeIdIndex);
1698 * //030305 fix lowresolution bug */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001699
Aaro Koskinen58839b02011-03-13 12:26:23 +02001700 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001701
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301702 if (HwDeviceExtension->jChipType == XG27) {
1703 if (data & 0x40)
1704 data = 0x2c;
1705 else
1706 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001707 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001708 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301709 } else if (HwDeviceExtension->jChipType >= XG20) {
1710 if (data & 0x40)
1711 data = 0x33;
1712 else
1713 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001714 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1715 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301716 } else {
1717 if (data & 0x40)
1718 data = 0x2c;
1719 else
1720 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001721 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301722 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001723
1724}
1725
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301726/*
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001727void XGI_VesaLowResolution(unsigned short ModeNo,
1728 unsigned short ModeIdIndex,
1729 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001730{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301731 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001732
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301733 if (ModeNo > 0x13)
1734 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1735 else
1736 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001737
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301738 if (ModeNo > 0x13) {
1739 if (modeflag & DoubleScanMode) {
1740 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001741 if (pVBInfo->VBType & VB_XGI301B |
1742 VB_XGI302B |
1743 VB_XGI301LV |
1744 VB_XGI302LV |
1745 VB_XGI301C)) {
1746 if (!(pVBInfo->VBInfo &
1747 SetCRT2ToRAMDAC)) {
1748 if (pVBInfo->VBInfo &
1749 SetInSlaveMode) {
1750 xgifb_reg_and_or(
1751 pVBInfo->P3c4,
1752 0x01,
1753 0xf7,
1754 0x00);
1755 xgifb_reg_and_or(
1756 pVBInfo->P3c4,
1757 0x0f,
1758 0x7f,
1759 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301760 return;
1761 }
1762 }
1763 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001764 xgifb_reg_and_or(pVBInfo->P3c4,
1765 0x0f,
1766 0xff,
1767 0x80);
1768 xgifb_reg_and_or(pVBInfo->P3c4,
1769 0x01,
1770 0xf7,
1771 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301772 return;
1773 }
1774 }
1775 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001776 xgifb_reg_and_or(pVBInfo->P3c4, 0x0f, 0x7f, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001777}
1778*/
1779
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001780static void XGI_WriteDAC(unsigned short dl,
1781 unsigned short ah,
1782 unsigned short al,
1783 unsigned short dh,
1784 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001785{
1786 unsigned short temp, bh, bl;
1787
1788 bh = ah;
1789 bl = al;
1790
1791 if (dl != 0) {
1792 temp = bh;
1793 bh = dh;
1794 dh = temp;
1795 if (dl == 1) {
1796 temp = bl;
1797 bl = dh;
1798 dh = temp;
1799 } else {
1800 temp = bl;
1801 bl = bh;
1802 bh = temp;
1803 }
1804 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001805 outb((unsigned short) dh, pVBInfo->P3c9);
1806 outb((unsigned short) bh, pVBInfo->P3c9);
1807 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001808}
1809
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001810static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301811 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001812{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301813 unsigned short data, data2, time, i, j, k, m, n, o, si, di, bx, dl, al,
1814 ah, dh, *table = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001815
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301816 if (ModeNo <= 0x13)
1817 data = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1818 else
1819 data = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001820
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301821 data &= DACInfoFlag;
1822 time = 64;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001823
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301824 if (data == 0x00)
1825 table = XGINew_MDA_DAC;
1826 else if (data == 0x08)
1827 table = XGINew_CGA_DAC;
1828 else if (data == 0x10)
1829 table = XGINew_EGA_DAC;
1830 else if (data == 0x18) {
1831 time = 256;
1832 table = XGINew_VGA_DAC;
1833 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001834
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301835 if (time == 256)
1836 j = 16;
1837 else
1838 j = time;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001839
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001840 outb(0xFF, pVBInfo->P3c6);
1841 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001842
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301843 for (i = 0; i < j; i++) {
1844 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001845
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301846 for (k = 0; k < 3; k++) {
1847 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001848
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301849 if (data & 0x01)
1850 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001851
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301852 if (data & 0x02)
1853 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001854
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001855 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301856 data = data >> 2;
1857 }
1858 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001859
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301860 if (time == 256) {
1861 for (i = 16; i < 32; i++) {
1862 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001863
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301864 for (k = 0; k < 3; k++)
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001865 outb(data, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301866 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001867
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301868 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001869
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301870 for (m = 0; m < 9; m++) {
1871 di = si;
1872 bx = si + 0x04;
1873 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001874
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301875 for (n = 0; n < 3; n++) {
1876 for (o = 0; o < 5; o++) {
1877 dh = table[si];
1878 ah = table[di];
1879 al = table[bx];
1880 si++;
1881 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1882 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001883
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301884 si -= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001885
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301886 for (o = 0; o < 3; o++) {
1887 dh = table[bx];
1888 ah = table[di];
1889 al = table[si];
1890 si--;
1891 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1892 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001893
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301894 dl++;
1895 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001896
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301897 si += 5;
1898 }
1899 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001900}
1901
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001902static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1903 unsigned short ModeIdIndex,
1904 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001905{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301906 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001907
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301908 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001909 /* si+St_ResInfo */
1910 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301911 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001912 /* si+Ext_ResInfo */
1913 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001914
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301915 /* if (ModeNo > 0x13) */
1916 /* modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag; */
1917 /* else */
1918 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001919
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301920 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001921 /* si+St_ResInfo */
1922 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301923 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001924 /* si+Ext_ResInfo */
1925 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001926
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301927 /* resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001928
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301929 if (ModeNo <= 0x13) {
1930 xres = pVBInfo->StResInfo[resindex].HTotal;
1931 yres = pVBInfo->StResInfo[resindex].VTotal;
1932 } else {
1933 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1934 yres = pVBInfo->ModeResInfo[resindex].VTotal;
1935 }
1936 if (ModeNo > 0x13) {
1937 if (modeflag & HalfDCLK)
1938 xres = xres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001939
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301940 if (modeflag & DoubleScanMode)
1941 yres = yres << 1;
1942 }
1943 /* if (modeflag & Charx8Dot) */
1944 /* { */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001945
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301946 if (xres == 720)
1947 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001948
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301949 /* } */
1950 pVBInfo->VGAHDE = xres;
1951 pVBInfo->HDE = xres;
1952 pVBInfo->VGAVDE = yres;
1953 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001954}
1955
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001956static void *XGI_GetLcdPtr(unsigned short BX, unsigned short ModeNo,
1957 unsigned short ModeIdIndex,
1958 unsigned short RefreshRateTableIndex,
1959 struct vb_device_info *pVBInfo)
1960{
1961 unsigned short i, tempdx, tempcx, tempbx, tempal, modeflag, table;
1962
1963 struct XGI330_LCDDataTablStruct *tempdi = NULL;
1964
1965 tempbx = BX;
1966
1967 if (ModeNo <= 0x13) {
1968 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1969 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1970 } else {
1971 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1972 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1973 }
1974
1975 tempal = tempal & 0x0f;
1976
1977 if (tempbx <= 1) { /* ExpLink */
1978 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001979 /* find no Ext_CRT2CRTC2 */
1980 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001981 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001982 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].
1983 Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001984 }
1985
1986 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
1987 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001988 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
1989 St_CRT2CRTC2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001990 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001991 tempal = pVBInfo->RefIndex[
1992 RefreshRateTableIndex].
1993 Ext_CRT2CRTC2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001994 }
1995
1996 if (tempbx & 0x01)
1997 tempal = (tempal >> 4);
1998
1999 tempal = (tempal & 0x0f);
2000 }
2001
2002 tempcx = LCDLenList[tempbx]; /* mov cl,byte ptr cs:LCDLenList[bx] */
2003
2004 if (pVBInfo->LCDInfo & EnableScalingLCD) { /* ScaleLCD */
2005 if ((tempbx == 5) || (tempbx) == 7)
2006 tempcx = LCDDesDataLen2;
2007 else if ((tempbx == 3) || (tempbx == 8))
2008 tempcx = LVDSDesDataLen2;
2009 }
2010 /* mov di, word ptr cs:LCDDataList[bx] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002011 /* tempdi = pVideoMemory[LCDDataList + tempbx * 2] |
2012 (pVideoMemory[LCDDataList + tempbx * 2 + 1] << 8); */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002013
2014 switch (tempbx) {
2015 case 0:
2016 tempdi = XGI_EPLLCDCRT1Ptr_H;
2017 break;
2018 case 1:
2019 tempdi = XGI_EPLLCDCRT1Ptr_V;
2020 break;
2021 case 2:
2022 tempdi = XGI_EPLLCDDataPtr;
2023 break;
2024 case 3:
2025 tempdi = XGI_EPLLCDDesDataPtr;
2026 break;
2027 case 4:
2028 tempdi = XGI_LCDDataTable;
2029 break;
2030 case 5:
2031 tempdi = XGI_LCDDesDataTable;
2032 break;
2033 case 6:
2034 tempdi = XGI_EPLCHLCDRegPtr;
2035 break;
2036 case 7:
2037 case 8:
2038 case 9:
2039 tempdi = NULL;
2040 break;
2041 default:
2042 break;
2043 }
2044
2045 if (tempdi == NULL) /* OEMUtil */
2046 return NULL;
2047
2048 table = tempbx;
2049 i = 0;
2050
2051 while (tempdi[i].PANELID != 0xff) {
2052 tempdx = pVBInfo->LCDResInfo;
2053 if (tempbx & 0x0080) { /* OEMUtil */
2054 tempbx &= (~0x0080);
2055 tempdx = pVBInfo->LCDTypeInfo;
2056 }
2057
2058 if (pVBInfo->LCDInfo & EnableScalingLCD)
2059 tempdx &= (~PanelResInfo);
2060
2061 if (tempdi[i].PANELID == tempdx) {
2062 tempbx = tempdi[i].MASK;
2063 tempdx = pVBInfo->LCDInfo;
2064
2065 if (ModeNo <= 0x13) /* alan 09/10/2003 */
2066 tempdx |= SetLCDStdMode;
2067
2068 if (modeflag & HalfDCLK)
2069 tempdx |= SetLCDLowResolution;
2070
2071 tempbx &= tempdx;
2072 if (tempbx == tempdi[i].CAP)
2073 break;
2074 }
2075 i++;
2076 }
2077
2078 if (table == 0) {
2079 switch (tempdi[i].DATAPTR) {
2080 case 0:
2081 return &XGI_LVDSCRT11024x768_1_H[tempal];
2082 break;
2083 case 1:
2084 return &XGI_LVDSCRT11024x768_2_H[tempal];
2085 break;
2086 case 2:
2087 return &XGI_LVDSCRT11280x1024_1_H[tempal];
2088 break;
2089 case 3:
2090 return &XGI_LVDSCRT11280x1024_2_H[tempal];
2091 break;
2092 case 4:
2093 return &XGI_LVDSCRT11400x1050_1_H[tempal];
2094 break;
2095 case 5:
2096 return &XGI_LVDSCRT11400x1050_2_H[tempal];
2097 break;
2098 case 6:
2099 return &XGI_LVDSCRT11600x1200_1_H[tempal];
2100 break;
2101 case 7:
2102 return &XGI_LVDSCRT11024x768_1_Hx75[tempal];
2103 break;
2104 case 8:
2105 return &XGI_LVDSCRT11024x768_2_Hx75[tempal];
2106 break;
2107 case 9:
2108 return &XGI_LVDSCRT11280x1024_1_Hx75[tempal];
2109 break;
2110 case 10:
2111 return &XGI_LVDSCRT11280x1024_2_Hx75[tempal];
2112 break;
2113 default:
2114 break;
2115 }
2116 } else if (table == 1) {
2117 switch (tempdi[i].DATAPTR) {
2118 case 0:
2119 return &XGI_LVDSCRT11024x768_1_V[tempal];
2120 break;
2121 case 1:
2122 return &XGI_LVDSCRT11024x768_2_V[tempal];
2123 break;
2124 case 2:
2125 return &XGI_LVDSCRT11280x1024_1_V[tempal];
2126 break;
2127 case 3:
2128 return &XGI_LVDSCRT11280x1024_2_V[tempal];
2129 break;
2130 case 4:
2131 return &XGI_LVDSCRT11400x1050_1_V[tempal];
2132 break;
2133 case 5:
2134 return &XGI_LVDSCRT11400x1050_2_V[tempal];
2135 break;
2136 case 6:
2137 return &XGI_LVDSCRT11600x1200_1_V[tempal];
2138 break;
2139 case 7:
2140 return &XGI_LVDSCRT11024x768_1_Vx75[tempal];
2141 break;
2142 case 8:
2143 return &XGI_LVDSCRT11024x768_2_Vx75[tempal];
2144 break;
2145 case 9:
2146 return &XGI_LVDSCRT11280x1024_1_Vx75[tempal];
2147 break;
2148 case 10:
2149 return &XGI_LVDSCRT11280x1024_2_Vx75[tempal];
2150 break;
2151 default:
2152 break;
2153 }
2154 } else if (table == 2) {
2155 switch (tempdi[i].DATAPTR) {
2156 case 0:
2157 return &XGI_LVDS1024x768Data_1[tempal];
2158 break;
2159 case 1:
2160 return &XGI_LVDS1024x768Data_2[tempal];
2161 break;
2162 case 2:
2163 return &XGI_LVDS1280x1024Data_1[tempal];
2164 break;
2165 case 3:
2166 return &XGI_LVDS1280x1024Data_2[tempal];
2167 break;
2168 case 4:
2169 return &XGI_LVDS1400x1050Data_1[tempal];
2170 break;
2171 case 5:
2172 return &XGI_LVDS1400x1050Data_2[tempal];
2173 break;
2174 case 6:
2175 return &XGI_LVDS1600x1200Data_1[tempal];
2176 break;
2177 case 7:
2178 return &XGI_LVDSNoScalingData[tempal];
2179 break;
2180 case 8:
2181 return &XGI_LVDS1024x768Data_1x75[tempal];
2182 break;
2183 case 9:
2184 return &XGI_LVDS1024x768Data_2x75[tempal];
2185 break;
2186 case 10:
2187 return &XGI_LVDS1280x1024Data_1x75[tempal];
2188 break;
2189 case 11:
2190 return &XGI_LVDS1280x1024Data_2x75[tempal];
2191 break;
2192 case 12:
2193 return &XGI_LVDSNoScalingDatax75[tempal];
2194 break;
2195 default:
2196 break;
2197 }
2198 } else if (table == 3) {
2199 switch (tempdi[i].DATAPTR) {
2200 case 0:
2201 return &XGI_LVDS1024x768Des_1[tempal];
2202 break;
2203 case 1:
2204 return &XGI_LVDS1024x768Des_3[tempal];
2205 break;
2206 case 2:
2207 return &XGI_LVDS1024x768Des_2[tempal];
2208 break;
2209 case 3:
2210 return &XGI_LVDS1280x1024Des_1[tempal];
2211 break;
2212 case 4:
2213 return &XGI_LVDS1280x1024Des_2[tempal];
2214 break;
2215 case 5:
2216 return &XGI_LVDS1400x1050Des_1[tempal];
2217 break;
2218 case 6:
2219 return &XGI_LVDS1400x1050Des_2[tempal];
2220 break;
2221 case 7:
2222 return &XGI_LVDS1600x1200Des_1[tempal];
2223 break;
2224 case 8:
2225 return &XGI_LVDSNoScalingDesData[tempal];
2226 break;
2227 case 9:
2228 return &XGI_LVDS1024x768Des_1x75[tempal];
2229 break;
2230 case 10:
2231 return &XGI_LVDS1024x768Des_3x75[tempal];
2232 break;
2233 case 11:
2234 return &XGI_LVDS1024x768Des_2x75[tempal];
2235 break;
2236 case 12:
2237 return &XGI_LVDS1280x1024Des_1x75[tempal];
2238 break;
2239 case 13:
2240 return &XGI_LVDS1280x1024Des_2x75[tempal];
2241 break;
2242 case 14:
2243 return &XGI_LVDSNoScalingDesDatax75[tempal];
2244 break;
2245 default:
2246 break;
2247 }
2248 } else if (table == 4) {
2249 switch (tempdi[i].DATAPTR) {
2250 case 0:
2251 return &XGI_ExtLCD1024x768Data[tempal];
2252 break;
2253 case 1:
2254 return &XGI_StLCD1024x768Data[tempal];
2255 break;
2256 case 2:
2257 return &XGI_CetLCD1024x768Data[tempal];
2258 break;
2259 case 3:
2260 return &XGI_ExtLCD1280x1024Data[tempal];
2261 break;
2262 case 4:
2263 return &XGI_StLCD1280x1024Data[tempal];
2264 break;
2265 case 5:
2266 return &XGI_CetLCD1280x1024Data[tempal];
2267 break;
2268 case 6:
2269 return &XGI_ExtLCD1400x1050Data[tempal];
2270 break;
2271 case 7:
2272 return &XGI_StLCD1400x1050Data[tempal];
2273 break;
2274 case 8:
2275 return &XGI_CetLCD1400x1050Data[tempal];
2276 break;
2277 case 9:
2278 return &XGI_ExtLCD1600x1200Data[tempal];
2279 break;
2280 case 10:
2281 return &XGI_StLCD1600x1200Data[tempal];
2282 break;
2283 case 11:
2284 return &XGI_NoScalingData[tempal];
2285 break;
2286 case 12:
2287 return &XGI_ExtLCD1024x768x75Data[tempal];
2288 break;
2289 case 13:
2290 return &XGI_ExtLCD1024x768x75Data[tempal];
2291 break;
2292 case 14:
2293 return &XGI_CetLCD1024x768x75Data[tempal];
2294 break;
2295 case 15:
2296 return &XGI_ExtLCD1280x1024x75Data[tempal];
2297 break;
2298 case 16:
2299 return &XGI_StLCD1280x1024x75Data[tempal];
2300 break;
2301 case 17:
2302 return &XGI_CetLCD1280x1024x75Data[tempal];
2303 break;
2304 case 18:
2305 return &XGI_NoScalingDatax75[tempal];
2306 break;
2307 default:
2308 break;
2309 }
2310 } else if (table == 5) {
2311 switch (tempdi[i].DATAPTR) {
2312 case 0:
2313 return &XGI_ExtLCDDes1024x768Data[tempal];
2314 break;
2315 case 1:
2316 return &XGI_StLCDDes1024x768Data[tempal];
2317 break;
2318 case 2:
2319 return &XGI_CetLCDDes1024x768Data[tempal];
2320 break;
2321 case 3:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002322 if ((pVBInfo->VBType & VB_XGI301LV) ||
2323 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002324 return &XGI_ExtLCDDLDes1280x1024Data[tempal];
2325 else
2326 return &XGI_ExtLCDDes1280x1024Data[tempal];
2327 break;
2328 case 4:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002329 if ((pVBInfo->VBType & VB_XGI301LV) ||
2330 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002331 return &XGI_StLCDDLDes1280x1024Data[tempal];
2332 else
2333 return &XGI_StLCDDes1280x1024Data[tempal];
2334 break;
2335 case 5:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002336 if ((pVBInfo->VBType & VB_XGI301LV) ||
2337 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002338 return &XGI_CetLCDDLDes1280x1024Data[tempal];
2339 else
2340 return &XGI_CetLCDDes1280x1024Data[tempal];
2341 break;
2342 case 6:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002343 if ((pVBInfo->VBType & VB_XGI301LV) ||
2344 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002345 return &XGI_ExtLCDDLDes1400x1050Data[tempal];
2346 else
2347 return &XGI_ExtLCDDes1400x1050Data[tempal];
2348 break;
2349 case 7:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002350 if ((pVBInfo->VBType & VB_XGI301LV) ||
2351 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002352 return &XGI_StLCDDLDes1400x1050Data[tempal];
2353 else
2354 return &XGI_StLCDDes1400x1050Data[tempal];
2355 break;
2356 case 8:
2357 return &XGI_CetLCDDes1400x1050Data[tempal];
2358 break;
2359 case 9:
2360 return &XGI_CetLCDDes1400x1050Data2[tempal];
2361 break;
2362 case 10:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002363 if ((pVBInfo->VBType & VB_XGI301LV) ||
2364 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002365 return &XGI_ExtLCDDLDes1600x1200Data[tempal];
2366 else
2367 return &XGI_ExtLCDDes1600x1200Data[tempal];
2368 break;
2369 case 11:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002370 if ((pVBInfo->VBType & VB_XGI301LV) ||
2371 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002372 return &XGI_StLCDDLDes1600x1200Data[tempal];
2373 else
2374 return &XGI_StLCDDes1600x1200Data[tempal];
2375 break;
2376 case 12:
2377 return &XGI_NoScalingDesData[tempal];
2378 break;
2379 case 13:
2380 return &XGI_ExtLCDDes1024x768x75Data[tempal];
2381 break;
2382 case 14:
2383 return &XGI_StLCDDes1024x768x75Data[tempal];
2384 break;
2385 case 15:
2386 return &XGI_CetLCDDes1024x768x75Data[tempal];
2387 break;
2388 case 16:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002389 if ((pVBInfo->VBType & VB_XGI301LV) ||
2390 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002391 return &XGI_ExtLCDDLDes1280x1024x75Data[tempal];
2392 else
2393 return &XGI_ExtLCDDes1280x1024x75Data[tempal];
2394 break;
2395 case 17:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002396 if ((pVBInfo->VBType & VB_XGI301LV) ||
2397 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002398 return &XGI_StLCDDLDes1280x1024x75Data[tempal];
2399 else
2400 return &XGI_StLCDDes1280x1024x75Data[tempal];
2401 break;
2402 case 18:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002403 if ((pVBInfo->VBType & VB_XGI301LV) ||
2404 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002405 return &XGI_CetLCDDLDes1280x1024x75Data[tempal];
2406 else
2407 return &XGI_CetLCDDes1280x1024x75Data[tempal];
2408 break;
2409 case 19:
2410 return &XGI_NoScalingDesDatax75[tempal];
2411 break;
2412 default:
2413 break;
2414 }
2415 } else if (table == 6) {
2416 switch (tempdi[i].DATAPTR) {
2417 case 0:
2418 return &XGI_CH7017LV1024x768[tempal];
2419 break;
2420 case 1:
2421 return &XGI_CH7017LV1400x1050[tempal];
2422 break;
2423 default:
2424 break;
2425 }
2426 }
2427 return NULL;
2428}
2429
2430static void *XGI_GetTVPtr(unsigned short BX, unsigned short ModeNo,
2431 unsigned short ModeIdIndex,
2432 unsigned short RefreshRateTableIndex,
2433 struct vb_device_info *pVBInfo)
2434{
2435 unsigned short i, tempdx, tempbx, tempal, modeflag, table;
2436 struct XGI330_TVDataTablStruct *tempdi = NULL;
2437
2438 tempbx = BX;
2439
2440 if (ModeNo <= 0x13) {
2441 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2442 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2443 } else {
2444 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2445 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2446 }
2447
2448 tempal = tempal & 0x3f;
2449 table = tempbx;
2450
2451 switch (tempbx) {
2452 case 0:
2453 tempdi = NULL; /*EPLCHTVCRT1Ptr_H;*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002454 break;
2455 case 1:
2456 tempdi = NULL; /*EPLCHTVCRT1Ptr_V;*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002457 break;
2458 case 2:
2459 tempdi = XGI_EPLCHTVDataPtr;
2460 break;
2461 case 3:
2462 tempdi = NULL;
2463 break;
2464 case 4:
2465 tempdi = XGI_TVDataTable;
2466 break;
2467 case 5:
2468 tempdi = NULL;
2469 break;
2470 case 6:
2471 tempdi = XGI_EPLCHTVRegPtr;
2472 break;
2473 default:
2474 break;
2475 }
2476
2477 if (tempdi == NULL) /* OEMUtil */
2478 return NULL;
2479
2480 tempdx = pVBInfo->TVInfo;
2481
2482 if (pVBInfo->VBInfo & SetInSlaveMode)
2483 tempdx = tempdx | SetTVLockMode;
2484
2485 if (modeflag & HalfDCLK)
2486 tempdx = tempdx | SetTVLowResolution;
2487
2488 i = 0;
2489
2490 while (tempdi[i].MASK != 0xffff) {
2491 if ((tempdx & tempdi[i].MASK) == tempdi[i].CAP)
2492 break;
2493 i++;
2494 }
2495
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002496 /* 07/05/22 */
2497 if (table == 0x00) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002498 } else if (table == 0x01) {
2499 } else if (table == 0x04) {
2500 switch (tempdi[i].DATAPTR) {
2501 case 0:
2502 return &XGI_ExtPALData[tempal];
2503 break;
2504 case 1:
2505 return &XGI_ExtNTSCData[tempal];
2506 break;
2507 case 2:
2508 return &XGI_StPALData[tempal];
2509 break;
2510 case 3:
2511 return &XGI_StNTSCData[tempal];
2512 break;
2513 case 4:
2514 return &XGI_ExtHiTVData[tempal];
2515 break;
2516 case 5:
2517 return &XGI_St2HiTVData[tempal];
2518 break;
2519 case 6:
2520 return &XGI_ExtYPbPr525iData[tempal];
2521 break;
2522 case 7:
2523 return &XGI_ExtYPbPr525pData[tempal];
2524 break;
2525 case 8:
2526 return &XGI_ExtYPbPr750pData[tempal];
2527 break;
2528 case 9:
2529 return &XGI_StYPbPr525iData[tempal];
2530 break;
2531 case 10:
2532 return &XGI_StYPbPr525pData[tempal];
2533 break;
2534 case 11:
2535 return &XGI_StYPbPr750pData[tempal];
2536 break;
2537 case 12: /* avoid system hang */
2538 return &XGI_ExtNTSCData[tempal];
2539 break;
2540 case 13:
2541 return &XGI_St1HiTVData[tempal];
2542 break;
2543 default:
2544 break;
2545 }
2546 } else if (table == 0x02) {
2547 switch (tempdi[i].DATAPTR) {
2548 case 0:
2549 return &XGI_CHTVUNTSCData[tempal];
2550 break;
2551 case 1:
2552 return &XGI_CHTVONTSCData[tempal];
2553 break;
2554 case 2:
2555 return &XGI_CHTVUPALData[tempal];
2556 break;
2557 case 3:
2558 return &XGI_CHTVOPALData[tempal];
2559 break;
2560 default:
2561 break;
2562 }
2563 } else if (table == 0x06) {
2564 }
2565 return NULL;
2566}
2567
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002568static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302569 unsigned short RefreshRateTableIndex,
2570 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002571{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302572 unsigned short tempbx;
2573 struct XGI330_LVDSDataStruct *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002574
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302575 tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002576
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302577 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2578 LCDPtr = (struct XGI330_LVDSDataStruct *) XGI_GetLcdPtr(tempbx,
2579 ModeNo, ModeIdIndex, RefreshRateTableIndex,
2580 pVBInfo);
2581 pVBInfo->VGAHT = LCDPtr->VGAHT;
2582 pVBInfo->VGAVT = LCDPtr->VGAVT;
2583 pVBInfo->HT = LCDPtr->LCDHT;
2584 pVBInfo->VT = LCDPtr->LCDVT;
2585 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002586
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302587 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2588 if (!(pVBInfo->LCDInfo & (SetLCDtoNonExpanding
2589 | EnableScalingLCD))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002590 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2591 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302592 pVBInfo->HDE = 1024;
2593 pVBInfo->VDE = 768;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002594 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2595 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302596 pVBInfo->HDE = 1280;
2597 pVBInfo->VDE = 1024;
2598 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2599 pVBInfo->HDE = 1400;
2600 pVBInfo->VDE = 1050;
2601 } else {
2602 pVBInfo->HDE = 1600;
2603 pVBInfo->VDE = 1200;
2604 }
2605 }
2606 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002607}
2608
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002609static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302610 unsigned short RefreshRateTableIndex,
2611 struct xgi_hw_device_info *HwDeviceExtension,
2612 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002613{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302614 unsigned char index;
2615 unsigned short tempbx, i;
2616 struct XGI_LVDSCRT1HDataStruct *LCDPtr = NULL;
2617 struct XGI_LVDSCRT1VDataStruct *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002618
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302619 if (ModeNo <= 0x13)
2620 index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2621 else
2622 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002623
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302624 index = index & IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002625
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002626 if ((pVBInfo->IF_DEF_ScaleLCD == 0) ||
2627 ((pVBInfo->IF_DEF_ScaleLCD == 1) &&
2628 (!(pVBInfo->LCDInfo & EnableScalingLCD)))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302629 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002630
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302631 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002632 LCDPtr = (struct XGI_LVDSCRT1HDataStruct *)
2633 XGI_GetLcdPtr(tempbx, ModeNo,
2634 ModeIdIndex,
2635 RefreshRateTableIndex,
2636 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002637
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302638 for (i = 0; i < 8; i++)
2639 pVBInfo->TimingH[0].data[i] = LCDPtr[0].Reg[i];
2640 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002641
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302642 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002643
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302644 tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002645
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302646 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002647 LCDPtr1 = (struct XGI_LVDSCRT1VDataStruct *)
2648 XGI_GetLcdPtr(
2649 tempbx,
2650 ModeNo,
2651 ModeIdIndex,
2652 RefreshRateTableIndex,
2653 pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302654 for (i = 0; i < 7; i++)
2655 pVBInfo->TimingV[0].data[i] = LCDPtr1[0].Reg[i];
2656 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002657
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302658 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302659 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002660}
2661
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002662static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
2663{
2664 unsigned char tempal, tempah, tempbl, i;
2665
Aaro Koskinen58839b02011-03-13 12:26:23 +02002666 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002667 tempal = tempah & 0x0F;
2668 tempah = tempah & 0xF0;
2669 i = 0;
2670 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2671
2672 while (tempbl != 0xFF) {
2673 if (tempbl & 0x80) { /* OEMUtil */
2674 tempal = tempah;
2675 tempbl = tempbl & ~(0x80);
2676 }
2677
2678 if (tempal == tempbl)
2679 break;
2680
2681 i++;
2682
2683 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2684 }
2685
2686 return i;
2687}
2688
2689static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
2690{
2691 unsigned short tempah, tempal, tempbl, i;
2692
2693 tempal = pVBInfo->LCDResInfo;
2694 tempah = pVBInfo->LCDTypeInfo;
2695
2696 i = 0;
2697 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2698
2699 while (tempbl != 0xFF) {
2700 if ((tempbl & 0x80) && (tempbl != 0x80)) {
2701 tempal = tempah;
2702 tempbl &= ~0x80;
2703 }
2704
2705 if (tempal == tempbl)
2706 break;
2707
2708 i++;
2709 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2710 }
2711
2712 if (tempbl == 0xFF) {
2713 pVBInfo->LCDResInfo = Panel1024x768;
2714 pVBInfo->LCDTypeInfo = 0;
2715 i = 0;
2716 }
2717
2718 return i;
2719}
2720
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002721static void XGI_GetLCDSync(unsigned short *HSyncWidth,
2722 unsigned short *VSyncWidth,
2723 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002724{
2725 unsigned short Index;
2726
2727 Index = XGI_GetLCDCapPtr(pVBInfo);
2728 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
2729 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
2730
2731 return;
2732}
2733
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002734static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302735 unsigned short RefreshRateTableIndex,
2736 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002737{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302738 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
2739 unsigned long temp, temp1, temp2, temp3, push3;
2740 struct XGI330_LCDDataDesStruct *LCDPtr = NULL;
2741 struct XGI330_LCDDataDesStruct2 *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002742
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302743 if (ModeNo > 0x13)
2744 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2745 else
2746 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002747
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302748 if (!(pVBInfo->SetFlag & Win9xDOSMode)) {
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002749 if (pVBInfo->IF_DEF_OEMUtil == 1) {
2750 tempbx = 8;
2751 LCDPtr = (struct XGI330_LCDDataDesStruct *)
2752 XGI_GetLcdPtr(tempbx,
2753 ModeNo,
2754 ModeIdIndex,
2755 RefreshRateTableIndex,
2756 pVBInfo);
2757 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002758
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002759 if ((pVBInfo->IF_DEF_OEMUtil == 0) ||
2760 (LCDPtr == NULL)) {
2761 tempbx = 3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302762 if (pVBInfo->LCDInfo & EnableScalingLCD)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002763 LCDPtr1 =
2764 (struct XGI330_LCDDataDesStruct2 *)
2765 XGI_GetLcdPtr(
2766 tempbx,
2767 ModeNo,
2768 ModeIdIndex,
2769 RefreshRateTableIndex,
2770 pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302771 else
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002772 LCDPtr =
2773 (struct XGI330_LCDDataDesStruct *)
2774 XGI_GetLcdPtr(
2775 tempbx,
2776 ModeNo,
2777 ModeIdIndex,
2778 RefreshRateTableIndex,
2779 pVBInfo);
2780 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002781
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002782 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
2783 push1 = tempbx;
2784 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002785
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002786 /* GetLCDResInfo */
2787 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2788 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
2789 tempax = 1024;
2790 tempbx = 768;
2791 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2792 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
2793 tempax = 1280;
2794 tempbx = 1024;
2795 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2796 tempax = 1400;
2797 tempbx = 1050;
2798 } else {
2799 tempax = 1600;
2800 tempbx = 1200;
2801 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002802
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002803 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
2804 pVBInfo->HDE = tempax;
2805 pVBInfo->VDE = tempbx;
2806 pVBInfo->VGAHDE = tempax;
2807 pVBInfo->VGAVDE = tempbx;
2808 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002809
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002810 if ((pVBInfo->IF_DEF_ScaleLCD == 1) &&
2811 (pVBInfo->LCDInfo & EnableScalingLCD)) {
2812 tempax = pVBInfo->HDE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302813 tempbx = pVBInfo->VDE;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002814 }
2815
2816 tempax = pVBInfo->HT;
2817
2818 if (pVBInfo->LCDInfo & EnableScalingLCD)
2819 tempbx = LCDPtr1->LCDHDES;
2820 else
2821 tempbx = LCDPtr->LCDHDES;
2822
2823 tempcx = pVBInfo->HDE;
2824 tempbx = tempbx & 0x0fff;
2825 tempcx += tempbx;
2826
2827 if (tempcx >= tempax)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302828 tempcx -= tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002829
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002830 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002831
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002832 tempcx = tempcx >> 3;
2833 tempbx = tempbx >> 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002834
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002835 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
2836 (unsigned short) (tempbx & 0xff));
2837 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
2838 (unsigned short) (tempcx & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002839
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002840 tempax = pVBInfo->HT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002841
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002842 if (pVBInfo->LCDInfo & EnableScalingLCD)
2843 tempbx = LCDPtr1->LCDHRS;
2844 else
2845 tempbx = LCDPtr->LCDHRS;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002846
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002847 tempcx = push2;
2848
2849 if (pVBInfo->LCDInfo & EnableScalingLCD)
2850 tempcx = LCDPtr1->LCDHSync;
2851
2852 tempcx += tempbx;
2853
2854 if (tempcx >= tempax)
2855 tempcx -= tempax;
2856
2857 tempax = tempbx & 0x07;
2858 tempax = tempax >> 5;
2859 tempcx = tempcx >> 3;
2860 tempbx = tempbx >> 3;
2861
2862 tempcx &= 0x1f;
2863 tempax |= tempcx;
2864
2865 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
2866 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
2867 (unsigned short) (tempbx & 0xff));
2868
2869 tempax = pVBInfo->VT;
2870 if (pVBInfo->LCDInfo & EnableScalingLCD)
2871 tempbx = LCDPtr1->LCDVDES;
2872 else
2873 tempbx = LCDPtr->LCDVDES;
2874 tempcx = pVBInfo->VDE;
2875
2876 tempbx = tempbx & 0x0fff;
2877 tempcx += tempbx;
2878 if (tempcx >= tempax)
2879 tempcx -= tempax;
2880
2881 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
2882 (unsigned short) (tempbx & 0xff));
2883 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
2884 (unsigned short) (tempcx & 0xff));
2885
2886 tempbx = (tempbx >> 8) & 0x07;
2887 tempcx = (tempcx >> 8) & 0x07;
2888
2889 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
2890 (unsigned short) ((tempcx << 3)
2891 | tempbx));
2892
2893 tempax = pVBInfo->VT;
2894 if (pVBInfo->LCDInfo & EnableScalingLCD)
2895 tempbx = LCDPtr1->LCDVRS;
2896 else
2897 tempbx = LCDPtr->LCDVRS;
2898
2899 /* tempbx = tempbx >> 4; */
2900 tempcx = push1;
2901
2902 if (pVBInfo->LCDInfo & EnableScalingLCD)
2903 tempcx = LCDPtr1->LCDVSync;
2904
2905 tempcx += tempbx;
2906 if (tempcx >= tempax)
2907 tempcx -= tempax;
2908
2909 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
2910 (unsigned short) (tempbx & 0xff));
2911 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
2912 (unsigned short) (tempcx & 0x0f));
2913
2914 tempax = ((tempbx >> 8) & 0x07) << 3;
2915
2916 tempbx = pVBInfo->VGAVDE;
2917 if (tempbx != pVBInfo->VDE)
2918 tempax |= 0x40;
2919
2920 if (pVBInfo->LCDInfo & EnableLVDSDDA)
2921 tempax |= 0x40;
2922
2923 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
2924 tempax);
2925
2926 tempcx = pVBInfo->VGAVT;
2927 tempbx = pVBInfo->VDE;
2928 tempax = pVBInfo->VGAVDE;
2929 tempcx -= tempax;
2930
2931 temp = tempax; /* 0430 ylshieh */
2932 temp1 = (temp << 18) / tempbx;
2933
2934 tempdx = (unsigned short) ((temp << 18) % tempbx);
2935
2936 if (tempdx != 0)
2937 temp1 += 1;
2938
2939 temp2 = temp1;
2940 push3 = temp2;
2941
2942 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
2943 (unsigned short) (temp2 & 0xff));
2944 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
2945 (unsigned short) ((temp2 >> 8) & 0xff));
2946
2947 tempbx = (unsigned short) (temp2 >> 16);
2948 tempax = tempbx & 0x03;
2949
2950 tempbx = pVBInfo->VGAVDE;
2951 if (tempbx == pVBInfo->VDE)
2952 tempax |= 0x04;
2953
2954 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
2955
2956 if (pVBInfo->VBType & VB_XGI301C) {
2957 temp2 = push3;
2958 xgifb_reg_set(pVBInfo->Part4Port,
2959 0x3c,
2960 (unsigned short) (temp2 & 0xff));
2961 xgifb_reg_set(pVBInfo->Part4Port,
2962 0x3b,
2963 (unsigned short) ((temp2 >> 8) &
2964 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302965 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002966 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
2967 ~0xc0,
2968 (unsigned short) ((tempbx &
2969 0xff) << 6));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002970
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002971 tempcx = pVBInfo->VGAVDE;
2972 if (tempcx == pVBInfo->VDE)
2973 xgifb_reg_and_or(pVBInfo->Part4Port,
2974 0x30, ~0x0c, 0x00);
2975 else
2976 xgifb_reg_and_or(pVBInfo->Part4Port,
2977 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302978 }
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002979
2980 tempcx = pVBInfo->VGAHDE;
2981 tempbx = pVBInfo->HDE;
2982
2983 temp1 = tempcx << 16;
2984
2985 tempax = (unsigned short) (temp1 / tempbx);
2986
2987 if ((tempbx & 0xffff) == (tempcx & 0xffff))
2988 tempax = 65535;
2989
2990 temp3 = tempax;
2991 temp1 = pVBInfo->VGAHDE << 16;
2992
2993 temp1 /= temp3;
2994 temp3 = temp3 << 16;
2995 temp1 -= 1;
2996
2997 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
2998
2999 tempax = (unsigned short) (temp3 & 0xff);
3000 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
3001
3002 temp1 = pVBInfo->VGAVDE << 18;
3003 temp1 = temp1 / push3;
3004 tempbx = (unsigned short) (temp1 & 0xffff);
3005
3006 if (pVBInfo->LCDResInfo == Panel1024x768)
3007 tempbx -= 1;
3008
3009 tempax = ((tempbx >> 8) & 0xff) << 3;
3010 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
3011 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
3012 (unsigned short) (tempax & 0xff));
3013 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
3014 (unsigned short) (tempbx & 0xff));
3015
3016 temp3 = temp3 >> 16;
3017
3018 if (modeflag & HalfDCLK)
3019 temp3 = temp3 >> 1;
3020
3021 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
3022 (unsigned short) ((temp3 >> 8) & 0xff));
3023 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
3024 (unsigned short) (temp3 & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303025 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003026}
3027
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003028/* --------------------------------------------------------------------- */
3029/* Function : XGI_GETLCDVCLKPtr */
3030/* Input : */
3031/* Output : al -> VCLK Index */
3032/* Description : */
3033/* --------------------------------------------------------------------- */
3034static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
3035 struct vb_device_info *pVBInfo)
3036{
3037 unsigned short index;
3038
3039 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
3040 if (pVBInfo->IF_DEF_ScaleLCD == 1) {
3041 if (pVBInfo->LCDInfo & EnableScalingLCD)
3042 return;
3043 }
3044
3045 /* index = XGI_GetLCDCapPtr(pVBInfo); */
3046 index = XGI_GetLCDCapPtr1(pVBInfo);
3047
3048 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
3049 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
3050 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
3051 } else { /* LCDA */
3052 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
3053 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
3054 }
3055 }
3056 return;
3057}
3058
3059static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
3060 unsigned short ModeNo, unsigned short ModeIdIndex,
3061 struct vb_device_info *pVBInfo)
3062{
3063
3064 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003065 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003066
3067 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003068 /* si+St_ResInfo */
3069 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003070 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003071 /* si+Ext_ResInfo */
3072 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003073
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003074 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
3075 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003076 index = XGI_GetLCDCapPtr(pVBInfo);
3077 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
3078
3079 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
3080 return tempal;
3081
3082 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003083 if (pVBInfo->VBType &
3084 (VB_XGI301B |
3085 VB_XGI302B |
3086 VB_XGI301LV |
3087 VB_XGI302LV |
3088 VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003089 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3090 tempal = HiTVVCLKDIV2;
3091 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
3092 tempal = HiTVVCLK;
3093 if (pVBInfo->TVInfo & TVSimuMode) {
3094 tempal = HiTVSimuVCLK;
3095 if (!(modeflag & Charx8Dot))
3096 tempal = HiTVTextVCLK;
3097
3098 }
3099 return tempal;
3100 }
3101
3102 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
3103 tempal = YPbPr750pVCLK;
3104 return tempal;
3105 }
3106
3107 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
3108 tempal = YPbPr525pVCLK;
3109 return tempal;
3110 }
3111
3112 tempal = NTSC1024VCLK;
3113
3114 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
3115 tempal = TVVCLKDIV2;
3116 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
3117 tempal = TVVCLK;
3118 }
3119
3120 if (pVBInfo->VBInfo & SetCRT2ToTV)
3121 return tempal;
3122 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003123 } /* {End of VB} */
3124
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003125 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003126 tempal = tempal >> 2;
3127 tempal &= 0x03;
3128
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003129 /* for Dot8 Scaling LCD */
3130 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003131 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
3132
3133 if (ModeNo <= 0x13)
3134 return tempal;
3135
3136 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
3137 return tempal;
3138}
3139
3140static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
3141 unsigned char *di_1, struct vb_device_info *pVBInfo)
3142{
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003143 if (pVBInfo->VBType & (VB_XGI301 | VB_XGI301B | VB_XGI302B
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003144 | VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
3145 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) && (pVBInfo->SetFlag
3146 & ProgrammingCRT2)) {
3147 *di_0 = (unsigned char) XGI_VBVCLKData[tempal].SR2B;
3148 *di_1 = XGI_VBVCLKData[tempal].SR2C;
3149 }
3150 } else {
3151 *di_0 = XGI_VCLKData[tempal].SR2B;
3152 *di_1 = XGI_VCLKData[tempal].SR2C;
3153 }
3154}
3155
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003156static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303157 unsigned short RefreshRateTableIndex,
3158 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003159{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303160 unsigned char di_0, di_1, tempal;
3161 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003162
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303163 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
3164 pVBInfo);
3165 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
3166 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003167
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303168 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003169 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303170 (unsigned short) (0x10 * i));
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003171 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303172 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003173 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
3174 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303175 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003176 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
3177 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303178 }
3179 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003180}
3181
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003182static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303183 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003184{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303185 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003186
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303187 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
3188 | VB_XGI302LV | VB_XGI301C)) {
3189 tempcl = 0;
3190 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003191 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003192
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303193 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003194 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303195 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003196 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303197 if (!(temp & 0x40))
3198 tempcl |= ActiveCRT1;
3199 }
3200 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003201
Aaro Koskinen58839b02011-03-13 12:26:23 +02003202 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303203 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003204
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303205 if (!(temp == 0x08)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003206 /* Check ChannelA by Part1_13 [2003/10/03] */
3207 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303208 if (tempax & 0x04)
3209 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003210
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303211 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003212
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303213 if (!(tempcl & ActiveLCD))
3214 if (temp == 0x01)
3215 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003216
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303217 if (temp == 0x04)
3218 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003219
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303220 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003221 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003222
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303223 if (!(temp & 0x08))
3224 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003225
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303226 if (!(temp & 0x04))
3227 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003228
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303229 if (temp & 0x02)
3230 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003231
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303232 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3233 if (temp & 0x01)
3234 tempch |= ActiveHiTV;
3235 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003236
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303237 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003238 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303239 pVBInfo->Part2Port,
3240 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003241
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303242 if (temp & 0x10)
3243 tempch |= ActiveYPbPr;
3244 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003245
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303246 if (tempch != 0)
3247 tempcl |= ActiveTV;
3248 }
3249 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003250
Aaro Koskinen58839b02011-03-13 12:26:23 +02003251 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303252 if (tempcl & ActiveLCD) {
3253 if ((pVBInfo->SetFlag & ReserveTVOption)) {
3254 if (temp & ActiveTV)
3255 tempcl |= ActiveTV;
3256 }
3257 }
3258 temp = tempcl;
3259 tempbl = ~ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003260 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003261
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303262 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003263 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303264 } else {
3265 return;
3266 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003267}
3268
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303269void XGI_GetVGAType(struct xgi_hw_device_info *HwDeviceExtension,
3270 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003271{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303272 /*
3273 if ( HwDeviceExtension->jChipType >= XG20 ) {
3274 pVBInfo->Set_VGAType = XG20;
Aaro Koskinen06587332011-03-13 12:26:10 +02003275 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303276 pVBInfo->Set_VGAType = VGA_XGI340;
3277 }
3278 */
3279 pVBInfo->Set_VGAType = HwDeviceExtension->jChipType;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003280}
3281
Bill Pemberton80adad82010-06-17 13:10:51 -04003282void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003283{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303284 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003285
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303286 if (pVBInfo->IF_DEF_LVDS == 0) {
3287 tempbx = VB_XGI302B;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003288 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303289 if (flag != 0x02) {
3290 tempbx = VB_XGI301;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003291 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303292 if (flag >= 0xB0) {
3293 tempbx = VB_XGI301B;
3294 if (flag >= 0xC0) {
3295 tempbx = VB_XGI301C;
3296 if (flag >= 0xD0) {
3297 tempbx = VB_XGI301LV;
3298 if (flag >= 0xE0) {
3299 tempbx = VB_XGI302LV;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003300 tempah = xgifb_reg_get(
3301 pVBInfo->Part4Port,
3302 0x39);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303303 if (tempah != 0xFF)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003304 tempbx =
3305 VB_XGI301C;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303306 }
3307 }
3308 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003309
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303310 if (tempbx & (VB_XGI301B | VB_XGI302B)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003311 flag = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303312 pVBInfo->Part4Port,
3313 0x23);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003314
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303315 if (!(flag & 0x02))
3316 tempbx = tempbx | VB_NoLCD;
3317 }
3318 }
3319 }
3320 pVBInfo->VBType = tempbx;
3321 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003322}
3323
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303324void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3325 struct xgi_hw_device_info *HwDeviceExtension,
3326 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003327{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303328 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003329
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303330 if (ModeNo <= 0x13)
3331 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3332 else
3333 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003334
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303335 pVBInfo->SetFlag = 0;
3336 pVBInfo->ModeType = modeflag & ModeInfoFlag;
3337 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003338
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303339 if (pVBInfo->VBType & 0xFFFF) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003340 /* Check Display Device */
3341 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303342 tempbx = tempbx | temp;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003343 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303344 push = temp;
3345 push = push << 8;
3346 tempax = temp << 8;
3347 tempbx = tempbx | tempax;
3348 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr | SetCRT2ToLCDA
3349 | SetInSlaveMode | DisableCRT2Display);
3350 temp = 0xFFFF ^ temp;
3351 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003352
Aaro Koskinen58839b02011-03-13 12:26:23 +02003353 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003354
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303355 if (pVBInfo->IF_DEF_LCDA == 1) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003356
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303357 if ((pVBInfo->Set_VGAType >= XG20)
3358 || (pVBInfo->Set_VGAType >= XG40)) {
3359 if (pVBInfo->IF_DEF_LVDS == 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003360 /* if ((pVBInfo->VBType & VB_XGI302B)
3361 || (pVBInfo->VBType & VB_XGI301LV)
3362 || (pVBInfo->VBType & VB_XGI302LV)
3363 || (pVBInfo->VBType & VB_XGI301C))
3364 */
3365 if (pVBInfo->VBType &
3366 (VB_XGI302B |
3367 VB_XGI301LV |
3368 VB_XGI302LV |
3369 VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303370 if (temp & EnableDualEdge) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003371 tempbx |=
3372 SetCRT2ToDualEdge;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003373
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303374 if (temp & SetToLCDA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003375 tempbx |=
3376 SetCRT2ToLCDA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303377 }
3378 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303379 }
3380 }
3381 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003382
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303383 if (pVBInfo->IF_DEF_YPbPr == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003384 /* [Billy] 07/05/04 */
3385 if (((pVBInfo->IF_DEF_LVDS == 0) &&
3386 ((pVBInfo->VBType & VB_XGI301LV) ||
3387 (pVBInfo->VBType & VB_XGI302LV) ||
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003388 (pVBInfo->VBType & VB_XGI301C)))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303389 if (temp & SetYPbPr) { /* temp = CR38 */
3390 if (pVBInfo->IF_DEF_HiVision == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003391 /* shampoo add for new
3392 * scratch */
Aaro Koskinen58839b02011-03-13 12:26:23 +02003393 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303394 pVBInfo->P3d4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003395 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303396 temp &= YPbPrMode;
3397 tempbx |= SetCRT2ToHiVisionTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003398
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303399 if (temp != YPbPrMode1080i) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003400 tempbx &=
3401 (~SetCRT2ToHiVisionTV);
3402 tempbx |=
3403 SetCRT2ToYPbPr;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303404 }
3405 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003406
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303407 /* tempbx |= SetCRT2ToYPbPr; */
3408 }
3409 }
3410 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003411
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303412 tempax = push; /* restore CR31 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003413
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303414 if (pVBInfo->IF_DEF_LVDS == 0) {
3415 if (pVBInfo->IF_DEF_YPbPr == 1) {
3416 if (pVBInfo->IF_DEF_HiVision == 1)
3417 temp = 0x09FC;
3418 else
3419 temp = 0x097C;
3420 } else {
3421 if (pVBInfo->IF_DEF_HiVision == 1)
3422 temp = 0x01FC;
3423 else
3424 temp = 0x017C;
3425 }
3426 } else { /* 3nd party chip */
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003427 temp = SetCRT2ToLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303428 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003429
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303430 if (!(tempbx & temp)) {
3431 tempax |= DisableCRT2Display;
3432 tempbx = 0;
3433 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003434
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303435 if (pVBInfo->IF_DEF_LCDA == 1) { /* Select Display Device */
3436 if (!(pVBInfo->VBType & VB_NoLCD)) {
3437 if (tempbx & SetCRT2ToLCDA) {
3438 if (tempbx & SetSimuScanMode)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003439 tempbx &= (~(SetCRT2ToLCD |
3440 SetCRT2ToRAMDAC |
3441 SwitchToCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303442 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003443 tempbx &= (~(SetCRT2ToLCD |
3444 SetCRT2ToRAMDAC |
3445 SetCRT2ToTV |
3446 SwitchToCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303447 }
3448 }
3449 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003450
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303451 /* shampoo add */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003452 /* for driver abnormal */
3453 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303454 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
3455 if (tempbx & SetCRT2ToRAMDAC) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003456 tempbx &= (0xFF00 |
3457 SetCRT2ToRAMDAC |
3458 SwitchToCRT2 |
3459 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303460 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3461 }
3462 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003463 tempbx &= (~(SetCRT2ToRAMDAC |
3464 SetCRT2ToLCD |
3465 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303466 }
3467 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003468
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303469 if (!(pVBInfo->VBType & VB_NoLCD)) {
3470 if (tempbx & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003471 tempbx &= (0xFF00 |
3472 SetCRT2ToLCD |
3473 SwitchToCRT2 |
3474 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303475 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3476 }
3477 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003478
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303479 if (tempbx & SetCRT2ToSCART) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003480 tempbx &= (0xFF00 |
3481 SetCRT2ToSCART |
3482 SwitchToCRT2 |
3483 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303484 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3485 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003486
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303487 if (pVBInfo->IF_DEF_YPbPr == 1) {
3488 if (tempbx & SetCRT2ToYPbPr)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003489 tempbx &= (0xFF00 |
3490 SwitchToCRT2 |
3491 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303492 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003493
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303494 if (pVBInfo->IF_DEF_HiVision == 1) {
3495 if (tempbx & SetCRT2ToHiVisionTV)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003496 tempbx &= (0xFF00 |
3497 SetCRT2ToHiVisionTV |
3498 SwitchToCRT2 |
3499 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303500 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003501
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303502 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
3503 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode)))
3504 tempbx = DisableCRT2Display;
3505 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003506
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303507 if (!(tempbx & DisableCRT2Display)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003508 if ((!(tempbx & DriverMode)) ||
3509 (!(modeflag & CRT2Mode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303510 if (pVBInfo->IF_DEF_LCDA == 1) {
3511 if (!(tempbx & SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003512 tempbx |= (SetInSlaveMode |
3513 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303514 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003515
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303516 if (pVBInfo->IF_DEF_VideoCapture == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003517 if (((HwDeviceExtension->jChipType ==
3518 XG40) &&
3519 (pVBInfo->Set_VGAType == XG40)) ||
3520 ((HwDeviceExtension->jChipType ==
3521 XG41) &&
3522 (pVBInfo->Set_VGAType == XG41)) ||
3523 ((HwDeviceExtension->jChipType ==
3524 XG42) &&
3525 (pVBInfo->Set_VGAType == XG42)) ||
3526 ((HwDeviceExtension->jChipType ==
3527 XG45) &&
3528 (pVBInfo->Set_VGAType == XG45))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303529 if (ModeNo <= 13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003530 if (!(tempbx &
3531 SetCRT2ToRAMDAC)) {
3532 /*CRT2 not need
3533 * to support*/
3534 tempbx &=
3535 (0x00FF |
3536 (~SetInSlaveMode));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303537 pVBInfo->SetFlag
3538 |= EnableVCMode;
3539 }
3540 }
3541 }
3542 }
3543 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003544
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003545 /* LCD+TV can't support in slave mode
3546 * (Force LCDA+TV->LCDB) */
3547 if ((tempbx & SetInSlaveMode) &&
3548 (tempbx & SetCRT2ToLCDA)) {
3549 tempbx ^= (SetCRT2ToLCD |
3550 SetCRT2ToLCDA |
3551 SetCRT2ToDualEdge);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303552 pVBInfo->SetFlag |= ReserveTVOption;
3553 }
3554 }
3555 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003556
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303557 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003558}
3559
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303560void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3561 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003562{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303563 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003564
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303565 tempbx = 0;
3566 resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003567
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303568 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3569 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003570 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].
3571 St_ModeFlag; /* si+St_ModeFlag */
3572 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].
3573 St_ResInfo; /* si+St_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303574 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003575 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].
3576 Ext_ModeFlag;
3577 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].
3578 Ext_RESINFO; /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303579 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003580
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303581 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003582 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303583 tempbx = temp;
3584 if (tempbx & SetPALTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003585 tempbx &= (SetCHTVOverScan |
3586 SetPALMTV |
3587 SetPALNTV |
3588 SetPALTV);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303589 if (tempbx & SetPALMTV)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003590 /* set to NTSC if PAL-M */
3591 tempbx &= ~SetPALTV;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303592 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003593 tempbx &= (SetCHTVOverScan |
3594 SetNTSCJ |
3595 SetPALTV);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303596 /*
3597 if (pVBInfo->IF_DEF_LVDS == 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003598 //PAL-M/PAL-N Info
3599 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x38);
3600 //00:PAL, 01:PAL-M, 10:PAL-N
3601 temp2 = (index1 & 0xC0) >> 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303602 tempbx |= temp2;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003603 if (temp2 & 0x02) //PAL-M
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303604 tempbx &= (~SetPALTV);
3605 }
3606 */
3607 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003608
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303609 if (pVBInfo->IF_DEF_LVDS == 0) {
3610 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3611 tempbx |= SetPALTV;
3612 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003613
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303614 if (pVBInfo->IF_DEF_YPbPr == 1) {
3615 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003616 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303617 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003618
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303619 if (index1 == YPbPrMode525i)
3620 tempbx |= SetYPbPrMode525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003621
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303622 if (index1 == YPbPrMode525p)
3623 tempbx = tempbx | SetYPbPrMode525p;
3624 if (index1 == YPbPrMode750p)
3625 tempbx = tempbx | SetYPbPrMode750p;
3626 }
3627 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003628
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303629 if (pVBInfo->IF_DEF_HiVision == 1) {
3630 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
3631 tempbx = tempbx | SetYPbPrMode1080i | SetPALTV;
3632 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003633
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303634 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003635 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
3636 (!(pVBInfo->VBInfo & SetNotSimuMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303637 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003638
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003639 if (!(tempbx & SetPALTV) &&
3640 (modeflag > 13) &&
3641 (resinfo == 8)) /* NTSC 1024x768, */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303642 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003643
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303644 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003645
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303646 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3647 if (pVBInfo->VBInfo & SetInSlaveMode)
3648 tempbx &= (~RPLLDIV2XO);
3649 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003650 if (tempbx &
3651 (SetYPbPrMode525p | SetYPbPrMode750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303652 tempbx &= (~RPLLDIV2XO);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003653 else if (!(pVBInfo->VBType &
3654 (VB_XGI301B |
3655 VB_XGI302B |
3656 VB_XGI301LV |
3657 VB_XGI302LV |
3658 VB_XGI301C))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303659 if (tempbx & TVSimuMode)
3660 tempbx &= (~RPLLDIV2XO);
3661 }
3662 }
3663 }
3664 }
3665 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003666}
3667
Bill Pemberton108afbf2010-06-17 13:10:47 -04003668unsigned char XGI_GetLCDInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303669 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003670{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303671 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003672
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303673 pVBInfo->LCDResInfo = 0;
3674 pVBInfo->LCDTypeInfo = 0;
3675 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003676
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303677 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003678 /* si+St_ModeFlag // */
3679 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303680 } else {
3681 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003682 /* si+Ext_ResInfo // */
3683 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303684 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003685
Aaro Koskinen58839b02011-03-13 12:26:23 +02003686 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303687 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003688
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303689 if (tempbx == 0)
3690 tempbx = Panel1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003691
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303692 /* LCD75 [2003/8/22] Vicent */
3693 if ((tempbx == Panel1024x768) || (tempbx == Panel1280x1024)) {
3694 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003695 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303696 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
3697 tempax &= 0x0F;
3698 else
3699 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003700
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303701 if ((resinfo == 6) || (resinfo == 9)) {
3702 if (tempax >= 3)
3703 tempbx |= PanelRef75Hz;
3704 } else if ((resinfo == 7) || (resinfo == 8)) {
3705 if (tempax >= 4)
3706 tempbx |= PanelRef75Hz;
3707 }
3708 }
3709 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003710
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303711 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003712
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303713 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003714
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303715 if (pVBInfo->IF_DEF_OEMUtil == 1)
3716 pVBInfo->LCDTypeInfo = (temp & 0xf0) >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003717
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303718 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
3719 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003720
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303721 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003722
Aaro Koskinen58839b02011-03-13 12:26:23 +02003723 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003724
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303725 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003726
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303727 if ((pVBInfo->IF_DEF_ScaleLCD == 1) && (temp & LCDNonExpanding))
3728 temp &= ~EnableScalingLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003729
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303730 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003731
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303732 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003733
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303734 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003735
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303736 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
3737 if (((pVBInfo->VBType & VB_XGI302LV) || (pVBInfo->VBType
3738 & VB_XGI301C)) && (tempax & LCDDualLink)) {
3739 tempbx |= SetLCDDualLink;
3740 }
3741 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003742
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303743 if (pVBInfo->IF_DEF_LVDS == 0) {
3744 if ((pVBInfo->LCDResInfo == Panel1400x1050) && (pVBInfo->VBInfo
3745 & SetCRT2ToLCD) && (ModeNo > 0x13) && (resinfo
3746 == 9) && (!(tempbx & EnableScalingLCD)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003747 /* set to center in 1280x1024 LCDB for Panel1400x1050 */
3748 tempbx |= SetLCDtoNonExpanding;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303749 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003750
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303751 /*
3752 if (tempax & LCDBToA) {
3753 tempbx |= SetLCDBToA;
3754 }
3755 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003756
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303757 if (pVBInfo->IF_DEF_ExpLink == 1) {
3758 if (modeflag & HalfDCLK) {
3759 /* if (!(pVBInfo->LCDInfo&LCDNonExpanding)) */
3760 if (!(tempbx & SetLCDtoNonExpanding)) {
3761 tempbx |= EnableLVDSDDA;
3762 } else {
3763 if (ModeNo > 0x13) {
3764 if (pVBInfo->LCDResInfo
3765 == Panel1024x768) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003766 if (resinfo == 4) {/* 512x384 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303767 tempbx |= EnableLVDSDDA;
3768 }
3769 }
3770 }
3771 }
3772 }
3773 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003774
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303775 if (pVBInfo->VBInfo & SetInSlaveMode) {
3776 if (pVBInfo->VBInfo & SetNotSimuMode)
3777 tempbx |= LCDVESATiming;
3778 } else {
3779 tempbx |= LCDVESATiming;
3780 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003781
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303782 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003783
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303784 if (pVBInfo->IF_DEF_PWD == 1) {
3785 if (pVBInfo->LCDInfo & SetPWDEnable) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003786 if ((pVBInfo->VBType & VB_XGI302LV) ||
3787 (pVBInfo->VBType & VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303788 if (!(tempax & PWDEnable))
3789 pVBInfo->LCDInfo &= ~SetPWDEnable;
3790 }
3791 }
3792 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003793
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303794 if (pVBInfo->IF_DEF_LVDS == 0) {
3795 if (tempax & (LockLCDBToA | StLCDBToA)) {
3796 if (pVBInfo->VBInfo & SetInSlaveMode) {
3797 if (!(tempax & LockLCDBToA)) {
3798 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003799 pVBInfo->VBInfo &=
3800 ~(SetSimuScanMode |
3801 SetInSlaveMode |
3802 SetCRT2ToLCD);
3803 pVBInfo->VBInfo |=
3804 SetCRT2ToLCDA |
3805 SetCRT2ToDualEdge;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303806 }
3807 }
3808 }
3809 }
3810 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003811
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303812 /*
3813 if (pVBInfo->IF_DEF_LVDS == 0) {
3814 if (tempax & (LockLCDBToA | StLCDBToA)) {
3815 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003816 if (!((!(tempax & LockLCDBToA)) &&
3817 (ModeNo > 0x13))) {
3818 pVBInfo->VBInfo &=
3819 ~(SetSimuScanMode |
3820 SetInSlaveMode |
3821 SetCRT2ToLCD);
3822 pVBInfo->VBInfo |=
3823 SetCRT2ToLCDA |
3824 SetCRT2ToDualEdge;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303825 }
3826 }
3827 }
3828 }
3829 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003830
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303831 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003832}
3833
Bill Pemberton108afbf2010-06-17 13:10:47 -04003834unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303835 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003836{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303837 if (ModeNo <= 5)
3838 ModeNo |= 1;
3839 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003840 /* for (*ModeIdIndex=0;
3841 *ModeIdIndex < sizeof(pVBInfo->SModeIDTable)
3842 / sizeof(struct XGI_StStruct);
3843 (*ModeIdIndex)++) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303844 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003845 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3846 ModeNo)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303847 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003848 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3849 0xFF)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303850 return 0;
3851 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003852
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303853 if (ModeNo == 0x07)
3854 (*ModeIdIndex)++; /* 400 lines */
3855 if (ModeNo <= 3)
3856 (*ModeIdIndex) += 2; /* 400 lines */
3857 /* else 350 lines */
3858 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003859 /* for (*ModeIdIndex=0;
3860 *ModeIdIndex < sizeof(pVBInfo->EModeIDTable)
3861 / sizeof(struct XGI_ExtStruct);
3862 (*ModeIdIndex)++) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303863 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003864 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3865 ModeNo)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303866 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003867 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3868 0xFF)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303869 return 0;
3870 }
3871 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003872
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303873 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003874}
3875
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003876/* win2000 MM adapter not support standard mode! */
3877
Randy Dunlap89229672010-08-10 08:46:44 -07003878#if 0
Randy Dunlap89229672010-08-10 08:46:44 -07003879static unsigned char XGINew_CheckMemorySize(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303880 struct xgi_hw_device_info *HwDeviceExtension,
3881 unsigned short ModeNo,
3882 unsigned short ModeIdIndex,
3883 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003884{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303885 unsigned short memorysize, modeflag, temp, temp1, tmp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003886
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303887 /*
3888 if ((HwDeviceExtension->jChipType == XGI_650) ||
3889 (HwDeviceExtension->jChipType == XGI_650M)) {
3890 return 1;
3891 }
3892 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003893
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303894 if (ModeNo <= 0x13)
3895 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3896 else
3897 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003898
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303899 /* ModeType = modeflag&ModeInfoFlag; // Get mode type */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003900
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303901 memorysize = modeflag & MemoryInfoFlag;
3902 memorysize = memorysize > MemorySizeShift;
3903 memorysize++; /* Get memory size */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003904
Aaro Koskinen58839b02011-03-13 12:26:23 +02003905 temp = xgifb_reg_get(pVBInfo->P3c4, 0x14); /* Get DRAM Size */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303906 tmp = temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003907
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303908 if (HwDeviceExtension->jChipType == XG40) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003909 /* memory size per channel SR14[7:4] */
3910 temp = 1 << ((temp & 0x0F0) >> 4);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303911 if ((tmp & 0x0c) == 0x0C) { /* Qual channels */
3912 temp <<= 2;
3913 } else if ((tmp & 0x0c) == 0x08) { /* Dual channels */
3914 temp <<= 1;
3915 }
3916 } else if (HwDeviceExtension->jChipType == XG42) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003917 /* memory size per channel SR14[7:4] */
3918 temp = 1 << ((temp & 0x0F0) >> 4);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303919 if ((tmp & 0x04) == 0x04) { /* Dual channels */
3920 temp <<= 1;
3921 }
3922 } else if (HwDeviceExtension->jChipType == XG45) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003923 /* memory size per channel SR14[7:4] */
3924 temp = 1 << ((temp & 0x0F0) >> 4);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303925 if ((tmp & 0x0c) == 0x0C) { /* Qual channels */
3926 temp <<= 2;
3927 } else if ((tmp & 0x0c) == 0x08) { /* triple channels */
3928 temp1 = temp;
3929 temp <<= 1;
3930 temp += temp1;
3931 } else if ((tmp & 0x0c) == 0x04) { /* Dual channels */
3932 temp <<= 1;
3933 }
3934 }
3935 if (temp < memorysize)
3936 return 0;
3937 else
3938 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003939}
Randy Dunlap89229672010-08-10 08:46:44 -07003940#endif
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003941
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303942/*
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003943void XGINew_IsLowResolution(unsigned short ModeNo,
3944 unsigned short ModeIdIndex,
3945 unsigned char XGINew_CheckMemorySize(
3946 struct xgi_hw_device_info *HwDeviceExtension,
3947 unsigned short ModeNo,
3948 unsigned short ModeIdIndex,
3949 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003950{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303951 unsigned short data ;
3952 unsigned short ModeFlag ;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003953
Aaro Koskinen58839b02011-03-13 12:26:23 +02003954 data = xgifb_reg_get(pVBInfo->P3c4, 0x0F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303955 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003956 xgifb_reg_set(pVBInfo->P3c4, 0x0F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003957
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303958 if (ModeNo > 0x13) {
3959 ModeFlag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3960 if ((ModeFlag & HalfDCLK) && (ModeFlag & DoubleScanMode)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003961 data = xgifb_reg_get(pVBInfo->P3c4, 0x0F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303962 data |= 0x80;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003963 xgifb_reg_set(pVBInfo->P3c4, 0x0F, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003964 data = xgifb_reg_get(pVBInfo->P3c4, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303965 data &= 0xF7;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003966 xgifb_reg_set(pVBInfo->P3c4, 0x01, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303967 }
3968 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003969}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003970*/
3971
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003972static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
3973{
3974 unsigned char ujRet = 0;
3975 unsigned char i = 0;
3976
3977 for (i = 0; i < 8; i++) {
3978 ujRet = ujRet << 1;
3979 /* ujRet |= GETBITS(ujDate >> i, 0:0); */
3980 ujRet |= (ujDate >> i) & 1;
3981 }
3982
3983 return ujRet;
3984}
3985
3986/*----------------------------------------------------------------------------*/
3987/* output */
3988/* bl[5] : LVDS signal */
3989/* bl[1] : LVDS backlight */
3990/* bl[0] : LVDS VDD */
3991/*----------------------------------------------------------------------------*/
3992static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
3993{
3994 unsigned char CR4A, temp;
3995
Aaro Koskinen58839b02011-03-13 12:26:23 +02003996 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02003997 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003998
Aaro Koskinen58839b02011-03-13 12:26:23 +02003999 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004000
4001 temp = XG21GPIODataTransfer(temp);
4002 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004003 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004004 return temp;
4005}
4006
4007/*----------------------------------------------------------------------------*/
4008/* output */
4009/* bl[5] : LVDS signal */
4010/* bl[1] : LVDS backlight */
4011/* bl[0] : LVDS VDD */
4012/*----------------------------------------------------------------------------*/
4013static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
4014{
4015 unsigned char CR4A, CRB4, temp;
4016
Aaro Koskinen58839b02011-03-13 12:26:23 +02004017 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02004018 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004019
Aaro Koskinen58839b02011-03-13 12:26:23 +02004020 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004021
4022 temp &= 0x0C;
4023 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004024 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02004025 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004026 temp |= ((CRB4 & 0x04) << 3);
4027 return temp;
4028}
4029
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304030void XGI_DisplayOn(struct xgi_hw_device_info *pXGIHWDE,
4031 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004032{
4033
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004034 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304035 if (pXGIHWDE->jChipType == XG21) {
4036 if (pVBInfo->IF_DEF_LVDS == 1) {
4037 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004038 /* LVDS VDD on */
4039 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304040 XGI_XG21SetPanelDelay(2, pVBInfo);
4041 }
4042 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004043 /* LVDS signal on */
4044 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304045 XGI_XG21SetPanelDelay(3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004046 /* LVDS backlight on */
4047 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304048 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004049 /* DVO/DVI signal on */
4050 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304051 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004052
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304053 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004054
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304055 if (pXGIHWDE->jChipType == XG27) {
4056 if (pVBInfo->IF_DEF_LVDS == 1) {
4057 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004058 /* LVDS VDD on */
4059 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304060 XGI_XG21SetPanelDelay(2, pVBInfo);
4061 }
4062 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004063 /* LVDS signal on */
4064 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304065 XGI_XG21SetPanelDelay(3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004066 /* LVDS backlight on */
4067 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304068 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004069 /* DVO/DVI signal on */
4070 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304071 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004072
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304073 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004074}
4075
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304076void XGI_DisplayOff(struct xgi_hw_device_info *pXGIHWDE,
4077 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004078{
4079
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304080 if (pXGIHWDE->jChipType == XG21) {
4081 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004082 /* LVDS backlight off */
4083 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304084 XGI_XG21SetPanelDelay(3, pVBInfo);
4085 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004086 /* DVO/DVI signal off */
4087 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304088 }
4089 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004090
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304091 if (pXGIHWDE->jChipType == XG27) {
4092 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004093 /* LVDS backlight off */
4094 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304095 XGI_XG21SetPanelDelay(3, pVBInfo);
4096 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004097
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304098 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004099 /* DVO/DVI signal off */
4100 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304101 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004102
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004103 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004104}
4105
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004106static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004107{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004108 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304109 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004110
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004111 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304112 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004113}
4114
Randy Dunlap89229672010-08-10 08:46:44 -07004115#if 0
Randy Dunlap89229672010-08-10 08:46:44 -07004116static void XGI_WaitDisplay(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004117{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004118 while (!(inb(pVBInfo->P3da) & 0x01))
4119 ;
4120 while (inb(pVBInfo->P3da) & 0x01)
4121 ;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004122}
Randy Dunlap89229672010-08-10 08:46:44 -07004123#endif
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004124
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004125static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004126{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304127 if (!(pVBInfo->SetFlag & Win9xDOSMode))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004128 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004129}
4130
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004131static void XGI_SaveCRT2Info(unsigned short ModeNo,
4132 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004133{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304134 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004135
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004136 /* reserve CR34 for CRT1 Mode No */
4137 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304138 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
4139 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004140 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004141}
4142
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004143static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
4144 unsigned short ModeIdIndex,
4145 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004146{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304147 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004148
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304149 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
4150 if (ModeNo <= 0x13) {
4151 xres = pVBInfo->StResInfo[resindex].HTotal;
4152 yres = pVBInfo->StResInfo[resindex].VTotal;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004153 /* si+St_ResInfo */
4154 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;*/
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304155 } else {
4156 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
4157 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004158 /* si+St_ModeFlag */
4159 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004160
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304161 /*
4162 if (pVBInfo->IF_DEF_FSTN) {
4163 xres *= 2;
4164 yres *= 2;
4165 } else {
4166 */
4167 if (modeflag & HalfDCLK)
4168 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004169
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304170 if (modeflag & DoubleScanMode)
4171 yres *= 2;
4172 /* } */
4173 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004174
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304175 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4176 if (pVBInfo->IF_DEF_LVDS == 0) {
4177 if (pVBInfo->LCDResInfo == Panel1600x1200) {
4178 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4179 if (yres == 1024)
4180 yres = 1056;
4181 }
4182 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004183
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304184 if (pVBInfo->LCDResInfo == Panel1280x1024) {
4185 if (yres == 400)
4186 yres = 405;
4187 else if (yres == 350)
4188 yres = 360;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004189
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304190 if (pVBInfo->LCDInfo & LCDVESATiming) {
4191 if (yres == 360)
4192 yres = 375;
4193 }
4194 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004195
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304196 if (pVBInfo->LCDResInfo == Panel1024x768) {
4197 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4198 if (!(pVBInfo->LCDInfo
4199 & LCDNonExpanding)) {
4200 if (yres == 350)
4201 yres = 357;
4202 else if (yres == 400)
4203 yres = 420;
4204 else if (yres == 480)
4205 yres = 525;
4206 }
4207 }
4208 }
4209 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004210
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304211 if (xres == 720)
4212 xres = 640;
4213 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004214
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304215 pVBInfo->VGAHDE = xres;
4216 pVBInfo->HDE = xres;
4217 pVBInfo->VGAVDE = yres;
4218 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004219}
4220
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004221static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004222{
4223
Dan Carpentera65fd092011-01-04 09:02:27 +03004224 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
4225 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304226 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004227
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304228 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004229}
4230
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004231static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
4232 unsigned short ModeIdIndex,
4233 unsigned short RefreshRateTableIndex,
4234 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004235{
4236 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
4237 StandTableIndex, CRT1Index;
4238
4239 pVBInfo->RVBHCMAX = 1;
4240 pVBInfo->RVBHCFACT = 1;
4241
4242 if (ModeNo <= 0x13) {
4243 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4244 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
4245 tempax = pVBInfo->StandTable[StandTableIndex].CRTC[0];
4246 tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[6];
4247 temp1 = pVBInfo->StandTable[StandTableIndex].CRTC[7];
4248 } else {
4249 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004250 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
4251 Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004252 CRT1Index &= IndexMask;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004253 temp1 = (unsigned short) pVBInfo->
4254 XGINEWUB_CRT1Table[CRT1Index].CR[0];
4255 temp2 = (unsigned short) pVBInfo->
4256 XGINEWUB_CRT1Table[CRT1Index].CR[5];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004257 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004258 tempbx = (unsigned short) pVBInfo->
4259 XGINEWUB_CRT1Table[CRT1Index].CR[8];
4260 tempcx = (unsigned short) pVBInfo->
4261 XGINEWUB_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004262 tempcx &= 0x0100;
4263 tempcx = tempcx << 2;
4264 tempbx |= tempcx;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004265 temp1 = (unsigned short) pVBInfo->
4266 XGINEWUB_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004267 }
4268
4269 if (temp1 & 0x01)
4270 tempbx |= 0x0100;
4271
4272 if (temp1 & 0x20)
4273 tempbx |= 0x0200;
4274 tempax += 5;
4275
4276 if (modeflag & Charx8Dot)
4277 tempax *= 8;
4278 else
4279 tempax *= 9;
4280
4281 pVBInfo->VGAHT = tempax;
4282 pVBInfo->HT = tempax;
4283 tempbx++;
4284 pVBInfo->VGAVT = tempbx;
4285 pVBInfo->VT = tempbx;
4286}
4287
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004288static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304289 unsigned short RefreshRateTableIndex,
4290 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004291{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304292 unsigned short tempax = 0, tempbx, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004293
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304294 struct XGI_LCDDataStruct *LCDPtr = NULL;
4295 struct XGI_TVDataStruct *TVPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004296
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304297 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004298 /* si+St_ResInfo */
4299 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304300 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4301 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004302 /* si+Ext_ResInfo */
4303 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304304 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4305 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004306
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304307 pVBInfo->NewFlickerMode = 0;
4308 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004309
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304310 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4311 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4312 pVBInfo);
4313 return;
4314 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004315
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304316 tempbx = 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004317
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304318 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
4319 LCDPtr = (struct XGI_LCDDataStruct *) XGI_GetLcdPtr(tempbx,
4320 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4321 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004322
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304323 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
4324 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
4325 pVBInfo->VGAHT = LCDPtr->VGAHT;
4326 pVBInfo->VGAVT = LCDPtr->VGAVT;
4327 pVBInfo->HT = LCDPtr->LCDHT;
4328 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004329
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304330 if (pVBInfo->LCDResInfo == Panel1024x768) {
4331 tempax = 1024;
4332 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004333
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304334 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4335 if (pVBInfo->VGAVDE == 357)
4336 tempbx = 527;
4337 else if (pVBInfo->VGAVDE == 420)
4338 tempbx = 620;
4339 else if (pVBInfo->VGAVDE == 525)
4340 tempbx = 775;
4341 else if (pVBInfo->VGAVDE == 600)
4342 tempbx = 775;
4343 /* else if (pVBInfo->VGAVDE==350) tempbx=560; */
4344 /* else if (pVBInfo->VGAVDE==400) tempbx=640; */
4345 else
4346 tempbx = 768;
4347 } else
4348 tempbx = 768;
4349 } else if (pVBInfo->LCDResInfo == Panel1024x768x75) {
4350 tempax = 1024;
4351 tempbx = 768;
4352 } else if (pVBInfo->LCDResInfo == Panel1280x1024) {
4353 tempax = 1280;
4354 if (pVBInfo->VGAVDE == 360)
4355 tempbx = 768;
4356 else if (pVBInfo->VGAVDE == 375)
4357 tempbx = 800;
4358 else if (pVBInfo->VGAVDE == 405)
4359 tempbx = 864;
4360 else
4361 tempbx = 1024;
4362 } else if (pVBInfo->LCDResInfo == Panel1280x1024x75) {
4363 tempax = 1280;
4364 tempbx = 1024;
4365 } else if (pVBInfo->LCDResInfo == Panel1280x960) {
4366 tempax = 1280;
4367 if (pVBInfo->VGAVDE == 350)
4368 tempbx = 700;
4369 else if (pVBInfo->VGAVDE == 400)
4370 tempbx = 800;
4371 else if (pVBInfo->VGAVDE == 1024)
4372 tempbx = 960;
4373 else
4374 tempbx = 960;
4375 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
4376 tempax = 1400;
4377 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004378
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304379 if (pVBInfo->VGAVDE == 1024) {
4380 tempax = 1280;
4381 tempbx = 1024;
4382 }
4383 } else if (pVBInfo->LCDResInfo == Panel1600x1200) {
4384 tempax = 1600;
4385 tempbx = 1200; /* alan 10/14/2003 */
4386 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4387 if (pVBInfo->VGAVDE == 350)
4388 tempbx = 875;
4389 else if (pVBInfo->VGAVDE == 400)
4390 tempbx = 1000;
4391 }
4392 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004393
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304394 if (pVBInfo->LCDInfo & LCDNonExpanding) {
4395 tempax = pVBInfo->VGAHDE;
4396 tempbx = pVBInfo->VGAVDE;
4397 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004398
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304399 pVBInfo->HDE = tempax;
4400 pVBInfo->VDE = tempbx;
4401 return;
4402 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004403
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304404 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
4405 tempbx = 4;
4406 TVPtr = (struct XGI_TVDataStruct *) XGI_GetTVPtr(tempbx,
4407 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4408 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004409
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304410 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
4411 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
4412 pVBInfo->VGAHT = TVPtr->VGAHT;
4413 pVBInfo->VGAVT = TVPtr->VGAVT;
4414 pVBInfo->HDE = TVPtr->TVHDE;
4415 pVBInfo->VDE = TVPtr->TVVDE;
4416 pVBInfo->RVBHRS = TVPtr->RVBHRS;
4417 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004418
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304419 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4420 if (resinfo == 0x08)
4421 pVBInfo->NewFlickerMode = 0x40;
4422 else if (resinfo == 0x09)
4423 pVBInfo->NewFlickerMode = 0x40;
4424 else if (resinfo == 0x12)
4425 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004426
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304427 if (pVBInfo->VGAVDE == 350)
4428 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004429
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304430 tempax = ExtHiTVHT;
4431 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004432
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304433 if (pVBInfo->VBInfo & SetInSlaveMode) {
4434 if (pVBInfo->TVInfo & TVSimuMode) {
4435 tempax = StHiTVHT;
4436 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004437
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304438 if (!(modeflag & Charx8Dot)) {
4439 tempax = StHiTextTVHT;
4440 tempbx = StHiTextTVVT;
4441 }
4442 }
4443 }
4444 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
4445 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
4446 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
4447 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
4448 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004449
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304450 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
4451 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
4452 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
4453 } else if (pVBInfo->TVInfo & SetYPbPrMode525i) {
4454 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
4455 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
4456 if (pVBInfo->TVInfo & NTSC1024x768)
4457 tempax = NTSC1024x768HT;
4458 }
4459 } else {
4460 tempax = PALHT;
4461 tempbx = PALVT;
4462 if (!(pVBInfo->TVInfo & SetPALTV)) {
4463 tempax = NTSCHT;
4464 tempbx = NTSCVT;
4465 if (pVBInfo->TVInfo & NTSC1024x768)
4466 tempax = NTSC1024x768HT;
4467 }
4468 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004469
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304470 pVBInfo->HT = tempax;
4471 pVBInfo->VT = tempbx;
4472 return;
4473 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004474}
4475
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004476static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304477 unsigned short RefreshRateTableIndex,
4478 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004479{
Bill Pemberton108afbf2010-06-17 13:10:47 -04004480 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004481
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304482 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
4483 pVBInfo);
4484 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
4485 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004486
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304487 if (pVBInfo->VBType & VB_XGI301) { /* shampoo 0129 */
4488 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004489 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
4490 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
4491 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304492 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004493 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
4494 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304495 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004496
Aaro Koskinen8104e322011-03-13 12:26:22 +02004497 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004498
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304499 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004500 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304501 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004502 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004503}
4504
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004505static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
4506 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004507{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004508 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
4509 short index;
4510 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304511
4512 if (ModeNo <= 0x13)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004513 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304514 else
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004515 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304516
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004517 index = (modeflag & ModeInfoFlag) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304518
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004519 if (index < 0)
4520 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304521
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004522 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304523}
4524
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004525static unsigned short XGI_GetOffset(unsigned short ModeNo,
4526 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304527 unsigned short RefreshRateTableIndex,
4528 struct xgi_hw_device_info *HwDeviceExtension,
4529 struct vb_device_info *pVBInfo)
4530{
4531 unsigned short temp, colordepth, modeinfo, index, infoflag,
4532 ColorDepth[] = { 0x01, 0x02, 0x04 };
4533
4534 modeinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
4535 if (ModeNo <= 0x14)
4536 infoflag = 0;
4537 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004538 infoflag = pVBInfo->
4539 RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304540
4541 index = (modeinfo >> 8) & 0xFF;
4542
4543 temp = pVBInfo->ScreenOffset[index];
4544
4545 if (infoflag & InterlaceMode)
4546 temp = temp << 1;
4547
4548 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4549
4550 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
4551 temp = ModeNo - 0x7C;
4552 colordepth = ColorDepth[temp];
4553 temp = 0x6B;
4554 if (infoflag & InterlaceMode)
4555 temp = temp << 1;
4556 return temp * colordepth;
4557 } else {
4558 return temp * colordepth;
4559 }
4560}
4561
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004562static void XGI_SetCRT2Offset(unsigned short ModeNo,
4563 unsigned short ModeIdIndex,
4564 unsigned short RefreshRateTableIndex,
4565 struct xgi_hw_device_info *HwDeviceExtension,
4566 struct vb_device_info *pVBInfo)
4567{
4568 unsigned short offset;
4569 unsigned char temp;
4570
4571 if (pVBInfo->VBInfo & SetInSlaveMode)
4572 return;
4573
4574 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4575 HwDeviceExtension, pVBInfo);
4576 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004577 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004578 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004579 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004580 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004581 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004582}
4583
Randy Dunlap89229672010-08-10 08:46:44 -07004584static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004585{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004586 /* threshold high ,disable auto threshold */
4587 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
4588 /* threshold low default 04h */
4589 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004590}
4591
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004592static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304593 struct xgi_hw_device_info *HwDeviceExtension,
4594 unsigned short RefreshRateTableIndex,
4595 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004596{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304597 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004598
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304599 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004600 CRT1Index = pVBInfo->
4601 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304602 CRT1Index &= IndexMask;
4603 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4604 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004605
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304606 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4607 HwDeviceExtension, pVBInfo);
4608 XGI_SetCRT2FIFO(pVBInfo);
4609 /* XGI_SetCRT2Sync(ModeNo,RefreshRateTableIndex); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004610
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304611 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004612 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004613
Aaro Koskinen8104e322011-03-13 12:26:22 +02004614 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
4615 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004616}
4617
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004618static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304619 struct xgi_hw_device_info *HwDeviceExtension,
4620 unsigned short RefreshRateTableIndex,
4621 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004622{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304623 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
4624 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004625
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304626 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004627 CRT1Index = pVBInfo->
4628 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304629 CRT1Index &= IndexMask;
4630 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004631 }
4632
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304633 if (ModeNo <= 0x13)
4634 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4635 else
4636 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004637
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304638 /* bainy change table name */
4639 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004640 /* BTVGA2HT 0x08,0x09 */
4641 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004642 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304643 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004644 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004645 /* BTVGA2HDEE 0x0A,0x0C */
4646 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004647 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304648 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
4649 pushbx = pVBInfo->VGAHDE / 2 + 16;
4650 tempcx = tempcx >> 1;
4651 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4652 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004653
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304654 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4655 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004656 tempbx |= ((pVBInfo->
4657 XGINEWUB_CRT1Table[CRT1Index].CR[14] &
4658 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304659 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4660 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
4661 tempcx &= 0x1F;
4662 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[15];
4663 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4664 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4665 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004666
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304667 tempbx += 4;
4668 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004669
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304670 if (tempcx > (pVBInfo->VGAHT / 2))
4671 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004672
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304673 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004674
Aaro Koskinen8104e322011-03-13 12:26:22 +02004675 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304676 } else {
4677 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004678 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304679 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004680 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004681 /* BTVGA2HDEE 0x0A,0x0C */
4682 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004683 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304684 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
4685 pushbx = pVBInfo->VGAHDE + 16;
4686 tempcx = tempcx >> 1;
4687 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4688 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004689
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304690 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4691 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[3];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004692 tempbx |= ((pVBInfo->
4693 XGINEWUB_CRT1Table[CRT1Index].CR[5] &
4694 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304695 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4696 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
4697 tempcx &= 0x1F;
4698 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[6];
4699 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4700 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4701 tempbx += 16;
4702 tempcx += 16;
4703 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004704
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304705 if (tempcx > pVBInfo->VGAHT)
4706 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004707
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304708 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004709 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304710 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004711
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304712 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
4713 tempbx = pushbx;
4714 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
4715 tempax |= (tempbx & 0xFF00);
4716 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004717 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304718 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004719 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304720 tempcx = (pVBInfo->VGAVT - 1);
4721 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004722
Aaro Koskinen8104e322011-03-13 12:26:22 +02004723 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304724 tempbx = pVBInfo->VGAVDE - 1;
4725 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004726 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304727 temp = ((tempbx & 0xFF00) << 3) >> 8;
4728 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004729 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004730
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304731 tempax = pVBInfo->VGAVDE;
4732 tempbx = pVBInfo->VGAVDE;
4733 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004734 /* BTVGA2VRS 0x10,0x11 */
4735 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
4736 /* BTVGA2VRE 0x11 */
4737 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004738
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304739 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4740 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[10];
4741 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004742
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304743 if (temp & 0x04)
4744 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004745
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304746 if (temp & 0x080)
4747 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004748
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304749 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004750
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304751 if (temp & 0x08)
4752 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004753
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304754 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[11];
4755 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
4756 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004757
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304758 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004759 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304760 temp = ((tempbx & 0xFF00) >> 8) << 4;
4761 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004762 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304763 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004764
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304765 if (modeflag & DoubleScanMode)
4766 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004767
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304768 if (modeflag & HalfDCLK)
4769 tempax |= 0x40;
4770
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004771 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004772}
4773
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004774static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
4775{
4776 unsigned long tempax, tempbx;
4777
4778 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
4779 & 0xFFFF;
4780 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
4781 tempax = (tempax * pVBInfo->HT) / tempbx;
4782
4783 return (unsigned short) tempax;
4784}
4785
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004786static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304787 struct xgi_hw_device_info *HwDeviceExtension,
4788 unsigned short RefreshRateTableIndex,
4789 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004790{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304791 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
4792 modeflag, CRT1Index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004793
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304794 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004795 /* si+St_ResInfo */
4796 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304797 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4798 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004799 /* si+Ext_ResInfo */
4800 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304801 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004802 CRT1Index = pVBInfo->
4803 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304804 CRT1Index &= IndexMask;
4805 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004806
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304807 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4808 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004809
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304810 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004811 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304812 /* if (modeflag & Charx8Dot) */
4813 /* tempcx = 0x08; */
4814 /* else */
4815 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004816
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304817 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4818 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004819
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304820 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004821
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304822 if (modeflag & HalfDCLK)
4823 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004824
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304825 tempax = (tempax / tempcx) - 1;
4826 tempbx |= ((tempax & 0x00FF) << 8);
4827 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004828 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004829
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304830 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004831
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304832 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4833 if (!(pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4834 | VB_XGI302LV | VB_XGI301C)))
4835 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004836
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304837 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4838 if (pVBInfo->VBType & VB_XGI301LV) {
4839 if (pVBInfo->VBExtInfo == VB_YPbPr1080i) {
4840 if (resinfo == 7)
4841 temp -= 2;
4842 }
4843 } else if (resinfo == 7) {
4844 temp -= 2;
4845 }
4846 }
4847 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004848
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004849 /* 0x05 Horizontal Display Start */
4850 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
4851 /* 0x06 Horizontal Blank end */
4852 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004853
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304854 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
4855 if (pVBInfo->VBInfo & SetCRT2ToTV)
4856 tempax = pVBInfo->VGAHT;
4857 else
4858 tempax = XGI_GetVGAHT2(pVBInfo);
4859 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004860
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304861 if (tempax >= pVBInfo->VGAHT)
4862 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004863
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304864 if (modeflag & HalfDCLK)
4865 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004866
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304867 tempax = (tempax / tempcx) - 5;
4868 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
4869 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4870 temp = (tempbx & 0x00FF) - 1;
4871 if (!(modeflag & HalfDCLK)) {
4872 temp -= 6;
4873 if (pVBInfo->TVInfo & TVSimuMode) {
4874 temp -= 4;
4875 if (ModeNo > 0x13)
4876 temp -= 10;
4877 }
4878 }
4879 } else {
4880 /* tempcx = tempbx & 0x00FF ; */
4881 tempbx = (tempbx & 0xFF00) >> 8;
4882 tempcx = (tempcx + tempbx) >> 1;
4883 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004884
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304885 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4886 temp -= 1;
4887 if (!(modeflag & HalfDCLK)) {
4888 if ((modeflag & Charx8Dot)) {
4889 temp += 4;
4890 if (pVBInfo->VGAHDE >= 800)
4891 temp -= 6;
4892 }
4893 }
4894 } else {
4895 if (!(modeflag & HalfDCLK)) {
4896 temp -= 4;
4897 if (pVBInfo->LCDResInfo != Panel1280x960) {
4898 if (pVBInfo->VGAHDE >= 800) {
4899 temp -= 7;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004900 if (pVBInfo->ModeType ==
4901 ModeEGA) {
4902 if (pVBInfo->VGAVDE ==
4903 1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304904 temp += 15;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004905 if (pVBInfo->LCDResInfo != Panel1280x1024) {
4906 temp +=
4907 7;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304908 }
4909 }
4910 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004911
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304912 if (pVBInfo->VGAHDE >= 1280) {
4913 if (pVBInfo->LCDResInfo
4914 != Panel1280x960) {
4915 if (pVBInfo->LCDInfo
4916 & LCDNonExpanding) {
4917 temp
4918 += 28;
4919 }
4920 }
4921 }
4922 }
4923 }
4924 }
4925 }
4926 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004927
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004928 /* 0x07 Horizontal Retrace Start */
4929 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4930 /* 0x08 Horizontal Retrace End */
4931 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004932
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304933 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4934 if (pVBInfo->TVInfo & TVSimuMode) {
4935 if ((ModeNo == 0x06) || (ModeNo == 0x10) || (ModeNo
4936 == 0x11) || (ModeNo == 0x13) || (ModeNo
4937 == 0x0F)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004938 xgifb_reg_set(pVBInfo->Part1Port, 0x07, 0x5b);
4939 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0x03);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304940 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004941
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304942 if ((ModeNo == 0x00) || (ModeNo == 0x01)) {
4943 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004944 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304945 0x07, 0x2A);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004946 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304947 0x08, 0x61);
4948 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004949 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304950 0x07, 0x2A);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004951 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304952 0x08, 0x41);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004953 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304954 0x0C, 0xF0);
4955 }
4956 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004957
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304958 if ((ModeNo == 0x02) || (ModeNo == 0x03) || (ModeNo
4959 == 0x07)) {
4960 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004961 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304962 0x07, 0x54);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004963 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304964 0x08, 0x00);
4965 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004966 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304967 0x07, 0x55);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004968 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304969 0x08, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004970 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304971 0x0C, 0xF0);
4972 }
4973 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004974
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304975 if ((ModeNo == 0x04) || (ModeNo == 0x05) || (ModeNo
4976 == 0x0D) || (ModeNo == 0x50)) {
4977 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004978 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304979 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004980 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304981 0x08, 0x03);
4982 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004983 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304984 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004985 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304986 0x08, 0x02);
4987 }
4988 }
4989 }
4990 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004991
Aaro Koskinen8104e322011-03-13 12:26:22 +02004992 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004993 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004994 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004995
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304996 tempbx = pVBInfo->VGAVT;
4997 push1 = tempbx;
4998 tempcx = 0x121;
4999 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005000
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305001 if (tempbx == 357)
5002 tempbx = 350;
5003 if (tempbx == 360)
5004 tempbx = 350;
5005 if (tempbx == 375)
5006 tempbx = 350;
5007 if (tempbx == 405)
5008 tempbx = 400;
5009 if (tempbx == 525)
5010 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005011
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305012 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005013
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305014 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5015 if (pVBInfo->LCDResInfo == Panel1024x768) {
5016 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
5017 if (tempbx == 350)
5018 tempbx += 5;
5019 if (tempbx == 480)
5020 tempbx += 5;
5021 }
5022 }
5023 }
5024 tempbx--;
5025 temp = tempbx & 0x00FF;
5026 tempbx--;
5027 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005028 /* 0x10 vertical Blank Start */
5029 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305030 tempbx = push2;
5031 tempbx--;
5032 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005033 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005034
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305035 if (tempbx & 0x0100)
5036 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005037
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305038 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005039
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305040 if (modeflag & DoubleScanMode)
5041 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005042
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305043 if (tempbx & 0x0200)
5044 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005045
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305046 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005047 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005048
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305049 if (tempbx & 0x0400)
5050 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005051
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005052 /* 0x11 Vertival Blank End */
5053 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305054
5055 tempax = push1;
5056 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
5057 tempax = tempax >> 2;
5058 push1 = tempax; /* push ax */
5059
5060 if (resinfo != 0x09) {
5061 tempax = tempax << 1;
5062 tempbx += tempax;
5063 }
5064
5065 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5066 if (pVBInfo->VBType & VB_XGI301LV) {
5067 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5068 tempbx -= 10;
5069 } else {
5070 if (pVBInfo->TVInfo & TVSimuMode) {
5071 if (pVBInfo->TVInfo & SetPALTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005072 if (pVBInfo->VBType &
5073 VB_XGI301LV) {
5074 if (!(pVBInfo->TVInfo &
5075 (SetYPbPrMode525p |
5076 SetYPbPrMode750p |
5077 SetYPbPrMode1080i)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305078 tempbx += 40;
5079 } else {
5080 tempbx += 40;
5081 }
5082 }
5083 }
5084 }
5085 } else {
5086 tempbx -= 10;
5087 }
5088 } else {
5089 if (pVBInfo->TVInfo & TVSimuMode) {
5090 if (pVBInfo->TVInfo & SetPALTV) {
5091 if (pVBInfo->VBType & VB_XGI301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005092 if (!(pVBInfo->TVInfo &
5093 (SetYPbPrMode525p |
5094 SetYPbPrMode750p |
5095 SetYPbPrMode1080i)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305096 tempbx += 40;
5097 } else {
5098 tempbx += 40;
5099 }
5100 }
5101 }
5102 }
5103 tempax = push1;
5104 tempax = tempax >> 2;
5105 tempax++;
5106 tempax += tempbx;
5107 push1 = tempax; /* push ax */
5108
5109 if ((pVBInfo->TVInfo & SetPALTV)) {
5110 if (tempbx <= 513) {
5111 if (tempax >= 513)
5112 tempbx = 513;
5113 }
5114 }
5115
5116 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005117 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305118 tempbx--;
5119 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005120 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305121
5122 if (tempbx & 0x0100)
5123 tempcx |= 0x0008;
5124
5125 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005126 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305127
5128 tempbx++;
5129
5130 if (tempbx & 0x0100)
5131 tempcx |= 0x0004;
5132
5133 if (tempbx & 0x0200)
5134 tempcx |= 0x0080;
5135
5136 if (tempbx & 0x0400)
5137 tempcx |= 0x0C00;
5138
5139 tempbx = push1; /* pop ax */
5140 temp = tempbx & 0x00FF;
5141 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005142 /* 0x0D vertical Retrace End */
5143 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305144
5145 if (tempbx & 0x0010)
5146 tempcx |= 0x2000;
5147
5148 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005149 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305150 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005151 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305152 tempax = modeflag;
5153 temp = (tempax & 0xFF00) >> 8;
5154
5155 temp = (temp >> 1) & 0x09;
5156
5157 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
5158 temp |= 0x01;
5159
Aaro Koskinen8104e322011-03-13 12:26:22 +02005160 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
5161 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
5162 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305163
5164 if (pVBInfo->LCDInfo & LCDRGB18Bit)
5165 temp = 0x80;
5166 else
5167 temp = 0x00;
5168
Aaro Koskinen8104e322011-03-13 12:26:22 +02005169 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305170
5171 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005172}
5173
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005174static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305175 unsigned short RefreshRateTableIndex,
5176 struct xgi_hw_device_info *HwDeviceExtension,
5177 struct vb_device_info *pVBInfo)
5178{
5179 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
5180 modeflag, resinfo, crt2crtc;
5181 unsigned char *TimingPoint;
5182
5183 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
5184
5185 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005186 /* si+St_ResInfo */
5187 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305188 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
5189 crt2crtc = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
5190 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005191 /* si+Ext_ResInfo */
5192 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305193 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005194 crt2crtc = pVBInfo->RefIndex[RefreshRateTableIndex].
5195 Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305196 }
5197
5198 tempax = 0;
5199
5200 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
5201 tempax |= 0x0800;
5202
5203 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5204 tempax |= 0x0400;
5205
5206 if (pVBInfo->VBInfo & SetCRT2ToSCART)
5207 tempax |= 0x0200;
5208
5209 if (!(pVBInfo->TVInfo & SetPALTV))
5210 tempax |= 0x1000;
5211
5212 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5213 tempax |= 0x0100;
5214
5215 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
5216 tempax &= 0xfe00;
5217
5218 tempax = (tempax & 0xff00) >> 8;
5219
Aaro Koskinen8104e322011-03-13 12:26:22 +02005220 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305221 TimingPoint = pVBInfo->NTSCTiming;
5222
5223 if (pVBInfo->TVInfo & SetPALTV)
5224 TimingPoint = pVBInfo->PALTiming;
5225
5226 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5227 TimingPoint = pVBInfo->HiTVExtTiming;
5228
5229 if (pVBInfo->VBInfo & SetInSlaveMode)
5230 TimingPoint = pVBInfo->HiTVSt2Timing;
5231
5232 if (pVBInfo->SetFlag & TVSimuMode)
5233 TimingPoint = pVBInfo->HiTVSt1Timing;
5234
5235 if (!(modeflag & Charx8Dot))
5236 TimingPoint = pVBInfo->HiTVTextTiming;
5237 }
5238
5239 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5240 if (pVBInfo->TVInfo & SetYPbPrMode525i)
5241 TimingPoint = pVBInfo->YPbPr525iTiming;
5242
5243 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5244 TimingPoint = pVBInfo->YPbPr525pTiming;
5245
5246 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5247 TimingPoint = pVBInfo->YPbPr750pTiming;
5248 }
5249
5250 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005251 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305252
5253 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005254 /* di->temp2[j] */
5255 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305256
5257 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005258 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305259
5260 temp = pVBInfo->NewFlickerMode;
5261 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005262 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305263
5264 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5265 tempax = 950;
5266
5267 if (pVBInfo->TVInfo & SetPALTV)
5268 tempax = 520;
5269 else
5270 tempax = 440;
5271
5272 if (pVBInfo->VDE <= tempax) {
5273 tempax -= pVBInfo->VDE;
5274 tempax = tempax >> 2;
5275 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
5276 push1 = tempax;
5277 temp = (tempax & 0xFF00) >> 8;
5278 temp += (unsigned short) TimingPoint[0];
5279
5280 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5281 | VB_XGI302LV | VB_XGI301C)) {
5282 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
5283 | SetCRT2ToSVIDEO | SetCRT2ToSCART
5284 | SetCRT2ToYPbPr)) {
5285 tempcx = pVBInfo->VGAHDE;
5286 if (tempcx >= 1024) {
5287 temp = 0x17; /* NTSC */
5288 if (pVBInfo->TVInfo & SetPALTV)
5289 temp = 0x19; /* PAL */
5290 }
5291 }
5292 }
5293
Aaro Koskinen8104e322011-03-13 12:26:22 +02005294 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305295 tempax = push1;
5296 temp = (tempax & 0xFF00) >> 8;
5297 temp += TimingPoint[1];
5298
5299 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5300 | VB_XGI302LV | VB_XGI301C)) {
5301 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
5302 | SetCRT2ToSVIDEO | SetCRT2ToSCART
5303 | SetCRT2ToYPbPr))) {
5304 tempcx = pVBInfo->VGAHDE;
5305 if (tempcx >= 1024) {
5306 temp = 0x1D; /* NTSC */
5307 if (pVBInfo->TVInfo & SetPALTV)
5308 temp = 0x52; /* PAL */
5309 }
5310 }
5311 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005312 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305313 }
5314
5315 /* 301b */
5316 tempcx = pVBInfo->HT;
5317
5318 if (XGI_IsLCDDualLink(pVBInfo))
5319 tempcx = tempcx >> 1;
5320
5321 tempcx -= 2;
5322 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005323 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305324
5325 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005326 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305327
5328 tempcx = pVBInfo->HT >> 1;
5329 push1 = tempcx; /* push cx */
5330 tempcx += 7;
5331
5332 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5333 tempcx -= 4;
5334
5335 temp = tempcx & 0x00FF;
5336 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005337 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305338
5339 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5340 tempbx += tempcx;
5341 push2 = tempbx;
5342 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005343 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305344 temp = (tempbx & 0xFF00) >> 8;
5345 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005346 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305347
5348 tempbx = push2;
5349 tempbx = tempbx + 8;
5350 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5351 tempbx = tempbx - 4;
5352 tempcx = tempbx;
5353 }
5354
5355 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005356 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305357
5358 j += 2;
5359 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
5360 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005361 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305362 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005363 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305364
5365 tempcx += 8;
5366 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5367 tempcx -= 4;
5368
5369 temp = tempcx & 0xFF;
5370 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005371 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305372
5373 tempcx = push1; /* pop cx */
5374 j += 2;
5375 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5376 tempcx -= temp;
5377 temp = tempcx & 0x00FF;
5378 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005379 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305380
5381 tempcx -= 11;
5382
5383 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
5384 tempax = XGI_GetVGAHT2(pVBInfo);
5385 tempcx = tempax - 1;
5386 }
5387 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005388 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305389
5390 tempbx = pVBInfo->VDE;
5391
5392 if (pVBInfo->VGAVDE == 360)
5393 tempbx = 746;
5394 if (pVBInfo->VGAVDE == 375)
5395 tempbx = 746;
5396 if (pVBInfo->VGAVDE == 405)
5397 tempbx = 853;
5398
5399 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005400 if (pVBInfo->VBType &
5401 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
5402 if (!(pVBInfo->TVInfo &
5403 (SetYPbPrMode525p | SetYPbPrMode750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305404 tempbx = tempbx >> 1;
5405 } else
5406 tempbx = tempbx >> 1;
5407 }
5408
5409 tempbx -= 2;
5410 temp = tempbx & 0x00FF;
5411
5412 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5413 if (pVBInfo->VBType & VB_XGI301LV) {
5414 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5415 if (pVBInfo->VBInfo & SetInSlaveMode) {
5416 if (ModeNo == 0x2f)
5417 temp += 1;
5418 }
5419 }
5420 } else {
5421 if (pVBInfo->VBInfo & SetInSlaveMode) {
5422 if (ModeNo == 0x2f)
5423 temp += 1;
5424 }
5425 }
5426 }
5427
Aaro Koskinen8104e322011-03-13 12:26:22 +02005428 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305429
5430 temp = (tempcx & 0xFF00) >> 8;
5431 temp |= ((tempbx & 0xFF00) >> 8) << 6;
5432
5433 if (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) {
5434 if (pVBInfo->VBType & VB_XGI301LV) {
5435 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5436 temp |= 0x10;
5437
5438 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5439 temp |= 0x20;
5440 }
5441 } else {
5442 temp |= 0x10;
5443 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5444 temp |= 0x20;
5445 }
5446 }
5447
Aaro Koskinen8104e322011-03-13 12:26:22 +02005448 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305449
5450 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5451 | VB_XGI302LV | VB_XGI301C)) { /* TV gatingno */
5452 tempbx = pVBInfo->VDE;
5453 tempcx = tempbx - 2;
5454
5455 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5456 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p
5457 | SetYPbPrMode750p)))
5458 tempbx = tempbx >> 1;
5459 }
5460
5461 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
5462 temp = 0;
5463 if (tempcx & 0x0400)
5464 temp |= 0x20;
5465
5466 if (tempbx & 0x0400)
5467 temp |= 0x40;
5468
Aaro Koskinen8104e322011-03-13 12:26:22 +02005469 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305470 }
5471
5472 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005473 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305474 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005475 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305476 }
5477
5478 tempbx = tempbx & 0x00FF;
5479
5480 if (!(modeflag & HalfDCLK)) {
5481 tempcx = pVBInfo->VGAHDE;
5482 if (tempcx >= pVBInfo->HDE) {
5483 tempbx |= 0x2000;
5484 tempax &= 0x00FF;
5485 }
5486 }
5487
5488 tempcx = 0x0101;
5489
5490 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
5491 if (pVBInfo->VGAHDE >= 1024) {
5492 tempcx = 0x1920;
5493 if (pVBInfo->VGAHDE >= 1280) {
5494 tempcx = 0x1420;
5495 tempbx = tempbx & 0xDFFF;
5496 }
5497 }
5498 }
5499
5500 if (!(tempbx & 0x2000)) {
5501 if (modeflag & HalfDCLK)
5502 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
5503
5504 push1 = tempbx;
5505 tempeax = pVBInfo->VGAHDE;
5506 tempebx = (tempcx & 0xFF00) >> 8;
5507 longtemp = tempeax * tempebx;
5508 tempecx = tempcx & 0x00FF;
5509 longtemp = longtemp / tempecx;
5510
5511 /* 301b */
5512 tempecx = 8 * 1024;
5513
5514 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5515 | VB_XGI302LV | VB_XGI301C)) {
5516 tempecx = tempecx * 8;
5517 }
5518
5519 longtemp = longtemp * tempecx;
5520 tempecx = pVBInfo->HDE;
5521 temp2 = longtemp % tempecx;
5522 tempeax = longtemp / tempecx;
5523 if (temp2 != 0)
5524 tempeax += 1;
5525
5526 tempax = (unsigned short) tempeax;
5527
5528 /* 301b */
5529 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5530 | VB_XGI302LV | VB_XGI301C)) {
5531 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
5532 }
5533 /* end 301b */
5534
5535 tempbx = push1;
5536 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
5537 | (tempbx & 0x00FF));
5538 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
5539 | (tempax & 0x00FF));
5540 temp = (tempax & 0xFF00) >> 8;
5541 } else {
5542 temp = (tempax & 0x00FF) >> 8;
5543 }
5544
Aaro Koskinen8104e322011-03-13 12:26:22 +02005545 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305546 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005547 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305548 temp = tempcx & 0x00FF;
5549
5550 if (tempbx & 0x2000)
5551 temp = 0;
5552
5553 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5554 temp |= 0x18;
5555
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005556 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305557 if (pVBInfo->TVInfo & SetPALTV) {
5558 tempbx = 0x0382;
5559 tempcx = 0x007e;
5560 } else {
5561 tempbx = 0x0369;
5562 tempcx = 0x0061;
5563 }
5564
5565 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005566 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305567 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005568 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305569
5570 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
5571 temp = temp << 2;
5572 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
5573
5574 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5575 temp |= 0x10;
5576
5577 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5578 temp |= 0x20;
5579
5580 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5581 temp |= 0x60;
5582 }
5583
Aaro Koskinen8104e322011-03-13 12:26:22 +02005584 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005585 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005586 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305587
5588 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))) {
5589 if (pVBInfo->TVInfo & NTSC1024x768) {
5590 TimingPoint = XGI_NTSC1024AdjTime;
5591 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005592 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305593 TimingPoint[j]);
5594 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005595 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305596 }
5597 }
5598
5599 /* [ycchen] 01/14/03 Modify for 301C PALM Support */
5600 if (pVBInfo->VBType & VB_XGI301C) {
5601 if (pVBInfo->TVInfo & SetPALMTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005602 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305603 0x08); /* PALM Mode */
5604 }
5605
5606 if (pVBInfo->TVInfo & SetPALMTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005607 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305608 0x01);
5609 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02005610 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305611
5612 /* if ( !( pVBInfo->VBType & VB_XGI301C ) ) */
Aaro Koskinendc505562011-03-13 12:26:26 +02005613 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305614 }
5615
5616 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5617 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02005618 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305619 }
5620
5621 if (pVBInfo->VBInfo & SetCRT2ToTV)
5622 return;
5623}
5624
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005625static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305626 struct xgi_hw_device_info *HwDeviceExtension,
5627 unsigned short RefreshRateTableIndex,
5628 struct vb_device_info *pVBInfo)
5629{
5630 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
5631 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
5632
5633 struct XGI_LCDDesStruct *LCDBDesPtr = NULL;
5634
5635 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005636 /* si+St_ResInfo */
5637 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305638 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
5639 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005640 /* si+Ext_ResInfo */
5641 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305642 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005643 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
5644 Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305645 CRT1Index &= IndexMask;
5646 }
5647
5648 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5649 return;
5650
5651 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
5652
5653 if (XGI_IsLCDDualLink(pVBInfo))
5654 tempbx = tempbx >> 1;
5655
5656 tempbx -= 1;
5657 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005658 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305659 temp = (tempbx & 0xFF00) >> 8;
5660 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005661 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305662 temp = 0x01;
5663
5664 if (pVBInfo->LCDResInfo == Panel1280x1024) {
5665 if (pVBInfo->ModeType == ModeEGA) {
5666 if (pVBInfo->VGAHDE >= 1024) {
5667 temp = 0x02;
5668 if (pVBInfo->LCDInfo & LCDVESATiming)
5669 temp = 0x01;
5670 }
5671 }
5672 }
5673
Aaro Koskinen8104e322011-03-13 12:26:22 +02005674 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305675 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
5676 push1 = tempbx;
5677 tempbx--;
5678 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005679 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305680 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005681 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305682
5683 tempcx = pVBInfo->VT - 1;
5684 push2 = tempcx + 1;
5685 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005686 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305687 temp = (tempcx & 0xFF00) >> 8;
5688 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005689 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005690 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
5691 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
5692 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
5693 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305694
5695 /* Customized LCDB Des no add */
5696 tempbx = 5;
5697 LCDBDesPtr = (struct XGI_LCDDesStruct *) XGI_GetLcdPtr(tempbx, ModeNo,
5698 ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5699 tempah = pVBInfo->LCDResInfo;
5700 tempah &= PanelResInfo;
5701
5702 if ((tempah == Panel1024x768) || (tempah == Panel1024x768x75)) {
5703 tempbx = 1024;
5704 tempcx = 768;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005705 } else if ((tempah == Panel1280x1024) ||
5706 (tempah == Panel1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305707 tempbx = 1280;
5708 tempcx = 1024;
5709 } else if (tempah == Panel1400x1050) {
5710 tempbx = 1400;
5711 tempcx = 1050;
5712 } else {
5713 tempbx = 1600;
5714 tempcx = 1200;
5715 }
5716
5717 if (pVBInfo->LCDInfo & EnableScalingLCD) {
5718 tempbx = pVBInfo->HDE;
5719 tempcx = pVBInfo->VDE;
5720 }
5721
5722 pushbx = tempbx;
5723 tempax = pVBInfo->VT;
5724 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
5725 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
5726 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
5727 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
5728 tempbx = pVBInfo->LCDVDES;
5729 tempcx += tempbx;
5730
5731 if (tempcx >= tempax)
5732 tempcx -= tempax; /* lcdvdes */
5733
5734 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005735 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305736 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005737 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305738 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
5739 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
5740 tempah = tempch;
5741 tempah = tempah << 3;
5742 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005743 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305744
5745 /* getlcdsync() */
5746 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5747 tempcx = tempbx;
5748 tempax = pVBInfo->VT;
5749 tempbx = pVBInfo->LCDVRS;
5750
5751 /* if (SetLCD_Info & EnableScalingLCD) */
5752 tempcx += tempbx;
5753 if (tempcx >= tempax)
5754 tempcx -= tempax;
5755
5756 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005757 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305758 temp = (tempbx & 0xFF00) >> 8;
5759 temp = temp << 4;
5760 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005761 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305762 tempcx = pushbx;
5763 tempax = pVBInfo->HT;
5764 tempbx = pVBInfo->LCDHDES;
5765 tempbx &= 0x0FFF;
5766
5767 if (XGI_IsLCDDualLink(pVBInfo)) {
5768 tempax = tempax >> 1;
5769 tempbx = tempbx >> 1;
5770 tempcx = tempcx >> 1;
5771 }
5772
5773 if (pVBInfo->VBType & VB_XGI302LV)
5774 tempbx += 1;
5775
5776 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
5777 tempbx += 1;
5778
5779 tempcx += tempbx;
5780
5781 if (tempcx >= tempax)
5782 tempcx -= tempax;
5783
5784 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005785 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305786 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005787 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305788 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005789 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305790 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005791 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305792
5793 /* getlcdsync() */
5794 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5795 tempcx = tempax;
5796 tempax = pVBInfo->HT;
5797 tempbx = pVBInfo->LCDHRS;
5798 /* if ( SetLCD_Info & EnableScalingLCD) */
5799 if (XGI_IsLCDDualLink(pVBInfo)) {
5800 tempax = tempax >> 1;
5801 tempbx = tempbx >> 1;
5802 tempcx = tempcx >> 1;
5803 }
5804
5805 if (pVBInfo->VBType & VB_XGI302LV)
5806 tempbx += 1;
5807
5808 tempcx += tempbx;
5809
5810 if (tempcx >= tempax)
5811 tempcx -= tempax;
5812
5813 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005814 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305815
5816 temp = (tempbx & 0xFF00) >> 8;
5817 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005818 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305819 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005820 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305821
5822 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
5823 if (pVBInfo->VGAVDE == 525) {
5824 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5825 | VB_XGI301LV | VB_XGI302LV
5826 | VB_XGI301C)) {
5827 temp = 0xC6;
5828 } else
5829 temp = 0xC4;
5830
Aaro Koskinen8104e322011-03-13 12:26:22 +02005831 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
5832 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305833 }
5834
5835 if (pVBInfo->VGAVDE == 420) {
5836 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5837 | VB_XGI301LV | VB_XGI302LV
5838 | VB_XGI301C)) {
5839 temp = 0x4F;
5840 } else
5841 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005842 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305843 }
5844 }
5845}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005846
5847/* --------------------------------------------------------------------- */
5848/* Function : XGI_GetTap4Ptr */
5849/* Input : */
5850/* Output : di -> Tap4 Reg. Setting Pointer */
5851/* Description : */
5852/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005853static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305854 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005855{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305856 unsigned short tempax, tempbx, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005857
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305858 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005859
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305860 if (tempcx == 0) {
5861 tempax = pVBInfo->VGAHDE;
5862 tempbx = pVBInfo->HDE;
5863 } else {
5864 tempax = pVBInfo->VGAVDE;
5865 tempbx = pVBInfo->VDE;
5866 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005867
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305868 if (tempax < tempbx)
5869 return &EnlargeTap4Timing[0];
5870 else if (tempax == tempbx)
5871 return &NoScaleTap4Timing[0]; /* 1:1 */
5872 else
5873 Tap4TimingPtr = NTSCTap4Timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005874
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305875 if (pVBInfo->TVInfo & SetPALTV)
5876 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005877
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305878 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5879 if (pVBInfo->TVInfo & SetYPbPrMode525i)
5880 Tap4TimingPtr = YPbPr525iTap4Timing;
5881 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5882 Tap4TimingPtr = YPbPr525pTap4Timing;
5883 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5884 Tap4TimingPtr = YPbPr750pTap4Timing;
5885 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005886
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305887 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5888 Tap4TimingPtr = HiTVTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005889
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305890 i = 0;
5891 while (Tap4TimingPtr[i].DE != 0xFFFF) {
5892 if (Tap4TimingPtr[i].DE == tempax)
5893 break;
5894 i++;
5895 }
5896 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005897}
5898
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005899static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005900{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305901 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005902
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305903 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005904
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305905 if (!(pVBInfo->VBType & VB_XGI301C))
5906 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005907
5908#ifndef Tap4
Aaro Koskinendc505562011-03-13 12:26:26 +02005909 xgifb_reg_and(pVBInfo->Part2Port, 0x4E, 0xEB); /* Disable Tap4 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005910#else /* Tap4 Setting */
5911
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305912 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
5913 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005914 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005915
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005916 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5917 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV))) {
5918 /* Set Vertical Scaling */
5919 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305920 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005921 xgifb_reg_set(pVBInfo->Part2Port,
5922 i,
5923 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305924 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005925
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005926 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5927 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)))
5928 /* Enable V.Scaling */
5929 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305930 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005931 /* Enable H.Scaling */
5932 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005933#endif
5934}
5935
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005936static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305937 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005938{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305939 unsigned short i;
5940 unsigned char *tempdi;
5941 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005942
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305943 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005944 /* si+St_ResInfo */
5945 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305946 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005947 /* si+Ext_ResInfo */
5948 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005949
Aaro Koskinen8104e322011-03-13 12:26:22 +02005950 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305951 if (pVBInfo->TVInfo & SetPALTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005952 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5953 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305954 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005955 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
5956 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305957 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005958
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305959 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5960 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005961
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305962 if (pVBInfo->TVInfo & SetPALMTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005963 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5964 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
5965 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305966 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005967
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305968 if ((pVBInfo->VBInfo & SetCRT2ToHiVisionTV) || (pVBInfo->VBInfo
5969 & SetCRT2ToYPbPr)) {
5970 if (pVBInfo->TVInfo & SetYPbPrMode525i)
5971 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005972
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305973 tempdi = pVBInfo->HiTVGroup3Data;
5974 if (pVBInfo->SetFlag & TVSimuMode) {
5975 tempdi = pVBInfo->HiTVGroup3Simu;
5976 if (!(modeflag & Charx8Dot))
5977 tempdi = pVBInfo->HiTVGroup3Text;
5978 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005979
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305980 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5981 tempdi = pVBInfo->Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005982
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305983 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5984 tempdi = pVBInfo->Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005985
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305986 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005987 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005988
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305989 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
5990 if (pVBInfo->TVInfo & SetYPbPrMode525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005991 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305992 }
5993 }
5994 return;
5995} /* {end of XGI_SetGroup3} */
5996
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005997static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305998 unsigned short RefreshRateTableIndex,
5999 struct xgi_hw_device_info *HwDeviceExtension,
6000 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006001{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306002 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006003
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306004 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006005
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306006 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006007 /* si+St_ResInfo */
6008 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306009 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006010 /* si+Ext_ResInfo */
6011 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006012
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306013 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006014 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006015
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306016 tempbx = pVBInfo->RVBHCMAX;
6017 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006018 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306019 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
6020 tempcx = pVBInfo->VGAHT - 1;
6021 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006022 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006023
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306024 temp = ((tempcx & 0xFF00) >> 8) << 3;
6025 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006026
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306027 tempcx = pVBInfo->VGAVT - 1;
6028 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
6029 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006030
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306031 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006032 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306033 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006034 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006035 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306036 tempcx = pVBInfo->VBInfo;
6037 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006038
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306039 if (modeflag & HalfDCLK)
6040 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006041
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306042 if (XGI_IsLCDDualLink(pVBInfo))
6043 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006044
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306045 if (tempcx & SetCRT2ToHiVisionTV) {
6046 temp = 0;
6047 if (tempbx <= 1024)
6048 temp = 0xA0;
6049 if (tempbx == 1280)
6050 temp = 0xC0;
6051 } else if (tempcx & SetCRT2ToTV) {
6052 temp = 0xA0;
6053 if (tempbx <= 800)
6054 temp = 0x80;
6055 } else {
6056 temp = 0x80;
6057 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
6058 temp = 0;
6059 if (tempbx > 800)
6060 temp = 0x60;
6061 }
6062 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006063
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306064 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p)) {
6065 temp = 0x00;
6066 if (pVBInfo->VGAHDE == 1280)
6067 temp = 0x40;
6068 if (pVBInfo->VGAHDE == 1024)
6069 temp = 0x20;
6070 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006071 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006072
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306073 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006074
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306075 if (tempcx & SetCRT2ToHiVisionTV) {
6076 if (!(temp & 0xE000))
6077 tempbx = tempbx >> 1;
6078 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006079
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306080 tempcx = pVBInfo->RVBHRS;
6081 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006082 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006083
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306084 tempeax = pVBInfo->VGAVDE;
6085 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006086
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306087 if (tempeax <= tempebx) {
6088 tempcx = (tempcx & (~0x4000));
6089 tempeax = pVBInfo->VGAVDE;
6090 } else {
6091 tempeax -= tempebx;
6092 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006093
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306094 templong = (tempeax * 256 * 1024) % tempebx;
6095 tempeax = (tempeax * 256 * 1024) / tempebx;
6096 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006097
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306098 if (templong != 0)
6099 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306101 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006102 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006103
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306104 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006105 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306106 tempbx = (unsigned short) (tempebx >> 16);
6107 temp = tempbx & 0x00FF;
6108 temp = temp << 4;
6109 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006110 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006111
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306112 /* 301b */
6113 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6114 | VB_XGI302LV | VB_XGI301C)) {
6115 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006116 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306117 tempax = pVBInfo->VGAHDE;
6118 if (modeflag & HalfDCLK)
6119 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006120
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306121 if (XGI_IsLCDDualLink(pVBInfo))
6122 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006123
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006124 /* if((pVBInfo->VBInfo&(SetCRT2ToLCD)) ||
6125 ((pVBInfo->TVInfo&SetYPbPrMode525p) ||
6126 (pVBInfo->TVInfo&SetYPbPrMode750p))) { */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306127 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
6128 if (tempax > 800)
6129 tempax -= 800;
6130 } else {
6131 if (pVBInfo->VGAHDE > 800) {
6132 if (pVBInfo->VGAHDE == 1024)
6133 tempax = (tempax * 25 / 32) - 1;
6134 else
6135 tempax = (tempax * 20 / 32) - 1;
6136 }
6137 }
6138 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006139
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306140 /*
6141 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
6142 if (pVBInfo->VBType & VB_XGI301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006143 if (!(pVBInfo->TVInfo &
6144 (SetYPbPrMode525p |
6145 SetYPbPrMode750p |
6146 SetYPbPrMode1080i))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306147 if (pVBInfo->VGAHDE > 800) {
6148 if (pVBInfo->VGAHDE == 1024)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006149 tempax =(tempax * 25 /
6150 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306151 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006152 tempax = (tempax * 20 /
6153 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306154 }
6155 }
6156 } else {
6157 if (pVBInfo->VGAHDE > 800) {
6158 if (pVBInfo->VGAHDE == 1024)
6159 tempax = (tempax * 25 / 32) - 1;
6160 else
6161 tempax = (tempax * 20 / 32) - 1;
6162 }
6163 }
6164 }
6165 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006166
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306167 temp = (tempax & 0xFF00) >> 8;
6168 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006169 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306170 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006171 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006172
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306173 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
6174 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006175 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006176
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306177 }
6178 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306180 if (pVBInfo->VBInfo & SetCRT2ToTV) {
6181 if (!(pVBInfo->TVInfo & (NTSC1024x768
6182 | SetYPbPrMode525p | SetYPbPrMode750p
6183 | SetYPbPrMode1080i))) {
6184 temp |= 0x0001;
6185 if ((pVBInfo->VBInfo & SetInSlaveMode)
6186 && (!(pVBInfo->TVInfo
6187 & TVSimuMode)))
6188 temp &= (~0x0001);
6189 }
6190 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006191
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006192 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306193 tempbx = pVBInfo->HT;
6194 if (XGI_IsLCDDualLink(pVBInfo))
6195 tempbx = tempbx >> 1;
6196 tempbx = (tempbx >> 1) - 2;
6197 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006198 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306199 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006200 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306201 }
6202 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006203
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306204 if (pVBInfo->ISXPDOS == 0)
6205 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6206 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006207}
6208
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006209static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
6210{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006211 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006212}
6213
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006214static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306215 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006216{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306217 unsigned short Pindex, Pdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006218
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306219 Pindex = pVBInfo->Part5Port;
6220 Pdata = pVBInfo->Part5Port + 1;
6221 if (pVBInfo->ModeType == ModeVGA) {
6222 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
6223 | CRT2DisplayFlag))) {
6224 XGINew_EnableCRT2(pVBInfo);
6225 /* LoadDAC2(pVBInfo->Part5Port, ModeNo, ModeIdIndex); */
6226 }
6227 }
6228 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006229}
6230
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006231static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306232 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006233{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006234 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006235}
6236
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006237static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306238 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006239{
6240
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006241 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006242}
6243
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006244/*----------------------------------------------------------------------------*/
6245/* input */
6246/* bl[5] : 1;LVDS signal on */
6247/* bl[1] : 1;LVDS backlight on */
6248/* bl[0] : 1:LVDS VDD on */
6249/* bh: 100000b : clear bit 5, to set bit5 */
6250/* 000010b : clear bit 1, to set bit1 */
6251/* 000001b : clear bit 0, to set bit0 */
6252/*----------------------------------------------------------------------------*/
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306253void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
6254 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006255{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306256 unsigned char CR4A, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006257
Aaro Koskinen58839b02011-03-13 12:26:23 +02006258 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306259 tempbh &= 0x23;
6260 tempbl &= 0x23;
Aaro Koskinendc505562011-03-13 12:26:26 +02006261 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006262
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306263 if (tempbh & 0x20) {
6264 temp = (tempbl >> 4) & 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006265
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006266 /* CR B4[1] */
6267 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006268
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306269 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006270
Aaro Koskinen58839b02011-03-13 12:26:23 +02006271 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006272
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306273 temp = XG21GPIODataTransfer(temp);
6274 temp &= ~tempbh;
6275 temp |= tempbl;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006276 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006277}
6278
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306279void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
6280 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006281{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306282 unsigned char CR4A, temp;
6283 unsigned short tempbh0, tempbl0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006284
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306285 tempbh0 = tempbh;
6286 tempbl0 = tempbl;
6287 tempbh0 &= 0x20;
6288 tempbl0 &= 0x20;
6289 tempbh0 >>= 3;
6290 tempbl0 >>= 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006291
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306292 if (tempbh & 0x20) {
6293 temp = (tempbl >> 4) & 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006294
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006295 /* CR B4[1] */
6296 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006297
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306298 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006299 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006300
Aaro Koskinen58839b02011-03-13 12:26:23 +02006301 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306302 tempbh &= 0x03;
6303 tempbl &= 0x03;
6304 tempbh <<= 2;
6305 tempbl <<= 2; /* GPIOC,GPIOD */
Aaro Koskinendc505562011-03-13 12:26:26 +02006306 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006307 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006308}
6309
6310/* --------------------------------------------------------------------- */
Bill Pemberton80adad82010-06-17 13:10:51 -04006311unsigned short XGI_GetLVDSOEMTableIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006312{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306313 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006314
Aaro Koskinen58839b02011-03-13 12:26:23 +02006315 index = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306316 if (index < sizeof(XGI21_LCDCapList)
6317 / sizeof(struct XGI21_LVDSCapStruct))
6318 return index;
6319 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006320}
6321
6322/* --------------------------------------------------------------------- */
6323/* Function : XGI_XG21SetPanelDelay */
6324/* Input : */
6325/* Output : */
6326/* Description : */
6327/* I/P : bl : 1 ; T1 : the duration between CPL on and signal on */
6328/* : bl : 2 ; T2 : the duration signal on and Vdd on */
6329/* : bl : 3 ; T3 : the duration between CPL off and signal off */
6330/* : bl : 4 ; T4 : the duration signal off and Vdd off */
6331/* --------------------------------------------------------------------- */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306332void XGI_XG21SetPanelDelay(unsigned short tempbl,
6333 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006334{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306335 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006336
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306337 index = XGI_GetLVDSOEMTableIndex(pVBInfo);
6338 if (tempbl == 1)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006339 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006340
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306341 if (tempbl == 2)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006342 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006343
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306344 if (tempbl == 3)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006345 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S3);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006346
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306347 if (tempbl == 4)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006348 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S4);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006349}
6350
Bill Pemberton82d6eb52010-06-17 13:10:46 -04006351unsigned char XGI_XG21CheckLVDSMode(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306352 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006353{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306354 unsigned short xres, yres, colordepth, modeflag, resindex,
6355 lvdstableindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006356
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306357 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6358 if (ModeNo <= 0x13) {
6359 xres = pVBInfo->StResInfo[resindex].HTotal;
6360 yres = pVBInfo->StResInfo[resindex].VTotal;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006361 /* si+St_ResInfo */
6362 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306363 } else {
6364 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6365 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006366 /* si+St_ModeFlag */
6367 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306368 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006369
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306370 if (!(modeflag & Charx8Dot)) {
6371 xres /= 9;
6372 xres *= 8;
6373 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006374
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306375 if (ModeNo > 0x13) {
6376 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
6377 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006378
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306379 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6380 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006381
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306382 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006383
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306384 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
6385 if (xres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE))
6386 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04006387
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306388 if (yres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE))
6389 return 0;
6390
6391 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006392 if ((xres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6393 LVDSHDE)) ||
6394 (yres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6395 LVDSVDE))) {
6396 colordepth = XGI_GetColorDepth(ModeNo,
6397 ModeIdIndex,
6398 pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306399 if (colordepth > 2)
6400 return 0;
6401
6402 }
6403 }
6404 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006405}
6406
Bill Pemberton80adad82010-06-17 13:10:51 -04006407void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006408{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306409 unsigned char temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006410
Aaro Koskinen58839b02011-03-13 12:26:23 +02006411 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306412 temp = (temp & 1) << 6;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006413 /* SR06[6] 18bit Dither */
6414 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
6415 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
6416 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006417
6418}
6419
Bill Pemberton80adad82010-06-17 13:10:51 -04006420void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006421{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306422 unsigned char temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006423
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006424 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
6425 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306426 temp = (temp & 3) << 6;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006427 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
6428 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
6429 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
6430 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006431
6432}
6433
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006434static void XGI_SetXG21LVDSPara(unsigned short ModeNo,
6435 unsigned short ModeIdIndex,
6436 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006437{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306438 unsigned char temp, Miscdata;
6439 unsigned short xres, yres, modeflag, resindex, lvdstableindex;
6440 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
6441 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
6442 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006443
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306444 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006445
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006446 temp = (unsigned char) ((pVBInfo->XG21_LVDSCapList[lvdstableindex].
6447 LVDS_Capability &
6448 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306449 temp &= LCDPolarity;
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006450 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006451
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006452 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006453
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006454 temp = (unsigned char) (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6455 LVDS_Capability & LCDPolarity);
6456 /* SR35[7] FP VSync polarity */
6457 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
6458 /* SR30[5] FP HSync polarity */
6459 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006460
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306461 XGI_SetXG21FPBits(pVBInfo);
6462 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6463 if (ModeNo <= 0x13) {
6464 xres = pVBInfo->StResInfo[resindex].HTotal;
6465 yres = pVBInfo->StResInfo[resindex].VTotal;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006466 /* si+St_ResInfo */
6467 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306468 } else {
6469 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6470 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006471 /* si+St_ModeFlag */
6472 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306473 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006474
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306475 if (!(modeflag & Charx8Dot))
6476 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006477
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306478 LVDSHT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006479
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306480 LVDSHBS = xres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE
6481 - xres) / 2;
6482 if ((ModeNo <= 0x13) && (modeflag & HalfDCLK))
6483 LVDSHBS -= xres / 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006484
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306485 if (LVDSHBS > LVDSHT)
6486 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006487
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306488 LVDSHRS = LVDSHBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHFP;
6489 if (LVDSHRS > LVDSHT)
6490 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006491
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306492 LVDSHRE = LVDSHRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHSYNC;
6493 if (LVDSHRE > LVDSHT)
6494 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006495
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306496 LVDSHBE = LVDSHBS + LVDSHT
6497 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006498
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306499 LVDSVT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006500
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306501 LVDSVBS = yres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE
6502 - yres) / 2;
6503 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6504 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006505
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306506 if (LVDSVBS > LVDSVT)
6507 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006508
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306509 LVDSVRS = LVDSVBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVFP;
6510 if (LVDSVRS > LVDSVT)
6511 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006512
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306513 LVDSVRE = LVDSVRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVSYNC;
6514 if (LVDSVRE > LVDSVT)
6515 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006516
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306517 LVDSVBE = LVDSVBS + LVDSVT
6518 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006519
Aaro Koskinen58839b02011-03-13 12:26:23 +02006520 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006521 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006522
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306523 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006524 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006525
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306526 /* HT SR0B[1:0] CR00 */
6527 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006528 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006529 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006530
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306531 /* HBS SR0B[5:4] CR02 */
6532 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006533 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006534 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006535
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306536 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
6537 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006538 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
6539 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
6540 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006541
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306542 /* HRS SR0B[7:6] CR04 */
6543 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006544 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006545 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006546
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306547 /* Panel HRS SR2F[1:0] SR2E[7:0] */
6548 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006549 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006550 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006551
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306552 /* HRE SR0C[2] CR05[4:0] */
6553 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006554 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
6555 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006556
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306557 /* Panel HRE SR2F[7:2] */
6558 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006559 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006560
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306561 /* VT SR0A[0] CR07[5][0] CR06 */
6562 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006563 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
6564 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
6565 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006566 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006567
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306568 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
6569 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006570 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
6571 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
6572 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006573 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006574
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306575 /* VBE SR0A[4] CR16 */
6576 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006577 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006578 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006579
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306580 /* VRS SR0A[3] CR7[7][2] CR10 */
6581 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006582 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
6583 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
6584 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006585 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006586
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306587 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006588 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03, (value & 0x600) >> 9);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006589 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006590 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006591
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306592 /* VRE SR0A[5] CR11[3:0] */
6593 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006594 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
6595 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006596
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306597 /* Panel VRE SR3F[7:2] *//* SR3F[7] has to be 0, h/w bug */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006598 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006599
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306600 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006601
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006602 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006603 xgifb_reg_set(pVBInfo->P3c4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006604 0x2B,
6605 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6606 VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006607 xgifb_reg_set(pVBInfo->P3c4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006608 0x2C,
6609 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6610 VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306611 value += 0x10;
6612 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006613
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306614 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006615 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006616 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006617 /* set data, panning = 0, shift left 1 dot*/
6618 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006619
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006620 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006621 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306622
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006623 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306624 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006625
6626}
6627
6628/* no shadow case */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006629static void XGI_SetXG27LVDSPara(unsigned short ModeNo,
6630 unsigned short ModeIdIndex,
6631 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006632{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306633 unsigned char temp, Miscdata;
6634 unsigned short xres, yres, modeflag, resindex, lvdstableindex;
6635 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
6636 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
6637 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006638
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306639 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006640 temp = (unsigned char) ((pVBInfo->XG21_LVDSCapList[lvdstableindex].
6641 LVDS_Capability &
6642 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306643 temp &= LCDPolarity;
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006644 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006645
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006646 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006647
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006648 temp = (unsigned char) (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6649 LVDS_Capability & LCDPolarity);
6650 /* SR35[7] FP VSync polarity */
6651 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
6652 /* SR30[5] FP HSync polarity */
6653 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006654
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306655 XGI_SetXG27FPBits(pVBInfo);
6656 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6657 if (ModeNo <= 0x13) {
6658 xres = pVBInfo->StResInfo[resindex].HTotal;
6659 yres = pVBInfo->StResInfo[resindex].VTotal;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006660 /* si+St_ResInfo */
6661 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306662 } else {
6663 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6664 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006665 /* si+St_ModeFlag */
6666 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306667 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006668
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306669 if (!(modeflag & Charx8Dot))
6670 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006671
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306672 LVDSHT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006673
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306674 LVDSHBS = xres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE
6675 - xres) / 2;
6676 if ((ModeNo <= 0x13) && (modeflag & HalfDCLK))
6677 LVDSHBS -= xres / 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006678
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306679 if (LVDSHBS > LVDSHT)
6680 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006681
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306682 LVDSHRS = LVDSHBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHFP;
6683 if (LVDSHRS > LVDSHT)
6684 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006685
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306686 LVDSHRE = LVDSHRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHSYNC;
6687 if (LVDSHRE > LVDSHT)
6688 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006689
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306690 LVDSHBE = LVDSHBS + LVDSHT
6691 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006692
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306693 LVDSVT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006694
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306695 LVDSVBS = yres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE
6696 - yres) / 2;
6697 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6698 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006699
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306700 if (LVDSVBS > LVDSVT)
6701 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006702
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306703 LVDSVRS = LVDSVBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVFP;
6704 if (LVDSVRS > LVDSVT)
6705 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006706
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006707 LVDSVRE = LVDSVRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].
6708 LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306709 if (LVDSVRE > LVDSVT)
6710 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006711
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306712 LVDSVBE = LVDSVBS + LVDSVT
6713 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006714
Aaro Koskinen58839b02011-03-13 12:26:23 +02006715 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006716 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006717
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306718 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006719 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006720
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306721 /* HT SR0B[1:0] CR00 */
6722 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006723 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006724 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006725
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306726 /* HBS SR0B[5:4] CR02 */
6727 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006728 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006729 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006730
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306731 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
6732 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006733 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
6734 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
6735 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006736
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306737 /* HRS SR0B[7:6] CR04 */
6738 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006739 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006740 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006741
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306742 /* Panel HRS SR2F[1:0] SR2E[7:0] */
6743 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006744 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006745 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006746
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306747 /* HRE SR0C[2] CR05[4:0] */
6748 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006749 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
6750 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006751
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306752 /* Panel HRE SR2F[7:2] */
6753 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006754 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006755
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306756 /* VT SR0A[0] CR07[5][0] CR06 */
6757 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006758 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
6759 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
6760 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006761 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006762
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306763 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
6764 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006765 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
6766 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
6767 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006768 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006769
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306770 /* VBE SR0A[4] CR16 */
6771 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006772 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006773 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006774
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306775 /* VRS SR0A[3] CR7[7][2] CR10 */
6776 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006777 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
6778 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
6779 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006780 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006781
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306782 /* Panel VRS SR35[2:0] SR34[7:0] */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006783 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, (value & 0x700) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006784 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006785
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306786 /* VRE SR0A[5] CR11[3:0] */
6787 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006788 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
6789 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006790
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306791 /* Panel VRE SR3F[7:2] */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006792 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, (value << 2) & 0xFC);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006793
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306794 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006795
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006796 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006797 xgifb_reg_set(pVBInfo->P3c4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006798 0x2B,
6799 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6800 VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006801 xgifb_reg_set(pVBInfo->P3c4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006802 0x2C,
6803 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6804 VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306805 value += 0x10;
6806 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006807
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306808 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006809 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006810 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006811 /* set data, panning = 0, shift left 1 dot*/
6812 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006813
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006814 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006815 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306816
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006817 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306818 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006819
6820}
6821
6822/* --------------------------------------------------------------------- */
6823/* Function : XGI_IsLCDON */
6824/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04006825/* Output : 0 : Skip PSC Control */
6826/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006827/* Description : */
6828/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006829static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006830{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306831 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006832
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306833 tempax = pVBInfo->VBInfo;
6834 if (tempax & SetCRT2ToDualEdge)
6835 return 0;
6836 else if (tempax & (DisableCRT2Display | SwitchToCRT2 | SetSimuScanMode))
6837 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006838
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306839 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006840}
6841
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006842/* --------------------------------------------------------------------- */
6843/* Function : XGI_DisableChISLCD */
6844/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04006845/* Output : 0 -> Not LCD Mode */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006846/* Description : */
6847/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006848static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006849{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306850 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006851
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306852 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02006853 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006854
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306855 if (tempbx & (EnableChA | DisableChA)) {
6856 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6857 return 0;
6858 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006859
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306860 if (!(tempbx & (EnableChB | DisableChB)))
6861 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006862
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306863 if (tempah & 0x01) /* Chk LCDB Mode */
6864 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006865
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306866 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006867}
6868
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006869/* --------------------------------------------------------------------- */
6870/* Function : XGI_EnableChISLCD */
6871/* Input : */
6872/* Output : 0 -> Not LCD mode */
6873/* Description : */
6874/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006875static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006876{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306877 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006878
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306879 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02006880 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006881
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306882 if (tempbx & (EnableChA | DisableChA)) {
6883 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6884 return 0;
6885 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006886
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306887 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04006888 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006889
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306890 if (tempah & 0x01) /* Chk LCDB Mode */
6891 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006892
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306893 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006894}
6895
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306896void XGI_DisableBridge(struct xgi_hw_device_info *HwDeviceExtension,
6897 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006898{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02006899 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006900
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306901 if (pVBInfo->SetFlag == Win9xDOSMode)
6902 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006903
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306904 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6905 | VB_XGI302LV | VB_XGI301C)) {
6906 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006907 if (!(pVBInfo->VBInfo &
6908 (DisableCRT2Display | SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306909 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6910 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6911 tempah = 0x7F; /* Disable Channel A */
6912 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006913 /* Disable Channel B */
6914 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006915
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306916 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006917 /* force to disable Cahnnel */
6918 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006919
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306920 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006921 /* Force to disable Channel B */
6922 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306923 }
6924 }
6925 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006926
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006927 /* disable part4_1f */
6928 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006929
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306930 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6931 if (((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
6932 || (XGI_DisableChISLCD(pVBInfo))
6933 || (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006934 /* LVDS Driver power down */
6935 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306936 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006937
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306938 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6939 & (DisableCRT2Display | SetCRT2ToLCDA
6940 | SetSimuScanMode))) {
6941 if (pVBInfo->SetFlag & GatingCRT)
6942 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
6943 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6944 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006945
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306946 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6947 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6948 & SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006949 /* Power down */
6950 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306951 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006952
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006953 /* disable TV as primary VGA swap */
6954 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006955
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306956 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02006957 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006958
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006959 if ((pVBInfo->SetFlag & DisableChB) ||
6960 (pVBInfo->VBInfo &
6961 (DisableCRT2Display | SetSimuScanMode)) ||
6962 ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) &&
6963 (pVBInfo->VBInfo &
6964 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
6965 /* BScreenOff=1 */
6966 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006967
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006968 if ((pVBInfo->SetFlag & DisableChB) ||
6969 (pVBInfo->VBInfo &
6970 (DisableCRT2Display | SetSimuScanMode)) ||
6971 (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) ||
6972 (pVBInfo->VBInfo &
6973 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
6974 /* save Part1 index 0 */
6975 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
6976 /* BTDAC = 1, avoid VB reset */
6977 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
6978 /* disable CRT2 */
6979 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6980 /* restore Part1 index 0 */
6981 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306982 }
6983 } else { /* {301} */
6984 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006985 /* BScreenOff=1 */
6986 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
6987 /* Disable CRT2 */
6988 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6989 /* Disable TV asPrimary VGA swap */
6990 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306991 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006992
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306993 if (pVBInfo->VBInfo & (DisableCRT2Display | SetCRT2ToLCDA
6994 | SetSimuScanMode))
6995 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6996 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006997}
6998
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006999/* --------------------------------------------------------------------- */
7000/* Function : XGI_GetTVPtrIndex */
7001/* Input : */
7002/* Output : */
7003/* Description : bx 0 : ExtNTSC */
7004/* 1 : StNTSC */
7005/* 2 : ExtPAL */
7006/* 3 : StPAL */
7007/* 4 : ExtHiTV */
7008/* 5 : StHiTV */
7009/* 6 : Ext525i */
7010/* 7 : St525i */
7011/* 8 : Ext525p */
7012/* 9 : St525p */
7013/* A : Ext750p */
7014/* B : St750p */
7015/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02007016static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007017{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307018 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007019
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307020 if (pVBInfo->TVInfo & SetPALTV)
7021 tempbx = 2;
7022 if (pVBInfo->TVInfo & SetYPbPrMode1080i)
7023 tempbx = 4;
7024 if (pVBInfo->TVInfo & SetYPbPrMode525i)
7025 tempbx = 6;
7026 if (pVBInfo->TVInfo & SetYPbPrMode525p)
7027 tempbx = 8;
7028 if (pVBInfo->TVInfo & SetYPbPrMode750p)
7029 tempbx = 10;
7030 if (pVBInfo->TVInfo & TVSimuMode)
7031 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007032
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307033 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007034}
7035
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007036/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007037/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007038/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007039/* Output : bx 0 : NTSC */
7040/* 1 : PAL */
7041/* 2 : PALM */
7042/* 3 : PALN */
7043/* 4 : NTSC1024x768 */
7044/* 5 : PAL-M 1024x768 */
7045/* 6-7: reserved */
7046/* cl 0 : YFilter1 */
7047/* 1 : YFilter2 */
7048/* ch 0 : 301A */
7049/* 1 : 301B/302B/301LV/302LV */
7050/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007051/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007052static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
7053 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007054{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007055 *tempbx = 0;
7056 *tempcl = 0;
7057 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007058
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007059 if (pVBInfo->TVInfo & SetPALTV)
7060 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007061
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007062 if (pVBInfo->TVInfo & SetPALMTV)
7063 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007064
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007065 if (pVBInfo->TVInfo & SetPALNTV)
7066 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007067
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007068 if (pVBInfo->TVInfo & NTSC1024x768) {
7069 *tempbx = 4;
7070 if (pVBInfo->TVInfo & SetPALMTV)
7071 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307072 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007073
7074 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7075 | VB_XGI302LV | VB_XGI301C)) {
7076 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
7077 & TVSimuMode)) {
7078 *tempbx += 8;
7079 *tempcl += 1;
7080 }
7081 }
7082
7083 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7084 | VB_XGI302LV | VB_XGI301C))
7085 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007086}
7087
Aaro Koskinen063b9c42011-03-08 22:16:13 +02007088static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007089{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307090 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007091
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307092 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007093
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307094 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7095 | VB_XGI302LV | VB_XGI301C)) {
7096 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA
7097 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
7098 tempbl = 0;
7099 tempbh = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307101 index = XGI_GetTVPtrIndex(pVBInfo); /* Get TV Delay */
7102 tempbl = pVBInfo->XGI_TVDelayList[index];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007103
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307104 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
7105 | VB_XGI301LV | VB_XGI302LV
7106 | VB_XGI301C))
7107 tempbl = pVBInfo->XGI_TVDelayList2[index];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007108
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307109 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7110 tempbl = tempbl >> 4;
7111 /*
7112 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
7113 tempbl = CRT2Delay1; // Get CRT2 Delay
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007114 if (pVBInfo->VBType &
7115 (VB_XGI301B |
7116 VB_XGI302B |
7117 VB_XGI301LV |
7118 VB_XGI302LV |
7119 VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307120 tempbl = CRT2Delay2;
7121 */
7122 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007123 /* Get LCD Delay */
7124 index = XGI_GetLCDCapPtr(pVBInfo);
7125 tempbh = pVBInfo->LCDCapList[index].
7126 LCD_DelayCompensation;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007127
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307128 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
7129 tempbl = tempbh;
7130 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007131
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307132 tempbl &= 0x0F;
7133 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02007134 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007135
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307136 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
7137 | SetCRT2ToTV)) { /* Channel B */
7138 tempah &= 0xF0;
7139 tempah |= tempbl;
7140 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007141
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307142 if (pVBInfo->VBInfo & SetCRT2ToLCDA) { /* Channel A */
7143 tempah &= 0x0F;
7144 tempah |= tempbh;
7145 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02007146 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307147 }
7148 } else if (pVBInfo->IF_DEF_LVDS == 1) {
7149 tempbl = 0;
7150 tempbh = 0;
7151 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007152 /* / Get LCD Delay */
7153 tempah = pVBInfo->LCDCapList[
7154 XGI_GetLCDCapPtr(pVBInfo)].
7155 LCD_DelayCompensation;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307156 tempah &= 0x0f;
7157 tempah = tempah << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007158 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307159 tempah);
7160 }
7161 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007162}
7163
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007164static void XGI_SetLCDCap_A(unsigned short tempcx,
7165 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007166{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307167 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007168
Aaro Koskinen58839b02011-03-13 12:26:23 +02007169 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007170
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307171 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007172 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007173 /* Enable Dither */
7174 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007175 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307176 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007177 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307178 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007179 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307180 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007181
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307182 /*
7183 if (tempcx & EnableLCD24bpp) { // 24bits
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007184 xgifb_reg_and_or(pVBInfo->Part1Port,
7185 0x19,
7186 0x0F,
7187 (unsigned short)(0x30 | (tempcx&0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007188 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307189 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007190 xgifb_reg_and_or(pVBInfo->Part1Port,
7191 0x19,
7192 0x0F,
7193 // Enable Dither
7194 (unsigned short)(0x20 | (tempcx&0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007195 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307196 }
7197 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007198}
7199
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007200/* --------------------------------------------------------------------- */
7201/* Function : XGI_SetLCDCap_B */
7202/* Input : cx -> LCD Capability */
7203/* Output : */
7204/* Description : */
7205/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007206static void XGI_SetLCDCap_B(unsigned short tempcx,
7207 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007208{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307209 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007210 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307211 (unsigned short) (((tempcx & 0x00ff) >> 6)
7212 | 0x0c));
7213 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007214 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307215 (unsigned short) (((tempcx & 0x00ff) >> 6)
7216 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007217}
7218
Aaro Koskinen063b9c42011-03-08 22:16:13 +02007219static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007220{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307221 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007222
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307223 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007224
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007225 /* disable down spectrum D[4] */
7226 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307227 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02007228 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307229 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007230
Aaro Koskinen8104e322011-03-13 12:26:22 +02007231 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307232 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007233 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307234 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007235 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307236 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007237 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307238 pVBInfo->LCDCapList[index].Spectrum_34);
7239 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02007240 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007241}
7242
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007243static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
7244{
7245 unsigned short tempcx;
7246
7247 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
7248
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007249 if (pVBInfo->VBType &
7250 (VB_XGI301B |
7251 VB_XGI302B |
7252 VB_XGI301LV |
7253 VB_XGI302LV |
7254 VB_XGI301C)) { /* 301LV/302LV only */
7255 if (pVBInfo->VBType &
7256 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007257 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02007258 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007259 (unsigned char) (tempcx & 0x1F));
7260 }
7261 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007262 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007263 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
7264 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
7265 | EnablePLLSPLOW)) >> 8));
7266 }
7267
7268 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7269 | VB_XGI302LV | VB_XGI301C)) {
7270 if (pVBInfo->VBInfo & SetCRT2ToLCD)
7271 XGI_SetLCDCap_B(tempcx, pVBInfo);
7272 else if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7273 XGI_SetLCDCap_A(tempcx, pVBInfo);
7274
7275 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7276 if (tempcx & EnableSpectrum)
7277 SetSpectrum(pVBInfo);
7278 }
7279 } else {
7280 /* LVDS,CH7017 */
7281 XGI_SetLCDCap_A(tempcx, pVBInfo);
7282 }
7283}
7284
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007285/* --------------------------------------------------------------------- */
7286/* Function : XGI_SetAntiFlicker */
7287/* Input : */
7288/* Output : */
7289/* Description : Set TV Customized Param. */
7290/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007291static void XGI_SetAntiFlicker(unsigned short ModeNo,
7292 unsigned short ModeIdIndex,
7293 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007294{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307295 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007296
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307297 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007298
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307299 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
7300 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007301
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307302 tempbx = XGI_GetTVPtrIndex(pVBInfo);
7303 tempbx &= 0xFE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007304
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307305 if (ModeNo <= 0x13)
7306 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
7307 else
7308 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007309
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307310 tempbx += index;
7311 tempah = TVAntiFlickList[tempbx];
7312 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007313
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007314 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007315}
7316
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007317static void XGI_SetEdgeEnhance(unsigned short ModeNo,
7318 unsigned short ModeIdIndex,
7319 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007320{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307321 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007322
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307323 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007324
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307325 tempbx = XGI_GetTVPtrIndex(pVBInfo);
7326 tempbx &= 0xFE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007327
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307328 if (ModeNo <= 0x13)
7329 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
7330 else
7331 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007332
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307333 tempbx += index;
7334 tempah = TVEdgeList[tempbx];
7335 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007336
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007337 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007338}
7339
Aaro Koskinen063b9c42011-03-08 22:16:13 +02007340static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007341{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307342 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007343
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307344 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007345
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307346 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007347
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307348 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
7349 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007350
Aaro Koskinen8104e322011-03-13 12:26:22 +02007351 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307352 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02007353 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307354 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02007355 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307356 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02007357 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307358 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007359}
7360
Aaro Koskinen063b9c42011-03-08 22:16:13 +02007361static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307362 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007363{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307364 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007365
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307366 unsigned char tempcl, tempch, tempal, *filterPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007367
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307368 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007369
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307370 switch (tempbx) {
7371 case 0x00:
7372 case 0x04:
7373 filterPtr = NTSCYFilter1;
7374 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007375
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307376 case 0x01:
7377 filterPtr = PALYFilter1;
7378 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007379
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307380 case 0x02:
7381 case 0x05:
7382 case 0x0D:
7383 filterPtr = PALMYFilter1;
7384 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007385
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307386 case 0x03:
7387 filterPtr = PALNYFilter1;
7388 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007389
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307390 case 0x08:
7391 case 0x0C:
7392 filterPtr = NTSCYFilter2;
7393 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007394
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307395 case 0x0A:
7396 filterPtr = PALMYFilter2;
7397 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007398
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307399 case 0x0B:
7400 filterPtr = PALNYFilter2;
7401 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007402
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307403 case 0x09:
7404 filterPtr = PALYFilter2;
7405 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007406
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307407 default:
7408 return;
7409 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007410
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307411 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007412 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
7413 VB_StTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307414 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007415 tempal = pVBInfo->EModeIDTable[ModeIdIndex].
7416 VB_ExtTVYFilterIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007417
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307418 if (tempcl == 0)
7419 index = tempal * 4;
7420 else
7421 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007422
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307423 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02007424 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
7425 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
7426 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
7427 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307428 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02007429 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
7430 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
7431 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
7432 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307433 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007434
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307435 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7436 | VB_XGI302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02007437 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
7438 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
7439 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307440 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007441}
7442
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007443/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007444/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007445/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007446/* Output : */
7447/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007448/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007449static void XGI_OEM310Setting(unsigned short ModeNo,
7450 unsigned short ModeIdIndex,
7451 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007452{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007453 if (pVBInfo->SetFlag & Win9xDOSMode)
7454 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007455
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007456 /* GetPart1IO(); */
7457 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007458
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007459 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
7460 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007461
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007462 if (pVBInfo->VBInfo & SetCRT2ToTV) {
7463 /* GetPart2IO() */
7464 XGI_SetPhaseIncr(pVBInfo);
7465 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
7466 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007467
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007468 if (pVBInfo->VBType & VB_XGI301)
7469 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307470 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007471}
7472
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007473/* --------------------------------------------------------------------- */
7474/* Function : XGI_SetCRT2ModeRegs */
7475/* Input : */
7476/* Output : */
7477/* Description : Origin code for crt2group */
7478/* --------------------------------------------------------------------- */
Bill Pemberton82d6eb52010-06-17 13:10:46 -04007479void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307480 struct xgi_hw_device_info *HwDeviceExtension,
7481 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007482{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307483 unsigned short tempbl;
7484 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007485
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307486 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007487
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007488 /* // fix write part1 index 0 BTDRAM bit Bug
7489 * xgifb_reg_set(pVBInfo->Part1Port, 0x03, 0x00); */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307490 tempah = 0;
7491 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007492 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307493 tempah &= ~0x10; /* BTRAMDAC */
7494 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007495
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307496 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
7497 | SetCRT2ToLCD)) {
7498 tempah = 0x40; /* BTDRAM */
7499 if (ModeNo > 0x13) {
7500 tempcl = pVBInfo->ModeType;
7501 tempcl -= ModeVGA;
7502 if (tempcl >= 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007503 /* BT Color */
7504 tempah = (0x008 >> tempcl);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307505 if (tempah == 0)
7506 tempah = 1;
7507 tempah |= 0x040;
7508 }
7509 }
7510 if (pVBInfo->VBInfo & SetInSlaveMode)
7511 tempah ^= 0x50; /* BTDAC */
7512 }
7513 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007514
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307515 /* 0210 shampoo
7516 if (pVBInfo->VBInfo & DisableCRT2Display) {
7517 tempah = 0;
7518 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007519
Aaro Koskinen8104e322011-03-13 12:26:22 +02007520 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307521 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)) {
7522 tempcl = pVBInfo->ModeType;
7523 if (ModeNo > 0x13) {
7524 tempcl -= ModeVGA;
7525 if ((tempcl > 0) || (tempcl == 0)) {
7526 tempah=(0x008>>tempcl) ;
7527 if (tempah == 0)
7528 tempah = 1;
7529 tempah |= 0x040;
7530 }
7531 } else {
7532 tempah = 0x040;
7533 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007534
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307535 if (pVBInfo->VBInfo & SetInSlaveMode) {
7536 tempah = (tempah ^ 0x050);
7537 }
7538 }
7539 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007540
Aaro Koskinen8104e322011-03-13 12:26:22 +02007541 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307542 tempah = 0x08;
7543 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007544
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307545 if (pVBInfo->VBInfo & DisableCRT2Display) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007546 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307547 } else {
7548 tempah = 0x00;
7549 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007550
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307551 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
7552 | SetCRT2ToLCD | SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007553 if ((pVBInfo->VBInfo & SetCRT2ToLCDA) &&
7554 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307555 tempbl &= 0xf7;
7556 tempah |= 0x01;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007557 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307558 tempbl, tempah);
7559 } else {
7560 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7561 tempbl &= 0xf7;
7562 tempah |= 0x01;
7563 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007564
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007565 if (pVBInfo->VBInfo &
7566 (SetCRT2ToRAMDAC |
7567 SetCRT2ToTV |
7568 SetCRT2ToLCD)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307569 tempbl &= 0xf8;
7570 tempah = 0x01;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007571
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307572 if (!(pVBInfo->VBInfo & SetInSlaveMode))
7573 tempah |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007574
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007575 if (!(pVBInfo->VBInfo &
7576 SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307577 tempah = tempah ^ 0x05;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007578 if (!(pVBInfo->VBInfo &
7579 SetCRT2ToLCD))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307580 tempah = tempah ^ 0x01;
7581 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007582
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007583 if (!(pVBInfo->VBInfo &
7584 SetCRT2ToDualEdge))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307585 tempah |= 0x08;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007586 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307587 0x2e, tempbl, tempah);
7588 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007589 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307590 0x2e, tempbl, tempah);
7591 }
7592 }
7593 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007594 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307595 tempah);
7596 }
7597 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007598
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307599 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
7600 | SetCRT2ToLCDA)) {
7601 tempah &= (~0x08);
7602 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
7603 & SetInSlaveMode))) {
7604 tempah |= 0x010;
7605 }
7606 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007607
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307608 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007609 /* if (!(pVBInfo->TVInfo &
7610 (SetYPbPrMode525p | SetYPbPrMode750p))) { */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307611 tempah |= 0x020;
7612 if (ModeNo > 0x13) {
7613 if (pVBInfo->VBInfo & DriverMode)
7614 tempah = tempah ^ 0x20;
7615 }
7616 /* } */
7617 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007618
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007619 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307620 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007621
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307622 if (pVBInfo->LCDInfo & SetLCDDualLink)
7623 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007624
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307625 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007626 /* if ((!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) &&
7627 (!(pVBInfo->TVInfo &
7628 (SetYPbPrMode525p | SetYPbPrMode750p)))) { */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307629 if (pVBInfo->TVInfo & RPLLDIV2XO)
7630 tempah |= 0x40;
7631 /* } */
7632 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007633
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307634 if ((pVBInfo->LCDResInfo == Panel1280x1024)
7635 || (pVBInfo->LCDResInfo == Panel1280x1024x75))
7636 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007637
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307638 if (pVBInfo->LCDResInfo == Panel1280x960)
7639 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007640
Aaro Koskinen8104e322011-03-13 12:26:22 +02007641 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307642 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007643
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307644 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7645 | VB_XGI302LV | VB_XGI301C)) {
7646 tempah = 0;
7647 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007648
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307649 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7650 tempbl = 0xff;
7651 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7652 tempah |= 0x04; /* shampoo 0129 */
7653 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007654
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007655 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307656 tempah = 0x00;
7657 tempbl = 0xcf;
7658 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7659 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7660 tempah |= 0x30;
7661 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007662
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007663 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307664 tempah = 0;
7665 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007666
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307667 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7668 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7669 tempah |= 0xc0;
7670 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007671 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307672 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007673
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307674 tempah = 0;
7675 tempbl = 0x7f;
7676 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) {
7677 tempbl = 0xff;
7678 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
7679 tempah |= 0x80;
7680 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007681
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007682 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007683
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307684 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7685 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02007686 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
7687 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307688 }
7689 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007690}
7691
Aaro Koskinen063b9c42011-03-08 22:16:13 +02007692static void XGI_CloseCRTC(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307693 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007694{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307695 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007696
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307697 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007698
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307699 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7700 tempbx = 0x08A0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007701
7702}
7703
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307704void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
7705 struct vb_device_info *pVBInfo)
7706{
7707
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007708 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007709
7710}
7711
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307712void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
7713 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007714{
7715
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007716 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007717
7718}
7719
Bill Pemberton80adad82010-06-17 13:10:51 -04007720unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007721{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307722 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007723
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307724 if (pVBInfo->IF_DEF_LVDS == 1) {
7725 return 1;
7726 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007727 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307728 if ((flag == 1) || (flag == 2))
7729 return 1; /* 301b */
7730 else
7731 return 0;
7732 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007733}
7734
Bill Pemberton80adad82010-06-17 13:10:51 -04007735void XGI_LongWait(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007736{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307737 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007738
Aaro Koskinen58839b02011-03-13 12:26:23 +02007739 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007740
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307741 if (!(i & 0xC0)) {
7742 for (i = 0; i < 0xFFFF; i++) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007743 if (!(inb(pVBInfo->P3da) & 0x08))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307744 break;
7745 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007746
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307747 for (i = 0; i < 0xFFFF; i++) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007748 if ((inb(pVBInfo->P3da) & 0x08))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307749 break;
7750 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007751 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007752}
7753
Aaro Koskinen063b9c42011-03-08 22:16:13 +02007754static void XGI_VBLongWait(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007755{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307756 unsigned short tempal, temp, i, j;
7757 return;
7758 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
7759 temp = 0;
7760 for (i = 0; i < 3; i++) {
7761 for (j = 0; j < 100; j++) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007762 tempal = inb(pVBInfo->P3da);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307763 if (temp & 0x01) { /* VBWaitMode2 */
7764 if ((tempal & 0x08))
7765 continue;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007766
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307767 if (!(tempal & 0x08))
7768 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007769
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307770 } else { /* VBWaitMode1 */
7771 if (!(tempal & 0x08))
7772 continue;
7773
7774 if ((tempal & 0x08))
7775 break;
7776 }
7777 }
7778 temp = temp ^ 0x01;
7779 }
7780 } else {
7781 XGI_LongWait(pVBInfo);
7782 }
7783 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007784}
7785
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007786unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
7787 unsigned short ModeNo, unsigned short ModeIdIndex,
7788 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007789{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007790 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
7791 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
7792 0x01, 0x01 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007793
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007794 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007795
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007796 if (ModeNo <= 0x13)
7797 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
7798 else
7799 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
7800
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007801 if (ModeNo < 0x14)
7802 return 0xFFFF;
7803
Aaro Koskinen58839b02011-03-13 12:26:23 +02007804 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007805 index = index >> pVBInfo->SelectCRT2Rate;
7806 index &= 0x0F;
7807
7808 if (pVBInfo->LCDInfo & LCDNonExpanding)
7809 index = 0;
7810
7811 if (index > 0)
7812 index--;
7813
7814 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007815 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
7816 if (pVBInfo->IF_DEF_LVDS == 0) {
7817 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
7818 | VB_XGI301LV | VB_XGI302LV
7819 | VB_XGI301C))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007820 /* 301b */
7821 temp = LCDARefreshIndex[
7822 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007823 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007824 temp = LCDRefreshIndex[
7825 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007826
7827 if (index > temp)
7828 index = temp;
7829 } else {
7830 index = 0;
7831 }
7832 }
7833 }
7834
7835 RefreshRateTableIndex = pVBInfo->EModeIDTable[ModeIdIndex].REFindex;
7836 ModeNo = pVBInfo->RefIndex[RefreshRateTableIndex].ModeID;
7837 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
7838 /*
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007839 if (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag &
7840 XG2xNotSupport) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007841 index++;
7842 }
7843 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007844 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 800) &&
7845 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007846 index++;
7847 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007848 /* Alan 10/19/2007;
7849 * do the similar adjustment like XGISearchCRT1Rate() */
7850 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1024) &&
7851 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007852 index++;
7853 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007854 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1280) &&
7855 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007856 index++;
7857 }
7858 }
7859
7860 i = 0;
7861 do {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007862 if (pVBInfo->RefIndex[RefreshRateTableIndex + i].
7863 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007864 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007865 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i].
7866 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007867 temp &= ModeInfoFlag;
7868 if (temp < pVBInfo->ModeType)
7869 break;
7870 i++;
7871 index--;
7872
7873 } while (index != 0xFFFF);
7874 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
7875 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007876 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i - 1].
7877 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007878 if (temp & InterlaceMode)
7879 i++;
7880 }
7881 }
7882 i--;
7883 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
7884 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
7885 RefreshRateTableIndex, &i, pVBInfo);
7886 }
7887 return RefreshRateTableIndex + i; /* return (0x01 | (temp1<<1)); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007888}
7889
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007890static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307891 struct xgi_hw_device_info *HwDeviceExtension,
7892 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007893{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007894 unsigned short RefreshRateTableIndex;
7895 /* unsigned short temp ; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007896
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007897 /* pVBInfo->SelectCRT2Rate = 0; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007898
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007899 pVBInfo->SetFlag |= ProgrammingCRT2;
7900 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7901 ModeIdIndex, pVBInfo);
7902 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
7903 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7904 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7905 HwDeviceExtension, pVBInfo);
7906 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7907 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007908}
7909
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007910unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
7911 struct xgi_hw_device_info *HwDeviceExtension,
7912 struct vb_device_info *pVBInfo)
7913{
7914 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
7915
7916 tempbx = pVBInfo->VBInfo;
7917 pVBInfo->SetFlag |= ProgrammingCRT2;
7918 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7919 pVBInfo->SelectCRT2Rate = 4;
7920 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7921 ModeIdIndex, pVBInfo);
7922 XGI_SaveCRT2Info(ModeNo, pVBInfo);
7923 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
7924 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7925 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7926 RefreshRateTableIndex, pVBInfo);
7927 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7928 RefreshRateTableIndex, pVBInfo);
7929 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7930 RefreshRateTableIndex, pVBInfo);
7931 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7932 HwDeviceExtension, pVBInfo);
7933 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7934 RefreshRateTableIndex, pVBInfo);
7935 XGI_SetTap4Regs(pVBInfo);
7936 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
7937 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7938 HwDeviceExtension, pVBInfo);
7939 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7940 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
7941 XGI_AutoThreshold(pVBInfo);
7942 return 1;
7943}
7944
7945void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
7946{
7947 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
7948 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
7949 0x05, 0x00 };
7950
7951 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
7952
7953 unsigned char CR17, CR63, SR31;
7954 unsigned short temp;
7955 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
7956
7957 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02007958 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007959
7960 /* [2004/05/06] Vicent to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02007961 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02007962 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007963 pVBInfo->P3d4, 0x53) | 0x02));
7964
Aaro Koskinen58839b02011-03-13 12:26:23 +02007965 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
7966 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
7967 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007968
Aaro Koskinen8104e322011-03-13 12:26:22 +02007969 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
7970 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007971
Aaro Koskinen58839b02011-03-13 12:26:23 +02007972 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007973 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007974
Aaro Koskinen58839b02011-03-13 12:26:23 +02007975 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007976 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007977
Aaro Koskinen58839b02011-03-13 12:26:23 +02007978 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007979 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Aaro Koskinen58839b02011-03-13 12:26:23 +02007980 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007981 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007982
Aaro Koskinen8104e322011-03-13 12:26:22 +02007983 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007984
7985 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007986 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007987
7988 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007989 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007990 CRTCData[i]);
7991
7992 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007993 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007994 CRTCData[i]);
7995
7996 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007997 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007998 CRTCData[i]);
7999
Aaro Koskinen8104e322011-03-13 12:26:22 +02008000 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008001 & 0xE0));
8002
Aaro Koskinen8104e322011-03-13 12:26:22 +02008003 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
8004 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
8005 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008006
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02008007 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008008
8009 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02008010 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
8011 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
8012 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008013 }
8014
8015 XGI_VBLongWait(pVBInfo);
8016 XGI_VBLongWait(pVBInfo);
8017 XGI_VBLongWait(pVBInfo);
8018
8019 mdelay(1);
8020
8021 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02008022 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008023
8024 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02008025 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008026 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02008027 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008028
8029 /* alan, avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02008030 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008031
8032 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02008033 outb(0, (pVBInfo->P3c8 + 1));
8034 outb(0, (pVBInfo->P3c8 + 1));
8035 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008036 }
8037
Aaro Koskinen8104e322011-03-13 12:26:22 +02008038 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
8039 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
8040 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008041
8042 /* [2004/05/11] Vicent */
Aaro Koskinen58839b02011-03-13 12:26:23 +02008043 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008044 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02008045 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008046}
8047
8048void XGI_EnableBridge(struct xgi_hw_device_info *HwDeviceExtension,
8049 struct vb_device_info *pVBInfo)
8050{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02008051 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008052
8053 if (pVBInfo->SetFlag == Win9xDOSMode) {
8054 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
8055 | VB_XGI302LV | VB_XGI301C)) {
8056 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
8057 return;
8058 } else
8059 /* LVDS or CH7017 */
8060 return;
8061 }
8062
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008063 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
8064 | VB_XGI302LV | VB_XGI301C)) {
8065 if (!(pVBInfo->SetFlag & DisableChA)) {
8066 if (pVBInfo->SetFlag & EnableChA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008067 /* Power on */
8068 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008069 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008070 /* SetCRT2ToLCDA ) */
8071 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
8072 /* Power on */
Aaro Koskinen8104e322011-03-13 12:26:22 +02008073 xgifb_reg_set(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008074 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008075 }
8076 }
8077 }
8078
8079 if (!(pVBInfo->SetFlag & DisableChB)) {
8080 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
8081 & (SetCRT2ToLCD | SetCRT2ToTV
8082 | SetCRT2ToRAMDAC))) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02008083 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008084 pVBInfo->P3c4, 0x32);
8085 tempah &= 0xDF;
8086 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008087 if (!(pVBInfo->VBInfo &
8088 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008089 tempah |= 0x20;
8090 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02008091 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02008092 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008093
Aaro Koskinen58839b02011-03-13 12:26:23 +02008094 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008095 pVBInfo->Part1Port, 0x2E);
8096
8097 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008098 /* BVBDOENABLE = 1 */
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02008099 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008100 0x2E, 0x80);
8101 /* BScreenOFF = 0 */
8102 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008103 }
8104 }
8105
8106 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
8107 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02008108 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008109 0x20); /* shampoo 0129 */
8110 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
8111 if (!XGI_DisableChISLCD(pVBInfo)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008112 if (XGI_EnableChISLCD(pVBInfo) ||
8113 (pVBInfo->VBInfo &
8114 (SetCRT2ToLCD | SetCRT2ToLCDA)))
8115 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02008116 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008117 pVBInfo->Part4Port,
8118 0x2A,
8119 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008120 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008121 /* LVDS Driver power on */
8122 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008123 }
8124 }
8125
8126 tempah = 0x00;
8127
8128 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
8129 tempah = 0xc0;
8130
8131 if (!(pVBInfo->VBInfo & SetSimuScanMode)) {
8132 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008133 if (pVBInfo->VBInfo &
8134 SetCRT2ToDualEdge) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008135 tempah = tempah & 0x40;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008136 if (pVBInfo->VBInfo &
8137 SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008138 tempah = tempah ^ 0xC0;
8139
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008140 if (pVBInfo->SetFlag &
8141 DisableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008142 tempah &= 0xBF;
8143
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008144 if (pVBInfo->SetFlag &
8145 DisableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008146 tempah &= 0x7F;
8147
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008148 if (pVBInfo->SetFlag &
8149 EnableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008150 tempah |= 0x40;
8151
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008152 if (pVBInfo->SetFlag &
8153 EnableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008154 tempah |= 0x80;
8155 }
8156 }
8157 }
8158 }
8159
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008160 /* EnablePart4_1F */
8161 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008162
8163 if (pVBInfo->SetFlag & Win9xDOSMode) {
8164 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
8165 return;
8166 }
8167
8168 if (!(pVBInfo->SetFlag & DisableChA)) {
8169 XGI_VBLongWait(pVBInfo);
8170 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008171 XGI_DisableGatingCRT(HwDeviceExtension,
8172 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008173 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
8174 XGI_VBLongWait(pVBInfo);
8175 }
8176 }
8177 } /* 301 */
8178 else { /* LVDS */
8179 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
8180 | SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008181 /* enable CRT2 */
8182 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008183
Aaro Koskinen58839b02011-03-13 12:26:23 +02008184 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008185 0x2E);
8186 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008187 /* BVBDOENABLE = 1 */
8188 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008189
Aaro Koskinendc505562011-03-13 12:26:26 +02008190 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008191 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
8192 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008193}
8194
8195static void XGI_SetCRT1Group(struct xgi_hw_device_info *HwDeviceExtension,
8196 unsigned short ModeNo, unsigned short ModeIdIndex,
8197 struct vb_device_info *pVBInfo)
8198{
8199 unsigned short StandTableIndex, RefreshRateTableIndex, b3CC, temp;
8200
8201 unsigned short XGINew_P3cc = pVBInfo->P3cc;
8202
8203 /* XGINew_CRT1Mode = ModeNo; // SaveModeID */
8204 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
8205 /* XGI_SetBIOSData(ModeNo, ModeIdIndex); */
8206 /* XGI_ClearBankRegs(ModeNo, ModeIdIndex); */
8207 XGI_SetSeqRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
8208 XGI_SetMiscRegs(StandTableIndex, pVBInfo);
8209 XGI_SetCRTCRegs(HwDeviceExtension, StandTableIndex, pVBInfo);
8210 XGI_SetATTRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
8211 XGI_SetGRCRegs(StandTableIndex, pVBInfo);
8212 XGI_ClearExt1Regs(pVBInfo);
8213
8214 /* if (pVBInfo->IF_DEF_ExpLink) */
8215 if (HwDeviceExtension->jChipType == XG27) {
8216 if (pVBInfo->IF_DEF_LVDS == 0)
8217 XGI_SetDefaultVCLK(pVBInfo);
8218 }
8219
8220 temp = ~ProgrammingCRT2;
8221 pVBInfo->SetFlag &= temp;
8222 pVBInfo->SelectCRT2Rate = 0;
8223
8224 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
8225 | VB_XGI302LV | VB_XGI301C)) {
8226 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA
8227 | SetInSlaveMode)) {
8228 pVBInfo->SetFlag |= ProgrammingCRT2;
8229 }
8230 }
8231
8232 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
8233 ModeIdIndex, pVBInfo);
8234 if (RefreshRateTableIndex != 0xFFFF) {
8235 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
8236 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
8237 pVBInfo, HwDeviceExtension);
8238 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
8239 RefreshRateTableIndex, pVBInfo);
8240 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
8241 HwDeviceExtension, pVBInfo);
8242 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
8243 RefreshRateTableIndex, pVBInfo);
8244 }
8245
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008246 if ((HwDeviceExtension->jChipType >= XG20) &&
8247 (HwDeviceExtension->jChipType < XG27)) { /* fix H/W DCLK/2 bug */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008248 if ((ModeNo == 0x00) | (ModeNo == 0x01)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02008249 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x4E);
8250 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE9);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02008251 b3CC = (unsigned char) inb(XGINew_P3cc);
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02008252 outb((b3CC |= 0x0C), XGINew_P3cc);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008253 } else if ((ModeNo == 0x04) | (ModeNo == 0x05) | (ModeNo
8254 == 0x0D)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02008255 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
8256 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE3);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02008257 b3CC = (unsigned char) inb(XGINew_P3cc);
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02008258 outb((b3CC |= 0x0C), XGINew_P3cc);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008259 }
8260 }
8261
8262 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02008263 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008264 if (temp & 0xA0) {
8265
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008266 /* Enable write GPIOF */
8267 /* xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x20); */
8268 /* P. DWN */
8269 /* xgifb_reg_and(pVBInfo->P3d4, 0x48, ~0x20); */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008270 /* XG21 CRT1 Timing */
8271 if (HwDeviceExtension->jChipType == XG27)
8272 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
8273 RefreshRateTableIndex, pVBInfo);
8274 else
8275 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
8276 RefreshRateTableIndex, pVBInfo);
8277
8278 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
8279 RefreshRateTableIndex);
8280
8281 if (HwDeviceExtension->jChipType == XG27)
8282 XGI_SetXG27LCD(pVBInfo, RefreshRateTableIndex,
8283 ModeNo);
8284 else
8285 XGI_SetXG21LCD(pVBInfo, RefreshRateTableIndex,
8286 ModeNo);
8287
8288 if (pVBInfo->IF_DEF_LVDS == 1) {
8289 if (HwDeviceExtension->jChipType == XG27)
8290 XGI_SetXG27LVDSPara(ModeNo,
8291 ModeIdIndex, pVBInfo);
8292 else
8293 XGI_SetXG21LVDSPara(ModeNo,
8294 ModeIdIndex, pVBInfo);
8295 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008296 /* P. ON */
8297 /* xgifb_reg_or(pVBInfo->P3d4, 0x48, 0x20); */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008298 }
8299 }
8300
8301 pVBInfo->SetFlag &= (~ProgrammingCRT2);
8302 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
8303 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
8304 RefreshRateTableIndex, pVBInfo);
8305
8306 /* XGI_LoadCharacter(); //dif ifdef TVFont */
8307
8308 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
8309 /* XGI_ClearBuffer(HwDeviceExtension, ModeNo, pVBInfo); */
8310}
8311
8312unsigned char XGISetModeNew(struct xgi_hw_device_info *HwDeviceExtension,
8313 unsigned short ModeNo)
8314{
8315 unsigned short ModeIdIndex;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008316 /* unsigned char *pVBInfo->FBAddr =
8317 HwDeviceExtension->pjVideoMemoryAddress; */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008318 struct vb_device_info VBINF;
8319 struct vb_device_info *pVBInfo = &VBINF;
8320 pVBInfo->ROMAddr = HwDeviceExtension->pjVirtualRomBase;
8321 pVBInfo->BaseAddr = (unsigned long) HwDeviceExtension->pjIOAddress;
8322 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008323 pVBInfo->IF_DEF_LCDA = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008324 pVBInfo->IF_DEF_VideoCapture = 0;
8325 pVBInfo->IF_DEF_ScaleLCD = 0;
8326 pVBInfo->IF_DEF_OEMUtil = 0;
8327 pVBInfo->IF_DEF_PWD = 0;
8328
8329 if (HwDeviceExtension->jChipType >= XG20) { /* kuku 2004/06/25 */
8330 pVBInfo->IF_DEF_YPbPr = 0;
8331 pVBInfo->IF_DEF_HiVision = 0;
8332 pVBInfo->IF_DEF_CRT2Monitor = 0;
8333 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008334 } else {
8335 pVBInfo->IF_DEF_YPbPr = 1;
8336 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02008337 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008338 }
8339
8340 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
8341 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
8342 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
8343 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
8344 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
8345 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
8346 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
8347 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
8348 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
8349 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
8350 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
8351 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
8352 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
8353 pVBInfo->Part1Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_04;
8354 pVBInfo->Part2Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_10;
8355 pVBInfo->Part3Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_12;
8356 pVBInfo->Part4Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14;
8357 pVBInfo->Part5Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 + 2;
8358
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008359 /* for x86 Linux, XG21 LVDS */
8360 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02008361 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008362 pVBInfo->IF_DEF_LVDS = 1;
8363 }
8364 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02008365 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
8366 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008367 pVBInfo->IF_DEF_LVDS = 1;
8368 }
8369 }
8370
8371 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 */
8372 XGI_GetVBType(pVBInfo);
8373
8374 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
8375 if (ModeNo & 0x80) {
8376 ModeNo = ModeNo & 0x7F;
8377 /* XGINew_flag_clearbuffer = 0; */
8378 }
8379 /* else {
8380 XGINew_flag_clearbuffer = 1;
8381 }
8382 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02008383 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008384
8385 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 1.Openkey */
8386 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
8387
8388 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
8389
8390 XGI_GetVGAType(HwDeviceExtension, pVBInfo);
8391
8392 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
8393 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
8394 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
8395 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
8396 XGI_DisableBridge(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008397
8398 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) {
8399 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
8400 ModeIdIndex, pVBInfo);
8401
8402 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
8403 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
8404 HwDeviceExtension, pVBInfo);
8405 }
8406 } else {
8407 if (!(pVBInfo->VBInfo & SwitchToCRT2)) {
8408 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
8409 ModeIdIndex, pVBInfo);
8410 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
8411 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
8412 HwDeviceExtension,
8413 pVBInfo);
8414 }
8415 }
8416 }
8417
8418 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchToCRT2)) {
8419 switch (HwDeviceExtension->ujVBChipID) {
8420 case VB_CHIP_301:
8421 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
8422 pVBInfo); /*add for CRT2 */
8423 break;
8424
8425 case VB_CHIP_302:
8426 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
8427 pVBInfo); /*add for CRT2 */
8428 break;
8429
8430 default:
8431 break;
8432 }
8433 }
8434
8435 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
8436 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
8437 XGI_CloseCRTC(HwDeviceExtension, pVBInfo);
8438 XGI_EnableBridge(HwDeviceExtension, pVBInfo);
8439 } /* !XG20 */
8440 else {
8441 if (pVBInfo->IF_DEF_LVDS == 1)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008442 if (!XGI_XG21CheckLVDSMode(ModeNo,
8443 ModeIdIndex,
8444 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008445 return 0;
8446
8447 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008448 pVBInfo->ModeType = pVBInfo->SModeIDTable[ModeIdIndex].
8449 St_ModeFlag & ModeInfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008450 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008451 pVBInfo->ModeType = pVBInfo->EModeIDTable[ModeIdIndex].
8452 Ext_ModeFlag & ModeInfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008453 }
8454
8455 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03008456 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008457
8458 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
8459
8460 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex,
8461 pVBInfo);
8462
8463 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
8464 /*
8465 if (HwDeviceExtension->jChipType == XG21)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02008466 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0x80, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008467 */
8468 }
8469
8470 /*
8471 if (ModeNo <= 0x13) {
8472 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
8473 } else {
8474 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
8475 }
8476 pVBInfo->ModeType = modeflag&ModeInfoFlag;
8477 pVBInfo->SetFlag = 0x00;
8478 pVBInfo->VBInfo = DisableCRT2Display;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08008479 temp = XGINew_CheckMemorySize(HwDeviceExtension,
8480 ModeNo,
8481 ModeIdIndex,
8482 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02008483
8484 if (temp == 0)
8485 return (0);
8486
8487 XGI_DisplayOff(HwDeviceExtension, pVBInfo) ;
8488 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex, pVBInfo);
8489 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
8490 */
8491
8492 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
8493
8494 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
8495 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
8496 }
8497
8498 return 1;
8499}