blob: 3ba3c48a56963a42dc60e7f59b6c244d34cbac7b [file] [log] [blame]
Aaro Koskinend80aaa02011-02-17 23:29:14 +02001#include <linux/delay.h>
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002#include "XGIfb.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004#include "vb_def.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005#include "vb_util.h"
6#include "vb_table.h"
Miguel Gómeze0541022012-06-18 13:12:05 +02007#include "vb_setmode.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02008
9#define IndexMask 0xff
Peter Huewe95072592012-06-14 00:21:48 +020010#define TVCLKBASE_315_25 (TVCLKBASE_315 + 25)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020011
Aaro Koskinen624554d2011-10-11 21:47:35 +030012static const unsigned short XGINew_VGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040013 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
14 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
15 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
16 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
17 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
18 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
19 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
20 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
21 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
22 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020023
Bill Pemberton80adad82010-06-17 13:10:51 -040024void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020025{
Aaro Koskinenfb60d0c2012-04-07 01:14:04 +030026 pVBInfo->StandTable = (struct SiS_StandTable_S *) &XGI330_StandTable;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053027 pVBInfo->EModeIDTable = (struct XGI_ExtStruct *) XGI330_EModeIDTable;
28 pVBInfo->RefIndex = (struct XGI_Ext2Struct *) XGI330_RefIndex;
29 pVBInfo->XGINEWUB_CRT1Table
30 = (struct XGI_CRT1TableStruct *) XGI_CRT1Table;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020031
Peter Huewefc39dcb2012-01-15 19:22:12 +010032 pVBInfo->MCLKData = (struct SiS_MCLKData *) XGI340New_MCLKData;
Aaro Koskinen06587332011-03-13 12:26:10 +020033 pVBInfo->ECLKData = (struct XGI_ECLKDataStruct *) XGI340_ECLKData;
Peter Huewefc39dcb2012-01-15 19:22:12 +010034 pVBInfo->VCLKData = (struct SiS_VCLKData *) XGI_VCLKData;
35 pVBInfo->VBVCLKData = (struct SiS_VBVCLKData *) XGI_VBVCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053036 pVBInfo->ScreenOffset = XGI330_ScreenOffset;
Peter Huewefc39dcb2012-01-15 19:22:12 +010037 pVBInfo->StResInfo = (struct SiS_StResInfo_S *) XGI330_StResInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053038 pVBInfo->ModeResInfo
Peter Huewefc39dcb2012-01-15 19:22:12 +010039 = (struct SiS_ModeResInfo_S *) XGI330_ModeResInfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020040
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053041 pVBInfo->LCDResInfo = 0;
42 pVBInfo->LCDTypeInfo = 0;
43 pVBInfo->LCDInfo = 0;
44 pVBInfo->VBInfo = 0;
45 pVBInfo->TVInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020046
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053047 pVBInfo->SR15 = XGI340_SR13;
48 pVBInfo->CR40 = XGI340_cr41;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053049 pVBInfo->CR6B = XGI340_CR6B;
50 pVBInfo->CR6E = XGI340_CR6E;
51 pVBInfo->CR6F = XGI340_CR6F;
52 pVBInfo->CR89 = XGI340_CR89;
53 pVBInfo->AGPReg = XGI340_AGPReg;
54 pVBInfo->SR16 = XGI340_SR16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020055
Peter Huewe6d12dae2012-06-14 00:21:52 +020056 pVBInfo->SR21 = 0xa3;
57 pVBInfo->SR22 = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020058
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053059 pVBInfo->NTSCTiming = XGI330_NTSCTiming;
60 pVBInfo->PALTiming = XGI330_PALTiming;
61 pVBInfo->HiTVExtTiming = XGI330_HiTVExtTiming;
62 pVBInfo->HiTVSt1Timing = XGI330_HiTVSt1Timing;
63 pVBInfo->HiTVSt2Timing = XGI330_HiTVSt2Timing;
64 pVBInfo->HiTVTextTiming = XGI330_HiTVTextTiming;
65 pVBInfo->YPbPr750pTiming = XGI330_YPbPr750pTiming;
66 pVBInfo->YPbPr525pTiming = XGI330_YPbPr525pTiming;
67 pVBInfo->YPbPr525iTiming = XGI330_YPbPr525iTiming;
68 pVBInfo->HiTVGroup3Data = XGI330_HiTVGroup3Data;
69 pVBInfo->HiTVGroup3Simu = XGI330_HiTVGroup3Simu;
70 pVBInfo->HiTVGroup3Text = XGI330_HiTVGroup3Text;
71 pVBInfo->Ren525pGroup3 = XGI330_Ren525pGroup3;
72 pVBInfo->Ren750pGroup3 = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020073
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053074 pVBInfo->TimingH = (struct XGI_TimingHStruct *) XGI_TimingH;
75 pVBInfo->TimingV = (struct XGI_TimingVStruct *) XGI_TimingV;
76 pVBInfo->UpdateCRT1 = (struct XGI_XG21CRT1Struct *) XGI_UpdateCRT1Table;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020077
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053078 /* 310 customization related */
Peter Huewe6896b942012-02-09 21:11:46 +010079 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053080 pVBInfo->LCDCapList = XGI_LCDDLCapList;
81 else
82 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020083
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053084 if (ChipType >= XG20)
Peter Huewe6d12dae2012-06-14 00:21:52 +020085 pVBInfo->XGINew_CR97 = 0x10;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020086
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053087 if (ChipType == XG27) {
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040088 unsigned char temp;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053089 pVBInfo->MCLKData
Peter Huewefc39dcb2012-01-15 19:22:12 +010090 = (struct SiS_MCLKData *) XGI27New_MCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053091 pVBInfo->CR40 = XGI27_cr41;
Peter Huewe6d12dae2012-06-14 00:21:52 +020092 pVBInfo->XGINew_CR97 = 0xc1;
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040093 pVBInfo->SR15 = XG27_SR13;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020094
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040095 /*Z11m DDR*/
96 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
97 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
98 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
Peter Huewe6d12dae2012-06-14 00:21:52 +020099 pVBInfo->XGINew_CR97 = 0x80;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530100 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200101
102}
103
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800104static void XGI_SetSeqRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800105 unsigned short ModeIdIndex,
106 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200107{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530108 unsigned char tempah, SRdata;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530109 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200110
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300111 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200112
Aaro Koskinen8104e322011-03-13 12:26:22 +0200113 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
Aaro Koskinenfb60d0c2012-04-07 01:14:04 +0300114 tempah = pVBInfo->StandTable->SR[0];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200115
Peter Huewea3d675c2012-02-09 21:11:47 +0100116 i = XGI_SetCRT2ToLCDA;
117 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530118 tempah |= 0x01;
119 } else {
120 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
121 if (pVBInfo->VBInfo & SetInSlaveMode)
122 tempah |= 0x01;
123 }
124 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200125
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530126 tempah |= 0x20; /* screen off */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200127 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200128
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530129 for (i = 02; i <= 04; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800130 /* Get SR2,3,4 from file */
Aaro Koskinenfb60d0c2012-04-07 01:14:04 +0300131 SRdata = pVBInfo->StandTable->SR[i - 1];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200132 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530133 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200134}
135
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200136static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800137 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200138{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530139 unsigned char CRTCdata;
140 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200141
Aaro Koskinen58839b02011-03-13 12:26:23 +0200142 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530143 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200144 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200145
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530146 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800147 /* Get CRTC from file */
Aaro Koskinenfb60d0c2012-04-07 01:14:04 +0300148 CRTCdata = pVBInfo->StandTable->CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200149 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530150 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200151}
152
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800153static void XGI_SetATTRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800154 unsigned short ModeIdIndex,
155 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200156{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530157 unsigned char ARdata;
158 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200159
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300160 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200161
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530162 for (i = 0; i <= 0x13; i++) {
Aaro Koskinenfb60d0c2012-04-07 01:14:04 +0300163 ARdata = pVBInfo->StandTable->ATTR[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530164 if (modeflag & Charx8Dot) { /* ifndef Dot9 */
165 if (i == 0x13) {
Peter Huewea3d675c2012-02-09 21:11:47 +0100166 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530167 ARdata = 0;
168 } else {
169 if (pVBInfo->VBInfo & (SetCRT2ToTV
170 | SetCRT2ToLCD)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800171 if (pVBInfo->VBInfo &
172 SetInSlaveMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530173 ARdata = 0;
174 }
175 }
176 }
177 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200178
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200179 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200180 outb(i, pVBInfo->P3c0); /* set index */
181 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530182 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200183
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200184 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200185 outb(0x14, pVBInfo->P3c0); /* set index */
186 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200187 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200188 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200189}
190
Aaro Koskinena1579612012-04-07 01:14:05 +0300191static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200192{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530193 unsigned char GRdata;
194 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200195
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530196 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800197 /* Get GR from file */
Aaro Koskinenfb60d0c2012-04-07 01:14:04 +0300198 GRdata = pVBInfo->StandTable->GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200199 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530200 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200201
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530202 if (pVBInfo->ModeType > ModeVGA) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200203 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530204 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200205 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530206 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200207}
208
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200209static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200210{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530211 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200212
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530213 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200214 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200215}
216
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200217static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200218{
219
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200220 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200221 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[0].SR2B);
222 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200223
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200224 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200225 xgifb_reg_set(pVBInfo->P3c4, 0x2B, pVBInfo->VCLKData[1].SR2B);
226 xgifb_reg_set(pVBInfo->P3c4, 0x2C, pVBInfo->VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200227
Aaro Koskinendc505562011-03-13 12:26:26 +0200228 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530229 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200230}
231
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200232static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530233 unsigned short ModeIdIndex,
234 unsigned short RefreshRateTableIndex, unsigned short *i,
235 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200236{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530237 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200238
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300239 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530240 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
241 tempbx = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID;
242 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200243
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530244 if (pVBInfo->IF_DEF_LVDS == 0) {
245 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
246 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200247
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530248 if (pVBInfo->VBType & VB_XGI301C)
249 tempax |= SupportCRT2in301C;
250 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200251
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800252 /* 301b */
Peter Huewea3d675c2012-02-09 21:11:47 +0100253 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530254 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200255
Peter Huewe255aabd2012-02-09 21:11:44 +0100256 if (pVBInfo->LCDResInfo != Panel_1280x1024) {
257 if (pVBInfo->LCDResInfo != Panel_1280x960) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800258 if (pVBInfo->LCDInfo &
259 LCDNonExpanding) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530260 if (resinfo >= 9) {
261 tempax = 0;
262 return 0;
263 }
264 }
265 }
266 }
267 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200268
Peter Huewe599801f2012-02-09 21:11:45 +0100269 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
Peter Huewe6896b942012-02-09 21:11:46 +0100270 if ((pVBInfo->VBType & VB_SIS301LV) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800271 (pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
Peter Huewe6896b942012-02-09 21:11:46 +0100272 tempax |= SupportYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530273 if (pVBInfo->VBInfo & SetInSlaveMode) {
274 if (resinfo == 4)
275 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200276
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530277 if (resinfo == 3)
278 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200279
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530280 if (resinfo > 7)
281 return 0;
282 }
283 } else {
Peter Huewe6896b942012-02-09 21:11:46 +0100284 tempax |= SupportHiVision;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530285 if (pVBInfo->VBInfo & SetInSlaveMode) {
286 if (resinfo == 4)
287 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200288
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530289 if (resinfo == 3) {
290 if (pVBInfo->SetFlag
291 & TVSimuMode)
292 return 0;
293 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200294
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530295 if (resinfo > 7)
296 return 0;
297 }
298 }
299 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800300 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
301 SetCRT2ToSVIDEO |
302 SetCRT2ToSCART |
Peter Huewe599801f2012-02-09 21:11:45 +0100303 SetCRT2ToYPbPr525750 |
304 SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530305 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200306
Peter Huewe6896b942012-02-09 21:11:46 +0100307 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
308 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530309 | VB_XGI301C)) {
310 tempax |= SupportTV1024;
311 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200312
Peter Huewe599801f2012-02-09 21:11:45 +0100313 if (!(pVBInfo->VBInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530314 if (modeflag & NoSupportSimuTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800315 if (pVBInfo->VBInfo &
316 SetInSlaveMode) {
317 if (!(pVBInfo->VBInfo &
318 SetNotSimuMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530319 return 0;
320 }
321 }
322 }
323 }
324 }
325 }
326 } else { /* for LVDS */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530327 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
328 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200329
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530330 if (resinfo > 0x08)
331 return 0; /* 1024x768 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200332
Peter Huewe255aabd2012-02-09 21:11:44 +0100333 if (pVBInfo->LCDResInfo < Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530334 if (resinfo > 0x07)
335 return 0; /* 800x600 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200336
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530337 if (resinfo == 0x04)
338 return 0; /* 512x384 */
339 }
340 }
341 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200342
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800343 for (; pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
344 tempbx; (*i)--) {
345 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
346 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530347 if (infoflag & tempax)
348 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200349
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530350 if ((*i) == 0)
351 break;
352 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200353
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530354 for ((*i) = 0;; (*i)++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800355 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].
356 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530357 if (pVBInfo->RefIndex[RefreshRateTableIndex + (*i)].ModeID
358 != tempbx) {
359 return 0;
360 }
361
362 if (infoflag & tempax)
363 return 1;
364 }
365 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200366}
367
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200368static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530369 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200370{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530371 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200372
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800373 /* di+0x00 */
374 sync = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530375 sync &= 0xC0;
376 temp = 0x2F;
377 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200378 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200379}
380
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200381static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530382 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200383{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530384 unsigned char data, data1, pushax;
385 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200386
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800387 /* unlock cr0-7 */
388 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530389 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200390 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200391
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530392 data = pVBInfo->TimingH[0].data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200393 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200394
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530395 for (i = 0x01; i <= 0x04; i++) {
396 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200397 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530398 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200399
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530400 for (i = 0x05; i <= 0x06; i++) {
401 data = pVBInfo->TimingH[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200402 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530403 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200404
Aaro Koskinen58839b02011-03-13 12:26:23 +0200405 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530406 j &= 0x1F;
407 data = pVBInfo->TimingH[0].data[7];
408 data &= 0xE0;
409 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200410 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200411
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530412 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200413 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530414 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200415 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200416 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530417 data1 = data;
418 data1 &= 0xE0;
419 data &= 0x1F;
420 if (data == 0) {
421 pushax = data;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200422 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530423 0x0c);
424 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200425 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530426 data = pushax;
427 }
428 data = data - 1;
429 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200430 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200431 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530432 data = data >> 5;
433 data = data + 3;
434 if (data > 7)
435 data = data - 7;
436 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200437 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530438 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200439}
440
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800441static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
442 unsigned short ModeNo,
443 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200444{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530445 unsigned char data;
446 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200447
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530448 for (i = 0x00; i <= 0x01; i++) {
449 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200450 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530451 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200452
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530453 for (i = 0x02; i <= 0x03; i++) {
454 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200455 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530456 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200457
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530458 for (i = 0x04; i <= 0x05; i++) {
459 data = pVBInfo->TimingV[0].data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200460 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530461 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200462
Aaro Koskinen58839b02011-03-13 12:26:23 +0200463 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530464 j &= 0xC0;
465 data = pVBInfo->TimingV[0].data[6];
466 data &= 0x3F;
467 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200468 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200469
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530470 data = pVBInfo->TimingV[0].data[6];
471 data &= 0x80;
472 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200473
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300474 i = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530475 i &= DoubleScanMode;
476 if (i)
477 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200478
Aaro Koskinen58839b02011-03-13 12:26:23 +0200479 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530480 j &= 0x5F;
481 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200482 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200483}
484
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200485static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
486 unsigned short RefreshRateTableIndex,
487 struct vb_device_info *pVBInfo,
488 struct xgi_hw_device_info *HwDeviceExtension)
489{
490 unsigned char index, data;
491 unsigned short i;
492
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800493 /* Get index */
494 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200495 index = index & IndexMask;
496
Aaro Koskinen58839b02011-03-13 12:26:23 +0200497 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200498 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200499 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200500
501 for (i = 0; i < 8; i++)
502 pVBInfo->TimingH[0].data[i]
503 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i];
504
505 for (i = 0; i < 7; i++)
506 pVBInfo->TimingV[0].data[i]
507 = pVBInfo->XGINEWUB_CRT1Table[index].CR[i + 8];
508
509 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
510
511 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
512
513 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200514 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200515}
516
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200517/* --------------------------------------------------------------------- */
518/* Function : XGI_SetXG21CRTC */
519/* Input : Stand or enhance CRTC table */
520/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
521/* Description : Set LCD timing */
522/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200523static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530524 unsigned short RefreshRateTableIndex,
525 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200526{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300527 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530528 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200529
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300530 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
531 /* Tempax: CR4 HRS */
532 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
533 Tempcx = Tempax; /* Tempcx: HRS */
534 /* SR2E[7:0]->HRS */
535 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200536
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300537 Tempdx = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SRB */
538 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
539 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
540 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
541 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800542
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300543 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
544 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200545
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300546 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
547 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
548 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
549 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200550
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300551 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
552 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200553
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300554 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
555 if (Tempax < Tempcx) /* HRE < HRS */
556 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200557
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300558 Temp2 &= 0xFF;
559 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
560 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
561 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
562 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
563 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
564 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
565 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200566
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300567 /* CR10 VRS */
568 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
569 Tempbx = Tempax; /* Tempbx: VRS */
570 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
571 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
572 /* CR7[2][7] VRE */
573 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
574 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
575 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
576 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
577 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
578 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200579
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300580 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
581 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
582 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
583 Tempax &= 0x80;
584 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
585 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
586 /* Tempax: SRA */
587 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
588 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
589 Temp2 = Tempax;
590 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
591 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200592
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300593 /* Tempax: CR11 VRE */
594 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
595 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
596 /* Tempbx: SRA */
597 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
598 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
599 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
600 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
601 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
602 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200603
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300604 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
605 if (Tempax < Temp3) /* VRE < VRS */
606 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200607
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300608 Temp2 &= 0xFF;
609 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
610 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
611 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
612 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
613 Tempbx = (unsigned char) Temp1;
614 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
615 Tempax &= 0x7F;
616 /* SR3F D[7:2]->VRE D[1:0]->VRS */
617 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200618}
619
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800620static void XGI_SetXG27CRTC(unsigned short ModeNo,
621 unsigned short ModeIdIndex,
622 unsigned short RefreshRateTableIndex,
623 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200624{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300625 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200626
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300627 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
628 /* Tempax: CR4 HRS */
629 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
630 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
631 /* SR2E[7:0]->HRS */
632 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200633
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300634 /* SR0B */
635 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5];
636 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
637 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200638
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300639 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[4]; /* CR5 HRE */
640 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
641 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200642
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300643 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[6]; /* SRC */
644 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
645 Tempax <<= 3; /* Tempax[5]: HRE[5] */
646 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200647
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300648 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
649 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200650
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300651 /* Tempax: CR4 HRS */
652 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[3];
653 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
654 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
655 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200656
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300657 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[5]; /* SR0B */
658 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
659 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
660 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
661 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
662 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
663 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200664
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300665 /* CR10 VRS */
666 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[10];
667 /* SR34[7:0]->VRS[7:0] */
668 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200669
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300670 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
671 /* CR7[7][2] VRS[9][8] */
672 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[9];
673 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
674 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
675 Tempax >>= 2; /* Tempax[0]: VRS[8] */
676 /* SR35[0]: VRS[8] */
677 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
678 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
679 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
680 /* Tempax: SR0A */
681 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
682 Tempax &= 0x08; /* SR0A[3] VRS[10] */
683 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200684
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300685 /* Tempax: CR11 VRE */
686 Tempax = pVBInfo->XGINEWUB_CRT1Table[index].CR[11];
687 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
688 /* Tempbx: SR0A */
689 Tempbx = pVBInfo->XGINEWUB_CRT1Table[index].CR[14];
690 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
691 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
692 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
693 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
694 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
695 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200696
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300697 if (Tempbx <= Tempcx) /* VRE <= VRS */
698 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200699
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300700 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
701 Tempax = (Tempbx << 2) & 0xFF;
702 /* SR3F[7:2]:VRE[5:0] */
703 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
704 Tempax = Tempcx >> 8;
705 /* SR35[2:0]:VRS[10:8] */
706 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200707}
708
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200709static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
710{
711 unsigned char temp;
712
713 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
714 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
715 temp = (temp & 3) << 6;
716 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
717 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
718 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
719 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
720
721}
722
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300723static void xgifb_set_lcd(int chip_id,
724 struct vb_device_info *pVBInfo,
725 unsigned short RefreshRateTableIndex,
726 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200727{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300728 unsigned short Data, Temp;
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400729 unsigned short XGI_P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200730
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530731 XGI_P3cc = pVBInfo->P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200732
Aaro Koskinen8104e322011-03-13 12:26:22 +0200733 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
734 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
735 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
736 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300737
738 if (chip_id == XG27) {
739 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
740 if ((Temp & 0x03) == 0) { /* dual 12 */
741 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
742 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
743 }
744 }
745
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300746 if (chip_id == XG27) {
747 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530748 } else {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300749 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
750 if (Temp & 0x01) {
751 /* 18 bits FP */
752 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
753 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
754 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530755 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200756
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200757 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200758
Aaro Koskinendc505562011-03-13 12:26:26 +0200759 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
760 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200761
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300762 Data = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
763 if (Data & 0x4000)
764 /* Hsync polarity */
765 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
766 if (Data & 0x8000)
767 /* Vsync polarity */
768 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200769}
770
771/* --------------------------------------------------------------------- */
772/* Function : XGI_UpdateXG21CRTC */
773/* Input : */
774/* Output : CRT1 CRTC */
775/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
776/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800777static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
778 struct vb_device_info *pVBInfo,
779 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200780{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300781 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200782
Aaro Koskinendc505562011-03-13 12:26:26 +0200783 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300784 if (ModeNo == 0x2E &&
785 (pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
786 RES640x480x60))
787 index = 12;
788 else if (ModeNo == 0x2E && (pVBInfo->RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800789 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300790 index = 13;
791 else if (ModeNo == 0x2F)
792 index = 14;
793 else if (ModeNo == 0x50)
794 index = 15;
795 else if (ModeNo == 0x59)
796 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200797
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530798 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200799 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530800 pVBInfo->UpdateCRT1[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200801 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530802 pVBInfo->UpdateCRT1[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200803 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530804 pVBInfo->UpdateCRT1[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200805 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530806 pVBInfo->UpdateCRT1[index].CR16);
807 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200808}
809
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200810static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530811 unsigned short ModeNo, unsigned short ModeIdIndex,
812 unsigned short RefreshRateTableIndex,
813 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200814{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400815 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200816
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530817 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200818
Aaro Koskinen6c0965f2012-04-07 01:14:11 +0300819 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200820
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300821 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
822 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
823 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200824
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530825 if (modeflag & HalfDCLK)
826 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200827
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300828 if (modeflag & HalfDCLK)
829 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200830
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300831 temp = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200832
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300833 if (temp & InterlaceMode)
834 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200835
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300836 if (modeflag & DoubleScanMode)
837 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200838
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530839 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200840
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530841 tempax /= tempcx;
842 tempax -= 1;
843 tempbx -= 1;
844 tempcx = tempax;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200845 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
846 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530847 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200848 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
849 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200850 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530851 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200852 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530853 tempax = 0;
854 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200855
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530856 if (tempbx & 0x01)
857 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200858
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530859 if (tempbx & 0x02)
860 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200861
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200862 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200863 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530864 data &= 0xFF;
865 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200866
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530867 if (tempbx & 0x04)
868 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200869
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200870 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200871 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200872}
873
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800874static void XGI_SetCRT1Offset(unsigned short ModeNo,
875 unsigned short ModeIdIndex,
876 unsigned short RefreshRateTableIndex,
877 struct xgi_hw_device_info *HwDeviceExtension,
878 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200879{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530880 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200881
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530882 /* GetOffset */
883 temp = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
884 temp = temp >> 8;
885 temp = pVBInfo->ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200886
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530887 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
888 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200889
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530890 if (temp2)
891 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200892
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530893 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200894
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530895 switch (temp2) {
896 case 0:
897 temp2 = 1;
898 break;
899 case 1:
900 temp2 = 2;
901 break;
902 case 2:
903 temp2 = 4;
904 break;
905 case 3:
906 temp2 = 4;
907 break;
908 case 4:
909 temp2 = 6;
910 break;
911 case 5:
912 temp2 = 8;
913 break;
914 default:
915 break;
916 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200917
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530918 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
919 temp = temp * temp2 + temp2 / 2;
920 else
921 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200922
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530923 /* SetOffset */
924 DisplayUnit = temp;
925 temp2 = temp;
926 temp = temp >> 8; /* ah */
927 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200928 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530929 i &= 0xF0;
930 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200931 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200932
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530933 temp = (unsigned char) temp2;
934 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200935 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200936
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530937 /* SetDisplayUnit */
938 temp2 = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
939 temp2 &= InterlaceMode;
940 if (temp2)
941 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200942
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530943 DisplayUnit = DisplayUnit << 5;
944 ah = (DisplayUnit & 0xff00) >> 8;
945 al = DisplayUnit & 0x00ff;
946 if (al == 0)
947 ah += 1;
948 else
949 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200950
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530951 if (HwDeviceExtension->jChipType >= XG20)
952 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
953 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200954
Aaro Koskinen8104e322011-03-13 12:26:22 +0200955 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200956}
957
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200958static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
959 unsigned short ModeIdIndex,
960 unsigned short RefreshRateTableIndex,
961 struct xgi_hw_device_info *HwDeviceExtension,
962 struct vb_device_info *pVBInfo)
963{
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200964 unsigned short CRT2Index, VCLKIndex;
965 unsigned short modeflag, resinfo;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200966
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300967 /* si+Ext_ResInfo */
968 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
969 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
970 CRT2Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200971
972 if (pVBInfo->IF_DEF_LVDS == 0) {
973 CRT2Index = CRT2Index >> 6; /* for LCD */
Peter Huewea3d675c2012-02-09 21:11:47 +0100974 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
Peter Huewe255aabd2012-02-09 21:11:44 +0100975 if (pVBInfo->LCDResInfo != Panel_1024x768)
Peter Huewef477d3e2012-06-14 00:21:47 +0200976 VCLKIndex = VCLK108_2_315 + 5; /* LCDXlat2VCLK */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200977 else
Peter Huewef477d3e2012-06-14 00:21:47 +0200978 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
Peter Huewe599801f2012-02-09 21:11:45 +0100979 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200980 if (pVBInfo->SetFlag & RPLLDIV2XO) {
Peter Huewe95072592012-06-14 00:21:48 +0200981 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200982 } else {
Peter Huewe95072592012-06-14 00:21:48 +0200983 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200984 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200985
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200986 if (pVBInfo->SetFlag & TVSimuMode) {
987 if (modeflag & Charx8Dot) {
Peter Huewe95072592012-06-14 00:21:48 +0200988 VCLKIndex = TVCLKBASE_315_25 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200989 } else {
Peter Huewe95072592012-06-14 00:21:48 +0200990 VCLKIndex = TVCLKBASE_315_25 + HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200991 }
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200992 }
993
994 /* 301lv */
Peter Huewe6896b942012-02-09 21:11:46 +0100995 if ((pVBInfo->VBType & VB_SIS301LV) &&
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200996 !(pVBInfo->VBExtInfo == VB_YPbPr1080i)) {
Peter Huewe6896b942012-02-09 21:11:46 +0100997 if (pVBInfo->VBExtInfo == YPbPr750p)
Peter Huewea3d675c2012-02-09 21:11:47 +0100998 VCLKIndex = XGI_YPbPr750pVCLK;
Peter Huewe6896b942012-02-09 21:11:46 +0100999 else if (pVBInfo->VBExtInfo == YPbPr525p)
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001000 VCLKIndex = YPbPr525pVCLK;
1001 else if (pVBInfo->SetFlag & RPLLDIV2XO)
1002 VCLKIndex = YPbPr525iVCLK_2;
1003 else
1004 VCLKIndex = YPbPr525iVCLK;
1005 }
1006 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
1007 if (pVBInfo->SetFlag & RPLLDIV2XO) {
Peter Huewe95072592012-06-14 00:21:48 +02001008 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001009 } else {
Peter Huewe95072592012-06-14 00:21:48 +02001010 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +02001011 }
1012 } else { /* for CRT2 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001013 /* di+Ext_CRTVCLK */
1014 VCLKIndex = pVBInfo->RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001015 Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001016 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001017 }
1018 } else { /* LVDS */
Peter Huewe255aabd2012-02-09 21:11:44 +01001019 if ((pVBInfo->LCDResInfo == Panel_800x600) ||
1020 (pVBInfo->LCDResInfo == Panel_320x480))
Peter Huewef477d3e2012-06-14 00:21:47 +02001021 VCLKIndex = VCLK40; /* LVDSXlat1VCLK */
Aaro Koskinen4c14bfd2011-08-31 21:45:57 +03001022 else
Peter Huewe95072592012-06-14 00:21:48 +02001023 VCLKIndex = VCLK65_315 + 2; /* LVDSXlat2VCLK, LVDSXlat3VCLK */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001024 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001025
1026 return VCLKIndex;
1027}
1028
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001029static void XGI_SetCRT1VCLK(unsigned short ModeNo,
1030 unsigned short ModeIdIndex,
1031 struct xgi_hw_device_info *HwDeviceExtension,
1032 unsigned short RefreshRateTableIndex,
1033 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001034{
Bill Pemberton108afbf2010-06-17 13:10:47 -04001035 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301036 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001037
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301038 if (pVBInfo->IF_DEF_LVDS == 1) {
1039 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001040 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001041 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1042 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301043 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001044 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301045 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001046 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Peter Huewe6896b942012-02-09 21:11:46 +01001047 } else if ((pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1048 | VB_SIS302LV | VB_XGI301C)) && (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01001049 & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301050 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
1051 RefreshRateTableIndex, HwDeviceExtension,
1052 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001053 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001054 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301055 data = pVBInfo->VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001056 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301057 data = pVBInfo->VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001058 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
1059 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301060 } else {
1061 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001062 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001063 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
1064 xgifb_reg_set(pVBInfo->P3c4, 0x2B,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301065 pVBInfo->VCLKData[index].SR2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001066 xgifb_reg_set(pVBInfo->P3c4, 0x2C,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301067 pVBInfo->VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001068 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301069 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001070
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301071 if (HwDeviceExtension->jChipType >= XG20) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001072 if (pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag &
1073 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001074 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +02001075 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +02001076 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301077 index = data;
1078 index &= 0xE0;
1079 data &= 0x1F;
1080 data = data << 1;
1081 data += 1;
1082 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001083 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301084 }
1085 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001086}
1087
Aaro Koskinene85f2032011-11-27 23:03:07 +02001088static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
1089{
1090 unsigned char temp;
1091
1092 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
1093 temp = (temp & 1) << 6;
1094 /* SR06[6] 18bit Dither */
1095 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
1096 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
1097 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
1098
1099}
1100
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001101static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301102 struct xgi_hw_device_info *HwDeviceExtension,
1103 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001104{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301105 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001106
Aaro Koskinen58839b02011-03-13 12:26:23 +02001107 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301108 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001109 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001110
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001111 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
1112 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1113 data &= 0xC0;
1114 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
1115 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1116 data |= 0x01;
1117 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001118
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301119 if (HwDeviceExtension->jChipType == XG21)
1120 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001121}
1122
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001123static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1124 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1125 struct vb_device_info *pVBInfo)
1126{
1127 unsigned short data, data2 = 0;
1128 short VCLK;
1129
1130 unsigned char index;
1131
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001132 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
1133 index &= IndexMask;
1134 VCLK = pVBInfo->VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001135
Aaro Koskinen58839b02011-03-13 12:26:23 +02001136 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001137 data &= 0xf3;
1138 if (VCLK >= 200)
1139 data |= 0x0c; /* VCLK > 200 */
1140
1141 if (HwDeviceExtension->jChipType >= XG20)
1142 data &= ~0x04; /* 2 pixel mode */
1143
Aaro Koskinen8104e322011-03-13 12:26:22 +02001144 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001145
1146 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001147 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001148 data &= 0xE7;
1149 if (VCLK < 200)
1150 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001151 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001152 }
1153
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001154 data2 = 0x00;
1155
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001156 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001157 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001158 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001159
1160}
1161
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001162static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301163 unsigned short ModeNo, unsigned short ModeIdIndex,
1164 unsigned short RefreshRateTableIndex,
1165 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001166{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301167 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1168 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001169
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001170 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1171 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001172
Aaro Koskinen58839b02011-03-13 12:26:23 +02001173 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001174 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001175
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001176 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301177 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001178 data2 |= 0x02;
1179 data3 = pVBInfo->ModeType - ModeVGA;
1180 data3 = data3 << 2;
1181 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301182 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001183
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301184 if (data)
1185 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001186
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001187 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinen6c0965f2012-04-07 01:14:11 +03001188 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001189 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001190
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301191 data = 0x0000;
1192 if (infoflag & InterlaceMode) {
1193 if (xres == 1024)
1194 data = 0x0035;
1195 else if (xres == 1280)
1196 data = 0x0048;
1197 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001198
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301199 data2 = data & 0x00FF;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001200 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301201 data2 = (data & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001202 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001203
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301204 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001205 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001206
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301207 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001208
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301209 if (modeflag & LineCompareOff)
1210 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001211
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001212 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301213 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001214 data = data ^ 0x60;
1215 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001216 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001217
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301218 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1219 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001220
Aaro Koskinen58839b02011-03-13 12:26:23 +02001221 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001222
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301223 if (HwDeviceExtension->jChipType == XG27) {
1224 if (data & 0x40)
1225 data = 0x2c;
1226 else
1227 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001228 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001229 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301230 } else if (HwDeviceExtension->jChipType >= XG20) {
1231 if (data & 0x40)
1232 data = 0x33;
1233 else
1234 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001235 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1236 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301237 } else {
1238 if (data & 0x40)
1239 data = 0x2c;
1240 else
1241 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001242 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301243 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001244
1245}
1246
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001247static void XGI_WriteDAC(unsigned short dl,
1248 unsigned short ah,
1249 unsigned short al,
1250 unsigned short dh,
1251 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001252{
1253 unsigned short temp, bh, bl;
1254
1255 bh = ah;
1256 bl = al;
1257
1258 if (dl != 0) {
1259 temp = bh;
1260 bh = dh;
1261 dh = temp;
1262 if (dl == 1) {
1263 temp = bl;
1264 bl = dh;
1265 dh = temp;
1266 } else {
1267 temp = bl;
1268 bl = bh;
1269 bh = temp;
1270 }
1271 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001272 outb((unsigned short) dh, pVBInfo->P3c9);
1273 outb((unsigned short) bh, pVBInfo->P3c9);
1274 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001275}
1276
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001277static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301278 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001279{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001280 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1281 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001282
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001283 outb(0xFF, pVBInfo->P3c6);
1284 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001285
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001286 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301287 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001288
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301289 for (k = 0; k < 3; k++) {
1290 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001291
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301292 if (data & 0x01)
1293 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001294
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301295 if (data & 0x02)
1296 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001297
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001298 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301299 data = data >> 2;
1300 }
1301 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001302
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001303 for (i = 16; i < 32; i++) {
1304 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001305
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001306 for (k = 0; k < 3; k++)
1307 outb(data, pVBInfo->P3c9);
1308 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001309
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001310 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001311
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001312 for (m = 0; m < 9; m++) {
1313 di = si;
1314 bx = si + 0x04;
1315 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001316
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001317 for (n = 0; n < 3; n++) {
1318 for (o = 0; o < 5; o++) {
1319 dh = table[si];
1320 ah = table[di];
1321 al = table[bx];
1322 si++;
1323 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301324 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001325
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001326 si -= 2;
1327
1328 for (o = 0; o < 3; o++) {
1329 dh = table[bx];
1330 ah = table[di];
1331 al = table[si];
1332 si--;
1333 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1334 }
1335
1336 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301337 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001338
1339 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301340 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001341}
1342
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001343static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1344 unsigned short ModeIdIndex,
1345 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001346{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301347 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001348
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001349 /* si+Ext_ResInfo */
1350 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001351
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001352 /* si+Ext_ResInfo */
1353 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001354
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001355 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1356 yres = pVBInfo->ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001357
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001358 if (modeflag & HalfDCLK)
1359 xres = xres << 1;
1360
1361 if (modeflag & DoubleScanMode)
1362 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001363
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301364 if (xres == 720)
1365 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001366
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301367 pVBInfo->VGAHDE = xres;
1368 pVBInfo->HDE = xres;
1369 pVBInfo->VGAVDE = yres;
1370 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001371}
1372
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001373static void *XGI_GetLcdPtr(unsigned short BX, unsigned short ModeNo,
1374 unsigned short ModeIdIndex,
1375 unsigned short RefreshRateTableIndex,
1376 struct vb_device_info *pVBInfo)
1377{
1378 unsigned short i, tempdx, tempcx, tempbx, tempal, modeflag, table;
1379
1380 struct XGI330_LCDDataTablStruct *tempdi = NULL;
1381
1382 tempbx = BX;
1383
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001384 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1385 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001386
1387 tempal = tempal & 0x0f;
1388
1389 if (tempbx <= 1) { /* ExpLink */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001390 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001391
Peter Huewea3d675c2012-02-09 21:11:47 +01001392 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001393 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001394 Ext_CRT2CRTC2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001395 }
1396
1397 if (tempbx & 0x01)
1398 tempal = (tempal >> 4);
1399
1400 tempal = (tempal & 0x0f);
1401 }
1402
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02001403 tempcx = LCDLenList[tempbx];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001404
1405 if (pVBInfo->LCDInfo & EnableScalingLCD) { /* ScaleLCD */
1406 if ((tempbx == 5) || (tempbx) == 7)
1407 tempcx = LCDDesDataLen2;
1408 else if ((tempbx == 3) || (tempbx == 8))
1409 tempcx = LVDSDesDataLen2;
1410 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001411
1412 switch (tempbx) {
1413 case 0:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001414 case 1:
Aaro Koskinencc5c2ae2011-08-31 21:46:08 +03001415 tempdi = xgifb_epllcd_crt1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001416 break;
1417 case 2:
1418 tempdi = XGI_EPLLCDDataPtr;
1419 break;
1420 case 3:
1421 tempdi = XGI_EPLLCDDesDataPtr;
1422 break;
1423 case 4:
1424 tempdi = XGI_LCDDataTable;
1425 break;
1426 case 5:
1427 tempdi = XGI_LCDDesDataTable;
1428 break;
1429 case 6:
1430 tempdi = XGI_EPLCHLCDRegPtr;
1431 break;
1432 case 7:
1433 case 8:
1434 case 9:
1435 tempdi = NULL;
1436 break;
1437 default:
1438 break;
1439 }
1440
1441 if (tempdi == NULL) /* OEMUtil */
1442 return NULL;
1443
1444 table = tempbx;
1445 i = 0;
1446
1447 while (tempdi[i].PANELID != 0xff) {
1448 tempdx = pVBInfo->LCDResInfo;
1449 if (tempbx & 0x0080) { /* OEMUtil */
1450 tempbx &= (~0x0080);
1451 tempdx = pVBInfo->LCDTypeInfo;
1452 }
1453
1454 if (pVBInfo->LCDInfo & EnableScalingLCD)
1455 tempdx &= (~PanelResInfo);
1456
1457 if (tempdi[i].PANELID == tempdx) {
1458 tempbx = tempdi[i].MASK;
1459 tempdx = pVBInfo->LCDInfo;
1460
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001461 if (modeflag & HalfDCLK)
1462 tempdx |= SetLCDLowResolution;
1463
1464 tempbx &= tempdx;
1465 if (tempbx == tempdi[i].CAP)
1466 break;
1467 }
1468 i++;
1469 }
1470
1471 if (table == 0) {
1472 switch (tempdi[i].DATAPTR) {
1473 case 0:
1474 return &XGI_LVDSCRT11024x768_1_H[tempal];
1475 break;
1476 case 1:
1477 return &XGI_LVDSCRT11024x768_2_H[tempal];
1478 break;
1479 case 2:
1480 return &XGI_LVDSCRT11280x1024_1_H[tempal];
1481 break;
1482 case 3:
1483 return &XGI_LVDSCRT11280x1024_2_H[tempal];
1484 break;
1485 case 4:
1486 return &XGI_LVDSCRT11400x1050_1_H[tempal];
1487 break;
1488 case 5:
1489 return &XGI_LVDSCRT11400x1050_2_H[tempal];
1490 break;
1491 case 6:
1492 return &XGI_LVDSCRT11600x1200_1_H[tempal];
1493 break;
1494 case 7:
1495 return &XGI_LVDSCRT11024x768_1_Hx75[tempal];
1496 break;
1497 case 8:
1498 return &XGI_LVDSCRT11024x768_2_Hx75[tempal];
1499 break;
1500 case 9:
1501 return &XGI_LVDSCRT11280x1024_1_Hx75[tempal];
1502 break;
1503 case 10:
1504 return &XGI_LVDSCRT11280x1024_2_Hx75[tempal];
1505 break;
1506 default:
1507 break;
1508 }
1509 } else if (table == 1) {
1510 switch (tempdi[i].DATAPTR) {
1511 case 0:
1512 return &XGI_LVDSCRT11024x768_1_V[tempal];
1513 break;
1514 case 1:
1515 return &XGI_LVDSCRT11024x768_2_V[tempal];
1516 break;
1517 case 2:
1518 return &XGI_LVDSCRT11280x1024_1_V[tempal];
1519 break;
1520 case 3:
1521 return &XGI_LVDSCRT11280x1024_2_V[tempal];
1522 break;
1523 case 4:
1524 return &XGI_LVDSCRT11400x1050_1_V[tempal];
1525 break;
1526 case 5:
1527 return &XGI_LVDSCRT11400x1050_2_V[tempal];
1528 break;
1529 case 6:
1530 return &XGI_LVDSCRT11600x1200_1_V[tempal];
1531 break;
1532 case 7:
1533 return &XGI_LVDSCRT11024x768_1_Vx75[tempal];
1534 break;
1535 case 8:
1536 return &XGI_LVDSCRT11024x768_2_Vx75[tempal];
1537 break;
1538 case 9:
1539 return &XGI_LVDSCRT11280x1024_1_Vx75[tempal];
1540 break;
1541 case 10:
1542 return &XGI_LVDSCRT11280x1024_2_Vx75[tempal];
1543 break;
1544 default:
1545 break;
1546 }
1547 } else if (table == 2) {
1548 switch (tempdi[i].DATAPTR) {
1549 case 0:
1550 return &XGI_LVDS1024x768Data_1[tempal];
1551 break;
1552 case 1:
1553 return &XGI_LVDS1024x768Data_2[tempal];
1554 break;
1555 case 2:
1556 return &XGI_LVDS1280x1024Data_1[tempal];
1557 break;
1558 case 3:
1559 return &XGI_LVDS1280x1024Data_2[tempal];
1560 break;
1561 case 4:
1562 return &XGI_LVDS1400x1050Data_1[tempal];
1563 break;
1564 case 5:
1565 return &XGI_LVDS1400x1050Data_2[tempal];
1566 break;
1567 case 6:
1568 return &XGI_LVDS1600x1200Data_1[tempal];
1569 break;
1570 case 7:
1571 return &XGI_LVDSNoScalingData[tempal];
1572 break;
1573 case 8:
1574 return &XGI_LVDS1024x768Data_1x75[tempal];
1575 break;
1576 case 9:
1577 return &XGI_LVDS1024x768Data_2x75[tempal];
1578 break;
1579 case 10:
1580 return &XGI_LVDS1280x1024Data_1x75[tempal];
1581 break;
1582 case 11:
1583 return &XGI_LVDS1280x1024Data_2x75[tempal];
1584 break;
1585 case 12:
1586 return &XGI_LVDSNoScalingDatax75[tempal];
1587 break;
1588 default:
1589 break;
1590 }
1591 } else if (table == 3) {
1592 switch (tempdi[i].DATAPTR) {
1593 case 0:
1594 return &XGI_LVDS1024x768Des_1[tempal];
1595 break;
1596 case 1:
1597 return &XGI_LVDS1024x768Des_3[tempal];
1598 break;
1599 case 2:
1600 return &XGI_LVDS1024x768Des_2[tempal];
1601 break;
1602 case 3:
1603 return &XGI_LVDS1280x1024Des_1[tempal];
1604 break;
1605 case 4:
1606 return &XGI_LVDS1280x1024Des_2[tempal];
1607 break;
1608 case 5:
1609 return &XGI_LVDS1400x1050Des_1[tempal];
1610 break;
1611 case 6:
1612 return &XGI_LVDS1400x1050Des_2[tempal];
1613 break;
1614 case 7:
1615 return &XGI_LVDS1600x1200Des_1[tempal];
1616 break;
1617 case 8:
1618 return &XGI_LVDSNoScalingDesData[tempal];
1619 break;
1620 case 9:
1621 return &XGI_LVDS1024x768Des_1x75[tempal];
1622 break;
1623 case 10:
1624 return &XGI_LVDS1024x768Des_3x75[tempal];
1625 break;
1626 case 11:
1627 return &XGI_LVDS1024x768Des_2x75[tempal];
1628 break;
1629 case 12:
1630 return &XGI_LVDS1280x1024Des_1x75[tempal];
1631 break;
1632 case 13:
1633 return &XGI_LVDS1280x1024Des_2x75[tempal];
1634 break;
1635 case 14:
1636 return &XGI_LVDSNoScalingDesDatax75[tempal];
1637 break;
1638 default:
1639 break;
1640 }
1641 } else if (table == 4) {
1642 switch (tempdi[i].DATAPTR) {
1643 case 0:
1644 return &XGI_ExtLCD1024x768Data[tempal];
1645 break;
1646 case 1:
1647 return &XGI_StLCD1024x768Data[tempal];
1648 break;
1649 case 2:
1650 return &XGI_CetLCD1024x768Data[tempal];
1651 break;
1652 case 3:
1653 return &XGI_ExtLCD1280x1024Data[tempal];
1654 break;
1655 case 4:
1656 return &XGI_StLCD1280x1024Data[tempal];
1657 break;
1658 case 5:
1659 return &XGI_CetLCD1280x1024Data[tempal];
1660 break;
1661 case 6:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001662 case 7:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001663 return &xgifb_lcd_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001664 break;
1665 case 8:
1666 return &XGI_CetLCD1400x1050Data[tempal];
1667 break;
1668 case 9:
1669 return &XGI_ExtLCD1600x1200Data[tempal];
1670 break;
1671 case 10:
1672 return &XGI_StLCD1600x1200Data[tempal];
1673 break;
1674 case 11:
1675 return &XGI_NoScalingData[tempal];
1676 break;
1677 case 12:
1678 return &XGI_ExtLCD1024x768x75Data[tempal];
1679 break;
1680 case 13:
1681 return &XGI_ExtLCD1024x768x75Data[tempal];
1682 break;
1683 case 14:
1684 return &XGI_CetLCD1024x768x75Data[tempal];
1685 break;
1686 case 15:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001687 case 16:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001688 return &xgifb_lcd_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001689 break;
1690 case 17:
1691 return &XGI_CetLCD1280x1024x75Data[tempal];
1692 break;
1693 case 18:
1694 return &XGI_NoScalingDatax75[tempal];
1695 break;
1696 default:
1697 break;
1698 }
1699 } else if (table == 5) {
1700 switch (tempdi[i].DATAPTR) {
1701 case 0:
1702 return &XGI_ExtLCDDes1024x768Data[tempal];
1703 break;
1704 case 1:
1705 return &XGI_StLCDDes1024x768Data[tempal];
1706 break;
1707 case 2:
1708 return &XGI_CetLCDDes1024x768Data[tempal];
1709 break;
1710 case 3:
Peter Huewe6896b942012-02-09 21:11:46 +01001711 if ((pVBInfo->VBType & VB_SIS301LV) ||
1712 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001713 return &XGI_ExtLCDDLDes1280x1024Data[tempal];
1714 else
1715 return &XGI_ExtLCDDes1280x1024Data[tempal];
1716 break;
1717 case 4:
Peter Huewe6896b942012-02-09 21:11:46 +01001718 if ((pVBInfo->VBType & VB_SIS301LV) ||
1719 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001720 return &XGI_StLCDDLDes1280x1024Data[tempal];
1721 else
1722 return &XGI_StLCDDes1280x1024Data[tempal];
1723 break;
1724 case 5:
Peter Huewe6896b942012-02-09 21:11:46 +01001725 if ((pVBInfo->VBType & VB_SIS301LV) ||
1726 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001727 return &XGI_CetLCDDLDes1280x1024Data[tempal];
1728 else
1729 return &XGI_CetLCDDes1280x1024Data[tempal];
1730 break;
1731 case 6:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001732 case 7:
Peter Huewe6896b942012-02-09 21:11:46 +01001733 if ((pVBInfo->VBType & VB_SIS301LV) ||
1734 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001735 return &xgifb_lcddldes_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001736 else
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001737 return &xgifb_lcddes_1400x1050[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001738 break;
1739 case 8:
1740 return &XGI_CetLCDDes1400x1050Data[tempal];
1741 break;
1742 case 9:
1743 return &XGI_CetLCDDes1400x1050Data2[tempal];
1744 break;
1745 case 10:
Peter Huewe6896b942012-02-09 21:11:46 +01001746 if ((pVBInfo->VBType & VB_SIS301LV) ||
1747 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001748 return &XGI_ExtLCDDLDes1600x1200Data[tempal];
1749 else
1750 return &XGI_ExtLCDDes1600x1200Data[tempal];
1751 break;
1752 case 11:
Peter Huewe6896b942012-02-09 21:11:46 +01001753 if ((pVBInfo->VBType & VB_SIS301LV) ||
1754 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001755 return &XGI_StLCDDLDes1600x1200Data[tempal];
1756 else
1757 return &XGI_StLCDDes1600x1200Data[tempal];
1758 break;
1759 case 12:
1760 return &XGI_NoScalingDesData[tempal];
1761 break;
1762 case 13:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001763 case 14:
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001764 return &xgifb_lcddes_1024x768x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001765 break;
1766 case 15:
1767 return &XGI_CetLCDDes1024x768x75Data[tempal];
1768 break;
1769 case 16:
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001770 case 17:
Peter Huewe6896b942012-02-09 21:11:46 +01001771 if ((pVBInfo->VBType & VB_SIS301LV) ||
1772 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001773 return &xgifb_lcddldes_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001774 else
Aaro Koskinenada2bda2011-08-31 21:46:07 +03001775 return &xgifb_lcddes_1280x1024x75[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001776 break;
1777 case 18:
Peter Huewe6896b942012-02-09 21:11:46 +01001778 if ((pVBInfo->VBType & VB_SIS301LV) ||
1779 (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001780 return &XGI_CetLCDDLDes1280x1024x75Data[tempal];
1781 else
1782 return &XGI_CetLCDDes1280x1024x75Data[tempal];
1783 break;
1784 case 19:
1785 return &XGI_NoScalingDesDatax75[tempal];
1786 break;
1787 default:
1788 break;
1789 }
1790 } else if (table == 6) {
1791 switch (tempdi[i].DATAPTR) {
1792 case 0:
1793 return &XGI_CH7017LV1024x768[tempal];
1794 break;
1795 case 1:
1796 return &XGI_CH7017LV1400x1050[tempal];
1797 break;
1798 default:
1799 break;
1800 }
1801 }
1802 return NULL;
1803}
1804
1805static void *XGI_GetTVPtr(unsigned short BX, unsigned short ModeNo,
1806 unsigned short ModeIdIndex,
1807 unsigned short RefreshRateTableIndex,
1808 struct vb_device_info *pVBInfo)
1809{
1810 unsigned short i, tempdx, tempbx, tempal, modeflag, table;
1811 struct XGI330_TVDataTablStruct *tempdi = NULL;
1812
1813 tempbx = BX;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001814 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
1815 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001816 tempal = tempal & 0x3f;
1817 table = tempbx;
1818
1819 switch (tempbx) {
1820 case 0:
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02001821 tempdi = NULL;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001822 break;
1823 case 1:
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02001824 tempdi = NULL;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001825 break;
1826 case 2:
Aaro Koskinen0c23b6d2011-08-31 21:46:09 +03001827 case 6:
1828 tempdi = xgifb_chrontel_tv;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001829 break;
1830 case 3:
1831 tempdi = NULL;
1832 break;
1833 case 4:
1834 tempdi = XGI_TVDataTable;
1835 break;
1836 case 5:
1837 tempdi = NULL;
1838 break;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001839 default:
1840 break;
1841 }
1842
1843 if (tempdi == NULL) /* OEMUtil */
1844 return NULL;
1845
1846 tempdx = pVBInfo->TVInfo;
1847
1848 if (pVBInfo->VBInfo & SetInSlaveMode)
1849 tempdx = tempdx | SetTVLockMode;
1850
1851 if (modeflag & HalfDCLK)
1852 tempdx = tempdx | SetTVLowResolution;
1853
1854 i = 0;
1855
1856 while (tempdi[i].MASK != 0xffff) {
1857 if ((tempdx & tempdi[i].MASK) == tempdi[i].CAP)
1858 break;
1859 i++;
1860 }
1861
Aaro Koskinenebe33022011-11-27 23:03:18 +02001862 if (table == 0x04) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001863 switch (tempdi[i].DATAPTR) {
1864 case 0:
1865 return &XGI_ExtPALData[tempal];
1866 break;
1867 case 1:
1868 return &XGI_ExtNTSCData[tempal];
1869 break;
1870 case 2:
1871 return &XGI_StPALData[tempal];
1872 break;
1873 case 3:
1874 return &XGI_StNTSCData[tempal];
1875 break;
1876 case 4:
1877 return &XGI_ExtHiTVData[tempal];
1878 break;
1879 case 5:
1880 return &XGI_St2HiTVData[tempal];
1881 break;
1882 case 6:
1883 return &XGI_ExtYPbPr525iData[tempal];
1884 break;
1885 case 7:
1886 return &XGI_ExtYPbPr525pData[tempal];
1887 break;
1888 case 8:
1889 return &XGI_ExtYPbPr750pData[tempal];
1890 break;
1891 case 9:
1892 return &XGI_StYPbPr525iData[tempal];
1893 break;
1894 case 10:
1895 return &XGI_StYPbPr525pData[tempal];
1896 break;
1897 case 11:
1898 return &XGI_StYPbPr750pData[tempal];
1899 break;
1900 case 12: /* avoid system hang */
1901 return &XGI_ExtNTSCData[tempal];
1902 break;
1903 case 13:
1904 return &XGI_St1HiTVData[tempal];
1905 break;
1906 default:
1907 break;
1908 }
1909 } else if (table == 0x02) {
1910 switch (tempdi[i].DATAPTR) {
1911 case 0:
1912 return &XGI_CHTVUNTSCData[tempal];
1913 break;
1914 case 1:
1915 return &XGI_CHTVONTSCData[tempal];
1916 break;
1917 case 2:
1918 return &XGI_CHTVUPALData[tempal];
1919 break;
1920 case 3:
1921 return &XGI_CHTVOPALData[tempal];
1922 break;
1923 default:
1924 break;
1925 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001926 }
1927 return NULL;
1928}
1929
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001930static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301931 unsigned short RefreshRateTableIndex,
1932 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001933{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301934 unsigned short tempbx;
Peter Huewe51f984b2012-06-14 00:21:51 +02001935 struct SiS_LVDSData *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001936
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301937 tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001938
Peter Huewea3d675c2012-02-09 21:11:47 +01001939 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe51f984b2012-06-14 00:21:51 +02001940 LCDPtr = (struct SiS_LVDSData *)XGI_GetLcdPtr(tempbx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301941 ModeNo, ModeIdIndex, RefreshRateTableIndex,
1942 pVBInfo);
1943 pVBInfo->VGAHT = LCDPtr->VGAHT;
1944 pVBInfo->VGAVT = LCDPtr->VGAVT;
1945 pVBInfo->HT = LCDPtr->LCDHT;
1946 pVBInfo->VT = LCDPtr->LCDVT;
1947 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001948
Peter Huewea3d675c2012-02-09 21:11:47 +01001949 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301950 if (!(pVBInfo->LCDInfo & (SetLCDtoNonExpanding
1951 | EnableScalingLCD))) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001952 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1953 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301954 pVBInfo->HDE = 1024;
1955 pVBInfo->VDE = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001956 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1957 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301958 pVBInfo->HDE = 1280;
1959 pVBInfo->VDE = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001960 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301961 pVBInfo->HDE = 1400;
1962 pVBInfo->VDE = 1050;
1963 } else {
1964 pVBInfo->HDE = 1600;
1965 pVBInfo->VDE = 1200;
1966 }
1967 }
1968 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001969}
1970
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001971static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301972 unsigned short RefreshRateTableIndex,
1973 struct xgi_hw_device_info *HwDeviceExtension,
1974 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001975{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301976 unsigned char index;
1977 unsigned short tempbx, i;
1978 struct XGI_LVDSCRT1HDataStruct *LCDPtr = NULL;
1979 struct XGI_LVDSCRT1VDataStruct *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001980
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001981 index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301982 index = index & IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001983
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001984 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001985
Peter Huewea3d675c2012-02-09 21:11:47 +01001986 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001987 LCDPtr = (struct XGI_LVDSCRT1HDataStruct *)
1988 XGI_GetLcdPtr(tempbx, ModeNo,
1989 ModeIdIndex,
1990 RefreshRateTableIndex,
1991 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001992
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001993 for (i = 0; i < 8; i++)
1994 pVBInfo->TimingH[0].data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301995 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001996
1997 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1998
1999 tempbx = 1;
2000
Peter Huewea3d675c2012-02-09 21:11:47 +01002001 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03002002 LCDPtr1 = (struct XGI_LVDSCRT1VDataStruct *)
2003 XGI_GetLcdPtr(
2004 tempbx,
2005 ModeNo,
2006 ModeIdIndex,
2007 RefreshRateTableIndex,
2008 pVBInfo);
2009 for (i = 0; i < 7; i++)
2010 pVBInfo->TimingV[0].data[i] = LCDPtr1[0].Reg[i];
2011 }
2012
2013 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002014}
2015
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002016static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
2017{
2018 unsigned char tempal, tempah, tempbl, i;
2019
Aaro Koskinen58839b02011-03-13 12:26:23 +02002020 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002021 tempal = tempah & 0x0F;
2022 tempah = tempah & 0xF0;
2023 i = 0;
2024 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2025
2026 while (tempbl != 0xFF) {
2027 if (tempbl & 0x80) { /* OEMUtil */
2028 tempal = tempah;
2029 tempbl = tempbl & ~(0x80);
2030 }
2031
2032 if (tempal == tempbl)
2033 break;
2034
2035 i++;
2036
2037 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2038 }
2039
2040 return i;
2041}
2042
2043static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
2044{
2045 unsigned short tempah, tempal, tempbl, i;
2046
2047 tempal = pVBInfo->LCDResInfo;
2048 tempah = pVBInfo->LCDTypeInfo;
2049
2050 i = 0;
2051 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2052
2053 while (tempbl != 0xFF) {
2054 if ((tempbl & 0x80) && (tempbl != 0x80)) {
2055 tempal = tempah;
2056 tempbl &= ~0x80;
2057 }
2058
2059 if (tempal == tempbl)
2060 break;
2061
2062 i++;
2063 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
2064 }
2065
2066 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01002067 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002068 pVBInfo->LCDTypeInfo = 0;
2069 i = 0;
2070 }
2071
2072 return i;
2073}
2074
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002075static void XGI_GetLCDSync(unsigned short *HSyncWidth,
2076 unsigned short *VSyncWidth,
2077 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002078{
2079 unsigned short Index;
2080
2081 Index = XGI_GetLCDCapPtr(pVBInfo);
2082 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
2083 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
2084
2085 return;
2086}
2087
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002088static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302089 unsigned short RefreshRateTableIndex,
2090 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002091{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302092 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
2093 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinend00d12f2012-04-07 01:14:10 +03002094 struct XGI_LCDDesStruct *LCDPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302095 struct XGI330_LCDDataDesStruct2 *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002096
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002097 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen66cface2011-08-31 21:46:13 +03002098 tempbx = 3;
2099 if (pVBInfo->LCDInfo & EnableScalingLCD)
2100 LCDPtr1 =
2101 (struct XGI330_LCDDataDesStruct2 *)
2102 XGI_GetLcdPtr(
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002103 tempbx,
2104 ModeNo,
2105 ModeIdIndex,
2106 RefreshRateTableIndex,
2107 pVBInfo);
Aaro Koskinen66cface2011-08-31 21:46:13 +03002108 else
2109 LCDPtr =
Aaro Koskinend00d12f2012-04-07 01:14:10 +03002110 (struct XGI_LCDDesStruct *)
Aaro Koskinen66cface2011-08-31 21:46:13 +03002111 XGI_GetLcdPtr(
2112 tempbx,
2113 ModeNo,
2114 ModeIdIndex,
2115 RefreshRateTableIndex,
2116 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002117
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002118 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
2119 push1 = tempbx;
2120 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002121
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002122 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01002123 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
2124 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002125 tempax = 1024;
2126 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002127 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
2128 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002129 tempax = 1280;
2130 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002131 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002132 tempax = 1400;
2133 tempbx = 1050;
2134 } else {
2135 tempax = 1600;
2136 tempbx = 1200;
2137 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002138
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002139 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
2140 pVBInfo->HDE = tempax;
2141 pVBInfo->VDE = tempbx;
2142 pVBInfo->VGAHDE = tempax;
2143 pVBInfo->VGAVDE = tempbx;
2144 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002145
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002146 tempax = pVBInfo->HT;
2147
2148 if (pVBInfo->LCDInfo & EnableScalingLCD)
2149 tempbx = LCDPtr1->LCDHDES;
2150 else
2151 tempbx = LCDPtr->LCDHDES;
2152
2153 tempcx = pVBInfo->HDE;
2154 tempbx = tempbx & 0x0fff;
2155 tempcx += tempbx;
2156
2157 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002158 tempcx -= tempax;
2159
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002160 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002161
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002162 tempcx = tempcx >> 3;
2163 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002164
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002165 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
2166 (unsigned short) (tempbx & 0xff));
2167 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
2168 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002169
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002170 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002171
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002172 if (pVBInfo->LCDInfo & EnableScalingLCD)
2173 tempbx = LCDPtr1->LCDHRS;
2174 else
2175 tempbx = LCDPtr->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002176
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002177 tempcx = push2;
2178
2179 if (pVBInfo->LCDInfo & EnableScalingLCD)
2180 tempcx = LCDPtr1->LCDHSync;
2181
2182 tempcx += tempbx;
2183
2184 if (tempcx >= tempax)
2185 tempcx -= tempax;
2186
2187 tempax = tempbx & 0x07;
2188 tempax = tempax >> 5;
2189 tempcx = tempcx >> 3;
2190 tempbx = tempbx >> 3;
2191
2192 tempcx &= 0x1f;
2193 tempax |= tempcx;
2194
2195 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
2196 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
2197 (unsigned short) (tempbx & 0xff));
2198
2199 tempax = pVBInfo->VT;
2200 if (pVBInfo->LCDInfo & EnableScalingLCD)
2201 tempbx = LCDPtr1->LCDVDES;
2202 else
2203 tempbx = LCDPtr->LCDVDES;
2204 tempcx = pVBInfo->VDE;
2205
2206 tempbx = tempbx & 0x0fff;
2207 tempcx += tempbx;
2208 if (tempcx >= tempax)
2209 tempcx -= tempax;
2210
2211 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
2212 (unsigned short) (tempbx & 0xff));
2213 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
2214 (unsigned short) (tempcx & 0xff));
2215
2216 tempbx = (tempbx >> 8) & 0x07;
2217 tempcx = (tempcx >> 8) & 0x07;
2218
2219 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
2220 (unsigned short) ((tempcx << 3)
2221 | tempbx));
2222
2223 tempax = pVBInfo->VT;
2224 if (pVBInfo->LCDInfo & EnableScalingLCD)
2225 tempbx = LCDPtr1->LCDVRS;
2226 else
2227 tempbx = LCDPtr->LCDVRS;
2228
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002229 tempcx = push1;
2230
2231 if (pVBInfo->LCDInfo & EnableScalingLCD)
2232 tempcx = LCDPtr1->LCDVSync;
2233
2234 tempcx += tempbx;
2235 if (tempcx >= tempax)
2236 tempcx -= tempax;
2237
2238 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
2239 (unsigned short) (tempbx & 0xff));
2240 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
2241 (unsigned short) (tempcx & 0x0f));
2242
2243 tempax = ((tempbx >> 8) & 0x07) << 3;
2244
2245 tempbx = pVBInfo->VGAVDE;
2246 if (tempbx != pVBInfo->VDE)
2247 tempax |= 0x40;
2248
Peter Huewea3d675c2012-02-09 21:11:47 +01002249 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002250 tempax |= 0x40;
2251
2252 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
2253 tempax);
2254
2255 tempcx = pVBInfo->VGAVT;
2256 tempbx = pVBInfo->VDE;
2257 tempax = pVBInfo->VGAVDE;
2258 tempcx -= tempax;
2259
2260 temp = tempax; /* 0430 ylshieh */
2261 temp1 = (temp << 18) / tempbx;
2262
2263 tempdx = (unsigned short) ((temp << 18) % tempbx);
2264
2265 if (tempdx != 0)
2266 temp1 += 1;
2267
2268 temp2 = temp1;
2269 push3 = temp2;
2270
2271 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
2272 (unsigned short) (temp2 & 0xff));
2273 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
2274 (unsigned short) ((temp2 >> 8) & 0xff));
2275
2276 tempbx = (unsigned short) (temp2 >> 16);
2277 tempax = tempbx & 0x03;
2278
2279 tempbx = pVBInfo->VGAVDE;
2280 if (tempbx == pVBInfo->VDE)
2281 tempax |= 0x04;
2282
2283 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
2284
2285 if (pVBInfo->VBType & VB_XGI301C) {
2286 temp2 = push3;
2287 xgifb_reg_set(pVBInfo->Part4Port,
2288 0x3c,
2289 (unsigned short) (temp2 & 0xff));
2290 xgifb_reg_set(pVBInfo->Part4Port,
2291 0x3b,
2292 (unsigned short) ((temp2 >> 8) &
2293 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002294 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002295 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
2296 ~0xc0,
2297 (unsigned short) ((tempbx &
2298 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03002299
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002300 tempcx = pVBInfo->VGAVDE;
2301 if (tempcx == pVBInfo->VDE)
2302 xgifb_reg_and_or(pVBInfo->Part4Port,
2303 0x30, ~0x0c, 0x00);
2304 else
2305 xgifb_reg_and_or(pVBInfo->Part4Port,
2306 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302307 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002308
2309 tempcx = pVBInfo->VGAHDE;
2310 tempbx = pVBInfo->HDE;
2311
2312 temp1 = tempcx << 16;
2313
2314 tempax = (unsigned short) (temp1 / tempbx);
2315
2316 if ((tempbx & 0xffff) == (tempcx & 0xffff))
2317 tempax = 65535;
2318
2319 temp3 = tempax;
2320 temp1 = pVBInfo->VGAHDE << 16;
2321
2322 temp1 /= temp3;
2323 temp3 = temp3 << 16;
2324 temp1 -= 1;
2325
2326 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
2327
2328 tempax = (unsigned short) (temp3 & 0xff);
2329 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
2330
2331 temp1 = pVBInfo->VGAVDE << 18;
2332 temp1 = temp1 / push3;
2333 tempbx = (unsigned short) (temp1 & 0xffff);
2334
Peter Huewe255aabd2012-02-09 21:11:44 +01002335 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002336 tempbx -= 1;
2337
2338 tempax = ((tempbx >> 8) & 0xff) << 3;
2339 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
2340 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
2341 (unsigned short) (tempax & 0xff));
2342 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
2343 (unsigned short) (tempbx & 0xff));
2344
2345 temp3 = temp3 >> 16;
2346
2347 if (modeflag & HalfDCLK)
2348 temp3 = temp3 >> 1;
2349
2350 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
2351 (unsigned short) ((temp3 >> 8) & 0xff));
2352 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
2353 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002354}
2355
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002356/* --------------------------------------------------------------------- */
2357/* Function : XGI_GETLCDVCLKPtr */
2358/* Input : */
2359/* Output : al -> VCLK Index */
2360/* Description : */
2361/* --------------------------------------------------------------------- */
2362static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
2363 struct vb_device_info *pVBInfo)
2364{
2365 unsigned short index;
2366
Peter Huewea3d675c2012-02-09 21:11:47 +01002367 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002368 index = XGI_GetLCDCapPtr1(pVBInfo);
2369
2370 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
2371 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
2372 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
2373 } else { /* LCDA */
2374 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
2375 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
2376 }
2377 }
2378 return;
2379}
2380
2381static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
2382 unsigned short ModeNo, unsigned short ModeIdIndex,
2383 struct vb_device_info *pVBInfo)
2384{
2385
2386 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002387 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002388
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002389 /* si+Ext_ResInfo */
2390 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002391
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002392 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
2393 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002394 index = XGI_GetLCDCapPtr(pVBInfo);
2395 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
2396
Peter Huewea3d675c2012-02-09 21:11:47 +01002397 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002398 return tempal;
2399
2400 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002401 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01002402 (VB_SIS301B |
2403 VB_SIS302B |
2404 VB_SIS301LV |
2405 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002406 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01002407 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01002408 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002409 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01002410 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002411 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01002412 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002413 if (!(modeflag & Charx8Dot))
Peter Hueweccc8cb22012-02-09 21:11:48 +01002414 tempal = TVCLKBASE_315 + HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002415
2416 }
2417 return tempal;
2418 }
2419
Peter Huewe599801f2012-02-09 21:11:45 +01002420 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01002421 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002422 return tempal;
2423 }
2424
Peter Huewe599801f2012-02-09 21:11:45 +01002425 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002426 tempal = YPbPr525pVCLK;
2427 return tempal;
2428 }
2429
2430 tempal = NTSC1024VCLK;
2431
2432 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01002433 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002434 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01002435 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002436 }
2437
2438 if (pVBInfo->VBInfo & SetCRT2ToTV)
2439 return tempal;
2440 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002441 } /* {End of VB} */
2442
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002443 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002444 tempal = tempal >> 2;
2445 tempal &= 0x03;
2446
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002447 /* for Dot8 Scaling LCD */
2448 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002449 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
2450
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002451 tempal = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
2452 return tempal;
2453}
2454
2455static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
2456 unsigned char *di_1, struct vb_device_info *pVBInfo)
2457{
Peter Huewe6896b942012-02-09 21:11:46 +01002458 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
2459 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01002460 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) && (pVBInfo->SetFlag
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002461 & ProgrammingCRT2)) {
2462 *di_0 = (unsigned char) XGI_VBVCLKData[tempal].SR2B;
2463 *di_1 = XGI_VBVCLKData[tempal].SR2C;
2464 }
2465 } else {
2466 *di_0 = XGI_VCLKData[tempal].SR2B;
2467 *di_1 = XGI_VCLKData[tempal].SR2C;
2468 }
2469}
2470
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002471static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302472 unsigned short RefreshRateTableIndex,
2473 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002474{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302475 unsigned char di_0, di_1, tempal;
2476 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002477
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302478 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2479 pVBInfo);
2480 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2481 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002482
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302483 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002484 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302485 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01002486 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302487 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02002488 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
2489 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302490 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02002491 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
2492 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302493 }
2494 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002495}
2496
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002497static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302498 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002499{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302500 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002501
Peter Huewe6896b942012-02-09 21:11:46 +01002502 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
2503 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302504 tempcl = 0;
2505 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002506 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002507
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302508 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002509 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302510 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002511 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302512 if (!(temp & 0x40))
2513 tempcl |= ActiveCRT1;
2514 }
2515 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002516
Aaro Koskinen58839b02011-03-13 12:26:23 +02002517 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302518 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002519
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302520 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002521 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002522 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302523 if (tempax & 0x04)
2524 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002525
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302526 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002527
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302528 if (!(tempcl & ActiveLCD))
2529 if (temp == 0x01)
2530 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002531
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302532 if (temp == 0x04)
2533 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002534
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302535 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002536 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002537
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302538 if (!(temp & 0x08))
2539 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002540
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302541 if (!(temp & 0x04))
2542 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002543
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302544 if (temp & 0x02)
2545 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002546
Peter Huewe599801f2012-02-09 21:11:45 +01002547 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302548 if (temp & 0x01)
2549 tempch |= ActiveHiTV;
2550 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002551
Peter Huewe599801f2012-02-09 21:11:45 +01002552 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002553 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302554 pVBInfo->Part2Port,
2555 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002556
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302557 if (temp & 0x10)
2558 tempch |= ActiveYPbPr;
2559 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002560
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302561 if (tempch != 0)
2562 tempcl |= ActiveTV;
2563 }
2564 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002565
Aaro Koskinen58839b02011-03-13 12:26:23 +02002566 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302567 if (tempcl & ActiveLCD) {
2568 if ((pVBInfo->SetFlag & ReserveTVOption)) {
2569 if (temp & ActiveTV)
2570 tempcl |= ActiveTV;
2571 }
2572 }
2573 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01002574 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002575 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002576
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302577 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02002578 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302579 } else {
2580 return;
2581 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002582}
2583
Bill Pemberton80adad82010-06-17 13:10:51 -04002584void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002585{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302586 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002587
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302588 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe6896b942012-02-09 21:11:46 +01002589 tempbx = VB_SIS302B;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002590 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302591 if (flag != 0x02) {
Peter Huewe6896b942012-02-09 21:11:46 +01002592 tempbx = VB_SIS301;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002593 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302594 if (flag >= 0xB0) {
Peter Huewe6896b942012-02-09 21:11:46 +01002595 tempbx = VB_SIS301B;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302596 if (flag >= 0xC0) {
2597 tempbx = VB_XGI301C;
2598 if (flag >= 0xD0) {
Peter Huewe6896b942012-02-09 21:11:46 +01002599 tempbx = VB_SIS301LV;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302600 if (flag >= 0xE0) {
Peter Huewe6896b942012-02-09 21:11:46 +01002601 tempbx = VB_SIS302LV;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002602 tempah = xgifb_reg_get(
2603 pVBInfo->Part4Port,
2604 0x39);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302605 if (tempah != 0xFF)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002606 tempbx =
2607 VB_XGI301C;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302608 }
2609 }
2610 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002611
Peter Huewe6896b942012-02-09 21:11:46 +01002612 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002613 flag = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302614 pVBInfo->Part4Port,
2615 0x23);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002616
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302617 if (!(flag & 0x02))
2618 tempbx = tempbx | VB_NoLCD;
2619 }
2620 }
2621 }
2622 pVBInfo->VBType = tempbx;
2623 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002624}
2625
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002626static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302627 struct xgi_hw_device_info *HwDeviceExtension,
2628 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002629{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302630 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002631
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002632 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302633 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01002634 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302635 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002636
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302637 if (pVBInfo->VBType & 0xFFFF) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002638 /* Check Display Device */
2639 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302640 tempbx = tempbx | temp;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002641 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302642 push = temp;
2643 push = push << 8;
2644 tempax = temp << 8;
2645 tempbx = tempbx | tempax;
Peter Huewea3d675c2012-02-09 21:11:47 +01002646 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302647 | SetInSlaveMode | DisableCRT2Display);
2648 temp = 0xFFFF ^ temp;
2649 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002650
Aaro Koskinen58839b02011-03-13 12:26:23 +02002651 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002652
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302653 if (pVBInfo->IF_DEF_LCDA == 1) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002654
Aaro Koskinen9ffc7e92011-11-27 23:03:14 +02002655 if ((HwDeviceExtension->jChipType >= XG20) ||
2656 (HwDeviceExtension->jChipType >= XG40)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302657 if (pVBInfo->IF_DEF_LVDS == 0) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002658 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01002659 (VB_SIS302B |
2660 VB_SIS301LV |
2661 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002662 VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302663 if (temp & EnableDualEdge) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002664 tempbx |=
2665 SetCRT2ToDualEdge;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002666
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302667 if (temp & SetToLCDA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002668 tempbx |=
Peter Huewea3d675c2012-02-09 21:11:47 +01002669 XGI_SetCRT2ToLCDA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302670 }
2671 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302672 }
2673 }
2674 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002675
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302676 if (pVBInfo->IF_DEF_YPbPr == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002677 if (((pVBInfo->IF_DEF_LVDS == 0) &&
Peter Huewe6896b942012-02-09 21:11:46 +01002678 ((pVBInfo->VBType & VB_SIS301LV) ||
2679 (pVBInfo->VBType & VB_SIS302LV) ||
Aaro Koskinen83f76a92011-08-31 21:45:58 +03002680 (pVBInfo->VBType & VB_XGI301C)))) {
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02002681 if (temp & SetYPbPr) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302682 if (pVBInfo->IF_DEF_HiVision == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002683 /* shampoo add for new
2684 * scratch */
Aaro Koskinen58839b02011-03-13 12:26:23 +02002685 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302686 pVBInfo->P3d4,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002687 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302688 temp &= YPbPrMode;
Peter Huewe599801f2012-02-09 21:11:45 +01002689 tempbx |= SetCRT2ToHiVision;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002690
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302691 if (temp != YPbPrMode1080i) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002692 tempbx &=
Peter Huewe599801f2012-02-09 21:11:45 +01002693 (~SetCRT2ToHiVision);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002694 tempbx |=
Peter Huewe599801f2012-02-09 21:11:45 +01002695 SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302696 }
2697 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302698 }
2699 }
2700 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002701
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302702 tempax = push; /* restore CR31 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002703
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302704 if (pVBInfo->IF_DEF_LVDS == 0) {
2705 if (pVBInfo->IF_DEF_YPbPr == 1) {
2706 if (pVBInfo->IF_DEF_HiVision == 1)
2707 temp = 0x09FC;
2708 else
2709 temp = 0x097C;
2710 } else {
2711 if (pVBInfo->IF_DEF_HiVision == 1)
2712 temp = 0x01FC;
2713 else
2714 temp = 0x017C;
2715 }
2716 } else { /* 3nd party chip */
Aaro Koskinen83f76a92011-08-31 21:45:58 +03002717 temp = SetCRT2ToLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302718 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002719
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302720 if (!(tempbx & temp)) {
2721 tempax |= DisableCRT2Display;
2722 tempbx = 0;
2723 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002724
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302725 if (pVBInfo->IF_DEF_LCDA == 1) { /* Select Display Device */
2726 if (!(pVBInfo->VBType & VB_NoLCD)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01002727 if (tempbx & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302728 if (tempbx & SetSimuScanMode)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002729 tempbx &= (~(SetCRT2ToLCD |
2730 SetCRT2ToRAMDAC |
Peter Huewe6896b942012-02-09 21:11:46 +01002731 SwitchCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302732 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002733 tempbx &= (~(SetCRT2ToLCD |
2734 SetCRT2ToRAMDAC |
2735 SetCRT2ToTV |
Peter Huewe6896b942012-02-09 21:11:46 +01002736 SwitchCRT2));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302737 }
2738 }
2739 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002740
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302741 /* shampoo add */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002742 /* for driver abnormal */
Peter Huewe6896b942012-02-09 21:11:46 +01002743 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302744 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2745 if (tempbx & SetCRT2ToRAMDAC) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002746 tempbx &= (0xFF00 |
2747 SetCRT2ToRAMDAC |
Peter Huewe6896b942012-02-09 21:11:46 +01002748 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002749 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002750 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302751 }
2752 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002753 tempbx &= (~(SetCRT2ToRAMDAC |
2754 SetCRT2ToLCD |
2755 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302756 }
2757 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002758
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302759 if (!(pVBInfo->VBType & VB_NoLCD)) {
2760 if (tempbx & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002761 tempbx &= (0xFF00 |
2762 SetCRT2ToLCD |
Peter Huewe6896b942012-02-09 21:11:46 +01002763 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002764 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002765 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302766 }
2767 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002768
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302769 if (tempbx & SetCRT2ToSCART) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002770 tempbx &= (0xFF00 |
2771 SetCRT2ToSCART |
Peter Huewe6896b942012-02-09 21:11:46 +01002772 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002773 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002774 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302775 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002776
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302777 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002778 if (tempbx & SetCRT2ToYPbPr525750)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002779 tempbx &= (0xFF00 |
Peter Huewe6896b942012-02-09 21:11:46 +01002780 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002781 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302782 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002783
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302784 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002785 if (tempbx & SetCRT2ToHiVision)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002786 tempbx &= (0xFF00 |
Peter Huewe599801f2012-02-09 21:11:45 +01002787 SetCRT2ToHiVision |
Peter Huewe6896b942012-02-09 21:11:46 +01002788 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002789 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302790 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002791
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302792 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
Peter Huewe6896b942012-02-09 21:11:46 +01002793 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302794 tempbx = DisableCRT2Display;
2795 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302797 if (!(tempbx & DisableCRT2Display)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002798 if ((!(tempbx & DriverMode)) ||
2799 (!(modeflag & CRT2Mode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302800 if (pVBInfo->IF_DEF_LCDA == 1) {
Peter Huewea3d675c2012-02-09 21:11:47 +01002801 if (!(tempbx & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002802 tempbx |= (SetInSlaveMode |
2803 SetSimuScanMode);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302804 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302805 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002806
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002807 /* LCD+TV can't support in slave mode
2808 * (Force LCDA+TV->LCDB) */
2809 if ((tempbx & SetInSlaveMode) &&
Peter Huewea3d675c2012-02-09 21:11:47 +01002810 (tempbx & XGI_SetCRT2ToLCDA)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002811 tempbx ^= (SetCRT2ToLCD |
Peter Huewea3d675c2012-02-09 21:11:47 +01002812 XGI_SetCRT2ToLCDA |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002813 SetCRT2ToDualEdge);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302814 pVBInfo->SetFlag |= ReserveTVOption;
2815 }
2816 }
2817 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002818
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302819 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002820}
2821
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002822static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302823 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002824{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302825 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002826
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302827 tempbx = 0;
2828 resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002829
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302830 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002831 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2832 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002833
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302834 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002835 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302836 tempbx = temp;
Peter Huewe599801f2012-02-09 21:11:45 +01002837 if (tempbx & TVSetPAL) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002838 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01002839 TVSetPALM |
2840 TVSetPALN |
2841 TVSetPAL);
2842 if (tempbx & TVSetPALM)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002843 /* set to NTSC if PAL-M */
Peter Huewe599801f2012-02-09 21:11:45 +01002844 tempbx &= ~TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302845 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002846 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01002847 TVSetNTSCJ |
2848 TVSetPAL);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302849 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002850
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302851 if (pVBInfo->IF_DEF_LVDS == 0) {
2852 if (pVBInfo->VBInfo & SetCRT2ToSCART)
Peter Huewe599801f2012-02-09 21:11:45 +01002853 tempbx |= TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302854 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002855
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302856 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002857 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002858 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302859 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002860
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302861 if (index1 == YPbPrMode525i)
Peter Huewe599801f2012-02-09 21:11:45 +01002862 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002863
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302864 if (index1 == YPbPrMode525p)
Peter Huewe599801f2012-02-09 21:11:45 +01002865 tempbx = tempbx | TVSetYPbPr525p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302866 if (index1 == YPbPrMode750p)
Peter Huewe599801f2012-02-09 21:11:45 +01002867 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302868 }
2869 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002870
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302871 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002872 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2873 tempbx = tempbx | TVSetHiVision | TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302874 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002875
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302876 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002877 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2878 (!(pVBInfo->VBInfo & SetNotSimuMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302879 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002880
Peter Huewe599801f2012-02-09 21:11:45 +01002881 if (!(tempbx & TVSetPAL) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002882 (modeflag > 13) &&
2883 (resinfo == 8)) /* NTSC 1024x768, */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302884 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002885
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302886 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002887
Peter Huewe599801f2012-02-09 21:11:45 +01002888 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302889 if (pVBInfo->VBInfo & SetInSlaveMode)
2890 tempbx &= (~RPLLDIV2XO);
2891 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002892 if (tempbx &
Peter Huewe599801f2012-02-09 21:11:45 +01002893 (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302894 tempbx &= (~RPLLDIV2XO);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002895 else if (!(pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01002896 (VB_SIS301B |
2897 VB_SIS302B |
2898 VB_SIS301LV |
2899 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002900 VB_XGI301C))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302901 if (tempbx & TVSimuMode)
2902 tempbx &= (~RPLLDIV2XO);
2903 }
2904 }
2905 }
2906 }
2907 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002908}
2909
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002910static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2911 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002912{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302913 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002914
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302915 pVBInfo->LCDResInfo = 0;
2916 pVBInfo->LCDTypeInfo = 0;
2917 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002918
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002919 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2920 /* si+Ext_ResInfo // */
2921 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002922 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302923 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002924
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302925 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002926 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002927
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002928 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002929 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302930 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002931 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002932 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302933 tempax &= 0x0F;
2934 else
2935 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002936
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302937 if ((resinfo == 6) || (resinfo == 9)) {
2938 if (tempax >= 3)
2939 tempbx |= PanelRef75Hz;
2940 } else if ((resinfo == 7) || (resinfo == 8)) {
2941 if (tempax >= 4)
2942 tempbx |= PanelRef75Hz;
2943 }
2944 }
2945 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002946
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302947 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002948
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302949 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002950
Peter Huewea3d675c2012-02-09 21:11:47 +01002951 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302952 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002953
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302954 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002955
Aaro Koskinen58839b02011-03-13 12:26:23 +02002956 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002957
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302958 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002959
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302960 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002961
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302962 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002963
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302964 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002965
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302966 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Peter Huewe6896b942012-02-09 21:11:46 +01002967 if (((pVBInfo->VBType & VB_SIS302LV) || (pVBInfo->VBType
Peter Huewea3d675c2012-02-09 21:11:47 +01002968 & VB_XGI301C)) && (tempax & XGI_LCDDualLink)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302969 tempbx |= SetLCDDualLink;
2970 }
2971 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002972
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302973 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe255aabd2012-02-09 21:11:44 +01002974 if ((pVBInfo->LCDResInfo == Panel_1400x1050) && (pVBInfo->VBInfo
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002975 & SetCRT2ToLCD) && (resinfo == 9) &&
2976 (!(tempbx & EnableScalingLCD)))
Peter Huewe255aabd2012-02-09 21:11:44 +01002977 /* set to center in 1280x1024 LCDB for Panel_1400x1050 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002978 tempbx |= SetLCDtoNonExpanding;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302979 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002980
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302981 if (pVBInfo->IF_DEF_ExpLink == 1) {
2982 if (modeflag & HalfDCLK) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302983 if (!(tempbx & SetLCDtoNonExpanding)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01002984 tempbx |= XGI_EnableLVDSDDA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302985 } else {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002986 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2987 if (resinfo == 4) {/* 512x384 */
2988 tempbx |= XGI_EnableLVDSDDA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302989 }
2990 }
2991 }
2992 }
2993 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002994
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302995 if (pVBInfo->VBInfo & SetInSlaveMode) {
2996 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002997 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302998 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002999 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303000 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003001
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303002 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003003
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303004 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003005}
3006
Bill Pemberton108afbf2010-06-17 13:10:47 -04003007unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303008 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003009{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003010 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
3011 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
3012 break;
3013 if (pVBInfo->EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
3014 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303015 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003016
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303017 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003018}
3019
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003020static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
3021{
3022 unsigned char ujRet = 0;
3023 unsigned char i = 0;
3024
3025 for (i = 0; i < 8; i++) {
3026 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003027 ujRet |= (ujDate >> i) & 1;
3028 }
3029
3030 return ujRet;
3031}
3032
3033/*----------------------------------------------------------------------------*/
3034/* output */
3035/* bl[5] : LVDS signal */
3036/* bl[1] : LVDS backlight */
3037/* bl[0] : LVDS VDD */
3038/*----------------------------------------------------------------------------*/
3039static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
3040{
3041 unsigned char CR4A, temp;
3042
Aaro Koskinen58839b02011-03-13 12:26:23 +02003043 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02003044 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003045
Aaro Koskinen58839b02011-03-13 12:26:23 +02003046 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003047
3048 temp = XG21GPIODataTransfer(temp);
3049 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003050 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003051 return temp;
3052}
3053
3054/*----------------------------------------------------------------------------*/
3055/* output */
3056/* bl[5] : LVDS signal */
3057/* bl[1] : LVDS backlight */
3058/* bl[0] : LVDS VDD */
3059/*----------------------------------------------------------------------------*/
3060static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
3061{
3062 unsigned char CR4A, CRB4, temp;
3063
Aaro Koskinen58839b02011-03-13 12:26:23 +02003064 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02003065 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003066
Aaro Koskinen58839b02011-03-13 12:26:23 +02003067 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003068
3069 temp &= 0x0C;
3070 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003071 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003072 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003073 temp |= ((CRB4 & 0x04) << 3);
3074 return temp;
3075}
3076
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02003077/*----------------------------------------------------------------------------*/
3078/* input */
3079/* bl[5] : 1;LVDS signal on */
3080/* bl[1] : 1;LVDS backlight on */
3081/* bl[0] : 1:LVDS VDD on */
3082/* bh: 100000b : clear bit 5, to set bit5 */
3083/* 000010b : clear bit 1, to set bit1 */
3084/* 000001b : clear bit 0, to set bit0 */
3085/*----------------------------------------------------------------------------*/
3086static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
3087 struct vb_device_info *pVBInfo)
3088{
3089 unsigned char CR4A, temp;
3090
3091 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3092 tempbh &= 0x23;
3093 tempbl &= 0x23;
3094 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
3095
3096 if (tempbh & 0x20) {
3097 temp = (tempbl >> 4) & 0x02;
3098
3099 /* CR B4[1] */
3100 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
3101
3102 }
3103
3104 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
3105
3106 temp = XG21GPIODataTransfer(temp);
3107 temp &= ~tempbh;
3108 temp |= tempbl;
3109 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
3110}
3111
Aaro Koskinen776115a2011-11-27 23:03:10 +02003112static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
3113 struct vb_device_info *pVBInfo)
3114{
3115 unsigned char CR4A, temp;
3116 unsigned short tempbh0, tempbl0;
3117
3118 tempbh0 = tempbh;
3119 tempbl0 = tempbl;
3120 tempbh0 &= 0x20;
3121 tempbl0 &= 0x20;
3122 tempbh0 >>= 3;
3123 tempbl0 >>= 3;
3124
3125 if (tempbh & 0x20) {
3126 temp = (tempbl >> 4) & 0x02;
3127
3128 /* CR B4[1] */
3129 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
3130
3131 }
3132 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
3133
3134 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
3135 tempbh &= 0x03;
3136 tempbl &= 0x03;
3137 tempbh <<= 2;
3138 tempbl <<= 2; /* GPIOC,GPIOD */
3139 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
3140 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
3141}
3142
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003143/* --------------------------------------------------------------------- */
3144/* Function : XGI_XG21SetPanelDelay */
3145/* Input : */
3146/* Output : */
3147/* Description : */
3148/* I/P : bl : 1 ; T1 : the duration between CPL on and signal on */
3149/* : bl : 2 ; T2 : the duration signal on and Vdd on */
3150/* : bl : 3 ; T3 : the duration between CPL off and signal off */
3151/* : bl : 4 ; T4 : the duration signal off and Vdd off */
3152/* --------------------------------------------------------------------- */
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003153static void XGI_XG21SetPanelDelay(struct xgifb_video_info *xgifb_info,
3154 unsigned short tempbl,
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003155 struct vb_device_info *pVBInfo)
3156{
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003157 if (tempbl == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003158 mdelay(xgifb_info->lvds_data.PSC_S1);
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003159
3160 if (tempbl == 2)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003161 mdelay(xgifb_info->lvds_data.PSC_S2);
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003162
3163 if (tempbl == 3)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003164 mdelay(xgifb_info->lvds_data.PSC_S3);
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003165
3166 if (tempbl == 4)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003167 mdelay(xgifb_info->lvds_data.PSC_S4);
Aaro Koskinen9913b6c2011-11-27 23:03:11 +02003168}
3169
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003170static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
3171 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303172 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003173{
3174
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003175 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303176 if (pXGIHWDE->jChipType == XG21) {
3177 if (pVBInfo->IF_DEF_LVDS == 1) {
3178 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003179 /* LVDS VDD on */
3180 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003181 XGI_XG21SetPanelDelay(xgifb_info, 2, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303182 }
3183 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003184 /* LVDS signal on */
3185 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003186 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003187 /* LVDS backlight on */
3188 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303189 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003190 /* DVO/DVI signal on */
3191 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303192 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003193
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303194 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003195
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303196 if (pXGIHWDE->jChipType == XG27) {
3197 if (pVBInfo->IF_DEF_LVDS == 1) {
3198 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003199 /* LVDS VDD on */
3200 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003201 XGI_XG21SetPanelDelay(xgifb_info, 2, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303202 }
3203 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003204 /* LVDS signal on */
3205 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003206 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003207 /* LVDS backlight on */
3208 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303209 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003210 /* DVO/DVI signal on */
3211 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303212 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003213
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303214 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003215}
3216
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003217void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
3218 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303219 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003220{
3221
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303222 if (pXGIHWDE->jChipType == XG21) {
3223 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003224 /* LVDS backlight off */
3225 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003226 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303227 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003228 /* DVO/DVI signal off */
3229 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303230 }
3231 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003232
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303233 if (pXGIHWDE->jChipType == XG27) {
3234 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003235 /* LVDS backlight off */
3236 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02003237 XGI_XG21SetPanelDelay(xgifb_info, 3, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303238 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003239
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303240 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003241 /* DVO/DVI signal off */
3242 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303243 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003244
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003245 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003246}
3247
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003248static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003249{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003250 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303251 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003252
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02003253 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303254 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003255}
3256
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003257static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003258{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03003259 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003260}
3261
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003262static void XGI_SaveCRT2Info(unsigned short ModeNo,
3263 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003264{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303265 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003266
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003267 /* reserve CR34 for CRT1 Mode No */
3268 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303269 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
3270 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003271 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003272}
3273
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003274static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
3275 unsigned short ModeIdIndex,
3276 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003277{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303278 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003279
Aaro Koskinen6c0965f2012-04-07 01:14:11 +03003280 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003281 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
3282 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
3283 /* si+St_ModeFlag */
3284 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003285
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003286 if (modeflag & HalfDCLK)
3287 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003288
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003289 if (modeflag & DoubleScanMode)
3290 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003291
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303292 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
3293 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003294 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003295 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303296 if (yres == 1024)
3297 yres = 1056;
3298 }
3299 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003300
Peter Huewe255aabd2012-02-09 21:11:44 +01003301 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303302 if (yres == 400)
3303 yres = 405;
3304 else if (yres == 350)
3305 yres = 360;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003306
Peter Huewea3d675c2012-02-09 21:11:47 +01003307 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303308 if (yres == 360)
3309 yres = 375;
3310 }
3311 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003312
Peter Huewe255aabd2012-02-09 21:11:44 +01003313 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003314 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303315 if (!(pVBInfo->LCDInfo
3316 & LCDNonExpanding)) {
3317 if (yres == 350)
3318 yres = 357;
3319 else if (yres == 400)
3320 yres = 420;
3321 else if (yres == 480)
3322 yres = 525;
3323 }
3324 }
3325 }
3326 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003327
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303328 if (xres == 720)
3329 xres = 640;
3330 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003331
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303332 pVBInfo->VGAHDE = xres;
3333 pVBInfo->HDE = xres;
3334 pVBInfo->VGAVDE = yres;
3335 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003336}
3337
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003338static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003339{
3340
Peter Huewea3d675c2012-02-09 21:11:47 +01003341 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03003342 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303343 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003344
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303345 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003346}
3347
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003348static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
3349 unsigned short ModeIdIndex,
3350 unsigned short RefreshRateTableIndex,
3351 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003352{
3353 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003354 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003355
3356 pVBInfo->RVBHCMAX = 1;
3357 pVBInfo->RVBHCFACT = 1;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003358 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3359 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3360 CRT1Index &= IndexMask;
3361 temp1 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[0];
3362 temp2 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
3363 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
3364 tempbx = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[8];
3365 tempcx = (unsigned short)
3366 pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14] << 8;
3367 tempcx &= 0x0100;
3368 tempcx = tempcx << 2;
3369 tempbx |= tempcx;
3370 temp1 = (unsigned short) pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003371
3372 if (temp1 & 0x01)
3373 tempbx |= 0x0100;
3374
3375 if (temp1 & 0x20)
3376 tempbx |= 0x0200;
3377 tempax += 5;
3378
3379 if (modeflag & Charx8Dot)
3380 tempax *= 8;
3381 else
3382 tempax *= 9;
3383
3384 pVBInfo->VGAHT = tempax;
3385 pVBInfo->HT = tempax;
3386 tempbx++;
3387 pVBInfo->VGAVT = tempbx;
3388 pVBInfo->VT = tempbx;
3389}
3390
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003391static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303392 unsigned short RefreshRateTableIndex,
3393 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003394{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303395 unsigned short tempax = 0, tempbx, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003396
Peter Huewefc39dcb2012-01-15 19:22:12 +01003397 struct SiS_LCDData *LCDPtr = NULL;
3398 struct SiS_TVData *TVPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003399
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003400 /* si+Ext_ResInfo */
3401 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3402 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303403 pVBInfo->NewFlickerMode = 0;
3404 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003405
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303406 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3407 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3408 pVBInfo);
3409 return;
3410 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003411
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303412 tempbx = 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003413
Peter Huewea3d675c2012-02-09 21:11:47 +01003414 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewefc39dcb2012-01-15 19:22:12 +01003415 LCDPtr = (struct SiS_LCDData *) XGI_GetLcdPtr(tempbx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303416 ModeNo, ModeIdIndex, RefreshRateTableIndex,
3417 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003418
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303419 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
3420 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
3421 pVBInfo->VGAHT = LCDPtr->VGAHT;
3422 pVBInfo->VGAVT = LCDPtr->VGAVT;
3423 pVBInfo->HT = LCDPtr->LCDHT;
3424 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003425
Peter Huewe255aabd2012-02-09 21:11:44 +01003426 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303427 tempax = 1024;
3428 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003429
Peter Huewea3d675c2012-02-09 21:11:47 +01003430 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303431 if (pVBInfo->VGAVDE == 357)
3432 tempbx = 527;
3433 else if (pVBInfo->VGAVDE == 420)
3434 tempbx = 620;
3435 else if (pVBInfo->VGAVDE == 525)
3436 tempbx = 775;
3437 else if (pVBInfo->VGAVDE == 600)
3438 tempbx = 775;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303439 else
3440 tempbx = 768;
3441 } else
3442 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003443 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303444 tempax = 1024;
3445 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003446 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303447 tempax = 1280;
3448 if (pVBInfo->VGAVDE == 360)
3449 tempbx = 768;
3450 else if (pVBInfo->VGAVDE == 375)
3451 tempbx = 800;
3452 else if (pVBInfo->VGAVDE == 405)
3453 tempbx = 864;
3454 else
3455 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003456 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303457 tempax = 1280;
3458 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003459 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303460 tempax = 1280;
3461 if (pVBInfo->VGAVDE == 350)
3462 tempbx = 700;
3463 else if (pVBInfo->VGAVDE == 400)
3464 tempbx = 800;
3465 else if (pVBInfo->VGAVDE == 1024)
3466 tempbx = 960;
3467 else
3468 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01003469 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303470 tempax = 1400;
3471 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003472
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303473 if (pVBInfo->VGAVDE == 1024) {
3474 tempax = 1280;
3475 tempbx = 1024;
3476 }
Peter Huewe255aabd2012-02-09 21:11:44 +01003477 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303478 tempax = 1600;
3479 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01003480 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303481 if (pVBInfo->VGAVDE == 350)
3482 tempbx = 875;
3483 else if (pVBInfo->VGAVDE == 400)
3484 tempbx = 1000;
3485 }
3486 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003487
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303488 if (pVBInfo->LCDInfo & LCDNonExpanding) {
3489 tempax = pVBInfo->VGAHDE;
3490 tempbx = pVBInfo->VGAVDE;
3491 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003492
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303493 pVBInfo->HDE = tempax;
3494 pVBInfo->VDE = tempbx;
3495 return;
3496 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003497
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303498 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
3499 tempbx = 4;
Peter Huewefc39dcb2012-01-15 19:22:12 +01003500 TVPtr = (struct SiS_TVData *) XGI_GetTVPtr(tempbx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303501 ModeNo, ModeIdIndex, RefreshRateTableIndex,
3502 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003503
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303504 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
3505 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
3506 pVBInfo->VGAHT = TVPtr->VGAHT;
3507 pVBInfo->VGAVT = TVPtr->VGAVT;
3508 pVBInfo->HDE = TVPtr->TVHDE;
3509 pVBInfo->VDE = TVPtr->TVVDE;
3510 pVBInfo->RVBHRS = TVPtr->RVBHRS;
3511 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003512
Peter Huewe599801f2012-02-09 21:11:45 +01003513 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303514 if (resinfo == 0x08)
3515 pVBInfo->NewFlickerMode = 0x40;
3516 else if (resinfo == 0x09)
3517 pVBInfo->NewFlickerMode = 0x40;
3518 else if (resinfo == 0x12)
3519 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003520
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303521 if (pVBInfo->VGAVDE == 350)
3522 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003523
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303524 tempax = ExtHiTVHT;
3525 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003526
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303527 if (pVBInfo->VBInfo & SetInSlaveMode) {
3528 if (pVBInfo->TVInfo & TVSimuMode) {
3529 tempax = StHiTVHT;
3530 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003531
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303532 if (!(modeflag & Charx8Dot)) {
3533 tempax = StHiTextTVHT;
3534 tempbx = StHiTextTVVT;
3535 }
3536 }
3537 }
Peter Huewe599801f2012-02-09 21:11:45 +01003538 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3539 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303540 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
3541 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
3542 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003543
Peter Huewe599801f2012-02-09 21:11:45 +01003544 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303545 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
3546 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01003547 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303548 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
3549 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
3550 if (pVBInfo->TVInfo & NTSC1024x768)
3551 tempax = NTSC1024x768HT;
3552 }
3553 } else {
3554 tempax = PALHT;
3555 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01003556 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303557 tempax = NTSCHT;
3558 tempbx = NTSCVT;
3559 if (pVBInfo->TVInfo & NTSC1024x768)
3560 tempax = NTSC1024x768HT;
3561 }
3562 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003563
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303564 pVBInfo->HT = tempax;
3565 pVBInfo->VT = tempbx;
3566 return;
3567 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003568}
3569
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003570static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303571 unsigned short RefreshRateTableIndex,
3572 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003573{
Bill Pemberton108afbf2010-06-17 13:10:47 -04003574 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003575
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303576 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
3577 pVBInfo);
3578 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
3579 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003580
Peter Huewe6896b942012-02-09 21:11:46 +01003581 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303582 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003583 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
3584 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
3585 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303586 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003587 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
3588 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303589 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003590
Aaro Koskinen8104e322011-03-13 12:26:22 +02003591 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003592
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303593 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02003594 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303595 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02003596 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003597}
3598
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003599static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
3600 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003601{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003602 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
3603 short index;
3604 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303605
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003606 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01003607 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303608
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003609 if (index < 0)
3610 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303611
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003612 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303613}
3614
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003615static unsigned short XGI_GetOffset(unsigned short ModeNo,
3616 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303617 unsigned short RefreshRateTableIndex,
3618 struct xgi_hw_device_info *HwDeviceExtension,
3619 struct vb_device_info *pVBInfo)
3620{
3621 unsigned short temp, colordepth, modeinfo, index, infoflag,
3622 ColorDepth[] = { 0x01, 0x02, 0x04 };
3623
3624 modeinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003625 infoflag = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303626
3627 index = (modeinfo >> 8) & 0xFF;
3628
3629 temp = pVBInfo->ScreenOffset[index];
3630
3631 if (infoflag & InterlaceMode)
3632 temp = temp << 1;
3633
3634 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
3635
3636 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
3637 temp = ModeNo - 0x7C;
3638 colordepth = ColorDepth[temp];
3639 temp = 0x6B;
3640 if (infoflag & InterlaceMode)
3641 temp = temp << 1;
3642 return temp * colordepth;
3643 } else {
3644 return temp * colordepth;
3645 }
3646}
3647
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003648static void XGI_SetCRT2Offset(unsigned short ModeNo,
3649 unsigned short ModeIdIndex,
3650 unsigned short RefreshRateTableIndex,
3651 struct xgi_hw_device_info *HwDeviceExtension,
3652 struct vb_device_info *pVBInfo)
3653{
3654 unsigned short offset;
3655 unsigned char temp;
3656
3657 if (pVBInfo->VBInfo & SetInSlaveMode)
3658 return;
3659
3660 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3661 HwDeviceExtension, pVBInfo);
3662 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003663 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003664 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003665 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003666 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003667 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003668}
3669
Randy Dunlap89229672010-08-10 08:46:44 -07003670static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003671{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003672 /* threshold high ,disable auto threshold */
3673 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
3674 /* threshold low default 04h */
3675 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003676}
3677
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003678static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303679 struct xgi_hw_device_info *HwDeviceExtension,
3680 unsigned short RefreshRateTableIndex,
3681 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003682{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303683 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003684
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003685 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3686 CRT1Index &= IndexMask;
3687 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003688
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303689 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3690 HwDeviceExtension, pVBInfo);
3691 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003692
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303693 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003694 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003695
Aaro Koskinen8104e322011-03-13 12:26:22 +02003696 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
3697 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003698}
3699
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003700static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303701 struct xgi_hw_device_info *HwDeviceExtension,
3702 unsigned short RefreshRateTableIndex,
3703 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003704{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303705 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
3706 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003707
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003708 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3709 CRT1Index &= IndexMask;
3710 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3711 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003712
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303713 /* bainy change table name */
3714 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003715 /* BTVGA2HT 0x08,0x09 */
3716 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003717 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303718 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003719 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003720 /* BTVGA2HDEE 0x0A,0x0C */
3721 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003722 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303723 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
3724 pushbx = pVBInfo->VGAHDE / 2 + 16;
3725 tempcx = tempcx >> 1;
3726 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3727 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003728
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303729 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3730 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003731 tempbx |= ((pVBInfo->
3732 XGINEWUB_CRT1Table[CRT1Index].CR[14] &
3733 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303734 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
3735 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[5];
3736 tempcx &= 0x1F;
3737 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[15];
3738 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3739 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3740 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003741
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303742 tempbx += 4;
3743 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003744
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303745 if (tempcx > (pVBInfo->VGAHT / 2))
3746 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003747
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303748 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003749
Aaro Koskinen8104e322011-03-13 12:26:22 +02003750 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303751 } else {
3752 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003753 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303754 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003755 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003756 /* BTVGA2HDEE 0x0A,0x0C */
3757 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003758 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303759 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
3760 pushbx = pVBInfo->VGAHDE + 16;
3761 tempcx = tempcx >> 1;
3762 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3763 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003764
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303765 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3766 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[3];
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003767 tempbx |= ((pVBInfo->
3768 XGINEWUB_CRT1Table[CRT1Index].CR[5] &
3769 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303770 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
3771 tempcx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[4];
3772 tempcx &= 0x1F;
3773 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[6];
3774 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3775 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3776 tempbx += 16;
3777 tempcx += 16;
3778 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003779
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303780 if (tempcx > pVBInfo->VGAHT)
3781 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003782
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303783 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003784 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303785 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003786
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303787 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
3788 tempbx = pushbx;
3789 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
3790 tempax |= (tempbx & 0xFF00);
3791 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003792 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303793 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003794 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303795 tempcx = (pVBInfo->VGAVT - 1);
3796 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003797
Aaro Koskinen8104e322011-03-13 12:26:22 +02003798 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303799 tempbx = pVBInfo->VGAVDE - 1;
3800 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003801 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303802 temp = ((tempbx & 0xFF00) << 3) >> 8;
3803 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003804 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003805
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303806 tempax = pVBInfo->VGAVDE;
3807 tempbx = pVBInfo->VGAVDE;
3808 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003809 /* BTVGA2VRS 0x10,0x11 */
3810 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
3811 /* BTVGA2VRE 0x11 */
3812 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003813
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303814 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
3815 tempbx = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[10];
3816 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003817
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303818 if (temp & 0x04)
3819 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003820
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303821 if (temp & 0x080)
3822 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003823
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303824 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003825
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303826 if (temp & 0x08)
3827 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003828
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303829 temp = pVBInfo->XGINEWUB_CRT1Table[CRT1Index].CR[11];
3830 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
3831 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003832
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303833 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003834 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303835 temp = ((tempbx & 0xFF00) >> 8) << 4;
3836 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02003837 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303838 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003839
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303840 if (modeflag & DoubleScanMode)
3841 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003842
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303843 if (modeflag & HalfDCLK)
3844 tempax |= 0x40;
3845
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003846 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003847}
3848
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003849static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
3850{
3851 unsigned long tempax, tempbx;
3852
3853 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
3854 & 0xFFFF;
3855 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
3856 tempax = (tempax * pVBInfo->HT) / tempbx;
3857
3858 return (unsigned short) tempax;
3859}
3860
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003861static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303862 struct xgi_hw_device_info *HwDeviceExtension,
3863 unsigned short RefreshRateTableIndex,
3864 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003865{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303866 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
3867 modeflag, CRT1Index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003868
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003869 /* si+Ext_ResInfo */
3870 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3871 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
3872 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
3873 CRT1Index &= IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003874
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303875 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3876 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003877
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303878 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003879 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303880 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003881
Peter Huewe6896b942012-02-09 21:11:46 +01003882 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303883 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003884
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303885 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003886
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303887 if (modeflag & HalfDCLK)
3888 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003889
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303890 tempax = (tempax / tempcx) - 1;
3891 tempbx |= ((tempax & 0x00FF) << 8);
3892 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003893 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003894
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303895 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003896
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303897 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01003898 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3899 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303900 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003901
Peter Huewe599801f2012-02-09 21:11:45 +01003902 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003903 if (pVBInfo->VBType & VB_SIS301LV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303904 if (pVBInfo->VBExtInfo == VB_YPbPr1080i) {
3905 if (resinfo == 7)
3906 temp -= 2;
3907 }
3908 } else if (resinfo == 7) {
3909 temp -= 2;
3910 }
3911 }
3912 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003913
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003914 /* 0x05 Horizontal Display Start */
3915 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3916 /* 0x06 Horizontal Blank end */
3917 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003918
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303919 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3920 if (pVBInfo->VBInfo & SetCRT2ToTV)
3921 tempax = pVBInfo->VGAHT;
3922 else
3923 tempax = XGI_GetVGAHT2(pVBInfo);
3924 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003925
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303926 if (tempax >= pVBInfo->VGAHT)
3927 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003928
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303929 if (modeflag & HalfDCLK)
3930 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003931
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303932 tempax = (tempax / tempcx) - 5;
3933 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003934 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303935 temp = (tempbx & 0x00FF) - 1;
3936 if (!(modeflag & HalfDCLK)) {
3937 temp -= 6;
3938 if (pVBInfo->TVInfo & TVSimuMode) {
3939 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003940 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303941 }
3942 }
3943 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303944 tempbx = (tempbx & 0xFF00) >> 8;
3945 tempcx = (tempcx + tempbx) >> 1;
3946 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003947
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303948 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3949 temp -= 1;
3950 if (!(modeflag & HalfDCLK)) {
3951 if ((modeflag & Charx8Dot)) {
3952 temp += 4;
3953 if (pVBInfo->VGAHDE >= 800)
3954 temp -= 6;
3955 }
3956 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003957 } else if (!(modeflag & HalfDCLK)) {
3958 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003959 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003960 pVBInfo->VGAHDE >= 800) {
3961 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003962 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003963 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003964 (pVBInfo->LCDInfo & LCDNonExpanding))
3965 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303966 }
3967 }
3968 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003969
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003970 /* 0x07 Horizontal Retrace Start */
3971 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3972 /* 0x08 Horizontal Retrace End */
3973 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003974
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303975 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3976 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003977 if (ModeNo == 0x50) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303978 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003979 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303980 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003981 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303982 0x08, 0x03);
3983 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003984 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303985 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003986 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303987 0x08, 0x02);
3988 }
3989 }
3990 }
3991 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003992
Aaro Koskinen8104e322011-03-13 12:26:22 +02003993 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003994 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003995 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003996
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303997 tempbx = pVBInfo->VGAVT;
3998 push1 = tempbx;
3999 tempcx = 0x121;
4000 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004001
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304002 if (tempbx == 357)
4003 tempbx = 350;
4004 if (tempbx == 360)
4005 tempbx = 350;
4006 if (tempbx == 375)
4007 tempbx = 350;
4008 if (tempbx == 405)
4009 tempbx = 400;
4010 if (tempbx == 525)
4011 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004012
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304013 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004014
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304015 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01004016 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004017 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304018 if (tempbx == 350)
4019 tempbx += 5;
4020 if (tempbx == 480)
4021 tempbx += 5;
4022 }
4023 }
4024 }
4025 tempbx--;
4026 temp = tempbx & 0x00FF;
4027 tempbx--;
4028 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004029 /* 0x10 vertical Blank Start */
4030 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304031 tempbx = push2;
4032 tempbx--;
4033 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004034 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004035
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304036 if (tempbx & 0x0100)
4037 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004038
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304039 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004040
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304041 if (modeflag & DoubleScanMode)
4042 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004043
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304044 if (tempbx & 0x0200)
4045 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004046
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304047 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004048 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004049
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304050 if (tempbx & 0x0400)
4051 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004052
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004053 /* 0x11 Vertival Blank End */
4054 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304055
4056 tempax = push1;
4057 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
4058 tempax = tempax >> 2;
4059 push1 = tempax; /* push ax */
4060
4061 if (resinfo != 0x09) {
4062 tempax = tempax << 1;
4063 tempbx += tempax;
4064 }
4065
Peter Huewe599801f2012-02-09 21:11:45 +01004066 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01004067 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01004068 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304069 tempbx -= 10;
4070 } else {
4071 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Huewe599801f2012-02-09 21:11:45 +01004072 if (pVBInfo->TVInfo & TVSetPAL) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004073 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004074 VB_SIS301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004075 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01004076 (TVSetYPbPr525p |
4077 TVSetYPbPr750p |
4078 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304079 tempbx += 40;
4080 } else {
4081 tempbx += 40;
4082 }
4083 }
4084 }
4085 }
4086 } else {
4087 tempbx -= 10;
4088 }
4089 } else {
4090 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Huewe599801f2012-02-09 21:11:45 +01004091 if (pVBInfo->TVInfo & TVSetPAL) {
Peter Huewe6896b942012-02-09 21:11:46 +01004092 if (pVBInfo->VBType & VB_SIS301LV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004093 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01004094 (TVSetYPbPr525p |
4095 TVSetYPbPr750p |
4096 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304097 tempbx += 40;
4098 } else {
4099 tempbx += 40;
4100 }
4101 }
4102 }
4103 }
4104 tempax = push1;
4105 tempax = tempax >> 2;
4106 tempax++;
4107 tempax += tempbx;
4108 push1 = tempax; /* push ax */
4109
Peter Huewe599801f2012-02-09 21:11:45 +01004110 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304111 if (tempbx <= 513) {
4112 if (tempax >= 513)
4113 tempbx = 513;
4114 }
4115 }
4116
4117 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004118 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304119 tempbx--;
4120 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004121 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304122
4123 if (tempbx & 0x0100)
4124 tempcx |= 0x0008;
4125
4126 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004127 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304128
4129 tempbx++;
4130
4131 if (tempbx & 0x0100)
4132 tempcx |= 0x0004;
4133
4134 if (tempbx & 0x0200)
4135 tempcx |= 0x0080;
4136
4137 if (tempbx & 0x0400)
4138 tempcx |= 0x0C00;
4139
4140 tempbx = push1; /* pop ax */
4141 temp = tempbx & 0x00FF;
4142 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004143 /* 0x0D vertical Retrace End */
4144 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304145
4146 if (tempbx & 0x0010)
4147 tempcx |= 0x2000;
4148
4149 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004150 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304151 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004152 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304153 tempax = modeflag;
4154 temp = (tempax & 0xFF00) >> 8;
4155
4156 temp = (temp >> 1) & 0x09;
4157
Peter Huewe6896b942012-02-09 21:11:46 +01004158 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304159 temp |= 0x01;
4160
Aaro Koskinen8104e322011-03-13 12:26:22 +02004161 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
4162 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
4163 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304164
4165 if (pVBInfo->LCDInfo & LCDRGB18Bit)
4166 temp = 0x80;
4167 else
4168 temp = 0x00;
4169
Aaro Koskinen8104e322011-03-13 12:26:22 +02004170 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304171
4172 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004173}
4174
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004175static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304176 unsigned short RefreshRateTableIndex,
4177 struct xgi_hw_device_info *HwDeviceExtension,
4178 struct vb_device_info *pVBInfo)
4179{
4180 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
4181 modeflag, resinfo, crt2crtc;
4182 unsigned char *TimingPoint;
4183
4184 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
4185
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004186 /* si+Ext_ResInfo */
4187 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4188 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4189 crt2crtc = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304190
4191 tempax = 0;
4192
4193 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
4194 tempax |= 0x0800;
4195
4196 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4197 tempax |= 0x0400;
4198
4199 if (pVBInfo->VBInfo & SetCRT2ToSCART)
4200 tempax |= 0x0200;
4201
Peter Huewe599801f2012-02-09 21:11:45 +01004202 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304203 tempax |= 0x1000;
4204
Peter Huewe599801f2012-02-09 21:11:45 +01004205 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304206 tempax |= 0x0100;
4207
Peter Huewe599801f2012-02-09 21:11:45 +01004208 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304209 tempax &= 0xfe00;
4210
4211 tempax = (tempax & 0xff00) >> 8;
4212
Aaro Koskinen8104e322011-03-13 12:26:22 +02004213 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304214 TimingPoint = pVBInfo->NTSCTiming;
4215
Peter Huewe599801f2012-02-09 21:11:45 +01004216 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304217 TimingPoint = pVBInfo->PALTiming;
4218
Peter Huewe599801f2012-02-09 21:11:45 +01004219 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304220 TimingPoint = pVBInfo->HiTVExtTiming;
4221
4222 if (pVBInfo->VBInfo & SetInSlaveMode)
4223 TimingPoint = pVBInfo->HiTVSt2Timing;
4224
4225 if (pVBInfo->SetFlag & TVSimuMode)
4226 TimingPoint = pVBInfo->HiTVSt1Timing;
4227
4228 if (!(modeflag & Charx8Dot))
4229 TimingPoint = pVBInfo->HiTVTextTiming;
4230 }
4231
Peter Huewe599801f2012-02-09 21:11:45 +01004232 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4233 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304234 TimingPoint = pVBInfo->YPbPr525iTiming;
4235
Peter Huewe599801f2012-02-09 21:11:45 +01004236 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304237 TimingPoint = pVBInfo->YPbPr525pTiming;
4238
Peter Huewe599801f2012-02-09 21:11:45 +01004239 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304240 TimingPoint = pVBInfo->YPbPr750pTiming;
4241 }
4242
4243 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004244 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304245
4246 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004247 /* di->temp2[j] */
4248 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304249
4250 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004251 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304252
4253 temp = pVBInfo->NewFlickerMode;
4254 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004255 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304256
Peter Huewe599801f2012-02-09 21:11:45 +01004257 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304258 tempax = 950;
4259
Peter Huewe599801f2012-02-09 21:11:45 +01004260 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304261 tempax = 520;
4262 else
4263 tempax = 440;
4264
4265 if (pVBInfo->VDE <= tempax) {
4266 tempax -= pVBInfo->VDE;
4267 tempax = tempax >> 2;
4268 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
4269 push1 = tempax;
4270 temp = (tempax & 0xFF00) >> 8;
4271 temp += (unsigned short) TimingPoint[0];
4272
Peter Huewe6896b942012-02-09 21:11:46 +01004273 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4274 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304275 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4276 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01004277 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304278 tempcx = pVBInfo->VGAHDE;
4279 if (tempcx >= 1024) {
4280 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01004281 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304282 temp = 0x19; /* PAL */
4283 }
4284 }
4285 }
4286
Aaro Koskinen8104e322011-03-13 12:26:22 +02004287 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304288 tempax = push1;
4289 temp = (tempax & 0xFF00) >> 8;
4290 temp += TimingPoint[1];
4291
Peter Huewe6896b942012-02-09 21:11:46 +01004292 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4293 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304294 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
4295 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01004296 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304297 tempcx = pVBInfo->VGAHDE;
4298 if (tempcx >= 1024) {
4299 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01004300 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304301 temp = 0x52; /* PAL */
4302 }
4303 }
4304 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004305 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304306 }
4307
4308 /* 301b */
4309 tempcx = pVBInfo->HT;
4310
4311 if (XGI_IsLCDDualLink(pVBInfo))
4312 tempcx = tempcx >> 1;
4313
4314 tempcx -= 2;
4315 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004316 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304317
4318 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004319 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304320
4321 tempcx = pVBInfo->HT >> 1;
4322 push1 = tempcx; /* push cx */
4323 tempcx += 7;
4324
Peter Huewe599801f2012-02-09 21:11:45 +01004325 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304326 tempcx -= 4;
4327
4328 temp = tempcx & 0x00FF;
4329 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004330 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304331
4332 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
4333 tempbx += tempcx;
4334 push2 = tempbx;
4335 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004336 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304337 temp = (tempbx & 0xFF00) >> 8;
4338 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004339 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304340
4341 tempbx = push2;
4342 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004343 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304344 tempbx = tempbx - 4;
4345 tempcx = tempbx;
4346 }
4347
4348 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004349 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304350
4351 j += 2;
4352 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
4353 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004354 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304355 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004356 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304357
4358 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004359 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304360 tempcx -= 4;
4361
4362 temp = tempcx & 0xFF;
4363 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004364 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304365
4366 tempcx = push1; /* pop cx */
4367 j += 2;
4368 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
4369 tempcx -= temp;
4370 temp = tempcx & 0x00FF;
4371 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004372 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304373
4374 tempcx -= 11;
4375
4376 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
4377 tempax = XGI_GetVGAHT2(pVBInfo);
4378 tempcx = tempax - 1;
4379 }
4380 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004381 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304382
4383 tempbx = pVBInfo->VDE;
4384
4385 if (pVBInfo->VGAVDE == 360)
4386 tempbx = 746;
4387 if (pVBInfo->VGAVDE == 375)
4388 tempbx = 746;
4389 if (pVBInfo->VGAVDE == 405)
4390 tempbx = 853;
4391
4392 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004393 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004394 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004395 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01004396 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304397 tempbx = tempbx >> 1;
4398 } else
4399 tempbx = tempbx >> 1;
4400 }
4401
4402 tempbx -= 2;
4403 temp = tempbx & 0x00FF;
4404
Peter Huewe599801f2012-02-09 21:11:45 +01004405 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01004406 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01004407 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304408 if (pVBInfo->VBInfo & SetInSlaveMode) {
4409 if (ModeNo == 0x2f)
4410 temp += 1;
4411 }
4412 }
4413 } else {
4414 if (pVBInfo->VBInfo & SetInSlaveMode) {
4415 if (ModeNo == 0x2f)
4416 temp += 1;
4417 }
4418 }
4419 }
4420
Aaro Koskinen8104e322011-03-13 12:26:22 +02004421 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304422
4423 temp = (tempcx & 0xFF00) >> 8;
4424 temp |= ((tempbx & 0xFF00) >> 8) << 6;
4425
Peter Huewe599801f2012-02-09 21:11:45 +01004426 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01004427 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01004428 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304429 temp |= 0x10;
4430
4431 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4432 temp |= 0x20;
4433 }
4434 } else {
4435 temp |= 0x10;
4436 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
4437 temp |= 0x20;
4438 }
4439 }
4440
Aaro Koskinen8104e322011-03-13 12:26:22 +02004441 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304442
Peter Huewe6896b942012-02-09 21:11:46 +01004443 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4444 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304445 tempbx = pVBInfo->VDE;
4446 tempcx = tempbx - 2;
4447
4448 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01004449 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
4450 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304451 tempbx = tempbx >> 1;
4452 }
4453
Peter Huewe6896b942012-02-09 21:11:46 +01004454 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304455 temp = 0;
4456 if (tempcx & 0x0400)
4457 temp |= 0x20;
4458
4459 if (tempbx & 0x0400)
4460 temp |= 0x40;
4461
Aaro Koskinen8104e322011-03-13 12:26:22 +02004462 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304463 }
4464
4465 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004466 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304467 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004468 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304469 }
4470
4471 tempbx = tempbx & 0x00FF;
4472
4473 if (!(modeflag & HalfDCLK)) {
4474 tempcx = pVBInfo->VGAHDE;
4475 if (tempcx >= pVBInfo->HDE) {
4476 tempbx |= 0x2000;
4477 tempax &= 0x00FF;
4478 }
4479 }
4480
4481 tempcx = 0x0101;
4482
4483 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
4484 if (pVBInfo->VGAHDE >= 1024) {
4485 tempcx = 0x1920;
4486 if (pVBInfo->VGAHDE >= 1280) {
4487 tempcx = 0x1420;
4488 tempbx = tempbx & 0xDFFF;
4489 }
4490 }
4491 }
4492
4493 if (!(tempbx & 0x2000)) {
4494 if (modeflag & HalfDCLK)
4495 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
4496
4497 push1 = tempbx;
4498 tempeax = pVBInfo->VGAHDE;
4499 tempebx = (tempcx & 0xFF00) >> 8;
4500 longtemp = tempeax * tempebx;
4501 tempecx = tempcx & 0x00FF;
4502 longtemp = longtemp / tempecx;
4503
4504 /* 301b */
4505 tempecx = 8 * 1024;
4506
Peter Huewe6896b942012-02-09 21:11:46 +01004507 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4508 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304509 tempecx = tempecx * 8;
4510 }
4511
4512 longtemp = longtemp * tempecx;
4513 tempecx = pVBInfo->HDE;
4514 temp2 = longtemp % tempecx;
4515 tempeax = longtemp / tempecx;
4516 if (temp2 != 0)
4517 tempeax += 1;
4518
4519 tempax = (unsigned short) tempeax;
4520
4521 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004522 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4523 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304524 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
4525 }
4526 /* end 301b */
4527
4528 tempbx = push1;
4529 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
4530 | (tempbx & 0x00FF));
4531 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
4532 | (tempax & 0x00FF));
4533 temp = (tempax & 0xFF00) >> 8;
4534 } else {
4535 temp = (tempax & 0x00FF) >> 8;
4536 }
4537
Aaro Koskinen8104e322011-03-13 12:26:22 +02004538 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304539 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004540 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304541 temp = tempcx & 0x00FF;
4542
4543 if (tempbx & 0x2000)
4544 temp = 0;
4545
4546 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
4547 temp |= 0x18;
4548
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004549 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01004550 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304551 tempbx = 0x0382;
4552 tempcx = 0x007e;
4553 } else {
4554 tempbx = 0x0369;
4555 tempcx = 0x0061;
4556 }
4557
4558 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004559 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304560 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004561 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304562
4563 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
4564 temp = temp << 2;
4565 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
4566
Peter Huewe599801f2012-02-09 21:11:45 +01004567 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304568 temp |= 0x10;
4569
Peter Huewe599801f2012-02-09 21:11:45 +01004570 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304571 temp |= 0x20;
4572
Peter Huewe599801f2012-02-09 21:11:45 +01004573 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304574 temp |= 0x60;
4575 }
4576
Aaro Koskinen8104e322011-03-13 12:26:22 +02004577 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02004578 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004579 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304580
Peter Huewe599801f2012-02-09 21:11:45 +01004581 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304582 if (pVBInfo->TVInfo & NTSC1024x768) {
4583 TimingPoint = XGI_NTSC1024AdjTime;
4584 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004585 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304586 TimingPoint[j]);
4587 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004588 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304589 }
4590 }
4591
Miguel Gómez949eb0a2012-07-06 12:40:36 +02004592 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304593 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01004594 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004595 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304596 0x08); /* PALM Mode */
4597 }
4598
Peter Huewe599801f2012-02-09 21:11:45 +01004599 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02004600 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304601 0x01);
4602 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02004603 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304604
Aaro Koskinendc505562011-03-13 12:26:26 +02004605 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304606 }
4607
Peter Huewe599801f2012-02-09 21:11:45 +01004608 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304609 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02004610 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304611 }
4612
4613 if (pVBInfo->VBInfo & SetCRT2ToTV)
4614 return;
4615}
4616
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004617static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304618 struct xgi_hw_device_info *HwDeviceExtension,
4619 unsigned short RefreshRateTableIndex,
4620 struct vb_device_info *pVBInfo)
4621{
4622 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
4623 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
4624
4625 struct XGI_LCDDesStruct *LCDBDesPtr = NULL;
4626
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004627 /* si+Ext_ResInfo */
4628 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
4629 resinfo = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
4630 CRT1Index = pVBInfo->RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
4631 CRT1Index &= IndexMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304632
4633 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
4634 return;
4635
4636 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
4637
4638 if (XGI_IsLCDDualLink(pVBInfo))
4639 tempbx = tempbx >> 1;
4640
4641 tempbx -= 1;
4642 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004643 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304644 temp = (tempbx & 0xFF00) >> 8;
4645 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004646 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304647 temp = 0x01;
4648
Aaro Koskinen8104e322011-03-13 12:26:22 +02004649 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304650 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
4651 push1 = tempbx;
4652 tempbx--;
4653 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004654 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304655 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004656 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304657
4658 tempcx = pVBInfo->VT - 1;
4659 push2 = tempcx + 1;
4660 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004661 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304662 temp = (tempcx & 0xFF00) >> 8;
4663 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004664 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004665 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
4666 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
4667 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
4668 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304669
4670 /* Customized LCDB Des no add */
4671 tempbx = 5;
4672 LCDBDesPtr = (struct XGI_LCDDesStruct *) XGI_GetLcdPtr(tempbx, ModeNo,
4673 ModeIdIndex, RefreshRateTableIndex, pVBInfo);
4674 tempah = pVBInfo->LCDResInfo;
4675 tempah &= PanelResInfo;
4676
Peter Huewe255aabd2012-02-09 21:11:44 +01004677 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304678 tempbx = 1024;
4679 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01004680 } else if ((tempah == Panel_1280x1024) ||
4681 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304682 tempbx = 1280;
4683 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01004684 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304685 tempbx = 1400;
4686 tempcx = 1050;
4687 } else {
4688 tempbx = 1600;
4689 tempcx = 1200;
4690 }
4691
4692 if (pVBInfo->LCDInfo & EnableScalingLCD) {
4693 tempbx = pVBInfo->HDE;
4694 tempcx = pVBInfo->VDE;
4695 }
4696
4697 pushbx = tempbx;
4698 tempax = pVBInfo->VT;
4699 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
4700 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
4701 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
4702 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
4703 tempbx = pVBInfo->LCDVDES;
4704 tempcx += tempbx;
4705
4706 if (tempcx >= tempax)
4707 tempcx -= tempax; /* lcdvdes */
4708
4709 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004710 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304711 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004712 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304713 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
4714 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
4715 tempah = tempch;
4716 tempah = tempah << 3;
4717 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004718 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304719
4720 /* getlcdsync() */
4721 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4722 tempcx = tempbx;
4723 tempax = pVBInfo->VT;
4724 tempbx = pVBInfo->LCDVRS;
4725
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304726 tempcx += tempbx;
4727 if (tempcx >= tempax)
4728 tempcx -= tempax;
4729
4730 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004731 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304732 temp = (tempbx & 0xFF00) >> 8;
4733 temp = temp << 4;
4734 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004735 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304736 tempcx = pushbx;
4737 tempax = pVBInfo->HT;
4738 tempbx = pVBInfo->LCDHDES;
4739 tempbx &= 0x0FFF;
4740
4741 if (XGI_IsLCDDualLink(pVBInfo)) {
4742 tempax = tempax >> 1;
4743 tempbx = tempbx >> 1;
4744 tempcx = tempcx >> 1;
4745 }
4746
Peter Huewe6896b942012-02-09 21:11:46 +01004747 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304748 tempbx += 1;
4749
4750 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
4751 tempbx += 1;
4752
4753 tempcx += tempbx;
4754
4755 if (tempcx >= tempax)
4756 tempcx -= tempax;
4757
4758 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004759 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304760 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004761 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304762 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004763 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304764 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004765 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304766
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304767 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4768 tempcx = tempax;
4769 tempax = pVBInfo->HT;
4770 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304771 if (XGI_IsLCDDualLink(pVBInfo)) {
4772 tempax = tempax >> 1;
4773 tempbx = tempbx >> 1;
4774 tempcx = tempcx >> 1;
4775 }
4776
Peter Huewe6896b942012-02-09 21:11:46 +01004777 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304778 tempbx += 1;
4779
4780 tempcx += tempbx;
4781
4782 if (tempcx >= tempax)
4783 tempcx -= tempax;
4784
4785 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004786 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304787
4788 temp = (tempbx & 0xFF00) >> 8;
4789 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004790 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304791 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004792 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304793
Peter Huewea3d675c2012-02-09 21:11:47 +01004794 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304795 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01004796 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4797 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304798 | VB_XGI301C)) {
4799 temp = 0xC6;
4800 } else
4801 temp = 0xC4;
4802
Aaro Koskinen8104e322011-03-13 12:26:22 +02004803 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
4804 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304805 }
4806
4807 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01004808 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4809 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304810 | VB_XGI301C)) {
4811 temp = 0x4F;
4812 } else
4813 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004814 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304815 }
4816 }
4817}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004818
4819/* --------------------------------------------------------------------- */
4820/* Function : XGI_GetTap4Ptr */
4821/* Input : */
4822/* Output : di -> Tap4 Reg. Setting Pointer */
4823/* Description : */
4824/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004825static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304826 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004827{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304828 unsigned short tempax, tempbx, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004829
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304830 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004831
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304832 if (tempcx == 0) {
4833 tempax = pVBInfo->VGAHDE;
4834 tempbx = pVBInfo->HDE;
4835 } else {
4836 tempax = pVBInfo->VGAVDE;
4837 tempbx = pVBInfo->VDE;
4838 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004839
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004840 if (tempax <= tempbx)
4841 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304842 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004843 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004844
Peter Huewe599801f2012-02-09 21:11:45 +01004845 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304846 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004847
Peter Huewe599801f2012-02-09 21:11:45 +01004848 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4849 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
4850 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004851 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01004852 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304853 Tap4TimingPtr = YPbPr750pTap4Timing;
4854 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004855
Peter Huewe599801f2012-02-09 21:11:45 +01004856 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004857 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004858
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304859 i = 0;
4860 while (Tap4TimingPtr[i].DE != 0xFFFF) {
4861 if (Tap4TimingPtr[i].DE == tempax)
4862 break;
4863 i++;
4864 }
4865 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004866}
4867
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004868static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004869{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304870 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004871
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304872 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004873
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304874 if (!(pVBInfo->VBType & VB_XGI301C))
4875 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004876
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304877 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
4878 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004879 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004880
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004881 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004882 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004883 /* Set Vertical Scaling */
4884 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304885 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004886 xgifb_reg_set(pVBInfo->Part2Port,
4887 i,
4888 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304889 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004890
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004891 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004892 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004893 /* Enable V.Scaling */
4894 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304895 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004896 /* Enable H.Scaling */
4897 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004898}
4899
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004900static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304901 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004902{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304903 unsigned short i;
4904 unsigned char *tempdi;
4905 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004906
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004907 /* si+Ext_ResInfo */
4908 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004909
Aaro Koskinen8104e322011-03-13 12:26:22 +02004910 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01004911 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004912 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4913 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304914 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004915 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
4916 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304917 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004918
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304919 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4920 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004921
Peter Huewe599801f2012-02-09 21:11:45 +01004922 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004923 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4924 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
4925 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304926 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004927
Peter Huewe599801f2012-02-09 21:11:45 +01004928 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
4929 & SetCRT2ToYPbPr525750)) {
4930 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304931 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004932
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304933 tempdi = pVBInfo->HiTVGroup3Data;
4934 if (pVBInfo->SetFlag & TVSimuMode) {
4935 tempdi = pVBInfo->HiTVGroup3Simu;
4936 if (!(modeflag & Charx8Dot))
4937 tempdi = pVBInfo->HiTVGroup3Text;
4938 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004939
Peter Huewe599801f2012-02-09 21:11:45 +01004940 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304941 tempdi = pVBInfo->Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004942
Peter Huewe599801f2012-02-09 21:11:45 +01004943 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304944 tempdi = pVBInfo->Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004945
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304946 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004947 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004948
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304949 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004950 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004951 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304952 }
4953 }
4954 return;
4955} /* {end of XGI_SetGroup3} */
4956
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004957static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304958 unsigned short RefreshRateTableIndex,
4959 struct xgi_hw_device_info *HwDeviceExtension,
4960 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004961{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304962 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004963
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304964 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004965
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004966 /* si+Ext_ResInfo */
4967 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304968 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004969 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004970
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304971 tempbx = pVBInfo->RVBHCMAX;
4972 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004973 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304974 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4975 tempcx = pVBInfo->VGAHT - 1;
4976 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004977 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004978
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304979 temp = ((tempcx & 0xFF00) >> 8) << 3;
4980 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004981
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304982 tempcx = pVBInfo->VGAVT - 1;
4983 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4984 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004985
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304986 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004987 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304988 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004989 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004990 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304991 tempcx = pVBInfo->VBInfo;
4992 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004993
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304994 if (modeflag & HalfDCLK)
4995 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004996
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304997 if (XGI_IsLCDDualLink(pVBInfo))
4998 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004999
Peter Huewe599801f2012-02-09 21:11:45 +01005000 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305001 temp = 0;
5002 if (tempbx <= 1024)
5003 temp = 0xA0;
5004 if (tempbx == 1280)
5005 temp = 0xC0;
5006 } else if (tempcx & SetCRT2ToTV) {
5007 temp = 0xA0;
5008 if (tempbx <= 800)
5009 temp = 0x80;
5010 } else {
5011 temp = 0x80;
5012 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5013 temp = 0;
5014 if (tempbx > 800)
5015 temp = 0x60;
5016 }
5017 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005018
Peter Huewe599801f2012-02-09 21:11:45 +01005019 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305020 temp = 0x00;
5021 if (pVBInfo->VGAHDE == 1280)
5022 temp = 0x40;
5023 if (pVBInfo->VGAHDE == 1024)
5024 temp = 0x20;
5025 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005026 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005027
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305028 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005029
Peter Huewe599801f2012-02-09 21:11:45 +01005030 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305031 if (!(temp & 0xE000))
5032 tempbx = tempbx >> 1;
5033 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005034
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305035 tempcx = pVBInfo->RVBHRS;
5036 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005037 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005038
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305039 tempeax = pVBInfo->VGAVDE;
5040 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005041
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305042 if (tempeax <= tempebx) {
5043 tempcx = (tempcx & (~0x4000));
5044 tempeax = pVBInfo->VGAVDE;
5045 } else {
5046 tempeax -= tempebx;
5047 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005048
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305049 templong = (tempeax * 256 * 1024) % tempebx;
5050 tempeax = (tempeax * 256 * 1024) / tempebx;
5051 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005052
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305053 if (templong != 0)
5054 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005055
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305056 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005057 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005058
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305059 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005060 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305061 tempbx = (unsigned short) (tempebx >> 16);
5062 temp = tempbx & 0x00FF;
5063 temp = temp << 4;
5064 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005065 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005066
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305067 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01005068 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5069 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305070 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005071 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305072 tempax = pVBInfo->VGAHDE;
5073 if (modeflag & HalfDCLK)
5074 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005075
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305076 if (XGI_IsLCDDualLink(pVBInfo))
5077 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005078
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305079 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
5080 if (tempax > 800)
5081 tempax -= 800;
5082 } else {
5083 if (pVBInfo->VGAHDE > 800) {
5084 if (pVBInfo->VGAHDE == 1024)
5085 tempax = (tempax * 25 / 32) - 1;
5086 else
5087 tempax = (tempax * 20 / 32) - 1;
5088 }
5089 }
5090 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005091
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305092 temp = (tempax & 0xFF00) >> 8;
5093 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005094 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305095 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005096 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005097
Peter Huewe599801f2012-02-09 21:11:45 +01005098 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305099 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005100 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005101
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305102 }
5103 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305105 if (pVBInfo->VBInfo & SetCRT2ToTV) {
5106 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01005107 | TVSetYPbPr525p | TVSetYPbPr750p
5108 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305109 temp |= 0x0001;
5110 if ((pVBInfo->VBInfo & SetInSlaveMode)
5111 && (!(pVBInfo->TVInfo
5112 & TVSimuMode)))
5113 temp &= (~0x0001);
5114 }
5115 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005116
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005117 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305118 tempbx = pVBInfo->HT;
5119 if (XGI_IsLCDDualLink(pVBInfo))
5120 tempbx = tempbx >> 1;
5121 tempbx = (tempbx >> 1) - 2;
5122 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005123 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305124 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005125 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305126 }
5127 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005128
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305129 if (pVBInfo->ISXPDOS == 0)
5130 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5131 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005132}
5133
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005134static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
5135{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005136 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005137}
5138
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005139static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305140 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005141{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305142 unsigned short Pindex, Pdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005143
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305144 Pindex = pVBInfo->Part5Port;
5145 Pdata = pVBInfo->Part5Port + 1;
5146 if (pVBInfo->ModeType == ModeVGA) {
5147 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01005148 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305149 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305150 }
5151 }
5152 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005153}
5154
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005155static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305156 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005157{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005158 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005159}
5160
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005161static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305162 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005163{
5164
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005165 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005166}
5167
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005168static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
5169 unsigned short ModeNo, unsigned short ModeIdIndex,
5170 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005171{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005172 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005173
Aaro Koskinen6c0965f2012-04-07 01:14:11 +03005174 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005175 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
5176 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
5177 /* si+St_ModeFlag */
5178 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005179
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305180 if (!(modeflag & Charx8Dot)) {
5181 xres /= 9;
5182 xres *= 8;
5183 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005184
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005185 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
5186 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005187
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005188 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
5189 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005190
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005191 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305192 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04005193
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005194 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305195 return 0;
5196
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005197 if (xres != xgifb_info->lvds_data.LVDSHDE ||
5198 yres != xgifb_info->lvds_data.LVDSVDE) {
5199 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
5200 if (colordepth > 2)
5201 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305202 }
5203 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005204}
5205
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005206static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
5207 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005208 unsigned short ModeNo,
5209 unsigned short ModeIdIndex,
5210 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005211{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305212 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005213 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305214 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
5215 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
5216 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005217
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005218 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005219 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305220 temp &= LCDPolarity;
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005221 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005222
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005223 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005224
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005225 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005226 /* SR35[7] FP VSync polarity */
5227 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
5228 /* SR30[5] FP HSync polarity */
5229 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005230
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005231 if (chip_id == XG27)
5232 XGI_SetXG27FPBits(pVBInfo);
5233 else
5234 XGI_SetXG21FPBits(pVBInfo);
5235
Aaro Koskinen6c0965f2012-04-07 01:14:11 +03005236 resindex = pVBInfo->EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005237 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
5238 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
5239 /* si+St_ModeFlag */
5240 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005241
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305242 if (!(modeflag & Charx8Dot))
5243 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005244
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005245 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005246
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005247 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005248
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305249 if (LVDSHBS > LVDSHT)
5250 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005251
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005252 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305253 if (LVDSHRS > LVDSHT)
5254 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005255
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005256 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305257 if (LVDSHRE > LVDSHT)
5258 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005259
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005260 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005261
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005262 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005263
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005264 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005265 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305266 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005267
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305268 if (LVDSVBS > LVDSVT)
5269 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005270
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005271 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305272 if (LVDSVRS > LVDSVT)
5273 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005274
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005275 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305276 if (LVDSVRE > LVDSVT)
5277 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005278
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005279 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005280
Aaro Koskinen58839b02011-03-13 12:26:23 +02005281 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005282 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005283
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305284 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005285 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005286
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305287 /* HT SR0B[1:0] CR00 */
5288 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005289 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005290 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005291
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305292 /* HBS SR0B[5:4] CR02 */
5293 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005294 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005295 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005296
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305297 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
5298 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005299 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
5300 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
5301 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005302
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305303 /* HRS SR0B[7:6] CR04 */
5304 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005305 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005306 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005307
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305308 /* Panel HRS SR2F[1:0] SR2E[7:0] */
5309 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005310 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005311 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005312
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305313 /* HRE SR0C[2] CR05[4:0] */
5314 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005315 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
5316 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005317
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305318 /* Panel HRE SR2F[7:2] */
5319 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005320 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005321
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305322 /* VT SR0A[0] CR07[5][0] CR06 */
5323 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005324 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
5325 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
5326 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005327 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005328
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305329 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
5330 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005331 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
5332 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
5333 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005334 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005335
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305336 /* VBE SR0A[4] CR16 */
5337 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005338 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005339 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005340
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305341 /* VRS SR0A[3] CR7[7][2] CR10 */
5342 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005343 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
5344 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
5345 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005346 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005347
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005348 if (chip_id == XG27) {
5349 /* Panel VRS SR35[2:0] SR34[7:0] */
5350 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
5351 (value & 0x700) >> 8);
5352 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
5353 } else {
5354 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
5355 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
5356 (value & 0x600) >> 9);
5357 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
5358 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
5359 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005360
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305361 /* VRE SR0A[5] CR11[3:0] */
5362 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005363 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
5364 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005365
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305366 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005367 if (chip_id == XG27)
5368 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
5369 (value << 2) & 0xFC);
5370 else
5371 /* SR3F[7] has to be 0, h/w bug */
5372 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
5373 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005374
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305375 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005376
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005377 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005378 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005379 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005380 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005381 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305382 value += 0x10;
5383 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005384
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305385 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005386 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005387 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005388 /* set data, panning = 0, shift left 1 dot*/
5389 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005390
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005391 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005392 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305393
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005394 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305395 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005396
5397}
5398
5399/* --------------------------------------------------------------------- */
5400/* Function : XGI_IsLCDON */
5401/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04005402/* Output : 0 : Skip PSC Control */
5403/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005404/* Description : */
5405/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005406static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005407{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305408 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005409
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305410 tempax = pVBInfo->VBInfo;
5411 if (tempax & SetCRT2ToDualEdge)
5412 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01005413 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305414 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005415
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305416 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005417}
5418
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005419/* --------------------------------------------------------------------- */
5420/* Function : XGI_DisableChISLCD */
5421/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04005422/* Output : 0 -> Not LCD Mode */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005423/* Description : */
5424/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005425static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005426{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305427 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005428
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305429 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005430 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005431
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305432 if (tempbx & (EnableChA | DisableChA)) {
5433 if (!(tempah & 0x08)) /* Chk LCDA Mode */
5434 return 0;
5435 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005436
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305437 if (!(tempbx & (EnableChB | DisableChB)))
5438 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005439
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305440 if (tempah & 0x01) /* Chk LCDB Mode */
5441 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005442
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305443 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005444}
5445
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005446/* --------------------------------------------------------------------- */
5447/* Function : XGI_EnableChISLCD */
5448/* Input : */
5449/* Output : 0 -> Not LCD mode */
5450/* Description : */
5451/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005452static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005453{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305454 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005455
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305456 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005457 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005458
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305459 if (tempbx & (EnableChA | DisableChA)) {
5460 if (!(tempah & 0x08)) /* Chk LCDA Mode */
5461 return 0;
5462 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005463
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305464 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04005465 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005466
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305467 if (tempah & 0x01) /* Chk LCDB Mode */
5468 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005469
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305470 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005471}
5472
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005473static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
5474 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305475 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005476{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005477 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005478
Peter Huewe6896b942012-02-09 21:11:46 +01005479 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5480 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305481 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005482 if (!(pVBInfo->VBInfo &
5483 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005484 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305485 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5486 tempah = 0x7F; /* Disable Channel A */
Peter Huewea3d675c2012-02-09 21:11:47 +01005487 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005488 /* Disable Channel B */
5489 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005490
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305491 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005492 /* force to disable Cahnnel */
5493 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005494
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305495 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005496 /* Force to disable Channel B */
5497 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305498 }
5499 }
5500 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005501
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005502 /* disable part4_1f */
5503 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005504
Peter Huewe6896b942012-02-09 21:11:46 +01005505 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005506 if (((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305507 || (XGI_DisableChISLCD(pVBInfo))
5508 || (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005509 /* LVDS Driver power down */
5510 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305511 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005512
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305513 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01005514 & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305515 | SetSimuScanMode))) {
5516 if (pVBInfo->SetFlag & GatingCRT)
5517 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005518 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305519 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005520
Peter Huewea3d675c2012-02-09 21:11:47 +01005521 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305522 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01005523 & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005524 /* Power down */
5525 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305526 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005527
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005528 /* disable TV as primary VGA swap */
5529 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005530
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305531 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02005532 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005533
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005534 if ((pVBInfo->SetFlag & DisableChB) ||
5535 (pVBInfo->VBInfo &
5536 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01005537 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005538 (pVBInfo->VBInfo &
5539 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005540 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005541
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005542 if ((pVBInfo->SetFlag & DisableChB) ||
5543 (pVBInfo->VBInfo &
5544 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01005545 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005546 (pVBInfo->VBInfo &
5547 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
5548 /* save Part1 index 0 */
5549 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
5550 /* BTDAC = 1, avoid VB reset */
5551 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
5552 /* disable CRT2 */
5553 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
5554 /* restore Part1 index 0 */
5555 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305556 }
5557 } else { /* {301} */
5558 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005559 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
5560 /* Disable CRT2 */
5561 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
5562 /* Disable TV asPrimary VGA swap */
5563 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305564 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005565
Peter Huewea3d675c2012-02-09 21:11:47 +01005566 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305567 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005568 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305569 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005570}
5571
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005572/* --------------------------------------------------------------------- */
5573/* Function : XGI_GetTVPtrIndex */
5574/* Input : */
5575/* Output : */
5576/* Description : bx 0 : ExtNTSC */
5577/* 1 : StNTSC */
5578/* 2 : ExtPAL */
5579/* 3 : StPAL */
5580/* 4 : ExtHiTV */
5581/* 5 : StHiTV */
5582/* 6 : Ext525i */
5583/* 7 : St525i */
5584/* 8 : Ext525p */
5585/* 9 : St525p */
5586/* A : Ext750p */
5587/* B : St750p */
5588/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005589static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005590{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305591 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005592
Peter Huewe599801f2012-02-09 21:11:45 +01005593 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305594 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01005595 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305596 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01005597 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305598 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01005599 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305600 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01005601 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305602 tempbx = 10;
5603 if (pVBInfo->TVInfo & TVSimuMode)
5604 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005605
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305606 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005607}
5608
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005609/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005610/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005611/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005612/* Output : bx 0 : NTSC */
5613/* 1 : PAL */
5614/* 2 : PALM */
5615/* 3 : PALN */
5616/* 4 : NTSC1024x768 */
5617/* 5 : PAL-M 1024x768 */
5618/* 6-7: reserved */
5619/* cl 0 : YFilter1 */
5620/* 1 : YFilter2 */
5621/* ch 0 : 301A */
5622/* 1 : 301B/302B/301LV/302LV */
5623/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005624/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005625static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
5626 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005627{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005628 *tempbx = 0;
5629 *tempcl = 0;
5630 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005631
Peter Huewe599801f2012-02-09 21:11:45 +01005632 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005633 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005634
Peter Huewe599801f2012-02-09 21:11:45 +01005635 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005636 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005637
Peter Huewe599801f2012-02-09 21:11:45 +01005638 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005639 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005640
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005641 if (pVBInfo->TVInfo & NTSC1024x768) {
5642 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01005643 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005644 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305645 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005646
Peter Huewe6896b942012-02-09 21:11:46 +01005647 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5648 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005649 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
5650 & TVSimuMode)) {
5651 *tempbx += 8;
5652 *tempcl += 1;
5653 }
5654 }
5655
Peter Huewe6896b942012-02-09 21:11:46 +01005656 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5657 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005658 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005659}
5660
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005661static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005662{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305663 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005664
Peter Huewe6896b942012-02-09 21:11:46 +01005665 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5666 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005667 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305668 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305669 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02005670 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005671
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305672 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5673 tempbl = tempbl >> 4;
Peter Huewea3d675c2012-02-09 21:11:47 +01005674 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02005675 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005676
Peter Huewea3d675c2012-02-09 21:11:47 +01005677 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305678 tempbl = tempbh;
5679 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005680
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305681 tempbl &= 0x0F;
5682 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02005683 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005684
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305685 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
5686 | SetCRT2ToTV)) { /* Channel B */
5687 tempah &= 0xF0;
5688 tempah |= tempbl;
5689 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005690
Peter Huewea3d675c2012-02-09 21:11:47 +01005691 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) { /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305692 tempah &= 0x0F;
5693 tempah |= tempbh;
5694 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005695 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305696 }
5697 } else if (pVBInfo->IF_DEF_LVDS == 1) {
5698 tempbl = 0;
5699 tempbh = 0;
5700 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02005701 tempah = XGI301LCDDelay;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305702 tempah &= 0x0f;
5703 tempah = tempah << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005704 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305705 tempah);
5706 }
5707 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005708}
5709
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005710static void XGI_SetLCDCap_A(unsigned short tempcx,
5711 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005712{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305713 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005714
Aaro Koskinen58839b02011-03-13 12:26:23 +02005715 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005716
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305717 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005718 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005719 /* Enable Dither */
5720 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005721 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305722 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005723 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305724 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005725 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305726 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005727}
5728
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005729/* --------------------------------------------------------------------- */
5730/* Function : XGI_SetLCDCap_B */
5731/* Input : cx -> LCD Capability */
5732/* Output : */
5733/* Description : */
5734/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005735static void XGI_SetLCDCap_B(unsigned short tempcx,
5736 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005737{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305738 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005739 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305740 (unsigned short) (((tempcx & 0x00ff) >> 6)
5741 | 0x0c));
5742 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005743 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305744 (unsigned short) (((tempcx & 0x00ff) >> 6)
5745 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005746}
5747
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02005748static void XGI_LongWait(struct vb_device_info *pVBInfo)
5749{
5750 unsigned short i;
5751
5752 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
5753
5754 if (!(i & 0xC0)) {
5755 for (i = 0; i < 0xFFFF; i++) {
5756 if (!(inb(pVBInfo->P3da) & 0x08))
5757 break;
5758 }
5759
5760 for (i = 0; i < 0xFFFF; i++) {
5761 if ((inb(pVBInfo->P3da) & 0x08))
5762 break;
5763 }
5764 }
5765}
5766
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005767static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005768{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305769 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005770
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305771 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005772
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005773 /* disable down spectrum D[4] */
5774 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305775 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005776 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305777 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005778
Aaro Koskinen8104e322011-03-13 12:26:22 +02005779 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305780 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005781 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305782 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005783 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305784 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005785 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305786 pVBInfo->LCDCapList[index].Spectrum_34);
5787 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005788 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005789}
5790
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005791static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
5792{
5793 unsigned short tempcx;
5794
5795 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
5796
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005797 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005798 (VB_SIS301B |
5799 VB_SIS302B |
5800 VB_SIS301LV |
5801 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005802 VB_XGI301C)) { /* 301LV/302LV only */
5803 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005804 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005805 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005806 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005807 (unsigned char) (tempcx & 0x1F));
5808 }
5809 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005810 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005811 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
5812 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
5813 | EnablePLLSPLOW)) >> 8));
5814 }
5815
Peter Huewe6896b942012-02-09 21:11:46 +01005816 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5817 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005818 if (pVBInfo->VBInfo & SetCRT2ToLCD)
5819 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01005820 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005821 XGI_SetLCDCap_A(tempcx, pVBInfo);
5822
Peter Huewe6896b942012-02-09 21:11:46 +01005823 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005824 if (tempcx & EnableSpectrum)
5825 SetSpectrum(pVBInfo);
5826 }
5827 } else {
5828 /* LVDS,CH7017 */
5829 XGI_SetLCDCap_A(tempcx, pVBInfo);
5830 }
5831}
5832
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005833/* --------------------------------------------------------------------- */
5834/* Function : XGI_SetAntiFlicker */
5835/* Input : */
5836/* Output : */
5837/* Description : Set TV Customized Param. */
5838/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005839static void XGI_SetAntiFlicker(unsigned short ModeNo,
5840 unsigned short ModeIdIndex,
5841 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005842{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03005843 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005844
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305845 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005846
Peter Huewe599801f2012-02-09 21:11:45 +01005847 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305848 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005849
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305850 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5851 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305852 tempah = TVAntiFlickList[tempbx];
5853 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005854
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005855 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005856}
5857
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005858static void XGI_SetEdgeEnhance(unsigned short ModeNo,
5859 unsigned short ModeIdIndex,
5860 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005861{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03005862 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005863
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305864 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005865
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305866 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5867 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305868 tempah = TVEdgeList[tempbx];
5869 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005870
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005871 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005872}
5873
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005874static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005875{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305876 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005877
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305878 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005879
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305880 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005881
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305882 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
5883 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005884
Aaro Koskinen8104e322011-03-13 12:26:22 +02005885 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305886 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005887 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305888 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005889 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305890 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005891 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305892 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005893}
5894
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005895static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305896 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005897{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305898 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005899
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305900 unsigned char tempcl, tempch, tempal, *filterPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005901
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305902 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005903
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305904 switch (tempbx) {
5905 case 0x00:
5906 case 0x04:
5907 filterPtr = NTSCYFilter1;
5908 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005909
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305910 case 0x01:
5911 filterPtr = PALYFilter1;
5912 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005913
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305914 case 0x02:
5915 case 0x05:
5916 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305917 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03005918 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305919 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005920
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305921 case 0x08:
5922 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305923 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305924 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305925 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03005926 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305927 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005928
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305929 default:
5930 return;
5931 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005932
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005933 tempal = pVBInfo->EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305934 if (tempcl == 0)
5935 index = tempal * 4;
5936 else
5937 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005938
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305939 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005940 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
5941 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
5942 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
5943 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305944 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005945 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
5946 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
5947 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
5948 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305949 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005950
Peter Huewe6896b942012-02-09 21:11:46 +01005951 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5952 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005953 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
5954 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
5955 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305956 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005957}
5958
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005959/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005960/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005961/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005962/* Output : */
5963/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005964/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005965static void XGI_OEM310Setting(unsigned short ModeNo,
5966 unsigned short ModeIdIndex,
5967 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005968{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005969 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005970
Peter Huewea3d675c2012-02-09 21:11:47 +01005971 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005972 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005973
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005974 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005975 XGI_SetPhaseIncr(pVBInfo);
5976 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
5977 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005978
Peter Huewe6896b942012-02-09 21:11:46 +01005979 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005980 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305981 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005982}
5983
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005984/* --------------------------------------------------------------------- */
5985/* Function : XGI_SetCRT2ModeRegs */
5986/* Input : */
5987/* Output : */
5988/* Description : Origin code for crt2group */
5989/* --------------------------------------------------------------------- */
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005990static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305991 struct xgi_hw_device_info *HwDeviceExtension,
5992 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005993{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305994 unsigned short tempbl;
5995 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005996
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305997 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005998
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305999 tempah = 0;
6000 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006001 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306002 tempah &= ~0x10; /* BTRAMDAC */
6003 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006004
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306005 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
6006 | SetCRT2ToLCD)) {
6007 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006008 tempcl = pVBInfo->ModeType;
6009 tempcl -= ModeVGA;
6010 if (tempcl >= 0) {
6011 /* BT Color */
6012 tempah = (0x008 >> tempcl);
6013 if (tempah == 0)
6014 tempah = 1;
6015 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306016 }
6017 if (pVBInfo->VBInfo & SetInSlaveMode)
6018 tempah ^= 0x50; /* BTDAC */
6019 }
6020 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006021
Aaro Koskinen8104e322011-03-13 12:26:22 +02006022 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306023 tempah = 0x08;
6024 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006025
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306026 if (pVBInfo->VBInfo & DisableCRT2Display) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006027 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306028 } else {
6029 tempah = 0x00;
6030 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006031
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306032 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
Peter Huewea3d675c2012-02-09 21:11:47 +01006033 | SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
6034 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006035 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306036 tempbl &= 0xf7;
6037 tempah |= 0x01;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006038 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306039 tempbl, tempah);
6040 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01006041 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306042 tempbl &= 0xf7;
6043 tempah |= 0x01;
6044 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006045
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006046 if (pVBInfo->VBInfo &
6047 (SetCRT2ToRAMDAC |
6048 SetCRT2ToTV |
6049 SetCRT2ToLCD)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306050 tempbl &= 0xf8;
6051 tempah = 0x01;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006052
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306053 if (!(pVBInfo->VBInfo & SetInSlaveMode))
6054 tempah |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006055
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006056 if (!(pVBInfo->VBInfo &
6057 SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306058 tempah = tempah ^ 0x05;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006059 if (!(pVBInfo->VBInfo &
6060 SetCRT2ToLCD))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306061 tempah = tempah ^ 0x01;
6062 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006063
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006064 if (!(pVBInfo->VBInfo &
6065 SetCRT2ToDualEdge))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306066 tempah |= 0x08;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006067 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306068 0x2e, tempbl, tempah);
6069 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006070 xgifb_reg_and_or(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306071 0x2e, tempbl, tempah);
6072 }
6073 }
6074 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006075 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306076 tempah);
6077 }
6078 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006079
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306080 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01006081 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306082 tempah &= (~0x08);
6083 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
6084 & SetInSlaveMode))) {
6085 tempah |= 0x010;
6086 }
6087 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006088
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306089 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306090 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006091 if (pVBInfo->VBInfo & DriverMode)
6092 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306093 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006094
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006095 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306096 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006097
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306098 if (pVBInfo->LCDInfo & SetLCDDualLink)
6099 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306101 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306102 if (pVBInfo->TVInfo & RPLLDIV2XO)
6103 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306104 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006105
Peter Huewe255aabd2012-02-09 21:11:44 +01006106 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
6107 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306108 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006109
Peter Huewe255aabd2012-02-09 21:11:44 +01006110 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306111 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006112
Aaro Koskinen8104e322011-03-13 12:26:22 +02006113 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306114 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006115
Peter Huewe6896b942012-02-09 21:11:46 +01006116 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6117 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306118 tempah = 0;
6119 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006120
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306121 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6122 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01006123 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306124 tempah |= 0x04; /* shampoo 0129 */
6125 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006126
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006127 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306128 tempah = 0x00;
6129 tempbl = 0xcf;
6130 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6131 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6132 tempah |= 0x30;
6133 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006134
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006135 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306136 tempah = 0;
6137 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006138
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306139 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6140 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
6141 tempah |= 0xc0;
6142 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006143 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306144 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006145
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306146 tempah = 0;
6147 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01006148 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306149 tempbl = 0xff;
6150 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
6151 tempah |= 0x80;
6152 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006153
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006154 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006155
Peter Huewe6896b942012-02-09 21:11:46 +01006156 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306157 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006158 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
6159 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306160 }
6161 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006162}
6163
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006164
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306165void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
6166 struct vb_device_info *pVBInfo)
6167{
6168
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006169 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006170
6171}
6172
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306173void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
6174 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006175{
6176
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006177 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006178
6179}
6180
Bill Pemberton80adad82010-06-17 13:10:51 -04006181unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006182{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306183 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006184
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306185 if (pVBInfo->IF_DEF_LVDS == 1) {
6186 return 1;
6187 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006188 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306189 if ((flag == 1) || (flag == 2))
6190 return 1; /* 301b */
6191 else
6192 return 0;
6193 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006194}
6195
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006196unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
6197 unsigned short ModeNo, unsigned short ModeIdIndex,
6198 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006199{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006200 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
6201 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
6202 0x01, 0x01 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006203
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006204 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006205
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006206 modeflag = pVBInfo->EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006207
Aaro Koskinen58839b02011-03-13 12:26:23 +02006208 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006209 index = index >> pVBInfo->SelectCRT2Rate;
6210 index &= 0x0F;
6211
6212 if (pVBInfo->LCDInfo & LCDNonExpanding)
6213 index = 0;
6214
6215 if (index > 0)
6216 index--;
6217
6218 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01006219 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006220 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe6896b942012-02-09 21:11:46 +01006221 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
6222 | VB_SIS301LV | VB_SIS302LV
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006223 | VB_XGI301C))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006224 /* 301b */
6225 temp = LCDARefreshIndex[
6226 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006227 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006228 temp = LCDRefreshIndex[
6229 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006230
6231 if (index > temp)
6232 index = temp;
6233 } else {
6234 index = 0;
6235 }
6236 }
6237 }
6238
6239 RefreshRateTableIndex = pVBInfo->EModeIDTable[ModeIdIndex].REFindex;
6240 ModeNo = pVBInfo->RefIndex[RefreshRateTableIndex].ModeID;
6241 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006242 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 800) &&
6243 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006244 index++;
6245 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006246 /* do the similar adjustment like XGISearchCRT1Rate() */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006247 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1024) &&
6248 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006249 index++;
6250 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006251 if ((pVBInfo->RefIndex[RefreshRateTableIndex].XRes == 1280) &&
6252 (pVBInfo->RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006253 index++;
6254 }
6255 }
6256
6257 i = 0;
6258 do {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006259 if (pVBInfo->RefIndex[RefreshRateTableIndex + i].
6260 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006261 break;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006262 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i].
6263 Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01006264 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006265 if (temp < pVBInfo->ModeType)
6266 break;
6267 i++;
6268 index--;
6269
6270 } while (index != 0xFFFF);
6271 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
6272 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006273 temp = pVBInfo->RefIndex[RefreshRateTableIndex + i - 1].
6274 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006275 if (temp & InterlaceMode)
6276 i++;
6277 }
6278 }
6279 i--;
6280 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
6281 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
6282 RefreshRateTableIndex, &i, pVBInfo);
6283 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02006284 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006285}
6286
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006287static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05306288 struct xgi_hw_device_info *HwDeviceExtension,
6289 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006290{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006291 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006292
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006293 pVBInfo->SetFlag |= ProgrammingCRT2;
6294 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
6295 ModeIdIndex, pVBInfo);
6296 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
6297 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6298 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6299 HwDeviceExtension, pVBInfo);
6300 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6301 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006302}
6303
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02006304static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006305 struct xgi_hw_device_info *HwDeviceExtension,
6306 struct vb_device_info *pVBInfo)
6307{
6308 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
6309
6310 tempbx = pVBInfo->VBInfo;
6311 pVBInfo->SetFlag |= ProgrammingCRT2;
6312 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
6313 pVBInfo->SelectCRT2Rate = 4;
6314 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
6315 ModeIdIndex, pVBInfo);
6316 XGI_SaveCRT2Info(ModeNo, pVBInfo);
6317 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
6318 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6319 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
6320 RefreshRateTableIndex, pVBInfo);
6321 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
6322 RefreshRateTableIndex, pVBInfo);
6323 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
6324 RefreshRateTableIndex, pVBInfo);
6325 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6326 HwDeviceExtension, pVBInfo);
6327 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
6328 RefreshRateTableIndex, pVBInfo);
6329 XGI_SetTap4Regs(pVBInfo);
6330 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
6331 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6332 HwDeviceExtension, pVBInfo);
6333 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
6334 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
6335 XGI_AutoThreshold(pVBInfo);
6336 return 1;
6337}
6338
6339void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
6340{
6341 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
6342 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
6343 0x05, 0x00 };
6344
6345 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
6346
6347 unsigned char CR17, CR63, SR31;
6348 unsigned short temp;
6349 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
6350
6351 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006352 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006353
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006354 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02006355 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02006356 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006357 pVBInfo->P3d4, 0x53) | 0x02));
6358
Aaro Koskinen58839b02011-03-13 12:26:23 +02006359 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
6360 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
6361 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006362
Aaro Koskinen8104e322011-03-13 12:26:22 +02006363 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
6364 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006365
Aaro Koskinen58839b02011-03-13 12:26:23 +02006366 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006367 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006368
Aaro Koskinen58839b02011-03-13 12:26:23 +02006369 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006370 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006371
Aaro Koskinen58839b02011-03-13 12:26:23 +02006372 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006373 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Aaro Koskinen58839b02011-03-13 12:26:23 +02006374 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02006375 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006376
Aaro Koskinen8104e322011-03-13 12:26:22 +02006377 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006378
6379 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02006380 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006381
6382 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02006383 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006384 CRTCData[i]);
6385
6386 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02006387 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006388 CRTCData[i]);
6389
6390 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02006391 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006392 CRTCData[i]);
6393
Aaro Koskinen8104e322011-03-13 12:26:22 +02006394 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006395 & 0xE0));
6396
Aaro Koskinen8104e322011-03-13 12:26:22 +02006397 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
6398 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
6399 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006400
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006401 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006402
6403 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006404 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
6405 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
6406 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006407 }
6408
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006409 mdelay(1);
6410
6411 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02006412 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006413
6414 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006415 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006416 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006417 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006418
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006419 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006420 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006421
6422 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02006423 outb(0, (pVBInfo->P3c8 + 1));
6424 outb(0, (pVBInfo->P3c8 + 1));
6425 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006426 }
6427
Aaro Koskinen8104e322011-03-13 12:26:22 +02006428 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
6429 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
6430 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006431
Aaro Koskinen58839b02011-03-13 12:26:23 +02006432 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006433 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02006434 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006435}
6436
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006437static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
6438 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006439 struct vb_device_info *pVBInfo)
6440{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02006441 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006442
Peter Huewe6896b942012-02-09 21:11:46 +01006443 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6444 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006445 if (!(pVBInfo->SetFlag & DisableChA)) {
6446 if (pVBInfo->SetFlag & EnableChA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006447 /* Power on */
6448 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006449 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006450 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
6451 /* Power on */
Aaro Koskinen8104e322011-03-13 12:26:22 +02006452 xgifb_reg_set(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006453 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006454 }
6455 }
6456 }
6457
6458 if (!(pVBInfo->SetFlag & DisableChB)) {
6459 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
6460 & (SetCRT2ToLCD | SetCRT2ToTV
6461 | SetCRT2ToRAMDAC))) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006462 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006463 pVBInfo->P3c4, 0x32);
6464 tempah &= 0xDF;
6465 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006466 if (!(pVBInfo->VBInfo &
6467 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006468 tempah |= 0x20;
6469 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02006470 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006471 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006472
Aaro Koskinen58839b02011-03-13 12:26:23 +02006473 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006474 pVBInfo->Part1Port, 0x2E);
6475
6476 if (!(tempah & 0x80))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02006477 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006478 0x2E, 0x80);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006479 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006480 }
6481 }
6482
6483 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
6484 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02006485 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006486 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01006487 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006488 if (!XGI_DisableChISLCD(pVBInfo)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006489 if (XGI_EnableChISLCD(pVBInfo) ||
6490 (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01006491 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006492 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02006493 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006494 pVBInfo->Part4Port,
6495 0x2A,
6496 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006497 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006498 /* LVDS Driver power on */
6499 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006500 }
6501 }
6502
6503 tempah = 0x00;
6504
6505 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
6506 tempah = 0xc0;
6507
6508 if (!(pVBInfo->VBInfo & SetSimuScanMode)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01006509 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006510 if (pVBInfo->VBInfo &
6511 SetCRT2ToDualEdge) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006512 tempah = tempah & 0x40;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006513 if (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01006514 XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006515 tempah = tempah ^ 0xC0;
6516
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006517 if (pVBInfo->SetFlag &
6518 DisableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006519 tempah &= 0xBF;
6520
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006521 if (pVBInfo->SetFlag &
6522 DisableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006523 tempah &= 0x7F;
6524
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006525 if (pVBInfo->SetFlag &
6526 EnableChB)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006527 tempah |= 0x40;
6528
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006529 if (pVBInfo->SetFlag &
6530 EnableChA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006531 tempah |= 0x80;
6532 }
6533 }
6534 }
6535 }
6536
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006537 /* EnablePart4_1F */
6538 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006539
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006540 if (!(pVBInfo->SetFlag & DisableChA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006541 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006542 XGI_DisableGatingCRT(HwDeviceExtension,
6543 pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006544 XGI_DisplayOn(xgifb_info, HwDeviceExtension,
6545 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006546 }
6547 }
6548 } /* 301 */
6549 else { /* LVDS */
6550 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01006551 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006552 /* enable CRT2 */
6553 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006554
Aaro Koskinen58839b02011-03-13 12:26:23 +02006555 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006556 0x2E);
6557 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006558 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006559
Aaro Koskinendc505562011-03-13 12:26:26 +02006560 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006561 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006562 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006563}
6564
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006565static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
6566 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006567 unsigned short ModeNo, unsigned short ModeIdIndex,
6568 struct vb_device_info *pVBInfo)
6569{
Aaro Koskinena1579612012-04-07 01:14:05 +03006570 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006571
Aaro Koskinena1579612012-04-07 01:14:05 +03006572 XGI_SetSeqRegs(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfb60d0c2012-04-07 01:14:04 +03006573 outb(pVBInfo->StandTable->MISC, pVBInfo->P3c2);
Aaro Koskinena1579612012-04-07 01:14:05 +03006574 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
6575 XGI_SetATTRegs(ModeNo, ModeIdIndex, pVBInfo);
6576 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006577 XGI_ClearExt1Regs(pVBInfo);
6578
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006579 if (HwDeviceExtension->jChipType == XG27) {
6580 if (pVBInfo->IF_DEF_LVDS == 0)
6581 XGI_SetDefaultVCLK(pVBInfo);
6582 }
6583
6584 temp = ~ProgrammingCRT2;
6585 pVBInfo->SetFlag &= temp;
6586 pVBInfo->SelectCRT2Rate = 0;
6587
Peter Huewe6896b942012-02-09 21:11:46 +01006588 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
6589 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01006590 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006591 | SetInSlaveMode)) {
6592 pVBInfo->SetFlag |= ProgrammingCRT2;
6593 }
6594 }
6595
6596 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
6597 ModeIdIndex, pVBInfo);
6598 if (RefreshRateTableIndex != 0xFFFF) {
6599 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
6600 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6601 pVBInfo, HwDeviceExtension);
6602 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
6603 RefreshRateTableIndex, pVBInfo);
6604 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
6605 HwDeviceExtension, pVBInfo);
6606 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
6607 RefreshRateTableIndex, pVBInfo);
6608 }
6609
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006610 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006611 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006612 if (temp & 0xA0) {
6613
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006614 if (HwDeviceExtension->jChipType == XG27)
6615 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
6616 RefreshRateTableIndex, pVBInfo);
6617 else
6618 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
6619 RefreshRateTableIndex, pVBInfo);
6620
6621 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
6622 RefreshRateTableIndex);
6623
Aaro Koskinen105d8d02011-08-31 21:46:00 +03006624 xgifb_set_lcd(HwDeviceExtension->jChipType,
6625 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006626
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006627 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006628 xgifb_set_lvds(xgifb_info,
6629 HwDeviceExtension->jChipType,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03006630 ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006631 }
6632 }
6633
6634 pVBInfo->SetFlag &= (~ProgrammingCRT2);
6635 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
6636 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
6637 RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006638 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006639}
6640
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006641unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
6642 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006643 unsigned short ModeNo)
6644{
6645 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006646 struct vb_device_info VBINF;
6647 struct vb_device_info *pVBInfo = &VBINF;
Dmitry Eremin-Solenikov9a801f22012-03-19 21:50:13 +04006648 pVBInfo->BaseAddr = xgifb_info->vga_base;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006649 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006650 pVBInfo->IF_DEF_LCDA = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006651
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006652 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006653 pVBInfo->IF_DEF_YPbPr = 0;
6654 pVBInfo->IF_DEF_HiVision = 0;
6655 pVBInfo->IF_DEF_CRT2Monitor = 0;
6656 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006657 } else {
6658 pVBInfo->IF_DEF_YPbPr = 1;
6659 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02006660 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006661 }
6662
6663 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
6664 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
6665 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
6666 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
6667 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
6668 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
6669 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
6670 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
6671 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
6672 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
6673 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
6674 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
6675 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
Peter Huewe6896b942012-02-09 21:11:46 +01006676 pVBInfo->Part1Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_04;
6677 pVBInfo->Part2Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_10;
6678 pVBInfo->Part3Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_12;
6679 pVBInfo->Part4Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14;
6680 pVBInfo->Part5Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14 + 2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006681
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006682 /* for x86 Linux, XG21 LVDS */
6683 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006684 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006685 pVBInfo->IF_DEF_LVDS = 1;
6686 }
6687 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02006688 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
6689 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006690 pVBInfo->IF_DEF_LVDS = 1;
6691 }
6692 }
6693
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006694 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006695 XGI_GetVBType(pVBInfo);
6696
6697 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02006698 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006699 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006700 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006701
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006702 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006703 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
6704
6705 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
6706
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006707 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006708 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
6709 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
6710 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006711 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006712
Peter Huewea3d675c2012-02-09 21:11:47 +01006713 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006714 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006715 ModeIdIndex, pVBInfo);
6716
Peter Huewea3d675c2012-02-09 21:11:47 +01006717 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006718 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6719 HwDeviceExtension, pVBInfo);
6720 }
6721 } else {
Peter Huewe6896b942012-02-09 21:11:46 +01006722 if (!(pVBInfo->VBInfo & SwitchCRT2)) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006723 XGI_SetCRT1Group(xgifb_info,
6724 HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006725 ModeIdIndex, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01006726 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006727 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6728 HwDeviceExtension,
6729 pVBInfo);
6730 }
6731 }
6732 }
6733
Peter Huewe6896b942012-02-09 21:11:46 +01006734 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006735 switch (HwDeviceExtension->ujVBChipID) {
6736 case VB_CHIP_301:
6737 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6738 pVBInfo); /*add for CRT2 */
6739 break;
6740
6741 case VB_CHIP_302:
6742 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6743 pVBInfo); /*add for CRT2 */
6744 break;
6745
6746 default:
6747 break;
6748 }
6749 }
6750
6751 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
6752 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006753 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006754 } /* !XG20 */
6755 else {
6756 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006757 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006758 ModeIdIndex,
6759 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006760 return 0;
6761
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03006762 pVBInfo->ModeType = pVBInfo->EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01006763 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006764
6765 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03006766 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006767
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006768 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006769
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006770 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
6771 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006772
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006773 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006774 }
6775
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006776 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
6777
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006778 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006779 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
6780 }
6781
6782 return 1;
6783}