blob: 137c3df9d69d2868f45afed47a68e56ad772ed11 [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 Koskinena7e46d8b2012-09-11 00:15:32 +030026 pVBInfo->MCLKData = XGI340New_MCLKData;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030027 pVBInfo->StResInfo = XGI330_StResInfo;
28 pVBInfo->ModeResInfo = XGI330_ModeResInfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020029
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053030 pVBInfo->LCDResInfo = 0;
31 pVBInfo->LCDTypeInfo = 0;
32 pVBInfo->LCDInfo = 0;
33 pVBInfo->VBInfo = 0;
34 pVBInfo->TVInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020035
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053036 pVBInfo->SR15 = XGI340_SR13;
37 pVBInfo->CR40 = XGI340_cr41;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053038 pVBInfo->CR6B = XGI340_CR6B;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053039 pVBInfo->AGPReg = XGI340_AGPReg;
40 pVBInfo->SR16 = XGI340_SR16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020041
Peter Huewe6d12dae2012-06-14 00:21:52 +020042 pVBInfo->SR21 = 0xa3;
43 pVBInfo->SR22 = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020044
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053045 /* 310 customization related */
Peter Huewe6896b942012-02-09 21:11:46 +010046 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053047 pVBInfo->LCDCapList = XGI_LCDDLCapList;
48 else
49 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020050
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053051 if (ChipType >= XG20)
Peter Huewe6d12dae2012-06-14 00:21:52 +020052 pVBInfo->XGINew_CR97 = 0x10;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020053
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053054 if (ChipType == XG27) {
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040055 unsigned char temp;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030056 pVBInfo->MCLKData = XGI27New_MCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053057 pVBInfo->CR40 = XGI27_cr41;
Peter Huewe6d12dae2012-06-14 00:21:52 +020058 pVBInfo->XGINew_CR97 = 0xc1;
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040059 pVBInfo->SR15 = XG27_SR13;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020060
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040061 /*Z11m DDR*/
62 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
63 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
64 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
Peter Huewe6d12dae2012-06-14 00:21:52 +020065 pVBInfo->XGINew_CR97 = 0x80;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053066 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020067
68}
69
Kenji Toyama1d7f6562011-04-23 19:36:49 +080070static void XGI_SetSeqRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080071 unsigned short ModeIdIndex,
72 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020073{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053074 unsigned char tempah, SRdata;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053075 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020076
Aaro Koskinenb3979922012-11-04 21:14:52 +020077 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020078
Aaro Koskinen8104e322011-03-13 12:26:22 +020079 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +020080 tempah = XGI330_StandTable.SR[0];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020081
Peter Huewea3d675c2012-02-09 21:11:47 +010082 i = XGI_SetCRT2ToLCDA;
83 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053084 tempah |= 0x01;
Aaro Koskinend3ae5762012-09-11 00:15:27 +030085 } else if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD)) {
86 if (pVBInfo->VBInfo & SetInSlaveMode)
87 tempah |= 0x01;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053088 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053090 tempah |= 0x20; /* screen off */
Aaro Koskinen8104e322011-03-13 12:26:22 +020091 xgifb_reg_set(pVBInfo->P3c4, 0x01, tempah); /* Set SR1 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020092
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053093 for (i = 02; i <= 04; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +080094 /* Get SR2,3,4 from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +020095 SRdata = XGI330_StandTable.SR[i - 1];
Aaro Koskinen8104e322011-03-13 12:26:22 +020096 xgifb_reg_set(pVBInfo->P3c4, i, SRdata); /* Set SR2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053097 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020098}
99
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200100static void XGI_SetCRTCRegs(struct xgi_hw_device_info *HwDeviceExtension,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800101 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200102{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530103 unsigned char CRTCdata;
104 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200105
Aaro Koskinen58839b02011-03-13 12:26:23 +0200106 CRTCdata = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530107 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200108 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200109
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530110 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800111 /* Get CRTC from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200112 CRTCdata = XGI330_StandTable.CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200113 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530114 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200115}
116
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800117static void XGI_SetATTRegs(unsigned short ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800118 unsigned short ModeIdIndex,
119 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200120{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530121 unsigned char ARdata;
122 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200123
Aaro Koskinenb3979922012-11-04 21:14:52 +0200124 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200125
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530126 for (i = 0; i <= 0x13; i++) {
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200127 ARdata = XGI330_StandTable.ATTR[i];
Miguel Gómez661a6382012-07-06 12:40:45 +0200128
129 if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
130 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
131 ARdata = 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300132 } else if ((pVBInfo->VBInfo &
Miguel Gómez661a6382012-07-06 12:40:45 +0200133 (SetCRT2ToTV | SetCRT2ToLCD)) &&
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300134 (pVBInfo->VBInfo & SetInSlaveMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530135 ARdata = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530136 }
137 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200138
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200139 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200140 outb(i, pVBInfo->P3c0); /* set index */
141 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530142 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200143
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200144 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200145 outb(0x14, pVBInfo->P3c0); /* set index */
146 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200147 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200148 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200149}
150
Aaro Koskinena1579612012-04-07 01:14:05 +0300151static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200152{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530153 unsigned char GRdata;
154 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200155
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530156 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800157 /* Get GR from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200158 GRdata = XGI330_StandTable.GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200159 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530160 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200161
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530162 if (pVBInfo->ModeType > ModeVGA) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200163 GRdata = (unsigned char) xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530164 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200165 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530166 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200167}
168
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200169static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200170{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530171 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200172
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530173 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200174 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200175}
176
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200177static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200178{
179
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200180 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200181 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[0].SR2B);
182 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200183
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200184 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200185 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[1].SR2B);
186 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200187
Aaro Koskinendc505562011-03-13 12:26:26 +0200188 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530189 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200190}
191
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200192static unsigned char XGI_AjustCRT2Rate(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530193 unsigned short ModeIdIndex,
194 unsigned short RefreshRateTableIndex, unsigned short *i,
195 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200196{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530197 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200198
Aaro Koskinenb3979922012-11-04 21:14:52 +0200199 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
200 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200201 tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530202 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200203
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530204 if (pVBInfo->IF_DEF_LVDS == 0) {
205 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
206 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200207
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530208 if (pVBInfo->VBType & VB_XGI301C)
209 tempax |= SupportCRT2in301C;
210 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200211
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800212 /* 301b */
Peter Huewea3d675c2012-02-09 21:11:47 +0100213 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530214 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200215
Miguel Gómez3b175622012-07-06 12:40:46 +0200216 if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
217 pVBInfo->LCDResInfo != Panel_1280x960 &&
218 (pVBInfo->LCDInfo & LCDNonExpanding) &&
219 resinfo >= 9)
220 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530221 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200222
Peter Huewe599801f2012-02-09 21:11:45 +0100223 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
Aaro Koskinen31fb40f2012-09-11 00:15:15 +0300224 tempax |= SupportHiVision;
225 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
226 ((resinfo == 4) ||
227 (resinfo == 3 &&
228 (pVBInfo->SetFlag & TVSimuMode)) ||
229 (resinfo > 7)))
Miguel Gómez3b175622012-07-06 12:40:46 +0200230 return 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300231 } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO |
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800232 SetCRT2ToSVIDEO |
233 SetCRT2ToSCART |
Peter Huewe599801f2012-02-09 21:11:45 +0100234 SetCRT2ToYPbPr525750 |
235 SetCRT2ToHiVision)) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300236 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200237
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300238 if (pVBInfo->VBType & (VB_SIS301B |
239 VB_SIS302B |
240 VB_SIS301LV |
241 VB_SIS302LV |
242 VB_XGI301C))
243 tempax |= SupportTV1024;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200244
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300245 if (!(pVBInfo->VBInfo & TVSetPAL) &&
246 (modeflag & NoSupportSimuTV) &&
247 (pVBInfo->VBInfo & SetInSlaveMode) &&
248 (!(pVBInfo->VBInfo & SetNotSimuMode)))
249 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530250 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300251 } else if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* for LVDS */
252 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200253
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300254 if (resinfo > 0x08)
255 return 0; /* 1024x768 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200256
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300257 if (pVBInfo->LCDResInfo < Panel_1024x768) {
258 if (resinfo > 0x07)
259 return 0; /* 800x600 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200260
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300261 if (resinfo == 0x04)
262 return 0; /* 512x384 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530263 }
264 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200265
Aaro Koskinena39325d2012-11-04 21:14:53 +0200266 for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800267 tempbx; (*i)--) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200268 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800269 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530270 if (infoflag & tempax)
271 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200272
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530273 if ((*i) == 0)
274 break;
275 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200276
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530277 for ((*i) = 0;; (*i)++) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200278 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800279 Ext_InfoFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200280 if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530281 != tempbx) {
282 return 0;
283 }
284
285 if (infoflag & tempax)
286 return 1;
287 }
288 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200289}
290
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200291static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530292 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200293{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530294 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200295
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800296 /* di+0x00 */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200297 sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530298 sync &= 0xC0;
299 temp = 0x2F;
300 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200301 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200302}
303
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200304static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530305 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200306{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530307 unsigned char data, data1, pushax;
308 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200309
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800310 /* unlock cr0-7 */
311 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530312 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200313 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200314
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200315 data = pVBInfo->TimingH.data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200316 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200317
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530318 for (i = 0x01; i <= 0x04; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200319 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200320 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530321 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200322
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530323 for (i = 0x05; i <= 0x06; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200324 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200325 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530326 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200327
Aaro Koskinen58839b02011-03-13 12:26:23 +0200328 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530329 j &= 0x1F;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200330 data = pVBInfo->TimingH.data[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530331 data &= 0xE0;
332 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200333 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200334
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530335 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200336 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530337 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200338 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200339 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530340 data1 = data;
341 data1 &= 0xE0;
342 data &= 0x1F;
343 if (data == 0) {
344 pushax = data;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200345 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530346 0x0c);
347 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200348 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530349 data = pushax;
350 }
351 data = data - 1;
352 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200353 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200354 data = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530355 data = data >> 5;
356 data = data + 3;
357 if (data > 7)
358 data = data - 7;
359 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200360 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530361 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200362}
363
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800364static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
365 unsigned short ModeNo,
366 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200367{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530368 unsigned char data;
369 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200370
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530371 for (i = 0x00; i <= 0x01; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200372 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200373 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530374 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200375
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530376 for (i = 0x02; i <= 0x03; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200377 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200378 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530379 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200380
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530381 for (i = 0x04; i <= 0x05; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200382 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200383 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530384 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200385
Aaro Koskinen58839b02011-03-13 12:26:23 +0200386 j = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530387 j &= 0xC0;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200388 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530389 data &= 0x3F;
390 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200391 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200392
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200393 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530394 data &= 0x80;
395 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200396
Aaro Koskinenb3979922012-11-04 21:14:52 +0200397 i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530398 i &= DoubleScanMode;
399 if (i)
400 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200401
Aaro Koskinen58839b02011-03-13 12:26:23 +0200402 j = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530403 j &= 0x5F;
404 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200405 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200406}
407
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200408static void XGI_SetCRT1CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
409 unsigned short RefreshRateTableIndex,
410 struct vb_device_info *pVBInfo,
411 struct xgi_hw_device_info *HwDeviceExtension)
412{
413 unsigned char index, data;
414 unsigned short i;
415
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800416 /* Get index */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200417 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200418 index = index & IndexMask;
419
Aaro Koskinen58839b02011-03-13 12:26:23 +0200420 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200421 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200422 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200423
424 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200425 pVBInfo->TimingH.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200426 = XGI_CRT1Table[index].CR[i];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200427
428 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200429 pVBInfo->TimingV.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200430 = XGI_CRT1Table[index].CR[i + 8];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200431
432 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
433
434 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
435
436 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200437 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200438}
439
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200440/* --------------------------------------------------------------------- */
441/* Function : XGI_SetXG21CRTC */
442/* Input : Stand or enhance CRTC table */
443/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
444/* Description : Set LCD timing */
445/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200446static void XGI_SetXG21CRTC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530447 unsigned short RefreshRateTableIndex,
448 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200449{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300450 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530451 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200452
Aaro Koskinena39325d2012-11-04 21:14:53 +0200453 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300454 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200455 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300456 Tempcx = Tempax; /* Tempcx: HRS */
457 /* SR2E[7:0]->HRS */
458 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200459
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200460 Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300461 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
462 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
463 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
464 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800465
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200466 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300467 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200468
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200469 Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300470 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
471 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
472 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200473
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300474 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
475 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200476
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300477 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
478 if (Tempax < Tempcx) /* HRE < HRS */
479 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200480
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300481 Temp2 &= 0xFF;
482 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
483 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
484 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
485 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
486 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
487 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
488 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200489
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300490 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200491 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300492 Tempbx = Tempax; /* Tempbx: VRS */
493 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
494 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
495 /* CR7[2][7] VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200496 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300497 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
498 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
499 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
500 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
501 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200502
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300503 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
504 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
505 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
506 Tempax &= 0x80;
507 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
508 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
509 /* Tempax: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200510 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300511 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
512 Temp2 = Tempax;
513 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
514 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200515
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300516 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200517 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300518 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
519 /* Tempbx: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200520 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300521 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
522 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
523 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
524 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
525 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200526
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300527 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
528 if (Tempax < Temp3) /* VRE < VRS */
529 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200530
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300531 Temp2 &= 0xFF;
532 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
533 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
534 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
535 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
536 Tempbx = (unsigned char) Temp1;
537 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
538 Tempax &= 0x7F;
539 /* SR3F D[7:2]->VRE D[1:0]->VRS */
540 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200541}
542
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800543static void XGI_SetXG27CRTC(unsigned short ModeNo,
544 unsigned short ModeIdIndex,
545 unsigned short RefreshRateTableIndex,
546 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200547{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300548 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200549
Aaro Koskinena39325d2012-11-04 21:14:53 +0200550 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300551 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200552 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300553 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
554 /* SR2E[7:0]->HRS */
555 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200556
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300557 /* SR0B */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200558 Tempax = XGI_CRT1Table[index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300559 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
560 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200561
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200562 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300563 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
564 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200565
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200566 Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300567 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
568 Tempax <<= 3; /* Tempax[5]: HRE[5] */
569 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200570
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300571 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
572 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200573
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300574 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200575 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300576 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
577 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
578 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200579
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200580 Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300581 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
582 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
583 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
584 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
585 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
586 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200587
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300588 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200589 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300590 /* SR34[7:0]->VRS[7:0] */
591 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200592
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300593 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
594 /* CR7[7][2] VRS[9][8] */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200595 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300596 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
597 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
598 Tempax >>= 2; /* Tempax[0]: VRS[8] */
599 /* SR35[0]: VRS[8] */
600 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
601 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
602 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
603 /* Tempax: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200604 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300605 Tempax &= 0x08; /* SR0A[3] VRS[10] */
606 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200607
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300608 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200609 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300610 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
611 /* Tempbx: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200612 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300613 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
614 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
615 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
616 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
617 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
618 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200619
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300620 if (Tempbx <= Tempcx) /* VRE <= VRS */
621 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200622
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300623 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
624 Tempax = (Tempbx << 2) & 0xFF;
625 /* SR3F[7:2]:VRE[5:0] */
626 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
627 Tempax = Tempcx >> 8;
628 /* SR35[2:0]:VRS[10:8] */
629 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200630}
631
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200632static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
633{
634 unsigned char temp;
635
636 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
637 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
638 temp = (temp & 3) << 6;
639 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
640 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
641 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
642 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
643
644}
645
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300646static void xgifb_set_lcd(int chip_id,
647 struct vb_device_info *pVBInfo,
648 unsigned short RefreshRateTableIndex,
649 unsigned short ModeNo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200650{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300651 unsigned short Data, Temp;
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400652 unsigned short XGI_P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200653
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530654 XGI_P3cc = pVBInfo->P3cc;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200655
Aaro Koskinen8104e322011-03-13 12:26:22 +0200656 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
657 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
658 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
659 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300660
661 if (chip_id == XG27) {
662 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
663 if ((Temp & 0x03) == 0) { /* dual 12 */
664 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
665 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
666 }
667 }
668
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300669 if (chip_id == XG27) {
670 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530671 } else {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300672 Temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
673 if (Temp & 0x01) {
674 /* 18 bits FP */
675 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
676 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
677 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530678 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200679
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200680 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200681
Aaro Koskinendc505562011-03-13 12:26:26 +0200682 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
683 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200684
Aaro Koskinena39325d2012-11-04 21:14:53 +0200685 Data = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300686 if (Data & 0x4000)
687 /* Hsync polarity */
688 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
689 if (Data & 0x8000)
690 /* Vsync polarity */
691 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200692}
693
694/* --------------------------------------------------------------------- */
695/* Function : XGI_UpdateXG21CRTC */
696/* Input : */
697/* Output : CRT1 CRTC */
698/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
699/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800700static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
701 struct vb_device_info *pVBInfo,
702 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200703{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300704 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200705
Aaro Koskinendc505562011-03-13 12:26:26 +0200706 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300707 if (ModeNo == 0x2E &&
Aaro Koskinena39325d2012-11-04 21:14:53 +0200708 (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300709 RES640x480x60))
710 index = 12;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200711 else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800712 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300713 index = 13;
714 else if (ModeNo == 0x2F)
715 index = 14;
716 else if (ModeNo == 0x50)
717 index = 15;
718 else if (ModeNo == 0x59)
719 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200720
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530721 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200722 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200723 XGI_UpdateCRT1Table[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200724 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200725 XGI_UpdateCRT1Table[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200726 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200727 XGI_UpdateCRT1Table[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200728 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200729 XGI_UpdateCRT1Table[index].CR16);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530730 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200731}
732
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200733static void XGI_SetCRT1DE(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530734 unsigned short ModeNo, unsigned short ModeIdIndex,
735 unsigned short RefreshRateTableIndex,
736 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200737{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400738 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200739
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530740 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200741
Aaro Koskinenb3979922012-11-04 21:14:52 +0200742 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200743
Aaro Koskinenb3979922012-11-04 21:14:52 +0200744 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300745 tempax = pVBInfo->ModeResInfo[resindex].HTotal;
746 tempbx = pVBInfo->ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200747
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530748 if (modeflag & HalfDCLK)
749 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200750
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300751 if (modeflag & HalfDCLK)
752 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200753
Aaro Koskinena39325d2012-11-04 21:14:53 +0200754 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200755
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300756 if (temp & InterlaceMode)
757 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200758
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300759 if (modeflag & DoubleScanMode)
760 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200761
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530762 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200763
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530764 tempax /= tempcx;
765 tempax -= 1;
766 tempbx -= 1;
767 tempcx = tempax;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200768 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
769 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530770 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200771 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
772 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200773 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530774 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200775 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530776 tempax = 0;
777 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200778
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530779 if (tempbx & 0x01)
780 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200781
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530782 if (tempbx & 0x02)
783 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200784
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200785 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200786 data = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530787 data &= 0xFF;
788 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200789
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530790 if (tempbx & 0x04)
791 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200792
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200793 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200794 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200795}
796
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800797static void XGI_SetCRT1Offset(unsigned short ModeNo,
798 unsigned short ModeIdIndex,
799 unsigned short RefreshRateTableIndex,
800 struct xgi_hw_device_info *HwDeviceExtension,
801 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200802{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530803 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200804
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530805 /* GetOffset */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200806 temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530807 temp = temp >> 8;
Aaro Koskinen224114c2012-11-04 21:14:59 +0200808 temp = XGI330_ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200809
Aaro Koskinena39325d2012-11-04 21:14:53 +0200810 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530811 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200812
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530813 if (temp2)
814 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200815
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530816 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200817
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530818 switch (temp2) {
819 case 0:
820 temp2 = 1;
821 break;
822 case 1:
823 temp2 = 2;
824 break;
825 case 2:
826 temp2 = 4;
827 break;
828 case 3:
829 temp2 = 4;
830 break;
831 case 4:
832 temp2 = 6;
833 break;
834 case 5:
835 temp2 = 8;
836 break;
837 default:
838 break;
839 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200840
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530841 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
842 temp = temp * temp2 + temp2 / 2;
843 else
844 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200845
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530846 /* SetOffset */
847 DisplayUnit = temp;
848 temp2 = temp;
849 temp = temp >> 8; /* ah */
850 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200851 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530852 i &= 0xF0;
853 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200854 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200855
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530856 temp = (unsigned char) temp2;
857 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200858 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200859
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530860 /* SetDisplayUnit */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200861 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530862 temp2 &= InterlaceMode;
863 if (temp2)
864 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200865
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530866 DisplayUnit = DisplayUnit << 5;
867 ah = (DisplayUnit & 0xff00) >> 8;
868 al = DisplayUnit & 0x00ff;
869 if (al == 0)
870 ah += 1;
871 else
872 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200873
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530874 if (HwDeviceExtension->jChipType >= XG20)
875 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
876 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200877
Aaro Koskinen8104e322011-03-13 12:26:22 +0200878 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200879}
880
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200881static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeNo,
882 unsigned short ModeIdIndex,
883 unsigned short RefreshRateTableIndex,
884 struct xgi_hw_device_info *HwDeviceExtension,
885 struct vb_device_info *pVBInfo)
886{
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200887 unsigned short CRT2Index, VCLKIndex;
888 unsigned short modeflag, resinfo;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200889
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300890 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200891 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
892 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200893 CRT2Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200894
895 if (pVBInfo->IF_DEF_LVDS == 0) {
896 CRT2Index = CRT2Index >> 6; /* for LCD */
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200897 if (pVBInfo->VBInfo &
898 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
Peter Huewe255aabd2012-02-09 21:11:44 +0100899 if (pVBInfo->LCDResInfo != Panel_1024x768)
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200900 /* LCDXlat2VCLK */
901 VCLKIndex = VCLK108_2_315 + 5;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200902 else
Peter Huewef477d3e2012-06-14 00:21:47 +0200903 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
Peter Huewe599801f2012-02-09 21:11:45 +0100904 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200905 if (pVBInfo->SetFlag & RPLLDIV2XO)
Peter Huewe95072592012-06-14 00:21:48 +0200906 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200907 else
Peter Huewe95072592012-06-14 00:21:48 +0200908 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200909
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200910 if (pVBInfo->SetFlag & TVSimuMode) {
911 if (modeflag & Charx8Dot) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200912 VCLKIndex = TVCLKBASE_315_25 +
913 HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200914 } else {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200915 VCLKIndex = TVCLKBASE_315_25 +
916 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200917 }
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200918 }
919
920 /* 301lv */
Aaro Koskinen31fb40f2012-09-11 00:15:15 +0300921 if (pVBInfo->VBType & VB_SIS301LV) {
922 if (pVBInfo->SetFlag & RPLLDIV2XO)
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200923 VCLKIndex = YPbPr525iVCLK_2;
924 else
925 VCLKIndex = YPbPr525iVCLK;
926 }
927 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200928 if (pVBInfo->SetFlag & RPLLDIV2XO)
Peter Huewe95072592012-06-14 00:21:48 +0200929 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
Miguel Gómez3bcc2462012-07-06 12:40:53 +0200930 else
Peter Huewe95072592012-06-14 00:21:48 +0200931 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200932 } else { /* for CRT2 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300933 /* di+Ext_CRTVCLK */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200934 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800935 Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300936 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200937 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300938 } else if ((pVBInfo->LCDResInfo == Panel_800x600) ||
939 (pVBInfo->LCDResInfo == Panel_320x480)) { /* LVDS */
940 VCLKIndex = VCLK40; /* LVDSXlat1VCLK */
941 } else {
942 VCLKIndex = VCLK65_315 + 2; /* LVDSXlat2VCLK, LVDSXlat3VCLK */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200943 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200944
945 return VCLKIndex;
946}
947
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800948static void XGI_SetCRT1VCLK(unsigned short ModeNo,
949 unsigned short ModeIdIndex,
950 struct xgi_hw_device_info *HwDeviceExtension,
951 unsigned short RefreshRateTableIndex,
952 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200953{
Bill Pemberton108afbf2010-06-17 13:10:47 -0400954 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530955 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200956
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530957 if (pVBInfo->IF_DEF_LVDS == 1) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200958 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200959 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200960 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200961 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
962 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200963 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Peter Huewe6896b942012-02-09 21:11:46 +0100964 } else if ((pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
965 | VB_SIS302LV | VB_XGI301C)) && (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +0100966 & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530967 vclkindex = XGI_GetVCLK2Ptr(ModeNo, ModeIdIndex,
968 RefreshRateTableIndex, HwDeviceExtension,
969 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200970 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200971 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200972 data = XGI_VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200973 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200974 data = XGI_VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200975 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
976 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530977 } else {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200978 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200979 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200980 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200981 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
982 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200983 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530984 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200985
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530986 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinenb3979922012-11-04 21:14:52 +0200987 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800988 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200989 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200990 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200991 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530992 index = data;
993 index &= 0xE0;
994 data &= 0x1F;
995 data = data << 1;
996 data += 1;
997 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200998 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530999 }
1000 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001001}
1002
Aaro Koskinene85f2032011-11-27 23:03:07 +02001003static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
1004{
1005 unsigned char temp;
1006
1007 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
1008 temp = (temp & 1) << 6;
1009 /* SR06[6] 18bit Dither */
1010 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
1011 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
1012 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
1013
1014}
1015
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001016static void XGI_SetCRT1FIFO(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301017 struct xgi_hw_device_info *HwDeviceExtension,
1018 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001019{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301020 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001021
Aaro Koskinen58839b02011-03-13 12:26:23 +02001022 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301023 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001024 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001025
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001026 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
1027 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
1028 data &= 0xC0;
1029 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
1030 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
1031 data |= 0x01;
1032 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001033
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301034 if (HwDeviceExtension->jChipType == XG21)
1035 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001036}
1037
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001038static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
1039 unsigned short ModeNo, unsigned short RefreshRateTableIndex,
1040 struct vb_device_info *pVBInfo)
1041{
1042 unsigned short data, data2 = 0;
1043 short VCLK;
1044
1045 unsigned char index;
1046
Aaro Koskinena39325d2012-11-04 21:14:53 +02001047 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001048 index &= IndexMask;
Aaro Koskinenacfe0932012-11-04 21:14:58 +02001049 VCLK = XGI_VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001050
Aaro Koskinen58839b02011-03-13 12:26:23 +02001051 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001052 data &= 0xf3;
1053 if (VCLK >= 200)
1054 data |= 0x0c; /* VCLK > 200 */
1055
1056 if (HwDeviceExtension->jChipType >= XG20)
1057 data &= ~0x04; /* 2 pixel mode */
1058
Aaro Koskinen8104e322011-03-13 12:26:22 +02001059 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001060
1061 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001062 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001063 data &= 0xE7;
1064 if (VCLK < 200)
1065 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001066 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001067 }
1068
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001069 data2 = 0x00;
1070
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001071 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001072 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001073 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001074
1075}
1076
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001077static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301078 unsigned short ModeNo, unsigned short ModeIdIndex,
1079 unsigned short RefreshRateTableIndex,
1080 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001081{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301082 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1083 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001084
Aaro Koskinenb3979922012-11-04 21:14:52 +02001085 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001086 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001087
Aaro Koskinen58839b02011-03-13 12:26:23 +02001088 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001089 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001090
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001091 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301092 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001093 data2 |= 0x02;
1094 data3 = pVBInfo->ModeType - ModeVGA;
1095 data3 = data3 << 2;
1096 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301097 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001098
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301099 if (data)
1100 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001101
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001102 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinenb3979922012-11-04 21:14:52 +02001103 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001104 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301106 data = 0x0000;
1107 if (infoflag & InterlaceMode) {
1108 if (xres == 1024)
1109 data = 0x0035;
1110 else if (xres == 1280)
1111 data = 0x0048;
1112 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301114 data2 = data & 0x00FF;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001115 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301116 data2 = (data & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001117 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, data2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001118
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301119 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001120 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001121
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301122 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001123
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301124 if (modeflag & LineCompareOff)
1125 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001126
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001127 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301128 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001129 data = data ^ 0x60;
1130 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001131 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001132
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301133 XGI_SetVCLKState(HwDeviceExtension, ModeNo, RefreshRateTableIndex,
1134 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001135
Aaro Koskinen58839b02011-03-13 12:26:23 +02001136 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001137
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301138 if (HwDeviceExtension->jChipType == XG27) {
1139 if (data & 0x40)
1140 data = 0x2c;
1141 else
1142 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001143 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001144 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301145 } else if (HwDeviceExtension->jChipType >= XG20) {
1146 if (data & 0x40)
1147 data = 0x33;
1148 else
1149 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001150 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1151 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301152 } else {
1153 if (data & 0x40)
1154 data = 0x2c;
1155 else
1156 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001157 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301158 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001159
1160}
1161
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001162static void XGI_WriteDAC(unsigned short dl,
1163 unsigned short ah,
1164 unsigned short al,
1165 unsigned short dh,
1166 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001167{
1168 unsigned short temp, bh, bl;
1169
1170 bh = ah;
1171 bl = al;
1172
1173 if (dl != 0) {
1174 temp = bh;
1175 bh = dh;
1176 dh = temp;
1177 if (dl == 1) {
1178 temp = bl;
1179 bl = dh;
1180 dh = temp;
1181 } else {
1182 temp = bl;
1183 bl = bh;
1184 bh = temp;
1185 }
1186 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001187 outb((unsigned short) dh, pVBInfo->P3c9);
1188 outb((unsigned short) bh, pVBInfo->P3c9);
1189 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001190}
1191
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001192static void XGI_LoadDAC(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301193 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001194{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001195 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1196 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001197
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001198 outb(0xFF, pVBInfo->P3c6);
1199 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001200
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001201 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301202 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001203
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301204 for (k = 0; k < 3; k++) {
1205 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001206
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301207 if (data & 0x01)
1208 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001209
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301210 if (data & 0x02)
1211 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001212
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001213 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301214 data = data >> 2;
1215 }
1216 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001217
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001218 for (i = 16; i < 32; i++) {
1219 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001220
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001221 for (k = 0; k < 3; k++)
1222 outb(data, pVBInfo->P3c9);
1223 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001224
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001225 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001226
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001227 for (m = 0; m < 9; m++) {
1228 di = si;
1229 bx = si + 0x04;
1230 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001231
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001232 for (n = 0; n < 3; n++) {
1233 for (o = 0; o < 5; o++) {
1234 dh = table[si];
1235 ah = table[di];
1236 al = table[bx];
1237 si++;
1238 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301239 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001240
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001241 si -= 2;
1242
1243 for (o = 0; o < 3; o++) {
1244 dh = table[bx];
1245 ah = table[di];
1246 al = table[si];
1247 si--;
1248 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1249 }
1250
1251 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301252 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001253
1254 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301255 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001256}
1257
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001258static void XGI_GetLVDSResInfo(unsigned short ModeNo,
1259 unsigned short ModeIdIndex,
1260 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001261{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301262 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001263
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001264 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001265 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001266
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001267 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001268 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001269
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001270 xres = pVBInfo->ModeResInfo[resindex].HTotal;
1271 yres = pVBInfo->ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001272
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001273 if (modeflag & HalfDCLK)
1274 xres = xres << 1;
1275
1276 if (modeflag & DoubleScanMode)
1277 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001278
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301279 if (xres == 720)
1280 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001281
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301282 pVBInfo->VGAHDE = xres;
1283 pVBInfo->HDE = xres;
1284 pVBInfo->VGAVDE = yres;
1285 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001286}
1287
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001288static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001289 unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001290 unsigned short ModeIdIndex,
1291 unsigned short RefreshRateTableIndex,
1292 struct vb_device_info *pVBInfo)
1293{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001294 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001295
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001296 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001297
Aaro Koskinenb3979922012-11-04 21:14:52 +02001298 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001299
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001300 i = 0;
1301
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001302 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001303 tempdx = pVBInfo->LCDResInfo;
1304 if (tempbx & 0x0080) { /* OEMUtil */
1305 tempbx &= (~0x0080);
1306 tempdx = pVBInfo->LCDTypeInfo;
1307 }
1308
1309 if (pVBInfo->LCDInfo & EnableScalingLCD)
1310 tempdx &= (~PanelResInfo);
1311
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001312 if (table[i].PANELID == tempdx) {
1313 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001314 tempdx = pVBInfo->LCDInfo;
1315
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001316 if (modeflag & HalfDCLK)
1317 tempdx |= SetLCDLowResolution;
1318
1319 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001320 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001321 break;
1322 }
1323 i++;
1324 }
1325
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001326 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001327}
1328
Aaro Koskinen24572542012-09-11 00:15:21 +03001329static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001330 unsigned short ModeIdIndex,
1331 unsigned short RefreshRateTableIndex,
1332 struct vb_device_info *pVBInfo)
1333{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001334 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001335
Aaro Koskinenb3979922012-11-04 21:14:52 +02001336 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001337 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001338 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001339 tempdx = pVBInfo->TVInfo;
1340
1341 if (pVBInfo->VBInfo & SetInSlaveMode)
1342 tempdx = tempdx | SetTVLockMode;
1343
1344 if (modeflag & HalfDCLK)
1345 tempdx = tempdx | SetTVLowResolution;
1346
1347 i = 0;
1348
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001349 while (XGI_TVDataTable[i].MASK != 0xffff) {
1350 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1351 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001352 break;
1353 i++;
1354 }
1355
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001356 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001357}
1358
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001359static void XGI_GetLVDSData(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301360 unsigned short RefreshRateTableIndex,
1361 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001362{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001363 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001364
Aaro Koskinen6008f872012-11-04 21:14:49 +02001365 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1366 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001367
Aaro Koskinen6008f872012-11-04 21:14:49 +02001368 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeNo, ModeIdIndex,
1369 RefreshRateTableIndex, pVBInfo);
1370 pVBInfo->VGAHT = LCDPtr->VGAHT;
1371 pVBInfo->VGAVT = LCDPtr->VGAVT;
1372 pVBInfo->HT = LCDPtr->LCDHT;
1373 pVBInfo->VT = LCDPtr->LCDVT;
1374
1375 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1376 return;
1377
1378 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1379 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1380 pVBInfo->HDE = 1024;
1381 pVBInfo->VDE = 768;
1382 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1383 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1384 pVBInfo->HDE = 1280;
1385 pVBInfo->VDE = 1024;
1386 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1387 pVBInfo->HDE = 1400;
1388 pVBInfo->VDE = 1050;
1389 } else {
1390 pVBInfo->HDE = 1600;
1391 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301392 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001393}
1394
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001395static void XGI_ModCRT1Regs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301396 unsigned short RefreshRateTableIndex,
1397 struct xgi_hw_device_info *HwDeviceExtension,
1398 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001399{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301400 unsigned char index;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001401 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001402 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1403 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001404
Aaro Koskinena39325d2012-11-04 21:14:53 +02001405 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301406 index = index & IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001407
Peter Huewea3d675c2012-02-09 21:11:47 +01001408 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001409 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001410 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001411
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001412 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001413 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301414 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001415
1416 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1417
Peter Huewea3d675c2012-02-09 21:11:47 +01001418 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001419 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeNo,
1420 ModeIdIndex, RefreshRateTableIndex,
1421 pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001422 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001423 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001424 }
1425
1426 XGI_SetCRT1Timing_V(ModeIdIndex, ModeNo, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001427}
1428
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001429static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1430{
1431 unsigned char tempal, tempah, tempbl, i;
1432
Aaro Koskinen58839b02011-03-13 12:26:23 +02001433 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001434 tempal = tempah & 0x0F;
1435 tempah = tempah & 0xF0;
1436 i = 0;
1437 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1438
1439 while (tempbl != 0xFF) {
1440 if (tempbl & 0x80) { /* OEMUtil */
1441 tempal = tempah;
1442 tempbl = tempbl & ~(0x80);
1443 }
1444
1445 if (tempal == tempbl)
1446 break;
1447
1448 i++;
1449
1450 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1451 }
1452
1453 return i;
1454}
1455
1456static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1457{
1458 unsigned short tempah, tempal, tempbl, i;
1459
1460 tempal = pVBInfo->LCDResInfo;
1461 tempah = pVBInfo->LCDTypeInfo;
1462
1463 i = 0;
1464 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1465
1466 while (tempbl != 0xFF) {
1467 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1468 tempal = tempah;
1469 tempbl &= ~0x80;
1470 }
1471
1472 if (tempal == tempbl)
1473 break;
1474
1475 i++;
1476 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1477 }
1478
1479 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001480 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001481 pVBInfo->LCDTypeInfo = 0;
1482 i = 0;
1483 }
1484
1485 return i;
1486}
1487
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001488static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1489 unsigned short *VSyncWidth,
1490 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001491{
1492 unsigned short Index;
1493
1494 Index = XGI_GetLCDCapPtr(pVBInfo);
1495 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1496 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
1497
1498 return;
1499}
1500
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001501static void XGI_SetLVDSRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301502 unsigned short RefreshRateTableIndex,
1503 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001504{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301505 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1506 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001507 struct XGI_LCDDesStruct const *LCDPtr = NULL;
1508 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001509
Aaro Koskinenb3979922012-11-04 21:14:52 +02001510 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen66cface2011-08-31 21:46:13 +03001511 if (pVBInfo->LCDInfo & EnableScalingLCD)
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001512 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo,
1513 ModeIdIndex, RefreshRateTableIndex,
1514 pVBInfo);
Aaro Koskinen66cface2011-08-31 21:46:13 +03001515 else
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001516 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeNo,
1517 ModeIdIndex, RefreshRateTableIndex,
1518 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001519
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001520 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1521 push1 = tempbx;
1522 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001523
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001524 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001525 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1526 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001527 tempax = 1024;
1528 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001529 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1530 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001531 tempax = 1280;
1532 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001533 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001534 tempax = 1400;
1535 tempbx = 1050;
1536 } else {
1537 tempax = 1600;
1538 tempbx = 1200;
1539 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001540
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001541 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1542 pVBInfo->HDE = tempax;
1543 pVBInfo->VDE = tempbx;
1544 pVBInfo->VGAHDE = tempax;
1545 pVBInfo->VGAVDE = tempbx;
1546 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001547
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001548 tempax = pVBInfo->HT;
1549
1550 if (pVBInfo->LCDInfo & EnableScalingLCD)
1551 tempbx = LCDPtr1->LCDHDES;
1552 else
1553 tempbx = LCDPtr->LCDHDES;
1554
1555 tempcx = pVBInfo->HDE;
1556 tempbx = tempbx & 0x0fff;
1557 tempcx += tempbx;
1558
1559 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001560 tempcx -= tempax;
1561
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001562 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001563
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001564 tempcx = tempcx >> 3;
1565 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001566
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001567 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1568 (unsigned short) (tempbx & 0xff));
1569 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1570 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001571
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001572 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001573
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001574 if (pVBInfo->LCDInfo & EnableScalingLCD)
1575 tempbx = LCDPtr1->LCDHRS;
1576 else
1577 tempbx = LCDPtr->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001578
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001579 tempcx = push2;
1580
1581 if (pVBInfo->LCDInfo & EnableScalingLCD)
1582 tempcx = LCDPtr1->LCDHSync;
1583
1584 tempcx += tempbx;
1585
1586 if (tempcx >= tempax)
1587 tempcx -= tempax;
1588
1589 tempax = tempbx & 0x07;
1590 tempax = tempax >> 5;
1591 tempcx = tempcx >> 3;
1592 tempbx = tempbx >> 3;
1593
1594 tempcx &= 0x1f;
1595 tempax |= tempcx;
1596
1597 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1598 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1599 (unsigned short) (tempbx & 0xff));
1600
1601 tempax = pVBInfo->VT;
1602 if (pVBInfo->LCDInfo & EnableScalingLCD)
1603 tempbx = LCDPtr1->LCDVDES;
1604 else
1605 tempbx = LCDPtr->LCDVDES;
1606 tempcx = pVBInfo->VDE;
1607
1608 tempbx = tempbx & 0x0fff;
1609 tempcx += tempbx;
1610 if (tempcx >= tempax)
1611 tempcx -= tempax;
1612
1613 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1614 (unsigned short) (tempbx & 0xff));
1615 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1616 (unsigned short) (tempcx & 0xff));
1617
1618 tempbx = (tempbx >> 8) & 0x07;
1619 tempcx = (tempcx >> 8) & 0x07;
1620
1621 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1622 (unsigned short) ((tempcx << 3)
1623 | tempbx));
1624
1625 tempax = pVBInfo->VT;
1626 if (pVBInfo->LCDInfo & EnableScalingLCD)
1627 tempbx = LCDPtr1->LCDVRS;
1628 else
1629 tempbx = LCDPtr->LCDVRS;
1630
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001631 tempcx = push1;
1632
1633 if (pVBInfo->LCDInfo & EnableScalingLCD)
1634 tempcx = LCDPtr1->LCDVSync;
1635
1636 tempcx += tempbx;
1637 if (tempcx >= tempax)
1638 tempcx -= tempax;
1639
1640 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1641 (unsigned short) (tempbx & 0xff));
1642 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1643 (unsigned short) (tempcx & 0x0f));
1644
1645 tempax = ((tempbx >> 8) & 0x07) << 3;
1646
1647 tempbx = pVBInfo->VGAVDE;
1648 if (tempbx != pVBInfo->VDE)
1649 tempax |= 0x40;
1650
Peter Huewea3d675c2012-02-09 21:11:47 +01001651 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001652 tempax |= 0x40;
1653
1654 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1655 tempax);
1656
1657 tempcx = pVBInfo->VGAVT;
1658 tempbx = pVBInfo->VDE;
1659 tempax = pVBInfo->VGAVDE;
1660 tempcx -= tempax;
1661
1662 temp = tempax; /* 0430 ylshieh */
1663 temp1 = (temp << 18) / tempbx;
1664
1665 tempdx = (unsigned short) ((temp << 18) % tempbx);
1666
1667 if (tempdx != 0)
1668 temp1 += 1;
1669
1670 temp2 = temp1;
1671 push3 = temp2;
1672
1673 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1674 (unsigned short) (temp2 & 0xff));
1675 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1676 (unsigned short) ((temp2 >> 8) & 0xff));
1677
1678 tempbx = (unsigned short) (temp2 >> 16);
1679 tempax = tempbx & 0x03;
1680
1681 tempbx = pVBInfo->VGAVDE;
1682 if (tempbx == pVBInfo->VDE)
1683 tempax |= 0x04;
1684
1685 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1686
1687 if (pVBInfo->VBType & VB_XGI301C) {
1688 temp2 = push3;
1689 xgifb_reg_set(pVBInfo->Part4Port,
1690 0x3c,
1691 (unsigned short) (temp2 & 0xff));
1692 xgifb_reg_set(pVBInfo->Part4Port,
1693 0x3b,
1694 (unsigned short) ((temp2 >> 8) &
1695 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001696 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001697 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1698 ~0xc0,
1699 (unsigned short) ((tempbx &
1700 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001701
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001702 tempcx = pVBInfo->VGAVDE;
1703 if (tempcx == pVBInfo->VDE)
1704 xgifb_reg_and_or(pVBInfo->Part4Port,
1705 0x30, ~0x0c, 0x00);
1706 else
1707 xgifb_reg_and_or(pVBInfo->Part4Port,
1708 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301709 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001710
1711 tempcx = pVBInfo->VGAHDE;
1712 tempbx = pVBInfo->HDE;
1713
1714 temp1 = tempcx << 16;
1715
1716 tempax = (unsigned short) (temp1 / tempbx);
1717
1718 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1719 tempax = 65535;
1720
1721 temp3 = tempax;
1722 temp1 = pVBInfo->VGAHDE << 16;
1723
1724 temp1 /= temp3;
1725 temp3 = temp3 << 16;
1726 temp1 -= 1;
1727
1728 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1729
1730 tempax = (unsigned short) (temp3 & 0xff);
1731 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1732
1733 temp1 = pVBInfo->VGAVDE << 18;
1734 temp1 = temp1 / push3;
1735 tempbx = (unsigned short) (temp1 & 0xffff);
1736
Peter Huewe255aabd2012-02-09 21:11:44 +01001737 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001738 tempbx -= 1;
1739
1740 tempax = ((tempbx >> 8) & 0xff) << 3;
1741 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1742 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1743 (unsigned short) (tempax & 0xff));
1744 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1745 (unsigned short) (tempbx & 0xff));
1746
1747 temp3 = temp3 >> 16;
1748
1749 if (modeflag & HalfDCLK)
1750 temp3 = temp3 >> 1;
1751
1752 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1753 (unsigned short) ((temp3 >> 8) & 0xff));
1754 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1755 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001756}
1757
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001758/* --------------------------------------------------------------------- */
1759/* Function : XGI_GETLCDVCLKPtr */
1760/* Input : */
1761/* Output : al -> VCLK Index */
1762/* Description : */
1763/* --------------------------------------------------------------------- */
1764static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1765 struct vb_device_info *pVBInfo)
1766{
1767 unsigned short index;
1768
Peter Huewea3d675c2012-02-09 21:11:47 +01001769 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001770 index = XGI_GetLCDCapPtr1(pVBInfo);
1771
1772 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1773 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1774 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1775 } else { /* LCDA */
1776 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1777 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1778 }
1779 }
1780 return;
1781}
1782
1783static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
1784 unsigned short ModeNo, unsigned short ModeIdIndex,
1785 struct vb_device_info *pVBInfo)
1786{
1787
1788 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001789 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001790
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001791 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001792 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001793
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001794 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1795 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001796 index = XGI_GetLCDCapPtr(pVBInfo);
1797 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1798
Peter Huewea3d675c2012-02-09 21:11:47 +01001799 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001800 return tempal;
1801
1802 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001803 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001804 (VB_SIS301B |
1805 VB_SIS302B |
1806 VB_SIS301LV |
1807 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001808 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001809 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001810 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001811 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001812 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001813 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001814 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001815 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001816 tempal = TVCLKBASE_315 +
1817 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001818
1819 }
1820 return tempal;
1821 }
1822
Peter Huewe599801f2012-02-09 21:11:45 +01001823 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001824 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001825 return tempal;
1826 }
1827
Peter Huewe599801f2012-02-09 21:11:45 +01001828 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001829 tempal = YPbPr525pVCLK;
1830 return tempal;
1831 }
1832
1833 tempal = NTSC1024VCLK;
1834
1835 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001836 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001837 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001838 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001839 }
1840
1841 if (pVBInfo->VBInfo & SetCRT2ToTV)
1842 return tempal;
1843 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001844 } /* {End of VB} */
1845
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02001846 tempal = (unsigned char) inb((pVBInfo->P3ca + 0x02));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001847 tempal = tempal >> 2;
1848 tempal &= 0x03;
1849
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001850 /* for Dot8 Scaling LCD */
1851 if ((pVBInfo->LCDInfo & EnableScalingLCD) && (modeflag & Charx8Dot))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001852 tempal = tempal ^ tempal; /* ; set to VCLK25MHz always */
1853
Aaro Koskinena39325d2012-11-04 21:14:53 +02001854 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001855 return tempal;
1856}
1857
1858static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1859 unsigned char *di_1, struct vb_device_info *pVBInfo)
1860{
Peter Huewe6896b942012-02-09 21:11:46 +01001861 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1862 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001863 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1864 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001865 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001866 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001867 }
1868 } else {
1869 *di_0 = XGI_VCLKData[tempal].SR2B;
1870 *di_1 = XGI_VCLKData[tempal].SR2C;
1871 }
1872}
1873
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001874static void XGI_SetCRT2ECLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301875 unsigned short RefreshRateTableIndex,
1876 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001877{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301878 unsigned char di_0, di_1, tempal;
1879 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001880
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301881 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
1882 pVBInfo);
1883 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1884 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001885
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301886 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001887 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301888 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001889 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301890 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001891 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1892 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301893 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001894 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1895 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301896 }
1897 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001898}
1899
Aaro Koskinen063b9c42011-03-08 22:16:13 +02001900static void XGI_UpdateModeInfo(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301901 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001902{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301903 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001904
Peter Huewe6896b942012-02-09 21:11:46 +01001905 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1906 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301907 tempcl = 0;
1908 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001909 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001910
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301911 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001912 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301913 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001914 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301915 if (!(temp & 0x40))
1916 tempcl |= ActiveCRT1;
1917 }
1918 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001919
Aaro Koskinen58839b02011-03-13 12:26:23 +02001920 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301921 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001922
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301923 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001924 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001925 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301926 if (tempax & 0x04)
1927 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001928
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301929 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001930
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301931 if (!(tempcl & ActiveLCD))
1932 if (temp == 0x01)
1933 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001934
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301935 if (temp == 0x04)
1936 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001937
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301938 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001939 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001940
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301941 if (!(temp & 0x08))
1942 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001943
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301944 if (!(temp & 0x04))
1945 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001946
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301947 if (temp & 0x02)
1948 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001949
Peter Huewe599801f2012-02-09 21:11:45 +01001950 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301951 if (temp & 0x01)
1952 tempch |= ActiveHiTV;
1953 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001954
Peter Huewe599801f2012-02-09 21:11:45 +01001955 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001956 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301957 pVBInfo->Part2Port,
1958 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001959
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301960 if (temp & 0x10)
1961 tempch |= ActiveYPbPr;
1962 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001963
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301964 if (tempch != 0)
1965 tempcl |= ActiveTV;
1966 }
1967 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001968
Aaro Koskinen58839b02011-03-13 12:26:23 +02001969 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301970 if (tempcl & ActiveLCD) {
1971 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1972 if (temp & ActiveTV)
1973 tempcl |= ActiveTV;
1974 }
1975 }
1976 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001977 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001978 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001979
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301980 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001981 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301982 } else {
1983 return;
1984 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001985}
1986
Bill Pemberton80adad82010-06-17 13:10:51 -04001987void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001988{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301989 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001990
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001991 if (pVBInfo->IF_DEF_LVDS != 0)
1992 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001993
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001994 tempbx = VB_SIS302B;
1995 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1996 if (flag == 0x02)
1997 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001998
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001999 tempbx = VB_SIS301;
2000 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
2001 if (flag < 0xB0)
2002 goto finish;
2003
2004 tempbx = VB_SIS301B;
2005 if (flag < 0xC0)
2006 goto bigger_than_0xB0;
2007
2008 tempbx = VB_XGI301C;
2009 if (flag < 0xD0)
2010 goto bigger_than_0xB0;
2011
2012 tempbx = VB_SIS301LV;
2013 if (flag < 0xE0)
2014 goto bigger_than_0xB0;
2015
2016 tempbx = VB_SIS302LV;
2017 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
2018 if (tempah != 0xFF)
2019 tempbx = VB_XGI301C;
2020
2021bigger_than_0xB0:
2022 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
2023 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
2024 if (!(flag & 0x02))
2025 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302026 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02002027
2028finish:
2029 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002030}
2031
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002032static void XGI_GetVBInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302033 struct xgi_hw_device_info *HwDeviceExtension,
2034 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002035{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302036 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002037
Aaro Koskinenb3979922012-11-04 21:14:52 +02002038 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302039 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01002040 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302041 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002042
Miguel Gómezf9317352012-07-06 12:40:48 +02002043 if (!(pVBInfo->VBType & 0xFFFF))
2044 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002045
Miguel Gómezf9317352012-07-06 12:40:48 +02002046 /* Check Display Device */
2047 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
2048 tempbx = tempbx | temp;
2049 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
2050 push = temp;
2051 push = push << 8;
2052 tempax = temp << 8;
2053 tempbx = tempbx | tempax;
2054 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
2055 | SetInSlaveMode | DisableCRT2Display);
2056 temp = 0xFFFF ^ temp;
2057 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002058
Miguel Gómezf9317352012-07-06 12:40:48 +02002059 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002060
Aaro Koskinen4d8f5ca2012-09-11 00:15:17 +03002061 if (pVBInfo->IF_DEF_LVDS == 0) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002062 if (pVBInfo->VBType &
2063 (VB_SIS302B |
2064 VB_SIS301LV |
2065 VB_SIS302LV |
2066 VB_XGI301C)) {
2067 if (temp & EnableDualEdge) {
2068 tempbx |= SetCRT2ToDualEdge;
2069 if (temp & SetToLCDA)
2070 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02002071 }
2072 }
2073 }
2074
2075 if (pVBInfo->IF_DEF_YPbPr == 1) {
2076 if (((pVBInfo->IF_DEF_LVDS == 0) &&
2077 ((pVBInfo->VBType & VB_SIS301LV) ||
2078 (pVBInfo->VBType & VB_SIS302LV) ||
2079 (pVBInfo->VBType & VB_XGI301C)))) {
2080 if (temp & SetYPbPr) {
2081 if (pVBInfo->IF_DEF_HiVision == 1) {
2082 /* shampoo add for new
2083 * scratch */
2084 temp = xgifb_reg_get(
2085 pVBInfo->P3d4,
2086 0x35);
2087 temp &= YPbPrMode;
2088 tempbx |= SetCRT2ToHiVision;
2089
2090 if (temp != YPbPrMode1080i) {
2091 tempbx &=
2092 (~SetCRT2ToHiVision);
2093 tempbx |=
2094 SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302095 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302096 }
2097 }
2098 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002099 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002100
Miguel Gómezf9317352012-07-06 12:40:48 +02002101 tempax = push; /* restore CR31 */
2102
2103 if (pVBInfo->IF_DEF_LVDS == 0) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302104 if (pVBInfo->IF_DEF_YPbPr == 1) {
Miguel Gómezf9317352012-07-06 12:40:48 +02002105 if (pVBInfo->IF_DEF_HiVision == 1)
2106 temp = 0x09FC;
2107 else
2108 temp = 0x097C;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002109 } else if (pVBInfo->IF_DEF_HiVision == 1) {
2110 temp = 0x01FC;
Miguel Gómezf9317352012-07-06 12:40:48 +02002111 } else {
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002112 temp = 0x017C;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302113 }
Justin P. Mattock558f7582012-10-02 21:17:11 -07002114 } else { /* 3rd party chip */
Miguel Gómezf9317352012-07-06 12:40:48 +02002115 temp = SetCRT2ToLCD;
2116 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002117
Miguel Gómezf9317352012-07-06 12:40:48 +02002118 if (!(tempbx & temp)) {
2119 tempax |= DisableCRT2Display;
2120 tempbx = 0;
2121 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002122
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002123 if (!(pVBInfo->VBType & VB_NoLCD)) {
2124 if (tempbx & XGI_SetCRT2ToLCDA) {
2125 if (tempbx & SetSimuScanMode)
2126 tempbx &= (~(SetCRT2ToLCD |
2127 SetCRT2ToRAMDAC |
2128 SwitchCRT2));
2129 else
2130 tempbx &= (~(SetCRT2ToLCD |
2131 SetCRT2ToRAMDAC |
2132 SetCRT2ToTV |
2133 SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02002134 }
2135 }
2136
2137 /* shampoo add */
2138 /* for driver abnormal */
2139 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
2140 if (pVBInfo->IF_DEF_CRT2Monitor == 1) {
2141 if (tempbx & SetCRT2ToRAMDAC) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002142 tempbx &= (0xFF00 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002143 SetCRT2ToRAMDAC |
Peter Huewe6896b942012-02-09 21:11:46 +01002144 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002145 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002146 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302147 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002148 } else {
2149 tempbx &= (~(SetCRT2ToRAMDAC |
2150 SetCRT2ToLCD |
2151 SetCRT2ToTV));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302152 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002153 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002154
Miguel Gómezf9317352012-07-06 12:40:48 +02002155 if (!(pVBInfo->VBType & VB_NoLCD)) {
2156 if (tempbx & SetCRT2ToLCD) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002157 tempbx &= (0xFF00 |
Miguel Gómezf9317352012-07-06 12:40:48 +02002158 SetCRT2ToLCD |
Peter Huewe6896b942012-02-09 21:11:46 +01002159 SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002160 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01002161 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302162 }
Miguel Gómezf9317352012-07-06 12:40:48 +02002163 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002164
Miguel Gómezf9317352012-07-06 12:40:48 +02002165 if (tempbx & SetCRT2ToSCART) {
2166 tempbx &= (0xFF00 |
2167 SetCRT2ToSCART |
2168 SwitchCRT2 |
2169 SetSimuScanMode);
2170 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
2171 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002172
Miguel Gómezf9317352012-07-06 12:40:48 +02002173 if (pVBInfo->IF_DEF_YPbPr == 1) {
2174 if (tempbx & SetCRT2ToYPbPr525750)
2175 tempbx &= (0xFF00 |
2176 SwitchCRT2 |
2177 SetSimuScanMode);
2178 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002179
Miguel Gómezf9317352012-07-06 12:40:48 +02002180 if (pVBInfo->IF_DEF_HiVision == 1) {
2181 if (tempbx & SetCRT2ToHiVision)
2182 tempbx &= (0xFF00 |
2183 SetCRT2ToHiVision |
2184 SwitchCRT2 |
2185 SetSimuScanMode);
2186 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002187
Miguel Gómezf9317352012-07-06 12:40:48 +02002188 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
2189 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
2190 tempbx = DisableCRT2Display;
2191 }
2192
2193 if (!(tempbx & DisableCRT2Display)) {
2194 if ((!(tempbx & DriverMode)) ||
2195 (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002196 if (!(tempbx & XGI_SetCRT2ToLCDA))
2197 tempbx |= (SetInSlaveMode |
2198 SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002199 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002200
Miguel Gómezf9317352012-07-06 12:40:48 +02002201 /* LCD+TV can't support in slave mode
2202 * (Force LCDA+TV->LCDB) */
2203 if ((tempbx & SetInSlaveMode) &&
2204 (tempbx & XGI_SetCRT2ToLCDA)) {
2205 tempbx ^= (SetCRT2ToLCD |
2206 XGI_SetCRT2ToLCDA |
2207 SetCRT2ToDualEdge);
2208 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302209 }
2210 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002211
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302212 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002213}
2214
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002215static void XGI_GetTVInfo(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302216 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002217{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302218 unsigned short temp, tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002219
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302220 tempbx = 0;
2221 resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002222
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302223 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002224 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2225 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002226
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302227 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002228 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302229 tempbx = temp;
Peter Huewe599801f2012-02-09 21:11:45 +01002230 if (tempbx & TVSetPAL) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002231 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01002232 TVSetPALM |
2233 TVSetPALN |
2234 TVSetPAL);
2235 if (tempbx & TVSetPALM)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002236 /* set to NTSC if PAL-M */
Peter Huewe599801f2012-02-09 21:11:45 +01002237 tempbx &= ~TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302238 } else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002239 tempbx &= (SetCHTVOverScan |
Peter Huewe599801f2012-02-09 21:11:45 +01002240 TVSetNTSCJ |
2241 TVSetPAL);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302242 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002243
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302244 if (pVBInfo->IF_DEF_LVDS == 0) {
2245 if (pVBInfo->VBInfo & SetCRT2ToSCART)
Peter Huewe599801f2012-02-09 21:11:45 +01002246 tempbx |= TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302247 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002248
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302249 if (pVBInfo->IF_DEF_YPbPr == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002250 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002251 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302252 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002253
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302254 if (index1 == YPbPrMode525i)
Peter Huewe599801f2012-02-09 21:11:45 +01002255 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002256
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302257 if (index1 == YPbPrMode525p)
Peter Huewe599801f2012-02-09 21:11:45 +01002258 tempbx = tempbx | TVSetYPbPr525p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302259 if (index1 == YPbPrMode750p)
Peter Huewe599801f2012-02-09 21:11:45 +01002260 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302261 }
2262 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002263
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302264 if (pVBInfo->IF_DEF_HiVision == 1) {
Peter Huewe599801f2012-02-09 21:11:45 +01002265 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2266 tempbx = tempbx | TVSetHiVision | TVSetPAL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302267 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002268
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302269 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002270 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2271 (!(pVBInfo->VBInfo & SetNotSimuMode)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302272 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002273
Peter Huewe599801f2012-02-09 21:11:45 +01002274 if (!(tempbx & TVSetPAL) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002275 (modeflag > 13) &&
2276 (resinfo == 8)) /* NTSC 1024x768, */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302277 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002278
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302279 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002280
Peter Huewe599801f2012-02-09 21:11:45 +01002281 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302282 if (pVBInfo->VBInfo & SetInSlaveMode)
2283 tempbx &= (~RPLLDIV2XO);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002284 } else if (tempbx &
2285 (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302286 tempbx &= (~RPLLDIV2XO);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002287 } else if (!(pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01002288 (VB_SIS301B |
2289 VB_SIS302B |
2290 VB_SIS301LV |
2291 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002292 VB_XGI301C))) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +03002293 if (tempbx & TVSimuMode)
2294 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302295 }
2296 }
2297 }
2298 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002299}
2300
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02002301static unsigned char XGI_GetLCDInfo(unsigned short ModeNo,
2302 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002303{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302304 unsigned short temp, tempax, tempbx, modeflag, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002305
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302306 pVBInfo->LCDResInfo = 0;
2307 pVBInfo->LCDTypeInfo = 0;
2308 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002309
Aaro Koskinenb3979922012-11-04 21:14:52 +02002310 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002311 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002312 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002313 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302314 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002315
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302316 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002317 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002318
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002319 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002320 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302321 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002322 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002323 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302324 tempax &= 0x0F;
2325 else
2326 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002327
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302328 if ((resinfo == 6) || (resinfo == 9)) {
2329 if (tempax >= 3)
2330 tempbx |= PanelRef75Hz;
2331 } else if ((resinfo == 7) || (resinfo == 8)) {
2332 if (tempax >= 4)
2333 tempbx |= PanelRef75Hz;
2334 }
2335 }
2336 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002337
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302338 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002339
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302340 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002341
Peter Huewea3d675c2012-02-09 21:11:47 +01002342 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302343 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002344
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302345 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002346
Aaro Koskinen58839b02011-03-13 12:26:23 +02002347 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002348
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302349 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002350
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302351 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002352
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302353 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002354
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302355 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002356
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302357 if (pVBInfo->IF_DEF_LVDS == 0) { /* shampoo */
Peter Huewe6896b942012-02-09 21:11:46 +01002358 if (((pVBInfo->VBType & VB_SIS302LV) || (pVBInfo->VBType
Peter Huewea3d675c2012-02-09 21:11:47 +01002359 & VB_XGI301C)) && (tempax & XGI_LCDDualLink)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302360 tempbx |= SetLCDDualLink;
2361 }
2362 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002363
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302364 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe255aabd2012-02-09 21:11:44 +01002365 if ((pVBInfo->LCDResInfo == Panel_1400x1050) && (pVBInfo->VBInfo
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002366 & SetCRT2ToLCD) && (resinfo == 9) &&
2367 (!(tempbx & EnableScalingLCD)))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02002368 /*
2369 * set to center in 1280x1024 LCDB
2370 * for Panel_1400x1050
2371 */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002372 tempbx |= SetLCDtoNonExpanding;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302373 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002374
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302375 if (pVBInfo->VBInfo & SetInSlaveMode) {
2376 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002377 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302378 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002379 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302380 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002381
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302382 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002383
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302384 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002385}
2386
Bill Pemberton108afbf2010-06-17 13:10:47 -04002387unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302388 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002389{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002390 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002391 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002392 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002393 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002394 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302395 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002396
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302397 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002398}
2399
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002400static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2401{
2402 unsigned char ujRet = 0;
2403 unsigned char i = 0;
2404
2405 for (i = 0; i < 8; i++) {
2406 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002407 ujRet |= (ujDate >> i) & 1;
2408 }
2409
2410 return ujRet;
2411}
2412
2413/*----------------------------------------------------------------------------*/
2414/* output */
2415/* bl[5] : LVDS signal */
2416/* bl[1] : LVDS backlight */
2417/* bl[0] : LVDS VDD */
2418/*----------------------------------------------------------------------------*/
2419static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2420{
2421 unsigned char CR4A, temp;
2422
Aaro Koskinen58839b02011-03-13 12:26:23 +02002423 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002424 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002425
Aaro Koskinen58839b02011-03-13 12:26:23 +02002426 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002427
2428 temp = XG21GPIODataTransfer(temp);
2429 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002430 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002431 return temp;
2432}
2433
2434/*----------------------------------------------------------------------------*/
2435/* output */
2436/* bl[5] : LVDS signal */
2437/* bl[1] : LVDS backlight */
2438/* bl[0] : LVDS VDD */
2439/*----------------------------------------------------------------------------*/
2440static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2441{
2442 unsigned char CR4A, CRB4, temp;
2443
Aaro Koskinen58839b02011-03-13 12:26:23 +02002444 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002445 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002446
Aaro Koskinen58839b02011-03-13 12:26:23 +02002447 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002448
2449 temp &= 0x0C;
2450 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002451 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002452 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002453 temp |= ((CRB4 & 0x04) << 3);
2454 return temp;
2455}
2456
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002457/*----------------------------------------------------------------------------*/
2458/* input */
2459/* bl[5] : 1;LVDS signal on */
2460/* bl[1] : 1;LVDS backlight on */
2461/* bl[0] : 1:LVDS VDD on */
2462/* bh: 100000b : clear bit 5, to set bit5 */
2463/* 000010b : clear bit 1, to set bit1 */
2464/* 000001b : clear bit 0, to set bit0 */
2465/*----------------------------------------------------------------------------*/
2466static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2467 struct vb_device_info *pVBInfo)
2468{
2469 unsigned char CR4A, temp;
2470
2471 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2472 tempbh &= 0x23;
2473 tempbl &= 0x23;
2474 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2475
2476 if (tempbh & 0x20) {
2477 temp = (tempbl >> 4) & 0x02;
2478
2479 /* CR B4[1] */
2480 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2481
2482 }
2483
2484 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2485
2486 temp = XG21GPIODataTransfer(temp);
2487 temp &= ~tempbh;
2488 temp |= tempbl;
2489 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2490}
2491
Aaro Koskinen776115a2011-11-27 23:03:10 +02002492static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2493 struct vb_device_info *pVBInfo)
2494{
2495 unsigned char CR4A, temp;
2496 unsigned short tempbh0, tempbl0;
2497
2498 tempbh0 = tempbh;
2499 tempbl0 = tempbl;
2500 tempbh0 &= 0x20;
2501 tempbl0 &= 0x20;
2502 tempbh0 >>= 3;
2503 tempbl0 >>= 3;
2504
2505 if (tempbh & 0x20) {
2506 temp = (tempbl >> 4) & 0x02;
2507
2508 /* CR B4[1] */
2509 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2510
2511 }
2512 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2513
2514 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2515 tempbh &= 0x03;
2516 tempbl &= 0x03;
2517 tempbh <<= 2;
2518 tempbl <<= 2; /* GPIOC,GPIOD */
2519 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2520 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2521}
2522
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002523static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2524 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302525 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002526{
2527
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002528 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302529 if (pXGIHWDE->jChipType == XG21) {
2530 if (pVBInfo->IF_DEF_LVDS == 1) {
2531 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002532 /* LVDS VDD on */
2533 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002534 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302535 }
2536 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002537 /* LVDS signal on */
2538 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002539 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002540 /* LVDS backlight on */
2541 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302542 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002543 /* DVO/DVI signal on */
2544 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302545 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002546
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302547 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002548
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302549 if (pXGIHWDE->jChipType == XG27) {
2550 if (pVBInfo->IF_DEF_LVDS == 1) {
2551 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002552 /* LVDS VDD on */
2553 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002554 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302555 }
2556 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002557 /* LVDS signal on */
2558 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002559 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002560 /* LVDS backlight on */
2561 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302562 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002563 /* DVO/DVI signal on */
2564 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302565 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002566
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302567 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002568}
2569
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002570void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2571 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302572 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002573{
2574
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302575 if (pXGIHWDE->jChipType == XG21) {
2576 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002577 /* LVDS backlight off */
2578 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002579 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302580 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002581 /* DVO/DVI signal off */
2582 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302583 }
2584 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002585
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302586 if (pXGIHWDE->jChipType == XG27) {
2587 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002588 /* LVDS backlight off */
2589 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002590 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302591 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002592
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302593 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002594 /* DVO/DVI signal off */
2595 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302596 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002597
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002598 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002599}
2600
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002601static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002602{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002603 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302604 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002605
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002606 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302607 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002608}
2609
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002610static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002611{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002612 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002613}
2614
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002615static void XGI_SaveCRT2Info(unsigned short ModeNo,
2616 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002617{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302618 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002619
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002620 /* reserve CR34 for CRT1 Mode No */
2621 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302622 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2623 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002624 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002625}
2626
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002627static void XGI_GetCRT2ResInfo(unsigned short ModeNo,
2628 unsigned short ModeIdIndex,
2629 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002630{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302631 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002632
Aaro Koskinenb3979922012-11-04 21:14:52 +02002633 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002634 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
2635 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
2636 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002637 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002638
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002639 if (modeflag & HalfDCLK)
2640 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002641
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002642 if (modeflag & DoubleScanMode)
2643 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002644
Miguel Gómez3339db82012-07-06 12:40:49 +02002645 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2646 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002647
Miguel Gómez3339db82012-07-06 12:40:49 +02002648 if (pVBInfo->IF_DEF_LVDS == 0) {
2649 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2650 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2651 if (yres == 1024)
2652 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302653 }
2654 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002655
Miguel Gómez3339db82012-07-06 12:40:49 +02002656 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2657 if (yres == 400)
2658 yres = 405;
2659 else if (yres == 350)
2660 yres = 360;
2661
2662 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2663 if (yres == 360)
2664 yres = 375;
2665 }
2666 }
2667
2668 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2669 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2670 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2671 if (yres == 350)
2672 yres = 357;
2673 else if (yres == 400)
2674 yres = 420;
2675 else if (yres == 480)
2676 yres = 525;
2677 }
2678 }
2679 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302680 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002681
Miguel Gómez3339db82012-07-06 12:40:49 +02002682 if (xres == 720)
2683 xres = 640;
2684
2685exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302686 pVBInfo->VGAHDE = xres;
2687 pVBInfo->HDE = xres;
2688 pVBInfo->VGAVDE = yres;
2689 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002690}
2691
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002692static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002693{
2694
Peter Huewea3d675c2012-02-09 21:11:47 +01002695 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002696 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302697 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002698
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302699 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002700}
2701
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002702static void XGI_GetRAMDAC2DATA(unsigned short ModeNo,
2703 unsigned short ModeIdIndex,
2704 unsigned short RefreshRateTableIndex,
2705 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002706{
2707 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002708 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002709
2710 pVBInfo->RVBHCMAX = 1;
2711 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002712 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002713 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002714 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002715 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2716 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002717 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002718 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002719 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002720 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002721 tempcx &= 0x0100;
2722 tempcx = tempcx << 2;
2723 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002724 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002725
2726 if (temp1 & 0x01)
2727 tempbx |= 0x0100;
2728
2729 if (temp1 & 0x20)
2730 tempbx |= 0x0200;
2731 tempax += 5;
2732
2733 if (modeflag & Charx8Dot)
2734 tempax *= 8;
2735 else
2736 tempax *= 9;
2737
2738 pVBInfo->VGAHT = tempax;
2739 pVBInfo->HT = tempax;
2740 tempbx++;
2741 pVBInfo->VGAVT = tempbx;
2742 pVBInfo->VT = tempbx;
2743}
2744
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002745static void XGI_GetCRT2Data(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302746 unsigned short RefreshRateTableIndex,
2747 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002748{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002749 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002750
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002751 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002752
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002753 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002754 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2755 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302756 pVBInfo->NewFlickerMode = 0;
2757 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002758
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302759 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
2760 XGI_GetRAMDAC2DATA(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2761 pVBInfo);
2762 return;
2763 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002764
Peter Huewea3d675c2012-02-09 21:11:47 +01002765 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002766 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeNo, ModeIdIndex,
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03002767 RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002768
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302769 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2770 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2771 pVBInfo->VGAHT = LCDPtr->VGAHT;
2772 pVBInfo->VGAVT = LCDPtr->VGAVT;
2773 pVBInfo->HT = LCDPtr->LCDHT;
2774 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002775
Peter Huewe255aabd2012-02-09 21:11:44 +01002776 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302777 tempax = 1024;
2778 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002779
Peter Huewea3d675c2012-02-09 21:11:47 +01002780 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302781 if (pVBInfo->VGAVDE == 357)
2782 tempbx = 527;
2783 else if (pVBInfo->VGAVDE == 420)
2784 tempbx = 620;
2785 else if (pVBInfo->VGAVDE == 525)
2786 tempbx = 775;
2787 else if (pVBInfo->VGAVDE == 600)
2788 tempbx = 775;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302789 else
2790 tempbx = 768;
2791 } else
2792 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002793 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302794 tempax = 1024;
2795 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002796 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302797 tempax = 1280;
2798 if (pVBInfo->VGAVDE == 360)
2799 tempbx = 768;
2800 else if (pVBInfo->VGAVDE == 375)
2801 tempbx = 800;
2802 else if (pVBInfo->VGAVDE == 405)
2803 tempbx = 864;
2804 else
2805 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002806 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302807 tempax = 1280;
2808 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002809 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302810 tempax = 1280;
2811 if (pVBInfo->VGAVDE == 350)
2812 tempbx = 700;
2813 else if (pVBInfo->VGAVDE == 400)
2814 tempbx = 800;
2815 else if (pVBInfo->VGAVDE == 1024)
2816 tempbx = 960;
2817 else
2818 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002819 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302820 tempax = 1400;
2821 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002822
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302823 if (pVBInfo->VGAVDE == 1024) {
2824 tempax = 1280;
2825 tempbx = 1024;
2826 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002827 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302828 tempax = 1600;
2829 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002830 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302831 if (pVBInfo->VGAVDE == 350)
2832 tempbx = 875;
2833 else if (pVBInfo->VGAVDE == 400)
2834 tempbx = 1000;
2835 }
2836 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002837
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302838 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2839 tempax = pVBInfo->VGAHDE;
2840 tempbx = pVBInfo->VGAVDE;
2841 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002842
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302843 pVBInfo->HDE = tempax;
2844 pVBInfo->VDE = tempbx;
2845 return;
2846 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002847
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302848 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002849 struct SiS_TVData const *TVPtr;
2850
2851 TVPtr = XGI_GetTVPtr(ModeNo, ModeIdIndex, RefreshRateTableIndex,
2852 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002853
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302854 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2855 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2856 pVBInfo->VGAHT = TVPtr->VGAHT;
2857 pVBInfo->VGAVT = TVPtr->VGAVT;
2858 pVBInfo->HDE = TVPtr->TVHDE;
2859 pVBInfo->VDE = TVPtr->TVVDE;
2860 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2861 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002862
Peter Huewe599801f2012-02-09 21:11:45 +01002863 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302864 if (resinfo == 0x08)
2865 pVBInfo->NewFlickerMode = 0x40;
2866 else if (resinfo == 0x09)
2867 pVBInfo->NewFlickerMode = 0x40;
2868 else if (resinfo == 0x12)
2869 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002870
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302871 if (pVBInfo->VGAVDE == 350)
2872 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002873
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302874 tempax = ExtHiTVHT;
2875 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002876
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302877 if (pVBInfo->VBInfo & SetInSlaveMode) {
2878 if (pVBInfo->TVInfo & TVSimuMode) {
2879 tempax = StHiTVHT;
2880 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002881
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302882 if (!(modeflag & Charx8Dot)) {
2883 tempax = StHiTextTVHT;
2884 tempbx = StHiTextTVVT;
2885 }
2886 }
2887 }
Peter Huewe599801f2012-02-09 21:11:45 +01002888 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2889 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302890 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2891 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2892 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002893
Peter Huewe599801f2012-02-09 21:11:45 +01002894 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302895 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2896 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002897 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302898 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2899 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2900 if (pVBInfo->TVInfo & NTSC1024x768)
2901 tempax = NTSC1024x768HT;
2902 }
2903 } else {
2904 tempax = PALHT;
2905 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002906 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302907 tempax = NTSCHT;
2908 tempbx = NTSCVT;
2909 if (pVBInfo->TVInfo & NTSC1024x768)
2910 tempax = NTSC1024x768HT;
2911 }
2912 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002913
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302914 pVBInfo->HT = tempax;
2915 pVBInfo->VT = tempbx;
2916 return;
2917 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002918}
2919
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002920static void XGI_SetCRT2VCLK(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302921 unsigned short RefreshRateTableIndex,
2922 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002923{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002924 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002925
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302926 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeNo, ModeIdIndex,
2927 pVBInfo);
2928 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2929 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002930
Peter Huewe6896b942012-02-09 21:11:46 +01002931 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302932 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002933 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2934 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2935 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302936 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002937 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2938 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302939 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002940
Aaro Koskinen8104e322011-03-13 12:26:22 +02002941 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002942
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302943 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002944 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302945 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002946 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002947}
2948
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002949static unsigned short XGI_GetColorDepth(unsigned short ModeNo,
2950 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002951{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002952 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2953 short index;
2954 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302955
Aaro Koskinenb3979922012-11-04 21:14:52 +02002956 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002957 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302958
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002959 if (index < 0)
2960 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302961
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002962 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302963}
2964
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002965static unsigned short XGI_GetOffset(unsigned short ModeNo,
2966 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302967 unsigned short RefreshRateTableIndex,
2968 struct xgi_hw_device_info *HwDeviceExtension,
2969 struct vb_device_info *pVBInfo)
2970{
2971 unsigned short temp, colordepth, modeinfo, index, infoflag,
2972 ColorDepth[] = { 0x01, 0x02, 0x04 };
2973
Aaro Koskinenb3979922012-11-04 21:14:52 +02002974 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002975 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302976
2977 index = (modeinfo >> 8) & 0xFF;
2978
Aaro Koskinen224114c2012-11-04 21:14:59 +02002979 temp = XGI330_ScreenOffset[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302980
2981 if (infoflag & InterlaceMode)
2982 temp = temp << 1;
2983
2984 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
2985
2986 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2987 temp = ModeNo - 0x7C;
2988 colordepth = ColorDepth[temp];
2989 temp = 0x6B;
2990 if (infoflag & InterlaceMode)
2991 temp = temp << 1;
2992 return temp * colordepth;
2993 } else {
2994 return temp * colordepth;
2995 }
2996}
2997
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002998static void XGI_SetCRT2Offset(unsigned short ModeNo,
2999 unsigned short ModeIdIndex,
3000 unsigned short RefreshRateTableIndex,
3001 struct xgi_hw_device_info *HwDeviceExtension,
3002 struct vb_device_info *pVBInfo)
3003{
3004 unsigned short offset;
3005 unsigned char temp;
3006
3007 if (pVBInfo->VBInfo & SetInSlaveMode)
3008 return;
3009
3010 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3011 HwDeviceExtension, pVBInfo);
3012 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003013 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003014 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003015 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003016 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003017 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003018}
3019
Randy Dunlap89229672010-08-10 08:46:44 -07003020static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003021{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003022 /* threshold high ,disable auto threshold */
3023 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
3024 /* threshold low default 04h */
3025 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003026}
3027
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003028static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303029 struct xgi_hw_device_info *HwDeviceExtension,
3030 unsigned short RefreshRateTableIndex,
3031 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003032{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303033 unsigned short tempcx = 0, CRT1Index = 0, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003034
Aaro Koskinena39325d2012-11-04 21:14:53 +02003035 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003036 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02003037 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003038
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303039 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
3040 HwDeviceExtension, pVBInfo);
3041 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003042
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303043 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003044 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003045
Aaro Koskinen8104e322011-03-13 12:26:22 +02003046 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
3047 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003048}
3049
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003050static void XGI_SetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303051 struct xgi_hw_device_info *HwDeviceExtension,
3052 unsigned short RefreshRateTableIndex,
3053 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003054{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303055 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
3056 pushbx = 0, CRT1Index = 0, modeflag, resinfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003057
Aaro Koskinena39325d2012-11-04 21:14:53 +02003058 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003059 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02003060 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
3061 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003062
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303063 /* bainy change table name */
3064 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003065 /* BTVGA2HT 0x08,0x09 */
3066 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003067 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303068 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003069 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003070 /* BTVGA2HDEE 0x0A,0x0C */
3071 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003072 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303073 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
3074 pushbx = pVBInfo->VGAHDE / 2 + 16;
3075 tempcx = tempcx >> 1;
3076 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3077 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003078
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303079 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003080 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
3081 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003082 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303083 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003084 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303085 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003086 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303087 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3088 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3089 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003090
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303091 tempbx += 4;
3092 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003093
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303094 if (tempcx > (pVBInfo->VGAHT / 2))
3095 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003096
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303097 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003098
Aaro Koskinen8104e322011-03-13 12:26:22 +02003099 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303100 } else {
3101 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003102 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303103 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003104 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003105 /* BTVGA2HDEE 0x0A,0x0C */
3106 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003107 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303108 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
3109 pushbx = pVBInfo->VGAHDE + 16;
3110 tempcx = tempcx >> 1;
3111 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
3112 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003113
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303114 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003115 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
3116 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003117 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303118 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003119 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303120 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003121 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303122 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
3123 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
3124 tempbx += 16;
3125 tempcx += 16;
3126 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003127
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303128 if (tempcx > pVBInfo->VGAHT)
3129 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003130
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303131 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003132 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303133 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303135 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
3136 tempbx = pushbx;
3137 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
3138 tempax |= (tempbx & 0xFF00);
3139 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003140 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303141 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003142 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303143 tempcx = (pVBInfo->VGAVT - 1);
3144 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003145
Aaro Koskinen8104e322011-03-13 12:26:22 +02003146 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303147 tempbx = pVBInfo->VGAVDE - 1;
3148 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003149 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303150 temp = ((tempbx & 0xFF00) << 3) >> 8;
3151 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003152 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003153
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303154 tempax = pVBInfo->VGAVDE;
3155 tempbx = pVBInfo->VGAVDE;
3156 tempcx = pVBInfo->VGAVT;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003157 /* BTVGA2VRS 0x10,0x11 */
3158 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
3159 /* BTVGA2VRE 0x11 */
3160 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003161
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303162 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003163 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
3164 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003165
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303166 if (temp & 0x04)
3167 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003168
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303169 if (temp & 0x080)
3170 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003171
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003172 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003173
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303174 if (temp & 0x08)
3175 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003176
Aaro Koskinen7853bce2012-11-04 21:14:54 +02003177 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303178 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
3179 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003180
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303181 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003182 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303183 temp = ((tempbx & 0xFF00) >> 8) << 4;
3184 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02003185 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303186 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003187
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303188 if (modeflag & DoubleScanMode)
3189 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003190
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303191 if (modeflag & HalfDCLK)
3192 tempax |= 0x40;
3193
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003194 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003195}
3196
Aaro Koskinencc1e2392011-03-13 12:26:07 +02003197static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
3198{
3199 unsigned long tempax, tempbx;
3200
3201 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
3202 & 0xFFFF;
3203 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
3204 tempax = (tempax * pVBInfo->HT) / tempbx;
3205
3206 return (unsigned short) tempax;
3207}
3208
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003209static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303210 struct xgi_hw_device_info *HwDeviceExtension,
3211 unsigned short RefreshRateTableIndex,
3212 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003213{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303214 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
3215 modeflag, CRT1Index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003216
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003217 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003218 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3219 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +02003220 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003221 CRT1Index &= IndexMask;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003222
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303223 if (!(pVBInfo->VBInfo & SetInSlaveMode))
3224 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003225
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303226 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003227 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303228 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003229
Peter Huewe6896b942012-02-09 21:11:46 +01003230 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303231 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003232
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303233 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003234
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303235 if (modeflag & HalfDCLK)
3236 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003237
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303238 tempax = (tempax / tempcx) - 1;
3239 tempbx |= ((tempax & 0x00FF) << 8);
3240 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003241 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003242
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303243 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003244
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303245 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01003246 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3247 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303248 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003249
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03003250 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
3251 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303252 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303253 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003254
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003255 /* 0x05 Horizontal Display Start */
3256 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3257 /* 0x06 Horizontal Blank end */
3258 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003259
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303260 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3261 if (pVBInfo->VBInfo & SetCRT2ToTV)
3262 tempax = pVBInfo->VGAHT;
3263 else
3264 tempax = XGI_GetVGAHT2(pVBInfo);
3265 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003266
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303267 if (tempax >= pVBInfo->VGAHT)
3268 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003269
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303270 if (modeflag & HalfDCLK)
3271 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003272
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303273 tempax = (tempax / tempcx) - 5;
3274 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003275 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303276 temp = (tempbx & 0x00FF) - 1;
3277 if (!(modeflag & HalfDCLK)) {
3278 temp -= 6;
3279 if (pVBInfo->TVInfo & TVSimuMode) {
3280 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003281 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303282 }
3283 }
3284 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303285 tempbx = (tempbx & 0xFF00) >> 8;
3286 tempcx = (tempcx + tempbx) >> 1;
3287 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003288
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303289 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3290 temp -= 1;
3291 if (!(modeflag & HalfDCLK)) {
3292 if ((modeflag & Charx8Dot)) {
3293 temp += 4;
3294 if (pVBInfo->VGAHDE >= 800)
3295 temp -= 6;
3296 }
3297 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003298 } else if (!(modeflag & HalfDCLK)) {
3299 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003300 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003301 pVBInfo->VGAHDE >= 800) {
3302 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003303 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003304 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003305 (pVBInfo->LCDInfo & LCDNonExpanding))
3306 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303307 }
3308 }
3309 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003310
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003311 /* 0x07 Horizontal Retrace Start */
3312 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3313 /* 0x08 Horizontal Retrace End */
3314 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003315
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303316 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3317 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003318 if (ModeNo == 0x50) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303319 if (pVBInfo->TVInfo & SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003320 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303321 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003322 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303323 0x08, 0x03);
3324 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003325 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303326 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003327 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303328 0x08, 0x02);
3329 }
3330 }
3331 }
3332 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003333
Aaro Koskinen8104e322011-03-13 12:26:22 +02003334 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003335 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003336 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003337
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303338 tempbx = pVBInfo->VGAVT;
3339 push1 = tempbx;
3340 tempcx = 0x121;
3341 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003342
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303343 if (tempbx == 357)
3344 tempbx = 350;
3345 if (tempbx == 360)
3346 tempbx = 350;
3347 if (tempbx == 375)
3348 tempbx = 350;
3349 if (tempbx == 405)
3350 tempbx = 400;
3351 if (tempbx == 525)
3352 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003353
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303354 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003355
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303356 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003357 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003358 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303359 if (tempbx == 350)
3360 tempbx += 5;
3361 if (tempbx == 480)
3362 tempbx += 5;
3363 }
3364 }
3365 }
3366 tempbx--;
3367 temp = tempbx & 0x00FF;
3368 tempbx--;
3369 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003370 /* 0x10 vertical Blank Start */
3371 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303372 tempbx = push2;
3373 tempbx--;
3374 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003375 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003376
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303377 if (tempbx & 0x0100)
3378 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003379
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303380 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003381
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303382 if (modeflag & DoubleScanMode)
3383 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003384
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303385 if (tempbx & 0x0200)
3386 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003387
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303388 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003389 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003390
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303391 if (tempbx & 0x0400)
3392 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003393
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003394 /* 0x11 Vertival Blank End */
3395 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303396
3397 tempax = push1;
3398 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3399 tempax = tempax >> 2;
3400 push1 = tempax; /* push ax */
3401
3402 if (resinfo != 0x09) {
3403 tempax = tempax << 1;
3404 tempbx += tempax;
3405 }
3406
Peter Huewe599801f2012-02-09 21:11:45 +01003407 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003408 if ((pVBInfo->VBType & VB_SIS301LV) &&
3409 !(pVBInfo->TVInfo & TVSetHiVision)) {
3410 if ((pVBInfo->TVInfo & TVSimuMode) &&
3411 (pVBInfo->TVInfo & TVSetPAL)) {
3412 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3413 !(pVBInfo->TVInfo &
3414 (TVSetYPbPr525p |
3415 TVSetYPbPr750p |
3416 TVSetHiVision)))
3417 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303418 }
3419 } else {
3420 tempbx -= 10;
3421 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003422 } else if (pVBInfo->TVInfo & TVSimuMode) {
3423 if (pVBInfo->TVInfo & TVSetPAL) {
3424 if (pVBInfo->VBType & VB_SIS301LV) {
3425 if (!(pVBInfo->TVInfo &
3426 (TVSetYPbPr525p |
3427 TVSetYPbPr750p |
3428 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303429 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003430 } else {
3431 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303432 }
3433 }
3434 }
3435 tempax = push1;
3436 tempax = tempax >> 2;
3437 tempax++;
3438 tempax += tempbx;
3439 push1 = tempax; /* push ax */
3440
Peter Huewe599801f2012-02-09 21:11:45 +01003441 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303442 if (tempbx <= 513) {
3443 if (tempax >= 513)
3444 tempbx = 513;
3445 }
3446 }
3447
3448 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003449 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303450 tempbx--;
3451 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003452 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303453
3454 if (tempbx & 0x0100)
3455 tempcx |= 0x0008;
3456
3457 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003458 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303459
3460 tempbx++;
3461
3462 if (tempbx & 0x0100)
3463 tempcx |= 0x0004;
3464
3465 if (tempbx & 0x0200)
3466 tempcx |= 0x0080;
3467
3468 if (tempbx & 0x0400)
3469 tempcx |= 0x0C00;
3470
3471 tempbx = push1; /* pop ax */
3472 temp = tempbx & 0x00FF;
3473 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003474 /* 0x0D vertical Retrace End */
3475 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303476
3477 if (tempbx & 0x0010)
3478 tempcx |= 0x2000;
3479
3480 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003481 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303482 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003483 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303484 tempax = modeflag;
3485 temp = (tempax & 0xFF00) >> 8;
3486
3487 temp = (temp >> 1) & 0x09;
3488
Peter Huewe6896b942012-02-09 21:11:46 +01003489 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303490 temp |= 0x01;
3491
Aaro Koskinen8104e322011-03-13 12:26:22 +02003492 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3493 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3494 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303495
3496 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3497 temp = 0x80;
3498 else
3499 temp = 0x00;
3500
Aaro Koskinen8104e322011-03-13 12:26:22 +02003501 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303502
3503 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003504}
3505
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003506static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303507 unsigned short RefreshRateTableIndex,
3508 struct xgi_hw_device_info *HwDeviceExtension,
3509 struct vb_device_info *pVBInfo)
3510{
3511 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
3512 modeflag, resinfo, crt2crtc;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003513 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303514
3515 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3516
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003517 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003518 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3519 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +02003520 crt2crtc = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303521
3522 tempax = 0;
3523
3524 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3525 tempax |= 0x0800;
3526
3527 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3528 tempax |= 0x0400;
3529
3530 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3531 tempax |= 0x0200;
3532
Peter Huewe599801f2012-02-09 21:11:45 +01003533 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303534 tempax |= 0x1000;
3535
Peter Huewe599801f2012-02-09 21:11:45 +01003536 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303537 tempax |= 0x0100;
3538
Peter Huewe599801f2012-02-09 21:11:45 +01003539 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303540 tempax &= 0xfe00;
3541
3542 tempax = (tempax & 0xff00) >> 8;
3543
Aaro Koskinen8104e322011-03-13 12:26:22 +02003544 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003545 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303546
Peter Huewe599801f2012-02-09 21:11:45 +01003547 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003548 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303549
Peter Huewe599801f2012-02-09 21:11:45 +01003550 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003551 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303552
3553 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003554 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303555
3556 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003557 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303558
3559 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003560 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303561 }
3562
Peter Huewe599801f2012-02-09 21:11:45 +01003563 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3564 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003565 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303566
Peter Huewe599801f2012-02-09 21:11:45 +01003567 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003568 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303569
Peter Huewe599801f2012-02-09 21:11:45 +01003570 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003571 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303572 }
3573
3574 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003575 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303576
3577 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003578 /* di->temp2[j] */
3579 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303580
3581 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003582 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303583
3584 temp = pVBInfo->NewFlickerMode;
3585 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003586 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303587
Peter Huewe599801f2012-02-09 21:11:45 +01003588 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303589 tempax = 950;
3590
Peter Huewe599801f2012-02-09 21:11:45 +01003591 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303592 tempax = 520;
3593 else
3594 tempax = 440;
3595
3596 if (pVBInfo->VDE <= tempax) {
3597 tempax -= pVBInfo->VDE;
3598 tempax = tempax >> 2;
3599 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3600 push1 = tempax;
3601 temp = (tempax & 0xFF00) >> 8;
3602 temp += (unsigned short) TimingPoint[0];
3603
Peter Huewe6896b942012-02-09 21:11:46 +01003604 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3605 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303606 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3607 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003608 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303609 tempcx = pVBInfo->VGAHDE;
3610 if (tempcx >= 1024) {
3611 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003612 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303613 temp = 0x19; /* PAL */
3614 }
3615 }
3616 }
3617
Aaro Koskinen8104e322011-03-13 12:26:22 +02003618 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303619 tempax = push1;
3620 temp = (tempax & 0xFF00) >> 8;
3621 temp += TimingPoint[1];
3622
Peter Huewe6896b942012-02-09 21:11:46 +01003623 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3624 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303625 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3626 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003627 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303628 tempcx = pVBInfo->VGAHDE;
3629 if (tempcx >= 1024) {
3630 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003631 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303632 temp = 0x52; /* PAL */
3633 }
3634 }
3635 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003636 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303637 }
3638
3639 /* 301b */
3640 tempcx = pVBInfo->HT;
3641
3642 if (XGI_IsLCDDualLink(pVBInfo))
3643 tempcx = tempcx >> 1;
3644
3645 tempcx -= 2;
3646 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003647 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303648
3649 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003650 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303651
3652 tempcx = pVBInfo->HT >> 1;
3653 push1 = tempcx; /* push cx */
3654 tempcx += 7;
3655
Peter Huewe599801f2012-02-09 21:11:45 +01003656 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303657 tempcx -= 4;
3658
3659 temp = tempcx & 0x00FF;
3660 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003661 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303662
3663 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3664 tempbx += tempcx;
3665 push2 = tempbx;
3666 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003667 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303668 temp = (tempbx & 0xFF00) >> 8;
3669 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003670 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303671
3672 tempbx = push2;
3673 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003674 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303675 tempbx = tempbx - 4;
3676 tempcx = tempbx;
3677 }
3678
3679 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003680 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303681
3682 j += 2;
3683 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3684 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003685 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303686 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003687 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303688
3689 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003690 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303691 tempcx -= 4;
3692
3693 temp = tempcx & 0xFF;
3694 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003695 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303696
3697 tempcx = push1; /* pop cx */
3698 j += 2;
3699 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3700 tempcx -= temp;
3701 temp = tempcx & 0x00FF;
3702 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003703 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303704
3705 tempcx -= 11;
3706
3707 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3708 tempax = XGI_GetVGAHT2(pVBInfo);
3709 tempcx = tempax - 1;
3710 }
3711 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003712 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303713
3714 tempbx = pVBInfo->VDE;
3715
3716 if (pVBInfo->VGAVDE == 360)
3717 tempbx = 746;
3718 if (pVBInfo->VGAVDE == 375)
3719 tempbx = 746;
3720 if (pVBInfo->VGAVDE == 405)
3721 tempbx = 853;
3722
3723 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003724 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003725 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003726 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003727 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303728 tempbx = tempbx >> 1;
3729 } else
3730 tempbx = tempbx >> 1;
3731 }
3732
3733 tempbx -= 2;
3734 temp = tempbx & 0x00FF;
3735
Peter Huewe599801f2012-02-09 21:11:45 +01003736 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003737 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003738 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303739 if (pVBInfo->VBInfo & SetInSlaveMode) {
3740 if (ModeNo == 0x2f)
3741 temp += 1;
3742 }
3743 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003744 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3745 if (ModeNo == 0x2f)
3746 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303747 }
3748 }
3749
Aaro Koskinen8104e322011-03-13 12:26:22 +02003750 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303751
3752 temp = (tempcx & 0xFF00) >> 8;
3753 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3754
Peter Huewe599801f2012-02-09 21:11:45 +01003755 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003756 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003757 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303758 temp |= 0x10;
3759
3760 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3761 temp |= 0x20;
3762 }
3763 } else {
3764 temp |= 0x10;
3765 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3766 temp |= 0x20;
3767 }
3768 }
3769
Aaro Koskinen8104e322011-03-13 12:26:22 +02003770 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303771
Peter Huewe6896b942012-02-09 21:11:46 +01003772 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3773 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303774 tempbx = pVBInfo->VDE;
3775 tempcx = tempbx - 2;
3776
3777 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003778 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3779 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303780 tempbx = tempbx >> 1;
3781 }
3782
Peter Huewe6896b942012-02-09 21:11:46 +01003783 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303784 temp = 0;
3785 if (tempcx & 0x0400)
3786 temp |= 0x20;
3787
3788 if (tempbx & 0x0400)
3789 temp |= 0x40;
3790
Aaro Koskinen8104e322011-03-13 12:26:22 +02003791 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303792 }
3793
3794 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003795 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303796 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003797 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303798 }
3799
3800 tempbx = tempbx & 0x00FF;
3801
3802 if (!(modeflag & HalfDCLK)) {
3803 tempcx = pVBInfo->VGAHDE;
3804 if (tempcx >= pVBInfo->HDE) {
3805 tempbx |= 0x2000;
3806 tempax &= 0x00FF;
3807 }
3808 }
3809
3810 tempcx = 0x0101;
3811
3812 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3813 if (pVBInfo->VGAHDE >= 1024) {
3814 tempcx = 0x1920;
3815 if (pVBInfo->VGAHDE >= 1280) {
3816 tempcx = 0x1420;
3817 tempbx = tempbx & 0xDFFF;
3818 }
3819 }
3820 }
3821
3822 if (!(tempbx & 0x2000)) {
3823 if (modeflag & HalfDCLK)
3824 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3825
3826 push1 = tempbx;
3827 tempeax = pVBInfo->VGAHDE;
3828 tempebx = (tempcx & 0xFF00) >> 8;
3829 longtemp = tempeax * tempebx;
3830 tempecx = tempcx & 0x00FF;
3831 longtemp = longtemp / tempecx;
3832
3833 /* 301b */
3834 tempecx = 8 * 1024;
3835
Peter Huewe6896b942012-02-09 21:11:46 +01003836 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3837 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303838 tempecx = tempecx * 8;
3839 }
3840
3841 longtemp = longtemp * tempecx;
3842 tempecx = pVBInfo->HDE;
3843 temp2 = longtemp % tempecx;
3844 tempeax = longtemp / tempecx;
3845 if (temp2 != 0)
3846 tempeax += 1;
3847
3848 tempax = (unsigned short) tempeax;
3849
3850 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003851 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3852 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303853 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3854 }
3855 /* end 301b */
3856
3857 tempbx = push1;
3858 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3859 | (tempbx & 0x00FF));
3860 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3861 | (tempax & 0x00FF));
3862 temp = (tempax & 0xFF00) >> 8;
3863 } else {
3864 temp = (tempax & 0x00FF) >> 8;
3865 }
3866
Aaro Koskinen8104e322011-03-13 12:26:22 +02003867 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303868 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003869 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303870 temp = tempcx & 0x00FF;
3871
3872 if (tempbx & 0x2000)
3873 temp = 0;
3874
3875 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3876 temp |= 0x18;
3877
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003878 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003879 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303880 tempbx = 0x0382;
3881 tempcx = 0x007e;
3882 } else {
3883 tempbx = 0x0369;
3884 tempcx = 0x0061;
3885 }
3886
3887 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003888 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303889 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003890 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303891
3892 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3893 temp = temp << 2;
3894 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3895
Peter Huewe599801f2012-02-09 21:11:45 +01003896 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303897 temp |= 0x10;
3898
Peter Huewe599801f2012-02-09 21:11:45 +01003899 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303900 temp |= 0x20;
3901
Peter Huewe599801f2012-02-09 21:11:45 +01003902 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303903 temp |= 0x60;
3904 }
3905
Aaro Koskinen8104e322011-03-13 12:26:22 +02003906 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003907 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003908 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303909
Peter Huewe599801f2012-02-09 21:11:45 +01003910 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303911 if (pVBInfo->TVInfo & NTSC1024x768) {
3912 TimingPoint = XGI_NTSC1024AdjTime;
3913 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003914 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303915 TimingPoint[j]);
3916 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003917 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303918 }
3919 }
3920
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003921 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303922 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003923 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003924 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303925 0x08); /* PALM Mode */
3926 }
3927
Peter Huewe599801f2012-02-09 21:11:45 +01003928 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02003929 tempax = (unsigned char) xgifb_reg_get(pVBInfo->Part2Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303930 0x01);
3931 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003932 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303933
Aaro Koskinendc505562011-03-13 12:26:26 +02003934 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303935 }
3936
Peter Huewe599801f2012-02-09 21:11:45 +01003937 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303938 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003939 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303940 }
3941
3942 if (pVBInfo->VBInfo & SetCRT2ToTV)
3943 return;
3944}
3945
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003946static void XGI_SetLCDRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303947 struct xgi_hw_device_info *HwDeviceExtension,
3948 unsigned short RefreshRateTableIndex,
3949 struct vb_device_info *pVBInfo)
3950{
3951 unsigned short push1, push2, pushbx, tempax, tempbx, tempcx, temp,
3952 tempah, tempbh, tempch, resinfo, modeflag, CRT1Index;
3953
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003954 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303955
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003956 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003957 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
3958 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +02003959 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003960 CRT1Index &= IndexMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303961
3962 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3963 return;
3964
3965 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3966
3967 if (XGI_IsLCDDualLink(pVBInfo))
3968 tempbx = tempbx >> 1;
3969
3970 tempbx -= 1;
3971 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003972 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303973 temp = (tempbx & 0xFF00) >> 8;
3974 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003975 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303976 temp = 0x01;
3977
Aaro Koskinen8104e322011-03-13 12:26:22 +02003978 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303979 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
3980 push1 = tempbx;
3981 tempbx--;
3982 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003983 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303984 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003985 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303986
3987 tempcx = pVBInfo->VT - 1;
3988 push2 = tempcx + 1;
3989 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003990 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303991 temp = (tempcx & 0xFF00) >> 8;
3992 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003993 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003994 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3995 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3996 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3997 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303998
Justin P. Mattock558f7582012-10-02 21:17:11 -07003999 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02004000 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
4001 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeNo, ModeIdIndex,
4002 RefreshRateTableIndex, pVBInfo);
4003 else
4004 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeNo,
4005 ModeIdIndex, RefreshRateTableIndex,
4006 pVBInfo);
4007
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304008 tempah = pVBInfo->LCDResInfo;
4009 tempah &= PanelResInfo;
4010
Peter Huewe255aabd2012-02-09 21:11:44 +01004011 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304012 tempbx = 1024;
4013 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01004014 } else if ((tempah == Panel_1280x1024) ||
4015 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304016 tempbx = 1280;
4017 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01004018 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304019 tempbx = 1400;
4020 tempcx = 1050;
4021 } else {
4022 tempbx = 1600;
4023 tempcx = 1200;
4024 }
4025
4026 if (pVBInfo->LCDInfo & EnableScalingLCD) {
4027 tempbx = pVBInfo->HDE;
4028 tempcx = pVBInfo->VDE;
4029 }
4030
4031 pushbx = tempbx;
4032 tempax = pVBInfo->VT;
4033 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
4034 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
4035 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
4036 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
4037 tempbx = pVBInfo->LCDVDES;
4038 tempcx += tempbx;
4039
4040 if (tempcx >= tempax)
4041 tempcx -= tempax; /* lcdvdes */
4042
4043 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004044 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304045 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004046 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304047 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
4048 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
4049 tempah = tempch;
4050 tempah = tempah << 3;
4051 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004052 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304053
4054 /* getlcdsync() */
4055 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4056 tempcx = tempbx;
4057 tempax = pVBInfo->VT;
4058 tempbx = pVBInfo->LCDVRS;
4059
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304060 tempcx += tempbx;
4061 if (tempcx >= tempax)
4062 tempcx -= tempax;
4063
4064 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004065 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304066 temp = (tempbx & 0xFF00) >> 8;
4067 temp = temp << 4;
4068 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004069 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304070 tempcx = pushbx;
4071 tempax = pVBInfo->HT;
4072 tempbx = pVBInfo->LCDHDES;
4073 tempbx &= 0x0FFF;
4074
4075 if (XGI_IsLCDDualLink(pVBInfo)) {
4076 tempax = tempax >> 1;
4077 tempbx = tempbx >> 1;
4078 tempcx = tempcx >> 1;
4079 }
4080
Peter Huewe6896b942012-02-09 21:11:46 +01004081 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304082 tempbx += 1;
4083
4084 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
4085 tempbx += 1;
4086
4087 tempcx += tempbx;
4088
4089 if (tempcx >= tempax)
4090 tempcx -= tempax;
4091
4092 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004093 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304094 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004095 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304096 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004097 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304098 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004099 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304100
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304101 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
4102 tempcx = tempax;
4103 tempax = pVBInfo->HT;
4104 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304105 if (XGI_IsLCDDualLink(pVBInfo)) {
4106 tempax = tempax >> 1;
4107 tempbx = tempbx >> 1;
4108 tempcx = tempcx >> 1;
4109 }
4110
Peter Huewe6896b942012-02-09 21:11:46 +01004111 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304112 tempbx += 1;
4113
4114 tempcx += tempbx;
4115
4116 if (tempcx >= tempax)
4117 tempcx -= tempax;
4118
4119 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004120 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304121
4122 temp = (tempbx & 0xFF00) >> 8;
4123 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004124 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304125 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004126 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304127
Peter Huewea3d675c2012-02-09 21:11:47 +01004128 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304129 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01004130 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4131 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304132 | VB_XGI301C)) {
4133 temp = 0xC6;
4134 } else
4135 temp = 0xC4;
4136
Aaro Koskinen8104e322011-03-13 12:26:22 +02004137 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
4138 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304139 }
4140
4141 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01004142 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
4143 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304144 | VB_XGI301C)) {
4145 temp = 0x4F;
4146 } else
4147 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004148 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304149 }
4150 }
4151}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004152
4153/* --------------------------------------------------------------------- */
4154/* Function : XGI_GetTap4Ptr */
4155/* Input : */
4156/* Output : di -> Tap4 Reg. Setting Pointer */
4157/* Description : */
4158/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004159static struct XGI301C_Tap4TimingStruct *XGI_GetTap4Ptr(unsigned short tempcx,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304160 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004161{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304162 unsigned short tempax, tempbx, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004163
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304164 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004165
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304166 if (tempcx == 0) {
4167 tempax = pVBInfo->VGAHDE;
4168 tempbx = pVBInfo->HDE;
4169 } else {
4170 tempax = pVBInfo->VGAVDE;
4171 tempbx = pVBInfo->VDE;
4172 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004173
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004174 if (tempax <= tempbx)
4175 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304176 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004177 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004178
Peter Huewe599801f2012-02-09 21:11:45 +01004179 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304180 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004181
Peter Huewe599801f2012-02-09 21:11:45 +01004182 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
4183 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
4184 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004185 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01004186 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304187 Tap4TimingPtr = YPbPr750pTap4Timing;
4188 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004189
Peter Huewe599801f2012-02-09 21:11:45 +01004190 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03004191 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004192
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304193 i = 0;
4194 while (Tap4TimingPtr[i].DE != 0xFFFF) {
4195 if (Tap4TimingPtr[i].DE == tempax)
4196 break;
4197 i++;
4198 }
4199 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004200}
4201
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004202static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004203{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304204 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004205
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304206 struct XGI301C_Tap4TimingStruct *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004207
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304208 if (!(pVBInfo->VBType & VB_XGI301C))
4209 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004210
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304211 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
4212 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004213 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004214
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004215 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004216 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004217 /* Set Vertical Scaling */
4218 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304219 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004220 xgifb_reg_set(pVBInfo->Part2Port,
4221 i,
4222 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304223 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004224
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004225 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01004226 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004227 /* Enable V.Scaling */
4228 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304229 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004230 /* Enable H.Scaling */
4231 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004232}
4233
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004234static void XGI_SetGroup3(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304235 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004236{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304237 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03004238 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304239 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004240
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004241 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004242 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004243
Aaro Koskinen8104e322011-03-13 12:26:22 +02004244 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01004245 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004246 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4247 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304248 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004249 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
4250 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304251 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004252
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304253 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4254 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004255
Peter Huewe599801f2012-02-09 21:11:45 +01004256 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004257 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
4258 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
4259 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304260 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004261
Peter Huewe599801f2012-02-09 21:11:45 +01004262 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
4263 & SetCRT2ToYPbPr525750)) {
4264 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304265 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004266
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004267 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304268 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004269 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304270 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004271 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304272 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004273
Peter Huewe599801f2012-02-09 21:11:45 +01004274 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004275 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004276
Peter Huewe599801f2012-02-09 21:11:45 +01004277 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004278 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004279
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304280 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004281 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004282
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304283 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004284 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004285 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304286 }
4287 }
4288 return;
4289} /* {end of XGI_SetGroup3} */
4290
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004291static void XGI_SetGroup4(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304292 unsigned short RefreshRateTableIndex,
4293 struct xgi_hw_device_info *HwDeviceExtension,
4294 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004295{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304296 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004297
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304298 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004299
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004300 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004301 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304302 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004303 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004304
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304305 tempbx = pVBInfo->RVBHCMAX;
4306 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004307 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304308 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4309 tempcx = pVBInfo->VGAHT - 1;
4310 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004311 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004312
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304313 temp = ((tempcx & 0xFF00) >> 8) << 3;
4314 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004315
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304316 tempcx = pVBInfo->VGAVT - 1;
4317 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4318 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004319
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304320 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004321 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304322 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004323 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004324 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304325 tempcx = pVBInfo->VBInfo;
4326 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004327
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304328 if (modeflag & HalfDCLK)
4329 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004330
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304331 if (XGI_IsLCDDualLink(pVBInfo))
4332 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004333
Peter Huewe599801f2012-02-09 21:11:45 +01004334 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304335 temp = 0;
4336 if (tempbx <= 1024)
4337 temp = 0xA0;
4338 if (tempbx == 1280)
4339 temp = 0xC0;
4340 } else if (tempcx & SetCRT2ToTV) {
4341 temp = 0xA0;
4342 if (tempbx <= 800)
4343 temp = 0x80;
4344 } else {
4345 temp = 0x80;
4346 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4347 temp = 0;
4348 if (tempbx > 800)
4349 temp = 0x60;
4350 }
4351 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004352
Peter Huewe599801f2012-02-09 21:11:45 +01004353 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304354 temp = 0x00;
4355 if (pVBInfo->VGAHDE == 1280)
4356 temp = 0x40;
4357 if (pVBInfo->VGAHDE == 1024)
4358 temp = 0x20;
4359 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004360 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004361
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304362 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004363
Peter Huewe599801f2012-02-09 21:11:45 +01004364 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304365 if (!(temp & 0xE000))
4366 tempbx = tempbx >> 1;
4367 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004368
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304369 tempcx = pVBInfo->RVBHRS;
4370 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004371 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004372
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304373 tempeax = pVBInfo->VGAVDE;
4374 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004375
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304376 if (tempeax <= tempebx) {
4377 tempcx = (tempcx & (~0x4000));
4378 tempeax = pVBInfo->VGAVDE;
4379 } else {
4380 tempeax -= tempebx;
4381 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004382
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304383 templong = (tempeax * 256 * 1024) % tempebx;
4384 tempeax = (tempeax * 256 * 1024) / tempebx;
4385 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004386
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304387 if (templong != 0)
4388 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004389
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304390 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004391 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004392
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304393 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004394 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304395 tempbx = (unsigned short) (tempebx >> 16);
4396 temp = tempbx & 0x00FF;
4397 temp = temp << 4;
4398 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004399 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004400
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304401 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004402 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4403 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304404 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004405 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304406 tempax = pVBInfo->VGAHDE;
4407 if (modeflag & HalfDCLK)
4408 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004409
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304410 if (XGI_IsLCDDualLink(pVBInfo))
4411 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004412
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304413 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4414 if (tempax > 800)
4415 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004416 } else if (pVBInfo->VGAHDE > 800) {
4417 if (pVBInfo->VGAHDE == 1024)
4418 tempax = (tempax * 25 / 32) - 1;
4419 else
4420 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304421 }
4422 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004423
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304424 temp = (tempax & 0xFF00) >> 8;
4425 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004426 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304427 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004428 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004429
Peter Huewe599801f2012-02-09 21:11:45 +01004430 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304431 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004432 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004433
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304434 }
4435 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004436
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304437 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4438 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004439 | TVSetYPbPr525p | TVSetYPbPr750p
4440 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304441 temp |= 0x0001;
4442 if ((pVBInfo->VBInfo & SetInSlaveMode)
4443 && (!(pVBInfo->TVInfo
4444 & TVSimuMode)))
4445 temp &= (~0x0001);
4446 }
4447 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004448
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004449 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304450 tempbx = pVBInfo->HT;
4451 if (XGI_IsLCDDualLink(pVBInfo))
4452 tempbx = tempbx >> 1;
4453 tempbx = (tempbx >> 1) - 2;
4454 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004455 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304456 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004457 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304458 }
4459 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004460
Aaro Koskinen8951dad2012-09-11 00:15:30 +03004461 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004462}
4463
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004464static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4465{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004466 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004467}
4468
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004469static void XGI_SetGroup5(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304470 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004471{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304472 unsigned short Pindex, Pdata;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004473
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304474 Pindex = pVBInfo->Part5Port;
4475 Pdata = pVBInfo->Part5Port + 1;
4476 if (pVBInfo->ModeType == ModeVGA) {
4477 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004478 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304479 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304480 }
4481 }
4482 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004483}
4484
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004485static void XGI_EnableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304486 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004487{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004488 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004489}
4490
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004491static void XGI_DisableGatingCRT(struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304492 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004493{
4494
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004495 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004496}
4497
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004498static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4499 unsigned short ModeNo, unsigned short ModeIdIndex,
4500 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004501{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004502 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004503
Aaro Koskinenb3979922012-11-04 21:14:52 +02004504 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004505 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
4506 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
4507 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004508 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004509
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304510 if (!(modeflag & Charx8Dot)) {
4511 xres /= 9;
4512 xres *= 8;
4513 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004514
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004515 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4516 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004517
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004518 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4519 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004520
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004521 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304522 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004523
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004524 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304525 return 0;
4526
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004527 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4528 yres != xgifb_info->lvds_data.LVDSVDE) {
4529 colordepth = XGI_GetColorDepth(ModeNo, ModeIdIndex, pVBInfo);
4530 if (colordepth > 2)
4531 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304532 }
4533 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004534}
4535
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004536static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4537 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004538 unsigned short ModeNo,
4539 unsigned short ModeIdIndex,
4540 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004541{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304542 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004543 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304544 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4545 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4546 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004547
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004548 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004549 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304550 temp &= LCDPolarity;
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004551 Miscdata = (unsigned char) inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004552
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004553 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004554
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004555 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004556 /* SR35[7] FP VSync polarity */
4557 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4558 /* SR30[5] FP HSync polarity */
4559 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004560
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004561 if (chip_id == XG27)
4562 XGI_SetXG27FPBits(pVBInfo);
4563 else
4564 XGI_SetXG21FPBits(pVBInfo);
4565
Aaro Koskinenb3979922012-11-04 21:14:52 +02004566 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004567 xres = pVBInfo->ModeResInfo[resindex].HTotal; /* xres->ax */
4568 yres = pVBInfo->ModeResInfo[resindex].VTotal; /* yres->bx */
4569 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004570 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004571
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304572 if (!(modeflag & Charx8Dot))
4573 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004574
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004575 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004576
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004577 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004578
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304579 if (LVDSHBS > LVDSHT)
4580 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004581
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004582 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304583 if (LVDSHRS > LVDSHT)
4584 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004585
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004586 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304587 if (LVDSHRE > LVDSHT)
4588 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004589
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004590 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004591
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004592 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004593
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004594 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004595 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304596 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004597
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304598 if (LVDSVBS > LVDSVT)
4599 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004600
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004601 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304602 if (LVDSVRS > LVDSVT)
4603 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004604
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004605 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304606 if (LVDSVRE > LVDSVT)
4607 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004608
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004609 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004610
Aaro Koskinen58839b02011-03-13 12:26:23 +02004611 temp = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004612 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004613
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304614 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004615 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004616
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304617 /* HT SR0B[1:0] CR00 */
4618 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004619 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004620 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004621
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304622 /* HBS SR0B[5:4] CR02 */
4623 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004624 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004625 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004626
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304627 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4628 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004629 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4630 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4631 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004632
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304633 /* HRS SR0B[7:6] CR04 */
4634 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004635 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004636 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004637
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304638 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4639 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004640 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004641 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004642
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304643 /* HRE SR0C[2] CR05[4:0] */
4644 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004645 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4646 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004647
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304648 /* Panel HRE SR2F[7:2] */
4649 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004650 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004651
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304652 /* VT SR0A[0] CR07[5][0] CR06 */
4653 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004654 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4655 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4656 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004657 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004658
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304659 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4660 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004661 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4662 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4663 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004664 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004665
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304666 /* VBE SR0A[4] CR16 */
4667 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004668 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004669 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004670
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304671 /* VRS SR0A[3] CR7[7][2] CR10 */
4672 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004673 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4674 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4675 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004676 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004677
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004678 if (chip_id == XG27) {
4679 /* Panel VRS SR35[2:0] SR34[7:0] */
4680 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4681 (value & 0x700) >> 8);
4682 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4683 } else {
4684 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4685 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4686 (value & 0x600) >> 9);
4687 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4688 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4689 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004690
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304691 /* VRE SR0A[5] CR11[3:0] */
4692 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004693 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4694 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004695
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304696 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004697 if (chip_id == XG27)
4698 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4699 (value << 2) & 0xFC);
4700 else
4701 /* SR3F[7] has to be 0, h/w bug */
4702 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4703 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004704
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304705 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004706
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004707 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004708 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004709 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004710 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004711 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304712 value += 0x10;
4713 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004714
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304715 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004716 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004717 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004718 /* set data, panning = 0, shift left 1 dot*/
4719 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004720
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004721 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004722 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304723
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004724 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304725 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004726
4727}
4728
4729/* --------------------------------------------------------------------- */
4730/* Function : XGI_IsLCDON */
4731/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004732/* Output : 0 : Skip PSC Control */
4733/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004734/* Description : */
4735/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004736static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004737{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304738 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004739
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304740 tempax = pVBInfo->VBInfo;
4741 if (tempax & SetCRT2ToDualEdge)
4742 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004743 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304744 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004745
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304746 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004747}
4748
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004749/* --------------------------------------------------------------------- */
4750/* Function : XGI_DisableChISLCD */
4751/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004752/* Output : 0 -> Not LCD Mode */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004753/* Description : */
4754/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004755static unsigned char XGI_DisableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004756{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304757 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004758
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304759 tempbx = pVBInfo->SetFlag & (DisableChA | DisableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02004760 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004761
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304762 if (tempbx & (EnableChA | DisableChA)) {
4763 if (!(tempah & 0x08)) /* Chk LCDA Mode */
4764 return 0;
4765 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004766
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304767 if (!(tempbx & (EnableChB | DisableChB)))
4768 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004769
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304770 if (tempah & 0x01) /* Chk LCDB Mode */
4771 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004772
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304773 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004774}
4775
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004776/* --------------------------------------------------------------------- */
4777/* Function : XGI_EnableChISLCD */
4778/* Input : */
4779/* Output : 0 -> Not LCD mode */
4780/* Description : */
4781/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004782static unsigned char XGI_EnableChISLCD(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004783{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304784 unsigned short tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004785
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304786 tempbx = pVBInfo->SetFlag & (EnableChA | EnableChB);
Aaro Koskinen58839b02011-03-13 12:26:23 +02004787 tempah = ~((unsigned short) xgifb_reg_get(pVBInfo->Part1Port, 0x2E));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004788
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304789 if (tempbx & (EnableChA | DisableChA)) {
4790 if (!(tempah & 0x08)) /* Chk LCDA Mode */
4791 return 0;
4792 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004793
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304794 if (!(tempbx & (EnableChB | DisableChB)))
Bill Pembertondda08c52010-06-17 13:10:42 -04004795 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004796
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304797 if (tempah & 0x01) /* Chk LCDB Mode */
4798 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004799
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304800 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004801}
4802
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004803static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4804 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304805 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004806{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004807 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004808
Peter Huewe6896b942012-02-09 21:11:46 +01004809 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4810 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304811 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004812 if (!(pVBInfo->VBInfo &
4813 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004814 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304815 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
4816 tempah = 0x7F; /* Disable Channel A */
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004817 if (!(pVBInfo->VBInfo &
4818 XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004819 /* Disable Channel B */
4820 tempah = 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004821
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304822 if (pVBInfo->SetFlag & DisableChB)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004823 /* force to disable Cahnnel */
4824 tempah &= 0xBF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004825
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304826 if (pVBInfo->SetFlag & DisableChA)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004827 /* Force to disable Channel B */
4828 tempah &= 0x7F;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304829 }
4830 }
4831 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004832
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004833 /* disable part4_1f */
4834 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004835
Peter Huewe6896b942012-02-09 21:11:46 +01004836 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004837 if (((pVBInfo->VBInfo &
4838 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
4839 || (XGI_DisableChISLCD(pVBInfo))
4840 || (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004841 /* LVDS Driver power down */
4842 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304843 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004844
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304845 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004846 & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304847 | SetSimuScanMode))) {
4848 if (pVBInfo->SetFlag & GatingCRT)
4849 XGI_EnableGatingCRT(HwDeviceExtension, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004850 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304851 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004852
Peter Huewea3d675c2012-02-09 21:11:47 +01004853 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304854 if ((pVBInfo->SetFlag & DisableChA) || (pVBInfo->VBInfo
Peter Huewea3d675c2012-02-09 21:11:47 +01004855 & XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004856 /* Power down */
4857 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304858 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004859
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004860 /* disable TV as primary VGA swap */
4861 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004862
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304863 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004864 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004865
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004866 if ((pVBInfo->SetFlag & DisableChB) ||
4867 (pVBInfo->VBInfo &
4868 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004869 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004870 (pVBInfo->VBInfo &
4871 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004872 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004873
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004874 if ((pVBInfo->SetFlag & DisableChB) ||
4875 (pVBInfo->VBInfo &
4876 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004877 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004878 (pVBInfo->VBInfo &
4879 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4880 /* save Part1 index 0 */
4881 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4882 /* BTDAC = 1, avoid VB reset */
4883 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4884 /* disable CRT2 */
4885 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4886 /* restore Part1 index 0 */
4887 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304888 }
4889 } else { /* {301} */
4890 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004891 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4892 /* Disable CRT2 */
4893 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4894 /* Disable TV asPrimary VGA swap */
4895 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304896 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004897
Peter Huewea3d675c2012-02-09 21:11:47 +01004898 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304899 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004900 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304901 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004902}
4903
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004904/* --------------------------------------------------------------------- */
4905/* Function : XGI_GetTVPtrIndex */
4906/* Input : */
4907/* Output : */
4908/* Description : bx 0 : ExtNTSC */
4909/* 1 : StNTSC */
4910/* 2 : ExtPAL */
4911/* 3 : StPAL */
4912/* 4 : ExtHiTV */
4913/* 5 : StHiTV */
4914/* 6 : Ext525i */
4915/* 7 : St525i */
4916/* 8 : Ext525p */
4917/* 9 : St525p */
4918/* A : Ext750p */
4919/* B : St750p */
4920/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004921static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004922{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304923 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004924
Peter Huewe599801f2012-02-09 21:11:45 +01004925 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304926 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004927 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304928 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004929 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304930 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004931 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304932 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004933 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304934 tempbx = 10;
4935 if (pVBInfo->TVInfo & TVSimuMode)
4936 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004937
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304938 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004939}
4940
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004941/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004942/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004943/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004944/* Output : bx 0 : NTSC */
4945/* 1 : PAL */
4946/* 2 : PALM */
4947/* 3 : PALN */
4948/* 4 : NTSC1024x768 */
4949/* 5 : PAL-M 1024x768 */
4950/* 6-7: reserved */
4951/* cl 0 : YFilter1 */
4952/* 1 : YFilter2 */
4953/* ch 0 : 301A */
4954/* 1 : 301B/302B/301LV/302LV */
4955/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004956/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004957static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4958 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004959{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004960 *tempbx = 0;
4961 *tempcl = 0;
4962 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004963
Peter Huewe599801f2012-02-09 21:11:45 +01004964 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004965 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004966
Peter Huewe599801f2012-02-09 21:11:45 +01004967 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004968 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004969
Peter Huewe599801f2012-02-09 21:11:45 +01004970 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004971 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004972
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004973 if (pVBInfo->TVInfo & NTSC1024x768) {
4974 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004975 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004976 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304977 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004978
Peter Huewe6896b942012-02-09 21:11:46 +01004979 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4980 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004981 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4982 & TVSimuMode)) {
4983 *tempbx += 8;
4984 *tempcl += 1;
4985 }
4986 }
4987
Peter Huewe6896b942012-02-09 21:11:46 +01004988 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4989 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004990 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004991}
4992
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004993static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004994{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304995 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004996
Peter Huewe6896b942012-02-09 21:11:46 +01004997 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4998 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004999 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305000 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305001 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02005002 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005003
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305004 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5005 tempbl = tempbl >> 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005006 if (pVBInfo->VBInfo &
5007 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02005008 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005009
Peter Huewea3d675c2012-02-09 21:11:47 +01005010 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305011 tempbl = tempbh;
5012 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005013
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305014 tempbl &= 0x0F;
5015 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02005016 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005017
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305018 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
5019 | SetCRT2ToTV)) { /* Channel B */
5020 tempah &= 0xF0;
5021 tempah |= tempbl;
5022 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005023
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005024 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5025 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305026 tempah &= 0x0F;
5027 tempah |= tempbh;
5028 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005029 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305030 }
5031 } else if (pVBInfo->IF_DEF_LVDS == 1) {
5032 tempbl = 0;
5033 tempbh = 0;
5034 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02005035 tempah = XGI301LCDDelay;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305036 tempah &= 0x0f;
5037 tempah = tempah << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005038 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2D, 0x0f,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305039 tempah);
5040 }
5041 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005042}
5043
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005044static void XGI_SetLCDCap_A(unsigned short tempcx,
5045 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005046{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305047 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005048
Aaro Koskinen58839b02011-03-13 12:26:23 +02005049 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005050
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305051 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005052 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005053 /* Enable Dither */
5054 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005055 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305056 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005057 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305058 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005059 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305060 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005061}
5062
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005063/* --------------------------------------------------------------------- */
5064/* Function : XGI_SetLCDCap_B */
5065/* Input : cx -> LCD Capability */
5066/* Output : */
5067/* Description : */
5068/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005069static void XGI_SetLCDCap_B(unsigned short tempcx,
5070 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005071{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305072 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005073 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305074 (unsigned short) (((tempcx & 0x00ff) >> 6)
5075 | 0x0c));
5076 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005077 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305078 (unsigned short) (((tempcx & 0x00ff) >> 6)
5079 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005080}
5081
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02005082static void XGI_LongWait(struct vb_device_info *pVBInfo)
5083{
5084 unsigned short i;
5085
5086 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
5087
5088 if (!(i & 0xC0)) {
5089 for (i = 0; i < 0xFFFF; i++) {
5090 if (!(inb(pVBInfo->P3da) & 0x08))
5091 break;
5092 }
5093
5094 for (i = 0; i < 0xFFFF; i++) {
5095 if ((inb(pVBInfo->P3da) & 0x08))
5096 break;
5097 }
5098 }
5099}
5100
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005101static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005102{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305103 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005104
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305105 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005106
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005107 /* disable down spectrum D[4] */
5108 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305109 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005110 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305111 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005112
Aaro Koskinen8104e322011-03-13 12:26:22 +02005113 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305114 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005115 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305116 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005117 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305118 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005119 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305120 pVBInfo->LCDCapList[index].Spectrum_34);
5121 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005122 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005123}
5124
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005125static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
5126{
5127 unsigned short tempcx;
5128
5129 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
5130
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005131 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005132 (VB_SIS301B |
5133 VB_SIS302B |
5134 VB_SIS301LV |
5135 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005136 VB_XGI301C)) { /* 301LV/302LV only */
5137 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01005138 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005139 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005140 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005141 (unsigned char) (tempcx & 0x1F));
5142 }
5143 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005144 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005145 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
5146 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
5147 | EnablePLLSPLOW)) >> 8));
5148 }
5149
Peter Huewe6896b942012-02-09 21:11:46 +01005150 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5151 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005152 if (pVBInfo->VBInfo & SetCRT2ToLCD)
5153 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01005154 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005155 XGI_SetLCDCap_A(tempcx, pVBInfo);
5156
Peter Huewe6896b942012-02-09 21:11:46 +01005157 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005158 if (tempcx & EnableSpectrum)
5159 SetSpectrum(pVBInfo);
5160 }
5161 } else {
5162 /* LVDS,CH7017 */
5163 XGI_SetLCDCap_A(tempcx, pVBInfo);
5164 }
5165}
5166
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005167/* --------------------------------------------------------------------- */
5168/* Function : XGI_SetAntiFlicker */
5169/* Input : */
5170/* Output : */
5171/* Description : Set TV Customized Param. */
5172/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005173static void XGI_SetAntiFlicker(unsigned short ModeNo,
5174 unsigned short ModeIdIndex,
5175 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005176{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03005177 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005178
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305179 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005180
Peter Huewe599801f2012-02-09 21:11:45 +01005181 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305182 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005183
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305184 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5185 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305186 tempah = TVAntiFlickList[tempbx];
5187 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005188
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005189 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005190}
5191
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005192static void XGI_SetEdgeEnhance(unsigned short ModeNo,
5193 unsigned short ModeIdIndex,
5194 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005195{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03005196 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005197
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305198 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005199
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305200 tempbx = XGI_GetTVPtrIndex(pVBInfo);
5201 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305202 tempah = TVEdgeList[tempbx];
5203 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005204
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005205 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005206}
5207
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005208static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005209{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305210 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005211
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305212 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005213
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305214 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005215
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305216 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
5217 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005218
Aaro Koskinen8104e322011-03-13 12:26:22 +02005219 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305220 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005221 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305222 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005223 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305224 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005225 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305226 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005227}
5228
Aaro Koskinen063b9c42011-03-08 22:16:13 +02005229static void XGI_SetYFilter(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305230 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005231{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305232 unsigned short tempbx, index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005233
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305234 unsigned char tempcl, tempch, tempal, *filterPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005235
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305236 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005237
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305238 switch (tempbx) {
5239 case 0x00:
5240 case 0x04:
5241 filterPtr = NTSCYFilter1;
5242 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005243
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305244 case 0x01:
5245 filterPtr = PALYFilter1;
5246 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005247
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305248 case 0x02:
5249 case 0x05:
5250 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305251 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03005252 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305253 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005254
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305255 case 0x08:
5256 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305257 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305258 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305259 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03005260 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305261 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005262
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305263 default:
5264 return;
5265 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005266
Aaro Koskinenb3979922012-11-04 21:14:52 +02005267 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305268 if (tempcl == 0)
5269 index = tempal * 4;
5270 else
5271 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005272
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305273 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005274 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
5275 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
5276 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
5277 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305278 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005279 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
5280 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
5281 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
5282 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305283 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005284
Peter Huewe6896b942012-02-09 21:11:46 +01005285 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5286 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02005287 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
5288 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
5289 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305290 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005291}
5292
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005293/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005294/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005295/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005296/* Output : */
5297/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005298/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005299static void XGI_OEM310Setting(unsigned short ModeNo,
5300 unsigned short ModeIdIndex,
5301 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005302{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005303 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005304
Peter Huewea3d675c2012-02-09 21:11:47 +01005305 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005306 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005307
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005308 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005309 XGI_SetPhaseIncr(pVBInfo);
5310 XGI_SetYFilter(ModeNo, ModeIdIndex, pVBInfo);
5311 XGI_SetAntiFlicker(ModeNo, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005312
Peter Huewe6896b942012-02-09 21:11:46 +01005313 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005314 XGI_SetEdgeEnhance(ModeNo, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305315 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005316}
5317
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005318/* --------------------------------------------------------------------- */
5319/* Function : XGI_SetCRT2ModeRegs */
5320/* Input : */
5321/* Output : */
5322/* Description : Origin code for crt2group */
5323/* --------------------------------------------------------------------- */
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005324static void XGI_SetCRT2ModeRegs(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305325 struct xgi_hw_device_info *HwDeviceExtension,
5326 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005327{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305328 unsigned short tempbl;
5329 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005330
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305331 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005332
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305333 tempah = 0;
5334 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005335 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305336 tempah &= ~0x10; /* BTRAMDAC */
5337 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005338
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305339 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
5340 | SetCRT2ToLCD)) {
5341 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005342 tempcl = pVBInfo->ModeType;
5343 tempcl -= ModeVGA;
5344 if (tempcl >= 0) {
5345 /* BT Color */
5346 tempah = (0x008 >> tempcl);
5347 if (tempah == 0)
5348 tempah = 1;
5349 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305350 }
5351 if (pVBInfo->VBInfo & SetInSlaveMode)
5352 tempah ^= 0x50; /* BTDAC */
5353 }
5354 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005355
Aaro Koskinen8104e322011-03-13 12:26:22 +02005356 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305357 tempah = 0x08;
5358 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005359
Miguel Gómeze123e462012-07-06 12:40:52 +02005360 if (pVBInfo->VBInfo & DisableCRT2Display)
5361 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005362
Miguel Gómeze123e462012-07-06 12:40:52 +02005363 tempah = 0x00;
5364 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005365
Miguel Gómeze123e462012-07-06 12:40:52 +02005366 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
5367 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
5368 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005369
Miguel Gómeze123e462012-07-06 12:40:52 +02005370 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5371 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
5372 tempbl &= 0xf7;
5373 tempah |= 0x01;
5374 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305375 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005376
Miguel Gómeze123e462012-07-06 12:40:52 +02005377 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
5378 tempbl &= 0xf7;
5379 tempah |= 0x01;
5380 }
5381
5382 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
5383 goto reg_and_or;
5384
5385 tempbl &= 0xf8;
5386 tempah = 0x01;
5387
5388 if (!(pVBInfo->VBInfo & SetInSlaveMode))
5389 tempah |= 0x02;
5390
5391 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5392 tempah = tempah ^ 0x05;
5393 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
5394 tempah = tempah ^ 0x01;
5395 }
5396
5397 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5398 tempah |= 0x08;
5399
5400reg_and_or:
5401 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
5402
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305403 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005404 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305405 tempah &= (~0x08);
5406 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5407 & SetInSlaveMode))) {
5408 tempah |= 0x010;
5409 }
5410 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005411
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305412 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305413 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005414 if (pVBInfo->VBInfo & DriverMode)
5415 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305416 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005417
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005418 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305419 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005420
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305421 if (pVBInfo->LCDInfo & SetLCDDualLink)
5422 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005423
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305424 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305425 if (pVBInfo->TVInfo & RPLLDIV2XO)
5426 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305427 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005428
Peter Huewe255aabd2012-02-09 21:11:44 +01005429 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5430 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305431 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005432
Peter Huewe255aabd2012-02-09 21:11:44 +01005433 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305434 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005435
Aaro Koskinen8104e322011-03-13 12:26:22 +02005436 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305437 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005438
Peter Huewe6896b942012-02-09 21:11:46 +01005439 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5440 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305441 tempah = 0;
5442 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005443
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305444 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5445 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005446 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305447 tempah |= 0x04; /* shampoo 0129 */
5448 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005449
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005450 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305451 tempah = 0x00;
5452 tempbl = 0xcf;
5453 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5454 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5455 tempah |= 0x30;
5456 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005457
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005458 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305459 tempah = 0;
5460 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005461
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305462 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5463 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5464 tempah |= 0xc0;
5465 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005466 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305467 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005468
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305469 tempah = 0;
5470 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005471 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305472 tempbl = 0xff;
5473 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5474 tempah |= 0x80;
5475 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005476
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005477 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005478
Peter Huewe6896b942012-02-09 21:11:46 +01005479 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305480 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005481 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5482 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305483 }
5484 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005485}
5486
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005487
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305488void XGI_UnLockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5489 struct vb_device_info *pVBInfo)
5490{
5491
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005492 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005493
5494}
5495
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305496void XGI_LockCRT2(struct xgi_hw_device_info *HwDeviceExtension,
5497 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005498{
5499
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005500 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005501
5502}
5503
Bill Pemberton80adad82010-06-17 13:10:51 -04005504unsigned char XGI_BridgeIsOn(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005505{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305506 unsigned short flag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005507
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305508 if (pVBInfo->IF_DEF_LVDS == 1) {
5509 return 1;
5510 } else {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005511 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305512 if ((flag == 1) || (flag == 2))
5513 return 1; /* 301b */
5514 else
5515 return 0;
5516 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005517}
5518
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005519unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5520 unsigned short ModeNo, unsigned short ModeIdIndex,
5521 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005522{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005523 short LCDRefreshIndex[] = { 0x00, 0x00, 0x03, 0x01 },
5524 LCDARefreshIndex[] = { 0x00, 0x00, 0x03, 0x01, 0x01,
5525 0x01, 0x01 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005526
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005527 unsigned short RefreshRateTableIndex, i, modeflag, index, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005528
Aaro Koskinenb3979922012-11-04 21:14:52 +02005529 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005530
Aaro Koskinen58839b02011-03-13 12:26:23 +02005531 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005532 index = index >> pVBInfo->SelectCRT2Rate;
5533 index &= 0x0F;
5534
5535 if (pVBInfo->LCDInfo & LCDNonExpanding)
5536 index = 0;
5537
5538 if (index > 0)
5539 index--;
5540
5541 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005542 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005543 if (pVBInfo->IF_DEF_LVDS == 0) {
Peter Huewe6896b942012-02-09 21:11:46 +01005544 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
5545 | VB_SIS301LV | VB_SIS302LV
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005546 | VB_XGI301C))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005547 /* 301b */
5548 temp = LCDARefreshIndex[
5549 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005550 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005551 temp = LCDRefreshIndex[
5552 pVBInfo->LCDResInfo & 0x0F];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005553
5554 if (index > temp)
5555 index = temp;
5556 } else {
5557 index = 0;
5558 }
5559 }
5560 }
5561
Aaro Koskinenb3979922012-11-04 21:14:52 +02005562 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005563 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005564 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005565 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5566 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005567 index++;
5568 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005569 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005570 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5571 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005572 index++;
5573 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005574 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5575 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005576 index++;
5577 }
5578 }
5579
5580 i = 0;
5581 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005582 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005583 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005584 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005585 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005586 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005587 if (temp < pVBInfo->ModeType)
5588 break;
5589 i++;
5590 index--;
5591
5592 } while (index != 0xFFFF);
5593 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5594 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005595 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005596 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005597 if (temp & InterlaceMode)
5598 i++;
5599 }
5600 }
5601 i--;
5602 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
5603 temp = XGI_AjustCRT2Rate(ModeNo, ModeIdIndex,
5604 RefreshRateTableIndex, &i, pVBInfo);
5605 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005606 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005607}
5608
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005609static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305610 struct xgi_hw_device_info *HwDeviceExtension,
5611 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005612{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005613 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005614
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005615 pVBInfo->SetFlag |= ProgrammingCRT2;
5616 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5617 ModeIdIndex, pVBInfo);
5618 XGI_GetLVDSResInfo(ModeNo, ModeIdIndex, pVBInfo);
5619 XGI_GetLVDSData(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5620 XGI_ModCRT1Regs(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5621 HwDeviceExtension, pVBInfo);
5622 XGI_SetLVDSRegs(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5623 XGI_SetCRT2ECLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005624}
5625
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005626static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005627 struct xgi_hw_device_info *HwDeviceExtension,
5628 struct vb_device_info *pVBInfo)
5629{
5630 unsigned short tempbx, ModeIdIndex, RefreshRateTableIndex;
5631
5632 tempbx = pVBInfo->VBInfo;
5633 pVBInfo->SetFlag |= ProgrammingCRT2;
5634 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5635 pVBInfo->SelectCRT2Rate = 4;
5636 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5637 ModeIdIndex, pVBInfo);
5638 XGI_SaveCRT2Info(ModeNo, pVBInfo);
5639 XGI_GetCRT2ResInfo(ModeNo, ModeIdIndex, pVBInfo);
5640 XGI_GetCRT2Data(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5641 XGI_PreSetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5642 RefreshRateTableIndex, pVBInfo);
5643 XGI_SetGroup1(ModeNo, ModeIdIndex, HwDeviceExtension,
5644 RefreshRateTableIndex, pVBInfo);
5645 XGI_SetLockRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5646 RefreshRateTableIndex, pVBInfo);
5647 XGI_SetGroup2(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5648 HwDeviceExtension, pVBInfo);
5649 XGI_SetLCDRegs(ModeNo, ModeIdIndex, HwDeviceExtension,
5650 RefreshRateTableIndex, pVBInfo);
5651 XGI_SetTap4Regs(pVBInfo);
5652 XGI_SetGroup3(ModeNo, ModeIdIndex, pVBInfo);
5653 XGI_SetGroup4(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5654 HwDeviceExtension, pVBInfo);
5655 XGI_SetCRT2VCLK(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5656 XGI_SetGroup5(ModeNo, ModeIdIndex, pVBInfo);
5657 XGI_AutoThreshold(pVBInfo);
5658 return 1;
5659}
5660
5661void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5662{
5663 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5664 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5665 0x05, 0x00 };
5666
5667 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5668
5669 unsigned char CR17, CR63, SR31;
5670 unsigned short temp;
5671 unsigned char DAC_TEST_PARMS[3] = { 0x0F, 0x0F, 0x0F };
5672
5673 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005674 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005675
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005676 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005677 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02005678 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005679 pVBInfo->P3d4, 0x53) | 0x02));
5680
Aaro Koskinen58839b02011-03-13 12:26:23 +02005681 SR31 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x31);
5682 CR63 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x63);
5683 SR01 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005684
Aaro Koskinen8104e322011-03-13 12:26:22 +02005685 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5686 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005687
Aaro Koskinen58839b02011-03-13 12:26:23 +02005688 CR17 = (unsigned char) xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005689 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005690
Aaro Koskinen58839b02011-03-13 12:26:23 +02005691 SR1F = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005692 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005693
Aaro Koskinen58839b02011-03-13 12:26:23 +02005694 SR07 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005695 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Aaro Koskinen58839b02011-03-13 12:26:23 +02005696 SR06 = (unsigned char) xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005697 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005698
Aaro Koskinen8104e322011-03-13 12:26:22 +02005699 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005700
5701 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005702 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005703
5704 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005705 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005706 CRTCData[i]);
5707
5708 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005709 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005710 CRTCData[i]);
5711
5712 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005713 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005714 CRTCData[i]);
5715
Aaro Koskinen8104e322011-03-13 12:26:22 +02005716 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005717 & 0xE0));
5718
Aaro Koskinen8104e322011-03-13 12:26:22 +02005719 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5720 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5721 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005722
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005723 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005724
5725 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005726 outb((unsigned char) DAC_TEST_PARMS[0], (pVBInfo->P3c8 + 1));
5727 outb((unsigned char) DAC_TEST_PARMS[1], (pVBInfo->P3c8 + 1));
5728 outb((unsigned char) DAC_TEST_PARMS[2], (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005729 }
5730
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005731 mdelay(1);
5732
5733 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005734 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005735
5736 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005737 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005738 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005739 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005740
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005741 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005742 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005743
5744 for (i = 0; i < 256; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005745 outb(0, (pVBInfo->P3c8 + 1));
5746 outb(0, (pVBInfo->P3c8 + 1));
5747 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005748 }
5749
Aaro Koskinen8104e322011-03-13 12:26:22 +02005750 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5751 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5752 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005753
Aaro Koskinen58839b02011-03-13 12:26:23 +02005754 xgifb_reg_set(pVBInfo->P3d4, 0x53, (unsigned char) (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005755 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005756 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005757}
5758
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005759static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5760 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005761 struct vb_device_info *pVBInfo)
5762{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005763 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005764
Peter Huewe6896b942012-02-09 21:11:46 +01005765 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5766 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005767 if (!(pVBInfo->SetFlag & DisableChA)) {
5768 if (pVBInfo->SetFlag & EnableChA) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005769 /* Power on */
5770 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinend3ae5762012-09-11 00:15:27 +03005771 } else if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5772 /* Power on */
5773 xgifb_reg_set(pVBInfo->Part1Port,
5774 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005775 }
5776 }
5777
5778 if (!(pVBInfo->SetFlag & DisableChB)) {
5779 if ((pVBInfo->SetFlag & EnableChB) || (pVBInfo->VBInfo
5780 & (SetCRT2ToLCD | SetCRT2ToTV
5781 | SetCRT2ToRAMDAC))) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005782 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005783 pVBInfo->P3c4, 0x32);
5784 tempah &= 0xDF;
5785 if (pVBInfo->VBInfo & SetInSlaveMode) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005786 if (!(pVBInfo->VBInfo &
5787 SetCRT2ToRAMDAC))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005788 tempah |= 0x20;
5789 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02005790 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005791 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005792
Aaro Koskinen58839b02011-03-13 12:26:23 +02005793 tempah = (unsigned char) xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005794 pVBInfo->Part1Port, 0x2E);
5795
5796 if (!(tempah & 0x80))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005797 xgifb_reg_or(pVBInfo->Part1Port,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005798 0x2E, 0x80);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005799 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005800 }
5801 }
5802
5803 if ((pVBInfo->SetFlag & (EnableChA | EnableChB))
5804 || (!(pVBInfo->VBInfo & DisableCRT2Display))) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005805 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005806 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005807 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005808 if (!XGI_DisableChISLCD(pVBInfo)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005809 if (XGI_EnableChISLCD(pVBInfo) ||
5810 (pVBInfo->VBInfo &
Peter Huewea3d675c2012-02-09 21:11:47 +01005811 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005812 /* LVDS PLL power on */
Aaro Koskinendc505562011-03-13 12:26:26 +02005813 xgifb_reg_and(
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005814 pVBInfo->Part4Port,
5815 0x2A,
5816 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005817 }
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005818 /* LVDS Driver power on */
5819 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005820 }
5821 }
5822
5823 tempah = 0x00;
5824
5825 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5826 tempah = 0xc0;
5827
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005828 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5829 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5830 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5831 tempah = tempah & 0x40;
5832 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5833 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005834
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005835 if (pVBInfo->SetFlag & DisableChB)
5836 tempah &= 0xBF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005837
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005838 if (pVBInfo->SetFlag & DisableChA)
5839 tempah &= 0x7F;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005840
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005841 if (pVBInfo->SetFlag & EnableChB)
5842 tempah |= 0x40;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005843
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005844 if (pVBInfo->SetFlag & EnableChA)
5845 tempah |= 0x80;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005846 }
5847 }
5848
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005849 /* EnablePart4_1F */
5850 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005851
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005852 if (!(pVBInfo->SetFlag & DisableChA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005853 if (!(pVBInfo->SetFlag & GatingCRT)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005854 XGI_DisableGatingCRT(HwDeviceExtension,
5855 pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005856 XGI_DisplayOn(xgifb_info, HwDeviceExtension,
5857 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005858 }
5859 }
5860 } /* 301 */
5861 else { /* LVDS */
5862 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005863 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005864 /* enable CRT2 */
5865 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005866
Aaro Koskinen58839b02011-03-13 12:26:23 +02005867 tempah = (unsigned char) xgifb_reg_get(pVBInfo->Part1Port,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005868 0x2E);
5869 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005870 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005871
Aaro Koskinendc505562011-03-13 12:26:26 +02005872 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005873 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005874 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005875}
5876
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005877static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5878 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005879 unsigned short ModeNo, unsigned short ModeIdIndex,
5880 struct vb_device_info *pVBInfo)
5881{
Aaro Koskinena1579612012-04-07 01:14:05 +03005882 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005883
Aaro Koskinena1579612012-04-07 01:14:05 +03005884 XGI_SetSeqRegs(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005885 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinena1579612012-04-07 01:14:05 +03005886 XGI_SetCRTCRegs(HwDeviceExtension, pVBInfo);
5887 XGI_SetATTRegs(ModeNo, ModeIdIndex, pVBInfo);
5888 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005889 XGI_ClearExt1Regs(pVBInfo);
5890
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005891 if (HwDeviceExtension->jChipType == XG27) {
5892 if (pVBInfo->IF_DEF_LVDS == 0)
5893 XGI_SetDefaultVCLK(pVBInfo);
5894 }
5895
5896 temp = ~ProgrammingCRT2;
5897 pVBInfo->SetFlag &= temp;
5898 pVBInfo->SelectCRT2Rate = 0;
5899
Peter Huewe6896b942012-02-09 21:11:46 +01005900 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5901 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005902 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005903 | SetInSlaveMode)) {
5904 pVBInfo->SetFlag |= ProgrammingCRT2;
5905 }
5906 }
5907
5908 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5909 ModeIdIndex, pVBInfo);
5910 if (RefreshRateTableIndex != 0xFFFF) {
5911 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
5912 XGI_SetCRT1CRTC(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5913 pVBInfo, HwDeviceExtension);
5914 XGI_SetCRT1DE(HwDeviceExtension, ModeNo, ModeIdIndex,
5915 RefreshRateTableIndex, pVBInfo);
5916 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5917 HwDeviceExtension, pVBInfo);
5918 XGI_SetCRT1VCLK(ModeNo, ModeIdIndex, HwDeviceExtension,
5919 RefreshRateTableIndex, pVBInfo);
5920 }
5921
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005922 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005923 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005924 if (temp & 0xA0) {
5925
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005926 if (HwDeviceExtension->jChipType == XG27)
5927 XGI_SetXG27CRTC(ModeNo, ModeIdIndex,
5928 RefreshRateTableIndex, pVBInfo);
5929 else
5930 XGI_SetXG21CRTC(ModeNo, ModeIdIndex,
5931 RefreshRateTableIndex, pVBInfo);
5932
5933 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5934 RefreshRateTableIndex);
5935
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005936 xgifb_set_lcd(HwDeviceExtension->jChipType,
5937 pVBInfo, RefreshRateTableIndex, ModeNo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005938
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005939 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005940 xgifb_set_lvds(xgifb_info,
5941 HwDeviceExtension->jChipType,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005942 ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005943 }
5944 }
5945
5946 pVBInfo->SetFlag &= (~ProgrammingCRT2);
5947 XGI_SetCRT1FIFO(ModeNo, HwDeviceExtension, pVBInfo);
5948 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeNo, ModeIdIndex,
5949 RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005950 XGI_LoadDAC(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005951}
5952
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005953unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5954 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005955 unsigned short ModeNo)
5956{
5957 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005958 struct vb_device_info VBINF;
5959 struct vb_device_info *pVBInfo = &VBINF;
Dmitry Eremin-Solenikov9a801f22012-03-19 21:50:13 +04005960 pVBInfo->BaseAddr = xgifb_info->vga_base;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005961 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005962
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005963 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005964 pVBInfo->IF_DEF_YPbPr = 0;
5965 pVBInfo->IF_DEF_HiVision = 0;
5966 pVBInfo->IF_DEF_CRT2Monitor = 0;
5967 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005968 } else {
5969 pVBInfo->IF_DEF_YPbPr = 1;
5970 pVBInfo->IF_DEF_HiVision = 1;
Aaro Koskinen06587332011-03-13 12:26:10 +02005971 pVBInfo->IF_DEF_CRT2Monitor = 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005972 }
5973
5974 pVBInfo->P3c4 = pVBInfo->BaseAddr + 0x14;
5975 pVBInfo->P3d4 = pVBInfo->BaseAddr + 0x24;
5976 pVBInfo->P3c0 = pVBInfo->BaseAddr + 0x10;
5977 pVBInfo->P3ce = pVBInfo->BaseAddr + 0x1e;
5978 pVBInfo->P3c2 = pVBInfo->BaseAddr + 0x12;
5979 pVBInfo->P3cc = pVBInfo->BaseAddr + 0x1C;
5980 pVBInfo->P3ca = pVBInfo->BaseAddr + 0x1a;
5981 pVBInfo->P3c6 = pVBInfo->BaseAddr + 0x16;
5982 pVBInfo->P3c7 = pVBInfo->BaseAddr + 0x17;
5983 pVBInfo->P3c8 = pVBInfo->BaseAddr + 0x18;
5984 pVBInfo->P3c9 = pVBInfo->BaseAddr + 0x19;
5985 pVBInfo->P3da = pVBInfo->BaseAddr + 0x2A;
5986 pVBInfo->Part0Port = pVBInfo->BaseAddr + XGI_CRT2_PORT_00;
Peter Huewe6896b942012-02-09 21:11:46 +01005987 pVBInfo->Part1Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_04;
5988 pVBInfo->Part2Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_10;
5989 pVBInfo->Part3Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_12;
5990 pVBInfo->Part4Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14;
5991 pVBInfo->Part5Port = pVBInfo->BaseAddr + SIS_CRT2_PORT_14 + 2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005992
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005993 /* for x86 Linux, XG21 LVDS */
5994 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005995 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005996 pVBInfo->IF_DEF_LVDS = 1;
5997 }
5998 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005999 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
6000 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006001 pVBInfo->IF_DEF_LVDS = 1;
6002 }
6003 }
6004
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006005 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006006 XGI_GetVBType(pVBInfo);
6007
6008 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02006009 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006010 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02006011 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006012
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006013 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006014 XGI_UnLockCRT2(HwDeviceExtension, pVBInfo);
6015
6016 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
6017
Miguel Gómez949eb0a2012-07-06 12:40:36 +02006018 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006019 XGI_GetVBInfo(ModeNo, ModeIdIndex, HwDeviceExtension, pVBInfo);
6020 XGI_GetTVInfo(ModeNo, ModeIdIndex, pVBInfo);
6021 XGI_GetLCDInfo(ModeNo, ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006022 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006023
Peter Huewea3d675c2012-02-09 21:11:47 +01006024 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006025 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006026 ModeIdIndex, pVBInfo);
6027
Peter Huewea3d675c2012-02-09 21:11:47 +01006028 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006029 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6030 HwDeviceExtension, pVBInfo);
6031 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03006032 } else if (!(pVBInfo->VBInfo & SwitchCRT2)) {
6033 XGI_SetCRT1Group(xgifb_info,
6034 HwDeviceExtension, ModeNo,
6035 ModeIdIndex, pVBInfo);
6036 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
6037 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
6038 HwDeviceExtension,
6039 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006040 }
6041 }
6042
Peter Huewe6896b942012-02-09 21:11:46 +01006043 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006044 switch (HwDeviceExtension->ujVBChipID) {
6045 case VB_CHIP_301:
6046 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6047 pVBInfo); /*add for CRT2 */
6048 break;
6049
6050 case VB_CHIP_302:
6051 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
6052 pVBInfo); /*add for CRT2 */
6053 break;
6054
6055 default:
6056 break;
6057 }
6058 }
6059
6060 XGI_SetCRT2ModeRegs(ModeNo, HwDeviceExtension, pVBInfo);
6061 XGI_OEM310Setting(ModeNo, ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006062 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006063 } /* !XG20 */
6064 else {
6065 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006066 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08006067 ModeIdIndex,
6068 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006069 return 0;
6070
Aaro Koskinenb3979922012-11-04 21:14:52 +02006071 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01006072 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006073
6074 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03006075 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006076
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006077 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006078
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006079 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
6080 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006081
Aaro Koskinenfab04b92011-12-06 00:10:45 +02006082 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006083 }
6084
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006085 XGI_UpdateModeInfo(HwDeviceExtension, pVBInfo);
6086
Miguel Gómez3bcc2462012-07-06 12:40:53 +02006087 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006088 XGI_LockCRT2(HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02006089
6090 return 1;
6091}