blob: 81c0cc41bb42969ede42b29f38481c96fc299982 [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"
Aaro Koskinen09d1cad2011-09-13 22:49:34 +030011#include "vb_init.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020012#include "vb_util.h"
13#include "vb_table.h"
Aaro Koskinen5e60b972011-03-08 22:16:14 +020014#include "vb_setmode.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020015
16
17#define IndexMask 0xff
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020018
Aaro Koskinen624554d2011-10-11 21:47:35 +030019static const unsigned short XGINew_MDA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040020 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
22 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
23 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
24 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
25 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
26 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15,
27 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020028
Aaro Koskinen624554d2011-10-11 21:47:35 +030029static const unsigned short XGINew_CGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040030 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
31 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
32 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
33 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
34 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
35 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
36 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
37 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020038
Aaro Koskinen624554d2011-10-11 21:47:35 +030039static const unsigned short XGINew_EGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040040 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x05, 0x15,
41 0x20, 0x30, 0x24, 0x34, 0x21, 0x31, 0x25, 0x35,
42 0x08, 0x18, 0x0C, 0x1C, 0x09, 0x19, 0x0D, 0x1D,
43 0x28, 0x38, 0x2C, 0x3C, 0x29, 0x39, 0x2D, 0x3D,
44 0x02, 0x12, 0x06, 0x16, 0x03, 0x13, 0x07, 0x17,
45 0x22, 0x32, 0x26, 0x36, 0x23, 0x33, 0x27, 0x37,
46 0x0A, 0x1A, 0x0E, 0x1E, 0x0B, 0x1B, 0x0F, 0x1F,
47 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020048
Aaro Koskinen624554d2011-10-11 21:47:35 +030049static const unsigned short XGINew_VGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040050 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
51 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
52 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
53 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
54 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
55 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
56 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
57 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
58 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
59 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020060
Bill Pemberton80adad82010-06-17 13:10:51 -040061void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020062{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053063 pVBInfo->SModeIDTable = (struct XGI_StStruct *) XGI330_SModeIDTable;
64 pVBInfo->StandTable = (struct XGI_StandTableStruct *) XGI330_StandTable;
65 pVBInfo->EModeIDTable = (struct XGI_ExtStruct *) XGI330_EModeIDTable;
66 pVBInfo->RefIndex = (struct XGI_Ext2Struct *) XGI330_RefIndex;
67 pVBInfo->XGINEWUB_CRT1Table
68 = (struct XGI_CRT1TableStruct *) XGI_CRT1Table;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020069
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053070 /* add for new UNIVGABIOS */
Kenji Toyama1d7f6562011-04-23 19:36:49 +080071 /* XGINew_UBLCDDataTable =
72 * (struct XGI_LCDDataTablStruct *) XGI_LCDDataTable; */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053073 /* XGINew_UBTVDataTable = (XGI_TVDataTablStruct *) XGI_TVDataTable; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020074
Aaro Koskinen06587332011-03-13 12:26:10 +020075 pVBInfo->MCLKData = (struct XGI_MCLKDataStruct *) XGI340New_MCLKData;
76 pVBInfo->ECLKData = (struct XGI_ECLKDataStruct *) XGI340_ECLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053077 pVBInfo->VCLKData = (struct XGI_VCLKDataStruct *) XGI_VCLKData;
78 pVBInfo->VBVCLKData = (struct XGI_VBVCLKDataStruct *) XGI_VBVCLKData;
79 pVBInfo->ScreenOffset = XGI330_ScreenOffset;
80 pVBInfo->StResInfo = (struct XGI_StResInfoStruct *) XGI330_StResInfo;
81 pVBInfo->ModeResInfo
82 = (struct XGI_ModeResInfoStruct *) XGI330_ModeResInfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020083
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053084 pVBInfo->pOutputSelect = &XGI330_OutputSelect;
85 pVBInfo->pSoftSetting = &XGI330_SoftSetting;
86 pVBInfo->pSR07 = &XGI330_SR07;
87 pVBInfo->LCDResInfo = 0;
88 pVBInfo->LCDTypeInfo = 0;
89 pVBInfo->LCDInfo = 0;
90 pVBInfo->VBInfo = 0;
91 pVBInfo->TVInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020092
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053093 pVBInfo->SR15 = XGI340_SR13;
94 pVBInfo->CR40 = XGI340_cr41;
95 pVBInfo->SR25 = XGI330_sr25;
96 pVBInfo->pSR31 = &XGI330_sr31;
97 pVBInfo->pSR32 = &XGI330_sr32;
98 pVBInfo->CR6B = XGI340_CR6B;
99 pVBInfo->CR6E = XGI340_CR6E;
100 pVBInfo->CR6F = XGI340_CR6F;
101 pVBInfo->CR89 = XGI340_CR89;
102 pVBInfo->AGPReg = XGI340_AGPReg;
103 pVBInfo->SR16 = XGI340_SR16;
104 pVBInfo->pCRCF = &XG40_CRCF;
105 pVBInfo->pXGINew_DRAMTypeDefinition = &XG40_DRAMTypeDefinition;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200106
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530107 pVBInfo->CR49 = XGI330_CR49;
108 pVBInfo->pSR1F = &XGI330_SR1F;
109 pVBInfo->pSR21 = &XGI330_SR21;
110 pVBInfo->pSR22 = &XGI330_SR22;
111 pVBInfo->pSR23 = &XGI330_SR23;
112 pVBInfo->pSR24 = &XGI330_SR24;
113 pVBInfo->pSR33 = &XGI330_SR33;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200114
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530115 pVBInfo->pCRT2Data_1_2 = &XGI330_CRT2Data_1_2;
116 pVBInfo->pCRT2Data_4_D = &XGI330_CRT2Data_4_D;
117 pVBInfo->pCRT2Data_4_E = &XGI330_CRT2Data_4_E;
118 pVBInfo->pCRT2Data_4_10 = &XGI330_CRT2Data_4_10;
119 pVBInfo->pRGBSenseData = &XGI330_RGBSenseData;
120 pVBInfo->pVideoSenseData = &XGI330_VideoSenseData;
121 pVBInfo->pYCSenseData = &XGI330_YCSenseData;
122 pVBInfo->pRGBSenseData2 = &XGI330_RGBSenseData2;
123 pVBInfo->pVideoSenseData2 = &XGI330_VideoSenseData2;
124 pVBInfo->pYCSenseData2 = &XGI330_YCSenseData2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200125
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530126 pVBInfo->NTSCTiming = XGI330_NTSCTiming;
127 pVBInfo->PALTiming = XGI330_PALTiming;
128 pVBInfo->HiTVExtTiming = XGI330_HiTVExtTiming;
129 pVBInfo->HiTVSt1Timing = XGI330_HiTVSt1Timing;
130 pVBInfo->HiTVSt2Timing = XGI330_HiTVSt2Timing;
131 pVBInfo->HiTVTextTiming = XGI330_HiTVTextTiming;
132 pVBInfo->YPbPr750pTiming = XGI330_YPbPr750pTiming;
133 pVBInfo->YPbPr525pTiming = XGI330_YPbPr525pTiming;
134 pVBInfo->YPbPr525iTiming = XGI330_YPbPr525iTiming;
135 pVBInfo->HiTVGroup3Data = XGI330_HiTVGroup3Data;
136 pVBInfo->HiTVGroup3Simu = XGI330_HiTVGroup3Simu;
137 pVBInfo->HiTVGroup3Text = XGI330_HiTVGroup3Text;
138 pVBInfo->Ren525pGroup3 = XGI330_Ren525pGroup3;
139 pVBInfo->Ren750pGroup3 = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530141 pVBInfo->TimingH = (struct XGI_TimingHStruct *) XGI_TimingH;
142 pVBInfo->TimingV = (struct XGI_TimingVStruct *) XGI_TimingV;
143 pVBInfo->UpdateCRT1 = (struct XGI_XG21CRT1Struct *) XGI_UpdateCRT1Table;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200144
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530145 /* 310 customization related */
146 if ((pVBInfo->VBType & VB_XGI301LV) || (pVBInfo->VBType & VB_XGI302LV))
147 pVBInfo->LCDCapList = XGI_LCDDLCapList;
148 else
149 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200150
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530151 if ((ChipType == XG21) || (ChipType == XG27))
152 pVBInfo->XG21_LVDSCapList = XGI21_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200153
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530154 pVBInfo->XGI_TVDelayList = XGI301TVDelayList;
155 pVBInfo->XGI_TVDelayList2 = XGI301TVDelayList2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200156
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530157 pVBInfo->pXGINew_I2CDefinition = &XG40_I2CDefinition;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200158
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530159 if (ChipType >= XG20)
160 pVBInfo->pXGINew_CR97 = &XG20_CR97;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200161
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530162 if (ChipType == XG27) {
163 pVBInfo->MCLKData
164 = (struct XGI_MCLKDataStruct *) XGI27New_MCLKData;
165 pVBInfo->CR40 = XGI27_cr41;
166 pVBInfo->pXGINew_CR97 = &XG27_CR97;
167 pVBInfo->pSR36 = &XG27_SR36;
168 pVBInfo->pCR8F = &XG27_CR8F;
169 pVBInfo->pCRD0 = XG27_CRD0;
170 pVBInfo->pCRDE = XG27_CRDE;
171 pVBInfo->pSR40 = &XG27_SR40;
172 pVBInfo->pSR41 = &XG27_SR41;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200173
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530174 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200175
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530176 if (ChipType >= XG20) {
177 pVBInfo->pDVOSetting = &XG21_DVOSetting;
178 pVBInfo->pCR2E = &XG21_CR2E;
179 pVBInfo->pCR2F = &XG21_CR2F;
180 pVBInfo->pCR46 = &XG21_CR46;
181 pVBInfo->pCR47 = &XG21_CR47;
182 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200183
184}
185
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800186static unsigned char XGI_GetModePtr(unsigned short ModeNo,
187 unsigned short ModeIdIndex,
188 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200189{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530190 unsigned char index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200191
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530192 if (ModeNo <= 0x13)
193 index = pVBInfo->SModeIDTable[ModeIdIndex].St_StTableIndex;
194 else {
195 if (pVBInfo->ModeType <= 0x02)
196 index = 0x1B; /* 02 -> ModeEGA */
197 else
198 index = 0x0F;
199 }
200 return index; /* Get pVBInfo->StandTable index */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200201}
202
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800203static void XGI_SetSeqRegs(unsigned short ModeNo,
204 unsigned short StandTableIndex,
205 unsigned short ModeIdIndex,
206 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200207{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530208 unsigned char tempah, SRdata;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530209 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200210
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530211 if (ModeNo <= 0x13)
212 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
213 else
214 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200215
Aaro Koskinen8104e322011-03-13 12:26:22 +0200216 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530217 tempah = pVBInfo->StandTable[StandTableIndex].SR[0];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200218
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530219 i = SetCRT2ToLCDA;
220 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
221 tempah |= 0x01;
222 } else {
223 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
224 if (pVBInfo->VBInfo & SetInSlaveMode)
225 tempah |= 0x01;
226 }
227 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200228
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530229 tempah |= 0x20; /* screen off */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200230 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200231
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530232 for (i = 02; i <= 04; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800233 /* Get SR2,3,4 from file */
234 SRdata = pVBInfo->StandTable[StandTableIndex].SR[i - 1];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200235 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530236 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200237}
238
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200239static void XGI_SetMiscRegs(unsigned short StandTableIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800240 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200241{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530242 unsigned char Miscdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200243
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800244 /* Get Misc from file */
245 Miscdata = pVBInfo->StandTable[StandTableIndex].MISC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530246 /*
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800247 if (pVBInfo->VBType & (VB_XGI301B |
248 VB_XGI302B |
249 VB_XGI301LV |
250 VB_XGI302LV |
251 VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530252 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
253 Miscdata |= 0x0C;
254 }
255 }
256 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200257
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200258 outb(Miscdata, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200259}
260
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200261static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800262 unsigned short StandTableIndex,
263 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200264{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530265 unsigned char CRTCdata;
266 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200267
Aaro Koskinen58839b02011-03-13 12:26:23 +0200268 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530269 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200270 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200271
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530272 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800273 /* Get CRTC from file */
274 CRTCdata = pVBInfo->StandTable[StandTableIndex].CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200275 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530276 }
277 /*
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800278 if ((HwDeviceExtension->jChipType == XGI_630) &&
279 (HwDeviceExtension->jChipRevision == 0x30)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530280 if (pVBInfo->VBInfo & SetInSlaveMode) {
281 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200282 xgifb_reg_set(pVBInfo->P3d4, 0x18, 0xFE);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530283 }
284 }
285 }
286 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200287}
288
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800289static void XGI_SetATTRegs(unsigned short ModeNo,
290 unsigned short StandTableIndex,
291 unsigned short ModeIdIndex,
292 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200293{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530294 unsigned char ARdata;
295 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200296
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530297 if (ModeNo <= 0x13)
298 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
299 else
300 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200301
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530302 for (i = 0; i <= 0x13; i++) {
303 ARdata = pVBInfo->StandTable[StandTableIndex].ATTR[i];
304 if (modeflag & Charx8Dot) { /* ifndef Dot9 */
305 if (i == 0x13) {
306 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
307 ARdata = 0;
308 } else {
309 if (pVBInfo->VBInfo & (SetCRT2ToTV
310 | SetCRT2ToLCD)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800311 if (pVBInfo->VBInfo &
312 SetInSlaveMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530313 ARdata = 0;
314 }
315 }
316 }
317 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200318
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200319 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200320 outb(i, pVBInfo->P3c0); /* set index */
321 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530322 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200323
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200324 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200325 outb(0x14, pVBInfo->P3c0); /* set index */
326 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200327 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200328 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200329}
330
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200331static void XGI_SetGRCRegs(unsigned short StandTableIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800332 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200333{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530334 unsigned char GRdata;
335 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200336
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530337 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800338 /* Get GR from file */
339 GRdata = pVBInfo->StandTable[StandTableIndex].GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200340 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530341 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200342
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530343 if (pVBInfo->ModeType > ModeVGA) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200344 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530345 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200346 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530347 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200348}
349
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200350static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200351{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530352 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200353
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530354 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200355 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200356}
357
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200358static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200359{
360
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200361 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200362 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[0].SR2B);
363 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200364
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200365 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200366 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[1].SR2B);
367 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200368
Aaro Koskinendc505562011-03-13 12:26:26 +0200369 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530370 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200371}
372
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200373static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530374 unsigned short ModeIdIndex,
375 unsigned short RefreshRateTableIndex, unsigned short *i,
376 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200377{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530378 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200379
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530380 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800381 /* si+St_ModeFlag */
382 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530383 else
384 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200385
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530386 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
387 tempbx = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID;
388 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200389
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530390 if (pVBInfo->IF_DEF_LVDS == 0) {
391 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
392 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200393
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530394 if (pVBInfo->VBType & VB_XGI301C)
395 tempax |= SupportCRT2in301C;
396 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200397
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800398 /* 301b */
399 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530400 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200401
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530402 if (pVBInfo->LCDResInfo != Panel1280x1024) {
403 if (pVBInfo->LCDResInfo != Panel1280x960) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800404 if (pVBInfo->LCDInfo &
405 LCDNonExpanding) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530406 if (resinfo >= 9) {
407 tempax = 0;
408 return 0;
409 }
410 }
411 }
412 }
413 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200414
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530415 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) { /* for HiTV */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800416 if ((pVBInfo->VBType & VB_XGI301LV) &&
417 (pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530418 tempax |= SupportYPbPr;
419 if (pVBInfo->VBInfo & SetInSlaveMode) {
420 if (resinfo == 4)
421 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200422
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530423 if (resinfo == 3)
424 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200425
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530426 if (resinfo > 7)
427 return 0;
428 }
429 } else {
430 tempax |= SupportHiVisionTV;
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 if (pVBInfo->SetFlag
437 & TVSimuMode)
438 return 0;
439 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200440
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530441 if (resinfo > 7)
442 return 0;
443 }
444 }
445 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800446 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
447 SetCRT2ToSVIDEO |
448 SetCRT2ToSCART |
449 SetCRT2ToYPbPr |
450 SetCRT2ToHiVisionTV)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530451 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200452
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530453 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
454 | VB_XGI301LV | VB_XGI302LV
455 | VB_XGI301C)) {
456 tempax |= SupportTV1024;
457 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200458
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530459 if (!(pVBInfo->VBInfo & SetPALTV)) {
460 if (modeflag & NoSupportSimuTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800461 if (pVBInfo->VBInfo &
462 SetInSlaveMode) {
463 if (!(pVBInfo->VBInfo &
464 SetNotSimuMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530465 return 0;
466 }
467 }
468 }
469 }
470 }
471 }
472 } else { /* for LVDS */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530473 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
474 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200475
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530476 if (resinfo > 0x08)
477 return 0; /* 1024x768 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200478
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530479 if (pVBInfo->LCDResInfo < Panel1024x768) {
480 if (resinfo > 0x07)
481 return 0; /* 800x600 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200482
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530483 if (resinfo == 0x04)
484 return 0; /* 512x384 */
485 }
486 }
487 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200488
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800489 for (; pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
490 tempbx; (*i)--) {
491 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
492 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530493 if (infoflag & tempax)
494 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200495
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530496 if ((*i) == 0)
497 break;
498 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200499
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530500 for ((*i) = 0;; (*i)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800501 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
502 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530503 if (pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID
504 != tempbx) {
505 return 0;
506 }
507
508 if (infoflag & tempax)
509 return 1;
510 }
511 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200512}
513
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200514static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530515 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200516{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530517 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200518
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800519 /* di+0x00 */
520 sync = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530521 sync &= 0xC0;
522 temp = 0x2F;
523 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200524 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200525}
526
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200527static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530528 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200529{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530530 unsigned char data, data1, pushax;
531 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200532
Aaro Koskinen8104e322011-03-13 12:26:22 +0200533 /* xgifb_reg_set(pVBInfo->P3d4, 0x51, 0); */
534 /* xgifb_reg_set(pVBInfo->P3d4, 0x56, 0); */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200535 /* xgifb_reg_and_or(pVBInfo->P3d4, 0x11, 0x7f, 0x00); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200536
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800537 /* unlock cr0-7 */
538 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530539 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200540 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200541
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530542 data = pVBInfo->TimingH[0].data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200543 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200544
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530545 for (i = 0x01; i <= 0x04; i++) {
546 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200547 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530548 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200549
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530550 for (i = 0x05; i <= 0x06; i++) {
551 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200552 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530553 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200554
Aaro Koskinen58839b02011-03-13 12:26:23 +0200555 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530556 j &= 0x1F;
557 data = pVBInfo->TimingH[0].data[7];
558 data &= 0xE0;
559 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200560 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200561
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530562 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200563 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530564 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200565 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200566 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530567 data1 = data;
568 data1 &= 0xE0;
569 data &= 0x1F;
570 if (data == 0) {
571 pushax = data;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200572 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530573 0x0c);
574 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200575 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530576 data = pushax;
577 }
578 data = data - 1;
579 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200580 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200581 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530582 data = data >> 5;
583 data = data + 3;
584 if (data > 7)
585 data = data - 7;
586 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200587 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530588 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200589}
590
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800591static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
592 unsigned short ModeNo,
593 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200594{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530595 unsigned char data;
596 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200597
Aaro Koskinen8104e322011-03-13 12:26:22 +0200598 /* xgifb_reg_set(pVBInfo->P3d4, 0x51, 0); */
599 /* xgifb_reg_set(pVBInfo->P3d4, 0x56, 0); */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200600 /* xgifb_reg_and_or(pVBInfo->P3d4, 0x11, 0x7f, 0x00); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200601
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530602 for (i = 0x00; i <= 0x01; i++) {
603 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200604 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530605 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200606
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530607 for (i = 0x02; i <= 0x03; i++) {
608 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200609 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530610 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200611
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530612 for (i = 0x04; i <= 0x05; i++) {
613 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200614 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530615 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200616
Aaro Koskinen58839b02011-03-13 12:26:23 +0200617 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530618 j &= 0xC0;
619 data = pVBInfo->TimingV[0].data[6];
620 data &= 0x3F;
621 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200622 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200623
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530624 data = pVBInfo->TimingV[0].data[6];
625 data &= 0x80;
626 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200627
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530628 if (ModeNo <= 0x13)
629 i = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
630 else
631 i = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200632
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530633 i &= DoubleScanMode;
634 if (i)
635 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200636
Aaro Koskinen58839b02011-03-13 12:26:23 +0200637 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530638 j &= 0x5F;
639 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200640 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200641}
642
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200643static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
644 unsigned short RefreshRateTableIndex,
645 struct vb_device_info *pVBInfo,
646 struct xgi_hw_device_info *HwDeviceExtension)
647{
648 unsigned char index, data;
649 unsigned short i;
650
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800651 /* Get index */
652 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200653 index = index & IndexMask;
654
Aaro Koskinen58839b02011-03-13 12:26:23 +0200655 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200656 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200657 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200658
659 for (i = 0; i < 8; i++)
660 pVBInfo->TimingH[0].data[i]
661 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i];
662
663 for (i = 0; i < 7; i++)
664 pVBInfo->TimingV[0].data[i]
665 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i + 8];
666
667 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
668
669 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
670
671 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200672 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200673}
674
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200675/* --------------------------------------------------------------------- */
676/* Function : XGI_SetXG21CRTC */
677/* Input : Stand or enhance CRTC table */
678/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
679/* Description : Set LCD timing */
680/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200681static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530682 unsigned short RefreshRateTableIndex,
683 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200684{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530685 unsigned char StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
686 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200687
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530688 if (ModeNo <= 0x13) {
689 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800690 /* CR04 HRS */
691 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4];
692 /* SR2E [7:0]->HRS */
693 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
694 /* Tempbx: CR05 HRE */
695 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530696 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */
697 Tempcx = Tempax;
698 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */
699 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
700 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */
701 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */
702 Tempdx <<= 2; /* Tempdx << 2 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800703 /* SR2F [7:2]->HRE */
704 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200705 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200706
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800707 /* Tempax: CR16 VRS */
708 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530709 Tempbx = Tempax; /* Tempbx=Tempax */
710 Tempax &= 0x01; /* Tempax: VRS[0] */
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200711 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800712
713 /* Tempax: CR7 VRS */
714 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530715 Tempdx = Tempbx >> 1; /* Tempdx: VRS[7:1] */
716 Tempcx = Tempax & 0x04; /* Tempcx: CR7[2] */
717 Tempcx <<= 5; /* Tempcx[7]: VRS[8] */
718 Tempdx |= Tempcx; /* Tempdx: VRS[8:1] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800719 /* SR34[7:0]: VRS[8:1] */
720 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempdx);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200721
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800722 /* Temp1[8]: VRS[8] unsigned char -> unsigned short */
723 Temp1 = Tempcx << 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530724 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
725 Tempax &= 0x80; /* Tempax[7]: CR7[7] */
726 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
727 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200728
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800729 /* CR16 VRE */
730 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530731 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
732 Temp2 = Temp1 & 0x3F0; /* Temp2[9:4]: VRS[9:4] */
733 Temp2 |= Tempax; /* Temp2[9:0]: VRE[9:0] */
734 Temp3 = Temp1 & 0x0F; /* Temp3[3:0]: VRS[3:0] */
735 if (Tempax < Temp3) /* VRE[3:0]<VRS[3:0] */
736 Temp2 |= 0x10; /* Temp2: VRE + 0x10 */
737 Temp2 &= 0xFF; /* Temp2[7:0]: VRE[7:0] */
738 Tempax = (unsigned char) Temp2; /* Tempax[7:0]: VRE[7:0] */
739 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */
740 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
741 Temp1 >>= 9; /* [10:9]->[1:0] */
742 Tempbx = (unsigned char) Temp1; /* Tempbx[1:0]: VRS[10:9] */
743 Tempax |= Tempbx; /* VRE[5:0]VRS[10:9] */
744 Tempax &= 0x7F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800745 /* SR3F D[7:2]->VRE D[1:0]->VRS */
746 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530747 } else {
748 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800749 /* Tempax: CR4 HRS */
750 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530751 Tempcx = Tempax; /* Tempcx: HRS */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800752 /* SR2E[7:0]->HRS */
753 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200754
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530755 Tempdx = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SRB */
756 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
757 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
758 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
759 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200760
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530761 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
762 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200763
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530764 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
765 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
766 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
767 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200768
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530769 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
770 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200771
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530772 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
773 if (Tempax < Tempcx) /* HRE < HRS */
774 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200775
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530776 Temp2 &= 0xFF;
777 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
778 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
779 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
780 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800781 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
782 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200783 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200784
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800785 /* CR10 VRS */
786 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530787 Tempbx = Tempax; /* Tempbx: VRS */
788 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200789 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800790 /* CR7[2][7] VRE */
791 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530792 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
793 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
794 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
795 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200796 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200797
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530798 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
799 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
800 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
801 Tempax &= 0x80;
802 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
803 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800804 /* Tempax: SRA */
805 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530806 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
807 Temp2 = Tempax;
808 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
809 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200810
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800811 /* Tempax: CR11 VRE */
812 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530813 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800814 /* Tempbx: SRA */
815 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530816 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
817 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
818 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
819 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
820 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200821
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530822 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
823 if (Tempax < Temp3) /* VRE < VRS */
824 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200825
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530826 Temp2 &= 0xFF;
827 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
828 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
829 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
830 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
831 Tempbx = (unsigned char) Temp1;
832 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
833 Tempax &= 0x7F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800834 /* SR3F D[7:2]->VRE D[1:0]->VRS */
835 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530836 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200837}
838
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800839static void XGI_SetXG27CRTC(unsigned short ModeNo,
840 unsigned short ModeIdIndex,
841 unsigned short RefreshRateTableIndex,
842 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200843{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400844 unsigned short StandTableIndex, index, Tempax, Tempbx, Tempcx, Tempdx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200845
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530846 if (ModeNo <= 0x13) {
847 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800848 /* CR04 HRS */
849 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[4];
850 /* SR2E [7:0]->HRS */
851 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
852 /* Tempbx: CR05 HRE */
853 Tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530854 Tempbx &= 0x1F; /* Tempbx: HRE[4:0] */
855 Tempcx = Tempax;
856 Tempcx &= 0xE0; /* Tempcx: HRS[7:5] */
857 Tempdx = Tempcx | Tempbx; /* Tempdx(HRE): HRS[7:5]HRE[4:0] */
858 if (Tempbx < (Tempax & 0x1F)) /* IF HRE < HRS */
859 Tempdx |= 0x20; /* Tempdx: HRE = HRE + 0x20 */
860 Tempdx <<= 2; /* Tempdx << 2 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800861 /* SR2F [7:2]->HRE */
862 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempdx);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200863 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200864
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800865 /* Tempax: CR10 VRS */
866 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[16];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200867 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax); /* SR34[7:0]->VRS */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530868 Tempcx = Tempax; /* Tempcx=Tempax=VRS[7:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800869 /* Tempax[7][2]: CR7[7][2] VRS[9][8] */
870 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530871 Tempbx = Tempax; /* Tempbx=CR07 */
872 Tempax &= 0x04; /* Tempax[2]: CR07[2] VRS[8] */
873 Tempax >>= 2;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800874 /* SR35 D[0]->VRS D[8] */
875 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530876 Tempcx |= (Tempax << 8); /* Tempcx[8] |= VRS[8] */
877 Tempcx |= (Tempbx & 0x80) << 2; /* Tempcx[9] |= VRS[9] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200878
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800879 /* CR11 VRE */
880 Tempax = pVBInfo->StandTable[StandTableIndex].CRTC[17];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530881 Tempax &= 0x0F; /* Tempax: VRE[3:0] */
882 Tempbx = Tempcx; /* Tempbx=Tempcx=VRS[9:0] */
883 Tempbx &= 0x3F0; /* Tempbx[9:4]: VRS[9:4] */
884 Tempbx |= Tempax; /* Tempbx[9:0]: VRE[9:0] */
885 if (Tempax <= (Tempcx & 0x0F)) /* VRE[3:0]<=VRS[3:0] */
886 Tempbx |= 0x10; /* Tempbx: VRE + 0x10 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800887 /* Tempax[7:0]: VRE[7:0] */
888 Tempax = (unsigned char) Tempbx & 0xFF;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530889 Tempax <<= 2; /* Tempax << 2: VRE[5:0] */
890 Tempcx = (Tempcx & 0x600) >> 8; /* Tempcx VRS[10:9] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800891 /* SR3F D[7:2]->VRE D[5:0] */
892 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
893 /* SR35 D[2:1]->VRS[10:9] */
894 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x06, Tempcx);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530895 } else {
896 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800897 /* Tempax: CR4 HRS */
898 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530899 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800900 /* SR2E[7:0]->HRS */
901 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200902
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800903 /* SR0B */
904 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530905 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
906 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200907
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530908 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
909 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
910 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200911
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530912 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
913 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
914 Tempax <<= 3; /* Tempax[5]: HRE[5] */
915 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200916
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530917 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
918 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200919
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800920 /* Tempax: CR4 HRS */
921 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530922 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
923 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
924 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200925
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530926 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SR0B */
927 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
928 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
929 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800930 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
931 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200932 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200933
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800934 /* CR10 VRS */
935 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
936 /* SR34[7:0]->VRS[7:0] */
937 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200938
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530939 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800940 /* CR7[7][2] VRS[9][8] */
941 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530942 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
943 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
944 Tempax >>= 2; /* Tempax[0]: VRS[8] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800945 /* SR35[0]: VRS[8] */
946 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530947 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
948 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800949 /* Tempax: SR0A */
950 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530951 Tempax &= 0x08; /* SR0A[3] VRS[10] */
952 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200953
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800954 /* Tempax: CR11 VRE */
955 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530956 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800957 /* Tempbx: SR0A */
958 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530959 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
960 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
961 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
962 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
963 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
964 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200965
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530966 if (Tempbx <= Tempcx) /* VRE <= VRS */
967 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200968
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800969 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
970 Tempax = (Tempbx << 2) & 0xFF;
971 /* SR3F[7:2]:VRE[5:0] */
972 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530973 Tempax = Tempcx >> 8;
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800974 /* SR35[2:0]:VRS[10:8] */
975 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530976 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200977}
978
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300979static void xgifb_set_lcd(int chip_id,
980 struct vb_device_info *pVBInfo,
981 unsigned short RefreshRateTableIndex,
982 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200983{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400984 unsigned short Data, Temp, b3CC;
985 unsigned short XGI_P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200986
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530987 XGI_P3cc = pVBInfo->P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200988
Aaro Koskinen8104e322011-03-13 12:26:22 +0200989 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
990 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
991 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
992 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300993
994 if (chip_id == XG27) {
995 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
996 if ((Temp & 0x03) == 0) { /* dual 12 */
997 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
998 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
999 }
1000 }
1001
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301002 if (((*pVBInfo->pDVOSetting) & 0xC0) == 0xC0) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001003 xgifb_reg_set(pVBInfo->P3d4, 0x2E, *pVBInfo->pCR2E);
1004 xgifb_reg_set(pVBInfo->P3d4, 0x2F, *pVBInfo->pCR2F);
1005 xgifb_reg_set(pVBInfo->P3d4, 0x46, *pVBInfo->pCR46);
1006 xgifb_reg_set(pVBInfo->P3d4, 0x47, *pVBInfo->pCR47);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301007 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001008
Aaro Koskinen105d8d02011-08-31 21:46:00 +03001009 if (chip_id == XG27) {
1010 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301011 } else {
Aaro Koskinen105d8d02011-08-31 21:46:00 +03001012 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
1013 if (Temp & 0x01) {
1014 /* 18 bits FP */
1015 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
1016 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
1017 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301018 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001019
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001020 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001021
Aaro Koskinendc505562011-03-13 12:26:26 +02001022 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
1023 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001024
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301025 if (ModeNo <= 0x13) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001026 b3CC = (unsigned char) inb(XGI_P3cc);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301027 if (b3CC & 0x40)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001028 /* Hsync polarity */
1029 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301030 if (b3CC & 0x80)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001031 /* Vsync polarity */
1032 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301033 } else {
1034 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1035 if (Data & 0x4000)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001036 /* Hsync polarity */
1037 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301038 if (Data & 0x8000)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001039 /* Vsync polarity */
1040 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301041 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001042}
1043
1044/* --------------------------------------------------------------------- */
1045/* Function : XGI_UpdateXG21CRTC */
1046/* Input : */
1047/* Output : CRT1 CRTC */
1048/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
1049/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001050static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
1051 struct vb_device_info *pVBInfo,
1052 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001053{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301054 int i, index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001055
Aaro Koskinendc505562011-03-13 12:26:26 +02001056 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301057 if (ModeNo <= 0x13) {
1058 for (i = 0; i < 12; i++) {
1059 if (ModeNo == pVBInfo->UpdateCRT1[i].ModeID)
1060 index = i;
1061 }
1062 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001063 if (ModeNo == 0x2E &&
1064 (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
1065 RES640x480x60))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301066 index = 12;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001067 else if (ModeNo == 0x2E &&
1068 (pVBInfo->RefIndex[RefreshRateTableIndex].
1069 Ext_CRT1CRTC == RES640x480x72))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301070 index = 13;
1071 else if (ModeNo == 0x2F)
1072 index = 14;
1073 else if (ModeNo == 0x50)
1074 index = 15;
1075 else if (ModeNo == 0x59)
1076 index = 16;
1077 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001078
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301079 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001080 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301081 pVBInfo->UpdateCRT1[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001082 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301083 pVBInfo->UpdateCRT1[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001084 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301085 pVBInfo->UpdateCRT1[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001086 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301087 pVBInfo->UpdateCRT1[index].CR16);
1088 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001089}
1090
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001091static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301092 unsigned short ModeNo, unsigned short ModeIdIndex,
1093 unsigned short RefreshRateTableIndex,
1094 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001095{
Bill Pemberton82d6eb52010-06-17 13:10:46 -04001096 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001097
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301098 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001099
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301100 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001101
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301102 if (ModeNo <= 0x13) {
1103 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1104 tempax = pVBInfo->StResInfo[resindex].HTotal;
1105 tempbx = pVBInfo->StResInfo[resindex].VTotal;
1106 } else {
1107 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1108 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
1109 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
1110 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001111
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301112 if (modeflag & HalfDCLK)
1113 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001114
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301115 if (ModeNo > 0x13) {
1116 if (modeflag & HalfDCLK)
1117 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001118
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301119 temp = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001120
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301121 if (temp & InterlaceMode)
1122 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001123
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301124 if (modeflag & DoubleScanMode)
1125 tempbx = tempbx << 1;
1126 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001127
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301128 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001129
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301130 /* if (!(modeflag & Charx8Dot)) */
1131 /* tempcx = 9; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001132
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301133 tempax /= tempcx;
1134 tempax -= 1;
1135 tempbx -= 1;
1136 tempcx = tempax;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001137 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
1138 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301139 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001140 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
1141 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001142 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301143 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +02001144 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301145 tempax = 0;
1146 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001147
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301148 if (tempbx & 0x01)
1149 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001150
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301151 if (tempbx & 0x02)
1152 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001153
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001154 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001155 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301156 data &= 0xFF;
1157 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001158
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301159 if (tempbx & 0x04)
1160 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001161
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001162 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001163 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001164}
1165
Bill Pemberton82d6eb52010-06-17 13:10:46 -04001166unsigned short XGI_GetResInfo(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301167 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001168{
Bill Pemberton82d6eb52010-06-17 13:10:46 -04001169 unsigned short resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001170
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301171 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001172 /* si+St_ResInfo */
1173 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301174 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001175 /* si+Ext_ResInfo */
1176 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301177 return resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001178}
1179
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001180static void XGI_SetCRT1Offset(unsigned short ModeNo,
1181 unsigned short ModeIdIndex,
1182 unsigned short RefreshRateTableIndex,
1183 struct xgi_hw_device_info *HwDeviceExtension,
1184 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001185{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301186 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001187
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301188 /* GetOffset */
1189 temp = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
1190 temp = temp >> 8;
1191 temp = pVBInfo->ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001192
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301193 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1194 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001195
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301196 if (temp2)
1197 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001198
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301199 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001200
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301201 switch (temp2) {
1202 case 0:
1203 temp2 = 1;
1204 break;
1205 case 1:
1206 temp2 = 2;
1207 break;
1208 case 2:
1209 temp2 = 4;
1210 break;
1211 case 3:
1212 temp2 = 4;
1213 break;
1214 case 4:
1215 temp2 = 6;
1216 break;
1217 case 5:
1218 temp2 = 8;
1219 break;
1220 default:
1221 break;
1222 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001223
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301224 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
1225 temp = temp * temp2 + temp2 / 2;
1226 else
1227 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001228
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301229 /* SetOffset */
1230 DisplayUnit = temp;
1231 temp2 = temp;
1232 temp = temp >> 8; /* ah */
1233 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001234 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301235 i &= 0xF0;
1236 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001237 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001238
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301239 temp = (unsigned char) temp2;
1240 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +02001241 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001242
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301243 /* SetDisplayUnit */
1244 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1245 temp2 &= InterlaceMode;
1246 if (temp2)
1247 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001248
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301249 DisplayUnit = DisplayUnit << 5;
1250 ah = (DisplayUnit & 0xff00) >> 8;
1251 al = DisplayUnit & 0x00ff;
1252 if (al == 0)
1253 ah += 1;
1254 else
1255 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001256
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301257 if (HwDeviceExtension->jChipType >= XG20)
1258 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
1259 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001260
Aaro Koskinen8104e322011-03-13 12:26:22 +02001261 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001262}
1263
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001264static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
1265 unsigned short ModeIdIndex,
1266 unsigned short RefreshRateTableIndex,
1267 struct xgi_hw_device_info *HwDeviceExtension,
1268 struct vb_device_info *pVBInfo)
1269{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001270 unsigned short LCDXlat1VCLK[4] = { VCLK65 + 2,
1271 VCLK65 + 2,
1272 VCLK65 + 2,
1273 VCLK65 + 2 };
1274 unsigned short LCDXlat2VCLK[4] = { VCLK108_2 + 5,
1275 VCLK108_2 + 5,
1276 VCLK108_2 + 5,
1277 VCLK108_2 + 5 };
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001278 unsigned short LVDSXlat1VCLK[4] = { VCLK40, VCLK40, VCLK40, VCLK40 };
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001279 unsigned short LVDSXlat2VCLK[4] = { VCLK65 + 2,
1280 VCLK65 + 2,
1281 VCLK65 + 2,
1282 VCLK65 + 2 };
1283 unsigned short LVDSXlat3VCLK[4] = { VCLK65 + 2,
1284 VCLK65 + 2,
1285 VCLK65 + 2,
1286 VCLK65 + 2 };
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001287
1288 unsigned short CRT2Index, VCLKIndex;
1289 unsigned short modeflag, resinfo;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001290
1291 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001292 /* si+St_ResInfo */
1293 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001294 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
1295 CRT2Index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1296 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001297 /* si+Ext_ResInfo */
1298 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001299 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001300 CRT2Index = pVBInfo->RefIndex[RefreshRateTableIndex].
1301 Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001302 }
1303
1304 if (pVBInfo->IF_DEF_LVDS == 0) {
1305 CRT2Index = CRT2Index >> 6; /* for LCD */
1306 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) { /*301b*/
1307 if (pVBInfo->LCDResInfo != Panel1024x768)
1308 VCLKIndex = LCDXlat2VCLK[CRT2Index];
1309 else
1310 VCLKIndex = LCDXlat1VCLK[CRT2Index];
1311 } else { /* for TV */
1312 if (pVBInfo->VBInfo & SetCRT2ToTV) {
1313 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
1314 if (pVBInfo->SetFlag & RPLLDIV2XO) {
1315 VCLKIndex = HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001316 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001317 } else {
1318 VCLKIndex = HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001319 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001320 }
1321
1322 if (pVBInfo->SetFlag & TVSimuMode) {
1323 if (modeflag & Charx8Dot) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001324 VCLKIndex =
1325 HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001326 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001327 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001328 VCLKIndex =
1329 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001330 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001331 }
1332 }
1333
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001334 /* 301lv */
1335 if (pVBInfo->VBType & VB_XGI301LV) {
1336 if (!(pVBInfo->VBExtInfo ==
1337 VB_YPbPr1080i)) {
1338 VCLKIndex =
1339 YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001340 if (!(pVBInfo->VBExtInfo
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001341 ==
1342 VB_YPbPr750p)) {
1343 VCLKIndex =
1344 YPbPr525pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001345 if (!(pVBInfo->VBExtInfo
1346 == VB_YPbPr525p)) {
1347 VCLKIndex
1348 = YPbPr525iVCLK_2;
1349 if (!(pVBInfo->SetFlag
1350 & RPLLDIV2XO))
1351 VCLKIndex
1352 = YPbPr525iVCLK;
1353 }
1354 }
1355 }
1356 }
1357 } else {
1358 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001359 if (pVBInfo->SetFlag &
1360 RPLLDIV2XO) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001361 VCLKIndex = TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001362 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001363 } else {
1364 VCLKIndex = TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001365 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001366 }
1367 }
1368 }
1369 } else { /* for CRT2 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001370 /* Port 3cch */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001371 VCLKIndex = (unsigned char) inb(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001372 (pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001373 VCLKIndex = ((VCLKIndex >> 2) & 0x03);
1374 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001375 /* di+Ext_CRTVCLK */
1376 VCLKIndex =
1377 pVBInfo->RefIndex[
1378 RefreshRateTableIndex].
1379 Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001380 VCLKIndex &= IndexMask;
1381 }
1382 }
1383 }
1384 } else { /* LVDS */
1385 if (ModeNo <= 0x13)
1386 VCLKIndex = CRT2Index;
1387 else
1388 VCLKIndex = CRT2Index;
1389
Aaro Koskinen4c14bfd2011-08-31 21:45:57 +03001390 VCLKIndex = VCLKIndex >> 6;
1391 if ((pVBInfo->LCDResInfo == Panel800x600) ||
1392 (pVBInfo->LCDResInfo == Panel320x480))
1393 VCLKIndex = LVDSXlat1VCLK[VCLKIndex];
1394 else if ((pVBInfo->LCDResInfo == Panel1024x768) ||
1395 (pVBInfo->LCDResInfo == Panel1024x768x75))
1396 VCLKIndex = LVDSXlat2VCLK[VCLKIndex];
1397 else
1398 VCLKIndex = LVDSXlat3VCLK[VCLKIndex];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001399 }
1400 /* VCLKIndex = VCLKIndex&IndexMask; */
1401
1402 return VCLKIndex;
1403}
1404
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001405static void XGI_SetCRT1VCLK(unsigned short ModeNo,
1406 unsigned short ModeIdIndex,
1407 struct xgi_hw_device_info *HwDeviceExtension,
1408 unsigned short RefreshRateTableIndex,
1409 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001410{
Bill Pemberton108afbf2010-06-17 13:10:47 -04001411 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301412 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001413
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301414 if (pVBInfo->IF_DEF_LVDS == 1) {
1415 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001416 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001417 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1418 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301419 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001420 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301421 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001422 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301423 } else if ((pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
1424 | VB_XGI302LV | VB_XGI301C)) && (pVBInfo->VBInfo
1425 & SetCRT2ToLCDA)) {
1426 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
1427 RefreshRateTableIndex, HwDeviceExtension,
1428 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001429 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001430 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301431 data = pVBInfo->VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001432 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301433 data = pVBInfo->VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001434 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1435 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301436 } else {
1437 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001438 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001439 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1440 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301441 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001442 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301443 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001444 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301445 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001446
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301447 if (HwDeviceExtension->jChipType >= XG20) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001448 if (pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag &
1449 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001450 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001451 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001452 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301453 index = data;
1454 index &= 0xE0;
1455 data &= 0x1F;
1456 data = data << 1;
1457 data += 1;
1458 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001459 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301460 }
1461 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001462}
1463
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001464static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301465 struct xgi_hw_device_info *HwDeviceExtension,
1466 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001467{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301468 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001469
Aaro Koskinen58839b02011-03-13 12:26:23 +02001470 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301471 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001472 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001473
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301474 if (ModeNo > 0x13) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001475 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001476 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301477 data &= 0xC0;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001478 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001479 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301480 data |= 0x01;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001481 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301482 } else {
1483 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001484 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x0E);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001485 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301486 data &= 0xC0;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001487 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301488 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001489 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0xAE);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001490 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301491 data &= 0xF0;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001492 xgifb_reg_set(pVBInfo->P3c4, 0x09, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301493 }
1494 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001495
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301496 if (HwDeviceExtension->jChipType == XG21)
1497 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001498}
1499
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001500static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1501 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1502 struct vb_device_info *pVBInfo)
1503{
1504 unsigned short data, data2 = 0;
1505 short VCLK;
1506
1507 unsigned char index;
1508
1509 if (ModeNo <= 0x13)
1510 VCLK = 0;
1511 else {
1512 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1513 index &= IndexMask;
1514 VCLK = pVBInfo->VCLKData[index].CLOCK;
1515 }
1516
Aaro Koskinen58839b02011-03-13 12:26:23 +02001517 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001518 data &= 0xf3;
1519 if (VCLK >= 200)
1520 data |= 0x0c; /* VCLK > 200 */
1521
1522 if (HwDeviceExtension->jChipType >= XG20)
1523 data &= ~0x04; /* 2 pixel mode */
1524
Aaro Koskinen8104e322011-03-13 12:26:22 +02001525 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001526
1527 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001528 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001529 data &= 0xE7;
1530 if (VCLK < 200)
1531 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001532 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001533 }
1534
1535 /* Jong for Adavantech LCD ripple issue
1536 if ((VCLK >= 0) && (VCLK < 135))
1537 data2 = 0x03;
1538 else if ((VCLK >= 135) && (VCLK < 160))
1539 data2 = 0x02;
1540 else if ((VCLK >= 160) && (VCLK < 260))
1541 data2 = 0x01;
1542 else if (VCLK > 260)
1543 data2 = 0x00;
1544 */
1545 data2 = 0x00;
1546
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001547 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001548 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001549 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001550
1551}
1552
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001553static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301554 unsigned short ModeNo, unsigned short ModeIdIndex,
1555 unsigned short RefreshRateTableIndex,
1556 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001557{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301558 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1559 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001560
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301561 if (ModeNo > 0x13) {
1562 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001563 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].
1564 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301565 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001566 /* si+St_ModeFlag */
1567 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001568
Aaro Koskinen58839b02011-03-13 12:26:23 +02001569 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001570 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001571
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301572 if (ModeNo > 0x13)
1573 data = infoflag;
1574 else
1575 data = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001576
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301577 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001578
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301579 if (ModeNo > 0x13) {
1580 if (pVBInfo->ModeType > 0x02) {
1581 data2 |= 0x02;
1582 data3 = pVBInfo->ModeType - ModeVGA;
1583 data3 = data3 << 2;
1584 data2 |= data3;
1585 }
1586 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001587
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301588 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001589
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301590 if (data)
1591 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001592
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001593 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001594 /* xgifb_reg_set(pVBInfo->P3c4,0x06,data2); */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301595 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
1596 if (ModeNo <= 0x13)
1597 xres = pVBInfo->StResInfo[resindex].HTotal;
1598 else
1599 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001600
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301601 data = 0x0000;
1602 if (infoflag & InterlaceMode) {
1603 if (xres == 1024)
1604 data = 0x0035;
1605 else if (xres == 1280)
1606 data = 0x0048;
1607 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001608
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301609 data2 = data & 0x00FF;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001610 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301611 data2 = (data & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001612 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001613
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301614 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001615 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001616
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301617 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001618
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301619 if (modeflag & LineCompareOff)
1620 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001621
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301622 if (ModeNo > 0x13) {
1623 if (pVBInfo->ModeType == ModeEGA)
1624 data2 |= 0x40;
1625 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001626
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001627 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301628 data = 0x60;
1629 if (pVBInfo->ModeType != ModeText) {
1630 data = data ^ 0x60;
1631 if (pVBInfo->ModeType != ModeEGA)
1632 data = data ^ 0xA0;
1633 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001634 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001635
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301636 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1637 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001638
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301639 /* if (modeflag&HalfDCLK) //030305 fix lowresolution bug */
1640 /* if (XGINew_IF_DEF_NEW_LOWRES) */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001641 /* XGI_VesaLowResolution(ModeNo, ModeIdIndex);
1642 * //030305 fix lowresolution bug */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001643
Aaro Koskinen58839b02011-03-13 12:26:23 +02001644 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001645
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301646 if (HwDeviceExtension->jChipType == XG27) {
1647 if (data & 0x40)
1648 data = 0x2c;
1649 else
1650 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001651 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001652 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301653 } else if (HwDeviceExtension->jChipType >= XG20) {
1654 if (data & 0x40)
1655 data = 0x33;
1656 else
1657 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001658 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1659 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301660 } else {
1661 if (data & 0x40)
1662 data = 0x2c;
1663 else
1664 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001665 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301666 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001667
1668}
1669
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001670static void XGI_WriteDAC(unsigned short dl,
1671 unsigned short ah,
1672 unsigned short al,
1673 unsigned short dh,
1674 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001675{
1676 unsigned short temp, bh, bl;
1677
1678 bh = ah;
1679 bl = al;
1680
1681 if (dl != 0) {
1682 temp = bh;
1683 bh = dh;
1684 dh = temp;
1685 if (dl == 1) {
1686 temp = bl;
1687 bl = dh;
1688 dh = temp;
1689 } else {
1690 temp = bl;
1691 bl = bh;
1692 bh = temp;
1693 }
1694 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001695 outb((unsigned short) dh, pVBInfo->P3c9);
1696 outb((unsigned short) bh, pVBInfo->P3c9);
1697 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001698}
1699
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001700static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301701 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001702{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301703 unsigned short data, data2, time, i, j, k, m, n, o, si, di, bx, dl, al,
Aaro Koskinen624554d2011-10-11 21:47:35 +03001704 ah, dh;
1705 const unsigned short *table = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001706
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301707 if (ModeNo <= 0x13)
1708 data = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1709 else
1710 data = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001711
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301712 data &= DACInfoFlag;
1713 time = 64;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001714
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301715 if (data == 0x00)
1716 table = XGINew_MDA_DAC;
1717 else if (data == 0x08)
1718 table = XGINew_CGA_DAC;
1719 else if (data == 0x10)
1720 table = XGINew_EGA_DAC;
1721 else if (data == 0x18) {
1722 time = 256;
1723 table = XGINew_VGA_DAC;
1724 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001725
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301726 if (time == 256)
1727 j = 16;
1728 else
1729 j = time;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001730
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001731 outb(0xFF, pVBInfo->P3c6);
1732 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001733
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301734 for (i = 0; i < j; i++) {
1735 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001736
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301737 for (k = 0; k < 3; k++) {
1738 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001739
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301740 if (data & 0x01)
1741 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001742
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301743 if (data & 0x02)
1744 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001745
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001746 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301747 data = data >> 2;
1748 }
1749 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001750
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301751 if (time == 256) {
1752 for (i = 16; i < 32; i++) {
1753 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001754
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301755 for (k = 0; k < 3; k++)
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001756 outb(data, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301757 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001758
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301759 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001760
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301761 for (m = 0; m < 9; m++) {
1762 di = si;
1763 bx = si + 0x04;
1764 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001765
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301766 for (n = 0; n < 3; n++) {
1767 for (o = 0; o < 5; o++) {
1768 dh = table[si];
1769 ah = table[di];
1770 al = table[bx];
1771 si++;
1772 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1773 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001774
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301775 si -= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001776
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301777 for (o = 0; o < 3; o++) {
1778 dh = table[bx];
1779 ah = table[di];
1780 al = table[si];
1781 si--;
1782 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1783 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001784
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301785 dl++;
1786 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001787
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301788 si += 5;
1789 }
1790 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001791}
1792
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001793static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1794 unsigned short ModeIdIndex,
1795 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001796{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301797 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001798
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301799 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001800 /* si+St_ResInfo */
1801 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301802 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001803 /* si+Ext_ResInfo */
1804 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001805
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301806 /* if (ModeNo > 0x13) */
1807 /* modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag; */
1808 /* else */
1809 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001810
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301811 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001812 /* si+St_ResInfo */
1813 resindex = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301814 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001815 /* si+Ext_ResInfo */
1816 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001817
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301818 /* resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001819
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301820 if (ModeNo <= 0x13) {
1821 xres = pVBInfo->StResInfo[resindex].HTotal;
1822 yres = pVBInfo->StResInfo[resindex].VTotal;
1823 } else {
1824 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1825 yres = pVBInfo->ModeResInfo[resindex].VTotal;
1826 }
1827 if (ModeNo > 0x13) {
1828 if (modeflag & HalfDCLK)
1829 xres = xres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001830
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301831 if (modeflag & DoubleScanMode)
1832 yres = yres << 1;
1833 }
1834 /* if (modeflag & Charx8Dot) */
1835 /* { */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001836
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301837 if (xres == 720)
1838 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001839
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301840 /* } */
1841 pVBInfo->VGAHDE = xres;
1842 pVBInfo->HDE = xres;
1843 pVBInfo->VGAVDE = yres;
1844 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001845}
1846
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001847static void *XGI_GetLcdPtr(unsigned short BX, unsigned short ModeNo,
1848 unsigned short ModeIdIndex,
1849 unsigned short RefreshRateTableIndex,
1850 struct vb_device_info *pVBInfo)
1851{
1852 unsigned short i, tempdx, tempcx, tempbx, tempal, modeflag, table;
1853
1854 struct XGI330_LCDDataTablStruct *tempdi = NULL;
1855
1856 tempbx = BX;
1857
1858 if (ModeNo <= 0x13) {
1859 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
1860 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
1861 } else {
1862 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1863 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
1864 }
1865
1866 tempal = tempal & 0x0f;
1867
1868 if (tempbx <= 1) { /* ExpLink */
1869 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001870 /* find no Ext_CRT2CRTC2 */
1871 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001872 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001873 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].
1874 Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001875 }
1876
1877 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
1878 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001879 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
1880 St_CRT2CRTC2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001881 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001882 tempal = pVBInfo->RefIndex[
1883 RefreshRateTableIndex].
1884 Ext_CRT2CRTC2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001885 }
1886
1887 if (tempbx & 0x01)
1888 tempal = (tempal >> 4);
1889
1890 tempal = (tempal & 0x0f);
1891 }
1892
1893 tempcx = LCDLenList[tempbx]; /* mov cl,byte ptr cs:LCDLenList[bx] */
1894
1895 if (pVBInfo->LCDInfo & EnableScalingLCD) { /* ScaleLCD */
1896 if ((tempbx == 5) || (tempbx) == 7)
1897 tempcx = LCDDesDataLen2;
1898 else if ((tempbx == 3) || (tempbx == 8))
1899 tempcx = LVDSDesDataLen2;
1900 }
1901 /* mov di, word ptr cs:LCDDataList[bx] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001902 /* tempdi = pVideoMemory[LCDDataList + tempbx * 2] |
1903 (pVideoMemory[LCDDataList + tempbx * 2 + 1] << 8); */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001904
1905 switch (tempbx) {
1906 case 0:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001907 case 1:
Aaro Koskinencc5c2ae2011-08-31 21:46:08 +03001908 tempdi = xgifb_epllcd_crt1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001909 break;
1910 case 2:
1911 tempdi = XGI_EPLLCDDataPtr;
1912 break;
1913 case 3:
1914 tempdi = XGI_EPLLCDDesDataPtr;
1915 break;
1916 case 4:
1917 tempdi = XGI_LCDDataTable;
1918 break;
1919 case 5:
1920 tempdi = XGI_LCDDesDataTable;
1921 break;
1922 case 6:
1923 tempdi = XGI_EPLCHLCDRegPtr;
1924 break;
1925 case 7:
1926 case 8:
1927 case 9:
1928 tempdi = NULL;
1929 break;
1930 default:
1931 break;
1932 }
1933
1934 if (tempdi == NULL) /* OEMUtil */
1935 return NULL;
1936
1937 table = tempbx;
1938 i = 0;
1939
1940 while (tempdi[i].PANELID != 0xff) {
1941 tempdx = pVBInfo->LCDResInfo;
1942 if (tempbx & 0x0080) { /* OEMUtil */
1943 tempbx &= (~0x0080);
1944 tempdx = pVBInfo->LCDTypeInfo;
1945 }
1946
1947 if (pVBInfo->LCDInfo & EnableScalingLCD)
1948 tempdx &= (~PanelResInfo);
1949
1950 if (tempdi[i].PANELID == tempdx) {
1951 tempbx = tempdi[i].MASK;
1952 tempdx = pVBInfo->LCDInfo;
1953
1954 if (ModeNo <= 0x13) /* alan 09/10/2003 */
1955 tempdx |= SetLCDStdMode;
1956
1957 if (modeflag & HalfDCLK)
1958 tempdx |= SetLCDLowResolution;
1959
1960 tempbx &= tempdx;
1961 if (tempbx == tempdi[i].CAP)
1962 break;
1963 }
1964 i++;
1965 }
1966
1967 if (table == 0) {
1968 switch (tempdi[i].DATAPTR) {
1969 case 0:
1970 return &XGI_LVDSCRT11024x768_1_H[tempal];
1971 break;
1972 case 1:
1973 return &XGI_LVDSCRT11024x768_2_H[tempal];
1974 break;
1975 case 2:
1976 return &XGI_LVDSCRT11280x1024_1_H[tempal];
1977 break;
1978 case 3:
1979 return &XGI_LVDSCRT11280x1024_2_H[tempal];
1980 break;
1981 case 4:
1982 return &XGI_LVDSCRT11400x1050_1_H[tempal];
1983 break;
1984 case 5:
1985 return &XGI_LVDSCRT11400x1050_2_H[tempal];
1986 break;
1987 case 6:
1988 return &XGI_LVDSCRT11600x1200_1_H[tempal];
1989 break;
1990 case 7:
1991 return &XGI_LVDSCRT11024x768_1_Hx75[tempal];
1992 break;
1993 case 8:
1994 return &XGI_LVDSCRT11024x768_2_Hx75[tempal];
1995 break;
1996 case 9:
1997 return &XGI_LVDSCRT11280x1024_1_Hx75[tempal];
1998 break;
1999 case 10:
2000 return &XGI_LVDSCRT11280x1024_2_Hx75[tempal];
2001 break;
2002 default:
2003 break;
2004 }
2005 } else if (table == 1) {
2006 switch (tempdi[i].DATAPTR) {
2007 case 0:
2008 return &XGI_LVDSCRT11024x768_1_V[tempal];
2009 break;
2010 case 1:
2011 return &XGI_LVDSCRT11024x768_2_V[tempal];
2012 break;
2013 case 2:
2014 return &XGI_LVDSCRT11280x1024_1_V[tempal];
2015 break;
2016 case 3:
2017 return &XGI_LVDSCRT11280x1024_2_V[tempal];
2018 break;
2019 case 4:
2020 return &XGI_LVDSCRT11400x1050_1_V[tempal];
2021 break;
2022 case 5:
2023 return &XGI_LVDSCRT11400x1050_2_V[tempal];
2024 break;
2025 case 6:
2026 return &XGI_LVDSCRT11600x1200_1_V[tempal];
2027 break;
2028 case 7:
2029 return &XGI_LVDSCRT11024x768_1_Vx75[tempal];
2030 break;
2031 case 8:
2032 return &XGI_LVDSCRT11024x768_2_Vx75[tempal];
2033 break;
2034 case 9:
2035 return &XGI_LVDSCRT11280x1024_1_Vx75[tempal];
2036 break;
2037 case 10:
2038 return &XGI_LVDSCRT11280x1024_2_Vx75[tempal];
2039 break;
2040 default:
2041 break;
2042 }
2043 } else if (table == 2) {
2044 switch (tempdi[i].DATAPTR) {
2045 case 0:
2046 return &XGI_LVDS1024x768Data_1[tempal];
2047 break;
2048 case 1:
2049 return &XGI_LVDS1024x768Data_2[tempal];
2050 break;
2051 case 2:
2052 return &XGI_LVDS1280x1024Data_1[tempal];
2053 break;
2054 case 3:
2055 return &XGI_LVDS1280x1024Data_2[tempal];
2056 break;
2057 case 4:
2058 return &XGI_LVDS1400x1050Data_1[tempal];
2059 break;
2060 case 5:
2061 return &XGI_LVDS1400x1050Data_2[tempal];
2062 break;
2063 case 6:
2064 return &XGI_LVDS1600x1200Data_1[tempal];
2065 break;
2066 case 7:
2067 return &XGI_LVDSNoScalingData[tempal];
2068 break;
2069 case 8:
2070 return &XGI_LVDS1024x768Data_1x75[tempal];
2071 break;
2072 case 9:
2073 return &XGI_LVDS1024x768Data_2x75[tempal];
2074 break;
2075 case 10:
2076 return &XGI_LVDS1280x1024Data_1x75[tempal];
2077 break;
2078 case 11:
2079 return &XGI_LVDS1280x1024Data_2x75[tempal];
2080 break;
2081 case 12:
2082 return &XGI_LVDSNoScalingDatax75[tempal];
2083 break;
2084 default:
2085 break;
2086 }
2087 } else if (table == 3) {
2088 switch (tempdi[i].DATAPTR) {
2089 case 0:
2090 return &XGI_LVDS1024x768Des_1[tempal];
2091 break;
2092 case 1:
2093 return &XGI_LVDS1024x768Des_3[tempal];
2094 break;
2095 case 2:
2096 return &XGI_LVDS1024x768Des_2[tempal];
2097 break;
2098 case 3:
2099 return &XGI_LVDS1280x1024Des_1[tempal];
2100 break;
2101 case 4:
2102 return &XGI_LVDS1280x1024Des_2[tempal];
2103 break;
2104 case 5:
2105 return &XGI_LVDS1400x1050Des_1[tempal];
2106 break;
2107 case 6:
2108 return &XGI_LVDS1400x1050Des_2[tempal];
2109 break;
2110 case 7:
2111 return &XGI_LVDS1600x1200Des_1[tempal];
2112 break;
2113 case 8:
2114 return &XGI_LVDSNoScalingDesData[tempal];
2115 break;
2116 case 9:
2117 return &XGI_LVDS1024x768Des_1x75[tempal];
2118 break;
2119 case 10:
2120 return &XGI_LVDS1024x768Des_3x75[tempal];
2121 break;
2122 case 11:
2123 return &XGI_LVDS1024x768Des_2x75[tempal];
2124 break;
2125 case 12:
2126 return &XGI_LVDS1280x1024Des_1x75[tempal];
2127 break;
2128 case 13:
2129 return &XGI_LVDS1280x1024Des_2x75[tempal];
2130 break;
2131 case 14:
2132 return &XGI_LVDSNoScalingDesDatax75[tempal];
2133 break;
2134 default:
2135 break;
2136 }
2137 } else if (table == 4) {
2138 switch (tempdi[i].DATAPTR) {
2139 case 0:
2140 return &XGI_ExtLCD1024x768Data[tempal];
2141 break;
2142 case 1:
2143 return &XGI_StLCD1024x768Data[tempal];
2144 break;
2145 case 2:
2146 return &XGI_CetLCD1024x768Data[tempal];
2147 break;
2148 case 3:
2149 return &XGI_ExtLCD1280x1024Data[tempal];
2150 break;
2151 case 4:
2152 return &XGI_StLCD1280x1024Data[tempal];
2153 break;
2154 case 5:
2155 return &XGI_CetLCD1280x1024Data[tempal];
2156 break;
2157 case 6:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002158 case 7:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002159 return &xgifb_lcd_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002160 break;
2161 case 8:
2162 return &XGI_CetLCD1400x1050Data[tempal];
2163 break;
2164 case 9:
2165 return &XGI_ExtLCD1600x1200Data[tempal];
2166 break;
2167 case 10:
2168 return &XGI_StLCD1600x1200Data[tempal];
2169 break;
2170 case 11:
2171 return &XGI_NoScalingData[tempal];
2172 break;
2173 case 12:
2174 return &XGI_ExtLCD1024x768x75Data[tempal];
2175 break;
2176 case 13:
2177 return &XGI_ExtLCD1024x768x75Data[tempal];
2178 break;
2179 case 14:
2180 return &XGI_CetLCD1024x768x75Data[tempal];
2181 break;
2182 case 15:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002183 case 16:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002184 return &xgifb_lcd_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002185 break;
2186 case 17:
2187 return &XGI_CetLCD1280x1024x75Data[tempal];
2188 break;
2189 case 18:
2190 return &XGI_NoScalingDatax75[tempal];
2191 break;
2192 default:
2193 break;
2194 }
2195 } else if (table == 5) {
2196 switch (tempdi[i].DATAPTR) {
2197 case 0:
2198 return &XGI_ExtLCDDes1024x768Data[tempal];
2199 break;
2200 case 1:
2201 return &XGI_StLCDDes1024x768Data[tempal];
2202 break;
2203 case 2:
2204 return &XGI_CetLCDDes1024x768Data[tempal];
2205 break;
2206 case 3:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002207 if ((pVBInfo->VBType & VB_XGI301LV) ||
2208 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002209 return &XGI_ExtLCDDLDes1280x1024Data[tempal];
2210 else
2211 return &XGI_ExtLCDDes1280x1024Data[tempal];
2212 break;
2213 case 4:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002214 if ((pVBInfo->VBType & VB_XGI301LV) ||
2215 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002216 return &XGI_StLCDDLDes1280x1024Data[tempal];
2217 else
2218 return &XGI_StLCDDes1280x1024Data[tempal];
2219 break;
2220 case 5:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002221 if ((pVBInfo->VBType & VB_XGI301LV) ||
2222 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002223 return &XGI_CetLCDDLDes1280x1024Data[tempal];
2224 else
2225 return &XGI_CetLCDDes1280x1024Data[tempal];
2226 break;
2227 case 6:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002228 case 7:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002229 if ((pVBInfo->VBType & VB_XGI301LV) ||
2230 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002231 return &xgifb_lcddldes_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002232 else
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002233 return &xgifb_lcddes_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002234 break;
2235 case 8:
2236 return &XGI_CetLCDDes1400x1050Data[tempal];
2237 break;
2238 case 9:
2239 return &XGI_CetLCDDes1400x1050Data2[tempal];
2240 break;
2241 case 10:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002242 if ((pVBInfo->VBType & VB_XGI301LV) ||
2243 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002244 return &XGI_ExtLCDDLDes1600x1200Data[tempal];
2245 else
2246 return &XGI_ExtLCDDes1600x1200Data[tempal];
2247 break;
2248 case 11:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002249 if ((pVBInfo->VBType & VB_XGI301LV) ||
2250 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002251 return &XGI_StLCDDLDes1600x1200Data[tempal];
2252 else
2253 return &XGI_StLCDDes1600x1200Data[tempal];
2254 break;
2255 case 12:
2256 return &XGI_NoScalingDesData[tempal];
2257 break;
2258 case 13:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002259 case 14:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002260 return &xgifb_lcddes_1024x768x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002261 break;
2262 case 15:
2263 return &XGI_CetLCDDes1024x768x75Data[tempal];
2264 break;
2265 case 16:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002266 case 17:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002267 if ((pVBInfo->VBType & VB_XGI301LV) ||
2268 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002269 return &xgifb_lcddldes_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002270 else
Aaro Koskinenada2bda2011-08-31 21:46:07 +03002271 return &xgifb_lcddes_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002272 break;
2273 case 18:
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002274 if ((pVBInfo->VBType & VB_XGI301LV) ||
2275 (pVBInfo->VBType & VB_XGI302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002276 return &XGI_CetLCDDLDes1280x1024x75Data[tempal];
2277 else
2278 return &XGI_CetLCDDes1280x1024x75Data[tempal];
2279 break;
2280 case 19:
2281 return &XGI_NoScalingDesDatax75[tempal];
2282 break;
2283 default:
2284 break;
2285 }
2286 } else if (table == 6) {
2287 switch (tempdi[i].DATAPTR) {
2288 case 0:
2289 return &XGI_CH7017LV1024x768[tempal];
2290 break;
2291 case 1:
2292 return &XGI_CH7017LV1400x1050[tempal];
2293 break;
2294 default:
2295 break;
2296 }
2297 }
2298 return NULL;
2299}
2300
2301static void *XGI_GetTVPtr(unsigned short BX, unsigned short ModeNo,
2302 unsigned short ModeIdIndex,
2303 unsigned short RefreshRateTableIndex,
2304 struct vb_device_info *pVBInfo)
2305{
2306 unsigned short i, tempdx, tempbx, tempal, modeflag, table;
2307 struct XGI330_TVDataTablStruct *tempdi = NULL;
2308
2309 tempbx = BX;
2310
2311 if (ModeNo <= 0x13) {
2312 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
2313 tempal = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2314 } else {
2315 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2316 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
2317 }
2318
2319 tempal = tempal & 0x3f;
2320 table = tempbx;
2321
2322 switch (tempbx) {
2323 case 0:
2324 tempdi = NULL; /*EPLCHTVCRT1Ptr_H;*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002325 break;
2326 case 1:
2327 tempdi = NULL; /*EPLCHTVCRT1Ptr_V;*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002328 break;
2329 case 2:
Aaro Koskinen0c23b6d2011-08-31 21:46:09 +03002330 case 6:
2331 tempdi = xgifb_chrontel_tv;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002332 break;
2333 case 3:
2334 tempdi = NULL;
2335 break;
2336 case 4:
2337 tempdi = XGI_TVDataTable;
2338 break;
2339 case 5:
2340 tempdi = NULL;
2341 break;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002342 default:
2343 break;
2344 }
2345
2346 if (tempdi == NULL) /* OEMUtil */
2347 return NULL;
2348
2349 tempdx = pVBInfo->TVInfo;
2350
2351 if (pVBInfo->VBInfo & SetInSlaveMode)
2352 tempdx = tempdx | SetTVLockMode;
2353
2354 if (modeflag & HalfDCLK)
2355 tempdx = tempdx | SetTVLowResolution;
2356
2357 i = 0;
2358
2359 while (tempdi[i].MASK != 0xffff) {
2360 if ((tempdx & tempdi[i].MASK) == tempdi[i].CAP)
2361 break;
2362 i++;
2363 }
2364
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002365 /* 07/05/22 */
2366 if (table == 0x00) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002367 } else if (table == 0x01) {
2368 } else if (table == 0x04) {
2369 switch (tempdi[i].DATAPTR) {
2370 case 0:
2371 return &XGI_ExtPALData[tempal];
2372 break;
2373 case 1:
2374 return &XGI_ExtNTSCData[tempal];
2375 break;
2376 case 2:
2377 return &XGI_StPALData[tempal];
2378 break;
2379 case 3:
2380 return &XGI_StNTSCData[tempal];
2381 break;
2382 case 4:
2383 return &XGI_ExtHiTVData[tempal];
2384 break;
2385 case 5:
2386 return &XGI_St2HiTVData[tempal];
2387 break;
2388 case 6:
2389 return &XGI_ExtYPbPr525iData[tempal];
2390 break;
2391 case 7:
2392 return &XGI_ExtYPbPr525pData[tempal];
2393 break;
2394 case 8:
2395 return &XGI_ExtYPbPr750pData[tempal];
2396 break;
2397 case 9:
2398 return &XGI_StYPbPr525iData[tempal];
2399 break;
2400 case 10:
2401 return &XGI_StYPbPr525pData[tempal];
2402 break;
2403 case 11:
2404 return &XGI_StYPbPr750pData[tempal];
2405 break;
2406 case 12: /* avoid system hang */
2407 return &XGI_ExtNTSCData[tempal];
2408 break;
2409 case 13:
2410 return &XGI_St1HiTVData[tempal];
2411 break;
2412 default:
2413 break;
2414 }
2415 } else if (table == 0x02) {
2416 switch (tempdi[i].DATAPTR) {
2417 case 0:
2418 return &XGI_CHTVUNTSCData[tempal];
2419 break;
2420 case 1:
2421 return &XGI_CHTVONTSCData[tempal];
2422 break;
2423 case 2:
2424 return &XGI_CHTVUPALData[tempal];
2425 break;
2426 case 3:
2427 return &XGI_CHTVOPALData[tempal];
2428 break;
2429 default:
2430 break;
2431 }
2432 } else if (table == 0x06) {
2433 }
2434 return NULL;
2435}
2436
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002437static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302438 unsigned short RefreshRateTableIndex,
2439 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002440{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302441 unsigned short tempbx;
2442 struct XGI330_LVDSDataStruct *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002443
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302444 tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002445
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302446 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2447 LCDPtr = (struct XGI330_LVDSDataStruct *) XGI_GetLcdPtr(tempbx,
2448 ModeNo, ModeIdIndex, RefreshRateTableIndex,
2449 pVBInfo);
2450 pVBInfo->VGAHT = LCDPtr->VGAHT;
2451 pVBInfo->VGAVT = LCDPtr->VGAVT;
2452 pVBInfo->HT = LCDPtr->LCDHT;
2453 pVBInfo->VT = LCDPtr->LCDVT;
2454 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002455
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302456 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2457 if (!(pVBInfo->LCDInfo & (SetLCDtoNonExpanding
2458 | EnableScalingLCD))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002459 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2460 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302461 pVBInfo->HDE = 1024;
2462 pVBInfo->VDE = 768;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002463 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2464 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302465 pVBInfo->HDE = 1280;
2466 pVBInfo->VDE = 1024;
2467 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2468 pVBInfo->HDE = 1400;
2469 pVBInfo->VDE = 1050;
2470 } else {
2471 pVBInfo->HDE = 1600;
2472 pVBInfo->VDE = 1200;
2473 }
2474 }
2475 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002476}
2477
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002478static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302479 unsigned short RefreshRateTableIndex,
2480 struct xgi_hw_device_info *HwDeviceExtension,
2481 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002482{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302483 unsigned char index;
2484 unsigned short tempbx, i;
2485 struct XGI_LVDSCRT1HDataStruct *LCDPtr = NULL;
2486 struct XGI_LVDSCRT1VDataStruct *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002487
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302488 if (ModeNo <= 0x13)
2489 index = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
2490 else
2491 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002492
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302493 index = index & IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002494
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002495 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002496
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002497 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2498 LCDPtr = (struct XGI_LVDSCRT1HDataStruct *)
2499 XGI_GetLcdPtr(tempbx, ModeNo,
2500 ModeIdIndex,
2501 RefreshRateTableIndex,
2502 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002503
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002504 for (i = 0; i < 8; i++)
2505 pVBInfo->TimingH[0].data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302506 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002507
2508 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
2509
2510 tempbx = 1;
2511
2512 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
2513 LCDPtr1 = (struct XGI_LVDSCRT1VDataStruct *)
2514 XGI_GetLcdPtr(
2515 tempbx,
2516 ModeNo,
2517 ModeIdIndex,
2518 RefreshRateTableIndex,
2519 pVBInfo);
2520 for (i = 0; i < 7; i++)
2521 pVBInfo->TimingV[0].data[i] = LCDPtr1[0].Reg[i];
2522 }
2523
2524 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002525}
2526
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002527static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
2528{
2529 unsigned char tempal, tempah, tempbl, i;
2530
Aaro Koskinen58839b02011-03-13 12:26:23 +02002531 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002532 tempal = tempah & 0x0F;
2533 tempah = tempah & 0xF0;
2534 i = 0;
2535 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2536
2537 while (tempbl != 0xFF) {
2538 if (tempbl & 0x80) { /* OEMUtil */
2539 tempal = tempah;
2540 tempbl = tempbl & ~(0x80);
2541 }
2542
2543 if (tempal == tempbl)
2544 break;
2545
2546 i++;
2547
2548 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2549 }
2550
2551 return i;
2552}
2553
2554static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
2555{
2556 unsigned short tempah, tempal, tempbl, i;
2557
2558 tempal = pVBInfo->LCDResInfo;
2559 tempah = pVBInfo->LCDTypeInfo;
2560
2561 i = 0;
2562 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2563
2564 while (tempbl != 0xFF) {
2565 if ((tempbl & 0x80) && (tempbl != 0x80)) {
2566 tempal = tempah;
2567 tempbl &= ~0x80;
2568 }
2569
2570 if (tempal == tempbl)
2571 break;
2572
2573 i++;
2574 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2575 }
2576
2577 if (tempbl == 0xFF) {
2578 pVBInfo->LCDResInfo = Panel1024x768;
2579 pVBInfo->LCDTypeInfo = 0;
2580 i = 0;
2581 }
2582
2583 return i;
2584}
2585
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002586static void XGI_GetLCDSync(unsigned short *HSyncWidth,
2587 unsigned short *VSyncWidth,
2588 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002589{
2590 unsigned short Index;
2591
2592 Index = XGI_GetLCDCapPtr(pVBInfo);
2593 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
2594 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
2595
2596 return;
2597}
2598
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002599static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302600 unsigned short RefreshRateTableIndex,
2601 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002602{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302603 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
2604 unsigned long temp, temp1, temp2, temp3, push3;
2605 struct XGI330_LCDDataDesStruct *LCDPtr = NULL;
2606 struct XGI330_LCDDataDesStruct2 *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002607
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302608 if (ModeNo > 0x13)
2609 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2610 else
2611 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002612
Aaro Koskinen66cface2011-08-31 21:46:13 +03002613 tempbx = 3;
2614 if (pVBInfo->LCDInfo & EnableScalingLCD)
2615 LCDPtr1 =
2616 (struct XGI330_LCDDataDesStruct2 *)
2617 XGI_GetLcdPtr(
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002618 tempbx,
2619 ModeNo,
2620 ModeIdIndex,
2621 RefreshRateTableIndex,
2622 pVBInfo);
Aaro Koskinen66cface2011-08-31 21:46:13 +03002623 else
2624 LCDPtr =
2625 (struct XGI330_LCDDataDesStruct *)
2626 XGI_GetLcdPtr(
2627 tempbx,
2628 ModeNo,
2629 ModeIdIndex,
2630 RefreshRateTableIndex,
2631 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002632
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002633 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
2634 push1 = tempbx;
2635 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002636
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002637 /* GetLCDResInfo */
2638 if ((pVBInfo->LCDResInfo == Panel1024x768) ||
2639 (pVBInfo->LCDResInfo == Panel1024x768x75)) {
2640 tempax = 1024;
2641 tempbx = 768;
2642 } else if ((pVBInfo->LCDResInfo == Panel1280x1024) ||
2643 (pVBInfo->LCDResInfo == Panel1280x1024x75)) {
2644 tempax = 1280;
2645 tempbx = 1024;
2646 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
2647 tempax = 1400;
2648 tempbx = 1050;
2649 } else {
2650 tempax = 1600;
2651 tempbx = 1200;
2652 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002653
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002654 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
2655 pVBInfo->HDE = tempax;
2656 pVBInfo->VDE = tempbx;
2657 pVBInfo->VGAHDE = tempax;
2658 pVBInfo->VGAVDE = tempbx;
2659 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002660
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002661 tempax = pVBInfo->HT;
2662
2663 if (pVBInfo->LCDInfo & EnableScalingLCD)
2664 tempbx = LCDPtr1->LCDHDES;
2665 else
2666 tempbx = LCDPtr->LCDHDES;
2667
2668 tempcx = pVBInfo->HDE;
2669 tempbx = tempbx & 0x0fff;
2670 tempcx += tempbx;
2671
2672 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002673 tempcx -= tempax;
2674
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002675 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002676
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002677 tempcx = tempcx >> 3;
2678 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002679
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002680 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
2681 (unsigned short) (tempbx & 0xff));
2682 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
2683 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002684
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002685 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002686
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002687 if (pVBInfo->LCDInfo & EnableScalingLCD)
2688 tempbx = LCDPtr1->LCDHRS;
2689 else
2690 tempbx = LCDPtr->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002691
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002692 tempcx = push2;
2693
2694 if (pVBInfo->LCDInfo & EnableScalingLCD)
2695 tempcx = LCDPtr1->LCDHSync;
2696
2697 tempcx += tempbx;
2698
2699 if (tempcx >= tempax)
2700 tempcx -= tempax;
2701
2702 tempax = tempbx & 0x07;
2703 tempax = tempax >> 5;
2704 tempcx = tempcx >> 3;
2705 tempbx = tempbx >> 3;
2706
2707 tempcx &= 0x1f;
2708 tempax |= tempcx;
2709
2710 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
2711 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
2712 (unsigned short) (tempbx & 0xff));
2713
2714 tempax = pVBInfo->VT;
2715 if (pVBInfo->LCDInfo & EnableScalingLCD)
2716 tempbx = LCDPtr1->LCDVDES;
2717 else
2718 tempbx = LCDPtr->LCDVDES;
2719 tempcx = pVBInfo->VDE;
2720
2721 tempbx = tempbx & 0x0fff;
2722 tempcx += tempbx;
2723 if (tempcx >= tempax)
2724 tempcx -= tempax;
2725
2726 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
2727 (unsigned short) (tempbx & 0xff));
2728 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
2729 (unsigned short) (tempcx & 0xff));
2730
2731 tempbx = (tempbx >> 8) & 0x07;
2732 tempcx = (tempcx >> 8) & 0x07;
2733
2734 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
2735 (unsigned short) ((tempcx << 3)
2736 | tempbx));
2737
2738 tempax = pVBInfo->VT;
2739 if (pVBInfo->LCDInfo & EnableScalingLCD)
2740 tempbx = LCDPtr1->LCDVRS;
2741 else
2742 tempbx = LCDPtr->LCDVRS;
2743
2744 /* tempbx = tempbx >> 4; */
2745 tempcx = push1;
2746
2747 if (pVBInfo->LCDInfo & EnableScalingLCD)
2748 tempcx = LCDPtr1->LCDVSync;
2749
2750 tempcx += tempbx;
2751 if (tempcx >= tempax)
2752 tempcx -= tempax;
2753
2754 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
2755 (unsigned short) (tempbx & 0xff));
2756 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
2757 (unsigned short) (tempcx & 0x0f));
2758
2759 tempax = ((tempbx >> 8) & 0x07) << 3;
2760
2761 tempbx = pVBInfo->VGAVDE;
2762 if (tempbx != pVBInfo->VDE)
2763 tempax |= 0x40;
2764
2765 if (pVBInfo->LCDInfo & EnableLVDSDDA)
2766 tempax |= 0x40;
2767
2768 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
2769 tempax);
2770
2771 tempcx = pVBInfo->VGAVT;
2772 tempbx = pVBInfo->VDE;
2773 tempax = pVBInfo->VGAVDE;
2774 tempcx -= tempax;
2775
2776 temp = tempax; /* 0430 ylshieh */
2777 temp1 = (temp << 18) / tempbx;
2778
2779 tempdx = (unsigned short) ((temp << 18) % tempbx);
2780
2781 if (tempdx != 0)
2782 temp1 += 1;
2783
2784 temp2 = temp1;
2785 push3 = temp2;
2786
2787 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
2788 (unsigned short) (temp2 & 0xff));
2789 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
2790 (unsigned short) ((temp2 >> 8) & 0xff));
2791
2792 tempbx = (unsigned short) (temp2 >> 16);
2793 tempax = tempbx & 0x03;
2794
2795 tempbx = pVBInfo->VGAVDE;
2796 if (tempbx == pVBInfo->VDE)
2797 tempax |= 0x04;
2798
2799 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
2800
2801 if (pVBInfo->VBType & VB_XGI301C) {
2802 temp2 = push3;
2803 xgifb_reg_set(pVBInfo->Part4Port,
2804 0x3c,
2805 (unsigned short) (temp2 & 0xff));
2806 xgifb_reg_set(pVBInfo->Part4Port,
2807 0x3b,
2808 (unsigned short) ((temp2 >> 8) &
2809 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002810 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002811 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
2812 ~0xc0,
2813 (unsigned short) ((tempbx &
2814 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002815
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002816 tempcx = pVBInfo->VGAVDE;
2817 if (tempcx == pVBInfo->VDE)
2818 xgifb_reg_and_or(pVBInfo->Part4Port,
2819 0x30, ~0x0c, 0x00);
2820 else
2821 xgifb_reg_and_or(pVBInfo->Part4Port,
2822 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302823 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002824
2825 tempcx = pVBInfo->VGAHDE;
2826 tempbx = pVBInfo->HDE;
2827
2828 temp1 = tempcx << 16;
2829
2830 tempax = (unsigned short) (temp1 / tempbx);
2831
2832 if ((tempbx & 0xffff) == (tempcx & 0xffff))
2833 tempax = 65535;
2834
2835 temp3 = tempax;
2836 temp1 = pVBInfo->VGAHDE << 16;
2837
2838 temp1 /= temp3;
2839 temp3 = temp3 << 16;
2840 temp1 -= 1;
2841
2842 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
2843
2844 tempax = (unsigned short) (temp3 & 0xff);
2845 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
2846
2847 temp1 = pVBInfo->VGAVDE << 18;
2848 temp1 = temp1 / push3;
2849 tempbx = (unsigned short) (temp1 & 0xffff);
2850
2851 if (pVBInfo->LCDResInfo == Panel1024x768)
2852 tempbx -= 1;
2853
2854 tempax = ((tempbx >> 8) & 0xff) << 3;
2855 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
2856 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
2857 (unsigned short) (tempax & 0xff));
2858 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
2859 (unsigned short) (tempbx & 0xff));
2860
2861 temp3 = temp3 >> 16;
2862
2863 if (modeflag & HalfDCLK)
2864 temp3 = temp3 >> 1;
2865
2866 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
2867 (unsigned short) ((temp3 >> 8) & 0xff));
2868 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
2869 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002870}
2871
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002872/* --------------------------------------------------------------------- */
2873/* Function : XGI_GETLCDVCLKPtr */
2874/* Input : */
2875/* Output : al -> VCLK Index */
2876/* Description : */
2877/* --------------------------------------------------------------------- */
2878static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
2879 struct vb_device_info *pVBInfo)
2880{
2881 unsigned short index;
2882
2883 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002884 /* index = XGI_GetLCDCapPtr(pVBInfo); */
2885 index = XGI_GetLCDCapPtr1(pVBInfo);
2886
2887 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
2888 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
2889 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
2890 } else { /* LCDA */
2891 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
2892 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
2893 }
2894 }
2895 return;
2896}
2897
2898static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
2899 unsigned short ModeNo, unsigned short ModeIdIndex,
2900 struct vb_device_info *pVBInfo)
2901{
2902
2903 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002904 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002905
2906 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002907 /* si+St_ResInfo */
2908 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002909 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002910 /* si+Ext_ResInfo */
2911 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002912
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002913 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
2914 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002915 index = XGI_GetLCDCapPtr(pVBInfo);
2916 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
2917
2918 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
2919 return tempal;
2920
2921 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002922 if (pVBInfo->VBType &
2923 (VB_XGI301B |
2924 VB_XGI302B |
2925 VB_XGI301LV |
2926 VB_XGI302LV |
2927 VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002928 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
2929 tempal = HiTVVCLKDIV2;
2930 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2931 tempal = HiTVVCLK;
2932 if (pVBInfo->TVInfo & TVSimuMode) {
2933 tempal = HiTVSimuVCLK;
2934 if (!(modeflag & Charx8Dot))
2935 tempal = HiTVTextVCLK;
2936
2937 }
2938 return tempal;
2939 }
2940
2941 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
2942 tempal = YPbPr750pVCLK;
2943 return tempal;
2944 }
2945
2946 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
2947 tempal = YPbPr525pVCLK;
2948 return tempal;
2949 }
2950
2951 tempal = NTSC1024VCLK;
2952
2953 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
2954 tempal = TVVCLKDIV2;
2955 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
2956 tempal = TVVCLK;
2957 }
2958
2959 if (pVBInfo->VBInfo & SetCRT2ToTV)
2960 return tempal;
2961 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002962 } /* {End of VB} */
2963
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002964 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002965 tempal = tempal >> 2;
2966 tempal &= 0x03;
2967
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002968 /* for Dot8 Scaling LCD */
2969 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002970 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
2971
2972 if (ModeNo <= 0x13)
2973 return tempal;
2974
2975 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
2976 return tempal;
2977}
2978
2979static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
2980 unsigned char *di_1, struct vb_device_info *pVBInfo)
2981{
Aaro Koskinen83f76a92011-08-31 21:45:58 +03002982 if (pVBInfo->VBType & (VB_XGI301 | VB_XGI301B | VB_XGI302B
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002983 | VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
2984 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) && (pVBInfo->SetFlag
2985 & ProgrammingCRT2)) {
2986 *di_0 = (unsigned char) XGI_VBVCLKData[tempal].SR2B;
2987 *di_1 = XGI_VBVCLKData[tempal].SR2C;
2988 }
2989 } else {
2990 *di_0 = XGI_VCLKData[tempal].SR2B;
2991 *di_1 = XGI_VCLKData[tempal].SR2C;
2992 }
2993}
2994
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002995static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302996 unsigned short RefreshRateTableIndex,
2997 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002998{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302999 unsigned char di_0, di_1, tempal;
3000 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003001
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303002 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
3003 pVBInfo);
3004 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
3005 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003006
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303007 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003008 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303009 (unsigned short) (0x10 * i));
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003010 if ((!(pVBInfo->VBInfo & SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303011 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003012 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
3013 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303014 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003015 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
3016 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303017 }
3018 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003019}
3020
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003021static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303022 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003023{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303024 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003025
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303026 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
3027 | VB_XGI302LV | VB_XGI301C)) {
3028 tempcl = 0;
3029 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003030 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003031
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303032 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003033 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303034 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003035 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303036 if (!(temp & 0x40))
3037 tempcl |= ActiveCRT1;
3038 }
3039 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003040
Aaro Koskinen58839b02011-03-13 12:26:23 +02003041 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303042 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003043
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303044 if (!(temp == 0x08)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003045 /* Check ChannelA by Part1_13 [2003/10/03] */
3046 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303047 if (tempax & 0x04)
3048 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003049
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303050 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303052 if (!(tempcl & ActiveLCD))
3053 if (temp == 0x01)
3054 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003055
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303056 if (temp == 0x04)
3057 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003058
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303059 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003060 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003061
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303062 if (!(temp & 0x08))
3063 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003064
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303065 if (!(temp & 0x04))
3066 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003067
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303068 if (temp & 0x02)
3069 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003070
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303071 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3072 if (temp & 0x01)
3073 tempch |= ActiveHiTV;
3074 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003075
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303076 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003077 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303078 pVBInfo->Part2Port,
3079 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003080
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303081 if (temp & 0x10)
3082 tempch |= ActiveYPbPr;
3083 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003084
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303085 if (tempch != 0)
3086 tempcl |= ActiveTV;
3087 }
3088 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003089
Aaro Koskinen58839b02011-03-13 12:26:23 +02003090 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303091 if (tempcl & ActiveLCD) {
3092 if ((pVBInfo->SetFlag & ReserveTVOption)) {
3093 if (temp & ActiveTV)
3094 tempcl |= ActiveTV;
3095 }
3096 }
3097 temp = tempcl;
3098 tempbl = ~ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003099 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303101 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003102 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303103 } else {
3104 return;
3105 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003106}
3107
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303108void XGI_GetVGAType(struct xgi_hw_device_info *HwDeviceExtension,
3109 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003110{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303111 /*
3112 if ( HwDeviceExtension->jChipType >= XG20 ) {
3113 pVBInfo->Set_VGAType = XG20;
Aaro Koskinen06587332011-03-13 12:26:10 +02003114 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303115 pVBInfo->Set_VGAType = VGA_XGI340;
3116 }
3117 */
3118 pVBInfo->Set_VGAType = HwDeviceExtension->jChipType;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003119}
3120
Bill Pemberton80adad82010-06-17 13:10:51 -04003121void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003122{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303123 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003124
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303125 if (pVBInfo->IF_DEF_LVDS == 0) {
3126 tempbx = VB_XGI302B;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003127 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303128 if (flag != 0x02) {
3129 tempbx = VB_XGI301;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003130 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303131 if (flag >= 0xB0) {
3132 tempbx = VB_XGI301B;
3133 if (flag >= 0xC0) {
3134 tempbx = VB_XGI301C;
3135 if (flag >= 0xD0) {
3136 tempbx = VB_XGI301LV;
3137 if (flag >= 0xE0) {
3138 tempbx = VB_XGI302LV;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003139 tempah = xgifb_reg_get(
3140 pVBInfo->Part4Port,
3141 0x39);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303142 if (tempah != 0xFF)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003143 tempbx =
3144 VB_XGI301C;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303145 }
3146 }
3147 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003148
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303149 if (tempbx & (VB_XGI301B | VB_XGI302B)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003150 flag = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303151 pVBInfo->Part4Port,
3152 0x23);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003153
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303154 if (!(flag & 0x02))
3155 tempbx = tempbx | VB_NoLCD;
3156 }
3157 }
3158 }
3159 pVBInfo->VBType = tempbx;
3160 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003161}
3162
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303163void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3164 struct xgi_hw_device_info *HwDeviceExtension,
3165 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003166{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303167 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003168
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303169 if (ModeNo <= 0x13)
3170 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3171 else
3172 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003173
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303174 pVBInfo->SetFlag = 0;
3175 pVBInfo->ModeType = modeflag & ModeInfoFlag;
3176 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003177
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303178 if (pVBInfo->VBType & 0xFFFF) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003179 /* Check Display Device */
3180 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303181 tempbx = tempbx | temp;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003182 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303183 push = temp;
3184 push = push << 8;
3185 tempax = temp << 8;
3186 tempbx = tempbx | tempax;
3187 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr | SetCRT2ToLCDA
3188 | SetInSlaveMode | DisableCRT2Display);
3189 temp = 0xFFFF ^ temp;
3190 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003191
Aaro Koskinen58839b02011-03-13 12:26:23 +02003192 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003193
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303194 if (pVBInfo->IF_DEF_LCDA == 1) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003195
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303196 if ((pVBInfo->Set_VGAType >= XG20)
3197 || (pVBInfo->Set_VGAType >= XG40)) {
3198 if (pVBInfo->IF_DEF_LVDS == 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003199 /* if ((pVBInfo->VBType & VB_XGI302B)
3200 || (pVBInfo->VBType & VB_XGI301LV)
3201 || (pVBInfo->VBType & VB_XGI302LV)
3202 || (pVBInfo->VBType & VB_XGI301C))
3203 */
3204 if (pVBInfo->VBType &
3205 (VB_XGI302B |
3206 VB_XGI301LV |
3207 VB_XGI302LV |
3208 VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303209 if (temp & EnableDualEdge) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003210 tempbx |=
3211 SetCRT2ToDualEdge;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003212
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303213 if (temp & SetToLCDA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003214 tempbx |=
3215 SetCRT2ToLCDA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303216 }
3217 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303218 }
3219 }
3220 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003221
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303222 if (pVBInfo->IF_DEF_YPbPr == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003223 /* [Billy] 07/05/04 */
3224 if (((pVBInfo->IF_DEF_LVDS == 0) &&
3225 ((pVBInfo->VBType & VB_XGI301LV) ||
3226 (pVBInfo->VBType & VB_XGI302LV) ||
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003227 (pVBInfo->VBType & VB_XGI301C)))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303228 if (temp & SetYPbPr) { /* temp = CR38 */
3229 if (pVBInfo->IF_DEF_HiVision == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003230 /* shampoo add for new
3231 * scratch */
Aaro Koskinen58839b02011-03-13 12:26:23 +02003232 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303233 pVBInfo->P3d4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003234 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303235 temp &= YPbPrMode;
3236 tempbx |= SetCRT2ToHiVisionTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003237
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303238 if (temp != YPbPrMode1080i) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003239 tempbx &=
3240 (~SetCRT2ToHiVisionTV);
3241 tempbx |=
3242 SetCRT2ToYPbPr;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303243 }
3244 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003245
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303246 /* tempbx |= SetCRT2ToYPbPr; */
3247 }
3248 }
3249 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003250
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303251 tempax = push; /* restore CR31 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003252
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303253 if (pVBInfo->IF_DEF_LVDS == 0) {
3254 if (pVBInfo->IF_DEF_YPbPr == 1) {
3255 if (pVBInfo->IF_DEF_HiVision == 1)
3256 temp = 0x09FC;
3257 else
3258 temp = 0x097C;
3259 } else {
3260 if (pVBInfo->IF_DEF_HiVision == 1)
3261 temp = 0x01FC;
3262 else
3263 temp = 0x017C;
3264 }
3265 } else { /* 3nd party chip */
Aaro Koskinen83f76a92011-08-31 21:45:58 +03003266 temp = SetCRT2ToLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303267 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003268
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303269 if (!(tempbx & temp)) {
3270 tempax |= DisableCRT2Display;
3271 tempbx = 0;
3272 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003273
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303274 if (pVBInfo->IF_DEF_LCDA == 1) { /* Select Display Device */
3275 if (!(pVBInfo->VBType & VB_NoLCD)) {
3276 if (tempbx & SetCRT2ToLCDA) {
3277 if (tempbx & SetSimuScanMode)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003278 tempbx &= (~(SetCRT2ToLCD |
3279 SetCRT2ToRAMDAC |
3280 SwitchToCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303281 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003282 tempbx &= (~(SetCRT2ToLCD |
3283 SetCRT2ToRAMDAC |
3284 SetCRT2ToTV |
3285 SwitchToCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303286 }
3287 }
3288 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003289
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303290 /* shampoo add */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003291 /* for driver abnormal */
3292 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303293 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
3294 if (tempbx & SetCRT2ToRAMDAC) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003295 tempbx &= (0xFF00 |
3296 SetCRT2ToRAMDAC |
3297 SwitchToCRT2 |
3298 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303299 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3300 }
3301 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003302 tempbx &= (~(SetCRT2ToRAMDAC |
3303 SetCRT2ToLCD |
3304 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303305 }
3306 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003307
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303308 if (!(pVBInfo->VBType & VB_NoLCD)) {
3309 if (tempbx & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003310 tempbx &= (0xFF00 |
3311 SetCRT2ToLCD |
3312 SwitchToCRT2 |
3313 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303314 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3315 }
3316 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003317
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303318 if (tempbx & SetCRT2ToSCART) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003319 tempbx &= (0xFF00 |
3320 SetCRT2ToSCART |
3321 SwitchToCRT2 |
3322 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303323 tempbx &= (0x00FF | (~SetCRT2ToYPbPr));
3324 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003325
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303326 if (pVBInfo->IF_DEF_YPbPr == 1) {
3327 if (tempbx & SetCRT2ToYPbPr)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003328 tempbx &= (0xFF00 |
3329 SwitchToCRT2 |
3330 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303331 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003332
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303333 if (pVBInfo->IF_DEF_HiVision == 1) {
3334 if (tempbx & SetCRT2ToHiVisionTV)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003335 tempbx &= (0xFF00 |
3336 SetCRT2ToHiVisionTV |
3337 SwitchToCRT2 |
3338 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303339 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003340
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303341 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
3342 if (!(tempbx & (SwitchToCRT2 | SetSimuScanMode)))
3343 tempbx = DisableCRT2Display;
3344 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003345
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303346 if (!(tempbx & DisableCRT2Display)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003347 if ((!(tempbx & DriverMode)) ||
3348 (!(modeflag & CRT2Mode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303349 if (pVBInfo->IF_DEF_LCDA == 1) {
3350 if (!(tempbx & SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003351 tempbx |= (SetInSlaveMode |
3352 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303353 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303354 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003355
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003356 /* LCD+TV can't support in slave mode
3357 * (Force LCDA+TV->LCDB) */
3358 if ((tempbx & SetInSlaveMode) &&
3359 (tempbx & SetCRT2ToLCDA)) {
3360 tempbx ^= (SetCRT2ToLCD |
3361 SetCRT2ToLCDA |
3362 SetCRT2ToDualEdge);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303363 pVBInfo->SetFlag |= ReserveTVOption;
3364 }
3365 }
3366 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003367
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303368 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003369}
3370
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303371void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
3372 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003373{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303374 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003375
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303376 tempbx = 0;
3377 resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003378
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303379 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3380 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003381 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].
3382 St_ModeFlag; /* si+St_ModeFlag */
3383 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].
3384 St_ResInfo; /* si+St_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303385 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003386 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].
3387 Ext_ModeFlag;
3388 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].
3389 Ext_RESINFO; /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303390 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003391
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303392 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003393 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303394 tempbx = temp;
3395 if (tempbx & SetPALTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003396 tempbx &= (SetCHTVOverScan |
3397 SetPALMTV |
3398 SetPALNTV |
3399 SetPALTV);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303400 if (tempbx & SetPALMTV)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003401 /* set to NTSC if PAL-M */
3402 tempbx &= ~SetPALTV;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303403 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003404 tempbx &= (SetCHTVOverScan |
3405 SetNTSCJ |
3406 SetPALTV);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303407 /*
3408 if (pVBInfo->IF_DEF_LVDS == 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003409 //PAL-M/PAL-N Info
3410 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x38);
3411 //00:PAL, 01:PAL-M, 10:PAL-N
3412 temp2 = (index1 & 0xC0) >> 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303413 tempbx |= temp2;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003414 if (temp2 & 0x02) //PAL-M
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303415 tempbx &= (~SetPALTV);
3416 }
3417 */
3418 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003419
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303420 if (pVBInfo->IF_DEF_LVDS == 0) {
3421 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3422 tempbx |= SetPALTV;
3423 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003424
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303425 if (pVBInfo->IF_DEF_YPbPr == 1) {
3426 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003427 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303428 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003429
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303430 if (index1 == YPbPrMode525i)
3431 tempbx |= SetYPbPrMode525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003432
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303433 if (index1 == YPbPrMode525p)
3434 tempbx = tempbx | SetYPbPrMode525p;
3435 if (index1 == YPbPrMode750p)
3436 tempbx = tempbx | SetYPbPrMode750p;
3437 }
3438 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003439
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303440 if (pVBInfo->IF_DEF_HiVision == 1) {
3441 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
3442 tempbx = tempbx | SetYPbPrMode1080i | SetPALTV;
3443 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003444
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303445 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003446 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
3447 (!(pVBInfo->VBInfo & SetNotSimuMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303448 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003449
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003450 if (!(tempbx & SetPALTV) &&
3451 (modeflag > 13) &&
3452 (resinfo == 8)) /* NTSC 1024x768, */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303453 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003454
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303455 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003456
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303457 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
3458 if (pVBInfo->VBInfo & SetInSlaveMode)
3459 tempbx &= (~RPLLDIV2XO);
3460 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003461 if (tempbx &
3462 (SetYPbPrMode525p | SetYPbPrMode750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303463 tempbx &= (~RPLLDIV2XO);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003464 else if (!(pVBInfo->VBType &
3465 (VB_XGI301B |
3466 VB_XGI302B |
3467 VB_XGI301LV |
3468 VB_XGI302LV |
3469 VB_XGI301C))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303470 if (tempbx & TVSimuMode)
3471 tempbx &= (~RPLLDIV2XO);
3472 }
3473 }
3474 }
3475 }
3476 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003477}
3478
Bill Pemberton108afbf2010-06-17 13:10:47 -04003479unsigned char XGI_GetLCDInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303480 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003481{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303482 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003483
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303484 pVBInfo->LCDResInfo = 0;
3485 pVBInfo->LCDTypeInfo = 0;
3486 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003487
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303488 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003489 /* si+St_ModeFlag // */
3490 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303491 } else {
3492 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003493 /* si+Ext_ResInfo // */
3494 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303495 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003496
Aaro Koskinen58839b02011-03-13 12:26:23 +02003497 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303498 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003499
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303500 if (tempbx == 0)
3501 tempbx = Panel1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003502
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303503 /* LCD75 [2003/8/22] Vicent */
3504 if ((tempbx == Panel1024x768) || (tempbx == Panel1280x1024)) {
3505 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003506 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303507 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
3508 tempax &= 0x0F;
3509 else
3510 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003511
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303512 if ((resinfo == 6) || (resinfo == 9)) {
3513 if (tempax >= 3)
3514 tempbx |= PanelRef75Hz;
3515 } else if ((resinfo == 7) || (resinfo == 8)) {
3516 if (tempax >= 4)
3517 tempbx |= PanelRef75Hz;
3518 }
3519 }
3520 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003521
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303522 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003523
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303524 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003525
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303526 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
3527 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003528
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303529 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003530
Aaro Koskinen58839b02011-03-13 12:26:23 +02003531 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003532
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303533 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003534
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303535 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003536
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303537 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003538
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303539 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003540
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303541 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
3542 if (((pVBInfo->VBType & VB_XGI302LV) || (pVBInfo->VBType
3543 & VB_XGI301C)) && (tempax & LCDDualLink)) {
3544 tempbx |= SetLCDDualLink;
3545 }
3546 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003547
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303548 if (pVBInfo->IF_DEF_LVDS == 0) {
3549 if ((pVBInfo->LCDResInfo == Panel1400x1050) && (pVBInfo->VBInfo
3550 & SetCRT2ToLCD) && (ModeNo > 0x13) && (resinfo
3551 == 9) && (!(tempbx & EnableScalingLCD)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003552 /* set to center in 1280x1024 LCDB for Panel1400x1050 */
3553 tempbx |= SetLCDtoNonExpanding;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303554 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003555
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303556 /*
3557 if (tempax & LCDBToA) {
3558 tempbx |= SetLCDBToA;
3559 }
3560 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003561
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303562 if (pVBInfo->IF_DEF_ExpLink == 1) {
3563 if (modeflag & HalfDCLK) {
3564 /* if (!(pVBInfo->LCDInfo&LCDNonExpanding)) */
3565 if (!(tempbx & SetLCDtoNonExpanding)) {
3566 tempbx |= EnableLVDSDDA;
3567 } else {
3568 if (ModeNo > 0x13) {
3569 if (pVBInfo->LCDResInfo
3570 == Panel1024x768) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003571 if (resinfo == 4) {/* 512x384 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303572 tempbx |= EnableLVDSDDA;
3573 }
3574 }
3575 }
3576 }
3577 }
3578 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003579
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303580 if (pVBInfo->VBInfo & SetInSlaveMode) {
3581 if (pVBInfo->VBInfo & SetNotSimuMode)
3582 tempbx |= LCDVESATiming;
3583 } else {
3584 tempbx |= LCDVESATiming;
3585 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003586
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303587 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003588
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303589 if (pVBInfo->IF_DEF_LVDS == 0) {
3590 if (tempax & (LockLCDBToA | StLCDBToA)) {
3591 if (pVBInfo->VBInfo & SetInSlaveMode) {
3592 if (!(tempax & LockLCDBToA)) {
3593 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003594 pVBInfo->VBInfo &=
3595 ~(SetSimuScanMode |
3596 SetInSlaveMode |
3597 SetCRT2ToLCD);
3598 pVBInfo->VBInfo |=
3599 SetCRT2ToLCDA |
3600 SetCRT2ToDualEdge;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303601 }
3602 }
3603 }
3604 }
3605 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003606
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303607 /*
3608 if (pVBInfo->IF_DEF_LVDS == 0) {
3609 if (tempax & (LockLCDBToA | StLCDBToA)) {
3610 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003611 if (!((!(tempax & LockLCDBToA)) &&
3612 (ModeNo > 0x13))) {
3613 pVBInfo->VBInfo &=
3614 ~(SetSimuScanMode |
3615 SetInSlaveMode |
3616 SetCRT2ToLCD);
3617 pVBInfo->VBInfo |=
3618 SetCRT2ToLCDA |
3619 SetCRT2ToDualEdge;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303620 }
3621 }
3622 }
3623 }
3624 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003625
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303626 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003627}
3628
Bill Pemberton108afbf2010-06-17 13:10:47 -04003629unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303630 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003631{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303632 if (ModeNo <= 5)
3633 ModeNo |= 1;
3634 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003635 /* for (*ModeIdIndex=0;
3636 *ModeIdIndex < sizeof(pVBInfo->SModeIDTable)
3637 / sizeof(struct XGI_StStruct);
3638 (*ModeIdIndex)++) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303639 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003640 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3641 ModeNo)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303642 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003643 if (pVBInfo->SModeIDTable[*ModeIdIndex].St_ModeID ==
3644 0xFF)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303645 return 0;
3646 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003647
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303648 if (ModeNo == 0x07)
3649 (*ModeIdIndex)++; /* 400 lines */
3650 if (ModeNo <= 3)
3651 (*ModeIdIndex) += 2; /* 400 lines */
3652 /* else 350 lines */
3653 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003654 /* for (*ModeIdIndex=0;
3655 *ModeIdIndex < sizeof(pVBInfo->EModeIDTable)
3656 / sizeof(struct XGI_ExtStruct);
3657 (*ModeIdIndex)++) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303658 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003659 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3660 ModeNo)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303661 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003662 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID ==
3663 0xFF)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303664 return 0;
3665 }
3666 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003667
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303668 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003669}
3670
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003671static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
3672{
3673 unsigned char ujRet = 0;
3674 unsigned char i = 0;
3675
3676 for (i = 0; i < 8; i++) {
3677 ujRet = ujRet << 1;
3678 /* ujRet |= GETBITS(ujDate >> i, 0:0); */
3679 ujRet |= (ujDate >> i) & 1;
3680 }
3681
3682 return ujRet;
3683}
3684
3685/*----------------------------------------------------------------------------*/
3686/* output */
3687/* bl[5] : LVDS signal */
3688/* bl[1] : LVDS backlight */
3689/* bl[0] : LVDS VDD */
3690/*----------------------------------------------------------------------------*/
3691static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
3692{
3693 unsigned char CR4A, temp;
3694
Aaro Koskinen58839b02011-03-13 12:26:23 +02003695 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02003696 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003697
Aaro Koskinen58839b02011-03-13 12:26:23 +02003698 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003699
3700 temp = XG21GPIODataTransfer(temp);
3701 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003702 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003703 return temp;
3704}
3705
3706/*----------------------------------------------------------------------------*/
3707/* output */
3708/* bl[5] : LVDS signal */
3709/* bl[1] : LVDS backlight */
3710/* bl[0] : LVDS VDD */
3711/*----------------------------------------------------------------------------*/
3712static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
3713{
3714 unsigned char CR4A, CRB4, temp;
3715
Aaro Koskinen58839b02011-03-13 12:26:23 +02003716 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02003717 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003718
Aaro Koskinen58839b02011-03-13 12:26:23 +02003719 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003720
3721 temp &= 0x0C;
3722 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003723 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003724 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003725 temp |= ((CRB4 & 0x04) << 3);
3726 return temp;
3727}
3728
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303729void XGI_DisplayOn(struct xgi_hw_device_info *pXGIHWDE,
3730 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003731{
3732
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003733 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303734 if (pXGIHWDE->jChipType == XG21) {
3735 if (pVBInfo->IF_DEF_LVDS == 1) {
3736 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003737 /* LVDS VDD on */
3738 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303739 XGI_XG21SetPanelDelay(2, pVBInfo);
3740 }
3741 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003742 /* LVDS signal on */
3743 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303744 XGI_XG21SetPanelDelay(3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003745 /* LVDS backlight on */
3746 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303747 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003748 /* DVO/DVI signal on */
3749 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303750 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003751
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303752 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003753
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303754 if (pXGIHWDE->jChipType == XG27) {
3755 if (pVBInfo->IF_DEF_LVDS == 1) {
3756 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003757 /* LVDS VDD on */
3758 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303759 XGI_XG21SetPanelDelay(2, pVBInfo);
3760 }
3761 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003762 /* LVDS signal on */
3763 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303764 XGI_XG21SetPanelDelay(3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003765 /* LVDS backlight on */
3766 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303767 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003768 /* DVO/DVI signal on */
3769 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303770 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003771
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303772 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003773}
3774
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303775void XGI_DisplayOff(struct xgi_hw_device_info *pXGIHWDE,
3776 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003777{
3778
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303779 if (pXGIHWDE->jChipType == XG21) {
3780 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003781 /* LVDS backlight off */
3782 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303783 XGI_XG21SetPanelDelay(3, pVBInfo);
3784 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003785 /* DVO/DVI signal off */
3786 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303787 }
3788 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003789
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303790 if (pXGIHWDE->jChipType == XG27) {
3791 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003792 /* LVDS backlight off */
3793 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303794 XGI_XG21SetPanelDelay(3, pVBInfo);
3795 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303797 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003798 /* DVO/DVI signal off */
3799 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303800 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003801
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003802 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003803}
3804
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003805static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003806{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003807 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303808 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003809
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003810 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303811 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003812}
3813
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003814static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003815{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03003816 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003817}
3818
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003819static void XGI_SaveCRT2Info(unsigned short ModeNo,
3820 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003821{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303822 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003823
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003824 /* reserve CR34 for CRT1 Mode No */
3825 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303826 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
3827 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003828 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003829}
3830
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003831static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
3832 unsigned short ModeIdIndex,
3833 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003834{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303835 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003836
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303837 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
3838 if (ModeNo <= 0x13) {
3839 xres = pVBInfo->StResInfo[resindex].HTotal;
3840 yres = pVBInfo->StResInfo[resindex].VTotal;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003841 /* si+St_ResInfo */
3842 /* modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;*/
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303843 } else {
3844 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
3845 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003846 /* si+St_ModeFlag */
3847 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003848
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303849 /*
3850 if (pVBInfo->IF_DEF_FSTN) {
3851 xres *= 2;
3852 yres *= 2;
3853 } else {
3854 */
3855 if (modeflag & HalfDCLK)
3856 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003857
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303858 if (modeflag & DoubleScanMode)
3859 yres *= 2;
3860 /* } */
3861 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003862
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303863 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
3864 if (pVBInfo->IF_DEF_LVDS == 0) {
3865 if (pVBInfo->LCDResInfo == Panel1600x1200) {
3866 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
3867 if (yres == 1024)
3868 yres = 1056;
3869 }
3870 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003871
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303872 if (pVBInfo->LCDResInfo == Panel1280x1024) {
3873 if (yres == 400)
3874 yres = 405;
3875 else if (yres == 350)
3876 yres = 360;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003877
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303878 if (pVBInfo->LCDInfo & LCDVESATiming) {
3879 if (yres == 360)
3880 yres = 375;
3881 }
3882 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003883
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303884 if (pVBInfo->LCDResInfo == Panel1024x768) {
3885 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
3886 if (!(pVBInfo->LCDInfo
3887 & LCDNonExpanding)) {
3888 if (yres == 350)
3889 yres = 357;
3890 else if (yres == 400)
3891 yres = 420;
3892 else if (yres == 480)
3893 yres = 525;
3894 }
3895 }
3896 }
3897 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003898
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303899 if (xres == 720)
3900 xres = 640;
3901 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003902
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303903 pVBInfo->VGAHDE = xres;
3904 pVBInfo->HDE = xres;
3905 pVBInfo->VGAVDE = yres;
3906 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003907}
3908
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003909static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003910{
3911
Dan Carpentera65fd092011-01-04 09:02:27 +03003912 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) &&
3913 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303914 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003915
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303916 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003917}
3918
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003919static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
3920 unsigned short ModeIdIndex,
3921 unsigned short RefreshRateTableIndex,
3922 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003923{
3924 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
3925 StandTableIndex, CRT1Index;
3926
3927 pVBInfo->RVBHCMAX = 1;
3928 pVBInfo->RVBHCFACT = 1;
3929
3930 if (ModeNo <= 0x13) {
3931 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
3932 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
3933 tempax = pVBInfo->StandTable[StandTableIndex].CRTC[0];
3934 tempbx = pVBInfo->StandTable[StandTableIndex].CRTC[6];
3935 temp1 = pVBInfo->StandTable[StandTableIndex].CRTC[7];
3936 } else {
3937 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003938 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
3939 Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003940 CRT1Index &= IndexMask;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003941 temp1 = (unsigned short) pVBInfo->
3942 XGINEWUB_CRT1Table[CRT1Index].CR[0];
3943 temp2 = (unsigned short) pVBInfo->
3944 XGINEWUB_CRT1Table[CRT1Index].CR[5];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003945 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003946 tempbx = (unsigned short) pVBInfo->
3947 XGINEWUB_CRT1Table[CRT1Index].CR[8];
3948 tempcx = (unsigned short) pVBInfo->
3949 XGINEWUB_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003950 tempcx &= 0x0100;
3951 tempcx = tempcx << 2;
3952 tempbx |= tempcx;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003953 temp1 = (unsigned short) pVBInfo->
3954 XGINEWUB_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003955 }
3956
3957 if (temp1 & 0x01)
3958 tempbx |= 0x0100;
3959
3960 if (temp1 & 0x20)
3961 tempbx |= 0x0200;
3962 tempax += 5;
3963
3964 if (modeflag & Charx8Dot)
3965 tempax *= 8;
3966 else
3967 tempax *= 9;
3968
3969 pVBInfo->VGAHT = tempax;
3970 pVBInfo->HT = tempax;
3971 tempbx++;
3972 pVBInfo->VGAVT = tempbx;
3973 pVBInfo->VT = tempbx;
3974}
3975
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003976static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303977 unsigned short RefreshRateTableIndex,
3978 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003979{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303980 unsigned short tempax = 0, tempbx, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003981
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303982 struct XGI_LCDDataStruct *LCDPtr = NULL;
3983 struct XGI_TVDataStruct *TVPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003984
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303985 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003986 /* si+St_ResInfo */
3987 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303988 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
3989 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003990 /* si+Ext_ResInfo */
3991 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303992 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3993 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003994
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303995 pVBInfo->NewFlickerMode = 0;
3996 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003997
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303998 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3999 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4000 pVBInfo);
4001 return;
4002 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004003
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304004 tempbx = 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004005
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304006 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
4007 LCDPtr = (struct XGI_LCDDataStruct *) XGI_GetLcdPtr(tempbx,
4008 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4009 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004010
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304011 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
4012 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
4013 pVBInfo->VGAHT = LCDPtr->VGAHT;
4014 pVBInfo->VGAVT = LCDPtr->VGAVT;
4015 pVBInfo->HT = LCDPtr->LCDHT;
4016 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004017
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304018 if (pVBInfo->LCDResInfo == Panel1024x768) {
4019 tempax = 1024;
4020 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004021
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304022 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4023 if (pVBInfo->VGAVDE == 357)
4024 tempbx = 527;
4025 else if (pVBInfo->VGAVDE == 420)
4026 tempbx = 620;
4027 else if (pVBInfo->VGAVDE == 525)
4028 tempbx = 775;
4029 else if (pVBInfo->VGAVDE == 600)
4030 tempbx = 775;
4031 /* else if (pVBInfo->VGAVDE==350) tempbx=560; */
4032 /* else if (pVBInfo->VGAVDE==400) tempbx=640; */
4033 else
4034 tempbx = 768;
4035 } else
4036 tempbx = 768;
4037 } else if (pVBInfo->LCDResInfo == Panel1024x768x75) {
4038 tempax = 1024;
4039 tempbx = 768;
4040 } else if (pVBInfo->LCDResInfo == Panel1280x1024) {
4041 tempax = 1280;
4042 if (pVBInfo->VGAVDE == 360)
4043 tempbx = 768;
4044 else if (pVBInfo->VGAVDE == 375)
4045 tempbx = 800;
4046 else if (pVBInfo->VGAVDE == 405)
4047 tempbx = 864;
4048 else
4049 tempbx = 1024;
4050 } else if (pVBInfo->LCDResInfo == Panel1280x1024x75) {
4051 tempax = 1280;
4052 tempbx = 1024;
4053 } else if (pVBInfo->LCDResInfo == Panel1280x960) {
4054 tempax = 1280;
4055 if (pVBInfo->VGAVDE == 350)
4056 tempbx = 700;
4057 else if (pVBInfo->VGAVDE == 400)
4058 tempbx = 800;
4059 else if (pVBInfo->VGAVDE == 1024)
4060 tempbx = 960;
4061 else
4062 tempbx = 960;
4063 } else if (pVBInfo->LCDResInfo == Panel1400x1050) {
4064 tempax = 1400;
4065 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004066
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304067 if (pVBInfo->VGAVDE == 1024) {
4068 tempax = 1280;
4069 tempbx = 1024;
4070 }
4071 } else if (pVBInfo->LCDResInfo == Panel1600x1200) {
4072 tempax = 1600;
4073 tempbx = 1200; /* alan 10/14/2003 */
4074 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4075 if (pVBInfo->VGAVDE == 350)
4076 tempbx = 875;
4077 else if (pVBInfo->VGAVDE == 400)
4078 tempbx = 1000;
4079 }
4080 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004081
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304082 if (pVBInfo->LCDInfo & LCDNonExpanding) {
4083 tempax = pVBInfo->VGAHDE;
4084 tempbx = pVBInfo->VGAVDE;
4085 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004086
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304087 pVBInfo->HDE = tempax;
4088 pVBInfo->VDE = tempbx;
4089 return;
4090 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004091
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304092 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
4093 tempbx = 4;
4094 TVPtr = (struct XGI_TVDataStruct *) XGI_GetTVPtr(tempbx,
4095 ModeNo, ModeIdIndex, RefreshRateTableIndex,
4096 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004097
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304098 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
4099 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
4100 pVBInfo->VGAHT = TVPtr->VGAHT;
4101 pVBInfo->VGAVT = TVPtr->VGAVT;
4102 pVBInfo->HDE = TVPtr->TVHDE;
4103 pVBInfo->VDE = TVPtr->TVVDE;
4104 pVBInfo->RVBHRS = TVPtr->RVBHRS;
4105 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004106
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304107 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4108 if (resinfo == 0x08)
4109 pVBInfo->NewFlickerMode = 0x40;
4110 else if (resinfo == 0x09)
4111 pVBInfo->NewFlickerMode = 0x40;
4112 else if (resinfo == 0x12)
4113 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004114
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304115 if (pVBInfo->VGAVDE == 350)
4116 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004117
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304118 tempax = ExtHiTVHT;
4119 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004120
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304121 if (pVBInfo->VBInfo & SetInSlaveMode) {
4122 if (pVBInfo->TVInfo & TVSimuMode) {
4123 tempax = StHiTVHT;
4124 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004125
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304126 if (!(modeflag & Charx8Dot)) {
4127 tempax = StHiTextTVHT;
4128 tempbx = StHiTextTVVT;
4129 }
4130 }
4131 }
4132 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
4133 if (pVBInfo->TVInfo & SetYPbPrMode750p) {
4134 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
4135 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
4136 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004137
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304138 if (pVBInfo->TVInfo & SetYPbPrMode525p) {
4139 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
4140 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
4141 } else if (pVBInfo->TVInfo & SetYPbPrMode525i) {
4142 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
4143 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
4144 if (pVBInfo->TVInfo & NTSC1024x768)
4145 tempax = NTSC1024x768HT;
4146 }
4147 } else {
4148 tempax = PALHT;
4149 tempbx = PALVT;
4150 if (!(pVBInfo->TVInfo & SetPALTV)) {
4151 tempax = NTSCHT;
4152 tempbx = NTSCVT;
4153 if (pVBInfo->TVInfo & NTSC1024x768)
4154 tempax = NTSC1024x768HT;
4155 }
4156 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004157
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304158 pVBInfo->HT = tempax;
4159 pVBInfo->VT = tempbx;
4160 return;
4161 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004162}
4163
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004164static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304165 unsigned short RefreshRateTableIndex,
4166 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004167{
Bill Pemberton108afbf2010-06-17 13:10:47 -04004168 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004169
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304170 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
4171 pVBInfo);
4172 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
4173 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004174
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304175 if (pVBInfo->VBType & VB_XGI301) { /* shampoo 0129 */
4176 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004177 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
4178 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
4179 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304180 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004181 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
4182 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304183 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004184
Aaro Koskinen8104e322011-03-13 12:26:22 +02004185 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004186
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304187 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004188 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304189 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004190 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004191}
4192
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004193static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
4194 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004195{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004196 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
4197 short index;
4198 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304199
4200 if (ModeNo <= 0x13)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004201 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304202 else
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004203 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304204
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004205 index = (modeflag & ModeInfoFlag) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304206
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004207 if (index < 0)
4208 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304209
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004210 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304211}
4212
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004213static unsigned short XGI_GetOffset(unsigned short ModeNo,
4214 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304215 unsigned short RefreshRateTableIndex,
4216 struct xgi_hw_device_info *HwDeviceExtension,
4217 struct vb_device_info *pVBInfo)
4218{
4219 unsigned short temp, colordepth, modeinfo, index, infoflag,
4220 ColorDepth[] = { 0x01, 0x02, 0x04 };
4221
4222 modeinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
4223 if (ModeNo <= 0x14)
4224 infoflag = 0;
4225 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004226 infoflag = pVBInfo->
4227 RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304228
4229 index = (modeinfo >> 8) & 0xFF;
4230
4231 temp = pVBInfo->ScreenOffset[index];
4232
4233 if (infoflag & InterlaceMode)
4234 temp = temp << 1;
4235
4236 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4237
4238 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
4239 temp = ModeNo - 0x7C;
4240 colordepth = ColorDepth[temp];
4241 temp = 0x6B;
4242 if (infoflag & InterlaceMode)
4243 temp = temp << 1;
4244 return temp * colordepth;
4245 } else {
4246 return temp * colordepth;
4247 }
4248}
4249
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004250static void XGI_SetCRT2Offset(unsigned short ModeNo,
4251 unsigned short ModeIdIndex,
4252 unsigned short RefreshRateTableIndex,
4253 struct xgi_hw_device_info *HwDeviceExtension,
4254 struct vb_device_info *pVBInfo)
4255{
4256 unsigned short offset;
4257 unsigned char temp;
4258
4259 if (pVBInfo->VBInfo & SetInSlaveMode)
4260 return;
4261
4262 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4263 HwDeviceExtension, pVBInfo);
4264 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004265 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004266 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004267 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004268 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004269 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004270}
4271
Randy Dunlap89229672010-08-10 08:46:44 -07004272static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004273{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004274 /* threshold high ,disable auto threshold */
4275 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
4276 /* threshold low default 04h */
4277 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004278}
4279
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004280static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304281 struct xgi_hw_device_info *HwDeviceExtension,
4282 unsigned short RefreshRateTableIndex,
4283 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004284{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304285 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004286
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304287 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004288 CRT1Index = pVBInfo->
4289 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304290 CRT1Index &= IndexMask;
4291 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4292 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004293
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304294 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
4295 HwDeviceExtension, pVBInfo);
4296 XGI_SetCRT2FIFO(pVBInfo);
4297 /* XGI_SetCRT2Sync(ModeNo,RefreshRateTableIndex); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004298
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304299 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004300 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004301
Aaro Koskinen8104e322011-03-13 12:26:22 +02004302 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
4303 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004304}
4305
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004306static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304307 struct xgi_hw_device_info *HwDeviceExtension,
4308 unsigned short RefreshRateTableIndex,
4309 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004310{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304311 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
4312 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004313
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304314 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004315 CRT1Index = pVBInfo->
4316 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304317 CRT1Index &= IndexMask;
4318 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004319 }
4320
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304321 if (ModeNo <= 0x13)
4322 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
4323 else
4324 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004325
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304326 /* bainy change table name */
4327 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004328 /* BTVGA2HT 0x08,0x09 */
4329 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004330 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304331 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004332 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004333 /* BTVGA2HDEE 0x0A,0x0C */
4334 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004335 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304336 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
4337 pushbx = pVBInfo->VGAHDE / 2 + 16;
4338 tempcx = tempcx >> 1;
4339 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4340 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004341
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304342 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4343 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004344 tempbx |= ((pVBInfo->
4345 XGINEWUB_CRT1Table[CRT1Index].CR[14] &
4346 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304347 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4348 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
4349 tempcx &= 0x1F;
4350 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[15];
4351 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4352 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4353 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004354
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304355 tempbx += 4;
4356 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004357
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304358 if (tempcx > (pVBInfo->VGAHT / 2))
4359 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004360
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304361 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004362
Aaro Koskinen8104e322011-03-13 12:26:22 +02004363 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304364 } else {
4365 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004366 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304367 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004368 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004369 /* BTVGA2HDEE 0x0A,0x0C */
4370 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004371 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304372 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
4373 pushbx = pVBInfo->VGAHDE + 16;
4374 tempcx = tempcx >> 1;
4375 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
4376 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004377
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304378 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4379 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[3];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004380 tempbx |= ((pVBInfo->
4381 XGINEWUB_CRT1Table[CRT1Index].CR[5] &
4382 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304383 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
4384 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
4385 tempcx &= 0x1F;
4386 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[6];
4387 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
4388 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
4389 tempbx += 16;
4390 tempcx += 16;
4391 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004392
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304393 if (tempcx > pVBInfo->VGAHT)
4394 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004395
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304396 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004397 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304398 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004399
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304400 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
4401 tempbx = pushbx;
4402 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
4403 tempax |= (tempbx & 0xFF00);
4404 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004405 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304406 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004407 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304408 tempcx = (pVBInfo->VGAVT - 1);
4409 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004410
Aaro Koskinen8104e322011-03-13 12:26:22 +02004411 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304412 tempbx = pVBInfo->VGAVDE - 1;
4413 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004414 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304415 temp = ((tempbx & 0xFF00) << 3) >> 8;
4416 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004417 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004418
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304419 tempax = pVBInfo->VGAVDE;
4420 tempbx = pVBInfo->VGAVDE;
4421 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004422 /* BTVGA2VRS 0x10,0x11 */
4423 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
4424 /* BTVGA2VRE 0x11 */
4425 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004426
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304427 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
4428 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[10];
4429 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004430
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304431 if (temp & 0x04)
4432 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004433
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304434 if (temp & 0x080)
4435 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004436
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304437 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004438
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304439 if (temp & 0x08)
4440 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004441
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304442 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[11];
4443 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
4444 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004445
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304446 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004447 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304448 temp = ((tempbx & 0xFF00) >> 8) << 4;
4449 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004450 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304451 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004452
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304453 if (modeflag & DoubleScanMode)
4454 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004455
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304456 if (modeflag & HalfDCLK)
4457 tempax |= 0x40;
4458
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004459 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004460}
4461
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004462static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
4463{
4464 unsigned long tempax, tempbx;
4465
4466 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
4467 & 0xFFFF;
4468 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
4469 tempax = (tempax * pVBInfo->HT) / tempbx;
4470
4471 return (unsigned short) tempax;
4472}
4473
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004474static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304475 struct xgi_hw_device_info *HwDeviceExtension,
4476 unsigned short RefreshRateTableIndex,
4477 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004478{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304479 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
4480 modeflag, CRT1Index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004481
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304482 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004483 /* si+St_ResInfo */
4484 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304485 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4486 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004487 /* si+Ext_ResInfo */
4488 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304489 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004490 CRT1Index = pVBInfo->
4491 RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304492 CRT1Index &= IndexMask;
4493 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004494
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304495 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4496 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004497
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304498 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004499 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304500 /* if (modeflag & Charx8Dot) */
4501 /* tempcx = 0x08; */
4502 /* else */
4503 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004504
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304505 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4506 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004507
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304508 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004509
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304510 if (modeflag & HalfDCLK)
4511 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004512
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304513 tempax = (tempax / tempcx) - 1;
4514 tempbx |= ((tempax & 0x00FF) << 8);
4515 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004516 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004517
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304518 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004519
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304520 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4521 if (!(pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4522 | VB_XGI302LV | VB_XGI301C)))
4523 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004524
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304525 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4526 if (pVBInfo->VBType & VB_XGI301LV) {
4527 if (pVBInfo->VBExtInfo == VB_YPbPr1080i) {
4528 if (resinfo == 7)
4529 temp -= 2;
4530 }
4531 } else if (resinfo == 7) {
4532 temp -= 2;
4533 }
4534 }
4535 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004536
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004537 /* 0x05 Horizontal Display Start */
4538 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
4539 /* 0x06 Horizontal Blank end */
4540 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004541
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304542 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
4543 if (pVBInfo->VBInfo & SetCRT2ToTV)
4544 tempax = pVBInfo->VGAHT;
4545 else
4546 tempax = XGI_GetVGAHT2(pVBInfo);
4547 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004548
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304549 if (tempax >= pVBInfo->VGAHT)
4550 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004551
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304552 if (modeflag & HalfDCLK)
4553 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004554
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304555 tempax = (tempax / tempcx) - 5;
4556 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
4557 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4558 temp = (tempbx & 0x00FF) - 1;
4559 if (!(modeflag & HalfDCLK)) {
4560 temp -= 6;
4561 if (pVBInfo->TVInfo & TVSimuMode) {
4562 temp -= 4;
4563 if (ModeNo > 0x13)
4564 temp -= 10;
4565 }
4566 }
4567 } else {
4568 /* tempcx = tempbx & 0x00FF ; */
4569 tempbx = (tempbx & 0xFF00) >> 8;
4570 tempcx = (tempcx + tempbx) >> 1;
4571 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004572
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304573 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4574 temp -= 1;
4575 if (!(modeflag & HalfDCLK)) {
4576 if ((modeflag & Charx8Dot)) {
4577 temp += 4;
4578 if (pVBInfo->VGAHDE >= 800)
4579 temp -= 6;
4580 }
4581 }
4582 } else {
4583 if (!(modeflag & HalfDCLK)) {
4584 temp -= 4;
4585 if (pVBInfo->LCDResInfo != Panel1280x960) {
4586 if (pVBInfo->VGAHDE >= 800) {
4587 temp -= 7;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004588 if (pVBInfo->ModeType ==
4589 ModeEGA) {
4590 if (pVBInfo->VGAVDE ==
4591 1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304592 temp += 15;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004593 if (pVBInfo->LCDResInfo != Panel1280x1024) {
4594 temp +=
4595 7;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304596 }
4597 }
4598 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004599
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304600 if (pVBInfo->VGAHDE >= 1280) {
4601 if (pVBInfo->LCDResInfo
4602 != Panel1280x960) {
4603 if (pVBInfo->LCDInfo
4604 & LCDNonExpanding) {
4605 temp
4606 += 28;
4607 }
4608 }
4609 }
4610 }
4611 }
4612 }
4613 }
4614 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004615
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004616 /* 0x07 Horizontal Retrace Start */
4617 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4618 /* 0x08 Horizontal Retrace End */
4619 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004620
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304621 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4622 if (pVBInfo->TVInfo & TVSimuMode) {
4623 if ((ModeNo == 0x06) || (ModeNo == 0x10) || (ModeNo
4624 == 0x11) || (ModeNo == 0x13) || (ModeNo
4625 == 0x0F)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004626 xgifb_reg_set(pVBInfo->Part1Port, 0x07, 0x5b);
4627 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0x03);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304628 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004629
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304630 if ((ModeNo == 0x00) || (ModeNo == 0x01)) {
4631 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004632 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304633 0x07, 0x2A);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004634 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304635 0x08, 0x61);
4636 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004637 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304638 0x07, 0x2A);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004639 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304640 0x08, 0x41);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004641 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304642 0x0C, 0xF0);
4643 }
4644 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004645
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304646 if ((ModeNo == 0x02) || (ModeNo == 0x03) || (ModeNo
4647 == 0x07)) {
4648 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004649 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304650 0x07, 0x54);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004651 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304652 0x08, 0x00);
4653 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004654 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304655 0x07, 0x55);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004656 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304657 0x08, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004658 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304659 0x0C, 0xF0);
4660 }
4661 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004662
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304663 if ((ModeNo == 0x04) || (ModeNo == 0x05) || (ModeNo
4664 == 0x0D) || (ModeNo == 0x50)) {
4665 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004666 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304667 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004668 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304669 0x08, 0x03);
4670 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004671 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304672 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004673 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304674 0x08, 0x02);
4675 }
4676 }
4677 }
4678 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004679
Aaro Koskinen8104e322011-03-13 12:26:22 +02004680 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004681 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004682 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004683
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304684 tempbx = pVBInfo->VGAVT;
4685 push1 = tempbx;
4686 tempcx = 0x121;
4687 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004688
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304689 if (tempbx == 357)
4690 tempbx = 350;
4691 if (tempbx == 360)
4692 tempbx = 350;
4693 if (tempbx == 375)
4694 tempbx = 350;
4695 if (tempbx == 405)
4696 tempbx = 400;
4697 if (tempbx == 525)
4698 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004699
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304700 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004701
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304702 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4703 if (pVBInfo->LCDResInfo == Panel1024x768) {
4704 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
4705 if (tempbx == 350)
4706 tempbx += 5;
4707 if (tempbx == 480)
4708 tempbx += 5;
4709 }
4710 }
4711 }
4712 tempbx--;
4713 temp = tempbx & 0x00FF;
4714 tempbx--;
4715 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004716 /* 0x10 vertical Blank Start */
4717 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304718 tempbx = push2;
4719 tempbx--;
4720 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004721 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004722
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304723 if (tempbx & 0x0100)
4724 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004725
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304726 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004727
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304728 if (modeflag & DoubleScanMode)
4729 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004730
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304731 if (tempbx & 0x0200)
4732 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004733
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304734 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004735 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004736
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304737 if (tempbx & 0x0400)
4738 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004739
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004740 /* 0x11 Vertival Blank End */
4741 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304742
4743 tempax = push1;
4744 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
4745 tempax = tempax >> 2;
4746 push1 = tempax; /* push ax */
4747
4748 if (resinfo != 0x09) {
4749 tempax = tempax << 1;
4750 tempbx += tempax;
4751 }
4752
4753 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4754 if (pVBInfo->VBType & VB_XGI301LV) {
4755 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
4756 tempbx -= 10;
4757 } else {
4758 if (pVBInfo->TVInfo & TVSimuMode) {
4759 if (pVBInfo->TVInfo & SetPALTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004760 if (pVBInfo->VBType &
4761 VB_XGI301LV) {
4762 if (!(pVBInfo->TVInfo &
4763 (SetYPbPrMode525p |
4764 SetYPbPrMode750p |
4765 SetYPbPrMode1080i)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304766 tempbx += 40;
4767 } else {
4768 tempbx += 40;
4769 }
4770 }
4771 }
4772 }
4773 } else {
4774 tempbx -= 10;
4775 }
4776 } else {
4777 if (pVBInfo->TVInfo & TVSimuMode) {
4778 if (pVBInfo->TVInfo & SetPALTV) {
4779 if (pVBInfo->VBType & VB_XGI301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004780 if (!(pVBInfo->TVInfo &
4781 (SetYPbPrMode525p |
4782 SetYPbPrMode750p |
4783 SetYPbPrMode1080i)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304784 tempbx += 40;
4785 } else {
4786 tempbx += 40;
4787 }
4788 }
4789 }
4790 }
4791 tempax = push1;
4792 tempax = tempax >> 2;
4793 tempax++;
4794 tempax += tempbx;
4795 push1 = tempax; /* push ax */
4796
4797 if ((pVBInfo->TVInfo & SetPALTV)) {
4798 if (tempbx <= 513) {
4799 if (tempax >= 513)
4800 tempbx = 513;
4801 }
4802 }
4803
4804 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004805 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304806 tempbx--;
4807 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004808 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304809
4810 if (tempbx & 0x0100)
4811 tempcx |= 0x0008;
4812
4813 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004814 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304815
4816 tempbx++;
4817
4818 if (tempbx & 0x0100)
4819 tempcx |= 0x0004;
4820
4821 if (tempbx & 0x0200)
4822 tempcx |= 0x0080;
4823
4824 if (tempbx & 0x0400)
4825 tempcx |= 0x0C00;
4826
4827 tempbx = push1; /* pop ax */
4828 temp = tempbx & 0x00FF;
4829 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004830 /* 0x0D vertical Retrace End */
4831 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304832
4833 if (tempbx & 0x0010)
4834 tempcx |= 0x2000;
4835
4836 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004837 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304838 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004839 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304840 tempax = modeflag;
4841 temp = (tempax & 0xFF00) >> 8;
4842
4843 temp = (temp >> 1) & 0x09;
4844
4845 if (pVBInfo->VBType & (VB_XGI301LV | VB_XGI302LV | VB_XGI301C))
4846 temp |= 0x01;
4847
Aaro Koskinen8104e322011-03-13 12:26:22 +02004848 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
4849 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
4850 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304851
4852 if (pVBInfo->LCDInfo & LCDRGB18Bit)
4853 temp = 0x80;
4854 else
4855 temp = 0x00;
4856
Aaro Koskinen8104e322011-03-13 12:26:22 +02004857 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304858
4859 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004860}
4861
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004862static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304863 unsigned short RefreshRateTableIndex,
4864 struct xgi_hw_device_info *HwDeviceExtension,
4865 struct vb_device_info *pVBInfo)
4866{
4867 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
4868 modeflag, resinfo, crt2crtc;
4869 unsigned char *TimingPoint;
4870
4871 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
4872
4873 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004874 /* si+St_ResInfo */
4875 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304876 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
4877 crt2crtc = pVBInfo->SModeIDTable[ModeIdIndex].St_CRT2CRTC;
4878 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004879 /* si+Ext_ResInfo */
4880 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304881 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004882 crt2crtc = pVBInfo->RefIndex[RefreshRateTableIndex].
4883 Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304884 }
4885
4886 tempax = 0;
4887
4888 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
4889 tempax |= 0x0800;
4890
4891 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4892 tempax |= 0x0400;
4893
4894 if (pVBInfo->VBInfo & SetCRT2ToSCART)
4895 tempax |= 0x0200;
4896
4897 if (!(pVBInfo->TVInfo & SetPALTV))
4898 tempax |= 0x1000;
4899
4900 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
4901 tempax |= 0x0100;
4902
4903 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
4904 tempax &= 0xfe00;
4905
4906 tempax = (tempax & 0xff00) >> 8;
4907
Aaro Koskinen8104e322011-03-13 12:26:22 +02004908 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304909 TimingPoint = pVBInfo->NTSCTiming;
4910
4911 if (pVBInfo->TVInfo & SetPALTV)
4912 TimingPoint = pVBInfo->PALTiming;
4913
4914 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
4915 TimingPoint = pVBInfo->HiTVExtTiming;
4916
4917 if (pVBInfo->VBInfo & SetInSlaveMode)
4918 TimingPoint = pVBInfo->HiTVSt2Timing;
4919
4920 if (pVBInfo->SetFlag & TVSimuMode)
4921 TimingPoint = pVBInfo->HiTVSt1Timing;
4922
4923 if (!(modeflag & Charx8Dot))
4924 TimingPoint = pVBInfo->HiTVTextTiming;
4925 }
4926
4927 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
4928 if (pVBInfo->TVInfo & SetYPbPrMode525i)
4929 TimingPoint = pVBInfo->YPbPr525iTiming;
4930
4931 if (pVBInfo->TVInfo & SetYPbPrMode525p)
4932 TimingPoint = pVBInfo->YPbPr525pTiming;
4933
4934 if (pVBInfo->TVInfo & SetYPbPrMode750p)
4935 TimingPoint = pVBInfo->YPbPr750pTiming;
4936 }
4937
4938 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004939 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304940
4941 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004942 /* di->temp2[j] */
4943 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304944
4945 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004946 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304947
4948 temp = pVBInfo->NewFlickerMode;
4949 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004950 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304951
4952 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
4953 tempax = 950;
4954
4955 if (pVBInfo->TVInfo & SetPALTV)
4956 tempax = 520;
4957 else
4958 tempax = 440;
4959
4960 if (pVBInfo->VDE <= tempax) {
4961 tempax -= pVBInfo->VDE;
4962 tempax = tempax >> 2;
4963 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
4964 push1 = tempax;
4965 temp = (tempax & 0xFF00) >> 8;
4966 temp += (unsigned short) TimingPoint[0];
4967
4968 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4969 | VB_XGI302LV | VB_XGI301C)) {
4970 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4971 | SetCRT2ToSVIDEO | SetCRT2ToSCART
4972 | SetCRT2ToYPbPr)) {
4973 tempcx = pVBInfo->VGAHDE;
4974 if (tempcx >= 1024) {
4975 temp = 0x17; /* NTSC */
4976 if (pVBInfo->TVInfo & SetPALTV)
4977 temp = 0x19; /* PAL */
4978 }
4979 }
4980 }
4981
Aaro Koskinen8104e322011-03-13 12:26:22 +02004982 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304983 tempax = push1;
4984 temp = (tempax & 0xFF00) >> 8;
4985 temp += TimingPoint[1];
4986
4987 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
4988 | VB_XGI302LV | VB_XGI301C)) {
4989 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4990 | SetCRT2ToSVIDEO | SetCRT2ToSCART
4991 | SetCRT2ToYPbPr))) {
4992 tempcx = pVBInfo->VGAHDE;
4993 if (tempcx >= 1024) {
4994 temp = 0x1D; /* NTSC */
4995 if (pVBInfo->TVInfo & SetPALTV)
4996 temp = 0x52; /* PAL */
4997 }
4998 }
4999 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005000 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305001 }
5002
5003 /* 301b */
5004 tempcx = pVBInfo->HT;
5005
5006 if (XGI_IsLCDDualLink(pVBInfo))
5007 tempcx = tempcx >> 1;
5008
5009 tempcx -= 2;
5010 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005011 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305012
5013 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005014 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305015
5016 tempcx = pVBInfo->HT >> 1;
5017 push1 = tempcx; /* push cx */
5018 tempcx += 7;
5019
5020 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5021 tempcx -= 4;
5022
5023 temp = tempcx & 0x00FF;
5024 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005025 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305026
5027 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5028 tempbx += tempcx;
5029 push2 = tempbx;
5030 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005031 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305032 temp = (tempbx & 0xFF00) >> 8;
5033 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005034 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305035
5036 tempbx = push2;
5037 tempbx = tempbx + 8;
5038 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5039 tempbx = tempbx - 4;
5040 tempcx = tempbx;
5041 }
5042
5043 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005044 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305045
5046 j += 2;
5047 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
5048 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005049 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305050 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005051 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305052
5053 tempcx += 8;
5054 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
5055 tempcx -= 4;
5056
5057 temp = tempcx & 0xFF;
5058 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005059 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305060
5061 tempcx = push1; /* pop cx */
5062 j += 2;
5063 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
5064 tempcx -= temp;
5065 temp = tempcx & 0x00FF;
5066 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005067 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305068
5069 tempcx -= 11;
5070
5071 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
5072 tempax = XGI_GetVGAHT2(pVBInfo);
5073 tempcx = tempax - 1;
5074 }
5075 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005076 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305077
5078 tempbx = pVBInfo->VDE;
5079
5080 if (pVBInfo->VGAVDE == 360)
5081 tempbx = 746;
5082 if (pVBInfo->VGAVDE == 375)
5083 tempbx = 746;
5084 if (pVBInfo->VGAVDE == 405)
5085 tempbx = 853;
5086
5087 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005088 if (pVBInfo->VBType &
5089 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
5090 if (!(pVBInfo->TVInfo &
5091 (SetYPbPrMode525p | SetYPbPrMode750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305092 tempbx = tempbx >> 1;
5093 } else
5094 tempbx = tempbx >> 1;
5095 }
5096
5097 tempbx -= 2;
5098 temp = tempbx & 0x00FF;
5099
5100 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5101 if (pVBInfo->VBType & VB_XGI301LV) {
5102 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5103 if (pVBInfo->VBInfo & SetInSlaveMode) {
5104 if (ModeNo == 0x2f)
5105 temp += 1;
5106 }
5107 }
5108 } else {
5109 if (pVBInfo->VBInfo & SetInSlaveMode) {
5110 if (ModeNo == 0x2f)
5111 temp += 1;
5112 }
5113 }
5114 }
5115
Aaro Koskinen8104e322011-03-13 12:26:22 +02005116 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305117
5118 temp = (tempcx & 0xFF00) >> 8;
5119 temp |= ((tempbx & 0xFF00) >> 8) << 6;
5120
5121 if (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) {
5122 if (pVBInfo->VBType & VB_XGI301LV) {
5123 if (pVBInfo->TVInfo & SetYPbPrMode1080i) {
5124 temp |= 0x10;
5125
5126 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5127 temp |= 0x20;
5128 }
5129 } else {
5130 temp |= 0x10;
5131 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
5132 temp |= 0x20;
5133 }
5134 }
5135
Aaro Koskinen8104e322011-03-13 12:26:22 +02005136 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305137
5138 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5139 | VB_XGI302LV | VB_XGI301C)) { /* TV gatingno */
5140 tempbx = pVBInfo->VDE;
5141 tempcx = tempbx - 2;
5142
5143 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5144 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p
5145 | SetYPbPrMode750p)))
5146 tempbx = tempbx >> 1;
5147 }
5148
5149 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
5150 temp = 0;
5151 if (tempcx & 0x0400)
5152 temp |= 0x20;
5153
5154 if (tempbx & 0x0400)
5155 temp |= 0x40;
5156
Aaro Koskinen8104e322011-03-13 12:26:22 +02005157 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305158 }
5159
5160 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005161 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305162 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005163 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305164 }
5165
5166 tempbx = tempbx & 0x00FF;
5167
5168 if (!(modeflag & HalfDCLK)) {
5169 tempcx = pVBInfo->VGAHDE;
5170 if (tempcx >= pVBInfo->HDE) {
5171 tempbx |= 0x2000;
5172 tempax &= 0x00FF;
5173 }
5174 }
5175
5176 tempcx = 0x0101;
5177
5178 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
5179 if (pVBInfo->VGAHDE >= 1024) {
5180 tempcx = 0x1920;
5181 if (pVBInfo->VGAHDE >= 1280) {
5182 tempcx = 0x1420;
5183 tempbx = tempbx & 0xDFFF;
5184 }
5185 }
5186 }
5187
5188 if (!(tempbx & 0x2000)) {
5189 if (modeflag & HalfDCLK)
5190 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
5191
5192 push1 = tempbx;
5193 tempeax = pVBInfo->VGAHDE;
5194 tempebx = (tempcx & 0xFF00) >> 8;
5195 longtemp = tempeax * tempebx;
5196 tempecx = tempcx & 0x00FF;
5197 longtemp = longtemp / tempecx;
5198
5199 /* 301b */
5200 tempecx = 8 * 1024;
5201
5202 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5203 | VB_XGI302LV | VB_XGI301C)) {
5204 tempecx = tempecx * 8;
5205 }
5206
5207 longtemp = longtemp * tempecx;
5208 tempecx = pVBInfo->HDE;
5209 temp2 = longtemp % tempecx;
5210 tempeax = longtemp / tempecx;
5211 if (temp2 != 0)
5212 tempeax += 1;
5213
5214 tempax = (unsigned short) tempeax;
5215
5216 /* 301b */
5217 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5218 | VB_XGI302LV | VB_XGI301C)) {
5219 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
5220 }
5221 /* end 301b */
5222
5223 tempbx = push1;
5224 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
5225 | (tempbx & 0x00FF));
5226 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
5227 | (tempax & 0x00FF));
5228 temp = (tempax & 0xFF00) >> 8;
5229 } else {
5230 temp = (tempax & 0x00FF) >> 8;
5231 }
5232
Aaro Koskinen8104e322011-03-13 12:26:22 +02005233 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305234 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005235 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305236 temp = tempcx & 0x00FF;
5237
5238 if (tempbx & 0x2000)
5239 temp = 0;
5240
5241 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5242 temp |= 0x18;
5243
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005244 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305245 if (pVBInfo->TVInfo & SetPALTV) {
5246 tempbx = 0x0382;
5247 tempcx = 0x007e;
5248 } else {
5249 tempbx = 0x0369;
5250 tempcx = 0x0061;
5251 }
5252
5253 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005254 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305255 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005256 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305257
5258 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
5259 temp = temp << 2;
5260 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
5261
5262 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
5263 temp |= 0x10;
5264
5265 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5266 temp |= 0x20;
5267
5268 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5269 temp |= 0x60;
5270 }
5271
Aaro Koskinen8104e322011-03-13 12:26:22 +02005272 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005273 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005274 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305275
5276 if (!(pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))) {
5277 if (pVBInfo->TVInfo & NTSC1024x768) {
5278 TimingPoint = XGI_NTSC1024AdjTime;
5279 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005280 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305281 TimingPoint[j]);
5282 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005283 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305284 }
5285 }
5286
5287 /* [ycchen] 01/14/03 Modify for 301C PALM Support */
5288 if (pVBInfo->VBType & VB_XGI301C) {
5289 if (pVBInfo->TVInfo & SetPALMTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005290 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305291 0x08); /* PALM Mode */
5292 }
5293
5294 if (pVBInfo->TVInfo & SetPALMTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005295 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305296 0x01);
5297 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02005298 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305299
5300 /* if ( !( pVBInfo->VBType & VB_XGI301C ) ) */
Aaro Koskinendc505562011-03-13 12:26:26 +02005301 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305302 }
5303
5304 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV) {
5305 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02005306 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305307 }
5308
5309 if (pVBInfo->VBInfo & SetCRT2ToTV)
5310 return;
5311}
5312
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005313static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305314 struct xgi_hw_device_info *HwDeviceExtension,
5315 unsigned short RefreshRateTableIndex,
5316 struct vb_device_info *pVBInfo)
5317{
5318 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
5319 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
5320
5321 struct XGI_LCDDesStruct *LCDBDesPtr = NULL;
5322
5323 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005324 /* si+St_ResInfo */
5325 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305326 resinfo = pVBInfo->SModeIDTable[ModeIdIndex].St_ResInfo;
5327 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005328 /* si+Ext_ResInfo */
5329 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305330 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005331 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].
5332 Ext_CRT1CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305333 CRT1Index &= IndexMask;
5334 }
5335
5336 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5337 return;
5338
5339 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
5340
5341 if (XGI_IsLCDDualLink(pVBInfo))
5342 tempbx = tempbx >> 1;
5343
5344 tempbx -= 1;
5345 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005346 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305347 temp = (tempbx & 0xFF00) >> 8;
5348 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005349 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305350 temp = 0x01;
5351
5352 if (pVBInfo->LCDResInfo == Panel1280x1024) {
5353 if (pVBInfo->ModeType == ModeEGA) {
5354 if (pVBInfo->VGAHDE >= 1024) {
5355 temp = 0x02;
5356 if (pVBInfo->LCDInfo & LCDVESATiming)
5357 temp = 0x01;
5358 }
5359 }
5360 }
5361
Aaro Koskinen8104e322011-03-13 12:26:22 +02005362 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305363 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
5364 push1 = tempbx;
5365 tempbx--;
5366 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005367 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305368 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005369 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305370
5371 tempcx = pVBInfo->VT - 1;
5372 push2 = tempcx + 1;
5373 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005374 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305375 temp = (tempcx & 0xFF00) >> 8;
5376 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005377 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005378 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
5379 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
5380 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
5381 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305382
5383 /* Customized LCDB Des no add */
5384 tempbx = 5;
5385 LCDBDesPtr = (struct XGI_LCDDesStruct *) XGI_GetLcdPtr(tempbx, ModeNo,
5386 ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5387 tempah = pVBInfo->LCDResInfo;
5388 tempah &= PanelResInfo;
5389
5390 if ((tempah == Panel1024x768) || (tempah == Panel1024x768x75)) {
5391 tempbx = 1024;
5392 tempcx = 768;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005393 } else if ((tempah == Panel1280x1024) ||
5394 (tempah == Panel1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305395 tempbx = 1280;
5396 tempcx = 1024;
5397 } else if (tempah == Panel1400x1050) {
5398 tempbx = 1400;
5399 tempcx = 1050;
5400 } else {
5401 tempbx = 1600;
5402 tempcx = 1200;
5403 }
5404
5405 if (pVBInfo->LCDInfo & EnableScalingLCD) {
5406 tempbx = pVBInfo->HDE;
5407 tempcx = pVBInfo->VDE;
5408 }
5409
5410 pushbx = tempbx;
5411 tempax = pVBInfo->VT;
5412 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
5413 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
5414 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
5415 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
5416 tempbx = pVBInfo->LCDVDES;
5417 tempcx += tempbx;
5418
5419 if (tempcx >= tempax)
5420 tempcx -= tempax; /* lcdvdes */
5421
5422 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005423 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305424 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005425 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305426 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
5427 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
5428 tempah = tempch;
5429 tempah = tempah << 3;
5430 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005431 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305432
5433 /* getlcdsync() */
5434 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5435 tempcx = tempbx;
5436 tempax = pVBInfo->VT;
5437 tempbx = pVBInfo->LCDVRS;
5438
5439 /* if (SetLCD_Info & EnableScalingLCD) */
5440 tempcx += tempbx;
5441 if (tempcx >= tempax)
5442 tempcx -= tempax;
5443
5444 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005445 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305446 temp = (tempbx & 0xFF00) >> 8;
5447 temp = temp << 4;
5448 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005449 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305450 tempcx = pushbx;
5451 tempax = pVBInfo->HT;
5452 tempbx = pVBInfo->LCDHDES;
5453 tempbx &= 0x0FFF;
5454
5455 if (XGI_IsLCDDualLink(pVBInfo)) {
5456 tempax = tempax >> 1;
5457 tempbx = tempbx >> 1;
5458 tempcx = tempcx >> 1;
5459 }
5460
5461 if (pVBInfo->VBType & VB_XGI302LV)
5462 tempbx += 1;
5463
5464 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
5465 tempbx += 1;
5466
5467 tempcx += tempbx;
5468
5469 if (tempcx >= tempax)
5470 tempcx -= tempax;
5471
5472 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005473 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305474 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005475 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305476 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005477 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305478 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005479 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305480
5481 /* getlcdsync() */
5482 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
5483 tempcx = tempax;
5484 tempax = pVBInfo->HT;
5485 tempbx = pVBInfo->LCDHRS;
5486 /* if ( SetLCD_Info & EnableScalingLCD) */
5487 if (XGI_IsLCDDualLink(pVBInfo)) {
5488 tempax = tempax >> 1;
5489 tempbx = tempbx >> 1;
5490 tempcx = tempcx >> 1;
5491 }
5492
5493 if (pVBInfo->VBType & VB_XGI302LV)
5494 tempbx += 1;
5495
5496 tempcx += tempbx;
5497
5498 if (tempcx >= tempax)
5499 tempcx -= tempax;
5500
5501 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005502 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305503
5504 temp = (tempbx & 0xFF00) >> 8;
5505 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005506 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305507 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005508 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305509
5510 if (!(pVBInfo->LCDInfo & LCDVESATiming)) {
5511 if (pVBInfo->VGAVDE == 525) {
5512 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5513 | VB_XGI301LV | VB_XGI302LV
5514 | VB_XGI301C)) {
5515 temp = 0xC6;
5516 } else
5517 temp = 0xC4;
5518
Aaro Koskinen8104e322011-03-13 12:26:22 +02005519 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
5520 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305521 }
5522
5523 if (pVBInfo->VGAVDE == 420) {
5524 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
5525 | VB_XGI301LV | VB_XGI302LV
5526 | VB_XGI301C)) {
5527 temp = 0x4F;
5528 } else
5529 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005530 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305531 }
5532 }
5533}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005534
5535/* --------------------------------------------------------------------- */
5536/* Function : XGI_GetTap4Ptr */
5537/* Input : */
5538/* Output : di -> Tap4 Reg. Setting Pointer */
5539/* Description : */
5540/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005541static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305542 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005543{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305544 unsigned short tempax, tempbx, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005545
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305546 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005547
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305548 if (tempcx == 0) {
5549 tempax = pVBInfo->VGAHDE;
5550 tempbx = pVBInfo->HDE;
5551 } else {
5552 tempax = pVBInfo->VGAVDE;
5553 tempbx = pVBInfo->VDE;
5554 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005555
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005556 if (tempax <= tempbx)
5557 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305558 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005559 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005560
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305561 if (pVBInfo->TVInfo & SetPALTV)
5562 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005563
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305564 if (pVBInfo->VBInfo & SetCRT2ToYPbPr) {
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005565 if ((pVBInfo->TVInfo & SetYPbPrMode525i) ||
5566 (pVBInfo->TVInfo & SetYPbPrMode525p))
5567 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305568 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5569 Tap4TimingPtr = YPbPr750pTap4Timing;
5570 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005571
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305572 if (pVBInfo->VBInfo & SetCRT2ToHiVisionTV)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005573 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005574
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305575 i = 0;
5576 while (Tap4TimingPtr[i].DE != 0xFFFF) {
5577 if (Tap4TimingPtr[i].DE == tempax)
5578 break;
5579 i++;
5580 }
5581 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005582}
5583
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005584static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005585{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305586 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005587
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305588 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005589
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305590 if (!(pVBInfo->VBType & VB_XGI301C))
5591 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005592
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305593 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
5594 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005595 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005596
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005597 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5598 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV))) {
5599 /* Set Vertical Scaling */
5600 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305601 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005602 xgifb_reg_set(pVBInfo->Part2Port,
5603 i,
5604 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305605 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005606
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005607 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
5608 (!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)))
5609 /* Enable V.Scaling */
5610 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305611 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005612 /* Enable H.Scaling */
5613 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005614}
5615
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005616static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305617 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005618{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305619 unsigned short i;
5620 unsigned char *tempdi;
5621 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005622
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305623 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005624 /* si+St_ResInfo */
5625 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305626 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005627 /* si+Ext_ResInfo */
5628 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005629
Aaro Koskinen8104e322011-03-13 12:26:22 +02005630 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305631 if (pVBInfo->TVInfo & SetPALTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005632 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5633 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305634 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005635 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
5636 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305637 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005638
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305639 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5640 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005641
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305642 if (pVBInfo->TVInfo & SetPALMTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005643 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5644 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
5645 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305646 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005647
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305648 if ((pVBInfo->VBInfo & SetCRT2ToHiVisionTV) || (pVBInfo->VBInfo
5649 & SetCRT2ToYPbPr)) {
5650 if (pVBInfo->TVInfo & SetYPbPrMode525i)
5651 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005652
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305653 tempdi = pVBInfo->HiTVGroup3Data;
5654 if (pVBInfo->SetFlag & TVSimuMode) {
5655 tempdi = pVBInfo->HiTVGroup3Simu;
5656 if (!(modeflag & Charx8Dot))
5657 tempdi = pVBInfo->HiTVGroup3Text;
5658 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005659
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305660 if (pVBInfo->TVInfo & SetYPbPrMode525p)
5661 tempdi = pVBInfo->Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005662
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305663 if (pVBInfo->TVInfo & SetYPbPrMode750p)
5664 tempdi = pVBInfo->Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005665
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305666 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005667 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005668
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305669 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
5670 if (pVBInfo->TVInfo & SetYPbPrMode525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005671 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305672 }
5673 }
5674 return;
5675} /* {end of XGI_SetGroup3} */
5676
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005677static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305678 unsigned short RefreshRateTableIndex,
5679 struct xgi_hw_device_info *HwDeviceExtension,
5680 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005681{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305682 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005683
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305684 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005685
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305686 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005687 /* si+St_ResInfo */
5688 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305689 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005690 /* si+Ext_ResInfo */
5691 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005692
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305693 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005694 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005695
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305696 tempbx = pVBInfo->RVBHCMAX;
5697 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005698 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305699 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
5700 tempcx = pVBInfo->VGAHT - 1;
5701 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005702 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005703
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305704 temp = ((tempcx & 0xFF00) >> 8) << 3;
5705 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005706
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305707 tempcx = pVBInfo->VGAVT - 1;
5708 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5709 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005710
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305711 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005712 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305713 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005714 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005715 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305716 tempcx = pVBInfo->VBInfo;
5717 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005718
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305719 if (modeflag & HalfDCLK)
5720 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005721
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305722 if (XGI_IsLCDDualLink(pVBInfo))
5723 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005724
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305725 if (tempcx & SetCRT2ToHiVisionTV) {
5726 temp = 0;
5727 if (tempbx <= 1024)
5728 temp = 0xA0;
5729 if (tempbx == 1280)
5730 temp = 0xC0;
5731 } else if (tempcx & SetCRT2ToTV) {
5732 temp = 0xA0;
5733 if (tempbx <= 800)
5734 temp = 0x80;
5735 } else {
5736 temp = 0x80;
5737 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5738 temp = 0;
5739 if (tempbx > 800)
5740 temp = 0x60;
5741 }
5742 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005743
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305744 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p)) {
5745 temp = 0x00;
5746 if (pVBInfo->VGAHDE == 1280)
5747 temp = 0x40;
5748 if (pVBInfo->VGAHDE == 1024)
5749 temp = 0x20;
5750 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005751 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005752
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305753 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005754
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305755 if (tempcx & SetCRT2ToHiVisionTV) {
5756 if (!(temp & 0xE000))
5757 tempbx = tempbx >> 1;
5758 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005759
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305760 tempcx = pVBInfo->RVBHRS;
5761 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005762 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005763
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305764 tempeax = pVBInfo->VGAVDE;
5765 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005766
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305767 if (tempeax <= tempebx) {
5768 tempcx = (tempcx & (~0x4000));
5769 tempeax = pVBInfo->VGAVDE;
5770 } else {
5771 tempeax -= tempebx;
5772 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005773
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305774 templong = (tempeax * 256 * 1024) % tempebx;
5775 tempeax = (tempeax * 256 * 1024) / tempebx;
5776 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005777
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305778 if (templong != 0)
5779 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005780
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305781 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005782 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005783
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305784 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005785 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305786 tempbx = (unsigned short) (tempebx >> 16);
5787 temp = tempbx & 0x00FF;
5788 temp = temp << 4;
5789 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005790 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005791
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305792 /* 301b */
5793 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
5794 | VB_XGI302LV | VB_XGI301C)) {
5795 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005796 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305797 tempax = pVBInfo->VGAHDE;
5798 if (modeflag & HalfDCLK)
5799 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005800
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305801 if (XGI_IsLCDDualLink(pVBInfo))
5802 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005803
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005804 /* if((pVBInfo->VBInfo&(SetCRT2ToLCD)) ||
5805 ((pVBInfo->TVInfo&SetYPbPrMode525p) ||
5806 (pVBInfo->TVInfo&SetYPbPrMode750p))) { */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305807 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5808 if (tempax > 800)
5809 tempax -= 800;
5810 } else {
5811 if (pVBInfo->VGAHDE > 800) {
5812 if (pVBInfo->VGAHDE == 1024)
5813 tempax = (tempax * 25 / 32) - 1;
5814 else
5815 tempax = (tempax * 20 / 32) - 1;
5816 }
5817 }
5818 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005819
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305820 /*
5821 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
5822 if (pVBInfo->VBType & VB_XGI301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005823 if (!(pVBInfo->TVInfo &
5824 (SetYPbPrMode525p |
5825 SetYPbPrMode750p |
5826 SetYPbPrMode1080i))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305827 if (pVBInfo->VGAHDE > 800) {
5828 if (pVBInfo->VGAHDE == 1024)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005829 tempax =(tempax * 25 /
5830 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305831 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005832 tempax = (tempax * 20 /
5833 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305834 }
5835 }
5836 } else {
5837 if (pVBInfo->VGAHDE > 800) {
5838 if (pVBInfo->VGAHDE == 1024)
5839 tempax = (tempax * 25 / 32) - 1;
5840 else
5841 tempax = (tempax * 20 / 32) - 1;
5842 }
5843 }
5844 }
5845 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005846
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305847 temp = (tempax & 0xFF00) >> 8;
5848 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005849 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305850 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005851 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005852
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305853 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVisionTV)) {
5854 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005855 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005856
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305857 }
5858 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005859
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305860 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5861 if (!(pVBInfo->TVInfo & (NTSC1024x768
5862 | SetYPbPrMode525p | SetYPbPrMode750p
5863 | SetYPbPrMode1080i))) {
5864 temp |= 0x0001;
5865 if ((pVBInfo->VBInfo & SetInSlaveMode)
5866 && (!(pVBInfo->TVInfo
5867 & TVSimuMode)))
5868 temp &= (~0x0001);
5869 }
5870 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005871
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005872 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305873 tempbx = pVBInfo->HT;
5874 if (XGI_IsLCDDualLink(pVBInfo))
5875 tempbx = tempbx >> 1;
5876 tempbx = (tempbx >> 1) - 2;
5877 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005878 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305879 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005880 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305881 }
5882 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005883
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305884 if (pVBInfo->ISXPDOS == 0)
5885 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5886 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005887}
5888
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005889static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
5890{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005891 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005892}
5893
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005894static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305895 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005896{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305897 unsigned short Pindex, Pdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005898
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305899 Pindex = pVBInfo->Part5Port;
5900 Pdata = pVBInfo->Part5Port + 1;
5901 if (pVBInfo->ModeType == ModeVGA) {
5902 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
5903 | CRT2DisplayFlag))) {
5904 XGINew_EnableCRT2(pVBInfo);
5905 /* LoadDAC2(pVBInfo->Part5Port, ModeNo, ModeIdIndex); */
5906 }
5907 }
5908 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005909}
5910
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005911static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305912 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005913{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005914 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005915}
5916
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005917static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305918 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005919{
5920
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005921 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005922}
5923
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005924/*----------------------------------------------------------------------------*/
5925/* input */
5926/* bl[5] : 1;LVDS signal on */
5927/* bl[1] : 1;LVDS backlight on */
5928/* bl[0] : 1:LVDS VDD on */
5929/* bh: 100000b : clear bit 5, to set bit5 */
5930/* 000010b : clear bit 1, to set bit1 */
5931/* 000001b : clear bit 0, to set bit0 */
5932/*----------------------------------------------------------------------------*/
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305933void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
5934 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005935{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305936 unsigned char CR4A, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005937
Aaro Koskinen58839b02011-03-13 12:26:23 +02005938 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305939 tempbh &= 0x23;
5940 tempbl &= 0x23;
Aaro Koskinendc505562011-03-13 12:26:26 +02005941 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005942
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305943 if (tempbh & 0x20) {
5944 temp = (tempbl >> 4) & 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005945
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005946 /* CR B4[1] */
5947 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005948
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305949 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005950
Aaro Koskinen58839b02011-03-13 12:26:23 +02005951 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005952
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305953 temp = XG21GPIODataTransfer(temp);
5954 temp &= ~tempbh;
5955 temp |= tempbl;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005956 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005957}
5958
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305959void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
5960 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005961{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305962 unsigned char CR4A, temp;
5963 unsigned short tempbh0, tempbl0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005964
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305965 tempbh0 = tempbh;
5966 tempbl0 = tempbl;
5967 tempbh0 &= 0x20;
5968 tempbl0 &= 0x20;
5969 tempbh0 >>= 3;
5970 tempbl0 >>= 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005971
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305972 if (tempbh & 0x20) {
5973 temp = (tempbl >> 4) & 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005974
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005975 /* CR B4[1] */
5976 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005977
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305978 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005979 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005980
Aaro Koskinen58839b02011-03-13 12:26:23 +02005981 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305982 tempbh &= 0x03;
5983 tempbl &= 0x03;
5984 tempbh <<= 2;
5985 tempbl <<= 2; /* GPIOC,GPIOD */
Aaro Koskinendc505562011-03-13 12:26:26 +02005986 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005987 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005988}
5989
5990/* --------------------------------------------------------------------- */
Bill Pemberton80adad82010-06-17 13:10:51 -04005991unsigned short XGI_GetLVDSOEMTableIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005992{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305993 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005994
Aaro Koskinen58839b02011-03-13 12:26:23 +02005995 index = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305996 if (index < sizeof(XGI21_LCDCapList)
5997 / sizeof(struct XGI21_LVDSCapStruct))
5998 return index;
5999 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006000}
6001
6002/* --------------------------------------------------------------------- */
6003/* Function : XGI_XG21SetPanelDelay */
6004/* Input : */
6005/* Output : */
6006/* Description : */
6007/* I/P : bl : 1 ; T1 : the duration between CPL on and signal on */
6008/* : bl : 2 ; T2 : the duration signal on and Vdd on */
6009/* : bl : 3 ; T3 : the duration between CPL off and signal off */
6010/* : bl : 4 ; T4 : the duration signal off and Vdd off */
6011/* --------------------------------------------------------------------- */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306012void XGI_XG21SetPanelDelay(unsigned short tempbl,
6013 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006014{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306015 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006016
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306017 index = XGI_GetLVDSOEMTableIndex(pVBInfo);
6018 if (tempbl == 1)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006019 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006020
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306021 if (tempbl == 2)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006022 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006023
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306024 if (tempbl == 3)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006025 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S3);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006026
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306027 if (tempbl == 4)
Aaro Koskinend80aaa02011-02-17 23:29:14 +02006028 mdelay(pVBInfo->XG21_LVDSCapList[index].PSC_S4);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006029}
6030
Bill Pemberton82d6eb52010-06-17 13:10:46 -04006031unsigned char XGI_XG21CheckLVDSMode(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306032 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006033{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306034 unsigned short xres, yres, colordepth, modeflag, resindex,
6035 lvdstableindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006036
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306037 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6038 if (ModeNo <= 0x13) {
6039 xres = pVBInfo->StResInfo[resindex].HTotal;
6040 yres = pVBInfo->StResInfo[resindex].VTotal;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006041 /* si+St_ResInfo */
6042 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306043 } else {
6044 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6045 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006046 /* si+St_ModeFlag */
6047 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306048 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006049
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306050 if (!(modeflag & Charx8Dot)) {
6051 xres /= 9;
6052 xres *= 8;
6053 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006054
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306055 if (ModeNo > 0x13) {
6056 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
6057 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006058
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306059 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6060 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006061
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306062 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006063
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306064 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
6065 if (xres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE))
6066 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04006067
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306068 if (yres > (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE))
6069 return 0;
6070
6071 if (ModeNo > 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006072 if ((xres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6073 LVDSHDE)) ||
6074 (yres != (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6075 LVDSVDE))) {
6076 colordepth = XGI_GetColorDepth(ModeNo,
6077 ModeIdIndex,
6078 pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306079 if (colordepth > 2)
6080 return 0;
6081
6082 }
6083 }
6084 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006085}
6086
Bill Pemberton80adad82010-06-17 13:10:51 -04006087void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006088{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306089 unsigned char temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006090
Aaro Koskinen58839b02011-03-13 12:26:23 +02006091 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306092 temp = (temp & 1) << 6;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006093 /* SR06[6] 18bit Dither */
6094 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
6095 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
6096 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006097
6098}
6099
Bill Pemberton80adad82010-06-17 13:10:51 -04006100void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006101{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306102 unsigned char temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006103
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006104 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
6105 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306106 temp = (temp & 3) << 6;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006107 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
6108 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
6109 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
6110 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006111
6112}
6113
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006114static void xgifb_set_lvds(int chip_id,
6115 unsigned short ModeNo,
6116 unsigned short ModeIdIndex,
6117 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006118{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306119 unsigned char temp, Miscdata;
6120 unsigned short xres, yres, modeflag, resindex, lvdstableindex;
6121 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
6122 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
6123 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006124
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306125 lvdstableindex = XGI_GetLVDSOEMTableIndex(pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006126 temp = (unsigned char) ((pVBInfo->XG21_LVDSCapList[lvdstableindex].
6127 LVDS_Capability &
6128 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306129 temp &= LCDPolarity;
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006130 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006131
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006132 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006133
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006134 temp = (unsigned char) (pVBInfo->XG21_LVDSCapList[lvdstableindex].
6135 LVDS_Capability & LCDPolarity);
6136 /* SR35[7] FP VSync polarity */
6137 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
6138 /* SR30[5] FP HSync polarity */
6139 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006140
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006141 if (chip_id == XG27)
6142 XGI_SetXG27FPBits(pVBInfo);
6143 else
6144 XGI_SetXG21FPBits(pVBInfo);
6145
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306146 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
6147 if (ModeNo <= 0x13) {
6148 xres = pVBInfo->StResInfo[resindex].HTotal;
6149 yres = pVBInfo->StResInfo[resindex].VTotal;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006150 /* si+St_ResInfo */
6151 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306152 } else {
6153 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
6154 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006155 /* si+St_ModeFlag */
6156 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306157 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006158
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306159 if (!(modeflag & Charx8Dot))
6160 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006161
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306162 LVDSHT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006163
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306164 LVDSHBS = xres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE
6165 - xres) / 2;
6166 if ((ModeNo <= 0x13) && (modeflag & HalfDCLK))
6167 LVDSHBS -= xres / 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006168
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306169 if (LVDSHBS > LVDSHT)
6170 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006171
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306172 LVDSHRS = LVDSHBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHFP;
6173 if (LVDSHRS > LVDSHT)
6174 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006175
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306176 LVDSHRE = LVDSHRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHSYNC;
6177 if (LVDSHRE > LVDSHT)
6178 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306180 LVDSHBE = LVDSHBS + LVDSHT
6181 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006182
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306183 LVDSVT = pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006184
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306185 LVDSVBS = yres + (pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE
6186 - yres) / 2;
6187 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
6188 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006189
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306190 if (LVDSVBS > LVDSVT)
6191 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006192
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306193 LVDSVRS = LVDSVBS + pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVFP;
6194 if (LVDSVRS > LVDSVT)
6195 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006196
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006197 LVDSVRE = LVDSVRS + pVBInfo->XG21_LVDSCapList[lvdstableindex].
6198 LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306199 if (LVDSVRE > LVDSVT)
6200 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006201
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306202 LVDSVBE = LVDSVBS + LVDSVT
6203 - pVBInfo->XG21_LVDSCapList[lvdstableindex].LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006204
Aaro Koskinen58839b02011-03-13 12:26:23 +02006205 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006206 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006207
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306208 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006209 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006210
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306211 /* HT SR0B[1:0] CR00 */
6212 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006213 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006214 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006215
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306216 /* HBS SR0B[5:4] CR02 */
6217 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006218 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006219 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006220
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306221 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
6222 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006223 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
6224 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
6225 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006226
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306227 /* HRS SR0B[7:6] CR04 */
6228 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006229 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006230 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006231
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306232 /* Panel HRS SR2F[1:0] SR2E[7:0] */
6233 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006234 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006235 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006236
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306237 /* HRE SR0C[2] CR05[4:0] */
6238 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006239 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
6240 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006241
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306242 /* Panel HRE SR2F[7:2] */
6243 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006244 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006245
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306246 /* VT SR0A[0] CR07[5][0] CR06 */
6247 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006248 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
6249 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
6250 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006251 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006252
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306253 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
6254 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006255 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
6256 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
6257 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006258 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006259
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306260 /* VBE SR0A[4] CR16 */
6261 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006262 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006263 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006264
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306265 /* VRS SR0A[3] CR7[7][2] CR10 */
6266 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006267 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
6268 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
6269 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006270 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006271
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006272 if (chip_id == XG27) {
6273 /* Panel VRS SR35[2:0] SR34[7:0] */
6274 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
6275 (value & 0x700) >> 8);
6276 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
6277 } else {
6278 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
6279 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
6280 (value & 0x600) >> 9);
6281 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
6282 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
6283 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006284
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306285 /* VRE SR0A[5] CR11[3:0] */
6286 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006287 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
6288 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006289
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306290 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006291 if (chip_id == XG27)
6292 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6293 (value << 2) & 0xFC);
6294 else
6295 /* SR3F[7] has to be 0, h/w bug */
6296 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
6297 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006298
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306299 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006300
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006301 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006302 xgifb_reg_set(pVBInfo->P3c4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006303 0x2B,
6304 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6305 VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006306 xgifb_reg_set(pVBInfo->P3c4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006307 0x2C,
6308 pVBInfo->XG21_LVDSCapList[lvdstableindex].
6309 VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306310 value += 0x10;
6311 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006312
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306313 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006314 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006315 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006316 /* set data, panning = 0, shift left 1 dot*/
6317 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006318
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006319 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006320 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306321
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006322 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306323 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006324
6325}
6326
6327/* --------------------------------------------------------------------- */
6328/* Function : XGI_IsLCDON */
6329/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04006330/* Output : 0 : Skip PSC Control */
6331/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006332/* Description : */
6333/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006334static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006335{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306336 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006337
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306338 tempax = pVBInfo->VBInfo;
6339 if (tempax & SetCRT2ToDualEdge)
6340 return 0;
6341 else if (tempax & (DisableCRT2Display | SwitchToCRT2 | SetSimuScanMode))
6342 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006343
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306344 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006345}
6346
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006347/* --------------------------------------------------------------------- */
6348/* Function : XGI_DisableChISLCD */
6349/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04006350/* Output : 0 -> Not LCD Mode */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006351/* Description : */
6352/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006353static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006354{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306355 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006356
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306357 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02006358 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006359
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306360 if (tempbx & (EnableChA | DisableChA)) {
6361 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6362 return 0;
6363 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006364
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306365 if (!(tempbx & (EnableChB | DisableChB)))
6366 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006367
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306368 if (tempah & 0x01) /* Chk LCDB Mode */
6369 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006370
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306371 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006372}
6373
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006374/* --------------------------------------------------------------------- */
6375/* Function : XGI_EnableChISLCD */
6376/* Input : */
6377/* Output : 0 -> Not LCD mode */
6378/* Description : */
6379/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006380static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006381{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306382 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006383
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306384 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02006385 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006386
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306387 if (tempbx & (EnableChA | DisableChA)) {
6388 if (!(tempah & 0x08)) /* Chk LCDA Mode */
6389 return 0;
6390 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006391
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306392 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04006393 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006394
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306395 if (tempah & 0x01) /* Chk LCDB Mode */
6396 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006397
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306398 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006399}
6400
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306401void XGI_DisableBridge(struct xgi_hw_device_info *HwDeviceExtension,
6402 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006403{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02006404 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006405
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306406 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6407 | VB_XGI302LV | VB_XGI301C)) {
6408 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006409 if (!(pVBInfo->VBInfo &
6410 (DisableCRT2Display | SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306411 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6412 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6413 tempah = 0x7F; /* Disable Channel A */
6414 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006415 /* Disable Channel B */
6416 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006417
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306418 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006419 /* force to disable Cahnnel */
6420 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006421
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306422 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006423 /* Force to disable Channel B */
6424 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306425 }
6426 }
6427 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006428
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006429 /* disable part4_1f */
6430 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006431
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306432 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6433 if (((pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)))
6434 || (XGI_DisableChISLCD(pVBInfo))
6435 || (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006436 /* LVDS Driver power down */
6437 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306438 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006439
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306440 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6441 & (DisableCRT2Display | SetCRT2ToLCDA
6442 | SetSimuScanMode))) {
6443 if (pVBInfo->SetFlag & GatingCRT)
6444 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
6445 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6446 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006447
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306448 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
6449 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
6450 & SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006451 /* Power down */
6452 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306453 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006454
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006455 /* disable TV as primary VGA swap */
6456 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006457
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306458 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02006459 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006460
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006461 if ((pVBInfo->SetFlag & DisableChB) ||
6462 (pVBInfo->VBInfo &
6463 (DisableCRT2Display | SetSimuScanMode)) ||
6464 ((!(pVBInfo->VBInfo & SetCRT2ToLCDA)) &&
6465 (pVBInfo->VBInfo &
6466 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
6467 /* BScreenOff=1 */
6468 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006469
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006470 if ((pVBInfo->SetFlag & DisableChB) ||
6471 (pVBInfo->VBInfo &
6472 (DisableCRT2Display | SetSimuScanMode)) ||
6473 (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) ||
6474 (pVBInfo->VBInfo &
6475 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
6476 /* save Part1 index 0 */
6477 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
6478 /* BTDAC = 1, avoid VB reset */
6479 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
6480 /* disable CRT2 */
6481 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6482 /* restore Part1 index 0 */
6483 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306484 }
6485 } else { /* {301} */
6486 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006487 /* BScreenOff=1 */
6488 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
6489 /* Disable CRT2 */
6490 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
6491 /* Disable TV asPrimary VGA swap */
6492 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306493 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006494
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306495 if (pVBInfo->VBInfo & (DisableCRT2Display | SetCRT2ToLCDA
6496 | SetSimuScanMode))
6497 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
6498 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006499}
6500
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006501/* --------------------------------------------------------------------- */
6502/* Function : XGI_GetTVPtrIndex */
6503/* Input : */
6504/* Output : */
6505/* Description : bx 0 : ExtNTSC */
6506/* 1 : StNTSC */
6507/* 2 : ExtPAL */
6508/* 3 : StPAL */
6509/* 4 : ExtHiTV */
6510/* 5 : StHiTV */
6511/* 6 : Ext525i */
6512/* 7 : St525i */
6513/* 8 : Ext525p */
6514/* 9 : St525p */
6515/* A : Ext750p */
6516/* B : St750p */
6517/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006518static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006519{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306520 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006521
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306522 if (pVBInfo->TVInfo & SetPALTV)
6523 tempbx = 2;
6524 if (pVBInfo->TVInfo & SetYPbPrMode1080i)
6525 tempbx = 4;
6526 if (pVBInfo->TVInfo & SetYPbPrMode525i)
6527 tempbx = 6;
6528 if (pVBInfo->TVInfo & SetYPbPrMode525p)
6529 tempbx = 8;
6530 if (pVBInfo->TVInfo & SetYPbPrMode750p)
6531 tempbx = 10;
6532 if (pVBInfo->TVInfo & TVSimuMode)
6533 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006534
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306535 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006536}
6537
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006538/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006539/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006540/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006541/* Output : bx 0 : NTSC */
6542/* 1 : PAL */
6543/* 2 : PALM */
6544/* 3 : PALN */
6545/* 4 : NTSC1024x768 */
6546/* 5 : PAL-M 1024x768 */
6547/* 6-7: reserved */
6548/* cl 0 : YFilter1 */
6549/* 1 : YFilter2 */
6550/* ch 0 : 301A */
6551/* 1 : 301B/302B/301LV/302LV */
6552/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006553/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006554static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
6555 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006556{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006557 *tempbx = 0;
6558 *tempcl = 0;
6559 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006560
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006561 if (pVBInfo->TVInfo & SetPALTV)
6562 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006563
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006564 if (pVBInfo->TVInfo & SetPALMTV)
6565 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006566
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006567 if (pVBInfo->TVInfo & SetPALNTV)
6568 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006569
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006570 if (pVBInfo->TVInfo & NTSC1024x768) {
6571 *tempbx = 4;
6572 if (pVBInfo->TVInfo & SetPALMTV)
6573 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306574 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006575
6576 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6577 | VB_XGI302LV | VB_XGI301C)) {
6578 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
6579 & TVSimuMode)) {
6580 *tempbx += 8;
6581 *tempcl += 1;
6582 }
6583 }
6584
6585 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6586 | VB_XGI302LV | VB_XGI301C))
6587 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006588}
6589
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006590static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006591{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306592 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006593
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306594 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006595
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306596 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6597 | VB_XGI302LV | VB_XGI301C)) {
6598 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA
6599 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
6600 tempbl = 0;
6601 tempbh = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006602
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306603 index = XGI_GetTVPtrIndex(pVBInfo); /* Get TV Delay */
6604 tempbl = pVBInfo->XGI_TVDelayList[index];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006605
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306606 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
6607 | VB_XGI301LV | VB_XGI302LV
6608 | VB_XGI301C))
6609 tempbl = pVBInfo->XGI_TVDelayList2[index];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006610
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306611 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6612 tempbl = tempbl >> 4;
6613 /*
6614 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
6615 tempbl = CRT2Delay1; // Get CRT2 Delay
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006616 if (pVBInfo->VBType &
6617 (VB_XGI301B |
6618 VB_XGI302B |
6619 VB_XGI301LV |
6620 VB_XGI302LV |
6621 VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306622 tempbl = CRT2Delay2;
6623 */
6624 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006625 /* Get LCD Delay */
6626 index = XGI_GetLCDCapPtr(pVBInfo);
6627 tempbh = pVBInfo->LCDCapList[index].
6628 LCD_DelayCompensation;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006629
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306630 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA))
6631 tempbl = tempbh;
6632 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006633
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306634 tempbl &= 0x0F;
6635 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02006636 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006637
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306638 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
6639 | SetCRT2ToTV)) { /* Channel B */
6640 tempah &= 0xF0;
6641 tempah |= tempbl;
6642 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006643
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306644 if (pVBInfo->VBInfo & SetCRT2ToLCDA) { /* Channel A */
6645 tempah &= 0x0F;
6646 tempah |= tempbh;
6647 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02006648 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306649 }
6650 } else if (pVBInfo->IF_DEF_LVDS == 1) {
6651 tempbl = 0;
6652 tempbh = 0;
6653 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006654 /* / Get LCD Delay */
6655 tempah = pVBInfo->LCDCapList[
6656 XGI_GetLCDCapPtr(pVBInfo)].
6657 LCD_DelayCompensation;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306658 tempah &= 0x0f;
6659 tempah = tempah << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006660 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306661 tempah);
6662 }
6663 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006664}
6665
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006666static void XGI_SetLCDCap_A(unsigned short tempcx,
6667 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006668{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306669 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006670
Aaro Koskinen58839b02011-03-13 12:26:23 +02006671 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006672
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306673 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006674 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006675 /* Enable Dither */
6676 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006677 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306678 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006679 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306680 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006681 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306682 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006683
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306684 /*
6685 if (tempcx & EnableLCD24bpp) { // 24bits
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006686 xgifb_reg_and_or(pVBInfo->Part1Port,
6687 0x19,
6688 0x0F,
6689 (unsigned short)(0x30 | (tempcx&0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006690 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306691 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006692 xgifb_reg_and_or(pVBInfo->Part1Port,
6693 0x19,
6694 0x0F,
6695 // Enable Dither
6696 (unsigned short)(0x20 | (tempcx&0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006697 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306698 }
6699 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006700}
6701
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006702/* --------------------------------------------------------------------- */
6703/* Function : XGI_SetLCDCap_B */
6704/* Input : cx -> LCD Capability */
6705/* Output : */
6706/* Description : */
6707/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006708static void XGI_SetLCDCap_B(unsigned short tempcx,
6709 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006710{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306711 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006712 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306713 (unsigned short) (((tempcx & 0x00ff) >> 6)
6714 | 0x0c));
6715 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006716 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306717 (unsigned short) (((tempcx & 0x00ff) >> 6)
6718 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006719}
6720
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006721static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006722{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306723 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006724
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306725 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006726
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006727 /* disable down spectrum D[4] */
6728 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306729 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006730 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306731 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006732
Aaro Koskinen8104e322011-03-13 12:26:22 +02006733 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306734 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006735 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306736 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006737 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306738 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006739 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306740 pVBInfo->LCDCapList[index].Spectrum_34);
6741 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006742 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006743}
6744
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006745static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
6746{
6747 unsigned short tempcx;
6748
6749 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
6750
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006751 if (pVBInfo->VBType &
6752 (VB_XGI301B |
6753 VB_XGI302B |
6754 VB_XGI301LV |
6755 VB_XGI302LV |
6756 VB_XGI301C)) { /* 301LV/302LV only */
6757 if (pVBInfo->VBType &
6758 (VB_XGI301LV | VB_XGI302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006759 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02006760 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006761 (unsigned char) (tempcx & 0x1F));
6762 }
6763 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006764 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006765 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
6766 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
6767 | EnablePLLSPLOW)) >> 8));
6768 }
6769
6770 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6771 | VB_XGI302LV | VB_XGI301C)) {
6772 if (pVBInfo->VBInfo & SetCRT2ToLCD)
6773 XGI_SetLCDCap_B(tempcx, pVBInfo);
6774 else if (pVBInfo->VBInfo & SetCRT2ToLCDA)
6775 XGI_SetLCDCap_A(tempcx, pVBInfo);
6776
6777 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
6778 if (tempcx & EnableSpectrum)
6779 SetSpectrum(pVBInfo);
6780 }
6781 } else {
6782 /* LVDS,CH7017 */
6783 XGI_SetLCDCap_A(tempcx, pVBInfo);
6784 }
6785}
6786
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006787/* --------------------------------------------------------------------- */
6788/* Function : XGI_SetAntiFlicker */
6789/* Input : */
6790/* Output : */
6791/* Description : Set TV Customized Param. */
6792/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006793static void XGI_SetAntiFlicker(unsigned short ModeNo,
6794 unsigned short ModeIdIndex,
6795 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006796{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306797 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006798
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306799 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006800
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306801 if (pVBInfo->TVInfo & (SetYPbPrMode525p | SetYPbPrMode750p))
6802 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006803
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306804 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6805 tempbx &= 0xFE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006806
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306807 if (ModeNo <= 0x13)
6808 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVFlickerIndex;
6809 else
6810 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006811
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306812 tempbx += index;
6813 tempah = TVAntiFlickList[tempbx];
6814 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006815
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006816 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006817}
6818
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006819static void XGI_SetEdgeEnhance(unsigned short ModeNo,
6820 unsigned short ModeIdIndex,
6821 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006822{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306823 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006824
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306825 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006826
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306827 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6828 tempbx &= 0xFE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006829
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306830 if (ModeNo <= 0x13)
6831 index = pVBInfo->SModeIDTable[ModeIdIndex].VB_StTVEdgeIndex;
6832 else
6833 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006834
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306835 tempbx += index;
6836 tempah = TVEdgeList[tempbx];
6837 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006838
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006839 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006840}
6841
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006842static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006843{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306844 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006845
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306846 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006847
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306848 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006849
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306850 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
6851 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006852
Aaro Koskinen8104e322011-03-13 12:26:22 +02006853 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306854 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006855 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306856 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006857 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306858 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006859 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306860 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006861}
6862
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006863static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306864 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006865{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306866 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006867
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306868 unsigned char tempcl, tempch, tempal, *filterPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006869
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306870 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006871
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306872 switch (tempbx) {
6873 case 0x00:
6874 case 0x04:
6875 filterPtr = NTSCYFilter1;
6876 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006877
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306878 case 0x01:
6879 filterPtr = PALYFilter1;
6880 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006881
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306882 case 0x02:
6883 case 0x05:
6884 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306885 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03006886 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306887 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006888
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306889 case 0x08:
6890 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306891 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306892 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306893 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03006894 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306895 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006896
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306897 default:
6898 return;
6899 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006900
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306901 if (ModeNo <= 0x13)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006902 tempal = pVBInfo->SModeIDTable[ModeIdIndex].
6903 VB_StTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306904 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006905 tempal = pVBInfo->EModeIDTable[ModeIdIndex].
6906 VB_ExtTVYFilterIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006907
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306908 if (tempcl == 0)
6909 index = tempal * 4;
6910 else
6911 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006912
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306913 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02006914 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
6915 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
6916 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
6917 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306918 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02006919 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
6920 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
6921 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
6922 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306923 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006924
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306925 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
6926 | VB_XGI302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02006927 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
6928 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
6929 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306930 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006931}
6932
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006933/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006934/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006935/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006936/* Output : */
6937/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006938/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006939static void XGI_OEM310Setting(unsigned short ModeNo,
6940 unsigned short ModeIdIndex,
6941 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006942{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006943 /* GetPart1IO(); */
6944 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006945
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006946 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA))
6947 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006948
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006949 if (pVBInfo->VBInfo & SetCRT2ToTV) {
6950 /* GetPart2IO() */
6951 XGI_SetPhaseIncr(pVBInfo);
6952 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
6953 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006954
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006955 if (pVBInfo->VBType & VB_XGI301)
6956 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306957 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006958}
6959
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006960/* --------------------------------------------------------------------- */
6961/* Function : XGI_SetCRT2ModeRegs */
6962/* Input : */
6963/* Output : */
6964/* Description : Origin code for crt2group */
6965/* --------------------------------------------------------------------- */
Bill Pemberton82d6eb52010-06-17 13:10:46 -04006966void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306967 struct xgi_hw_device_info *HwDeviceExtension,
6968 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006969{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306970 unsigned short tempbl;
6971 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006972
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306973 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006974
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006975 /* // fix write part1 index 0 BTDRAM bit Bug
6976 * xgifb_reg_set(pVBInfo->Part1Port, 0x03, 0x00); */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306977 tempah = 0;
6978 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006979 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306980 tempah &= ~0x10; /* BTRAMDAC */
6981 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006982
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306983 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
6984 | SetCRT2ToLCD)) {
6985 tempah = 0x40; /* BTDRAM */
6986 if (ModeNo > 0x13) {
6987 tempcl = pVBInfo->ModeType;
6988 tempcl -= ModeVGA;
6989 if (tempcl >= 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006990 /* BT Color */
6991 tempah = (0x008 >> tempcl);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306992 if (tempah == 0)
6993 tempah = 1;
6994 tempah |= 0x040;
6995 }
6996 }
6997 if (pVBInfo->VBInfo & SetInSlaveMode)
6998 tempah ^= 0x50; /* BTDAC */
6999 }
7000 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007001
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307002 /* 0210 shampoo
7003 if (pVBInfo->VBInfo & DisableCRT2Display) {
7004 tempah = 0;
7005 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007006
Aaro Koskinen8104e322011-03-13 12:26:22 +02007007 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307008 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)) {
7009 tempcl = pVBInfo->ModeType;
7010 if (ModeNo > 0x13) {
7011 tempcl -= ModeVGA;
7012 if ((tempcl > 0) || (tempcl == 0)) {
7013 tempah=(0x008>>tempcl) ;
7014 if (tempah == 0)
7015 tempah = 1;
7016 tempah |= 0x040;
7017 }
7018 } else {
7019 tempah = 0x040;
7020 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007021
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307022 if (pVBInfo->VBInfo & SetInSlaveMode) {
7023 tempah = (tempah ^ 0x050);
7024 }
7025 }
7026 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007027
Aaro Koskinen8104e322011-03-13 12:26:22 +02007028 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307029 tempah = 0x08;
7030 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007031
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307032 if (pVBInfo->VBInfo & DisableCRT2Display) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007033 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307034 } else {
7035 tempah = 0x00;
7036 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007037
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307038 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
7039 | SetCRT2ToLCD | SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007040 if ((pVBInfo->VBInfo & SetCRT2ToLCDA) &&
7041 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307042 tempbl &= 0xf7;
7043 tempah |= 0x01;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007044 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307045 tempbl, tempah);
7046 } else {
7047 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7048 tempbl &= 0xf7;
7049 tempah |= 0x01;
7050 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007051
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007052 if (pVBInfo->VBInfo &
7053 (SetCRT2ToRAMDAC |
7054 SetCRT2ToTV |
7055 SetCRT2ToLCD)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307056 tempbl &= 0xf8;
7057 tempah = 0x01;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007058
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307059 if (!(pVBInfo->VBInfo & SetInSlaveMode))
7060 tempah |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007061
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007062 if (!(pVBInfo->VBInfo &
7063 SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307064 tempah = tempah ^ 0x05;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007065 if (!(pVBInfo->VBInfo &
7066 SetCRT2ToLCD))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307067 tempah = tempah ^ 0x01;
7068 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007069
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007070 if (!(pVBInfo->VBInfo &
7071 SetCRT2ToDualEdge))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307072 tempah |= 0x08;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007073 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307074 0x2e, tempbl, tempah);
7075 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007076 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307077 0x2e, tempbl, tempah);
7078 }
7079 }
7080 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007081 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307082 tempah);
7083 }
7084 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007085
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307086 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
7087 | SetCRT2ToLCDA)) {
7088 tempah &= (~0x08);
7089 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
7090 & SetInSlaveMode))) {
7091 tempah |= 0x010;
7092 }
7093 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007094
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307095 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007096 /* if (!(pVBInfo->TVInfo &
7097 (SetYPbPrMode525p | SetYPbPrMode750p))) { */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307098 tempah |= 0x020;
7099 if (ModeNo > 0x13) {
7100 if (pVBInfo->VBInfo & DriverMode)
7101 tempah = tempah ^ 0x20;
7102 }
7103 /* } */
7104 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007105
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007106 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307107 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007108
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307109 if (pVBInfo->LCDInfo & SetLCDDualLink)
7110 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007111
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307112 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007113 /* if ((!(pVBInfo->VBInfo & SetCRT2ToHiVisionTV)) &&
7114 (!(pVBInfo->TVInfo &
7115 (SetYPbPrMode525p | SetYPbPrMode750p)))) { */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307116 if (pVBInfo->TVInfo & RPLLDIV2XO)
7117 tempah |= 0x40;
7118 /* } */
7119 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007120
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307121 if ((pVBInfo->LCDResInfo == Panel1280x1024)
7122 || (pVBInfo->LCDResInfo == Panel1280x1024x75))
7123 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007124
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307125 if (pVBInfo->LCDResInfo == Panel1280x960)
7126 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007127
Aaro Koskinen8104e322011-03-13 12:26:22 +02007128 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307129 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007130
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307131 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7132 | VB_XGI302LV | VB_XGI301C)) {
7133 tempah = 0;
7134 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007135
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307136 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7137 tempbl = 0xff;
7138 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7139 tempah |= 0x04; /* shampoo 0129 */
7140 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007141
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007142 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307143 tempah = 0x00;
7144 tempbl = 0xcf;
7145 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7146 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7147 tempah |= 0x30;
7148 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007149
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007150 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307151 tempah = 0;
7152 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007153
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307154 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7155 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
7156 tempah |= 0xc0;
7157 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007158 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307159 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007160
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307161 tempah = 0;
7162 tempbl = 0x7f;
7163 if (!(pVBInfo->VBInfo & SetCRT2ToLCDA)) {
7164 tempbl = 0xff;
7165 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
7166 tempah |= 0x80;
7167 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007168
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007169 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007170
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307171 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7172 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02007173 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
7174 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307175 }
7176 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007177}
7178
Aaro Koskinen063b9c42011-03-08 22:16:13 +02007179static void XGI_CloseCRTC(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307180 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007181{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307182 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007183
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307184 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007185
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307186 if (pVBInfo->VBInfo & SetCRT2ToLCDA)
7187 tempbx = 0x08A0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007188
7189}
7190
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307191void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
7192 struct vb_device_info *pVBInfo)
7193{
7194
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007195 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007196
7197}
7198
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307199void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
7200 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007201{
7202
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007203 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007204
7205}
7206
Bill Pemberton80adad82010-06-17 13:10:51 -04007207unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007208{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307209 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007210
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307211 if (pVBInfo->IF_DEF_LVDS == 1) {
7212 return 1;
7213 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007214 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307215 if ((flag == 1) || (flag == 2))
7216 return 1; /* 301b */
7217 else
7218 return 0;
7219 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007220}
7221
Bill Pemberton80adad82010-06-17 13:10:51 -04007222void XGI_LongWait(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007223{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307224 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007225
Aaro Koskinen58839b02011-03-13 12:26:23 +02007226 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007227
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307228 if (!(i & 0xC0)) {
7229 for (i = 0; i < 0xFFFF; i++) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007230 if (!(inb(pVBInfo->P3da) & 0x08))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307231 break;
7232 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007233
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307234 for (i = 0; i < 0xFFFF; i++) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007235 if ((inb(pVBInfo->P3da) & 0x08))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307236 break;
7237 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007238 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007239}
7240
Aaro Koskinen063b9c42011-03-08 22:16:13 +02007241static void XGI_VBLongWait(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007242{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307243 unsigned short tempal, temp, i, j;
7244 return;
7245 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
7246 temp = 0;
7247 for (i = 0; i < 3; i++) {
7248 for (j = 0; j < 100; j++) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007249 tempal = inb(pVBInfo->P3da);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307250 if (temp & 0x01) { /* VBWaitMode2 */
7251 if ((tempal & 0x08))
7252 continue;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007253
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307254 if (!(tempal & 0x08))
7255 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007256
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307257 } else { /* VBWaitMode1 */
7258 if (!(tempal & 0x08))
7259 continue;
7260
7261 if ((tempal & 0x08))
7262 break;
7263 }
7264 }
7265 temp = temp ^ 0x01;
7266 }
7267 } else {
7268 XGI_LongWait(pVBInfo);
7269 }
7270 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007271}
7272
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007273unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
7274 unsigned short ModeNo, unsigned short ModeIdIndex,
7275 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007276{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007277 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
7278 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
7279 0x01, 0x01 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007280
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007281 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007282
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007283 if (ModeNo <= 0x13)
7284 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
7285 else
7286 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
7287
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007288 if (ModeNo < 0x14)
7289 return 0xFFFF;
7290
Aaro Koskinen58839b02011-03-13 12:26:23 +02007291 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007292 index = index >> pVBInfo->SelectCRT2Rate;
7293 index &= 0x0F;
7294
7295 if (pVBInfo->LCDInfo & LCDNonExpanding)
7296 index = 0;
7297
7298 if (index > 0)
7299 index--;
7300
7301 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007302 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToLCDA)) {
7303 if (pVBInfo->IF_DEF_LVDS == 0) {
7304 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B
7305 | VB_XGI301LV | VB_XGI302LV
7306 | VB_XGI301C))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007307 /* 301b */
7308 temp = LCDARefreshIndex[
7309 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007310 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007311 temp = LCDRefreshIndex[
7312 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007313
7314 if (index > temp)
7315 index = temp;
7316 } else {
7317 index = 0;
7318 }
7319 }
7320 }
7321
7322 RefreshRateTableIndex = pVBInfo->EModeIDTable[ModeIdIndex].REFindex;
7323 ModeNo = pVBInfo->RefIndex[RefreshRateTableIndex].ModeID;
7324 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
7325 /*
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007326 if (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag &
7327 XG2xNotSupport) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007328 index++;
7329 }
7330 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007331 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 800) &&
7332 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007333 index++;
7334 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007335 /* Alan 10/19/2007;
7336 * do the similar adjustment like XGISearchCRT1Rate() */
7337 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1024) &&
7338 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007339 index++;
7340 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007341 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1280) &&
7342 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007343 index++;
7344 }
7345 }
7346
7347 i = 0;
7348 do {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007349 if (pVBInfo->RefIndex[RefreshRateTableIndex + i].
7350 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007351 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007352 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i].
7353 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007354 temp &= ModeInfoFlag;
7355 if (temp < pVBInfo->ModeType)
7356 break;
7357 i++;
7358 index--;
7359
7360 } while (index != 0xFFFF);
7361 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
7362 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007363 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i - 1].
7364 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007365 if (temp & InterlaceMode)
7366 i++;
7367 }
7368 }
7369 i--;
7370 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
7371 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
7372 RefreshRateTableIndex, &i, pVBInfo);
7373 }
7374 return RefreshRateTableIndex + i; /* return (0x01 | (temp1<<1)); */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007375}
7376
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007377static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05307378 struct xgi_hw_device_info *HwDeviceExtension,
7379 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007380{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007381 unsigned short RefreshRateTableIndex;
7382 /* unsigned short temp ; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007383
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007384 /* pVBInfo->SelectCRT2Rate = 0; */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007385
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007386 pVBInfo->SetFlag |= ProgrammingCRT2;
7387 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7388 ModeIdIndex, pVBInfo);
7389 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
7390 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7391 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7392 HwDeviceExtension, pVBInfo);
7393 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7394 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02007395}
7396
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007397unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
7398 struct xgi_hw_device_info *HwDeviceExtension,
7399 struct vb_device_info *pVBInfo)
7400{
7401 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
7402
7403 tempbx = pVBInfo->VBInfo;
7404 pVBInfo->SetFlag |= ProgrammingCRT2;
7405 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7406 pVBInfo->SelectCRT2Rate = 4;
7407 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7408 ModeIdIndex, pVBInfo);
7409 XGI_SaveCRT2Info(ModeNo, pVBInfo);
7410 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
7411 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7412 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7413 RefreshRateTableIndex, pVBInfo);
7414 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
7415 RefreshRateTableIndex, pVBInfo);
7416 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7417 RefreshRateTableIndex, pVBInfo);
7418 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7419 HwDeviceExtension, pVBInfo);
7420 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
7421 RefreshRateTableIndex, pVBInfo);
7422 XGI_SetTap4Regs(pVBInfo);
7423 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
7424 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7425 HwDeviceExtension, pVBInfo);
7426 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
7427 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
7428 XGI_AutoThreshold(pVBInfo);
7429 return 1;
7430}
7431
7432void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
7433{
7434 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
7435 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
7436 0x05, 0x00 };
7437
7438 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
7439
7440 unsigned char CR17, CR63, SR31;
7441 unsigned short temp;
7442 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
7443
7444 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02007445 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007446
7447 /* [2004/05/06] Vicent to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02007448 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02007449 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007450 pVBInfo->P3d4, 0x53) | 0x02));
7451
Aaro Koskinen58839b02011-03-13 12:26:23 +02007452 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
7453 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
7454 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007455
Aaro Koskinen8104e322011-03-13 12:26:22 +02007456 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
7457 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007458
Aaro Koskinen58839b02011-03-13 12:26:23 +02007459 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007460 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007461
Aaro Koskinen58839b02011-03-13 12:26:23 +02007462 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007463 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007464
Aaro Koskinen58839b02011-03-13 12:26:23 +02007465 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007466 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Aaro Koskinen58839b02011-03-13 12:26:23 +02007467 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02007468 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007469
Aaro Koskinen8104e322011-03-13 12:26:22 +02007470 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007471
7472 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007473 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007474
7475 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007476 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007477 CRTCData[i]);
7478
7479 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007480 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007481 CRTCData[i]);
7482
7483 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02007484 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007485 CRTCData[i]);
7486
Aaro Koskinen8104e322011-03-13 12:26:22 +02007487 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007488 & 0xE0));
7489
Aaro Koskinen8104e322011-03-13 12:26:22 +02007490 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
7491 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7492 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007493
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007494 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007495
7496 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007497 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
7498 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
7499 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007500 }
7501
7502 XGI_VBLongWait(pVBInfo);
7503 XGI_VBLongWait(pVBInfo);
7504 XGI_VBLongWait(pVBInfo);
7505
7506 mdelay(1);
7507
7508 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007509 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007510
7511 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007512 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007513 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007514 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007515
7516 /* alan, avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007517 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007518
7519 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007520 outb(0, (pVBInfo->P3c8 + 1));
7521 outb(0, (pVBInfo->P3c8 + 1));
7522 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007523 }
7524
Aaro Koskinen8104e322011-03-13 12:26:22 +02007525 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
7526 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
7527 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007528
7529 /* [2004/05/11] Vicent */
Aaro Koskinen58839b02011-03-13 12:26:23 +02007530 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007531 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02007532 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007533}
7534
7535void XGI_EnableBridge(struct xgi_hw_device_info *HwDeviceExtension,
7536 struct vb_device_info *pVBInfo)
7537{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02007538 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007539
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007540 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7541 | VB_XGI302LV | VB_XGI301C)) {
7542 if (!(pVBInfo->SetFlag & DisableChA)) {
7543 if (pVBInfo->SetFlag & EnableChA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007544 /* Power on */
7545 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007546 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007547 /* SetCRT2ToLCDA ) */
7548 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
7549 /* Power on */
Aaro Koskinen8104e322011-03-13 12:26:22 +02007550 xgifb_reg_set(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007551 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007552 }
7553 }
7554 }
7555
7556 if (!(pVBInfo->SetFlag & DisableChB)) {
7557 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
7558 & (SetCRT2ToLCD | SetCRT2ToTV
7559 | SetCRT2ToRAMDAC))) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007560 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007561 pVBInfo->P3c4, 0x32);
7562 tempah &= 0xDF;
7563 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007564 if (!(pVBInfo->VBInfo &
7565 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007566 tempah |= 0x20;
7567 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02007568 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02007569 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007570
Aaro Koskinen58839b02011-03-13 12:26:23 +02007571 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007572 pVBInfo->Part1Port, 0x2E);
7573
7574 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007575 /* BVBDOENABLE = 1 */
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02007576 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007577 0x2E, 0x80);
7578 /* BScreenOFF = 0 */
7579 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007580 }
7581 }
7582
7583 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
7584 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007585 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007586 0x20); /* shampoo 0129 */
7587 if (pVBInfo->VBType & (VB_XGI302LV | VB_XGI301C)) {
7588 if (!XGI_DisableChISLCD(pVBInfo)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007589 if (XGI_EnableChISLCD(pVBInfo) ||
7590 (pVBInfo->VBInfo &
7591 (SetCRT2ToLCD | SetCRT2ToLCDA)))
7592 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02007593 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007594 pVBInfo->Part4Port,
7595 0x2A,
7596 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007597 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007598 /* LVDS Driver power on */
7599 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007600 }
7601 }
7602
7603 tempah = 0x00;
7604
7605 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
7606 tempah = 0xc0;
7607
7608 if (!(pVBInfo->VBInfo & SetSimuScanMode)) {
7609 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007610 if (pVBInfo->VBInfo &
7611 SetCRT2ToDualEdge) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007612 tempah = tempah & 0x40;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007613 if (pVBInfo->VBInfo &
7614 SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007615 tempah = tempah ^ 0xC0;
7616
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007617 if (pVBInfo->SetFlag &
7618 DisableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007619 tempah &= 0xBF;
7620
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007621 if (pVBInfo->SetFlag &
7622 DisableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007623 tempah &= 0x7F;
7624
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007625 if (pVBInfo->SetFlag &
7626 EnableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007627 tempah |= 0x40;
7628
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007629 if (pVBInfo->SetFlag &
7630 EnableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007631 tempah |= 0x80;
7632 }
7633 }
7634 }
7635 }
7636
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007637 /* EnablePart4_1F */
7638 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007639
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007640 if (!(pVBInfo->SetFlag & DisableChA)) {
7641 XGI_VBLongWait(pVBInfo);
7642 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007643 XGI_DisableGatingCRT(HwDeviceExtension,
7644 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007645 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7646 XGI_VBLongWait(pVBInfo);
7647 }
7648 }
7649 } /* 301 */
7650 else { /* LVDS */
7651 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
7652 | SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007653 /* enable CRT2 */
7654 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007655
Aaro Koskinen58839b02011-03-13 12:26:23 +02007656 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007657 0x2E);
7658 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007659 /* BVBDOENABLE = 1 */
7660 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007661
Aaro Koskinendc505562011-03-13 12:26:26 +02007662 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007663 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7664 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007665}
7666
7667static void XGI_SetCRT1Group(struct xgi_hw_device_info *HwDeviceExtension,
7668 unsigned short ModeNo, unsigned short ModeIdIndex,
7669 struct vb_device_info *pVBInfo)
7670{
7671 unsigned short StandTableIndex, RefreshRateTableIndex, b3CC, temp;
7672
7673 unsigned short XGINew_P3cc = pVBInfo->P3cc;
7674
7675 /* XGINew_CRT1Mode = ModeNo; // SaveModeID */
7676 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
7677 /* XGI_SetBIOSData(ModeNo, ModeIdIndex); */
7678 /* XGI_ClearBankRegs(ModeNo, ModeIdIndex); */
7679 XGI_SetSeqRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7680 XGI_SetMiscRegs(StandTableIndex, pVBInfo);
7681 XGI_SetCRTCRegs(HwDeviceExtension, StandTableIndex, pVBInfo);
7682 XGI_SetATTRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
7683 XGI_SetGRCRegs(StandTableIndex, pVBInfo);
7684 XGI_ClearExt1Regs(pVBInfo);
7685
7686 /* if (pVBInfo->IF_DEF_ExpLink) */
7687 if (HwDeviceExtension->jChipType == XG27) {
7688 if (pVBInfo->IF_DEF_LVDS == 0)
7689 XGI_SetDefaultVCLK(pVBInfo);
7690 }
7691
7692 temp = ~ProgrammingCRT2;
7693 pVBInfo->SetFlag &= temp;
7694 pVBInfo->SelectCRT2Rate = 0;
7695
7696 if (pVBInfo->VBType & (VB_XGI301B | VB_XGI302B | VB_XGI301LV
7697 | VB_XGI302LV | VB_XGI301C)) {
7698 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA
7699 | SetInSlaveMode)) {
7700 pVBInfo->SetFlag |= ProgrammingCRT2;
7701 }
7702 }
7703
7704 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
7705 ModeIdIndex, pVBInfo);
7706 if (RefreshRateTableIndex != 0xFFFF) {
7707 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
7708 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7709 pVBInfo, HwDeviceExtension);
7710 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
7711 RefreshRateTableIndex, pVBInfo);
7712 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
7713 HwDeviceExtension, pVBInfo);
7714 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
7715 RefreshRateTableIndex, pVBInfo);
7716 }
7717
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007718 if ((HwDeviceExtension->jChipType >= XG20) &&
7719 (HwDeviceExtension->jChipType < XG27)) { /* fix H/W DCLK/2 bug */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007720 if ((ModeNo == 0x00) | (ModeNo == 0x01)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02007721 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x4E);
7722 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE9);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007723 b3CC = (unsigned char) inb(XGINew_P3cc);
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007724 outb((b3CC |= 0x0C), XGINew_P3cc);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007725 } else if ((ModeNo == 0x04) | (ModeNo == 0x05) | (ModeNo
7726 == 0x0D)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02007727 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
7728 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE3);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02007729 b3CC = (unsigned char) inb(XGINew_P3cc);
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02007730 outb((b3CC |= 0x0C), XGINew_P3cc);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007731 }
7732 }
7733
7734 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007735 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007736 if (temp & 0xA0) {
7737
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007738 /* Enable write GPIOF */
7739 /* xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x20); */
7740 /* P. DWN */
7741 /* xgifb_reg_and(pVBInfo->P3d4, 0x48, ~0x20); */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007742 /* XG21 CRT1 Timing */
7743 if (HwDeviceExtension->jChipType == XG27)
7744 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
7745 RefreshRateTableIndex, pVBInfo);
7746 else
7747 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
7748 RefreshRateTableIndex, pVBInfo);
7749
7750 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
7751 RefreshRateTableIndex);
7752
Aaro Koskinen105d8d02011-08-31 21:46:00 +03007753 xgifb_set_lcd(HwDeviceExtension->jChipType,
7754 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007755
Aaro Koskinen64db29f2011-08-31 21:46:01 +03007756 if (pVBInfo->IF_DEF_LVDS == 1)
7757 xgifb_set_lvds(HwDeviceExtension->jChipType,
7758 ModeNo, ModeIdIndex, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007759 /* P. ON */
7760 /* xgifb_reg_or(pVBInfo->P3d4, 0x48, 0x20); */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007761 }
7762 }
7763
7764 pVBInfo->SetFlag &= (~ProgrammingCRT2);
7765 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
7766 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
7767 RefreshRateTableIndex, pVBInfo);
7768
7769 /* XGI_LoadCharacter(); //dif ifdef TVFont */
7770
7771 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
7772 /* XGI_ClearBuffer(HwDeviceExtension, ModeNo, pVBInfo); */
7773}
7774
7775unsigned char XGISetModeNew(struct xgi_hw_device_info *HwDeviceExtension,
7776 unsigned short ModeNo)
7777{
7778 unsigned short ModeIdIndex;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007779 /* unsigned char *pVBInfo->FBAddr =
7780 HwDeviceExtension->pjVideoMemoryAddress; */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007781 struct vb_device_info VBINF;
7782 struct vb_device_info *pVBInfo = &VBINF;
7783 pVBInfo->ROMAddr = HwDeviceExtension->pjVirtualRomBase;
7784 pVBInfo->BaseAddr = (unsigned long) HwDeviceExtension->pjIOAddress;
7785 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007786 pVBInfo->IF_DEF_LCDA = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007787
7788 if (HwDeviceExtension->jChipType >= XG20) { /* kuku 2004/06/25 */
7789 pVBInfo->IF_DEF_YPbPr = 0;
7790 pVBInfo->IF_DEF_HiVision = 0;
7791 pVBInfo->IF_DEF_CRT2Monitor = 0;
7792 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007793 } else {
7794 pVBInfo->IF_DEF_YPbPr = 1;
7795 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02007796 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007797 }
7798
7799 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
7800 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
7801 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
7802 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
7803 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
7804 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
7805 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
7806 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
7807 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
7808 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
7809 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
7810 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
7811 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
7812 pVBInfo->Part1Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_04;
7813 pVBInfo->Part2Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_10;
7814 pVBInfo->Part3Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_12;
7815 pVBInfo->Part4Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14;
7816 pVBInfo->Part5Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_14 + 2;
7817
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007818 /* for x86 Linux, XG21 LVDS */
7819 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007820 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007821 pVBInfo->IF_DEF_LVDS = 1;
7822 }
7823 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02007824 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
7825 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007826 pVBInfo->IF_DEF_LVDS = 1;
7827 }
7828 }
7829
7830 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 */
7831 XGI_GetVBType(pVBInfo);
7832
7833 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
7834 if (ModeNo & 0x80) {
7835 ModeNo = ModeNo & 0x7F;
7836 /* XGINew_flag_clearbuffer = 0; */
7837 }
7838 /* else {
7839 XGINew_flag_clearbuffer = 1;
7840 }
7841 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02007842 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007843
7844 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 1.Openkey */
7845 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
7846
7847 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
7848
7849 XGI_GetVGAType(HwDeviceExtension, pVBInfo);
7850
7851 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
7852 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
7853 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
7854 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
7855 XGI_DisableBridge(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007856
7857 if (pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToLCDA)) {
7858 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
7859 ModeIdIndex, pVBInfo);
7860
7861 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7862 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7863 HwDeviceExtension, pVBInfo);
7864 }
7865 } else {
7866 if (!(pVBInfo->VBInfo & SwitchToCRT2)) {
7867 XGI_SetCRT1Group(HwDeviceExtension, ModeNo,
7868 ModeIdIndex, pVBInfo);
7869 if (pVBInfo->VBInfo & SetCRT2ToLCDA) {
7870 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
7871 HwDeviceExtension,
7872 pVBInfo);
7873 }
7874 }
7875 }
7876
7877 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchToCRT2)) {
7878 switch (HwDeviceExtension->ujVBChipID) {
7879 case VB_CHIP_301:
7880 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
7881 pVBInfo); /*add for CRT2 */
7882 break;
7883
7884 case VB_CHIP_302:
7885 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
7886 pVBInfo); /*add for CRT2 */
7887 break;
7888
7889 default:
7890 break;
7891 }
7892 }
7893
7894 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
7895 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
7896 XGI_CloseCRTC(HwDeviceExtension, pVBInfo);
7897 XGI_EnableBridge(HwDeviceExtension, pVBInfo);
7898 } /* !XG20 */
7899 else {
7900 if (pVBInfo->IF_DEF_LVDS == 1)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007901 if (!XGI_XG21CheckLVDSMode(ModeNo,
7902 ModeIdIndex,
7903 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007904 return 0;
7905
7906 if (ModeNo <= 0x13) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007907 pVBInfo->ModeType = pVBInfo->SModeIDTable[ModeIdIndex].
7908 St_ModeFlag & ModeInfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007909 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007910 pVBInfo->ModeType = pVBInfo->EModeIDTable[ModeIdIndex].
7911 Ext_ModeFlag & ModeInfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007912 }
7913
7914 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03007915 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007916
7917 XGI_DisplayOff(HwDeviceExtension, pVBInfo);
7918
7919 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex,
7920 pVBInfo);
7921
7922 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7923 /*
7924 if (HwDeviceExtension->jChipType == XG21)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02007925 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0x80, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007926 */
7927 }
7928
7929 /*
7930 if (ModeNo <= 0x13) {
7931 modeflag = pVBInfo->SModeIDTable[ModeIdIndex].St_ModeFlag;
7932 } else {
7933 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
7934 }
7935 pVBInfo->ModeType = modeflag&ModeInfoFlag;
7936 pVBInfo->SetFlag = 0x00;
7937 pVBInfo->VBInfo = DisableCRT2Display;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08007938 temp = XGINew_CheckMemorySize(HwDeviceExtension,
7939 ModeNo,
7940 ModeIdIndex,
7941 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02007942
7943 if (temp == 0)
7944 return (0);
7945
7946 XGI_DisplayOff(HwDeviceExtension, pVBInfo) ;
7947 XGI_SetCRT1Group(HwDeviceExtension, ModeNo, ModeIdIndex, pVBInfo);
7948 XGI_DisplayOn(HwDeviceExtension, pVBInfo);
7949 */
7950
7951 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
7952
7953 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
7954 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
7955 }
7956
7957 return 1;
7958}