blob: f1cc2100f0d445accc62bb0a09ff8ecefef38715 [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{
Peter Huewefc39dcb2012-01-15 19:22:12 +010063 pVBInfo->StandTable = (struct SiS_StandTable_S *) XGI330_StandTable;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053064 pVBInfo->EModeIDTable = (struct XGI_ExtStruct *) XGI330_EModeIDTable;
65 pVBInfo->RefIndex = (struct XGI_Ext2Struct *) XGI330_RefIndex;
66 pVBInfo->XGINEWUB_CRT1Table
67 = (struct XGI_CRT1TableStruct *) XGI_CRT1Table;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020068
Peter Huewefc39dcb2012-01-15 19:22:12 +010069 pVBInfo->MCLKData = (struct SiS_MCLKData *) XGI340New_MCLKData;
Aaro Koskinen06587332011-03-13 12:26:10 +020070 pVBInfo->ECLKData = (struct XGI_ECLKDataStruct *) XGI340_ECLKData;
Peter Huewefc39dcb2012-01-15 19:22:12 +010071 pVBInfo->VCLKData = (struct SiS_VCLKData *) XGI_VCLKData;
72 pVBInfo->VBVCLKData = (struct SiS_VBVCLKData *) XGI_VBVCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053073 pVBInfo->ScreenOffset = XGI330_ScreenOffset;
Peter Huewefc39dcb2012-01-15 19:22:12 +010074 pVBInfo->StResInfo = (struct SiS_StResInfo_S *) XGI330_StResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053075 pVBInfo->ModeResInfo
Peter Huewefc39dcb2012-01-15 19:22:12 +010076 = (struct SiS_ModeResInfo_S *) XGI330_ModeResInfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020077
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053078 pVBInfo->pOutputSelect = &XGI330_OutputSelect;
79 pVBInfo->pSoftSetting = &XGI330_SoftSetting;
80 pVBInfo->pSR07 = &XGI330_SR07;
81 pVBInfo->LCDResInfo = 0;
82 pVBInfo->LCDTypeInfo = 0;
83 pVBInfo->LCDInfo = 0;
84 pVBInfo->VBInfo = 0;
85 pVBInfo->TVInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020086
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053087 pVBInfo->SR15 = XGI340_SR13;
88 pVBInfo->CR40 = XGI340_cr41;
89 pVBInfo->SR25 = XGI330_sr25;
90 pVBInfo->pSR31 = &XGI330_sr31;
91 pVBInfo->pSR32 = &XGI330_sr32;
92 pVBInfo->CR6B = XGI340_CR6B;
93 pVBInfo->CR6E = XGI340_CR6E;
94 pVBInfo->CR6F = XGI340_CR6F;
95 pVBInfo->CR89 = XGI340_CR89;
96 pVBInfo->AGPReg = XGI340_AGPReg;
97 pVBInfo->SR16 = XGI340_SR16;
98 pVBInfo->pCRCF = &XG40_CRCF;
99 pVBInfo->pXGINew_DRAMTypeDefinition = &XG40_DRAMTypeDefinition;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530101 pVBInfo->CR49 = XGI330_CR49;
102 pVBInfo->pSR1F = &XGI330_SR1F;
103 pVBInfo->pSR21 = &XGI330_SR21;
104 pVBInfo->pSR22 = &XGI330_SR22;
105 pVBInfo->pSR23 = &XGI330_SR23;
106 pVBInfo->pSR24 = &XGI330_SR24;
107 pVBInfo->pSR33 = &XGI330_SR33;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200108
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530109 pVBInfo->pCRT2Data_1_2 = &XGI330_CRT2Data_1_2;
110 pVBInfo->pCRT2Data_4_D = &XGI330_CRT2Data_4_D;
111 pVBInfo->pCRT2Data_4_E = &XGI330_CRT2Data_4_E;
112 pVBInfo->pCRT2Data_4_10 = &XGI330_CRT2Data_4_10;
113 pVBInfo->pRGBSenseData = &XGI330_RGBSenseData;
114 pVBInfo->pVideoSenseData = &XGI330_VideoSenseData;
115 pVBInfo->pYCSenseData = &XGI330_YCSenseData;
116 pVBInfo->pRGBSenseData2 = &XGI330_RGBSenseData2;
117 pVBInfo->pVideoSenseData2 = &XGI330_VideoSenseData2;
118 pVBInfo->pYCSenseData2 = &XGI330_YCSenseData2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200119
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530120 pVBInfo->NTSCTiming = XGI330_NTSCTiming;
121 pVBInfo->PALTiming = XGI330_PALTiming;
122 pVBInfo->HiTVExtTiming = XGI330_HiTVExtTiming;
123 pVBInfo->HiTVSt1Timing = XGI330_HiTVSt1Timing;
124 pVBInfo->HiTVSt2Timing = XGI330_HiTVSt2Timing;
125 pVBInfo->HiTVTextTiming = XGI330_HiTVTextTiming;
126 pVBInfo->YPbPr750pTiming = XGI330_YPbPr750pTiming;
127 pVBInfo->YPbPr525pTiming = XGI330_YPbPr525pTiming;
128 pVBInfo->YPbPr525iTiming = XGI330_YPbPr525iTiming;
129 pVBInfo->HiTVGroup3Data = XGI330_HiTVGroup3Data;
130 pVBInfo->HiTVGroup3Simu = XGI330_HiTVGroup3Simu;
131 pVBInfo->HiTVGroup3Text = XGI330_HiTVGroup3Text;
132 pVBInfo->Ren525pGroup3 = XGI330_Ren525pGroup3;
133 pVBInfo->Ren750pGroup3 = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530135 pVBInfo->TimingH = (struct XGI_TimingHStruct *) XGI_TimingH;
136 pVBInfo->TimingV = (struct XGI_TimingVStruct *) XGI_TimingV;
137 pVBInfo->UpdateCRT1 = (struct XGI_XG21CRT1Struct *) XGI_UpdateCRT1Table;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200138
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530139 /* 310 customization related */
Peter Huewe6896b942012-02-09 21:11:46 +0100140 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530141 pVBInfo->LCDCapList = XGI_LCDDLCapList;
142 else
143 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200144
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530145 pVBInfo->XGI_TVDelayList = XGI301TVDelayList;
146 pVBInfo->XGI_TVDelayList2 = XGI301TVDelayList2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200147
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530148 pVBInfo->pXGINew_I2CDefinition = &XG40_I2CDefinition;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200149
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530150 if (ChipType >= XG20)
151 pVBInfo->pXGINew_CR97 = &XG20_CR97;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200152
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530153 if (ChipType == XG27) {
154 pVBInfo->MCLKData
Peter Huewefc39dcb2012-01-15 19:22:12 +0100155 = (struct SiS_MCLKData *) XGI27New_MCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530156 pVBInfo->CR40 = XGI27_cr41;
157 pVBInfo->pXGINew_CR97 = &XG27_CR97;
158 pVBInfo->pSR36 = &XG27_SR36;
159 pVBInfo->pCR8F = &XG27_CR8F;
160 pVBInfo->pCRD0 = XG27_CRD0;
161 pVBInfo->pCRDE = XG27_CRDE;
162 pVBInfo->pSR40 = &XG27_SR40;
163 pVBInfo->pSR41 = &XG27_SR41;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200164
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530165 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200166
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530167 if (ChipType >= XG20) {
168 pVBInfo->pDVOSetting = &XG21_DVOSetting;
169 pVBInfo->pCR2E = &XG21_CR2E;
170 pVBInfo->pCR2F = &XG21_CR2F;
171 pVBInfo->pCR46 = &XG21_CR46;
172 pVBInfo->pCR47 = &XG21_CR47;
173 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200174
175}
176
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800177static unsigned char XGI_GetModePtr(unsigned short ModeNo,
178 unsigned short ModeIdIndex,
179 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200180{
Aaro Koskinen969f7f32012-04-07 01:14:03 +0300181 return 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200182}
183
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800184static void XGI_SetSeqRegs(unsigned short ModeNo,
185 unsigned short StandTableIndex,
186 unsigned short ModeIdIndex,
187 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200188{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530189 unsigned char tempah, SRdata;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530190 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200191
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300192 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200193
Aaro Koskinen8104e322011-03-13 12:26:22 +0200194 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530195 tempah = pVBInfo->StandTable[StandTableIndex].SR[0];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200196
Peter Huewea3d675c2012-02-09 21:11:47 +0100197 i = XGI_SetCRT2ToLCDA;
198 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530199 tempah |= 0x01;
200 } else {
201 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
202 if (pVBInfo->VBInfo & SetInSlaveMode)
203 tempah |= 0x01;
204 }
205 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200206
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530207 tempah |= 0x20; /* screen off */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200208 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200209
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530210 for (i = 02; i <= 04; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800211 /* Get SR2,3,4 from file */
212 SRdata = pVBInfo->StandTable[StandTableIndex].SR[i - 1];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200213 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530214 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200215}
216
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200217static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800218 unsigned short StandTableIndex,
219 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200220{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530221 unsigned char CRTCdata;
222 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200223
Aaro Koskinen58839b02011-03-13 12:26:23 +0200224 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530225 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200226 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200227
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530228 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800229 /* Get CRTC from file */
230 CRTCdata = pVBInfo->StandTable[StandTableIndex].CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200231 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530232 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200233}
234
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800235static void XGI_SetATTRegs(unsigned short ModeNo,
236 unsigned short StandTableIndex,
237 unsigned short ModeIdIndex,
238 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200239{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530240 unsigned char ARdata;
241 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200242
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300243 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200244
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530245 for (i = 0; i <= 0x13; i++) {
246 ARdata = pVBInfo->StandTable[StandTableIndex].ATTR[i];
247 if (modeflag & Charx8Dot) { /* ifndef Dot9 */
248 if (i == 0x13) {
Peter Huewea3d675c2012-02-09 21:11:47 +0100249 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530250 ARdata = 0;
251 } else {
252 if (pVBInfo->VBInfo & (SetCRT2ToTV
253 | SetCRT2ToLCD)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800254 if (pVBInfo->VBInfo &
255 SetInSlaveMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530256 ARdata = 0;
257 }
258 }
259 }
260 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200261
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200262 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200263 outb(i, pVBInfo->P3c0); /* set index */
264 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530265 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200266
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200267 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200268 outb(0x14, pVBInfo->P3c0); /* set index */
269 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200270 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200271 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200272}
273
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200274static void XGI_SetGRCRegs(unsigned short StandTableIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800275 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200276{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530277 unsigned char GRdata;
278 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200279
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530280 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800281 /* Get GR from file */
282 GRdata = pVBInfo->StandTable[StandTableIndex].GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200283 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530284 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200285
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530286 if (pVBInfo->ModeType > ModeVGA) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200287 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530288 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200289 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530290 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200291}
292
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200293static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200294{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530295 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200296
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530297 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200298 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200299}
300
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200301static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200302{
303
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200304 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200305 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[0].SR2B);
306 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200307
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200308 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200309 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[1].SR2B);
310 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200311
Aaro Koskinendc505562011-03-13 12:26:26 +0200312 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530313 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200314}
315
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200316static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530317 unsigned short ModeIdIndex,
318 unsigned short RefreshRateTableIndex, unsigned short *i,
319 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200320{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530321 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200322
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300323 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530324 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
325 tempbx = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID;
326 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200327
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530328 if (pVBInfo->IF_DEF_LVDS == 0) {
329 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
330 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200331
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530332 if (pVBInfo->VBType & VB_XGI301C)
333 tempax |= SupportCRT2in301C;
334 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200335
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800336 /* 301b */
Peter Huewea3d675c2012-02-09 21:11:47 +0100337 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530338 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200339
Peter Huewe255aabd2012-02-09 21:11:44 +0100340 if (pVBInfo->LCDResInfo != Panel_1280x1024) {
341 if (pVBInfo->LCDResInfo != Panel_1280x960) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800342 if (pVBInfo->LCDInfo &
343 LCDNonExpanding) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530344 if (resinfo >= 9) {
345 tempax = 0;
346 return 0;
347 }
348 }
349 }
350 }
351 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200352
Peter Huewe599801f2012-02-09 21:11:45 +0100353 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
Peter Huewe6896b942012-02-09 21:11:46 +0100354 if ((pVBInfo->VBType & VB_SIS301LV) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800355 (pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
Peter Huewe6896b942012-02-09 21:11:46 +0100356 tempax |= SupportYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530357 if (pVBInfo->VBInfo & SetInSlaveMode) {
358 if (resinfo == 4)
359 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200360
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530361 if (resinfo == 3)
362 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200363
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530364 if (resinfo > 7)
365 return 0;
366 }
367 } else {
Peter Huewe6896b942012-02-09 21:11:46 +0100368 tempax |= SupportHiVision;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530369 if (pVBInfo->VBInfo & SetInSlaveMode) {
370 if (resinfo == 4)
371 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200372
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530373 if (resinfo == 3) {
374 if (pVBInfo->SetFlag
375 & TVSimuMode)
376 return 0;
377 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200378
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530379 if (resinfo > 7)
380 return 0;
381 }
382 }
383 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800384 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
385 SetCRT2ToSVIDEO |
386 SetCRT2ToSCART |
Peter Huewe599801f2012-02-09 21:11:45 +0100387 SetCRT2ToYPbPr525750 |
388 SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530389 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200390
Peter Huewe6896b942012-02-09 21:11:46 +0100391 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
392 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530393 | VB_XGI301C)) {
394 tempax |= SupportTV1024;
395 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200396
Peter Huewe599801f2012-02-09 21:11:45 +0100397 if (!(pVBInfo->VBInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530398 if (modeflag & NoSupportSimuTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800399 if (pVBInfo->VBInfo &
400 SetInSlaveMode) {
401 if (!(pVBInfo->VBInfo &
402 SetNotSimuMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530403 return 0;
404 }
405 }
406 }
407 }
408 }
409 }
410 } else { /* for LVDS */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530411 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
412 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200413
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530414 if (resinfo > 0x08)
415 return 0; /* 1024x768 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200416
Peter Huewe255aabd2012-02-09 21:11:44 +0100417 if (pVBInfo->LCDResInfo < Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530418 if (resinfo > 0x07)
419 return 0; /* 800x600 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200420
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530421 if (resinfo == 0x04)
422 return 0; /* 512x384 */
423 }
424 }
425 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200426
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800427 for (; pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
428 tempbx; (*i)--) {
429 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
430 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530431 if (infoflag & tempax)
432 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200433
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530434 if ((*i) == 0)
435 break;
436 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200437
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530438 for ((*i) = 0;; (*i)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800439 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
440 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530441 if (pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID
442 != tempbx) {
443 return 0;
444 }
445
446 if (infoflag & tempax)
447 return 1;
448 }
449 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200450}
451
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200452static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530453 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200454{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530455 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200456
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800457 /* di+0x00 */
458 sync = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530459 sync &= 0xC0;
460 temp = 0x2F;
461 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200462 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200463}
464
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200465static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530466 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200467{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530468 unsigned char data, data1, pushax;
469 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200470
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800471 /* unlock cr0-7 */
472 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530473 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200474 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200475
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530476 data = pVBInfo->TimingH[0].data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200477 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200478
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530479 for (i = 0x01; i <= 0x04; i++) {
480 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200481 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530482 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200483
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530484 for (i = 0x05; i <= 0x06; i++) {
485 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200486 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530487 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200488
Aaro Koskinen58839b02011-03-13 12:26:23 +0200489 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530490 j &= 0x1F;
491 data = pVBInfo->TimingH[0].data[7];
492 data &= 0xE0;
493 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200494 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200495
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530496 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200497 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530498 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200499 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200500 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530501 data1 = data;
502 data1 &= 0xE0;
503 data &= 0x1F;
504 if (data == 0) {
505 pushax = data;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200506 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530507 0x0c);
508 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200509 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530510 data = pushax;
511 }
512 data = data - 1;
513 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200514 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200515 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530516 data = data >> 5;
517 data = data + 3;
518 if (data > 7)
519 data = data - 7;
520 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200521 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530522 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200523}
524
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800525static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
526 unsigned short ModeNo,
527 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200528{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530529 unsigned char data;
530 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200531
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530532 for (i = 0x00; i <= 0x01; i++) {
533 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200534 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530535 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200536
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530537 for (i = 0x02; i <= 0x03; i++) {
538 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200539 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530540 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200541
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530542 for (i = 0x04; i <= 0x05; i++) {
543 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200544 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530545 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200546
Aaro Koskinen58839b02011-03-13 12:26:23 +0200547 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530548 j &= 0xC0;
549 data = pVBInfo->TimingV[0].data[6];
550 data &= 0x3F;
551 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200552 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200553
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530554 data = pVBInfo->TimingV[0].data[6];
555 data &= 0x80;
556 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200557
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300558 i = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530559 i &= DoubleScanMode;
560 if (i)
561 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200562
Aaro Koskinen58839b02011-03-13 12:26:23 +0200563 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530564 j &= 0x5F;
565 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200566 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200567}
568
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200569static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
570 unsigned short RefreshRateTableIndex,
571 struct vb_device_info *pVBInfo,
572 struct xgi_hw_device_info *HwDeviceExtension)
573{
574 unsigned char index, data;
575 unsigned short i;
576
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800577 /* Get index */
578 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200579 index = index & IndexMask;
580
Aaro Koskinen58839b02011-03-13 12:26:23 +0200581 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200582 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200583 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200584
585 for (i = 0; i < 8; i++)
586 pVBInfo->TimingH[0].data[i]
587 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i];
588
589 for (i = 0; i < 7; i++)
590 pVBInfo->TimingV[0].data[i]
591 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i + 8];
592
593 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
594
595 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
596
597 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200598 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200599}
600
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200601/* --------------------------------------------------------------------- */
602/* Function : XGI_SetXG21CRTC */
603/* Input : Stand or enhance CRTC table */
604/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
605/* Description : Set LCD timing */
606/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200607static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530608 unsigned short RefreshRateTableIndex,
609 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200610{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300611 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530612 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200613
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300614 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
615 /* Tempax: CR4 HRS */
616 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
617 Tempcx = Tempax; /* Tempcx: HRS */
618 /* SR2E[7:0]->HRS */
619 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200620
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300621 Tempdx = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SRB */
622 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
623 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
624 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
625 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800626
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300627 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
628 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200629
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300630 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
631 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
632 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
633 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200634
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300635 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
636 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200637
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300638 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
639 if (Tempax < Tempcx) /* HRE < HRS */
640 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200641
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300642 Temp2 &= 0xFF;
643 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
644 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
645 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
646 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
647 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
648 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
649 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200650
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300651 /* CR10 VRS */
652 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
653 Tempbx = Tempax; /* Tempbx: VRS */
654 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
655 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
656 /* CR7[2][7] VRE */
657 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
658 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
659 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
660 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
661 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
662 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200663
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300664 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
665 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
666 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
667 Tempax &= 0x80;
668 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
669 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
670 /* Tempax: SRA */
671 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
672 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
673 Temp2 = Tempax;
674 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
675 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200676
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300677 /* Tempax: CR11 VRE */
678 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
679 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
680 /* Tempbx: SRA */
681 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
682 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
683 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
684 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
685 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
686 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200687
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300688 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
689 if (Tempax < Temp3) /* VRE < VRS */
690 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200691
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300692 Temp2 &= 0xFF;
693 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
694 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
695 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
696 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
697 Tempbx = (unsigned char) Temp1;
698 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
699 Tempax &= 0x7F;
700 /* SR3F D[7:2]->VRE D[1:0]->VRS */
701 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200702}
703
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800704static void XGI_SetXG27CRTC(unsigned short ModeNo,
705 unsigned short ModeIdIndex,
706 unsigned short RefreshRateTableIndex,
707 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200708{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300709 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200710
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300711 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
712 /* Tempax: CR4 HRS */
713 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
714 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
715 /* SR2E[7:0]->HRS */
716 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200717
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300718 /* SR0B */
719 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5];
720 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
721 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200722
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300723 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
724 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
725 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200726
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300727 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
728 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
729 Tempax <<= 3; /* Tempax[5]: HRE[5] */
730 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200731
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300732 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
733 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200734
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300735 /* Tempax: CR4 HRS */
736 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
737 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
738 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
739 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200740
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300741 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SR0B */
742 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
743 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
744 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
745 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
746 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
747 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200748
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300749 /* CR10 VRS */
750 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
751 /* SR34[7:0]->VRS[7:0] */
752 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200753
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300754 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
755 /* CR7[7][2] VRS[9][8] */
756 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
757 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
758 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
759 Tempax >>= 2; /* Tempax[0]: VRS[8] */
760 /* SR35[0]: VRS[8] */
761 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
762 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
763 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
764 /* Tempax: SR0A */
765 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
766 Tempax &= 0x08; /* SR0A[3] VRS[10] */
767 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200768
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300769 /* Tempax: CR11 VRE */
770 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
771 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
772 /* Tempbx: SR0A */
773 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
774 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
775 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
776 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
777 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
778 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
779 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200780
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300781 if (Tempbx <= Tempcx) /* VRE <= VRS */
782 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200783
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300784 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
785 Tempax = (Tempbx << 2) & 0xFF;
786 /* SR3F[7:2]:VRE[5:0] */
787 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
788 Tempax = Tempcx >> 8;
789 /* SR35[2:0]:VRS[10:8] */
790 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200791}
792
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200793static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
794{
795 unsigned char temp;
796
797 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
798 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
799 temp = (temp & 3) << 6;
800 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
801 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
802 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
803 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
804
805}
806
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300807static void xgifb_set_lcd(int chip_id,
808 struct vb_device_info *pVBInfo,
809 unsigned short RefreshRateTableIndex,
810 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200811{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300812 unsigned short Data, Temp;
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400813 unsigned short XGI_P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200814
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530815 XGI_P3cc = pVBInfo->P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200816
Aaro Koskinen8104e322011-03-13 12:26:22 +0200817 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
818 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
819 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
820 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300821
822 if (chip_id == XG27) {
823 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
824 if ((Temp & 0x03) == 0) { /* dual 12 */
825 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
826 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
827 }
828 }
829
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530830 if (((*pVBInfo->pDVOSetting) & 0xC0) == 0xC0) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200831 xgifb_reg_set(pVBInfo->P3d4, 0x2E, *pVBInfo->pCR2E);
832 xgifb_reg_set(pVBInfo->P3d4, 0x2F, *pVBInfo->pCR2F);
833 xgifb_reg_set(pVBInfo->P3d4, 0x46, *pVBInfo->pCR46);
834 xgifb_reg_set(pVBInfo->P3d4, 0x47, *pVBInfo->pCR47);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530835 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200836
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300837 if (chip_id == XG27) {
838 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530839 } else {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300840 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
841 if (Temp & 0x01) {
842 /* 18 bits FP */
843 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
844 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
845 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530846 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200847
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200848 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200849
Aaro Koskinendc505562011-03-13 12:26:26 +0200850 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
851 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200852
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300853 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
854 if (Data & 0x4000)
855 /* Hsync polarity */
856 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
857 if (Data & 0x8000)
858 /* Vsync polarity */
859 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200860}
861
862/* --------------------------------------------------------------------- */
863/* Function : XGI_UpdateXG21CRTC */
864/* Input : */
865/* Output : CRT1 CRTC */
866/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
867/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800868static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
869 struct vb_device_info *pVBInfo,
870 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200871{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300872 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200873
Aaro Koskinendc505562011-03-13 12:26:26 +0200874 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300875 if (ModeNo == 0x2E &&
876 (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
877 RES640x480x60))
878 index = 12;
879 else if (ModeNo == 0x2E && (pVBInfo->RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800880 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300881 index = 13;
882 else if (ModeNo == 0x2F)
883 index = 14;
884 else if (ModeNo == 0x50)
885 index = 15;
886 else if (ModeNo == 0x59)
887 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200888
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530889 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200890 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530891 pVBInfo->UpdateCRT1[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200892 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530893 pVBInfo->UpdateCRT1[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200894 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530895 pVBInfo->UpdateCRT1[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200896 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530897 pVBInfo->UpdateCRT1[index].CR16);
898 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200899}
900
Aaro Koskinen06465962011-11-27 23:03:06 +0200901static unsigned short XGI_GetResInfo(unsigned short ModeNo,
902 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
903{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300904 /* si+Ext_ResInfo */
905 return pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen06465962011-11-27 23:03:06 +0200906}
907
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200908static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530909 unsigned short ModeNo, unsigned short ModeIdIndex,
910 unsigned short RefreshRateTableIndex,
911 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200912{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400913 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200914
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530915 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200916
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530917 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200918
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300919 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
920 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
921 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200922
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530923 if (modeflag & HalfDCLK)
924 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200925
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300926 if (modeflag & HalfDCLK)
927 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200928
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300929 temp = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200930
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300931 if (temp & InterlaceMode)
932 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200933
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300934 if (modeflag & DoubleScanMode)
935 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200936
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530937 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200938
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530939 tempax /= tempcx;
940 tempax -= 1;
941 tempbx -= 1;
942 tempcx = tempax;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200943 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
944 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530945 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200946 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
947 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200948 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530949 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200950 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530951 tempax = 0;
952 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200953
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530954 if (tempbx & 0x01)
955 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200956
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530957 if (tempbx & 0x02)
958 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200959
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200960 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200961 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530962 data &= 0xFF;
963 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200964
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530965 if (tempbx & 0x04)
966 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200967
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200968 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200969 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200970}
971
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800972static void XGI_SetCRT1Offset(unsigned short ModeNo,
973 unsigned short ModeIdIndex,
974 unsigned short RefreshRateTableIndex,
975 struct xgi_hw_device_info *HwDeviceExtension,
976 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200977{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530978 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200979
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530980 /* GetOffset */
981 temp = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
982 temp = temp >> 8;
983 temp = pVBInfo->ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200984
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530985 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
986 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200987
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530988 if (temp2)
989 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200990
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530991 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200992
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530993 switch (temp2) {
994 case 0:
995 temp2 = 1;
996 break;
997 case 1:
998 temp2 = 2;
999 break;
1000 case 2:
1001 temp2 = 4;
1002 break;
1003 case 3:
1004 temp2 = 4;
1005 break;
1006 case 4:
1007 temp2 = 6;
1008 break;
1009 case 5:
1010 temp2 = 8;
1011 break;
1012 default:
1013 break;
1014 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001015
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301016 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
1017 temp = temp * temp2 + temp2 / 2;
1018 else
1019 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001020
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301021 /* SetOffset */
1022 DisplayUnit = temp;
1023 temp2 = temp;
1024 temp = temp >> 8; /* ah */
1025 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001026 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301027 i &= 0xF0;
1028 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001029 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001030
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301031 temp = (unsigned char) temp2;
1032 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +02001033 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001034
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301035 /* SetDisplayUnit */
1036 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
1037 temp2 &= InterlaceMode;
1038 if (temp2)
1039 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001040
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301041 DisplayUnit = DisplayUnit << 5;
1042 ah = (DisplayUnit & 0xff00) >> 8;
1043 al = DisplayUnit & 0x00ff;
1044 if (al == 0)
1045 ah += 1;
1046 else
1047 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001048
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301049 if (HwDeviceExtension->jChipType >= XG20)
1050 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
1051 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001052
Aaro Koskinen8104e322011-03-13 12:26:22 +02001053 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001054}
1055
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001056static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
1057 unsigned short ModeIdIndex,
1058 unsigned short RefreshRateTableIndex,
1059 struct xgi_hw_device_info *HwDeviceExtension,
1060 struct vb_device_info *pVBInfo)
1061{
Peter Huewe6896b942012-02-09 21:11:46 +01001062 unsigned short LCDXlat1VCLK[4] = { VCLK65_315 + 2,
1063 VCLK65_315 + 2,
1064 VCLK65_315 + 2,
1065 VCLK65_315 + 2 };
1066 unsigned short LCDXlat2VCLK[4] = { VCLK108_2_315 + 5,
1067 VCLK108_2_315 + 5,
1068 VCLK108_2_315 + 5,
1069 VCLK108_2_315 + 5 };
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001070 unsigned short LVDSXlat1VCLK[4] = { VCLK40, VCLK40, VCLK40, VCLK40 };
Peter Huewe6896b942012-02-09 21:11:46 +01001071 unsigned short LVDSXlat2VCLK[4] = { VCLK65_315 + 2,
1072 VCLK65_315 + 2,
1073 VCLK65_315 + 2,
1074 VCLK65_315 + 2 };
1075 unsigned short LVDSXlat3VCLK[4] = { VCLK65_315 + 2,
1076 VCLK65_315 + 2,
1077 VCLK65_315 + 2,
1078 VCLK65_315 + 2 };
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001079
1080 unsigned short CRT2Index, VCLKIndex;
1081 unsigned short modeflag, resinfo;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001082
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001083 /* si+Ext_ResInfo */
1084 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1085 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
1086 CRT2Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001087
1088 if (pVBInfo->IF_DEF_LVDS == 0) {
1089 CRT2Index = CRT2Index >> 6; /* for LCD */
Peter Huewea3d675c2012-02-09 21:11:47 +01001090 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
Peter Huewe255aabd2012-02-09 21:11:44 +01001091 if (pVBInfo->LCDResInfo != Panel_1024x768)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001092 VCLKIndex = LCDXlat2VCLK[CRT2Index];
1093 else
1094 VCLKIndex = LCDXlat1VCLK[CRT2Index];
Peter Huewe599801f2012-02-09 21:11:45 +01001095 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001096 if (pVBInfo->SetFlag & RPLLDIV2XO) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001097 VCLKIndex = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001098 VCLKIndex += 25;
1099 } else {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001100 VCLKIndex = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001101 VCLKIndex += 25;
1102 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001103
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001104 if (pVBInfo->SetFlag & TVSimuMode) {
1105 if (modeflag & Charx8Dot) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001106 VCLKIndex = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001107 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001108 } else {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001109 VCLKIndex = TVCLKBASE_315 + HiTVTextVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001110 VCLKIndex += 25;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001111 }
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001112 }
1113
1114 /* 301lv */
Peter Huewe6896b942012-02-09 21:11:46 +01001115 if ((pVBInfo->VBType & VB_SIS301LV) &&
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001116 !(pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
Peter Huewe6896b942012-02-09 21:11:46 +01001117 if (pVBInfo->VBExtInfo == YPbPr750p)
Peter Huewea3d675c2012-02-09 21:11:47 +01001118 VCLKIndex = XGI_YPbPr750pVCLK;
Peter Huewe6896b942012-02-09 21:11:46 +01001119 else if (pVBInfo->VBExtInfo == YPbPr525p)
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001120 VCLKIndex = YPbPr525pVCLK;
1121 else if (pVBInfo->SetFlag & RPLLDIV2XO)
1122 VCLKIndex = YPbPr525iVCLK_2;
1123 else
1124 VCLKIndex = YPbPr525iVCLK;
1125 }
1126 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
1127 if (pVBInfo->SetFlag & RPLLDIV2XO) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001128 VCLKIndex = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001129 VCLKIndex += 25;
1130 } else {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001131 VCLKIndex = TVCLKBASE_315 + TVVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001132 VCLKIndex += 25;
1133 }
1134 } else { /* for CRT2 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001135 /* di+Ext_CRTVCLK */
1136 VCLKIndex = pVBInfo->RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001137 Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001138 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001139 }
1140 } else { /* LVDS */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001141 VCLKIndex = CRT2Index;
Aaro Koskinen4c14bfd2011-08-31 21:45:57 +03001142 VCLKIndex = VCLKIndex >> 6;
Peter Huewe255aabd2012-02-09 21:11:44 +01001143 if ((pVBInfo->LCDResInfo == Panel_800x600) ||
1144 (pVBInfo->LCDResInfo == Panel_320x480))
Aaro Koskinen4c14bfd2011-08-31 21:45:57 +03001145 VCLKIndex = LVDSXlat1VCLK[VCLKIndex];
Peter Huewe255aabd2012-02-09 21:11:44 +01001146 else if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1147 (pVBInfo->LCDResInfo == Panel_1024x768x75))
Aaro Koskinen4c14bfd2011-08-31 21:45:57 +03001148 VCLKIndex = LVDSXlat2VCLK[VCLKIndex];
1149 else
1150 VCLKIndex = LVDSXlat3VCLK[VCLKIndex];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001151 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001152
1153 return VCLKIndex;
1154}
1155
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001156static void XGI_SetCRT1VCLK(unsigned short ModeNo,
1157 unsigned short ModeIdIndex,
1158 struct xgi_hw_device_info *HwDeviceExtension,
1159 unsigned short RefreshRateTableIndex,
1160 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001161{
Bill Pemberton108afbf2010-06-17 13:10:47 -04001162 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301163 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001164
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301165 if (pVBInfo->IF_DEF_LVDS == 1) {
1166 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001167 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001168 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1169 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301170 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001171 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301172 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001173 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Peter Huewe6896b942012-02-09 21:11:46 +01001174 } else if ((pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1175 | VB_SIS302LV | VB_XGI301C)) && (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01001176 & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301177 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
1178 RefreshRateTableIndex, HwDeviceExtension,
1179 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001180 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001181 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301182 data = pVBInfo->VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001183 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301184 data = pVBInfo->VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001185 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1186 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301187 } else {
1188 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001189 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001190 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1191 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301192 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001193 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301194 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001195 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301196 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001197
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301198 if (HwDeviceExtension->jChipType >= XG20) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001199 if (pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag &
1200 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001201 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001202 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001203 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301204 index = data;
1205 index &= 0xE0;
1206 data &= 0x1F;
1207 data = data << 1;
1208 data += 1;
1209 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001210 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301211 }
1212 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001213}
1214
Aaro Koskinene85f2032011-11-27 23:03:07 +02001215static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
1216{
1217 unsigned char temp;
1218
1219 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
1220 temp = (temp & 1) << 6;
1221 /* SR06[6] 18bit Dither */
1222 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
1223 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
1224 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
1225
1226}
1227
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001228static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301229 struct xgi_hw_device_info *HwDeviceExtension,
1230 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001231{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301232 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001233
Aaro Koskinen58839b02011-03-13 12:26:23 +02001234 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301235 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001236 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001237
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001238 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
1239 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1240 data &= 0xC0;
1241 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
1242 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1243 data |= 0x01;
1244 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001245
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301246 if (HwDeviceExtension->jChipType == XG21)
1247 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001248}
1249
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001250static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1251 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1252 struct vb_device_info *pVBInfo)
1253{
1254 unsigned short data, data2 = 0;
1255 short VCLK;
1256
1257 unsigned char index;
1258
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001259 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1260 index &= IndexMask;
1261 VCLK = pVBInfo->VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001262
Aaro Koskinen58839b02011-03-13 12:26:23 +02001263 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001264 data &= 0xf3;
1265 if (VCLK >= 200)
1266 data |= 0x0c; /* VCLK > 200 */
1267
1268 if (HwDeviceExtension->jChipType >= XG20)
1269 data &= ~0x04; /* 2 pixel mode */
1270
Aaro Koskinen8104e322011-03-13 12:26:22 +02001271 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001272
1273 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001274 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001275 data &= 0xE7;
1276 if (VCLK < 200)
1277 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001278 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001279 }
1280
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001281 data2 = 0x00;
1282
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001283 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001284 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001285 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001286
1287}
1288
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001289static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301290 unsigned short ModeNo, unsigned short ModeIdIndex,
1291 unsigned short RefreshRateTableIndex,
1292 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001293{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301294 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1295 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001296
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001297 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1298 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001299
Aaro Koskinen58839b02011-03-13 12:26:23 +02001300 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001301 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001302
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001303 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301304 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001305 data2 |= 0x02;
1306 data3 = pVBInfo->ModeType - ModeVGA;
1307 data3 = data3 << 2;
1308 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301309 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001310
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301311 if (data)
1312 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001313
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001314 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301315 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001316 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001317
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301318 data = 0x0000;
1319 if (infoflag & InterlaceMode) {
1320 if (xres == 1024)
1321 data = 0x0035;
1322 else if (xres == 1280)
1323 data = 0x0048;
1324 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001325
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301326 data2 = data & 0x00FF;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001327 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301328 data2 = (data & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001329 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001330
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301331 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001332 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001333
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301334 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001335
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301336 if (modeflag & LineCompareOff)
1337 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001338
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001339 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301340 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001341 data = data ^ 0x60;
1342 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001343 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001344
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301345 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1346 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001347
Aaro Koskinen58839b02011-03-13 12:26:23 +02001348 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001349
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301350 if (HwDeviceExtension->jChipType == XG27) {
1351 if (data & 0x40)
1352 data = 0x2c;
1353 else
1354 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001355 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001356 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301357 } else if (HwDeviceExtension->jChipType >= XG20) {
1358 if (data & 0x40)
1359 data = 0x33;
1360 else
1361 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001362 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1363 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301364 } else {
1365 if (data & 0x40)
1366 data = 0x2c;
1367 else
1368 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001369 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301370 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001371
1372}
1373
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001374static void XGI_WriteDAC(unsigned short dl,
1375 unsigned short ah,
1376 unsigned short al,
1377 unsigned short dh,
1378 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001379{
1380 unsigned short temp, bh, bl;
1381
1382 bh = ah;
1383 bl = al;
1384
1385 if (dl != 0) {
1386 temp = bh;
1387 bh = dh;
1388 dh = temp;
1389 if (dl == 1) {
1390 temp = bl;
1391 bl = dh;
1392 dh = temp;
1393 } else {
1394 temp = bl;
1395 bl = bh;
1396 bh = temp;
1397 }
1398 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001399 outb((unsigned short) dh, pVBInfo->P3c9);
1400 outb((unsigned short) bh, pVBInfo->P3c9);
1401 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001402}
1403
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001404static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301405 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001406{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301407 unsigned short data, data2, time, i, j, k, m, n, o, si, di, bx, dl, al,
Aaro Koskinen624554d2011-10-11 21:47:35 +03001408 ah, dh;
1409 const unsigned short *table = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001410
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001411 data = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301412 data &= DACInfoFlag;
1413 time = 64;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001414
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301415 if (data == 0x00)
1416 table = XGINew_MDA_DAC;
1417 else if (data == 0x08)
1418 table = XGINew_CGA_DAC;
1419 else if (data == 0x10)
1420 table = XGINew_EGA_DAC;
1421 else if (data == 0x18) {
1422 time = 256;
1423 table = XGINew_VGA_DAC;
1424 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001425
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301426 if (time == 256)
1427 j = 16;
1428 else
1429 j = time;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001430
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001431 outb(0xFF, pVBInfo->P3c6);
1432 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001433
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301434 for (i = 0; i < j; i++) {
1435 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001436
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301437 for (k = 0; k < 3; k++) {
1438 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001439
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301440 if (data & 0x01)
1441 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001442
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301443 if (data & 0x02)
1444 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001445
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001446 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301447 data = data >> 2;
1448 }
1449 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001450
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301451 if (time == 256) {
1452 for (i = 16; i < 32; i++) {
1453 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001454
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301455 for (k = 0; k < 3; k++)
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001456 outb(data, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301457 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001458
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301459 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001460
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301461 for (m = 0; m < 9; m++) {
1462 di = si;
1463 bx = si + 0x04;
1464 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001465
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301466 for (n = 0; n < 3; n++) {
1467 for (o = 0; o < 5; o++) {
1468 dh = table[si];
1469 ah = table[di];
1470 al = table[bx];
1471 si++;
1472 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1473 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001474
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301475 si -= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001476
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301477 for (o = 0; o < 3; o++) {
1478 dh = table[bx];
1479 ah = table[di];
1480 al = table[si];
1481 si--;
1482 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1483 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001484
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301485 dl++;
1486 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001487
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301488 si += 5;
1489 }
1490 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001491}
1492
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001493static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1494 unsigned short ModeIdIndex,
1495 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001496{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301497 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001498
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001499 /* si+Ext_ResInfo */
1500 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001501
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001502 /* si+Ext_ResInfo */
1503 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001504
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001505 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1506 yres = pVBInfo->ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001507
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001508 if (modeflag & HalfDCLK)
1509 xres = xres << 1;
1510
1511 if (modeflag & DoubleScanMode)
1512 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001513
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301514 if (xres == 720)
1515 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001516
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301517 pVBInfo->VGAHDE = xres;
1518 pVBInfo->HDE = xres;
1519 pVBInfo->VGAVDE = yres;
1520 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001521}
1522
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001523static void *XGI_GetLcdPtr(unsigned short BX, unsigned short ModeNo,
1524 unsigned short ModeIdIndex,
1525 unsigned short RefreshRateTableIndex,
1526 struct vb_device_info *pVBInfo)
1527{
1528 unsigned short i, tempdx, tempcx, tempbx, tempal, modeflag, table;
1529
1530 struct XGI330_LCDDataTablStruct *tempdi = NULL;
1531
1532 tempbx = BX;
1533
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001534 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1535 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001536
1537 tempal = tempal & 0x0f;
1538
1539 if (tempbx <= 1) { /* ExpLink */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001540 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001541
Peter Huewea3d675c2012-02-09 21:11:47 +01001542 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001543 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001544 Ext_CRT2CRTC2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001545 }
1546
1547 if (tempbx & 0x01)
1548 tempal = (tempal >> 4);
1549
1550 tempal = (tempal & 0x0f);
1551 }
1552
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02001553 tempcx = LCDLenList[tempbx];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001554
1555 if (pVBInfo->LCDInfo & EnableScalingLCD) { /* ScaleLCD */
1556 if ((tempbx == 5) || (tempbx) == 7)
1557 tempcx = LCDDesDataLen2;
1558 else if ((tempbx == 3) || (tempbx == 8))
1559 tempcx = LVDSDesDataLen2;
1560 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001561
1562 switch (tempbx) {
1563 case 0:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001564 case 1:
Aaro Koskinencc5c2ae2011-08-31 21:46:08 +03001565 tempdi = xgifb_epllcd_crt1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001566 break;
1567 case 2:
1568 tempdi = XGI_EPLLCDDataPtr;
1569 break;
1570 case 3:
1571 tempdi = XGI_EPLLCDDesDataPtr;
1572 break;
1573 case 4:
1574 tempdi = XGI_LCDDataTable;
1575 break;
1576 case 5:
1577 tempdi = XGI_LCDDesDataTable;
1578 break;
1579 case 6:
1580 tempdi = XGI_EPLCHLCDRegPtr;
1581 break;
1582 case 7:
1583 case 8:
1584 case 9:
1585 tempdi = NULL;
1586 break;
1587 default:
1588 break;
1589 }
1590
1591 if (tempdi == NULL) /* OEMUtil */
1592 return NULL;
1593
1594 table = tempbx;
1595 i = 0;
1596
1597 while (tempdi[i].PANELID != 0xff) {
1598 tempdx = pVBInfo->LCDResInfo;
1599 if (tempbx & 0x0080) { /* OEMUtil */
1600 tempbx &= (~0x0080);
1601 tempdx = pVBInfo->LCDTypeInfo;
1602 }
1603
1604 if (pVBInfo->LCDInfo & EnableScalingLCD)
1605 tempdx &= (~PanelResInfo);
1606
1607 if (tempdi[i].PANELID == tempdx) {
1608 tempbx = tempdi[i].MASK;
1609 tempdx = pVBInfo->LCDInfo;
1610
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001611 if (modeflag & HalfDCLK)
1612 tempdx |= SetLCDLowResolution;
1613
1614 tempbx &= tempdx;
1615 if (tempbx == tempdi[i].CAP)
1616 break;
1617 }
1618 i++;
1619 }
1620
1621 if (table == 0) {
1622 switch (tempdi[i].DATAPTR) {
1623 case 0:
1624 return &XGI_LVDSCRT11024x768_1_H[tempal];
1625 break;
1626 case 1:
1627 return &XGI_LVDSCRT11024x768_2_H[tempal];
1628 break;
1629 case 2:
1630 return &XGI_LVDSCRT11280x1024_1_H[tempal];
1631 break;
1632 case 3:
1633 return &XGI_LVDSCRT11280x1024_2_H[tempal];
1634 break;
1635 case 4:
1636 return &XGI_LVDSCRT11400x1050_1_H[tempal];
1637 break;
1638 case 5:
1639 return &XGI_LVDSCRT11400x1050_2_H[tempal];
1640 break;
1641 case 6:
1642 return &XGI_LVDSCRT11600x1200_1_H[tempal];
1643 break;
1644 case 7:
1645 return &XGI_LVDSCRT11024x768_1_Hx75[tempal];
1646 break;
1647 case 8:
1648 return &XGI_LVDSCRT11024x768_2_Hx75[tempal];
1649 break;
1650 case 9:
1651 return &XGI_LVDSCRT11280x1024_1_Hx75[tempal];
1652 break;
1653 case 10:
1654 return &XGI_LVDSCRT11280x1024_2_Hx75[tempal];
1655 break;
1656 default:
1657 break;
1658 }
1659 } else if (table == 1) {
1660 switch (tempdi[i].DATAPTR) {
1661 case 0:
1662 return &XGI_LVDSCRT11024x768_1_V[tempal];
1663 break;
1664 case 1:
1665 return &XGI_LVDSCRT11024x768_2_V[tempal];
1666 break;
1667 case 2:
1668 return &XGI_LVDSCRT11280x1024_1_V[tempal];
1669 break;
1670 case 3:
1671 return &XGI_LVDSCRT11280x1024_2_V[tempal];
1672 break;
1673 case 4:
1674 return &XGI_LVDSCRT11400x1050_1_V[tempal];
1675 break;
1676 case 5:
1677 return &XGI_LVDSCRT11400x1050_2_V[tempal];
1678 break;
1679 case 6:
1680 return &XGI_LVDSCRT11600x1200_1_V[tempal];
1681 break;
1682 case 7:
1683 return &XGI_LVDSCRT11024x768_1_Vx75[tempal];
1684 break;
1685 case 8:
1686 return &XGI_LVDSCRT11024x768_2_Vx75[tempal];
1687 break;
1688 case 9:
1689 return &XGI_LVDSCRT11280x1024_1_Vx75[tempal];
1690 break;
1691 case 10:
1692 return &XGI_LVDSCRT11280x1024_2_Vx75[tempal];
1693 break;
1694 default:
1695 break;
1696 }
1697 } else if (table == 2) {
1698 switch (tempdi[i].DATAPTR) {
1699 case 0:
1700 return &XGI_LVDS1024x768Data_1[tempal];
1701 break;
1702 case 1:
1703 return &XGI_LVDS1024x768Data_2[tempal];
1704 break;
1705 case 2:
1706 return &XGI_LVDS1280x1024Data_1[tempal];
1707 break;
1708 case 3:
1709 return &XGI_LVDS1280x1024Data_2[tempal];
1710 break;
1711 case 4:
1712 return &XGI_LVDS1400x1050Data_1[tempal];
1713 break;
1714 case 5:
1715 return &XGI_LVDS1400x1050Data_2[tempal];
1716 break;
1717 case 6:
1718 return &XGI_LVDS1600x1200Data_1[tempal];
1719 break;
1720 case 7:
1721 return &XGI_LVDSNoScalingData[tempal];
1722 break;
1723 case 8:
1724 return &XGI_LVDS1024x768Data_1x75[tempal];
1725 break;
1726 case 9:
1727 return &XGI_LVDS1024x768Data_2x75[tempal];
1728 break;
1729 case 10:
1730 return &XGI_LVDS1280x1024Data_1x75[tempal];
1731 break;
1732 case 11:
1733 return &XGI_LVDS1280x1024Data_2x75[tempal];
1734 break;
1735 case 12:
1736 return &XGI_LVDSNoScalingDatax75[tempal];
1737 break;
1738 default:
1739 break;
1740 }
1741 } else if (table == 3) {
1742 switch (tempdi[i].DATAPTR) {
1743 case 0:
1744 return &XGI_LVDS1024x768Des_1[tempal];
1745 break;
1746 case 1:
1747 return &XGI_LVDS1024x768Des_3[tempal];
1748 break;
1749 case 2:
1750 return &XGI_LVDS1024x768Des_2[tempal];
1751 break;
1752 case 3:
1753 return &XGI_LVDS1280x1024Des_1[tempal];
1754 break;
1755 case 4:
1756 return &XGI_LVDS1280x1024Des_2[tempal];
1757 break;
1758 case 5:
1759 return &XGI_LVDS1400x1050Des_1[tempal];
1760 break;
1761 case 6:
1762 return &XGI_LVDS1400x1050Des_2[tempal];
1763 break;
1764 case 7:
1765 return &XGI_LVDS1600x1200Des_1[tempal];
1766 break;
1767 case 8:
1768 return &XGI_LVDSNoScalingDesData[tempal];
1769 break;
1770 case 9:
1771 return &XGI_LVDS1024x768Des_1x75[tempal];
1772 break;
1773 case 10:
1774 return &XGI_LVDS1024x768Des_3x75[tempal];
1775 break;
1776 case 11:
1777 return &XGI_LVDS1024x768Des_2x75[tempal];
1778 break;
1779 case 12:
1780 return &XGI_LVDS1280x1024Des_1x75[tempal];
1781 break;
1782 case 13:
1783 return &XGI_LVDS1280x1024Des_2x75[tempal];
1784 break;
1785 case 14:
1786 return &XGI_LVDSNoScalingDesDatax75[tempal];
1787 break;
1788 default:
1789 break;
1790 }
1791 } else if (table == 4) {
1792 switch (tempdi[i].DATAPTR) {
1793 case 0:
1794 return &XGI_ExtLCD1024x768Data[tempal];
1795 break;
1796 case 1:
1797 return &XGI_StLCD1024x768Data[tempal];
1798 break;
1799 case 2:
1800 return &XGI_CetLCD1024x768Data[tempal];
1801 break;
1802 case 3:
1803 return &XGI_ExtLCD1280x1024Data[tempal];
1804 break;
1805 case 4:
1806 return &XGI_StLCD1280x1024Data[tempal];
1807 break;
1808 case 5:
1809 return &XGI_CetLCD1280x1024Data[tempal];
1810 break;
1811 case 6:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001812 case 7:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001813 return &xgifb_lcd_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001814 break;
1815 case 8:
1816 return &XGI_CetLCD1400x1050Data[tempal];
1817 break;
1818 case 9:
1819 return &XGI_ExtLCD1600x1200Data[tempal];
1820 break;
1821 case 10:
1822 return &XGI_StLCD1600x1200Data[tempal];
1823 break;
1824 case 11:
1825 return &XGI_NoScalingData[tempal];
1826 break;
1827 case 12:
1828 return &XGI_ExtLCD1024x768x75Data[tempal];
1829 break;
1830 case 13:
1831 return &XGI_ExtLCD1024x768x75Data[tempal];
1832 break;
1833 case 14:
1834 return &XGI_CetLCD1024x768x75Data[tempal];
1835 break;
1836 case 15:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001837 case 16:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001838 return &xgifb_lcd_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001839 break;
1840 case 17:
1841 return &XGI_CetLCD1280x1024x75Data[tempal];
1842 break;
1843 case 18:
1844 return &XGI_NoScalingDatax75[tempal];
1845 break;
1846 default:
1847 break;
1848 }
1849 } else if (table == 5) {
1850 switch (tempdi[i].DATAPTR) {
1851 case 0:
1852 return &XGI_ExtLCDDes1024x768Data[tempal];
1853 break;
1854 case 1:
1855 return &XGI_StLCDDes1024x768Data[tempal];
1856 break;
1857 case 2:
1858 return &XGI_CetLCDDes1024x768Data[tempal];
1859 break;
1860 case 3:
Peter Huewe6896b942012-02-09 21:11:46 +01001861 if ((pVBInfo->VBType & VB_SIS301LV) ||
1862 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001863 return &XGI_ExtLCDDLDes1280x1024Data[tempal];
1864 else
1865 return &XGI_ExtLCDDes1280x1024Data[tempal];
1866 break;
1867 case 4:
Peter Huewe6896b942012-02-09 21:11:46 +01001868 if ((pVBInfo->VBType & VB_SIS301LV) ||
1869 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001870 return &XGI_StLCDDLDes1280x1024Data[tempal];
1871 else
1872 return &XGI_StLCDDes1280x1024Data[tempal];
1873 break;
1874 case 5:
Peter Huewe6896b942012-02-09 21:11:46 +01001875 if ((pVBInfo->VBType & VB_SIS301LV) ||
1876 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001877 return &XGI_CetLCDDLDes1280x1024Data[tempal];
1878 else
1879 return &XGI_CetLCDDes1280x1024Data[tempal];
1880 break;
1881 case 6:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001882 case 7:
Peter Huewe6896b942012-02-09 21:11:46 +01001883 if ((pVBInfo->VBType & VB_SIS301LV) ||
1884 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001885 return &xgifb_lcddldes_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001886 else
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001887 return &xgifb_lcddes_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001888 break;
1889 case 8:
1890 return &XGI_CetLCDDes1400x1050Data[tempal];
1891 break;
1892 case 9:
1893 return &XGI_CetLCDDes1400x1050Data2[tempal];
1894 break;
1895 case 10:
Peter Huewe6896b942012-02-09 21:11:46 +01001896 if ((pVBInfo->VBType & VB_SIS301LV) ||
1897 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001898 return &XGI_ExtLCDDLDes1600x1200Data[tempal];
1899 else
1900 return &XGI_ExtLCDDes1600x1200Data[tempal];
1901 break;
1902 case 11:
Peter Huewe6896b942012-02-09 21:11:46 +01001903 if ((pVBInfo->VBType & VB_SIS301LV) ||
1904 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001905 return &XGI_StLCDDLDes1600x1200Data[tempal];
1906 else
1907 return &XGI_StLCDDes1600x1200Data[tempal];
1908 break;
1909 case 12:
1910 return &XGI_NoScalingDesData[tempal];
1911 break;
1912 case 13:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001913 case 14:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001914 return &xgifb_lcddes_1024x768x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001915 break;
1916 case 15:
1917 return &XGI_CetLCDDes1024x768x75Data[tempal];
1918 break;
1919 case 16:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001920 case 17:
Peter Huewe6896b942012-02-09 21:11:46 +01001921 if ((pVBInfo->VBType & VB_SIS301LV) ||
1922 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001923 return &xgifb_lcddldes_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001924 else
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001925 return &xgifb_lcddes_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001926 break;
1927 case 18:
Peter Huewe6896b942012-02-09 21:11:46 +01001928 if ((pVBInfo->VBType & VB_SIS301LV) ||
1929 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001930 return &XGI_CetLCDDLDes1280x1024x75Data[tempal];
1931 else
1932 return &XGI_CetLCDDes1280x1024x75Data[tempal];
1933 break;
1934 case 19:
1935 return &XGI_NoScalingDesDatax75[tempal];
1936 break;
1937 default:
1938 break;
1939 }
1940 } else if (table == 6) {
1941 switch (tempdi[i].DATAPTR) {
1942 case 0:
1943 return &XGI_CH7017LV1024x768[tempal];
1944 break;
1945 case 1:
1946 return &XGI_CH7017LV1400x1050[tempal];
1947 break;
1948 default:
1949 break;
1950 }
1951 }
1952 return NULL;
1953}
1954
1955static void *XGI_GetTVPtr(unsigned short BX, unsigned short ModeNo,
1956 unsigned short ModeIdIndex,
1957 unsigned short RefreshRateTableIndex,
1958 struct vb_device_info *pVBInfo)
1959{
1960 unsigned short i, tempdx, tempbx, tempal, modeflag, table;
1961 struct XGI330_TVDataTablStruct *tempdi = NULL;
1962
1963 tempbx = BX;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001964 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1965 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001966 tempal = tempal & 0x3f;
1967 table = tempbx;
1968
1969 switch (tempbx) {
1970 case 0:
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02001971 tempdi = NULL;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001972 break;
1973 case 1:
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02001974 tempdi = NULL;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001975 break;
1976 case 2:
Aaro Koskinen0c23b6d2011-08-31 21:46:09 +03001977 case 6:
1978 tempdi = xgifb_chrontel_tv;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001979 break;
1980 case 3:
1981 tempdi = NULL;
1982 break;
1983 case 4:
1984 tempdi = XGI_TVDataTable;
1985 break;
1986 case 5:
1987 tempdi = NULL;
1988 break;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001989 default:
1990 break;
1991 }
1992
1993 if (tempdi == NULL) /* OEMUtil */
1994 return NULL;
1995
1996 tempdx = pVBInfo->TVInfo;
1997
1998 if (pVBInfo->VBInfo & SetInSlaveMode)
1999 tempdx = tempdx | SetTVLockMode;
2000
2001 if (modeflag & HalfDCLK)
2002 tempdx = tempdx | SetTVLowResolution;
2003
2004 i = 0;
2005
2006 while (tempdi[i].MASK != 0xffff) {
2007 if ((tempdx & tempdi[i].MASK) == tempdi[i].CAP)
2008 break;
2009 i++;
2010 }
2011
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002012 /* 07/05/22 */
Aaro Koskinenebe33022011-11-27 23:03:18 +02002013 if (table == 0x04) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002014 switch (tempdi[i].DATAPTR) {
2015 case 0:
2016 return &XGI_ExtPALData[tempal];
2017 break;
2018 case 1:
2019 return &XGI_ExtNTSCData[tempal];
2020 break;
2021 case 2:
2022 return &XGI_StPALData[tempal];
2023 break;
2024 case 3:
2025 return &XGI_StNTSCData[tempal];
2026 break;
2027 case 4:
2028 return &XGI_ExtHiTVData[tempal];
2029 break;
2030 case 5:
2031 return &XGI_St2HiTVData[tempal];
2032 break;
2033 case 6:
2034 return &XGI_ExtYPbPr525iData[tempal];
2035 break;
2036 case 7:
2037 return &XGI_ExtYPbPr525pData[tempal];
2038 break;
2039 case 8:
2040 return &XGI_ExtYPbPr750pData[tempal];
2041 break;
2042 case 9:
2043 return &XGI_StYPbPr525iData[tempal];
2044 break;
2045 case 10:
2046 return &XGI_StYPbPr525pData[tempal];
2047 break;
2048 case 11:
2049 return &XGI_StYPbPr750pData[tempal];
2050 break;
2051 case 12: /* avoid system hang */
2052 return &XGI_ExtNTSCData[tempal];
2053 break;
2054 case 13:
2055 return &XGI_St1HiTVData[tempal];
2056 break;
2057 default:
2058 break;
2059 }
2060 } else if (table == 0x02) {
2061 switch (tempdi[i].DATAPTR) {
2062 case 0:
2063 return &XGI_CHTVUNTSCData[tempal];
2064 break;
2065 case 1:
2066 return &XGI_CHTVONTSCData[tempal];
2067 break;
2068 case 2:
2069 return &XGI_CHTVUPALData[tempal];
2070 break;
2071 case 3:
2072 return &XGI_CHTVOPALData[tempal];
2073 break;
2074 default:
2075 break;
2076 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002077 }
2078 return NULL;
2079}
2080
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002081static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302082 unsigned short RefreshRateTableIndex,
2083 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002084{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302085 unsigned short tempbx;
2086 struct XGI330_LVDSDataStruct *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002087
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302088 tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002089
Peter Huewea3d675c2012-02-09 21:11:47 +01002090 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302091 LCDPtr = (struct XGI330_LVDSDataStruct *) XGI_GetLcdPtr(tempbx,
2092 ModeNo, ModeIdIndex, RefreshRateTableIndex,
2093 pVBInfo);
2094 pVBInfo->VGAHT = LCDPtr->VGAHT;
2095 pVBInfo->VGAVT = LCDPtr->VGAVT;
2096 pVBInfo->HT = LCDPtr->LCDHT;
2097 pVBInfo->VT = LCDPtr->LCDVT;
2098 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002099
Peter Huewea3d675c2012-02-09 21:11:47 +01002100 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302101 if (!(pVBInfo->LCDInfo & (SetLCDtoNonExpanding
2102 | EnableScalingLCD))) {
Peter Huewe255aabd2012-02-09 21:11:44 +01002103 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
2104 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302105 pVBInfo->HDE = 1024;
2106 pVBInfo->VDE = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002107 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
2108 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302109 pVBInfo->HDE = 1280;
2110 pVBInfo->VDE = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002111 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302112 pVBInfo->HDE = 1400;
2113 pVBInfo->VDE = 1050;
2114 } else {
2115 pVBInfo->HDE = 1600;
2116 pVBInfo->VDE = 1200;
2117 }
2118 }
2119 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002120}
2121
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002122static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302123 unsigned short RefreshRateTableIndex,
2124 struct xgi_hw_device_info *HwDeviceExtension,
2125 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002126{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302127 unsigned char index;
2128 unsigned short tempbx, i;
2129 struct XGI_LVDSCRT1HDataStruct *LCDPtr = NULL;
2130 struct XGI_LVDSCRT1VDataStruct *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002131
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002132 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302133 index = index & IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002134
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002135 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002136
Peter Huewea3d675c2012-02-09 21:11:47 +01002137 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002138 LCDPtr = (struct XGI_LVDSCRT1HDataStruct *)
2139 XGI_GetLcdPtr(tempbx, ModeNo,
2140 ModeIdIndex,
2141 RefreshRateTableIndex,
2142 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002143
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002144 for (i = 0; i < 8; i++)
2145 pVBInfo->TimingH[0].data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302146 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002147
2148 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
2149
2150 tempbx = 1;
2151
Peter Huewea3d675c2012-02-09 21:11:47 +01002152 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002153 LCDPtr1 = (struct XGI_LVDSCRT1VDataStruct *)
2154 XGI_GetLcdPtr(
2155 tempbx,
2156 ModeNo,
2157 ModeIdIndex,
2158 RefreshRateTableIndex,
2159 pVBInfo);
2160 for (i = 0; i < 7; i++)
2161 pVBInfo->TimingV[0].data[i] = LCDPtr1[0].Reg[i];
2162 }
2163
2164 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002165}
2166
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002167static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
2168{
2169 unsigned char tempal, tempah, tempbl, i;
2170
Aaro Koskinen58839b02011-03-13 12:26:23 +02002171 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002172 tempal = tempah & 0x0F;
2173 tempah = tempah & 0xF0;
2174 i = 0;
2175 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2176
2177 while (tempbl != 0xFF) {
2178 if (tempbl & 0x80) { /* OEMUtil */
2179 tempal = tempah;
2180 tempbl = tempbl & ~(0x80);
2181 }
2182
2183 if (tempal == tempbl)
2184 break;
2185
2186 i++;
2187
2188 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2189 }
2190
2191 return i;
2192}
2193
2194static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
2195{
2196 unsigned short tempah, tempal, tempbl, i;
2197
2198 tempal = pVBInfo->LCDResInfo;
2199 tempah = pVBInfo->LCDTypeInfo;
2200
2201 i = 0;
2202 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2203
2204 while (tempbl != 0xFF) {
2205 if ((tempbl & 0x80) && (tempbl != 0x80)) {
2206 tempal = tempah;
2207 tempbl &= ~0x80;
2208 }
2209
2210 if (tempal == tempbl)
2211 break;
2212
2213 i++;
2214 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2215 }
2216
2217 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01002218 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002219 pVBInfo->LCDTypeInfo = 0;
2220 i = 0;
2221 }
2222
2223 return i;
2224}
2225
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002226static void XGI_GetLCDSync(unsigned short *HSyncWidth,
2227 unsigned short *VSyncWidth,
2228 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002229{
2230 unsigned short Index;
2231
2232 Index = XGI_GetLCDCapPtr(pVBInfo);
2233 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
2234 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
2235
2236 return;
2237}
2238
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002239static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302240 unsigned short RefreshRateTableIndex,
2241 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002242{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302243 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
2244 unsigned long temp, temp1, temp2, temp3, push3;
2245 struct XGI330_LCDDataDesStruct *LCDPtr = NULL;
2246 struct XGI330_LCDDataDesStruct2 *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002247
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002248 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen66cface2011-08-31 21:46:13 +03002249 tempbx = 3;
2250 if (pVBInfo->LCDInfo & EnableScalingLCD)
2251 LCDPtr1 =
2252 (struct XGI330_LCDDataDesStruct2 *)
2253 XGI_GetLcdPtr(
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002254 tempbx,
2255 ModeNo,
2256 ModeIdIndex,
2257 RefreshRateTableIndex,
2258 pVBInfo);
Aaro Koskinen66cface2011-08-31 21:46:13 +03002259 else
2260 LCDPtr =
2261 (struct XGI330_LCDDataDesStruct *)
2262 XGI_GetLcdPtr(
2263 tempbx,
2264 ModeNo,
2265 ModeIdIndex,
2266 RefreshRateTableIndex,
2267 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002268
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002269 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
2270 push1 = tempbx;
2271 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002272
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002273 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01002274 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
2275 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002276 tempax = 1024;
2277 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002278 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
2279 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002280 tempax = 1280;
2281 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002282 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002283 tempax = 1400;
2284 tempbx = 1050;
2285 } else {
2286 tempax = 1600;
2287 tempbx = 1200;
2288 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002289
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002290 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
2291 pVBInfo->HDE = tempax;
2292 pVBInfo->VDE = tempbx;
2293 pVBInfo->VGAHDE = tempax;
2294 pVBInfo->VGAVDE = tempbx;
2295 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002296
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002297 tempax = pVBInfo->HT;
2298
2299 if (pVBInfo->LCDInfo & EnableScalingLCD)
2300 tempbx = LCDPtr1->LCDHDES;
2301 else
2302 tempbx = LCDPtr->LCDHDES;
2303
2304 tempcx = pVBInfo->HDE;
2305 tempbx = tempbx & 0x0fff;
2306 tempcx += tempbx;
2307
2308 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002309 tempcx -= tempax;
2310
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002311 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002312
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002313 tempcx = tempcx >> 3;
2314 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002315
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002316 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
2317 (unsigned short) (tempbx & 0xff));
2318 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
2319 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002320
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002321 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002322
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002323 if (pVBInfo->LCDInfo & EnableScalingLCD)
2324 tempbx = LCDPtr1->LCDHRS;
2325 else
2326 tempbx = LCDPtr->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002327
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002328 tempcx = push2;
2329
2330 if (pVBInfo->LCDInfo & EnableScalingLCD)
2331 tempcx = LCDPtr1->LCDHSync;
2332
2333 tempcx += tempbx;
2334
2335 if (tempcx >= tempax)
2336 tempcx -= tempax;
2337
2338 tempax = tempbx & 0x07;
2339 tempax = tempax >> 5;
2340 tempcx = tempcx >> 3;
2341 tempbx = tempbx >> 3;
2342
2343 tempcx &= 0x1f;
2344 tempax |= tempcx;
2345
2346 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
2347 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
2348 (unsigned short) (tempbx & 0xff));
2349
2350 tempax = pVBInfo->VT;
2351 if (pVBInfo->LCDInfo & EnableScalingLCD)
2352 tempbx = LCDPtr1->LCDVDES;
2353 else
2354 tempbx = LCDPtr->LCDVDES;
2355 tempcx = pVBInfo->VDE;
2356
2357 tempbx = tempbx & 0x0fff;
2358 tempcx += tempbx;
2359 if (tempcx >= tempax)
2360 tempcx -= tempax;
2361
2362 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
2363 (unsigned short) (tempbx & 0xff));
2364 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
2365 (unsigned short) (tempcx & 0xff));
2366
2367 tempbx = (tempbx >> 8) & 0x07;
2368 tempcx = (tempcx >> 8) & 0x07;
2369
2370 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
2371 (unsigned short) ((tempcx << 3)
2372 | tempbx));
2373
2374 tempax = pVBInfo->VT;
2375 if (pVBInfo->LCDInfo & EnableScalingLCD)
2376 tempbx = LCDPtr1->LCDVRS;
2377 else
2378 tempbx = LCDPtr->LCDVRS;
2379
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002380 tempcx = push1;
2381
2382 if (pVBInfo->LCDInfo & EnableScalingLCD)
2383 tempcx = LCDPtr1->LCDVSync;
2384
2385 tempcx += tempbx;
2386 if (tempcx >= tempax)
2387 tempcx -= tempax;
2388
2389 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
2390 (unsigned short) (tempbx & 0xff));
2391 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
2392 (unsigned short) (tempcx & 0x0f));
2393
2394 tempax = ((tempbx >> 8) & 0x07) << 3;
2395
2396 tempbx = pVBInfo->VGAVDE;
2397 if (tempbx != pVBInfo->VDE)
2398 tempax |= 0x40;
2399
Peter Huewea3d675c2012-02-09 21:11:47 +01002400 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002401 tempax |= 0x40;
2402
2403 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
2404 tempax);
2405
2406 tempcx = pVBInfo->VGAVT;
2407 tempbx = pVBInfo->VDE;
2408 tempax = pVBInfo->VGAVDE;
2409 tempcx -= tempax;
2410
2411 temp = tempax; /* 0430 ylshieh */
2412 temp1 = (temp << 18) / tempbx;
2413
2414 tempdx = (unsigned short) ((temp << 18) % tempbx);
2415
2416 if (tempdx != 0)
2417 temp1 += 1;
2418
2419 temp2 = temp1;
2420 push3 = temp2;
2421
2422 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
2423 (unsigned short) (temp2 & 0xff));
2424 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
2425 (unsigned short) ((temp2 >> 8) & 0xff));
2426
2427 tempbx = (unsigned short) (temp2 >> 16);
2428 tempax = tempbx & 0x03;
2429
2430 tempbx = pVBInfo->VGAVDE;
2431 if (tempbx == pVBInfo->VDE)
2432 tempax |= 0x04;
2433
2434 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
2435
2436 if (pVBInfo->VBType & VB_XGI301C) {
2437 temp2 = push3;
2438 xgifb_reg_set(pVBInfo->Part4Port,
2439 0x3c,
2440 (unsigned short) (temp2 & 0xff));
2441 xgifb_reg_set(pVBInfo->Part4Port,
2442 0x3b,
2443 (unsigned short) ((temp2 >> 8) &
2444 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002445 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002446 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
2447 ~0xc0,
2448 (unsigned short) ((tempbx &
2449 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002450
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002451 tempcx = pVBInfo->VGAVDE;
2452 if (tempcx == pVBInfo->VDE)
2453 xgifb_reg_and_or(pVBInfo->Part4Port,
2454 0x30, ~0x0c, 0x00);
2455 else
2456 xgifb_reg_and_or(pVBInfo->Part4Port,
2457 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302458 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002459
2460 tempcx = pVBInfo->VGAHDE;
2461 tempbx = pVBInfo->HDE;
2462
2463 temp1 = tempcx << 16;
2464
2465 tempax = (unsigned short) (temp1 / tempbx);
2466
2467 if ((tempbx & 0xffff) == (tempcx & 0xffff))
2468 tempax = 65535;
2469
2470 temp3 = tempax;
2471 temp1 = pVBInfo->VGAHDE << 16;
2472
2473 temp1 /= temp3;
2474 temp3 = temp3 << 16;
2475 temp1 -= 1;
2476
2477 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
2478
2479 tempax = (unsigned short) (temp3 & 0xff);
2480 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
2481
2482 temp1 = pVBInfo->VGAVDE << 18;
2483 temp1 = temp1 / push3;
2484 tempbx = (unsigned short) (temp1 & 0xffff);
2485
Peter Huewe255aabd2012-02-09 21:11:44 +01002486 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002487 tempbx -= 1;
2488
2489 tempax = ((tempbx >> 8) & 0xff) << 3;
2490 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
2491 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
2492 (unsigned short) (tempax & 0xff));
2493 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
2494 (unsigned short) (tempbx & 0xff));
2495
2496 temp3 = temp3 >> 16;
2497
2498 if (modeflag & HalfDCLK)
2499 temp3 = temp3 >> 1;
2500
2501 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
2502 (unsigned short) ((temp3 >> 8) & 0xff));
2503 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
2504 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002505}
2506
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002507/* --------------------------------------------------------------------- */
2508/* Function : XGI_GETLCDVCLKPtr */
2509/* Input : */
2510/* Output : al -> VCLK Index */
2511/* Description : */
2512/* --------------------------------------------------------------------- */
2513static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
2514 struct vb_device_info *pVBInfo)
2515{
2516 unsigned short index;
2517
Peter Huewea3d675c2012-02-09 21:11:47 +01002518 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002519 index = XGI_GetLCDCapPtr1(pVBInfo);
2520
2521 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
2522 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
2523 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
2524 } else { /* LCDA */
2525 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
2526 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
2527 }
2528 }
2529 return;
2530}
2531
2532static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
2533 unsigned short ModeNo, unsigned short ModeIdIndex,
2534 struct vb_device_info *pVBInfo)
2535{
2536
2537 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002538 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002539
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002540 /* si+Ext_ResInfo */
2541 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002542
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002543 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
2544 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002545 index = XGI_GetLCDCapPtr(pVBInfo);
2546 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
2547
Peter Huewea3d675c2012-02-09 21:11:47 +01002548 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002549 return tempal;
2550
2551 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002552 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01002553 (VB_SIS301B |
2554 VB_SIS302B |
2555 VB_SIS301LV |
2556 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002557 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01002558 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01002559 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002560 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01002561 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002562 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01002563 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002564 if (!(modeflag & Charx8Dot))
Peter Hueweccc8cb22012-02-09 21:11:48 +01002565 tempal = TVCLKBASE_315 + HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002566
2567 }
2568 return tempal;
2569 }
2570
Peter Huewe599801f2012-02-09 21:11:45 +01002571 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01002572 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002573 return tempal;
2574 }
2575
Peter Huewe599801f2012-02-09 21:11:45 +01002576 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002577 tempal = YPbPr525pVCLK;
2578 return tempal;
2579 }
2580
2581 tempal = NTSC1024VCLK;
2582
2583 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01002584 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002585 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01002586 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002587 }
2588
2589 if (pVBInfo->VBInfo & SetCRT2ToTV)
2590 return tempal;
2591 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002592 } /* {End of VB} */
2593
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002594 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002595 tempal = tempal >> 2;
2596 tempal &= 0x03;
2597
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002598 /* for Dot8 Scaling LCD */
2599 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002600 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
2601
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002602 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
2603 return tempal;
2604}
2605
2606static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
2607 unsigned char *di_1, struct vb_device_info *pVBInfo)
2608{
Peter Huewe6896b942012-02-09 21:11:46 +01002609 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
2610 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01002611 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) && (pVBInfo->SetFlag
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002612 & ProgrammingCRT2)) {
2613 *di_0 = (unsigned char) XGI_VBVCLKData[tempal].SR2B;
2614 *di_1 = XGI_VBVCLKData[tempal].SR2C;
2615 }
2616 } else {
2617 *di_0 = XGI_VCLKData[tempal].SR2B;
2618 *di_1 = XGI_VCLKData[tempal].SR2C;
2619 }
2620}
2621
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002622static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302623 unsigned short RefreshRateTableIndex,
2624 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002625{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302626 unsigned char di_0, di_1, tempal;
2627 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002628
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302629 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2630 pVBInfo);
2631 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2632 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002633
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302634 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002635 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302636 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01002637 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302638 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02002639 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
2640 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302641 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02002642 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
2643 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302644 }
2645 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002646}
2647
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002648static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302649 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002650{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302651 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002652
Peter Huewe6896b942012-02-09 21:11:46 +01002653 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
2654 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302655 tempcl = 0;
2656 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002657 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002658
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302659 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002660 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302661 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002662 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302663 if (!(temp & 0x40))
2664 tempcl |= ActiveCRT1;
2665 }
2666 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002667
Aaro Koskinen58839b02011-03-13 12:26:23 +02002668 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302669 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002670
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302671 if (!(temp == 0x08)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002672 /* Check ChannelA by Part1_13 [2003/10/03] */
2673 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302674 if (tempax & 0x04)
2675 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002676
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302677 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002678
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302679 if (!(tempcl & ActiveLCD))
2680 if (temp == 0x01)
2681 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002682
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302683 if (temp == 0x04)
2684 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002685
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302686 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002687 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002688
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302689 if (!(temp & 0x08))
2690 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002691
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302692 if (!(temp & 0x04))
2693 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002694
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302695 if (temp & 0x02)
2696 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002697
Peter Huewe599801f2012-02-09 21:11:45 +01002698 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302699 if (temp & 0x01)
2700 tempch |= ActiveHiTV;
2701 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002702
Peter Huewe599801f2012-02-09 21:11:45 +01002703 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002704 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302705 pVBInfo->Part2Port,
2706 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002707
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302708 if (temp & 0x10)
2709 tempch |= ActiveYPbPr;
2710 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002711
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302712 if (tempch != 0)
2713 tempcl |= ActiveTV;
2714 }
2715 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002716
Aaro Koskinen58839b02011-03-13 12:26:23 +02002717 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302718 if (tempcl & ActiveLCD) {
2719 if ((pVBInfo->SetFlag & ReserveTVOption)) {
2720 if (temp & ActiveTV)
2721 tempcl |= ActiveTV;
2722 }
2723 }
2724 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01002725 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002726 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002727
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302728 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02002729 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302730 } else {
2731 return;
2732 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002733}
2734
Bill Pemberton80adad82010-06-17 13:10:51 -04002735void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002736{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302737 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002738
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302739 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe6896b942012-02-09 21:11:46 +01002740 tempbx = VB_SIS302B;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002741 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302742 if (flag != 0x02) {
Peter Huewe6896b942012-02-09 21:11:46 +01002743 tempbx = VB_SIS301;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002744 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302745 if (flag >= 0xB0) {
Peter Huewe6896b942012-02-09 21:11:46 +01002746 tempbx = VB_SIS301B;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302747 if (flag >= 0xC0) {
2748 tempbx = VB_XGI301C;
2749 if (flag >= 0xD0) {
Peter Huewe6896b942012-02-09 21:11:46 +01002750 tempbx = VB_SIS301LV;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302751 if (flag >= 0xE0) {
Peter Huewe6896b942012-02-09 21:11:46 +01002752 tempbx = VB_SIS302LV;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002753 tempah = xgifb_reg_get(
2754 pVBInfo->Part4Port,
2755 0x39);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302756 if (tempah != 0xFF)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002757 tempbx =
2758 VB_XGI301C;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302759 }
2760 }
2761 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002762
Peter Huewe6896b942012-02-09 21:11:46 +01002763 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002764 flag = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302765 pVBInfo->Part4Port,
2766 0x23);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002767
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302768 if (!(flag & 0x02))
2769 tempbx = tempbx | VB_NoLCD;
2770 }
2771 }
2772 }
2773 pVBInfo->VBType = tempbx;
2774 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002775}
2776
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002777static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302778 struct xgi_hw_device_info *HwDeviceExtension,
2779 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002780{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302781 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002782
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002783 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302784 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01002785 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302786 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002787
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302788 if (pVBInfo->VBType & 0xFFFF) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002789 /* Check Display Device */
2790 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302791 tempbx = tempbx | temp;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002792 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302793 push = temp;
2794 push = push << 8;
2795 tempax = temp << 8;
2796 tempbx = tempbx | tempax;
Peter Huewea3d675c2012-02-09 21:11:47 +01002797 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302798 | SetInSlaveMode | DisableCRT2Display);
2799 temp = 0xFFFF ^ temp;
2800 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002801
Aaro Koskinen58839b02011-03-13 12:26:23 +02002802 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002803
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302804 if (pVBInfo->IF_DEF_LCDA == 1) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002805
Aaro Koskinen9ffc7e92011-11-27 23:03:14 +02002806 if ((HwDeviceExtension->jChipType >= XG20) ||
2807 (HwDeviceExtension->jChipType >= XG40)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302808 if (pVBInfo->IF_DEF_LVDS == 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002809 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01002810 (VB_SIS302B |
2811 VB_SIS301LV |
2812 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002813 VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302814 if (temp & EnableDualEdge) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002815 tempbx |=
2816 SetCRT2ToDualEdge;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002817
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302818 if (temp & SetToLCDA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002819 tempbx |=
Peter Huewea3d675c2012-02-09 21:11:47 +01002820 XGI_SetCRT2ToLCDA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302821 }
2822 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302823 }
2824 }
2825 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002826
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302827 if (pVBInfo->IF_DEF_YPbPr == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002828 /* [Billy] 07/05/04 */
2829 if (((pVBInfo->IF_DEF_LVDS == 0) &&
Peter Huewe6896b942012-02-09 21:11:46 +01002830 ((pVBInfo->VBType & VB_SIS301LV) ||
2831 (pVBInfo->VBType & VB_SIS302LV) ||
Aaro Koskinen83f76a92011-08-31 21:45:58 +03002832 (pVBInfo->VBType & VB_XGI301C)))) {
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02002833 if (temp & SetYPbPr) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302834 if (pVBInfo->IF_DEF_HiVision == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002835 /* shampoo add for new
2836 * scratch */
Aaro Koskinen58839b02011-03-13 12:26:23 +02002837 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302838 pVBInfo->P3d4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002839 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302840 temp &= YPbPrMode;
Peter Huewe599801f2012-02-09 21:11:45 +01002841 tempbx |= SetCRT2ToHiVision;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002842
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302843 if (temp != YPbPrMode1080i) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002844 tempbx &=
Peter Huewe599801f2012-02-09 21:11:45 +01002845 (~SetCRT2ToHiVision);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002846 tempbx |=
Peter Huewe599801f2012-02-09 21:11:45 +01002847 SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302848 }
2849 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302850 }
2851 }
2852 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002853
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302854 tempax = push; /* restore CR31 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002855
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302856 if (pVBInfo->IF_DEF_LVDS == 0) {
2857 if (pVBInfo->IF_DEF_YPbPr == 1) {
2858 if (pVBInfo->IF_DEF_HiVision == 1)
2859 temp = 0x09FC;
2860 else
2861 temp = 0x097C;
2862 } else {
2863 if (pVBInfo->IF_DEF_HiVision == 1)
2864 temp = 0x01FC;
2865 else
2866 temp = 0x017C;
2867 }
2868 } else { /* 3nd party chip */
Aaro Koskinen83f76a92011-08-31 21:45:58 +03002869 temp = SetCRT2ToLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302870 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002871
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302872 if (!(tempbx & temp)) {
2873 tempax |= DisableCRT2Display;
2874 tempbx = 0;
2875 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002876
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302877 if (pVBInfo->IF_DEF_LCDA == 1) { /* Select Display Device */
2878 if (!(pVBInfo->VBType & VB_NoLCD)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01002879 if (tempbx & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302880 if (tempbx & SetSimuScanMode)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002881 tempbx &= (~(SetCRT2ToLCD |
2882 SetCRT2ToRAMDAC |
Peter Huewe6896b942012-02-09 21:11:46 +01002883 SwitchCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302884 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002885 tempbx &= (~(SetCRT2ToLCD |
2886 SetCRT2ToRAMDAC |
2887 SetCRT2ToTV |
Peter Huewe6896b942012-02-09 21:11:46 +01002888 SwitchCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302889 }
2890 }
2891 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002892
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302893 /* shampoo add */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002894 /* for driver abnormal */
Peter Huewe6896b942012-02-09 21:11:46 +01002895 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302896 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2897 if (tempbx & SetCRT2ToRAMDAC) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002898 tempbx &= (0xFF00 |
2899 SetCRT2ToRAMDAC |
Peter Huewe6896b942012-02-09 21:11:46 +01002900 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002901 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002902 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302903 }
2904 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002905 tempbx &= (~(SetCRT2ToRAMDAC |
2906 SetCRT2ToLCD |
2907 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302908 }
2909 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002910
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302911 if (!(pVBInfo->VBType & VB_NoLCD)) {
2912 if (tempbx & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002913 tempbx &= (0xFF00 |
2914 SetCRT2ToLCD |
Peter Huewe6896b942012-02-09 21:11:46 +01002915 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002916 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002917 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302918 }
2919 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002920
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302921 if (tempbx & SetCRT2ToSCART) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002922 tempbx &= (0xFF00 |
2923 SetCRT2ToSCART |
Peter Huewe6896b942012-02-09 21:11:46 +01002924 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002925 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002926 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302927 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002928
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302929 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002930 if (tempbx & SetCRT2ToYPbPr525750)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002931 tempbx &= (0xFF00 |
Peter Huewe6896b942012-02-09 21:11:46 +01002932 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002933 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302934 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002935
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302936 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002937 if (tempbx & SetCRT2ToHiVision)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002938 tempbx &= (0xFF00 |
Peter Huewe599801f2012-02-09 21:11:45 +01002939 SetCRT2ToHiVision |
Peter Huewe6896b942012-02-09 21:11:46 +01002940 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002941 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302942 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002943
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302944 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
Peter Huewe6896b942012-02-09 21:11:46 +01002945 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302946 tempbx = DisableCRT2Display;
2947 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002948
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302949 if (!(tempbx & DisableCRT2Display)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002950 if ((!(tempbx & DriverMode)) ||
2951 (!(modeflag & CRT2Mode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302952 if (pVBInfo->IF_DEF_LCDA == 1) {
Peter Huewea3d675c2012-02-09 21:11:47 +01002953 if (!(tempbx & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002954 tempbx |= (SetInSlaveMode |
2955 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302956 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302957 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002958
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002959 /* LCD+TV can't support in slave mode
2960 * (Force LCDA+TV->LCDB) */
2961 if ((tempbx & SetInSlaveMode) &&
Peter Huewea3d675c2012-02-09 21:11:47 +01002962 (tempbx & XGI_SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002963 tempbx ^= (SetCRT2ToLCD |
Peter Huewea3d675c2012-02-09 21:11:47 +01002964 XGI_SetCRT2ToLCDA |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002965 SetCRT2ToDualEdge);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302966 pVBInfo->SetFlag |= ReserveTVOption;
2967 }
2968 }
2969 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002970
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302971 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002972}
2973
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002974static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302975 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002976{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302977 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002978
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302979 tempbx = 0;
2980 resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002981
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302982 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002983 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2984 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002985
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302986 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002987 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302988 tempbx = temp;
Peter Huewe599801f2012-02-09 21:11:45 +01002989 if (tempbx & TVSetPAL) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002990 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01002991 TVSetPALM |
2992 TVSetPALN |
2993 TVSetPAL);
2994 if (tempbx & TVSetPALM)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002995 /* set to NTSC if PAL-M */
Peter Huewe599801f2012-02-09 21:11:45 +01002996 tempbx &= ~TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302997 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002998 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01002999 TVSetNTSCJ |
3000 TVSetPAL);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303001 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003002
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303003 if (pVBInfo->IF_DEF_LVDS == 0) {
3004 if (pVBInfo->VBInfo & SetCRT2ToSCART)
Peter Huewe599801f2012-02-09 21:11:45 +01003005 tempbx |= TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303006 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003007
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303008 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01003009 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003010 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303011 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003012
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303013 if (index1 == YPbPrMode525i)
Peter Huewe599801f2012-02-09 21:11:45 +01003014 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003015
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303016 if (index1 == YPbPrMode525p)
Peter Huewe599801f2012-02-09 21:11:45 +01003017 tempbx = tempbx | TVSetYPbPr525p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303018 if (index1 == YPbPrMode750p)
Peter Huewe599801f2012-02-09 21:11:45 +01003019 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303020 }
3021 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003022
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303023 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01003024 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
3025 tempbx = tempbx | TVSetHiVision | TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303026 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003027
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303028 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003029 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
3030 (!(pVBInfo->VBInfo & SetNotSimuMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303031 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003032
Peter Huewe599801f2012-02-09 21:11:45 +01003033 if (!(tempbx & TVSetPAL) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003034 (modeflag > 13) &&
3035 (resinfo == 8)) /* NTSC 1024x768, */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303036 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003037
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303038 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003039
Peter Huewe599801f2012-02-09 21:11:45 +01003040 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303041 if (pVBInfo->VBInfo & SetInSlaveMode)
3042 tempbx &= (~RPLLDIV2XO);
3043 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003044 if (tempbx &
Peter Huewe599801f2012-02-09 21:11:45 +01003045 (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303046 tempbx &= (~RPLLDIV2XO);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003047 else if (!(pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003048 (VB_SIS301B |
3049 VB_SIS302B |
3050 VB_SIS301LV |
3051 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003052 VB_XGI301C))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303053 if (tempbx & TVSimuMode)
3054 tempbx &= (~RPLLDIV2XO);
3055 }
3056 }
3057 }
3058 }
3059 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003060}
3061
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02003062static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
3063 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003064{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303065 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003066
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303067 pVBInfo->LCDResInfo = 0;
3068 pVBInfo->LCDTypeInfo = 0;
3069 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003070
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003071 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3072 /* si+Ext_ResInfo // */
3073 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02003074 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303075 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003076
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303077 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01003078 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003079
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303080 /* LCD75 [2003/8/22] Vicent */
Peter Huewe255aabd2012-02-09 21:11:44 +01003081 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303082 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003083 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01003084 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303085 tempax &= 0x0F;
3086 else
3087 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003088
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303089 if ((resinfo == 6) || (resinfo == 9)) {
3090 if (tempax >= 3)
3091 tempbx |= PanelRef75Hz;
3092 } else if ((resinfo == 7) || (resinfo == 8)) {
3093 if (tempax >= 4)
3094 tempbx |= PanelRef75Hz;
3095 }
3096 }
3097 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003098
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303099 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303101 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003102
Peter Huewea3d675c2012-02-09 21:11:47 +01003103 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303104 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303106 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003107
Aaro Koskinen58839b02011-03-13 12:26:23 +02003108 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003109
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303110 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003111
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303112 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303114 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003115
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303116 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003117
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303118 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Peter Huewe6896b942012-02-09 21:11:46 +01003119 if (((pVBInfo->VBType & VB_SIS302LV) || (pVBInfo->VBType
Peter Huewea3d675c2012-02-09 21:11:47 +01003120 & VB_XGI301C)) && (tempax & XGI_LCDDualLink)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303121 tempbx |= SetLCDDualLink;
3122 }
3123 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003124
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303125 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003126 if ((pVBInfo->LCDResInfo == Panel_1400x1050) && (pVBInfo->VBInfo
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003127 & SetCRT2ToLCD) && (resinfo == 9) &&
3128 (!(tempbx & EnableScalingLCD)))
Peter Huewe255aabd2012-02-09 21:11:44 +01003129 /* set to center in 1280x1024 LCDB for Panel_1400x1050 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003130 tempbx |= SetLCDtoNonExpanding;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303131 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003132
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303133 if (pVBInfo->IF_DEF_ExpLink == 1) {
3134 if (modeflag & HalfDCLK) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303135 if (!(tempbx & SetLCDtoNonExpanding)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003136 tempbx |= XGI_EnableLVDSDDA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303137 } else {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003138 if (pVBInfo->LCDResInfo == Panel_1024x768) {
3139 if (resinfo == 4) {/* 512x384 */
3140 tempbx |= XGI_EnableLVDSDDA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303141 }
3142 }
3143 }
3144 }
3145 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003146
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303147 if (pVBInfo->VBInfo & SetInSlaveMode) {
3148 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01003149 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303150 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01003151 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303152 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003153
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303154 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003155
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303156 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003157}
3158
Bill Pemberton108afbf2010-06-17 13:10:47 -04003159unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303160 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003161{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003162 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
3163 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
3164 break;
3165 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
3166 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303167 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003168
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303169 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003170}
3171
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003172static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
3173{
3174 unsigned char ujRet = 0;
3175 unsigned char i = 0;
3176
3177 for (i = 0; i < 8; i++) {
3178 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003179 ujRet |= (ujDate >> i) & 1;
3180 }
3181
3182 return ujRet;
3183}
3184
3185/*----------------------------------------------------------------------------*/
3186/* output */
3187/* bl[5] : LVDS signal */
3188/* bl[1] : LVDS backlight */
3189/* bl[0] : LVDS VDD */
3190/*----------------------------------------------------------------------------*/
3191static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
3192{
3193 unsigned char CR4A, temp;
3194
Aaro Koskinen58839b02011-03-13 12:26:23 +02003195 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02003196 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003197
Aaro Koskinen58839b02011-03-13 12:26:23 +02003198 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003199
3200 temp = XG21GPIODataTransfer(temp);
3201 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003202 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003203 return temp;
3204}
3205
3206/*----------------------------------------------------------------------------*/
3207/* output */
3208/* bl[5] : LVDS signal */
3209/* bl[1] : LVDS backlight */
3210/* bl[0] : LVDS VDD */
3211/*----------------------------------------------------------------------------*/
3212static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
3213{
3214 unsigned char CR4A, CRB4, temp;
3215
Aaro Koskinen58839b02011-03-13 12:26:23 +02003216 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02003217 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003218
Aaro Koskinen58839b02011-03-13 12:26:23 +02003219 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003220
3221 temp &= 0x0C;
3222 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003223 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003224 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003225 temp |= ((CRB4 & 0x04) << 3);
3226 return temp;
3227}
3228
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02003229/*----------------------------------------------------------------------------*/
3230/* input */
3231/* bl[5] : 1;LVDS signal on */
3232/* bl[1] : 1;LVDS backlight on */
3233/* bl[0] : 1:LVDS VDD on */
3234/* bh: 100000b : clear bit 5, to set bit5 */
3235/* 000010b : clear bit 1, to set bit1 */
3236/* 000001b : clear bit 0, to set bit0 */
3237/*----------------------------------------------------------------------------*/
3238static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
3239 struct vb_device_info *pVBInfo)
3240{
3241 unsigned char CR4A, temp;
3242
3243 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3244 tempbh &= 0x23;
3245 tempbl &= 0x23;
3246 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
3247
3248 if (tempbh & 0x20) {
3249 temp = (tempbl >> 4) & 0x02;
3250
3251 /* CR B4[1] */
3252 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
3253
3254 }
3255
3256 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3257
3258 temp = XG21GPIODataTransfer(temp);
3259 temp &= ~tempbh;
3260 temp |= tempbl;
3261 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
3262}
3263
Aaro Koskinen776115a2011-11-27 23:03:10 +02003264static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
3265 struct vb_device_info *pVBInfo)
3266{
3267 unsigned char CR4A, temp;
3268 unsigned short tempbh0, tempbl0;
3269
3270 tempbh0 = tempbh;
3271 tempbl0 = tempbl;
3272 tempbh0 &= 0x20;
3273 tempbl0 &= 0x20;
3274 tempbh0 >>= 3;
3275 tempbl0 >>= 3;
3276
3277 if (tempbh & 0x20) {
3278 temp = (tempbl >> 4) & 0x02;
3279
3280 /* CR B4[1] */
3281 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
3282
3283 }
3284 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
3285
3286 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3287 tempbh &= 0x03;
3288 tempbl &= 0x03;
3289 tempbh <<= 2;
3290 tempbl <<= 2; /* GPIOC,GPIOD */
3291 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
3292 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
3293}
3294
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003295/* --------------------------------------------------------------------- */
3296/* Function : XGI_XG21SetPanelDelay */
3297/* Input : */
3298/* Output : */
3299/* Description : */
3300/* I/P : bl : 1 ; T1 : the duration between CPL on and signal on */
3301/* : bl : 2 ; T2 : the duration signal on and Vdd on */
3302/* : bl : 3 ; T3 : the duration between CPL off and signal off */
3303/* : bl : 4 ; T4 : the duration signal off and Vdd off */
3304/* --------------------------------------------------------------------- */
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003305static void XGI_XG21SetPanelDelay(struct xgifb_video_info *xgifb_info,
3306 unsigned short tempbl,
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003307 struct vb_device_info *pVBInfo)
3308{
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003309 if (tempbl == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003310 mdelay(xgifb_info->lvds_data.PSC_S1);
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003311
3312 if (tempbl == 2)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003313 mdelay(xgifb_info->lvds_data.PSC_S2);
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003314
3315 if (tempbl == 3)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003316 mdelay(xgifb_info->lvds_data.PSC_S3);
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003317
3318 if (tempbl == 4)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003319 mdelay(xgifb_info->lvds_data.PSC_S4);
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003320}
3321
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003322static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
3323 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303324 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003325{
3326
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003327 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303328 if (pXGIHWDE->jChipType == XG21) {
3329 if (pVBInfo->IF_DEF_LVDS == 1) {
3330 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003331 /* LVDS VDD on */
3332 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003333 XGI_XG21SetPanelDelay(xgifb_info, 2, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303334 }
3335 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003336 /* LVDS signal on */
3337 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003338 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003339 /* LVDS backlight on */
3340 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303341 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003342 /* DVO/DVI signal on */
3343 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303344 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003345
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303346 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003347
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303348 if (pXGIHWDE->jChipType == XG27) {
3349 if (pVBInfo->IF_DEF_LVDS == 1) {
3350 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003351 /* LVDS VDD on */
3352 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003353 XGI_XG21SetPanelDelay(xgifb_info, 2, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303354 }
3355 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003356 /* LVDS signal on */
3357 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003358 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003359 /* LVDS backlight on */
3360 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303361 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003362 /* DVO/DVI signal on */
3363 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303364 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003365
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303366 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003367}
3368
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003369void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
3370 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303371 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003372{
3373
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303374 if (pXGIHWDE->jChipType == XG21) {
3375 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003376 /* LVDS backlight off */
3377 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003378 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303379 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003380 /* DVO/DVI signal off */
3381 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303382 }
3383 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003384
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303385 if (pXGIHWDE->jChipType == XG27) {
3386 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003387 /* LVDS backlight off */
3388 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003389 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
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->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003393 /* DVO/DVI signal off */
3394 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303395 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003396
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003397 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003398}
3399
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003400static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003401{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003402 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303403 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003404
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003405 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303406 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003407}
3408
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003409static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003410{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03003411 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003412}
3413
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003414static void XGI_SaveCRT2Info(unsigned short ModeNo,
3415 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003416{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303417 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003418
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003419 /* reserve CR34 for CRT1 Mode No */
3420 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303421 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
3422 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003423 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003424}
3425
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003426static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
3427 unsigned short ModeIdIndex,
3428 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003429{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303430 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003431
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303432 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003433 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
3434 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
3435 /* si+St_ModeFlag */
3436 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003437
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003438 if (modeflag & HalfDCLK)
3439 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003440
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003441 if (modeflag & DoubleScanMode)
3442 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003443
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303444 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
3445 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003446 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003447 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303448 if (yres == 1024)
3449 yres = 1056;
3450 }
3451 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003452
Peter Huewe255aabd2012-02-09 21:11:44 +01003453 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303454 if (yres == 400)
3455 yres = 405;
3456 else if (yres == 350)
3457 yres = 360;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003458
Peter Huewea3d675c2012-02-09 21:11:47 +01003459 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303460 if (yres == 360)
3461 yres = 375;
3462 }
3463 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003464
Peter Huewe255aabd2012-02-09 21:11:44 +01003465 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003466 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303467 if (!(pVBInfo->LCDInfo
3468 & LCDNonExpanding)) {
3469 if (yres == 350)
3470 yres = 357;
3471 else if (yres == 400)
3472 yres = 420;
3473 else if (yres == 480)
3474 yres = 525;
3475 }
3476 }
3477 }
3478 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003479
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303480 if (xres == 720)
3481 xres = 640;
3482 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003483
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303484 pVBInfo->VGAHDE = xres;
3485 pVBInfo->HDE = xres;
3486 pVBInfo->VGAVDE = yres;
3487 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003488}
3489
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003490static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003491{
3492
Peter Huewea3d675c2012-02-09 21:11:47 +01003493 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03003494 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303495 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003496
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303497 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003498}
3499
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003500static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
3501 unsigned short ModeIdIndex,
3502 unsigned short RefreshRateTableIndex,
3503 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003504{
3505 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003506 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003507
3508 pVBInfo->RVBHCMAX = 1;
3509 pVBInfo->RVBHCFACT = 1;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003510 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3511 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3512 CRT1Index &= IndexMask;
3513 temp1 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[0];
3514 temp2 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
3515 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
3516 tempbx = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[8];
3517 tempcx = (unsigned short)
3518 pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14] << 8;
3519 tempcx &= 0x0100;
3520 tempcx = tempcx << 2;
3521 tempbx |= tempcx;
3522 temp1 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003523
3524 if (temp1 & 0x01)
3525 tempbx |= 0x0100;
3526
3527 if (temp1 & 0x20)
3528 tempbx |= 0x0200;
3529 tempax += 5;
3530
3531 if (modeflag & Charx8Dot)
3532 tempax *= 8;
3533 else
3534 tempax *= 9;
3535
3536 pVBInfo->VGAHT = tempax;
3537 pVBInfo->HT = tempax;
3538 tempbx++;
3539 pVBInfo->VGAVT = tempbx;
3540 pVBInfo->VT = tempbx;
3541}
3542
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003543static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303544 unsigned short RefreshRateTableIndex,
3545 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003546{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303547 unsigned short tempax = 0, tempbx, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003548
Peter Huewefc39dcb2012-01-15 19:22:12 +01003549 struct SiS_LCDData *LCDPtr = NULL;
3550 struct SiS_TVData *TVPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003551
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003552 /* si+Ext_ResInfo */
3553 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3554 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303555 pVBInfo->NewFlickerMode = 0;
3556 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003557
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303558 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3559 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3560 pVBInfo);
3561 return;
3562 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003563
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303564 tempbx = 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003565
Peter Huewea3d675c2012-02-09 21:11:47 +01003566 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewefc39dcb2012-01-15 19:22:12 +01003567 LCDPtr = (struct SiS_LCDData *) XGI_GetLcdPtr(tempbx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303568 ModeNo, ModeIdIndex, RefreshRateTableIndex,
3569 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003570
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303571 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
3572 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
3573 pVBInfo->VGAHT = LCDPtr->VGAHT;
3574 pVBInfo->VGAVT = LCDPtr->VGAVT;
3575 pVBInfo->HT = LCDPtr->LCDHT;
3576 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003577
Peter Huewe255aabd2012-02-09 21:11:44 +01003578 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303579 tempax = 1024;
3580 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003581
Peter Huewea3d675c2012-02-09 21:11:47 +01003582 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303583 if (pVBInfo->VGAVDE == 357)
3584 tempbx = 527;
3585 else if (pVBInfo->VGAVDE == 420)
3586 tempbx = 620;
3587 else if (pVBInfo->VGAVDE == 525)
3588 tempbx = 775;
3589 else if (pVBInfo->VGAVDE == 600)
3590 tempbx = 775;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303591 else
3592 tempbx = 768;
3593 } else
3594 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003595 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303596 tempax = 1024;
3597 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003598 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303599 tempax = 1280;
3600 if (pVBInfo->VGAVDE == 360)
3601 tempbx = 768;
3602 else if (pVBInfo->VGAVDE == 375)
3603 tempbx = 800;
3604 else if (pVBInfo->VGAVDE == 405)
3605 tempbx = 864;
3606 else
3607 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003608 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303609 tempax = 1280;
3610 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003611 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303612 tempax = 1280;
3613 if (pVBInfo->VGAVDE == 350)
3614 tempbx = 700;
3615 else if (pVBInfo->VGAVDE == 400)
3616 tempbx = 800;
3617 else if (pVBInfo->VGAVDE == 1024)
3618 tempbx = 960;
3619 else
3620 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01003621 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303622 tempax = 1400;
3623 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003624
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303625 if (pVBInfo->VGAVDE == 1024) {
3626 tempax = 1280;
3627 tempbx = 1024;
3628 }
Peter Huewe255aabd2012-02-09 21:11:44 +01003629 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303630 tempax = 1600;
3631 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01003632 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303633 if (pVBInfo->VGAVDE == 350)
3634 tempbx = 875;
3635 else if (pVBInfo->VGAVDE == 400)
3636 tempbx = 1000;
3637 }
3638 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003639
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303640 if (pVBInfo->LCDInfo & LCDNonExpanding) {
3641 tempax = pVBInfo->VGAHDE;
3642 tempbx = pVBInfo->VGAVDE;
3643 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003644
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303645 pVBInfo->HDE = tempax;
3646 pVBInfo->VDE = tempbx;
3647 return;
3648 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003649
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303650 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
3651 tempbx = 4;
Peter Huewefc39dcb2012-01-15 19:22:12 +01003652 TVPtr = (struct SiS_TVData *) XGI_GetTVPtr(tempbx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303653 ModeNo, ModeIdIndex, RefreshRateTableIndex,
3654 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003655
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303656 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
3657 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
3658 pVBInfo->VGAHT = TVPtr->VGAHT;
3659 pVBInfo->VGAVT = TVPtr->VGAVT;
3660 pVBInfo->HDE = TVPtr->TVHDE;
3661 pVBInfo->VDE = TVPtr->TVVDE;
3662 pVBInfo->RVBHRS = TVPtr->RVBHRS;
3663 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003664
Peter Huewe599801f2012-02-09 21:11:45 +01003665 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303666 if (resinfo == 0x08)
3667 pVBInfo->NewFlickerMode = 0x40;
3668 else if (resinfo == 0x09)
3669 pVBInfo->NewFlickerMode = 0x40;
3670 else if (resinfo == 0x12)
3671 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003672
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303673 if (pVBInfo->VGAVDE == 350)
3674 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003675
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303676 tempax = ExtHiTVHT;
3677 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003678
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303679 if (pVBInfo->VBInfo & SetInSlaveMode) {
3680 if (pVBInfo->TVInfo & TVSimuMode) {
3681 tempax = StHiTVHT;
3682 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003683
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303684 if (!(modeflag & Charx8Dot)) {
3685 tempax = StHiTextTVHT;
3686 tempbx = StHiTextTVVT;
3687 }
3688 }
3689 }
Peter Huewe599801f2012-02-09 21:11:45 +01003690 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3691 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303692 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
3693 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
3694 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003695
Peter Huewe599801f2012-02-09 21:11:45 +01003696 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303697 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
3698 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01003699 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303700 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
3701 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
3702 if (pVBInfo->TVInfo & NTSC1024x768)
3703 tempax = NTSC1024x768HT;
3704 }
3705 } else {
3706 tempax = PALHT;
3707 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01003708 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303709 tempax = NTSCHT;
3710 tempbx = NTSCVT;
3711 if (pVBInfo->TVInfo & NTSC1024x768)
3712 tempax = NTSC1024x768HT;
3713 }
3714 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003715
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303716 pVBInfo->HT = tempax;
3717 pVBInfo->VT = tempbx;
3718 return;
3719 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003720}
3721
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003722static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303723 unsigned short RefreshRateTableIndex,
3724 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003725{
Bill Pemberton108afbf2010-06-17 13:10:47 -04003726 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003727
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303728 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
3729 pVBInfo);
3730 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
3731 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003732
Peter Huewe6896b942012-02-09 21:11:46 +01003733 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303734 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003735 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
3736 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
3737 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303738 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003739 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
3740 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303741 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003742
Aaro Koskinen8104e322011-03-13 12:26:22 +02003743 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003744
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303745 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02003746 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303747 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02003748 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003749}
3750
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003751static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
3752 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003753{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003754 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
3755 short index;
3756 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303757
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003758 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01003759 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303760
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003761 if (index < 0)
3762 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303763
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003764 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303765}
3766
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003767static unsigned short XGI_GetOffset(unsigned short ModeNo,
3768 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303769 unsigned short RefreshRateTableIndex,
3770 struct xgi_hw_device_info *HwDeviceExtension,
3771 struct vb_device_info *pVBInfo)
3772{
3773 unsigned short temp, colordepth, modeinfo, index, infoflag,
3774 ColorDepth[] = { 0x01, 0x02, 0x04 };
3775
3776 modeinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003777 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303778
3779 index = (modeinfo >> 8) & 0xFF;
3780
3781 temp = pVBInfo->ScreenOffset[index];
3782
3783 if (infoflag & InterlaceMode)
3784 temp = temp << 1;
3785
3786 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
3787
3788 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
3789 temp = ModeNo - 0x7C;
3790 colordepth = ColorDepth[temp];
3791 temp = 0x6B;
3792 if (infoflag & InterlaceMode)
3793 temp = temp << 1;
3794 return temp * colordepth;
3795 } else {
3796 return temp * colordepth;
3797 }
3798}
3799
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003800static void XGI_SetCRT2Offset(unsigned short ModeNo,
3801 unsigned short ModeIdIndex,
3802 unsigned short RefreshRateTableIndex,
3803 struct xgi_hw_device_info *HwDeviceExtension,
3804 struct vb_device_info *pVBInfo)
3805{
3806 unsigned short offset;
3807 unsigned char temp;
3808
3809 if (pVBInfo->VBInfo & SetInSlaveMode)
3810 return;
3811
3812 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3813 HwDeviceExtension, pVBInfo);
3814 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003815 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003816 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003817 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003818 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003819 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003820}
3821
Randy Dunlap89229672010-08-10 08:46:44 -07003822static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003823{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003824 /* threshold high ,disable auto threshold */
3825 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
3826 /* threshold low default 04h */
3827 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003828}
3829
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003830static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303831 struct xgi_hw_device_info *HwDeviceExtension,
3832 unsigned short RefreshRateTableIndex,
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 tempcx = 0, CRT1Index = 0, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003836
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003837 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3838 CRT1Index &= IndexMask;
3839 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003840
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303841 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3842 HwDeviceExtension, pVBInfo);
3843 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003844
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303845 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003846 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003847
Aaro Koskinen8104e322011-03-13 12:26:22 +02003848 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
3849 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003850}
3851
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003852static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303853 struct xgi_hw_device_info *HwDeviceExtension,
3854 unsigned short RefreshRateTableIndex,
3855 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003856{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303857 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
3858 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003859
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003860 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3861 CRT1Index &= IndexMask;
3862 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3863 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003864
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303865 /* bainy change table name */
3866 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003867 /* BTVGA2HT 0x08,0x09 */
3868 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003869 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303870 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003871 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003872 /* BTVGA2HDEE 0x0A,0x0C */
3873 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003874 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303875 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
3876 pushbx = pVBInfo->VGAHDE / 2 + 16;
3877 tempcx = tempcx >> 1;
3878 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3879 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003880
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303881 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3882 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003883 tempbx |= ((pVBInfo->
3884 XGINEWUB_CRT1Table[CRT1Index].CR[14] &
3885 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303886 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
3887 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
3888 tempcx &= 0x1F;
3889 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[15];
3890 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3891 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3892 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003893
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303894 tempbx += 4;
3895 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003896
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303897 if (tempcx > (pVBInfo->VGAHT / 2))
3898 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003899
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303900 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003901
Aaro Koskinen8104e322011-03-13 12:26:22 +02003902 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303903 } else {
3904 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003905 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303906 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003907 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003908 /* BTVGA2HDEE 0x0A,0x0C */
3909 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003910 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303911 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
3912 pushbx = pVBInfo->VGAHDE + 16;
3913 tempcx = tempcx >> 1;
3914 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3915 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003916
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303917 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3918 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[3];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003919 tempbx |= ((pVBInfo->
3920 XGINEWUB_CRT1Table[CRT1Index].CR[5] &
3921 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303922 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
3923 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
3924 tempcx &= 0x1F;
3925 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[6];
3926 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3927 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3928 tempbx += 16;
3929 tempcx += 16;
3930 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003931
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303932 if (tempcx > pVBInfo->VGAHT)
3933 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003934
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303935 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003936 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303937 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003938
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303939 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
3940 tempbx = pushbx;
3941 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
3942 tempax |= (tempbx & 0xFF00);
3943 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003944 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303945 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003946 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303947 tempcx = (pVBInfo->VGAVT - 1);
3948 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003949
Aaro Koskinen8104e322011-03-13 12:26:22 +02003950 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303951 tempbx = pVBInfo->VGAVDE - 1;
3952 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003953 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303954 temp = ((tempbx & 0xFF00) << 3) >> 8;
3955 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003956 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003957
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303958 tempax = pVBInfo->VGAVDE;
3959 tempbx = pVBInfo->VGAVDE;
3960 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003961 /* BTVGA2VRS 0x10,0x11 */
3962 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
3963 /* BTVGA2VRE 0x11 */
3964 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003965
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303966 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3967 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[10];
3968 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003969
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303970 if (temp & 0x04)
3971 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003972
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303973 if (temp & 0x080)
3974 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003975
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303976 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003977
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303978 if (temp & 0x08)
3979 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003980
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303981 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[11];
3982 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
3983 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003984
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303985 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003986 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303987 temp = ((tempbx & 0xFF00) >> 8) << 4;
3988 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02003989 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303990 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003991
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303992 if (modeflag & DoubleScanMode)
3993 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003994
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303995 if (modeflag & HalfDCLK)
3996 tempax |= 0x40;
3997
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003998 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003999}
4000
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004001static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
4002{
4003 unsigned long tempax, tempbx;
4004
4005 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
4006 & 0xFFFF;
4007 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
4008 tempax = (tempax * pVBInfo->HT) / tempbx;
4009
4010 return (unsigned short) tempax;
4011}
4012
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004013static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304014 struct xgi_hw_device_info *HwDeviceExtension,
4015 unsigned short RefreshRateTableIndex,
4016 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004017{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304018 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
4019 modeflag, CRT1Index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004020
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004021 /* si+Ext_ResInfo */
4022 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4023 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4024 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4025 CRT1Index &= IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004026
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304027 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4028 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004029
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304030 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004031 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304032 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004033
Peter Huewe6896b942012-02-09 21:11:46 +01004034 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304035 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004036
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304037 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004038
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304039 if (modeflag & HalfDCLK)
4040 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004041
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304042 tempax = (tempax / tempcx) - 1;
4043 tempbx |= ((tempax & 0x00FF) << 8);
4044 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004045 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004046
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304047 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004048
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304049 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01004050 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4051 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304052 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004053
Peter Huewe599801f2012-02-09 21:11:45 +01004054 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01004055 if (pVBInfo->VBType & VB_SIS301LV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304056 if (pVBInfo->VBExtInfo == VB_YPbPr1080i) {
4057 if (resinfo == 7)
4058 temp -= 2;
4059 }
4060 } else if (resinfo == 7) {
4061 temp -= 2;
4062 }
4063 }
4064 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004065
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004066 /* 0x05 Horizontal Display Start */
4067 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
4068 /* 0x06 Horizontal Blank end */
4069 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004070
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304071 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
4072 if (pVBInfo->VBInfo & SetCRT2ToTV)
4073 tempax = pVBInfo->VGAHT;
4074 else
4075 tempax = XGI_GetVGAHT2(pVBInfo);
4076 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004077
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304078 if (tempax >= pVBInfo->VGAHT)
4079 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004080
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304081 if (modeflag & HalfDCLK)
4082 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004083
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304084 tempax = (tempax / tempcx) - 5;
4085 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01004086 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304087 temp = (tempbx & 0x00FF) - 1;
4088 if (!(modeflag & HalfDCLK)) {
4089 temp -= 6;
4090 if (pVBInfo->TVInfo & TVSimuMode) {
4091 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004092 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304093 }
4094 }
4095 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304096 tempbx = (tempbx & 0xFF00) >> 8;
4097 tempcx = (tempcx + tempbx) >> 1;
4098 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004099
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304100 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4101 temp -= 1;
4102 if (!(modeflag & HalfDCLK)) {
4103 if ((modeflag & Charx8Dot)) {
4104 temp += 4;
4105 if (pVBInfo->VGAHDE >= 800)
4106 temp -= 6;
4107 }
4108 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02004109 } else if (!(modeflag & HalfDCLK)) {
4110 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01004111 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02004112 pVBInfo->VGAHDE >= 800) {
4113 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02004114 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01004115 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02004116 (pVBInfo->LCDInfo & LCDNonExpanding))
4117 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304118 }
4119 }
4120 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004121
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004122 /* 0x07 Horizontal Retrace Start */
4123 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
4124 /* 0x08 Horizontal Retrace End */
4125 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004126
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304127 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4128 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004129 if (ModeNo == 0x50) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304130 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004131 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304132 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004133 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304134 0x08, 0x03);
4135 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004136 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304137 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004138 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304139 0x08, 0x02);
4140 }
4141 }
4142 }
4143 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004144
Aaro Koskinen8104e322011-03-13 12:26:22 +02004145 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004146 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004147 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004148
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304149 tempbx = pVBInfo->VGAVT;
4150 push1 = tempbx;
4151 tempcx = 0x121;
4152 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004153
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304154 if (tempbx == 357)
4155 tempbx = 350;
4156 if (tempbx == 360)
4157 tempbx = 350;
4158 if (tempbx == 375)
4159 tempbx = 350;
4160 if (tempbx == 405)
4161 tempbx = 400;
4162 if (tempbx == 525)
4163 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004164
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304165 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004166
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304167 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01004168 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004169 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304170 if (tempbx == 350)
4171 tempbx += 5;
4172 if (tempbx == 480)
4173 tempbx += 5;
4174 }
4175 }
4176 }
4177 tempbx--;
4178 temp = tempbx & 0x00FF;
4179 tempbx--;
4180 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004181 /* 0x10 vertical Blank Start */
4182 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304183 tempbx = push2;
4184 tempbx--;
4185 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004186 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004187
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304188 if (tempbx & 0x0100)
4189 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004190
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304191 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004192
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304193 if (modeflag & DoubleScanMode)
4194 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004195
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304196 if (tempbx & 0x0200)
4197 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004198
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304199 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004200 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004201
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304202 if (tempbx & 0x0400)
4203 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004204
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004205 /* 0x11 Vertival Blank End */
4206 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304207
4208 tempax = push1;
4209 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
4210 tempax = tempax >> 2;
4211 push1 = tempax; /* push ax */
4212
4213 if (resinfo != 0x09) {
4214 tempax = tempax << 1;
4215 tempbx += tempax;
4216 }
4217
Peter Huewe599801f2012-02-09 21:11:45 +01004218 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01004219 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01004220 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304221 tempbx -= 10;
4222 } else {
4223 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Huewe599801f2012-02-09 21:11:45 +01004224 if (pVBInfo->TVInfo & TVSetPAL) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004225 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004226 VB_SIS301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004227 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01004228 (TVSetYPbPr525p |
4229 TVSetYPbPr750p |
4230 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304231 tempbx += 40;
4232 } else {
4233 tempbx += 40;
4234 }
4235 }
4236 }
4237 }
4238 } else {
4239 tempbx -= 10;
4240 }
4241 } else {
4242 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Huewe599801f2012-02-09 21:11:45 +01004243 if (pVBInfo->TVInfo & TVSetPAL) {
Peter Huewe6896b942012-02-09 21:11:46 +01004244 if (pVBInfo->VBType & VB_SIS301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004245 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01004246 (TVSetYPbPr525p |
4247 TVSetYPbPr750p |
4248 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304249 tempbx += 40;
4250 } else {
4251 tempbx += 40;
4252 }
4253 }
4254 }
4255 }
4256 tempax = push1;
4257 tempax = tempax >> 2;
4258 tempax++;
4259 tempax += tempbx;
4260 push1 = tempax; /* push ax */
4261
Peter Huewe599801f2012-02-09 21:11:45 +01004262 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304263 if (tempbx <= 513) {
4264 if (tempax >= 513)
4265 tempbx = 513;
4266 }
4267 }
4268
4269 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004270 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304271 tempbx--;
4272 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004273 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304274
4275 if (tempbx & 0x0100)
4276 tempcx |= 0x0008;
4277
4278 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004279 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304280
4281 tempbx++;
4282
4283 if (tempbx & 0x0100)
4284 tempcx |= 0x0004;
4285
4286 if (tempbx & 0x0200)
4287 tempcx |= 0x0080;
4288
4289 if (tempbx & 0x0400)
4290 tempcx |= 0x0C00;
4291
4292 tempbx = push1; /* pop ax */
4293 temp = tempbx & 0x00FF;
4294 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004295 /* 0x0D vertical Retrace End */
4296 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304297
4298 if (tempbx & 0x0010)
4299 tempcx |= 0x2000;
4300
4301 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004302 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304303 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004304 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304305 tempax = modeflag;
4306 temp = (tempax & 0xFF00) >> 8;
4307
4308 temp = (temp >> 1) & 0x09;
4309
Peter Huewe6896b942012-02-09 21:11:46 +01004310 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304311 temp |= 0x01;
4312
Aaro Koskinen8104e322011-03-13 12:26:22 +02004313 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
4314 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
4315 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304316
4317 if (pVBInfo->LCDInfo & LCDRGB18Bit)
4318 temp = 0x80;
4319 else
4320 temp = 0x00;
4321
Aaro Koskinen8104e322011-03-13 12:26:22 +02004322 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304323
4324 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004325}
4326
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004327static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304328 unsigned short RefreshRateTableIndex,
4329 struct xgi_hw_device_info *HwDeviceExtension,
4330 struct vb_device_info *pVBInfo)
4331{
4332 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
4333 modeflag, resinfo, crt2crtc;
4334 unsigned char *TimingPoint;
4335
4336 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
4337
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004338 /* si+Ext_ResInfo */
4339 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4340 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4341 crt2crtc = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304342
4343 tempax = 0;
4344
4345 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
4346 tempax |= 0x0800;
4347
4348 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4349 tempax |= 0x0400;
4350
4351 if (pVBInfo->VBInfo & SetCRT2ToSCART)
4352 tempax |= 0x0200;
4353
Peter Huewe599801f2012-02-09 21:11:45 +01004354 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304355 tempax |= 0x1000;
4356
Peter Huewe599801f2012-02-09 21:11:45 +01004357 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304358 tempax |= 0x0100;
4359
Peter Huewe599801f2012-02-09 21:11:45 +01004360 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304361 tempax &= 0xfe00;
4362
4363 tempax = (tempax & 0xff00) >> 8;
4364
Aaro Koskinen8104e322011-03-13 12:26:22 +02004365 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304366 TimingPoint = pVBInfo->NTSCTiming;
4367
Peter Huewe599801f2012-02-09 21:11:45 +01004368 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304369 TimingPoint = pVBInfo->PALTiming;
4370
Peter Huewe599801f2012-02-09 21:11:45 +01004371 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304372 TimingPoint = pVBInfo->HiTVExtTiming;
4373
4374 if (pVBInfo->VBInfo & SetInSlaveMode)
4375 TimingPoint = pVBInfo->HiTVSt2Timing;
4376
4377 if (pVBInfo->SetFlag & TVSimuMode)
4378 TimingPoint = pVBInfo->HiTVSt1Timing;
4379
4380 if (!(modeflag & Charx8Dot))
4381 TimingPoint = pVBInfo->HiTVTextTiming;
4382 }
4383
Peter Huewe599801f2012-02-09 21:11:45 +01004384 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4385 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304386 TimingPoint = pVBInfo->YPbPr525iTiming;
4387
Peter Huewe599801f2012-02-09 21:11:45 +01004388 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304389 TimingPoint = pVBInfo->YPbPr525pTiming;
4390
Peter Huewe599801f2012-02-09 21:11:45 +01004391 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304392 TimingPoint = pVBInfo->YPbPr750pTiming;
4393 }
4394
4395 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004396 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304397
4398 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004399 /* di->temp2[j] */
4400 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304401
4402 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004403 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304404
4405 temp = pVBInfo->NewFlickerMode;
4406 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004407 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304408
Peter Huewe599801f2012-02-09 21:11:45 +01004409 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304410 tempax = 950;
4411
Peter Huewe599801f2012-02-09 21:11:45 +01004412 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304413 tempax = 520;
4414 else
4415 tempax = 440;
4416
4417 if (pVBInfo->VDE <= tempax) {
4418 tempax -= pVBInfo->VDE;
4419 tempax = tempax >> 2;
4420 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
4421 push1 = tempax;
4422 temp = (tempax & 0xFF00) >> 8;
4423 temp += (unsigned short) TimingPoint[0];
4424
Peter Huewe6896b942012-02-09 21:11:46 +01004425 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4426 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304427 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4428 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01004429 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304430 tempcx = pVBInfo->VGAHDE;
4431 if (tempcx >= 1024) {
4432 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01004433 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304434 temp = 0x19; /* PAL */
4435 }
4436 }
4437 }
4438
Aaro Koskinen8104e322011-03-13 12:26:22 +02004439 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304440 tempax = push1;
4441 temp = (tempax & 0xFF00) >> 8;
4442 temp += TimingPoint[1];
4443
Peter Huewe6896b942012-02-09 21:11:46 +01004444 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4445 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304446 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4447 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01004448 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304449 tempcx = pVBInfo->VGAHDE;
4450 if (tempcx >= 1024) {
4451 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01004452 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304453 temp = 0x52; /* PAL */
4454 }
4455 }
4456 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004457 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304458 }
4459
4460 /* 301b */
4461 tempcx = pVBInfo->HT;
4462
4463 if (XGI_IsLCDDualLink(pVBInfo))
4464 tempcx = tempcx >> 1;
4465
4466 tempcx -= 2;
4467 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004468 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304469
4470 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004471 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304472
4473 tempcx = pVBInfo->HT >> 1;
4474 push1 = tempcx; /* push cx */
4475 tempcx += 7;
4476
Peter Huewe599801f2012-02-09 21:11:45 +01004477 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304478 tempcx -= 4;
4479
4480 temp = tempcx & 0x00FF;
4481 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004482 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304483
4484 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
4485 tempbx += tempcx;
4486 push2 = tempbx;
4487 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004488 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304489 temp = (tempbx & 0xFF00) >> 8;
4490 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004491 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304492
4493 tempbx = push2;
4494 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004495 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304496 tempbx = tempbx - 4;
4497 tempcx = tempbx;
4498 }
4499
4500 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004501 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304502
4503 j += 2;
4504 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
4505 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004506 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304507 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004508 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304509
4510 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004511 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304512 tempcx -= 4;
4513
4514 temp = tempcx & 0xFF;
4515 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004516 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304517
4518 tempcx = push1; /* pop cx */
4519 j += 2;
4520 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
4521 tempcx -= temp;
4522 temp = tempcx & 0x00FF;
4523 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004524 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304525
4526 tempcx -= 11;
4527
4528 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
4529 tempax = XGI_GetVGAHT2(pVBInfo);
4530 tempcx = tempax - 1;
4531 }
4532 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004533 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304534
4535 tempbx = pVBInfo->VDE;
4536
4537 if (pVBInfo->VGAVDE == 360)
4538 tempbx = 746;
4539 if (pVBInfo->VGAVDE == 375)
4540 tempbx = 746;
4541 if (pVBInfo->VGAVDE == 405)
4542 tempbx = 853;
4543
4544 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004545 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004546 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004547 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01004548 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304549 tempbx = tempbx >> 1;
4550 } else
4551 tempbx = tempbx >> 1;
4552 }
4553
4554 tempbx -= 2;
4555 temp = tempbx & 0x00FF;
4556
Peter Huewe599801f2012-02-09 21:11:45 +01004557 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01004558 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01004559 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304560 if (pVBInfo->VBInfo & SetInSlaveMode) {
4561 if (ModeNo == 0x2f)
4562 temp += 1;
4563 }
4564 }
4565 } else {
4566 if (pVBInfo->VBInfo & SetInSlaveMode) {
4567 if (ModeNo == 0x2f)
4568 temp += 1;
4569 }
4570 }
4571 }
4572
Aaro Koskinen8104e322011-03-13 12:26:22 +02004573 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304574
4575 temp = (tempcx & 0xFF00) >> 8;
4576 temp |= ((tempbx & 0xFF00) >> 8) << 6;
4577
Peter Huewe599801f2012-02-09 21:11:45 +01004578 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01004579 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01004580 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304581 temp |= 0x10;
4582
4583 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4584 temp |= 0x20;
4585 }
4586 } else {
4587 temp |= 0x10;
4588 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4589 temp |= 0x20;
4590 }
4591 }
4592
Aaro Koskinen8104e322011-03-13 12:26:22 +02004593 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304594
Peter Huewe6896b942012-02-09 21:11:46 +01004595 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4596 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304597 tempbx = pVBInfo->VDE;
4598 tempcx = tempbx - 2;
4599
4600 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01004601 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
4602 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304603 tempbx = tempbx >> 1;
4604 }
4605
Peter Huewe6896b942012-02-09 21:11:46 +01004606 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304607 temp = 0;
4608 if (tempcx & 0x0400)
4609 temp |= 0x20;
4610
4611 if (tempbx & 0x0400)
4612 temp |= 0x40;
4613
Aaro Koskinen8104e322011-03-13 12:26:22 +02004614 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304615 }
4616
4617 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004618 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304619 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004620 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304621 }
4622
4623 tempbx = tempbx & 0x00FF;
4624
4625 if (!(modeflag & HalfDCLK)) {
4626 tempcx = pVBInfo->VGAHDE;
4627 if (tempcx >= pVBInfo->HDE) {
4628 tempbx |= 0x2000;
4629 tempax &= 0x00FF;
4630 }
4631 }
4632
4633 tempcx = 0x0101;
4634
4635 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
4636 if (pVBInfo->VGAHDE >= 1024) {
4637 tempcx = 0x1920;
4638 if (pVBInfo->VGAHDE >= 1280) {
4639 tempcx = 0x1420;
4640 tempbx = tempbx & 0xDFFF;
4641 }
4642 }
4643 }
4644
4645 if (!(tempbx & 0x2000)) {
4646 if (modeflag & HalfDCLK)
4647 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
4648
4649 push1 = tempbx;
4650 tempeax = pVBInfo->VGAHDE;
4651 tempebx = (tempcx & 0xFF00) >> 8;
4652 longtemp = tempeax * tempebx;
4653 tempecx = tempcx & 0x00FF;
4654 longtemp = longtemp / tempecx;
4655
4656 /* 301b */
4657 tempecx = 8 * 1024;
4658
Peter Huewe6896b942012-02-09 21:11:46 +01004659 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4660 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304661 tempecx = tempecx * 8;
4662 }
4663
4664 longtemp = longtemp * tempecx;
4665 tempecx = pVBInfo->HDE;
4666 temp2 = longtemp % tempecx;
4667 tempeax = longtemp / tempecx;
4668 if (temp2 != 0)
4669 tempeax += 1;
4670
4671 tempax = (unsigned short) tempeax;
4672
4673 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004674 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4675 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304676 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
4677 }
4678 /* end 301b */
4679
4680 tempbx = push1;
4681 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
4682 | (tempbx & 0x00FF));
4683 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
4684 | (tempax & 0x00FF));
4685 temp = (tempax & 0xFF00) >> 8;
4686 } else {
4687 temp = (tempax & 0x00FF) >> 8;
4688 }
4689
Aaro Koskinen8104e322011-03-13 12:26:22 +02004690 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304691 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004692 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304693 temp = tempcx & 0x00FF;
4694
4695 if (tempbx & 0x2000)
4696 temp = 0;
4697
4698 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
4699 temp |= 0x18;
4700
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004701 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01004702 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304703 tempbx = 0x0382;
4704 tempcx = 0x007e;
4705 } else {
4706 tempbx = 0x0369;
4707 tempcx = 0x0061;
4708 }
4709
4710 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004711 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304712 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004713 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304714
4715 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
4716 temp = temp << 2;
4717 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
4718
Peter Huewe599801f2012-02-09 21:11:45 +01004719 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304720 temp |= 0x10;
4721
Peter Huewe599801f2012-02-09 21:11:45 +01004722 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304723 temp |= 0x20;
4724
Peter Huewe599801f2012-02-09 21:11:45 +01004725 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304726 temp |= 0x60;
4727 }
4728
Aaro Koskinen8104e322011-03-13 12:26:22 +02004729 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02004730 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004731 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304732
Peter Huewe599801f2012-02-09 21:11:45 +01004733 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304734 if (pVBInfo->TVInfo & NTSC1024x768) {
4735 TimingPoint = XGI_NTSC1024AdjTime;
4736 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004737 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304738 TimingPoint[j]);
4739 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004740 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304741 }
4742 }
4743
4744 /* [ycchen] 01/14/03 Modify for 301C PALM Support */
4745 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01004746 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004747 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304748 0x08); /* PALM Mode */
4749 }
4750
Peter Huewe599801f2012-02-09 21:11:45 +01004751 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02004752 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304753 0x01);
4754 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02004755 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304756
Aaro Koskinendc505562011-03-13 12:26:26 +02004757 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304758 }
4759
Peter Huewe599801f2012-02-09 21:11:45 +01004760 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304761 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02004762 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304763 }
4764
4765 if (pVBInfo->VBInfo & SetCRT2ToTV)
4766 return;
4767}
4768
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004769static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304770 struct xgi_hw_device_info *HwDeviceExtension,
4771 unsigned short RefreshRateTableIndex,
4772 struct vb_device_info *pVBInfo)
4773{
4774 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
4775 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
4776
4777 struct XGI_LCDDesStruct *LCDBDesPtr = NULL;
4778
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004779 /* si+Ext_ResInfo */
4780 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4781 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4782 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4783 CRT1Index &= IndexMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304784
4785 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
4786 return;
4787
4788 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
4789
4790 if (XGI_IsLCDDualLink(pVBInfo))
4791 tempbx = tempbx >> 1;
4792
4793 tempbx -= 1;
4794 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004795 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304796 temp = (tempbx & 0xFF00) >> 8;
4797 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004798 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304799 temp = 0x01;
4800
Aaro Koskinen8104e322011-03-13 12:26:22 +02004801 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304802 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
4803 push1 = tempbx;
4804 tempbx--;
4805 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004806 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304807 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004808 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304809
4810 tempcx = pVBInfo->VT - 1;
4811 push2 = tempcx + 1;
4812 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004813 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304814 temp = (tempcx & 0xFF00) >> 8;
4815 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004816 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004817 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
4818 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
4819 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
4820 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304821
4822 /* Customized LCDB Des no add */
4823 tempbx = 5;
4824 LCDBDesPtr = (struct XGI_LCDDesStruct *) XGI_GetLcdPtr(tempbx, ModeNo,
4825 ModeIdIndex, RefreshRateTableIndex, pVBInfo);
4826 tempah = pVBInfo->LCDResInfo;
4827 tempah &= PanelResInfo;
4828
Peter Huewe255aabd2012-02-09 21:11:44 +01004829 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304830 tempbx = 1024;
4831 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01004832 } else if ((tempah == Panel_1280x1024) ||
4833 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304834 tempbx = 1280;
4835 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01004836 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304837 tempbx = 1400;
4838 tempcx = 1050;
4839 } else {
4840 tempbx = 1600;
4841 tempcx = 1200;
4842 }
4843
4844 if (pVBInfo->LCDInfo & EnableScalingLCD) {
4845 tempbx = pVBInfo->HDE;
4846 tempcx = pVBInfo->VDE;
4847 }
4848
4849 pushbx = tempbx;
4850 tempax = pVBInfo->VT;
4851 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
4852 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
4853 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
4854 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
4855 tempbx = pVBInfo->LCDVDES;
4856 tempcx += tempbx;
4857
4858 if (tempcx >= tempax)
4859 tempcx -= tempax; /* lcdvdes */
4860
4861 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004862 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304863 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004864 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304865 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
4866 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
4867 tempah = tempch;
4868 tempah = tempah << 3;
4869 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004870 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304871
4872 /* getlcdsync() */
4873 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4874 tempcx = tempbx;
4875 tempax = pVBInfo->VT;
4876 tempbx = pVBInfo->LCDVRS;
4877
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304878 tempcx += tempbx;
4879 if (tempcx >= tempax)
4880 tempcx -= tempax;
4881
4882 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004883 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304884 temp = (tempbx & 0xFF00) >> 8;
4885 temp = temp << 4;
4886 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004887 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304888 tempcx = pushbx;
4889 tempax = pVBInfo->HT;
4890 tempbx = pVBInfo->LCDHDES;
4891 tempbx &= 0x0FFF;
4892
4893 if (XGI_IsLCDDualLink(pVBInfo)) {
4894 tempax = tempax >> 1;
4895 tempbx = tempbx >> 1;
4896 tempcx = tempcx >> 1;
4897 }
4898
Peter Huewe6896b942012-02-09 21:11:46 +01004899 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304900 tempbx += 1;
4901
4902 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
4903 tempbx += 1;
4904
4905 tempcx += tempbx;
4906
4907 if (tempcx >= tempax)
4908 tempcx -= tempax;
4909
4910 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004911 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304912 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004913 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304914 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004915 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304916 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004917 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304918
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304919 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4920 tempcx = tempax;
4921 tempax = pVBInfo->HT;
4922 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304923 if (XGI_IsLCDDualLink(pVBInfo)) {
4924 tempax = tempax >> 1;
4925 tempbx = tempbx >> 1;
4926 tempcx = tempcx >> 1;
4927 }
4928
Peter Huewe6896b942012-02-09 21:11:46 +01004929 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304930 tempbx += 1;
4931
4932 tempcx += tempbx;
4933
4934 if (tempcx >= tempax)
4935 tempcx -= tempax;
4936
4937 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004938 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304939
4940 temp = (tempbx & 0xFF00) >> 8;
4941 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004942 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304943 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004944 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304945
Peter Huewea3d675c2012-02-09 21:11:47 +01004946 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304947 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01004948 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4949 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304950 | VB_XGI301C)) {
4951 temp = 0xC6;
4952 } else
4953 temp = 0xC4;
4954
Aaro Koskinen8104e322011-03-13 12:26:22 +02004955 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
4956 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304957 }
4958
4959 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01004960 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4961 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304962 | VB_XGI301C)) {
4963 temp = 0x4F;
4964 } else
4965 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004966 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304967 }
4968 }
4969}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004970
4971/* --------------------------------------------------------------------- */
4972/* Function : XGI_GetTap4Ptr */
4973/* Input : */
4974/* Output : di -> Tap4 Reg. Setting Pointer */
4975/* Description : */
4976/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004977static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304978 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004979{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304980 unsigned short tempax, tempbx, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004981
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304982 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004983
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304984 if (tempcx == 0) {
4985 tempax = pVBInfo->VGAHDE;
4986 tempbx = pVBInfo->HDE;
4987 } else {
4988 tempax = pVBInfo->VGAVDE;
4989 tempbx = pVBInfo->VDE;
4990 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004991
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004992 if (tempax <= tempbx)
4993 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304994 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004995 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004996
Peter Huewe599801f2012-02-09 21:11:45 +01004997 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304998 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004999
Peter Huewe599801f2012-02-09 21:11:45 +01005000 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
5001 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
5002 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005003 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01005004 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305005 Tap4TimingPtr = YPbPr750pTap4Timing;
5006 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005007
Peter Huewe599801f2012-02-09 21:11:45 +01005008 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03005009 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005010
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305011 i = 0;
5012 while (Tap4TimingPtr[i].DE != 0xFFFF) {
5013 if (Tap4TimingPtr[i].DE == tempax)
5014 break;
5015 i++;
5016 }
5017 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005018}
5019
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005020static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005021{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305022 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005023
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305024 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005025
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305026 if (!(pVBInfo->VBType & VB_XGI301C))
5027 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005028
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305029 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
5030 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005031 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005032
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005033 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01005034 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005035 /* Set Vertical Scaling */
5036 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305037 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005038 xgifb_reg_set(pVBInfo->Part2Port,
5039 i,
5040 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305041 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005042
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005043 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01005044 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005045 /* Enable V.Scaling */
5046 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305047 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005048 /* Enable H.Scaling */
5049 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005050}
5051
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005052static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305053 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005054{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305055 unsigned short i;
5056 unsigned char *tempdi;
5057 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005058
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005059 /* si+Ext_ResInfo */
5060 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005061
Aaro Koskinen8104e322011-03-13 12:26:22 +02005062 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01005063 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005064 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5065 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305066 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005067 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
5068 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305069 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005070
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305071 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5072 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005073
Peter Huewe599801f2012-02-09 21:11:45 +01005074 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005075 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
5076 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
5077 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305078 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005079
Peter Huewe599801f2012-02-09 21:11:45 +01005080 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
5081 & SetCRT2ToYPbPr525750)) {
5082 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305083 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005084
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305085 tempdi = pVBInfo->HiTVGroup3Data;
5086 if (pVBInfo->SetFlag & TVSimuMode) {
5087 tempdi = pVBInfo->HiTVGroup3Simu;
5088 if (!(modeflag & Charx8Dot))
5089 tempdi = pVBInfo->HiTVGroup3Text;
5090 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005091
Peter Huewe599801f2012-02-09 21:11:45 +01005092 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305093 tempdi = pVBInfo->Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005094
Peter Huewe599801f2012-02-09 21:11:45 +01005095 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305096 tempdi = pVBInfo->Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005097
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305098 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005099 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305101 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01005102 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005103 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305104 }
5105 }
5106 return;
5107} /* {end of XGI_SetGroup3} */
5108
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005109static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305110 unsigned short RefreshRateTableIndex,
5111 struct xgi_hw_device_info *HwDeviceExtension,
5112 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005113{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305114 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005115
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305116 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005117
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005118 /* si+Ext_ResInfo */
5119 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305120 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005121 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005122
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305123 tempbx = pVBInfo->RVBHCMAX;
5124 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005125 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305126 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
5127 tempcx = pVBInfo->VGAHT - 1;
5128 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005129 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005130
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305131 temp = ((tempcx & 0xFF00) >> 8) << 3;
5132 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005133
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305134 tempcx = pVBInfo->VGAVT - 1;
5135 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
5136 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005137
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305138 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005139 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305140 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005141 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005142 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305143 tempcx = pVBInfo->VBInfo;
5144 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005145
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305146 if (modeflag & HalfDCLK)
5147 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005148
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305149 if (XGI_IsLCDDualLink(pVBInfo))
5150 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005151
Peter Huewe599801f2012-02-09 21:11:45 +01005152 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305153 temp = 0;
5154 if (tempbx <= 1024)
5155 temp = 0xA0;
5156 if (tempbx == 1280)
5157 temp = 0xC0;
5158 } else if (tempcx & SetCRT2ToTV) {
5159 temp = 0xA0;
5160 if (tempbx <= 800)
5161 temp = 0x80;
5162 } else {
5163 temp = 0x80;
5164 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5165 temp = 0;
5166 if (tempbx > 800)
5167 temp = 0x60;
5168 }
5169 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005170
Peter Huewe599801f2012-02-09 21:11:45 +01005171 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305172 temp = 0x00;
5173 if (pVBInfo->VGAHDE == 1280)
5174 temp = 0x40;
5175 if (pVBInfo->VGAHDE == 1024)
5176 temp = 0x20;
5177 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005178 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305180 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005181
Peter Huewe599801f2012-02-09 21:11:45 +01005182 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305183 if (!(temp & 0xE000))
5184 tempbx = tempbx >> 1;
5185 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005186
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305187 tempcx = pVBInfo->RVBHRS;
5188 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005189 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005190
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305191 tempeax = pVBInfo->VGAVDE;
5192 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005193
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305194 if (tempeax <= tempebx) {
5195 tempcx = (tempcx & (~0x4000));
5196 tempeax = pVBInfo->VGAVDE;
5197 } else {
5198 tempeax -= tempebx;
5199 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005200
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305201 templong = (tempeax * 256 * 1024) % tempebx;
5202 tempeax = (tempeax * 256 * 1024) / tempebx;
5203 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005204
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305205 if (templong != 0)
5206 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005207
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305208 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005209 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005210
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305211 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005212 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305213 tempbx = (unsigned short) (tempebx >> 16);
5214 temp = tempbx & 0x00FF;
5215 temp = temp << 4;
5216 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005217 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005218
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305219 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01005220 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5221 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305222 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005223 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305224 tempax = pVBInfo->VGAHDE;
5225 if (modeflag & HalfDCLK)
5226 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005227
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305228 if (XGI_IsLCDDualLink(pVBInfo))
5229 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005230
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305231 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5232 if (tempax > 800)
5233 tempax -= 800;
5234 } else {
5235 if (pVBInfo->VGAHDE > 800) {
5236 if (pVBInfo->VGAHDE == 1024)
5237 tempax = (tempax * 25 / 32) - 1;
5238 else
5239 tempax = (tempax * 20 / 32) - 1;
5240 }
5241 }
5242 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005243
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305244 temp = (tempax & 0xFF00) >> 8;
5245 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005246 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305247 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005248 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005249
Peter Huewe599801f2012-02-09 21:11:45 +01005250 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305251 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005252 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005253
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305254 }
5255 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005256
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305257 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5258 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01005259 | TVSetYPbPr525p | TVSetYPbPr750p
5260 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305261 temp |= 0x0001;
5262 if ((pVBInfo->VBInfo & SetInSlaveMode)
5263 && (!(pVBInfo->TVInfo
5264 & TVSimuMode)))
5265 temp &= (~0x0001);
5266 }
5267 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005268
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005269 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305270 tempbx = pVBInfo->HT;
5271 if (XGI_IsLCDDualLink(pVBInfo))
5272 tempbx = tempbx >> 1;
5273 tempbx = (tempbx >> 1) - 2;
5274 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005275 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305276 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005277 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305278 }
5279 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005280
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305281 if (pVBInfo->ISXPDOS == 0)
5282 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5283 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005284}
5285
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005286static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
5287{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005288 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005289}
5290
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005291static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305292 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005293{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305294 unsigned short Pindex, Pdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005295
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305296 Pindex = pVBInfo->Part5Port;
5297 Pdata = pVBInfo->Part5Port + 1;
5298 if (pVBInfo->ModeType == ModeVGA) {
5299 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01005300 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305301 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305302 }
5303 }
5304 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005305}
5306
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005307static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305308 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005309{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005310 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005311}
5312
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005313static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305314 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005315{
5316
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005317 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005318}
5319
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005320static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
5321 unsigned short ModeNo, unsigned short ModeIdIndex,
5322 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005323{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005324 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005325
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305326 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005327 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
5328 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
5329 /* si+St_ModeFlag */
5330 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005331
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305332 if (!(modeflag & Charx8Dot)) {
5333 xres /= 9;
5334 xres *= 8;
5335 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005336
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005337 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
5338 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005339
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005340 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
5341 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005342
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005343 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305344 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04005345
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005346 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305347 return 0;
5348
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005349 if (xres != xgifb_info->lvds_data.LVDSHDE ||
5350 yres != xgifb_info->lvds_data.LVDSVDE) {
5351 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
5352 if (colordepth > 2)
5353 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305354 }
5355 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005356}
5357
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005358static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
5359 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005360 unsigned short ModeNo,
5361 unsigned short ModeIdIndex,
5362 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005363{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305364 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005365 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305366 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
5367 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
5368 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005369
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005370 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005371 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305372 temp &= LCDPolarity;
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005373 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005374
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005375 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005376
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005377 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005378 /* SR35[7] FP VSync polarity */
5379 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
5380 /* SR30[5] FP HSync polarity */
5381 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005382
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005383 if (chip_id == XG27)
5384 XGI_SetXG27FPBits(pVBInfo);
5385 else
5386 XGI_SetXG21FPBits(pVBInfo);
5387
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305388 resindex = XGI_GetResInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005389 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
5390 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
5391 /* si+St_ModeFlag */
5392 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005393
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305394 if (!(modeflag & Charx8Dot))
5395 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005396
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005397 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005398
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005399 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005400
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305401 if (LVDSHBS > LVDSHT)
5402 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005403
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005404 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305405 if (LVDSHRS > LVDSHT)
5406 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005407
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005408 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305409 if (LVDSHRE > LVDSHT)
5410 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005411
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005412 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005413
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005414 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005415
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005416 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005417 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305418 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005419
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305420 if (LVDSVBS > LVDSVT)
5421 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005422
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005423 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305424 if (LVDSVRS > LVDSVT)
5425 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005426
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005427 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305428 if (LVDSVRE > LVDSVT)
5429 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005430
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005431 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005432
Aaro Koskinen58839b02011-03-13 12:26:23 +02005433 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005434 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005435
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305436 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005437 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005438
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305439 /* HT SR0B[1:0] CR00 */
5440 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005441 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005442 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005443
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305444 /* HBS SR0B[5:4] CR02 */
5445 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005446 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005447 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005448
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305449 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
5450 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005451 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
5452 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
5453 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005454
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305455 /* HRS SR0B[7:6] CR04 */
5456 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005457 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005458 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005459
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305460 /* Panel HRS SR2F[1:0] SR2E[7:0] */
5461 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005462 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005463 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005464
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305465 /* HRE SR0C[2] CR05[4:0] */
5466 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005467 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
5468 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005469
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305470 /* Panel HRE SR2F[7:2] */
5471 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005472 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005473
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305474 /* VT SR0A[0] CR07[5][0] CR06 */
5475 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005476 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
5477 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
5478 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005479 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005480
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305481 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
5482 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005483 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
5484 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
5485 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005486 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005487
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305488 /* VBE SR0A[4] CR16 */
5489 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005490 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005491 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005492
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305493 /* VRS SR0A[3] CR7[7][2] CR10 */
5494 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005495 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
5496 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
5497 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005498 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005499
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005500 if (chip_id == XG27) {
5501 /* Panel VRS SR35[2:0] SR34[7:0] */
5502 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
5503 (value & 0x700) >> 8);
5504 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
5505 } else {
5506 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
5507 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
5508 (value & 0x600) >> 9);
5509 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
5510 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
5511 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005512
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305513 /* VRE SR0A[5] CR11[3:0] */
5514 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005515 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
5516 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005517
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305518 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005519 if (chip_id == XG27)
5520 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
5521 (value << 2) & 0xFC);
5522 else
5523 /* SR3F[7] has to be 0, h/w bug */
5524 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
5525 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005526
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305527 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005528
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005529 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005530 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005531 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005532 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005533 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305534 value += 0x10;
5535 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005536
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305537 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005538 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005539 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005540 /* set data, panning = 0, shift left 1 dot*/
5541 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005542
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005543 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005544 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305545
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005546 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305547 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005548
5549}
5550
5551/* --------------------------------------------------------------------- */
5552/* Function : XGI_IsLCDON */
5553/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04005554/* Output : 0 : Skip PSC Control */
5555/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005556/* Description : */
5557/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005558static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005559{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305560 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005561
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305562 tempax = pVBInfo->VBInfo;
5563 if (tempax & SetCRT2ToDualEdge)
5564 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01005565 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305566 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005567
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305568 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005569}
5570
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005571/* --------------------------------------------------------------------- */
5572/* Function : XGI_DisableChISLCD */
5573/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04005574/* Output : 0 -> Not LCD Mode */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005575/* Description : */
5576/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005577static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005578{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305579 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005580
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305581 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005582 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005583
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305584 if (tempbx & (EnableChA | DisableChA)) {
5585 if (!(tempah & 0x08)) /* Chk LCDA Mode */
5586 return 0;
5587 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005588
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305589 if (!(tempbx & (EnableChB | DisableChB)))
5590 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005591
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305592 if (tempah & 0x01) /* Chk LCDB Mode */
5593 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005594
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305595 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005596}
5597
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005598/* --------------------------------------------------------------------- */
5599/* Function : XGI_EnableChISLCD */
5600/* Input : */
5601/* Output : 0 -> Not LCD mode */
5602/* Description : */
5603/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005604static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005605{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305606 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005607
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305608 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005609 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005610
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305611 if (tempbx & (EnableChA | DisableChA)) {
5612 if (!(tempah & 0x08)) /* Chk LCDA Mode */
5613 return 0;
5614 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005615
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305616 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04005617 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005618
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305619 if (tempah & 0x01) /* Chk LCDB Mode */
5620 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005621
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305622 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005623}
5624
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005625static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
5626 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305627 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005628{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005629 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005630
Peter Huewe6896b942012-02-09 21:11:46 +01005631 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5632 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305633 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005634 if (!(pVBInfo->VBInfo &
5635 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005636 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305637 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5638 tempah = 0x7F; /* Disable Channel A */
Peter Huewea3d675c2012-02-09 21:11:47 +01005639 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005640 /* Disable Channel B */
5641 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005642
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305643 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005644 /* force to disable Cahnnel */
5645 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005646
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305647 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005648 /* Force to disable Channel B */
5649 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305650 }
5651 }
5652 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005653
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005654 /* disable part4_1f */
5655 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005656
Peter Huewe6896b942012-02-09 21:11:46 +01005657 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005658 if (((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305659 || (XGI_DisableChISLCD(pVBInfo))
5660 || (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005661 /* LVDS Driver power down */
5662 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305663 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005664
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305665 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01005666 & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305667 | SetSimuScanMode))) {
5668 if (pVBInfo->SetFlag & GatingCRT)
5669 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005670 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305671 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005672
Peter Huewea3d675c2012-02-09 21:11:47 +01005673 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305674 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01005675 & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005676 /* Power down */
5677 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305678 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005679
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005680 /* disable TV as primary VGA swap */
5681 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005682
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305683 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02005684 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005685
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005686 if ((pVBInfo->SetFlag & DisableChB) ||
5687 (pVBInfo->VBInfo &
5688 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01005689 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005690 (pVBInfo->VBInfo &
5691 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005692 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005693
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005694 if ((pVBInfo->SetFlag & DisableChB) ||
5695 (pVBInfo->VBInfo &
5696 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01005697 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005698 (pVBInfo->VBInfo &
5699 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
5700 /* save Part1 index 0 */
5701 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
5702 /* BTDAC = 1, avoid VB reset */
5703 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
5704 /* disable CRT2 */
5705 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
5706 /* restore Part1 index 0 */
5707 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305708 }
5709 } else { /* {301} */
5710 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005711 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
5712 /* Disable CRT2 */
5713 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
5714 /* Disable TV asPrimary VGA swap */
5715 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305716 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005717
Peter Huewea3d675c2012-02-09 21:11:47 +01005718 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305719 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005720 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305721 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005722}
5723
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005724/* --------------------------------------------------------------------- */
5725/* Function : XGI_GetTVPtrIndex */
5726/* Input : */
5727/* Output : */
5728/* Description : bx 0 : ExtNTSC */
5729/* 1 : StNTSC */
5730/* 2 : ExtPAL */
5731/* 3 : StPAL */
5732/* 4 : ExtHiTV */
5733/* 5 : StHiTV */
5734/* 6 : Ext525i */
5735/* 7 : St525i */
5736/* 8 : Ext525p */
5737/* 9 : St525p */
5738/* A : Ext750p */
5739/* B : St750p */
5740/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005741static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005742{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305743 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005744
Peter Huewe599801f2012-02-09 21:11:45 +01005745 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305746 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01005747 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305748 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01005749 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305750 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01005751 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305752 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01005753 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305754 tempbx = 10;
5755 if (pVBInfo->TVInfo & TVSimuMode)
5756 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005757
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305758 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005759}
5760
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005761/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005762/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005763/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005764/* Output : bx 0 : NTSC */
5765/* 1 : PAL */
5766/* 2 : PALM */
5767/* 3 : PALN */
5768/* 4 : NTSC1024x768 */
5769/* 5 : PAL-M 1024x768 */
5770/* 6-7: reserved */
5771/* cl 0 : YFilter1 */
5772/* 1 : YFilter2 */
5773/* ch 0 : 301A */
5774/* 1 : 301B/302B/301LV/302LV */
5775/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005776/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005777static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
5778 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005779{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005780 *tempbx = 0;
5781 *tempcl = 0;
5782 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005783
Peter Huewe599801f2012-02-09 21:11:45 +01005784 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005785 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005786
Peter Huewe599801f2012-02-09 21:11:45 +01005787 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005788 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005789
Peter Huewe599801f2012-02-09 21:11:45 +01005790 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005791 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005792
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005793 if (pVBInfo->TVInfo & NTSC1024x768) {
5794 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01005795 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005796 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305797 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005798
Peter Huewe6896b942012-02-09 21:11:46 +01005799 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5800 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005801 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
5802 & TVSimuMode)) {
5803 *tempbx += 8;
5804 *tempcl += 1;
5805 }
5806 }
5807
Peter Huewe6896b942012-02-09 21:11:46 +01005808 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5809 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005810 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005811}
5812
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005813static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005814{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305815 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005816
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305817 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005818
Peter Huewe6896b942012-02-09 21:11:46 +01005819 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5820 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005821 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305822 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
5823 tempbl = 0;
5824 tempbh = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005825
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305826 index = XGI_GetTVPtrIndex(pVBInfo); /* Get TV Delay */
5827 tempbl = pVBInfo->XGI_TVDelayList[index];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005828
Peter Huewe6896b942012-02-09 21:11:46 +01005829 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
5830 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305831 | VB_XGI301C))
5832 tempbl = pVBInfo->XGI_TVDelayList2[index];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005833
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305834 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5835 tempbl = tempbl >> 4;
Peter Huewea3d675c2012-02-09 21:11:47 +01005836 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005837 /* Get LCD Delay */
5838 index = XGI_GetLCDCapPtr(pVBInfo);
5839 tempbh = pVBInfo->LCDCapList[index].
5840 LCD_DelayCompensation;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005841
Peter Huewea3d675c2012-02-09 21:11:47 +01005842 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305843 tempbl = tempbh;
5844 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005845
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305846 tempbl &= 0x0F;
5847 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02005848 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005849
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305850 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
5851 | SetCRT2ToTV)) { /* Channel B */
5852 tempah &= 0xF0;
5853 tempah |= tempbl;
5854 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005855
Peter Huewea3d675c2012-02-09 21:11:47 +01005856 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) { /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305857 tempah &= 0x0F;
5858 tempah |= tempbh;
5859 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005860 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305861 }
5862 } else if (pVBInfo->IF_DEF_LVDS == 1) {
5863 tempbl = 0;
5864 tempbh = 0;
5865 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005866 /* / Get LCD Delay */
5867 tempah = pVBInfo->LCDCapList[
5868 XGI_GetLCDCapPtr(pVBInfo)].
5869 LCD_DelayCompensation;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305870 tempah &= 0x0f;
5871 tempah = tempah << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005872 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305873 tempah);
5874 }
5875 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005876}
5877
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005878static void XGI_SetLCDCap_A(unsigned short tempcx,
5879 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005880{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305881 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005882
Aaro Koskinen58839b02011-03-13 12:26:23 +02005883 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005884
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305885 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005886 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005887 /* Enable Dither */
5888 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005889 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305890 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005891 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305892 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005893 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305894 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005895}
5896
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005897/* --------------------------------------------------------------------- */
5898/* Function : XGI_SetLCDCap_B */
5899/* Input : cx -> LCD Capability */
5900/* Output : */
5901/* Description : */
5902/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005903static void XGI_SetLCDCap_B(unsigned short tempcx,
5904 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005905{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305906 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005907 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305908 (unsigned short) (((tempcx & 0x00ff) >> 6)
5909 | 0x0c));
5910 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005911 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305912 (unsigned short) (((tempcx & 0x00ff) >> 6)
5913 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005914}
5915
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02005916static void XGI_LongWait(struct vb_device_info *pVBInfo)
5917{
5918 unsigned short i;
5919
5920 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
5921
5922 if (!(i & 0xC0)) {
5923 for (i = 0; i < 0xFFFF; i++) {
5924 if (!(inb(pVBInfo->P3da) & 0x08))
5925 break;
5926 }
5927
5928 for (i = 0; i < 0xFFFF; i++) {
5929 if ((inb(pVBInfo->P3da) & 0x08))
5930 break;
5931 }
5932 }
5933}
5934
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005935static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005936{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305937 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005938
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305939 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005940
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005941 /* disable down spectrum D[4] */
5942 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305943 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005944 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305945 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005946
Aaro Koskinen8104e322011-03-13 12:26:22 +02005947 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305948 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005949 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305950 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005951 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305952 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005953 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305954 pVBInfo->LCDCapList[index].Spectrum_34);
5955 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005956 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005957}
5958
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005959static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
5960{
5961 unsigned short tempcx;
5962
5963 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
5964
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005965 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005966 (VB_SIS301B |
5967 VB_SIS302B |
5968 VB_SIS301LV |
5969 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005970 VB_XGI301C)) { /* 301LV/302LV only */
5971 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005972 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005973 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005974 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005975 (unsigned char) (tempcx & 0x1F));
5976 }
5977 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005978 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005979 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
5980 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
5981 | EnablePLLSPLOW)) >> 8));
5982 }
5983
Peter Huewe6896b942012-02-09 21:11:46 +01005984 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5985 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005986 if (pVBInfo->VBInfo & SetCRT2ToLCD)
5987 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01005988 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005989 XGI_SetLCDCap_A(tempcx, pVBInfo);
5990
Peter Huewe6896b942012-02-09 21:11:46 +01005991 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005992 if (tempcx & EnableSpectrum)
5993 SetSpectrum(pVBInfo);
5994 }
5995 } else {
5996 /* LVDS,CH7017 */
5997 XGI_SetLCDCap_A(tempcx, pVBInfo);
5998 }
5999}
6000
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006001/* --------------------------------------------------------------------- */
6002/* Function : XGI_SetAntiFlicker */
6003/* Input : */
6004/* Output : */
6005/* Description : Set TV Customized Param. */
6006/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006007static void XGI_SetAntiFlicker(unsigned short ModeNo,
6008 unsigned short ModeIdIndex,
6009 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006010{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306011 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006012
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306013 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006014
Peter Huewe599801f2012-02-09 21:11:45 +01006015 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306016 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006017
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306018 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6019 tempbx &= 0xFE;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006020 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVFlickerIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306021 tempbx += index;
6022 tempah = TVAntiFlickList[tempbx];
6023 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006024
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006025 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006026}
6027
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006028static void XGI_SetEdgeEnhance(unsigned short ModeNo,
6029 unsigned short ModeIdIndex,
6030 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006031{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306032 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006033
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306034 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006035
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306036 tempbx = XGI_GetTVPtrIndex(pVBInfo);
6037 tempbx &= 0xFE;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006038 index = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVEdgeIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306039 tempbx += index;
6040 tempah = TVEdgeList[tempbx];
6041 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006042
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006043 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006044}
6045
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006046static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006047{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306048 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006049
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306050 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006051
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306052 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006053
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306054 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
6055 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006056
Aaro Koskinen8104e322011-03-13 12:26:22 +02006057 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306058 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006059 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306060 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006061 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306062 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006063 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306064 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006065}
6066
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006067static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306068 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006069{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306070 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006071
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306072 unsigned char tempcl, tempch, tempal, *filterPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006073
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306074 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006075
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306076 switch (tempbx) {
6077 case 0x00:
6078 case 0x04:
6079 filterPtr = NTSCYFilter1;
6080 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006081
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306082 case 0x01:
6083 filterPtr = PALYFilter1;
6084 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006085
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306086 case 0x02:
6087 case 0x05:
6088 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306089 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03006090 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306091 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006092
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306093 case 0x08:
6094 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306095 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306096 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306097 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03006098 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306099 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306101 default:
6102 return;
6103 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006104
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006105 tempal = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306106 if (tempcl == 0)
6107 index = tempal * 4;
6108 else
6109 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006110
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306111 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02006112 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
6113 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
6114 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
6115 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306116 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02006117 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
6118 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
6119 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
6120 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306121 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006122
Peter Huewe6896b942012-02-09 21:11:46 +01006123 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6124 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02006125 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
6126 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
6127 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306128 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006129}
6130
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006131/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006132/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006133/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006134/* Output : */
6135/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006136/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006137static void XGI_OEM310Setting(unsigned short ModeNo,
6138 unsigned short ModeIdIndex,
6139 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006140{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006141 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006142
Peter Huewea3d675c2012-02-09 21:11:47 +01006143 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006144 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006145
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006146 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006147 XGI_SetPhaseIncr(pVBInfo);
6148 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
6149 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006150
Peter Huewe6896b942012-02-09 21:11:46 +01006151 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006152 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306153 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006154}
6155
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006156/* --------------------------------------------------------------------- */
6157/* Function : XGI_SetCRT2ModeRegs */
6158/* Input : */
6159/* Output : */
6160/* Description : Origin code for crt2group */
6161/* --------------------------------------------------------------------- */
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02006162static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306163 struct xgi_hw_device_info *HwDeviceExtension,
6164 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006165{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306166 unsigned short tempbl;
6167 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006168
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306169 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006170
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306171 tempah = 0;
6172 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006173 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306174 tempah &= ~0x10; /* BTRAMDAC */
6175 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006176
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306177 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
6178 | SetCRT2ToLCD)) {
6179 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006180 tempcl = pVBInfo->ModeType;
6181 tempcl -= ModeVGA;
6182 if (tempcl >= 0) {
6183 /* BT Color */
6184 tempah = (0x008 >> tempcl);
6185 if (tempah == 0)
6186 tempah = 1;
6187 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306188 }
6189 if (pVBInfo->VBInfo & SetInSlaveMode)
6190 tempah ^= 0x50; /* BTDAC */
6191 }
6192 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006193
Aaro Koskinen8104e322011-03-13 12:26:22 +02006194 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306195 tempah = 0x08;
6196 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006197
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306198 if (pVBInfo->VBInfo & DisableCRT2Display) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006199 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306200 } else {
6201 tempah = 0x00;
6202 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006203
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306204 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
Peter Huewea3d675c2012-02-09 21:11:47 +01006205 | SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
6206 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006207 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306208 tempbl &= 0xf7;
6209 tempah |= 0x01;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006210 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306211 tempbl, tempah);
6212 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01006213 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306214 tempbl &= 0xf7;
6215 tempah |= 0x01;
6216 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006217
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006218 if (pVBInfo->VBInfo &
6219 (SetCRT2ToRAMDAC |
6220 SetCRT2ToTV |
6221 SetCRT2ToLCD)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306222 tempbl &= 0xf8;
6223 tempah = 0x01;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006224
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306225 if (!(pVBInfo->VBInfo & SetInSlaveMode))
6226 tempah |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006227
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006228 if (!(pVBInfo->VBInfo &
6229 SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306230 tempah = tempah ^ 0x05;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006231 if (!(pVBInfo->VBInfo &
6232 SetCRT2ToLCD))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306233 tempah = tempah ^ 0x01;
6234 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006235
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006236 if (!(pVBInfo->VBInfo &
6237 SetCRT2ToDualEdge))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306238 tempah |= 0x08;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006239 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306240 0x2e, tempbl, tempah);
6241 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006242 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306243 0x2e, tempbl, tempah);
6244 }
6245 }
6246 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006247 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306248 tempah);
6249 }
6250 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006251
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306252 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01006253 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306254 tempah &= (~0x08);
6255 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
6256 & SetInSlaveMode))) {
6257 tempah |= 0x010;
6258 }
6259 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006260
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306261 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306262 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006263 if (pVBInfo->VBInfo & DriverMode)
6264 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306265 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006266
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006267 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306268 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006269
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306270 if (pVBInfo->LCDInfo & SetLCDDualLink)
6271 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006272
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306273 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306274 if (pVBInfo->TVInfo & RPLLDIV2XO)
6275 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306276 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006277
Peter Huewe255aabd2012-02-09 21:11:44 +01006278 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
6279 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306280 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006281
Peter Huewe255aabd2012-02-09 21:11:44 +01006282 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306283 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006284
Aaro Koskinen8104e322011-03-13 12:26:22 +02006285 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306286 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006287
Peter Huewe6896b942012-02-09 21:11:46 +01006288 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6289 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306290 tempah = 0;
6291 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006292
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306293 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6294 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01006295 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306296 tempah |= 0x04; /* shampoo 0129 */
6297 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006298
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006299 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306300 tempah = 0x00;
6301 tempbl = 0xcf;
6302 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6303 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6304 tempah |= 0x30;
6305 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006306
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006307 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306308 tempah = 0;
6309 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006310
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306311 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6312 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6313 tempah |= 0xc0;
6314 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006315 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306316 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006317
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306318 tempah = 0;
6319 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01006320 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306321 tempbl = 0xff;
6322 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
6323 tempah |= 0x80;
6324 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006325
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006326 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006327
Peter Huewe6896b942012-02-09 21:11:46 +01006328 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306329 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006330 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
6331 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306332 }
6333 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006334}
6335
Aaro Koskinen063b9c42011-03-08 22:16:13 +02006336static void XGI_CloseCRTC(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306337 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006338{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306339 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006340
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306341 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006342
Peter Huewea3d675c2012-02-09 21:11:47 +01006343 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306344 tempbx = 0x08A0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006345
6346}
6347
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306348void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
6349 struct vb_device_info *pVBInfo)
6350{
6351
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006352 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006353
6354}
6355
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306356void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
6357 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006358{
6359
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006360 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006361
6362}
6363
Bill Pemberton80adad82010-06-17 13:10:51 -04006364unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006365{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306366 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006367
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306368 if (pVBInfo->IF_DEF_LVDS == 1) {
6369 return 1;
6370 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006371 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306372 if ((flag == 1) || (flag == 2))
6373 return 1; /* 301b */
6374 else
6375 return 0;
6376 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006377}
6378
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006379unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
6380 unsigned short ModeNo, unsigned short ModeIdIndex,
6381 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006382{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006383 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
6384 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
6385 0x01, 0x01 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006386
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006387 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006388
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006389 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006390
Aaro Koskinen58839b02011-03-13 12:26:23 +02006391 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006392 index = index >> pVBInfo->SelectCRT2Rate;
6393 index &= 0x0F;
6394
6395 if (pVBInfo->LCDInfo & LCDNonExpanding)
6396 index = 0;
6397
6398 if (index > 0)
6399 index--;
6400
6401 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01006402 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006403 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe6896b942012-02-09 21:11:46 +01006404 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
6405 | VB_SIS301LV | VB_SIS302LV
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006406 | VB_XGI301C))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006407 /* 301b */
6408 temp = LCDARefreshIndex[
6409 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006410 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006411 temp = LCDRefreshIndex[
6412 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006413
6414 if (index > temp)
6415 index = temp;
6416 } else {
6417 index = 0;
6418 }
6419 }
6420 }
6421
6422 RefreshRateTableIndex = pVBInfo->EModeIDTable[ModeIdIndex].REFindex;
6423 ModeNo = pVBInfo->RefIndex[RefreshRateTableIndex].ModeID;
6424 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006425 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 800) &&
6426 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006427 index++;
6428 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006429 /* Alan 10/19/2007;
6430 * do the similar adjustment like XGISearchCRT1Rate() */
6431 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1024) &&
6432 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006433 index++;
6434 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006435 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1280) &&
6436 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006437 index++;
6438 }
6439 }
6440
6441 i = 0;
6442 do {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006443 if (pVBInfo->RefIndex[RefreshRateTableIndex + i].
6444 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006445 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006446 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i].
6447 Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01006448 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006449 if (temp < pVBInfo->ModeType)
6450 break;
6451 i++;
6452 index--;
6453
6454 } while (index != 0xFFFF);
6455 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
6456 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006457 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i - 1].
6458 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006459 if (temp & InterlaceMode)
6460 i++;
6461 }
6462 }
6463 i--;
6464 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
6465 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
6466 RefreshRateTableIndex, &i, pVBInfo);
6467 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02006468 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006469}
6470
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006471static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306472 struct xgi_hw_device_info *HwDeviceExtension,
6473 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006474{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006475 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006476
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006477 pVBInfo->SetFlag |= ProgrammingCRT2;
6478 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
6479 ModeIdIndex, pVBInfo);
6480 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
6481 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6482 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6483 HwDeviceExtension, pVBInfo);
6484 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6485 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006486}
6487
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02006488static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006489 struct xgi_hw_device_info *HwDeviceExtension,
6490 struct vb_device_info *pVBInfo)
6491{
6492 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
6493
6494 tempbx = pVBInfo->VBInfo;
6495 pVBInfo->SetFlag |= ProgrammingCRT2;
6496 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
6497 pVBInfo->SelectCRT2Rate = 4;
6498 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
6499 ModeIdIndex, pVBInfo);
6500 XGI_SaveCRT2Info(ModeNo, pVBInfo);
6501 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
6502 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6503 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
6504 RefreshRateTableIndex, pVBInfo);
6505 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
6506 RefreshRateTableIndex, pVBInfo);
6507 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
6508 RefreshRateTableIndex, pVBInfo);
6509 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6510 HwDeviceExtension, pVBInfo);
6511 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
6512 RefreshRateTableIndex, pVBInfo);
6513 XGI_SetTap4Regs(pVBInfo);
6514 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
6515 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6516 HwDeviceExtension, pVBInfo);
6517 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6518 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
6519 XGI_AutoThreshold(pVBInfo);
6520 return 1;
6521}
6522
6523void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
6524{
6525 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
6526 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
6527 0x05, 0x00 };
6528
6529 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
6530
6531 unsigned char CR17, CR63, SR31;
6532 unsigned short temp;
6533 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
6534
6535 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006536 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006537
6538 /* [2004/05/06] Vicent to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02006539 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02006540 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006541 pVBInfo->P3d4, 0x53) | 0x02));
6542
Aaro Koskinen58839b02011-03-13 12:26:23 +02006543 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
6544 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
6545 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006546
Aaro Koskinen8104e322011-03-13 12:26:22 +02006547 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
6548 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006549
Aaro Koskinen58839b02011-03-13 12:26:23 +02006550 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006551 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006552
Aaro Koskinen58839b02011-03-13 12:26:23 +02006553 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006554 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006555
Aaro Koskinen58839b02011-03-13 12:26:23 +02006556 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006557 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Aaro Koskinen58839b02011-03-13 12:26:23 +02006558 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006559 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006560
Aaro Koskinen8104e322011-03-13 12:26:22 +02006561 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006562
6563 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02006564 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006565
6566 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02006567 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006568 CRTCData[i]);
6569
6570 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02006571 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006572 CRTCData[i]);
6573
6574 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02006575 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006576 CRTCData[i]);
6577
Aaro Koskinen8104e322011-03-13 12:26:22 +02006578 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006579 & 0xE0));
6580
Aaro Koskinen8104e322011-03-13 12:26:22 +02006581 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
6582 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
6583 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006584
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006585 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006586
6587 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006588 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
6589 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
6590 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006591 }
6592
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006593 mdelay(1);
6594
6595 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006596 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006597
6598 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006599 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006600 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006601 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006602
6603 /* alan, avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006604 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006605
6606 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006607 outb(0, (pVBInfo->P3c8 + 1));
6608 outb(0, (pVBInfo->P3c8 + 1));
6609 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006610 }
6611
Aaro Koskinen8104e322011-03-13 12:26:22 +02006612 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
6613 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
6614 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006615
6616 /* [2004/05/11] Vicent */
Aaro Koskinen58839b02011-03-13 12:26:23 +02006617 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006618 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006619 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006620}
6621
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006622static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
6623 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006624 struct vb_device_info *pVBInfo)
6625{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02006626 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006627
Peter Huewe6896b942012-02-09 21:11:46 +01006628 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6629 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006630 if (!(pVBInfo->SetFlag & DisableChA)) {
6631 if (pVBInfo->SetFlag & EnableChA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006632 /* Power on */
6633 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006634 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006635 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6636 /* Power on */
Aaro Koskinen8104e322011-03-13 12:26:22 +02006637 xgifb_reg_set(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006638 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006639 }
6640 }
6641 }
6642
6643 if (!(pVBInfo->SetFlag & DisableChB)) {
6644 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
6645 & (SetCRT2ToLCD | SetCRT2ToTV
6646 | SetCRT2ToRAMDAC))) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006647 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006648 pVBInfo->P3c4, 0x32);
6649 tempah &= 0xDF;
6650 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006651 if (!(pVBInfo->VBInfo &
6652 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006653 tempah |= 0x20;
6654 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02006655 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006656 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006657
Aaro Koskinen58839b02011-03-13 12:26:23 +02006658 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006659 pVBInfo->Part1Port, 0x2E);
6660
6661 if (!(tempah & 0x80))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006662 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006663 0x2E, 0x80);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006664 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006665 }
6666 }
6667
6668 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
6669 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006670 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006671 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01006672 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006673 if (!XGI_DisableChISLCD(pVBInfo)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006674 if (XGI_EnableChISLCD(pVBInfo) ||
6675 (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01006676 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006677 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02006678 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006679 pVBInfo->Part4Port,
6680 0x2A,
6681 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006682 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006683 /* LVDS Driver power on */
6684 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006685 }
6686 }
6687
6688 tempah = 0x00;
6689
6690 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6691 tempah = 0xc0;
6692
6693 if (!(pVBInfo->VBInfo & SetSimuScanMode)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01006694 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006695 if (pVBInfo->VBInfo &
6696 SetCRT2ToDualEdge) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006697 tempah = tempah & 0x40;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006698 if (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01006699 XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006700 tempah = tempah ^ 0xC0;
6701
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006702 if (pVBInfo->SetFlag &
6703 DisableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006704 tempah &= 0xBF;
6705
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006706 if (pVBInfo->SetFlag &
6707 DisableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006708 tempah &= 0x7F;
6709
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006710 if (pVBInfo->SetFlag &
6711 EnableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006712 tempah |= 0x40;
6713
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006714 if (pVBInfo->SetFlag &
6715 EnableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006716 tempah |= 0x80;
6717 }
6718 }
6719 }
6720 }
6721
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006722 /* EnablePart4_1F */
6723 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006724
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006725 if (!(pVBInfo->SetFlag & DisableChA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006726 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006727 XGI_DisableGatingCRT(HwDeviceExtension,
6728 pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006729 XGI_DisplayOn(xgifb_info, HwDeviceExtension,
6730 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006731 }
6732 }
6733 } /* 301 */
6734 else { /* LVDS */
6735 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01006736 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006737 /* enable CRT2 */
6738 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006739
Aaro Koskinen58839b02011-03-13 12:26:23 +02006740 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006741 0x2E);
6742 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006743 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006744
Aaro Koskinendc505562011-03-13 12:26:26 +02006745 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006746 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006747 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006748}
6749
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006750static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
6751 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006752 unsigned short ModeNo, unsigned short ModeIdIndex,
6753 struct vb_device_info *pVBInfo)
6754{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006755 unsigned short StandTableIndex, RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006756
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006757 StandTableIndex = XGI_GetModePtr(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006758 XGI_SetSeqRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
Aaro Koskineneb9aef12011-11-27 23:03:15 +02006759 outb(pVBInfo->StandTable[StandTableIndex].MISC, pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006760 XGI_SetCRTCRegs(HwDeviceExtension, StandTableIndex, pVBInfo);
6761 XGI_SetATTRegs(ModeNo, StandTableIndex, ModeIdIndex, pVBInfo);
6762 XGI_SetGRCRegs(StandTableIndex, pVBInfo);
6763 XGI_ClearExt1Regs(pVBInfo);
6764
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006765 if (HwDeviceExtension->jChipType == XG27) {
6766 if (pVBInfo->IF_DEF_LVDS == 0)
6767 XGI_SetDefaultVCLK(pVBInfo);
6768 }
6769
6770 temp = ~ProgrammingCRT2;
6771 pVBInfo->SetFlag &= temp;
6772 pVBInfo->SelectCRT2Rate = 0;
6773
Peter Huewe6896b942012-02-09 21:11:46 +01006774 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6775 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01006776 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006777 | SetInSlaveMode)) {
6778 pVBInfo->SetFlag |= ProgrammingCRT2;
6779 }
6780 }
6781
6782 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
6783 ModeIdIndex, pVBInfo);
6784 if (RefreshRateTableIndex != 0xFFFF) {
6785 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
6786 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6787 pVBInfo, HwDeviceExtension);
6788 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
6789 RefreshRateTableIndex, pVBInfo);
6790 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6791 HwDeviceExtension, pVBInfo);
6792 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
6793 RefreshRateTableIndex, pVBInfo);
6794 }
6795
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006796 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006797 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006798 if (temp & 0xA0) {
6799
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006800 if (HwDeviceExtension->jChipType == XG27)
6801 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
6802 RefreshRateTableIndex, pVBInfo);
6803 else
6804 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
6805 RefreshRateTableIndex, pVBInfo);
6806
6807 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
6808 RefreshRateTableIndex);
6809
Aaro Koskinen105d8d02011-08-31 21:46:00 +03006810 xgifb_set_lcd(HwDeviceExtension->jChipType,
6811 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006812
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006813 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006814 xgifb_set_lvds(xgifb_info,
6815 HwDeviceExtension->jChipType,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006816 ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006817 }
6818 }
6819
6820 pVBInfo->SetFlag &= (~ProgrammingCRT2);
6821 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
6822 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
6823 RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006824 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006825}
6826
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006827unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
6828 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006829 unsigned short ModeNo)
6830{
6831 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006832 struct vb_device_info VBINF;
6833 struct vb_device_info *pVBInfo = &VBINF;
Dmitry Eremin-Solenikov9a801f22012-03-19 21:50:13 +04006834 pVBInfo->BaseAddr = xgifb_info->vga_base;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006835 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006836 pVBInfo->IF_DEF_LCDA = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006837
6838 if (HwDeviceExtension->jChipType >= XG20) { /* kuku 2004/06/25 */
6839 pVBInfo->IF_DEF_YPbPr = 0;
6840 pVBInfo->IF_DEF_HiVision = 0;
6841 pVBInfo->IF_DEF_CRT2Monitor = 0;
6842 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006843 } else {
6844 pVBInfo->IF_DEF_YPbPr = 1;
6845 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02006846 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006847 }
6848
6849 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
6850 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
6851 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
6852 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
6853 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
6854 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
6855 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
6856 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
6857 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
6858 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
6859 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
6860 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
6861 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
Peter Huewe6896b942012-02-09 21:11:46 +01006862 pVBInfo->Part1Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_04;
6863 pVBInfo->Part2Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_10;
6864 pVBInfo->Part3Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_12;
6865 pVBInfo->Part4Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14;
6866 pVBInfo->Part5Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14 + 2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006867
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006868 /* for x86 Linux, XG21 LVDS */
6869 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006870 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006871 pVBInfo->IF_DEF_LVDS = 1;
6872 }
6873 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006874 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
6875 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006876 pVBInfo->IF_DEF_LVDS = 1;
6877 }
6878 }
6879
6880 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 */
6881 XGI_GetVBType(pVBInfo);
6882
6883 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02006884 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006885 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006886 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006887
6888 if (HwDeviceExtension->jChipType < XG20) /* kuku 2004/06/25 1.Openkey */
6889 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
6890
6891 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
6892
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006893 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
6894 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
6895 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
6896 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006897 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006898
Peter Huewea3d675c2012-02-09 21:11:47 +01006899 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006900 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006901 ModeIdIndex, pVBInfo);
6902
Peter Huewea3d675c2012-02-09 21:11:47 +01006903 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006904 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6905 HwDeviceExtension, pVBInfo);
6906 }
6907 } else {
Peter Huewe6896b942012-02-09 21:11:46 +01006908 if (!(pVBInfo->VBInfo & SwitchCRT2)) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006909 XGI_SetCRT1Group(xgifb_info,
6910 HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006911 ModeIdIndex, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01006912 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006913 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6914 HwDeviceExtension,
6915 pVBInfo);
6916 }
6917 }
6918 }
6919
Peter Huewe6896b942012-02-09 21:11:46 +01006920 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006921 switch (HwDeviceExtension->ujVBChipID) {
6922 case VB_CHIP_301:
6923 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6924 pVBInfo); /*add for CRT2 */
6925 break;
6926
6927 case VB_CHIP_302:
6928 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6929 pVBInfo); /*add for CRT2 */
6930 break;
6931
6932 default:
6933 break;
6934 }
6935 }
6936
6937 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
6938 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
6939 XGI_CloseCRTC(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006940 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006941 } /* !XG20 */
6942 else {
6943 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006944 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006945 ModeIdIndex,
6946 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006947 return 0;
6948
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006949 pVBInfo->ModeType = pVBInfo->EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01006950 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006951
6952 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03006953 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006954
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006955 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006956
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006957 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
6958 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006959
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006960 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006961 }
6962
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006963 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
6964
6965 if (HwDeviceExtension->jChipType < XG20) { /* kuku 2004/06/25 */
6966 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
6967 }
6968
6969 return 1;
6970}