blob: 7228d171d31efe46863af7ef4e07e210081bc95f [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"
Aaro Koskinen56810a92013-01-21 02:57:47 +02005#include "vb_init.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02006#include "vb_util.h"
7#include "vb_table.h"
Miguel Gómeze0541022012-06-18 13:12:05 +02008#include "vb_setmode.h"
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02009
10#define IndexMask 0xff
Peter Huewe95072592012-06-14 00:21:48 +020011#define TVCLKBASE_315_25 (TVCLKBASE_315 + 25)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020012
Aaro Koskinen624554d2011-10-11 21:47:35 +030013static const unsigned short XGINew_VGA_DAC[] = {
Bill Pemberton82d6eb52010-06-17 13:10:46 -040014 0x00, 0x10, 0x04, 0x14, 0x01, 0x11, 0x09, 0x15,
15 0x2A, 0x3A, 0x2E, 0x3E, 0x2B, 0x3B, 0x2F, 0x3F,
16 0x00, 0x05, 0x08, 0x0B, 0x0E, 0x11, 0x14, 0x18,
17 0x1C, 0x20, 0x24, 0x28, 0x2D, 0x32, 0x38, 0x3F,
18 0x00, 0x10, 0x1F, 0x2F, 0x3F, 0x1F, 0x27, 0x2F,
19 0x37, 0x3F, 0x2D, 0x31, 0x36, 0x3A, 0x3F, 0x00,
20 0x07, 0x0E, 0x15, 0x1C, 0x0E, 0x11, 0x15, 0x18,
21 0x1C, 0x14, 0x16, 0x18, 0x1A, 0x1C, 0x00, 0x04,
22 0x08, 0x0C, 0x10, 0x08, 0x0A, 0x0C, 0x0E, 0x10,
23 0x0B, 0x0C, 0x0D, 0x0F, 0x10};
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020024
Bill Pemberton80adad82010-06-17 13:10:51 -040025void InitTo330Pointer(unsigned char ChipType, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020026{
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030027 pVBInfo->MCLKData = XGI340New_MCLKData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020028
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053029 pVBInfo->LCDResInfo = 0;
30 pVBInfo->LCDTypeInfo = 0;
31 pVBInfo->LCDInfo = 0;
32 pVBInfo->VBInfo = 0;
33 pVBInfo->TVInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020034
Aaro Koskinen597d96b2013-03-27 23:53:15 +020035 pVBInfo->SR18 = XGI340_SR18;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053036 pVBInfo->CR40 = XGI340_cr41;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020037
Aaro Koskinence76de52013-05-29 23:59:02 +030038 if (ChipType < XG20)
39 XGI_GetVBType(pVBInfo);
40
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053041 /* 310 customization related */
Peter Huewe6896b942012-02-09 21:11:46 +010042 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053043 pVBInfo->LCDCapList = XGI_LCDDLCapList;
44 else
45 pVBInfo->LCDCapList = XGI_LCDCapList;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020046
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053047 if (ChipType >= XG20)
Peter Huewe6d12dae2012-06-14 00:21:52 +020048 pVBInfo->XGINew_CR97 = 0x10;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020049
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053050 if (ChipType == XG27) {
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040051 unsigned char temp;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +030052 pVBInfo->MCLKData = XGI27New_MCLKData;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053053 pVBInfo->CR40 = XGI27_cr41;
Peter Huewe6d12dae2012-06-14 00:21:52 +020054 pVBInfo->XGINew_CR97 = 0xc1;
Aaro Koskinen597d96b2013-03-27 23:53:15 +020055 pVBInfo->SR18 = XG27_SR18;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020056
Dmitry Eremin-Solenikov64903112012-03-19 21:50:09 +040057 /*Z11m DDR*/
58 temp = xgifb_reg_get(pVBInfo->P3c4, 0x3B);
59 /* SR3B[7][3]MAA15 MAA11 (Power on Trapping) */
60 if (((temp & 0x88) == 0x80) || ((temp & 0x88) == 0x08))
Peter Huewe6d12dae2012-06-14 00:21:52 +020061 pVBInfo->XGINew_CR97 = 0x80;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053062 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020063
64}
65
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +030066static void XGI_SetSeqRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020067{
Peter Huewe76a58992013-02-03 22:54:34 +010068 unsigned char SRdata, i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020069
Aaro Koskinen8104e322011-03-13 12:26:22 +020070 xgifb_reg_set(pVBInfo->P3c4, 0x00, 0x03); /* Set SR0 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020071
Peter Huewe76a58992013-02-03 22:54:34 +010072 for (i = 0; i < 4; i++) {
73 /* Get SR1,2,3,4 from file */
74 /* SR1 is with screen off 0x20 */
75 SRdata = XGI330_StandTable.SR[i];
76 xgifb_reg_set(pVBInfo->P3c4, i+1, SRdata); /* Set SR 1 2 3 4 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053077 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020078}
79
Aaro Koskinenb053af12013-07-16 23:13:28 +030080static void XGI_SetCRTCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020081{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053082 unsigned char CRTCdata;
83 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020084
Peter Huewe9388ad92013-02-15 20:37:10 +010085 CRTCdata = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053086 CRTCdata &= 0x7f;
Aaro Koskinen8104e322011-03-13 12:26:22 +020087 xgifb_reg_set(pVBInfo->P3d4, 0x11, CRTCdata); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020088
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053089 for (i = 0; i <= 0x18; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +080090 /* Get CRTC from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +020091 CRTCdata = XGI330_StandTable.CRTC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +020092 xgifb_reg_set(pVBInfo->P3d4, i, CRTCdata); /* Set CRTC(3d4) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053093 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020094}
95
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +030096static void XGI_SetATTRegs(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +080097 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +020098{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +053099 unsigned char ARdata;
100 unsigned short i, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200101
Aaro Koskinenb3979922012-11-04 21:14:52 +0200102 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200103
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530104 for (i = 0; i <= 0x13; i++) {
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200105 ARdata = XGI330_StandTable.ATTR[i];
Miguel Gómez661a6382012-07-06 12:40:45 +0200106
107 if ((modeflag & Charx8Dot) && i == 0x13) { /* ifndef Dot9 */
108 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
109 ARdata = 0;
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300110 } else if ((pVBInfo->VBInfo &
Miguel Gómez661a6382012-07-06 12:40:45 +0200111 (SetCRT2ToTV | SetCRT2ToLCD)) &&
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300112 (pVBInfo->VBInfo & SetInSlaveMode)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530113 ARdata = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530114 }
115 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200116
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200117 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200118 outb(i, pVBInfo->P3c0); /* set index */
119 outb(ARdata, pVBInfo->P3c0); /* set data */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530120 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200121
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200122 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200123 outb(0x14, pVBInfo->P3c0); /* set index */
124 outb(0x00, pVBInfo->P3c0); /* set data */
Aaro Koskinend8ad0a62011-03-13 12:26:18 +0200125 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200126 outb(0x20, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200127}
128
Aaro Koskinena1579612012-04-07 01:14:05 +0300129static void XGI_SetGRCRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200130{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530131 unsigned char GRdata;
132 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200133
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530134 for (i = 0; i <= 0x08; i++) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800135 /* Get GR from file */
Aaro Koskinen3625c9a2012-11-04 21:14:51 +0200136 GRdata = XGI330_StandTable.GRC[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200137 xgifb_reg_set(pVBInfo->P3ce, i, GRdata); /* Set GR(3ce) */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530138 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200139
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530140 if (pVBInfo->ModeType > ModeVGA) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100141 GRdata = xgifb_reg_get(pVBInfo->P3ce, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530142 GRdata &= 0xBF; /* 256 color disable */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200143 xgifb_reg_set(pVBInfo->P3ce, 0x05, GRdata);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530144 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200145}
146
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200147static void XGI_ClearExt1Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200148{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530149 unsigned short i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200150
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530151 for (i = 0x0A; i <= 0x0E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200152 xgifb_reg_set(pVBInfo->P3c4, i, 0x00); /* Clear SR0A-SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200153}
154
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200155static unsigned char XGI_SetDefaultVCLK(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200156{
157
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200158 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x20);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200159 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[0].SR2B);
160 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[0].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200161
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200162 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, 0x10);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200163 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[1].SR2B);
164 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[1].SR2C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200165
Aaro Koskinendc505562011-03-13 12:26:26 +0200166 xgifb_reg_and(pVBInfo->P3c4, 0x31, ~0x30);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530167 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200168}
169
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300170static unsigned char XGI_AjustCRT2Rate(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530171 unsigned short RefreshRateTableIndex, unsigned short *i,
172 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200173{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530174 unsigned short tempax, tempbx, resinfo, modeflag, infoflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200175
Aaro Koskinenb3979922012-11-04 21:14:52 +0200176 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
177 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200178 tempbx = XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530179 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200180
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300181 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
182 tempax |= SupportRAMDAC2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200183
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300184 if (pVBInfo->VBType & VB_XGI301C)
185 tempax |= SupportCRT2in301C;
186 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200187
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300188 /* 301b */
189 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinend3ae5762012-09-11 00:15:27 +0300190 tempax |= SupportLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200191
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300192 if (pVBInfo->LCDResInfo != Panel_1280x1024 &&
193 pVBInfo->LCDResInfo != Panel_1280x960 &&
194 (pVBInfo->LCDInfo & LCDNonExpanding) &&
195 resinfo >= 9)
196 return 0;
197 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200198
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300199 if (pVBInfo->VBInfo & SetCRT2ToHiVision) { /* for HiTV */
200 tempax |= SupportHiVision;
201 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
202 ((resinfo == 4) ||
203 (resinfo == 3 && (pVBInfo->SetFlag & TVSimuMode)) ||
204 (resinfo > 7)))
205 return 0;
206 } else if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO | SetCRT2ToSVIDEO |
207 SetCRT2ToSCART | SetCRT2ToYPbPr525750 |
208 SetCRT2ToHiVision)) {
209 tempax |= SupportTV;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200210
Aaro Koskinen0903b0d2013-05-29 23:59:03 +0300211 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
212 VB_SIS302LV | VB_XGI301C))
213 tempax |= SupportTV1024;
214
215 if (!(pVBInfo->VBInfo & TVSetPAL) &&
216 (modeflag & NoSupportSimuTV) &&
217 (pVBInfo->VBInfo & SetInSlaveMode) &&
218 (!(pVBInfo->VBInfo & SetNotSimuMode)))
219 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530220 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200221
Aaro Koskinena39325d2012-11-04 21:14:53 +0200222 for (; XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID ==
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800223 tempbx; (*i)--) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200224 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800225 Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530226 if (infoflag & tempax)
227 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200228
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530229 if ((*i) == 0)
230 break;
231 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200232
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530233 for ((*i) = 0;; (*i)++) {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200234 infoflag = XGI330_RefIndex[RefreshRateTableIndex + (*i)].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800235 Ext_InfoFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200236 if (XGI330_RefIndex[RefreshRateTableIndex + (*i)].ModeID
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530237 != tempbx) {
238 return 0;
239 }
240
241 if (infoflag & tempax)
242 return 1;
243 }
244 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200245}
246
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200247static void XGI_SetSync(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530248 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200249{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530250 unsigned short sync, temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200251
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800252 /* di+0x00 */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200253 sync = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag >> 8;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530254 sync &= 0xC0;
255 temp = 0x2F;
256 temp |= sync;
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +0200257 outb(temp, pVBInfo->P3c2); /* Set Misc(3c2) */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200258}
259
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200260static void XGI_SetCRT1Timing_H(struct vb_device_info *pVBInfo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530261 struct xgi_hw_device_info *HwDeviceExtension)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200262{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530263 unsigned char data, data1, pushax;
264 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200265
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800266 /* unlock cr0-7 */
Peter Huewe9388ad92013-02-15 20:37:10 +0100267 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530268 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200269 xgifb_reg_set(pVBInfo->P3d4, 0x11, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200270
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200271 data = pVBInfo->TimingH.data[0];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200272 xgifb_reg_set(pVBInfo->P3d4, 0, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200273
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530274 for (i = 0x01; i <= 0x04; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200275 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200276 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 1), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530277 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200278
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530279 for (i = 0x05; i <= 0x06; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200280 data = pVBInfo->TimingH.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200281 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530282 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200283
Peter Huewe9388ad92013-02-15 20:37:10 +0100284 j = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530285 j &= 0x1F;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200286 data = pVBInfo->TimingH.data[7];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530287 data &= 0xE0;
288 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200289 xgifb_reg_set(pVBInfo->P3c4, 0x0e, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200290
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530291 if (HwDeviceExtension->jChipType >= XG20) {
Peter Huewe9388ad92013-02-15 20:37:10 +0100292 data = xgifb_reg_get(pVBInfo->P3d4, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530293 data = data - 1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200294 xgifb_reg_set(pVBInfo->P3d4, 0x04, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100295 data = xgifb_reg_get(pVBInfo->P3d4, 0x05);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530296 data1 = data;
297 data1 &= 0xE0;
298 data &= 0x1F;
299 if (data == 0) {
300 pushax = data;
Peter Huewe9388ad92013-02-15 20:37:10 +0100301 data = xgifb_reg_get(pVBInfo->P3c4, 0x0c);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530302 data &= 0xFB;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200303 xgifb_reg_set(pVBInfo->P3c4, 0x0c, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530304 data = pushax;
305 }
306 data = data - 1;
307 data |= data1;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200308 xgifb_reg_set(pVBInfo->P3d4, 0x05, data);
Peter Huewe9388ad92013-02-15 20:37:10 +0100309 data = xgifb_reg_get(pVBInfo->P3c4, 0x0e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530310 data = data >> 5;
311 data = data + 3;
312 if (data > 7)
313 data = data - 7;
314 data = data << 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200315 xgifb_reg_and_or(pVBInfo->P3c4, 0x0e, ~0xE0, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530316 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200317}
318
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800319static void XGI_SetCRT1Timing_V(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800320 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200321{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530322 unsigned char data;
323 unsigned short i, j;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200324
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530325 for (i = 0x00; i <= 0x01; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200326 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200327 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 6), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530328 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200329
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530330 for (i = 0x02; i <= 0x03; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200331 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200332 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x0e), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530333 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200334
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530335 for (i = 0x04; i <= 0x05; i++) {
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200336 data = pVBInfo->TimingV.data[i];
Aaro Koskinen8104e322011-03-13 12:26:22 +0200337 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 0x11), data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530338 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200339
Peter Huewe9388ad92013-02-15 20:37:10 +0100340 j = xgifb_reg_get(pVBInfo->P3c4, 0x0a);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530341 j &= 0xC0;
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200342 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530343 data &= 0x3F;
344 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200345 xgifb_reg_set(pVBInfo->P3c4, 0x0a, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200346
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200347 data = pVBInfo->TimingV.data[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530348 data &= 0x80;
349 data = data >> 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200350
Aaro Koskinenb3979922012-11-04 21:14:52 +0200351 i = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530352 i &= DoubleScanMode;
353 if (i)
354 data |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200355
Peter Huewe9388ad92013-02-15 20:37:10 +0100356 j = xgifb_reg_get(pVBInfo->P3d4, 0x09);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530357 j &= 0x5F;
358 data |= j;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200359 xgifb_reg_set(pVBInfo->P3d4, 0x09, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200360}
361
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300362static void XGI_SetCRT1CRTC(unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200363 unsigned short RefreshRateTableIndex,
364 struct vb_device_info *pVBInfo,
365 struct xgi_hw_device_info *HwDeviceExtension)
366{
367 unsigned char index, data;
368 unsigned short i;
369
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800370 /* Get index */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200371 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200372 index = index & IndexMask;
373
Peter Huewe9388ad92013-02-15 20:37:10 +0100374 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200375 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200376 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200377
378 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200379 pVBInfo->TimingH.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200380 = XGI_CRT1Table[index].CR[i];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200381
382 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +0200383 pVBInfo->TimingV.data[i]
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200384 = XGI_CRT1Table[index].CR[i + 8];
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200385
386 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
387
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300388 XGI_SetCRT1Timing_V(ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200389
390 if (pVBInfo->ModeType > 0x03)
Aaro Koskinen8104e322011-03-13 12:26:22 +0200391 xgifb_reg_set(pVBInfo->P3d4, 0x14, 0x4F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200392}
393
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200394/* --------------------------------------------------------------------- */
395/* Function : XGI_SetXG21CRTC */
396/* Input : Stand or enhance CRTC table */
397/* Output : Fill CRT Hsync/Vsync to SR2E/SR2F/SR30/SR33/SR34/SR3F */
398/* Description : Set LCD timing */
399/* --------------------------------------------------------------------- */
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +0300400static void XGI_SetXG21CRTC(unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530401 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200402{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300403 unsigned char index, Tempax, Tempbx, Tempcx, Tempdx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530404 unsigned short Temp1, Temp2, Temp3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200405
Aaro Koskinena39325d2012-11-04 21:14:53 +0200406 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300407 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200408 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300409 Tempcx = Tempax; /* Tempcx: HRS */
410 /* SR2E[7:0]->HRS */
411 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200412
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200413 Tempdx = XGI_CRT1Table[index].CR[5]; /* SRB */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300414 Tempdx &= 0xC0; /* Tempdx[7:6]: SRB[7:6] */
415 Temp1 = Tempdx; /* Temp1[7:6]: HRS[9:8] */
416 Temp1 <<= 2; /* Temp1[9:8]: HRS[9:8] */
417 Temp1 |= Tempax; /* Temp1[9:0]: HRS[9:0] */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800418
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200419 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300420 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200421
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200422 Tempbx = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300423 Tempbx &= 0x04; /* Tempbx[2]: HRE[5] */
424 Tempbx <<= 3; /* Tempbx[5]: HRE[5] */
425 Tempax |= Tempbx; /* Tempax[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200426
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300427 Temp2 = Temp1 & 0x3C0; /* Temp2[9:6]: HRS[9:6] */
428 Temp2 |= Tempax; /* Temp2[9:0]: HRE[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200429
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300430 Tempcx &= 0x3F; /* Tempcx[5:0]: HRS[5:0] */
431 if (Tempax < Tempcx) /* HRE < HRS */
432 Temp2 |= 0x40; /* Temp2 + 0x40 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200433
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300434 Temp2 &= 0xFF;
435 Tempax = (unsigned char) Temp2; /* Tempax: HRE[7:0] */
436 Tempax <<= 2; /* Tempax[7:2]: HRE[5:0] */
437 Tempdx >>= 6; /* Tempdx[7:6]->[1:0] HRS[9:8] */
438 Tempax |= Tempdx; /* HRE[5:0]HRS[9:8] */
439 /* SR2F D[7:2]->HRE, D[1:0]->HRS */
440 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
441 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200442
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300443 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200444 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300445 Tempbx = Tempax; /* Tempbx: VRS */
446 Tempax &= 0x01; /* Tempax[0]: VRS[0] */
447 xgifb_reg_or(pVBInfo->P3c4, 0x33, Tempax); /* SR33[0]->VRS[0] */
448 /* CR7[2][7] VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200449 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300450 Tempcx = Tempbx >> 1; /* Tempcx[6:0]: VRS[7:1] */
451 Tempdx = Tempax & 0x04; /* Tempdx[2]: CR7[2] */
452 Tempdx <<= 5; /* Tempdx[7]: VRS[8] */
453 Tempcx |= Tempdx; /* Tempcx[7:0]: VRS[8:1] */
454 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempcx); /* SR34[8:1]->VRS */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200455
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300456 Temp1 = Tempdx; /* Temp1[7]: Tempdx[7] */
457 Temp1 <<= 1; /* Temp1[8]: VRS[8] */
458 Temp1 |= Tempbx; /* Temp1[8:0]: VRS[8:0] */
459 Tempax &= 0x80;
460 Temp2 = Tempax << 2; /* Temp2[9]: VRS[9] */
461 Temp1 |= Temp2; /* Temp1[9:0]: VRS[9:0] */
462 /* Tempax: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200463 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300464 Tempax &= 0x08; /* Tempax[3]: VRS[3] */
465 Temp2 = Tempax;
466 Temp2 <<= 7; /* Temp2[10]: VRS[10] */
467 Temp1 |= Temp2; /* Temp1[10:0]: VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200468
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300469 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200470 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300471 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
472 /* Tempbx: SRA */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200473 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300474 Tempbx &= 0x20; /* Tempbx[5]: VRE[5] */
475 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
476 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
477 Temp2 = Temp1 & 0x7E0; /* Temp2[10:5]: VRS[10:5] */
478 Temp2 |= Tempax; /* Temp2[10:5]: VRE[10:5] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200479
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300480 Temp3 = Temp1 & 0x1F; /* Temp3[4:0]: VRS[4:0] */
481 if (Tempax < Temp3) /* VRE < VRS */
482 Temp2 |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200483
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300484 Temp2 &= 0xFF;
485 Tempax = (unsigned char) Temp2; /* Tempax: VRE[7:0] */
486 Tempax <<= 2; /* Tempax[7:0]; VRE[5:0]00 */
487 Temp1 &= 0x600; /* Temp1[10:9]: VRS[10:9] */
488 Temp1 >>= 9; /* Temp1[1:0]: VRS[10:9] */
489 Tempbx = (unsigned char) Temp1;
490 Tempax |= Tempbx; /* Tempax[7:0]: VRE[5:0]VRS[10:9] */
491 Tempax &= 0x7F;
492 /* SR3F D[7:2]->VRE D[1:0]->VRS */
493 xgifb_reg_set(pVBInfo->P3c4, 0x3F, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200494}
495
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +0300496static void XGI_SetXG27CRTC(unsigned short RefreshRateTableIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800497 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200498{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300499 unsigned short index, Tempax, Tempbx, Tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200500
Aaro Koskinena39325d2012-11-04 21:14:53 +0200501 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300502 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200503 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300504 Tempbx = Tempax; /* Tempbx: HRS[7:0] */
505 /* SR2E[7:0]->HRS */
506 xgifb_reg_set(pVBInfo->P3c4, 0x2E, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200507
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300508 /* SR0B */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200509 Tempax = XGI_CRT1Table[index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300510 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
511 Tempbx |= (Tempax << 2); /* Tempbx: HRS[9:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200512
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200513 Tempax = XGI_CRT1Table[index].CR[4]; /* CR5 HRE */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300514 Tempax &= 0x1F; /* Tempax[4:0]: HRE[4:0] */
515 Tempcx = Tempax; /* Tempcx: HRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200516
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200517 Tempax = XGI_CRT1Table[index].CR[6]; /* SRC */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300518 Tempax &= 0x04; /* Tempax[2]: HRE[5] */
519 Tempax <<= 3; /* Tempax[5]: HRE[5] */
520 Tempcx |= Tempax; /* Tempcx[5:0]: HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200521
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300522 Tempbx = Tempbx & 0x3C0; /* Tempbx[9:6]: HRS[9:6] */
523 Tempbx |= Tempcx; /* Tempbx: HRS[9:6]HRE[5:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200524
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300525 /* Tempax: CR4 HRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200526 Tempax = XGI_CRT1Table[index].CR[3];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300527 Tempax &= 0x3F; /* Tempax: HRS[5:0] */
528 if (Tempcx <= Tempax) /* HRE[5:0] < HRS[5:0] */
529 Tempbx += 0x40; /* Tempbx= Tempbx + 0x40 : HRE[9:0]*/
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200530
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200531 Tempax = XGI_CRT1Table[index].CR[5]; /* SR0B */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300532 Tempax &= 0xC0; /* Tempax[7:6]: SR0B[7:6]: HRS[9:8]*/
533 Tempax >>= 6; /* Tempax[1:0]: HRS[9:8]*/
534 Tempax |= ((Tempbx << 2) & 0xFF); /* Tempax[7:2]: HRE[5:0] */
535 /* SR2F [7:2][1:0]: HRE[5:0]HRS[9:8] */
536 xgifb_reg_set(pVBInfo->P3c4, 0x2F, Tempax);
537 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, 0xE3, 00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200538
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300539 /* CR10 VRS */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200540 Tempax = XGI_CRT1Table[index].CR[10];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300541 /* SR34[7:0]->VRS[7:0] */
542 xgifb_reg_set(pVBInfo->P3c4, 0x34, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200543
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300544 Tempcx = Tempax; /* Tempcx <= VRS[7:0] */
545 /* CR7[7][2] VRS[9][8] */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200546 Tempax = XGI_CRT1Table[index].CR[9];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300547 Tempbx = Tempax; /* Tempbx <= CR07[7:0] */
548 Tempax = Tempax & 0x04; /* Tempax[2]: CR7[2]: VRS[8] */
549 Tempax >>= 2; /* Tempax[0]: VRS[8] */
550 /* SR35[0]: VRS[8] */
551 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x01, Tempax);
552 Tempcx |= (Tempax << 8); /* Tempcx <= VRS[8:0] */
553 Tempcx |= ((Tempbx & 0x80) << 2); /* Tempcx <= VRS[9:0] */
554 /* Tempax: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200555 Tempax = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300556 Tempax &= 0x08; /* SR0A[3] VRS[10] */
557 Tempcx |= (Tempax << 7); /* Tempcx <= VRS[10:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200558
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300559 /* Tempax: CR11 VRE */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200560 Tempax = XGI_CRT1Table[index].CR[11];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300561 Tempax &= 0x0F; /* Tempax[3:0]: VRE[3:0] */
562 /* Tempbx: SR0A */
Aaro Koskinen7853bce2012-11-04 21:14:54 +0200563 Tempbx = XGI_CRT1Table[index].CR[14];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300564 Tempbx &= 0x20; /* Tempbx[5]: SR0A[5]: VRE[4] */
565 Tempbx >>= 1; /* Tempbx[4]: VRE[4] */
566 Tempax |= Tempbx; /* Tempax[4:0]: VRE[4:0] */
567 Tempbx = Tempcx; /* Tempbx: VRS[10:0] */
568 Tempbx &= 0x7E0; /* Tempbx[10:5]: VRS[10:5] */
569 Tempbx |= Tempax; /* Tempbx: VRS[10:5]VRE[4:0] */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200570
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300571 if (Tempbx <= Tempcx) /* VRE <= VRS */
572 Tempbx |= 0x20; /* VRE + 0x20 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200573
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300574 /* Tempax: Tempax[7:0]; VRE[5:0]00 */
575 Tempax = (Tempbx << 2) & 0xFF;
576 /* SR3F[7:2]:VRE[5:0] */
577 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC, Tempax);
578 Tempax = Tempcx >> 8;
579 /* SR35[2:0]:VRS[10:8] */
580 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07, Tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200581}
582
Aaro Koskinena2d08cf2011-11-27 23:03:08 +0200583static void XGI_SetXG27FPBits(struct vb_device_info *pVBInfo)
584{
585 unsigned char temp;
586
587 /* D[1:0] 01: 18bit, 00: dual 12, 10: single 24 */
588 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
589 temp = (temp & 3) << 6;
590 /* SR06[7]0: dual 12/1: single 24 [6] 18bit Dither <= 0 h/w recommend */
591 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0xc0, temp & 0x80);
592 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: 24bits */
593 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
594
595}
596
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300597static void xgifb_set_lcd(int chip_id,
598 struct vb_device_info *pVBInfo,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300599 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200600{
Peter Huewee2e544c2013-02-03 04:08:46 +0100601 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200602
Aaro Koskinen8104e322011-03-13 12:26:22 +0200603 xgifb_reg_set(pVBInfo->P3d4, 0x2E, 0x00);
604 xgifb_reg_set(pVBInfo->P3d4, 0x2F, 0x00);
605 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x00);
606 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x00);
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300607
608 if (chip_id == XG27) {
Peter Huewee2e544c2013-02-03 04:08:46 +0100609 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
610 if ((temp & 0x03) == 0) { /* dual 12 */
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300611 xgifb_reg_set(pVBInfo->P3d4, 0x46, 0x13);
612 xgifb_reg_set(pVBInfo->P3d4, 0x47, 0x13);
613 }
614 }
615
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300616 if (chip_id == XG27) {
617 XGI_SetXG27FPBits(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530618 } else {
Peter Huewee2e544c2013-02-03 04:08:46 +0100619 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
620 if (temp & 0x01) {
Aaro Koskinen105d8d02011-08-31 21:46:00 +0300621 /* 18 bits FP */
622 xgifb_reg_or(pVBInfo->P3c4, 0x06, 0x40);
623 xgifb_reg_or(pVBInfo->P3c4, 0x09, 0x40);
624 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530625 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200626
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +0200627 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x01); /* Negative blank polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200628
Aaro Koskinendc505562011-03-13 12:26:26 +0200629 xgifb_reg_and(pVBInfo->P3c4, 0x30, ~0x20); /* Hsync polarity */
630 xgifb_reg_and(pVBInfo->P3c4, 0x35, ~0x80); /* Vsync polarity */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200631
Peter Huewee2e544c2013-02-03 04:08:46 +0100632 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
633 if (temp & 0x4000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300634 /* Hsync polarity */
635 xgifb_reg_or(pVBInfo->P3c4, 0x30, 0x20);
Peter Huewee2e544c2013-02-03 04:08:46 +0100636 if (temp & 0x8000)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300637 /* Vsync polarity */
638 xgifb_reg_or(pVBInfo->P3c4, 0x35, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200639}
640
641/* --------------------------------------------------------------------- */
642/* Function : XGI_UpdateXG21CRTC */
643/* Input : */
644/* Output : CRT1 CRTC */
645/* Description : Modify CRT1 Hsync/Vsync to fix LCD mode timing */
646/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800647static void XGI_UpdateXG21CRTC(unsigned short ModeNo,
648 struct vb_device_info *pVBInfo,
649 unsigned short RefreshRateTableIndex)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200650{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300651 int index = -1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200652
Aaro Koskinendc505562011-03-13 12:26:26 +0200653 xgifb_reg_and(pVBInfo->P3d4, 0x11, 0x7F); /* Unlock CR0~7 */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300654 if (ModeNo == 0x2E &&
Aaro Koskinena39325d2012-11-04 21:14:53 +0200655 (XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC ==
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300656 RES640x480x60))
657 index = 12;
Aaro Koskinena39325d2012-11-04 21:14:53 +0200658 else if (ModeNo == 0x2E && (XGI330_RefIndex[RefreshRateTableIndex].
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800659 Ext_CRT1CRTC == RES640x480x72))
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300660 index = 13;
661 else if (ModeNo == 0x2F)
662 index = 14;
663 else if (ModeNo == 0x50)
664 index = 15;
665 else if (ModeNo == 0x59)
666 index = 16;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200667
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530668 if (index != -1) {
Aaro Koskinen8104e322011-03-13 12:26:22 +0200669 xgifb_reg_set(pVBInfo->P3d4, 0x02,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200670 XGI_UpdateCRT1Table[index].CR02);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200671 xgifb_reg_set(pVBInfo->P3d4, 0x03,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200672 XGI_UpdateCRT1Table[index].CR03);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200673 xgifb_reg_set(pVBInfo->P3d4, 0x15,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200674 XGI_UpdateCRT1Table[index].CR15);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200675 xgifb_reg_set(pVBInfo->P3d4, 0x16,
Aaro Koskinen7c5c07a2012-11-04 21:14:55 +0200676 XGI_UpdateCRT1Table[index].CR16);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530677 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200678}
679
Aaro Koskinenb053af12013-07-16 23:13:28 +0300680static void XGI_SetCRT1DE(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530681 unsigned short RefreshRateTableIndex,
682 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200683{
Bill Pemberton82d6eb52010-06-17 13:10:46 -0400684 unsigned short resindex, tempax, tempbx, tempcx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200685
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530686 unsigned char data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200687
Aaro Koskinenb3979922012-11-04 21:14:52 +0200688 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200689
Aaro Koskinenb3979922012-11-04 21:14:52 +0200690 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinene8e6c752012-11-04 21:15:00 +0200691 tempax = XGI330_ModeResInfo[resindex].HTotal;
692 tempbx = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200693
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530694 if (modeflag & HalfDCLK)
695 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200696
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300697 if (modeflag & HalfDCLK)
698 tempax = tempax << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200699
Aaro Koskinena39325d2012-11-04 21:14:53 +0200700 temp = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200701
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300702 if (temp & InterlaceMode)
703 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200704
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300705 if (modeflag & DoubleScanMode)
706 tempbx = tempbx << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200707
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530708 tempcx = 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200709
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530710 tempax /= tempcx;
711 tempax -= 1;
712 tempbx -= 1;
713 tempcx = tempax;
Peter Huewe9388ad92013-02-15 20:37:10 +0100714 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
715 data = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530716 data &= 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200717 xgifb_reg_set(pVBInfo->P3d4, 0x11, data); /* Unlock CRTC */
718 xgifb_reg_set(pVBInfo->P3d4, 0x01, (unsigned short) (tempcx & 0xff));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200719 xgifb_reg_and_or(pVBInfo->P3d4, 0x0b, ~0x0c,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530720 (unsigned short) ((tempcx & 0x0ff00) >> 10));
Aaro Koskinen8104e322011-03-13 12:26:22 +0200721 xgifb_reg_set(pVBInfo->P3d4, 0x12, (unsigned short) (tempbx & 0xff));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530722 tempax = 0;
723 tempbx = tempbx >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200724
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530725 if (tempbx & 0x01)
726 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200727
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530728 if (tempbx & 0x02)
729 tempax |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200730
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200731 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x42, tempax);
Peter Huewe9388ad92013-02-15 20:37:10 +0100732 data = xgifb_reg_get(pVBInfo->P3d4, 0x07);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530733 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200734
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530735 if (tempbx & 0x04)
736 tempax |= 0x02;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200737
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200738 xgifb_reg_and_or(pVBInfo->P3d4, 0x0a, ~0x02, tempax);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200739 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200740}
741
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800742static void XGI_SetCRT1Offset(unsigned short ModeNo,
743 unsigned short ModeIdIndex,
744 unsigned short RefreshRateTableIndex,
745 struct xgi_hw_device_info *HwDeviceExtension,
746 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200747{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530748 unsigned short temp, ah, al, temp2, i, DisplayUnit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200749
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530750 /* GetOffset */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200751 temp = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530752 temp = temp >> 8;
Aaro Koskinen224114c2012-11-04 21:14:59 +0200753 temp = XGI330_ScreenOffset[temp];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200754
Aaro Koskinena39325d2012-11-04 21:14:53 +0200755 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530756 temp2 &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200757
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530758 if (temp2)
759 temp = temp << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200760
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530761 temp2 = pVBInfo->ModeType - ModeEGA;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200762
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530763 switch (temp2) {
764 case 0:
765 temp2 = 1;
766 break;
767 case 1:
768 temp2 = 2;
769 break;
770 case 2:
771 temp2 = 4;
772 break;
773 case 3:
774 temp2 = 4;
775 break;
776 case 4:
777 temp2 = 6;
778 break;
779 case 5:
780 temp2 = 8;
781 break;
782 default:
783 break;
784 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200785
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530786 if ((ModeNo >= 0x26) && (ModeNo <= 0x28))
787 temp = temp * temp2 + temp2 / 2;
788 else
789 temp *= temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200790
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530791 /* SetOffset */
792 DisplayUnit = temp;
793 temp2 = temp;
794 temp = temp >> 8; /* ah */
795 temp &= 0x0F;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200796 i = xgifb_reg_get(pVBInfo->P3c4, 0x0E);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530797 i &= 0xF0;
798 i |= temp;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200799 xgifb_reg_set(pVBInfo->P3c4, 0x0E, i);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200800
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530801 temp = (unsigned char) temp2;
802 temp &= 0xFF; /* al */
Aaro Koskinen8104e322011-03-13 12:26:22 +0200803 xgifb_reg_set(pVBInfo->P3d4, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200804
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530805 /* SetDisplayUnit */
Aaro Koskinena39325d2012-11-04 21:14:53 +0200806 temp2 = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530807 temp2 &= InterlaceMode;
808 if (temp2)
809 DisplayUnit >>= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200810
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530811 DisplayUnit = DisplayUnit << 5;
812 ah = (DisplayUnit & 0xff00) >> 8;
813 al = DisplayUnit & 0x00ff;
814 if (al == 0)
815 ah += 1;
816 else
817 ah += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200818
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530819 if (HwDeviceExtension->jChipType >= XG20)
820 if ((ModeNo == 0x4A) | (ModeNo == 0x49))
821 ah -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200822
Aaro Koskinen8104e322011-03-13 12:26:22 +0200823 xgifb_reg_set(pVBInfo->P3c4, 0x10, ah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200824}
825
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300826static unsigned short XGI_GetVCLK2Ptr(unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200827 unsigned short RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200828 struct vb_device_info *pVBInfo)
829{
Peter Hueweef9a6b92013-02-03 04:08:43 +0100830 unsigned short VCLKIndex, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200831
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300832 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +0200833 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200834
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200835 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) { /*301b*/
836 if (pVBInfo->LCDResInfo != Panel_1024x768)
837 /* LCDXlat2VCLK */
838 VCLKIndex = VCLK108_2_315 + 5;
839 else
840 VCLKIndex = VCLK65_315 + 2; /* LCDXlat1VCLK */
841 } else if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
842 if (pVBInfo->SetFlag & RPLLDIV2XO)
843 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLKDIV2;
844 else
845 VCLKIndex = TVCLKBASE_315_25 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200846
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200847 if (pVBInfo->SetFlag & TVSimuMode) {
848 if (modeflag & Charx8Dot) {
849 VCLKIndex = TVCLKBASE_315_25 + HiTVSimuVCLK;
850 } else {
851 VCLKIndex = TVCLKBASE_315_25 + HiTVTextVCLK;
Aaro Koskinen798b4da2011-11-27 23:03:20 +0200852 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200853 }
Aaro Koskinen7ac54d02013-02-09 00:03:43 +0200854
855 /* 301lv */
856 if (pVBInfo->VBType & VB_SIS301LV) {
857 if (pVBInfo->SetFlag & RPLLDIV2XO)
858 VCLKIndex = YPbPr525iVCLK_2;
859 else
860 VCLKIndex = YPbPr525iVCLK;
861 }
862 } else if (pVBInfo->VBInfo & SetCRT2ToTV) {
863 if (pVBInfo->SetFlag & RPLLDIV2XO)
864 VCLKIndex = TVCLKBASE_315_25 + TVVCLKDIV2;
865 else
866 VCLKIndex = TVCLKBASE_315_25 + TVVCLK;
867 } else { /* for CRT2 */
868 /* di+Ext_CRTVCLK */
869 VCLKIndex = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
870 VCLKIndex &= IndexMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200871 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200872
873 return VCLKIndex;
874}
875
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300876static void XGI_SetCRT1VCLK(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800877 struct xgi_hw_device_info *HwDeviceExtension,
878 unsigned short RefreshRateTableIndex,
879 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200880{
Bill Pemberton108afbf2010-06-17 13:10:47 -0400881 unsigned char index, data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530882 unsigned short vclkindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200883
Aaro Koskinenb750f512013-05-29 23:59:05 +0300884 if ((pVBInfo->IF_DEF_LVDS == 0) &&
885 (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
886 VB_SIS302LV | VB_XGI301C)) &&
887 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300888 vclkindex = XGI_GetVCLK2Ptr(ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinenb053af12013-07-16 23:13:28 +0300889 pVBInfo);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200890 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200891 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200892 data = XGI_VBVCLKData[vclkindex].Part4_A;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200893 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200894 data = XGI_VBVCLKData[vclkindex].Part4_B;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200895 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
896 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530897 } else {
Aaro Koskinena39325d2012-11-04 21:14:53 +0200898 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen58839b02011-03-13 12:26:23 +0200899 data = xgifb_reg_get(pVBInfo->P3c4, 0x31) & 0xCF;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200900 xgifb_reg_set(pVBInfo->P3c4, 0x31, data);
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200901 xgifb_reg_set(pVBInfo->P3c4, 0x2B, XGI_VCLKData[index].SR2B);
902 xgifb_reg_set(pVBInfo->P3c4, 0x2C, XGI_VCLKData[index].SR2C);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200903 xgifb_reg_set(pVBInfo->P3c4, 0x2D, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530904 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200905
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530906 if (HwDeviceExtension->jChipType >= XG20) {
Aaro Koskinenb3979922012-11-04 21:14:52 +0200907 if (XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag &
Kenji Toyama1d7f6562011-04-23 19:36:49 +0800908 HalfDCLK) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200909 data = xgifb_reg_get(pVBInfo->P3c4, 0x2B);
Aaro Koskinen8104e322011-03-13 12:26:22 +0200910 xgifb_reg_set(pVBInfo->P3c4, 0x2B, data);
Aaro Koskinen58839b02011-03-13 12:26:23 +0200911 data = xgifb_reg_get(pVBInfo->P3c4, 0x2C);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530912 index = data;
913 index &= 0xE0;
914 data &= 0x1F;
915 data = data << 1;
916 data += 1;
917 data |= index;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200918 xgifb_reg_set(pVBInfo->P3c4, 0x2C, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530919 }
920 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200921}
922
Aaro Koskinene85f2032011-11-27 23:03:07 +0200923static void XGI_SetXG21FPBits(struct vb_device_info *pVBInfo)
924{
925 unsigned char temp;
926
927 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37); /* D[0] 1: 18bit */
928 temp = (temp & 1) << 6;
929 /* SR06[6] 18bit Dither */
930 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x40, temp);
931 /* SR09[7] enable FP output, SR09[6] 1: sigle 18bits, 0: dual 12bits */
932 xgifb_reg_and_or(pVBInfo->P3c4, 0x09, ~0xc0, temp | 0x80);
933
934}
935
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300936static void XGI_SetCRT1FIFO(struct xgi_hw_device_info *HwDeviceExtension,
937 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200938{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530939 unsigned short data;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200940
Aaro Koskinen58839b02011-03-13 12:26:23 +0200941 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530942 data &= 0xfe;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200943 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data); /* diable auto-threshold */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200944
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300945 xgifb_reg_set(pVBInfo->P3c4, 0x08, 0x34);
946 data = xgifb_reg_get(pVBInfo->P3c4, 0x09);
947 data &= 0xC0;
948 xgifb_reg_set(pVBInfo->P3c4, 0x09, data | 0x30);
949 data = xgifb_reg_get(pVBInfo->P3c4, 0x3D);
950 data |= 0x01;
951 xgifb_reg_set(pVBInfo->P3c4, 0x3D, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200952
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530953 if (HwDeviceExtension->jChipType == XG21)
954 XGI_SetXG21FPBits(pVBInfo); /* Fix SR9[7:6] can't read back */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +0200955}
956
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200957static void XGI_SetVCLKState(struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300958 unsigned short RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200959 struct vb_device_info *pVBInfo)
960{
961 unsigned short data, data2 = 0;
962 short VCLK;
963
964 unsigned char index;
965
Aaro Koskinena39325d2012-11-04 21:14:53 +0200966 index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +0300967 index &= IndexMask;
Aaro Koskinenacfe0932012-11-04 21:14:58 +0200968 VCLK = XGI_VCLKData[index].CLOCK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200969
Aaro Koskinen58839b02011-03-13 12:26:23 +0200970 data = xgifb_reg_get(pVBInfo->P3c4, 0x32);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200971 data &= 0xf3;
972 if (VCLK >= 200)
973 data |= 0x0c; /* VCLK > 200 */
974
975 if (HwDeviceExtension->jChipType >= XG20)
976 data &= ~0x04; /* 2 pixel mode */
977
Aaro Koskinen8104e322011-03-13 12:26:22 +0200978 xgifb_reg_set(pVBInfo->P3c4, 0x32, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200979
980 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinen58839b02011-03-13 12:26:23 +0200981 data = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200982 data &= 0xE7;
983 if (VCLK < 200)
984 data |= 0x10;
Aaro Koskinen8104e322011-03-13 12:26:22 +0200985 xgifb_reg_set(pVBInfo->P3c4, 0x1F, data);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200986 }
987
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200988 data2 = 0x00;
989
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200990 xgifb_reg_and_or(pVBInfo->P3c4, 0x07, 0xFC, data2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200991 if (HwDeviceExtension->jChipType >= XG27)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +0200992 xgifb_reg_and_or(pVBInfo->P3c4, 0x40, 0xFC, data2 & 0x03);
Aaro Koskinencc1e2392011-03-13 12:26:07 +0200993
994}
995
Aaro Koskinen063b9c42011-03-08 22:16:13 +0200996static void XGI_SetCRT1ModeRegs(struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +0300997 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +0530998 unsigned short RefreshRateTableIndex,
999 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001000{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301001 unsigned short data, data2, data3, infoflag = 0, modeflag, resindex,
1002 xres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001003
Aaro Koskinenb3979922012-11-04 21:14:52 +02001004 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001005 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001006
Aaro Koskinen58839b02011-03-13 12:26:23 +02001007 if (xgifb_reg_get(pVBInfo->P3d4, 0x31) & 0x01)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001008 xgifb_reg_and_or(pVBInfo->P3c4, 0x1F, 0x3F, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001009
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001010 data = infoflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301011 data2 = 0;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001012 data2 |= 0x02;
1013 data3 = pVBInfo->ModeType - ModeVGA;
1014 data3 = data3 << 2;
1015 data2 |= data3;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301016 data &= InterlaceMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001017
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301018 if (data)
1019 data2 |= 0x20;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001020
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001021 xgifb_reg_and_or(pVBInfo->P3c4, 0x06, ~0x3F, data2);
Aaro Koskinenb3979922012-11-04 21:14:52 +02001022 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001023 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001024
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301025 data = 0x0000;
1026 if (infoflag & InterlaceMode) {
1027 if (xres == 1024)
1028 data = 0x0035;
1029 else if (xres == 1280)
1030 data = 0x0048;
1031 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001032
Peter Huewe5d1c2a92013-02-03 22:54:37 +01001033 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFF, data);
1034 xgifb_reg_and_or(pVBInfo->P3d4, 0x19, 0xFC, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001035
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301036 if (modeflag & HalfDCLK)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001037 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xF7, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001038
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301039 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001040
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301041 if (modeflag & LineCompareOff)
1042 data2 |= 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001043
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001044 xgifb_reg_and_or(pVBInfo->P3c4, 0x0F, ~0x48, data2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301045 data = 0x60;
Aaro Koskinen969f7f32012-04-07 01:14:03 +03001046 data = data ^ 0x60;
1047 data = data ^ 0xA0;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001048 xgifb_reg_and_or(pVBInfo->P3c4, 0x21, 0x1F, data);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001049
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001050 XGI_SetVCLKState(HwDeviceExtension, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001051
Aaro Koskinen58839b02011-03-13 12:26:23 +02001052 data = xgifb_reg_get(pVBInfo->P3d4, 0x31);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001053
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301054 if (HwDeviceExtension->jChipType == XG27) {
1055 if (data & 0x40)
1056 data = 0x2c;
1057 else
1058 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001059 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02001060 xgifb_reg_or(pVBInfo->P3d4, 0x51, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301061 } else if (HwDeviceExtension->jChipType >= XG20) {
1062 if (data & 0x40)
1063 data = 0x33;
1064 else
1065 data = 0x73;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001066 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
1067 xgifb_reg_set(pVBInfo->P3d4, 0x51, 0x02);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301068 } else {
1069 if (data & 0x40)
1070 data = 0x2c;
1071 else
1072 data = 0x6c;
Aaro Koskinen8104e322011-03-13 12:26:22 +02001073 xgifb_reg_set(pVBInfo->P3d4, 0x52, data);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301074 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001075
1076}
1077
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001078static void XGI_WriteDAC(unsigned short dl,
1079 unsigned short ah,
1080 unsigned short al,
1081 unsigned short dh,
1082 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001083{
1084 unsigned short temp, bh, bl;
1085
1086 bh = ah;
1087 bl = al;
1088
1089 if (dl != 0) {
1090 temp = bh;
1091 bh = dh;
1092 dh = temp;
1093 if (dl == 1) {
1094 temp = bl;
1095 bl = dh;
1096 dh = temp;
1097 } else {
1098 temp = bl;
1099 bl = bh;
1100 bh = temp;
1101 }
1102 }
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001103 outb((unsigned short) dh, pVBInfo->P3c9);
1104 outb((unsigned short) bh, pVBInfo->P3c9);
1105 outb((unsigned short) bl, pVBInfo->P3c9);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001106}
1107
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03001108static void XGI_LoadDAC(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001109{
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001110 unsigned short data, data2, i, k, m, n, o, si, di, bx, dl, al, ah, dh;
1111 const unsigned short *table = XGINew_VGA_DAC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001112
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001113 outb(0xFF, pVBInfo->P3c6);
1114 outb(0x00, pVBInfo->P3c8);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001115
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001116 for (i = 0; i < 16; i++) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301117 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001118
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301119 for (k = 0; k < 3; k++) {
1120 data2 = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001121
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301122 if (data & 0x01)
1123 data2 = 0x2A;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001124
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301125 if (data & 0x02)
1126 data2 += 0x15;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001127
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02001128 outb(data2, pVBInfo->P3c9);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301129 data = data >> 2;
1130 }
1131 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001132
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001133 for (i = 16; i < 32; i++) {
1134 data = table[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001135
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001136 for (k = 0; k < 3; k++)
1137 outb(data, pVBInfo->P3c9);
1138 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001139
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001140 si = 32;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001141
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001142 for (m = 0; m < 9; m++) {
1143 di = si;
1144 bx = si + 0x04;
1145 dl = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001146
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001147 for (n = 0; n < 3; n++) {
1148 for (o = 0; o < 5; o++) {
1149 dh = table[si];
1150 ah = table[di];
1151 al = table[bx];
1152 si++;
1153 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301154 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001155
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001156 si -= 2;
1157
1158 for (o = 0; o < 3; o++) {
1159 dh = table[bx];
1160 ah = table[di];
1161 al = table[si];
1162 si--;
1163 XGI_WriteDAC(dl, ah, al, dh, pVBInfo);
1164 }
1165
1166 dl++;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301167 }
Aaro Koskinen1bb52cc2012-04-07 01:14:06 +03001168
1169 si += 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301170 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001171}
1172
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001173static void XGI_GetLVDSResInfo(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001174 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001175{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301176 unsigned short resindex, xres, yres, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001177
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001178 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001179 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001180
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001181 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001182 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001183
Aaro Koskinene8e6c752012-11-04 21:15:00 +02001184 xres = XGI330_ModeResInfo[resindex].HTotal;
1185 yres = XGI330_ModeResInfo[resindex].VTotal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001186
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001187 if (modeflag & HalfDCLK)
1188 xres = xres << 1;
1189
1190 if (modeflag & DoubleScanMode)
1191 yres = yres << 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001192
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301193 if (xres == 720)
1194 xres = 640;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001195
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301196 pVBInfo->VGAHDE = xres;
1197 pVBInfo->HDE = xres;
1198 pVBInfo->VGAVDE = yres;
1199 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001200}
1201
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001202static void const *XGI_GetLcdPtr(struct XGI330_LCDDataTablStruct const *table,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001203 unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001204 struct vb_device_info *pVBInfo)
1205{
Aaro Koskinen6c27b372012-11-04 21:14:45 +02001206 unsigned short i, tempdx, tempbx, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001207
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001208 tempbx = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001209
Aaro Koskinenb3979922012-11-04 21:14:52 +02001210 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001211
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001212 i = 0;
1213
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001214 while (table[i].PANELID != 0xff) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001215 tempdx = pVBInfo->LCDResInfo;
1216 if (tempbx & 0x0080) { /* OEMUtil */
1217 tempbx &= (~0x0080);
1218 tempdx = pVBInfo->LCDTypeInfo;
1219 }
1220
1221 if (pVBInfo->LCDInfo & EnableScalingLCD)
1222 tempdx &= (~PanelResInfo);
1223
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001224 if (table[i].PANELID == tempdx) {
1225 tempbx = table[i].MASK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001226 tempdx = pVBInfo->LCDInfo;
1227
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001228 if (modeflag & HalfDCLK)
1229 tempdx |= SetLCDLowResolution;
1230
1231 tempbx &= tempdx;
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001232 if (tempbx == table[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001233 break;
1234 }
1235 i++;
1236 }
1237
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001238 return table[i].DATAPTR;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001239}
1240
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001241static struct SiS_TVData const *XGI_GetTVPtr(unsigned short ModeIdIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001242 unsigned short RefreshRateTableIndex,
1243 struct vb_device_info *pVBInfo)
1244{
Aaro Koskinen56d276c2012-09-11 00:15:19 +03001245 unsigned short i, tempdx, tempal, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001246
Aaro Koskinenb3979922012-11-04 21:14:52 +02001247 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02001248 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT2CRTC;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001249 tempal = tempal & 0x3f;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001250 tempdx = pVBInfo->TVInfo;
1251
1252 if (pVBInfo->VBInfo & SetInSlaveMode)
1253 tempdx = tempdx | SetTVLockMode;
1254
1255 if (modeflag & HalfDCLK)
1256 tempdx = tempdx | SetTVLowResolution;
1257
1258 i = 0;
1259
Aaro Koskinen6265ee42012-09-11 00:15:20 +03001260 while (XGI_TVDataTable[i].MASK != 0xffff) {
1261 if ((tempdx & XGI_TVDataTable[i].MASK) ==
1262 XGI_TVDataTable[i].CAP)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001263 break;
1264 i++;
1265 }
1266
Aaro Koskinen18ba8662012-09-11 00:15:22 +03001267 return &XGI_TVDataTable[i].DATAPTR[tempal];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001268}
1269
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001270static void XGI_GetLVDSData(unsigned short ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001271 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001272{
Aaro Koskinen6008f872012-11-04 21:14:49 +02001273 struct SiS_LVDSData const *LCDPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001274
Aaro Koskinen6008f872012-11-04 21:14:49 +02001275 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
1276 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001277
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001278 LCDPtr = XGI_GetLcdPtr(XGI_EPLLCDDataPtr, ModeIdIndex, pVBInfo);
Aaro Koskinen6008f872012-11-04 21:14:49 +02001279 pVBInfo->VGAHT = LCDPtr->VGAHT;
1280 pVBInfo->VGAVT = LCDPtr->VGAVT;
1281 pVBInfo->HT = LCDPtr->LCDHT;
1282 pVBInfo->VT = LCDPtr->LCDVT;
1283
1284 if (pVBInfo->LCDInfo & (SetLCDtoNonExpanding | EnableScalingLCD))
1285 return;
1286
1287 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1288 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
1289 pVBInfo->HDE = 1024;
1290 pVBInfo->VDE = 768;
1291 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1292 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
1293 pVBInfo->HDE = 1280;
1294 pVBInfo->VDE = 1024;
1295 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
1296 pVBInfo->HDE = 1400;
1297 pVBInfo->VDE = 1050;
1298 } else {
1299 pVBInfo->HDE = 1600;
1300 pVBInfo->VDE = 1200;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301301 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001302}
1303
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001304static void XGI_ModCRT1Regs(unsigned short ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001305 struct xgi_hw_device_info *HwDeviceExtension,
1306 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001307{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02001308 unsigned short i;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001309 struct XGI_LVDSCRT1HDataStruct const *LCDPtr = NULL;
1310 struct XGI_LVDSCRT1VDataStruct const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001311
Peter Huewea3d675c2012-02-09 21:11:47 +01001312 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001313 LCDPtr = XGI_GetLcdPtr(xgifb_epllcd_crt1_h, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001314 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001315
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001316 for (i = 0; i < 8; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001317 pVBInfo->TimingH.data[i] = LCDPtr[0].Reg[i];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301318 }
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001319
1320 XGI_SetCRT1Timing_H(pVBInfo, HwDeviceExtension);
1321
Peter Huewea3d675c2012-02-09 21:11:47 +01001322 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001323 LCDPtr1 = XGI_GetLcdPtr(xgifb_epllcd_crt1_v, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001324 pVBInfo);
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001325 for (i = 0; i < 7; i++)
Aaro Koskinen6154e7f2012-11-04 21:14:50 +02001326 pVBInfo->TimingV.data[i] = LCDPtr1[0].Reg[i];
Aaro Koskinenaef6bc72011-08-31 21:46:15 +03001327 }
1328
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001329 XGI_SetCRT1Timing_V(ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001330}
1331
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001332static unsigned short XGI_GetLCDCapPtr(struct vb_device_info *pVBInfo)
1333{
1334 unsigned char tempal, tempah, tempbl, i;
1335
Aaro Koskinen58839b02011-03-13 12:26:23 +02001336 tempah = xgifb_reg_get(pVBInfo->P3d4, 0x36);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001337 tempal = tempah & 0x0F;
1338 tempah = tempah & 0xF0;
1339 i = 0;
1340 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1341
1342 while (tempbl != 0xFF) {
1343 if (tempbl & 0x80) { /* OEMUtil */
1344 tempal = tempah;
1345 tempbl = tempbl & ~(0x80);
1346 }
1347
1348 if (tempal == tempbl)
1349 break;
1350
1351 i++;
1352
1353 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1354 }
1355
1356 return i;
1357}
1358
1359static unsigned short XGI_GetLCDCapPtr1(struct vb_device_info *pVBInfo)
1360{
1361 unsigned short tempah, tempal, tempbl, i;
1362
1363 tempal = pVBInfo->LCDResInfo;
1364 tempah = pVBInfo->LCDTypeInfo;
1365
1366 i = 0;
1367 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1368
1369 while (tempbl != 0xFF) {
1370 if ((tempbl & 0x80) && (tempbl != 0x80)) {
1371 tempal = tempah;
1372 tempbl &= ~0x80;
1373 }
1374
1375 if (tempal == tempbl)
1376 break;
1377
1378 i++;
1379 tempbl = pVBInfo->LCDCapList[i].LCD_ID;
1380 }
1381
1382 if (tempbl == 0xFF) {
Peter Huewe255aabd2012-02-09 21:11:44 +01001383 pVBInfo->LCDResInfo = Panel_1024x768;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001384 pVBInfo->LCDTypeInfo = 0;
1385 i = 0;
1386 }
1387
1388 return i;
1389}
1390
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001391static void XGI_GetLCDSync(unsigned short *HSyncWidth,
1392 unsigned short *VSyncWidth,
1393 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001394{
1395 unsigned short Index;
1396
1397 Index = XGI_GetLCDCapPtr(pVBInfo);
1398 *HSyncWidth = pVBInfo->LCDCapList[Index].LCD_HSyncWidth;
1399 *VSyncWidth = pVBInfo->LCDCapList[Index].LCD_VSyncWidth;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001400}
1401
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001402static void XGI_SetLVDSRegs(unsigned short ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001403 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001404{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301405 unsigned short tempbx, tempax, tempcx, tempdx, push1, push2, modeflag;
1406 unsigned long temp, temp1, temp2, temp3, push3;
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02001407 struct XGI330_LCDDataDesStruct2 const *LCDPtr1 = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001408
Aaro Koskinenb3979922012-11-04 21:14:52 +02001409 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03001410 LCDPtr1 = XGI_GetLcdPtr(XGI_EPLLCDDesDataPtr, ModeIdIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001411
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001412 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
1413 push1 = tempbx;
1414 push2 = tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001415
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001416 /* GetLCDResInfo */
Peter Huewe255aabd2012-02-09 21:11:44 +01001417 if ((pVBInfo->LCDResInfo == Panel_1024x768) ||
1418 (pVBInfo->LCDResInfo == Panel_1024x768x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001419 tempax = 1024;
1420 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01001421 } else if ((pVBInfo->LCDResInfo == Panel_1280x1024) ||
1422 (pVBInfo->LCDResInfo == Panel_1280x1024x75)) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001423 tempax = 1280;
1424 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01001425 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001426 tempax = 1400;
1427 tempbx = 1050;
1428 } else {
1429 tempax = 1600;
1430 tempbx = 1200;
1431 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001432
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001433 if (pVBInfo->LCDInfo & SetLCDtoNonExpanding) {
1434 pVBInfo->HDE = tempax;
1435 pVBInfo->VDE = tempbx;
1436 pVBInfo->VGAHDE = tempax;
1437 pVBInfo->VGAVDE = tempbx;
1438 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001439
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001440 tempax = pVBInfo->HT;
1441
Peter Huewe826215d2013-02-05 00:29:46 +01001442 tempbx = LCDPtr1->LCDHDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001443
1444 tempcx = pVBInfo->HDE;
1445 tempbx = tempbx & 0x0fff;
1446 tempcx += tempbx;
1447
1448 if (tempcx >= tempax)
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001449 tempcx -= tempax;
1450
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001451 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, tempbx & 0x07);
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001452
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001453 tempcx = tempcx >> 3;
1454 tempbx = tempbx >> 3;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001455
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001456 xgifb_reg_set(pVBInfo->Part1Port, 0x16,
1457 (unsigned short) (tempbx & 0xff));
1458 xgifb_reg_set(pVBInfo->Part1Port, 0x17,
1459 (unsigned short) (tempcx & 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001460
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001461 tempax = pVBInfo->HT;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001462
Peter Huewe826215d2013-02-05 00:29:46 +01001463 tempbx = LCDPtr1->LCDHRS;
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001464
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001465 tempcx = push2;
1466
1467 if (pVBInfo->LCDInfo & EnableScalingLCD)
1468 tempcx = LCDPtr1->LCDHSync;
1469
1470 tempcx += tempbx;
1471
1472 if (tempcx >= tempax)
1473 tempcx -= tempax;
1474
1475 tempax = tempbx & 0x07;
1476 tempax = tempax >> 5;
1477 tempcx = tempcx >> 3;
1478 tempbx = tempbx >> 3;
1479
1480 tempcx &= 0x1f;
1481 tempax |= tempcx;
1482
1483 xgifb_reg_set(pVBInfo->Part1Port, 0x15, tempax);
1484 xgifb_reg_set(pVBInfo->Part1Port, 0x14,
1485 (unsigned short) (tempbx & 0xff));
1486
1487 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001488 tempbx = LCDPtr1->LCDVDES;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001489 tempcx = pVBInfo->VDE;
1490
1491 tempbx = tempbx & 0x0fff;
1492 tempcx += tempbx;
1493 if (tempcx >= tempax)
1494 tempcx -= tempax;
1495
1496 xgifb_reg_set(pVBInfo->Part1Port, 0x1b,
1497 (unsigned short) (tempbx & 0xff));
1498 xgifb_reg_set(pVBInfo->Part1Port, 0x1c,
1499 (unsigned short) (tempcx & 0xff));
1500
1501 tempbx = (tempbx >> 8) & 0x07;
1502 tempcx = (tempcx >> 8) & 0x07;
1503
1504 xgifb_reg_set(pVBInfo->Part1Port, 0x1d,
1505 (unsigned short) ((tempcx << 3)
1506 | tempbx));
1507
1508 tempax = pVBInfo->VT;
Peter Huewe826215d2013-02-05 00:29:46 +01001509 tempbx = LCDPtr1->LCDVRS;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001510
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001511 tempcx = push1;
1512
1513 if (pVBInfo->LCDInfo & EnableScalingLCD)
1514 tempcx = LCDPtr1->LCDVSync;
1515
1516 tempcx += tempbx;
1517 if (tempcx >= tempax)
1518 tempcx -= tempax;
1519
1520 xgifb_reg_set(pVBInfo->Part1Port, 0x18,
1521 (unsigned short) (tempbx & 0xff));
1522 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, ~0x0f,
1523 (unsigned short) (tempcx & 0x0f));
1524
1525 tempax = ((tempbx >> 8) & 0x07) << 3;
1526
1527 tempbx = pVBInfo->VGAVDE;
1528 if (tempbx != pVBInfo->VDE)
1529 tempax |= 0x40;
1530
Peter Huewea3d675c2012-02-09 21:11:47 +01001531 if (pVBInfo->LCDInfo & XGI_EnableLVDSDDA)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001532 tempax |= 0x40;
1533
1534 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1a, 0x07,
1535 tempax);
1536
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001537 tempbx = pVBInfo->VDE;
1538 tempax = pVBInfo->VGAVDE;
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001539
1540 temp = tempax; /* 0430 ylshieh */
1541 temp1 = (temp << 18) / tempbx;
1542
1543 tempdx = (unsigned short) ((temp << 18) % tempbx);
1544
1545 if (tempdx != 0)
1546 temp1 += 1;
1547
1548 temp2 = temp1;
1549 push3 = temp2;
1550
1551 xgifb_reg_set(pVBInfo->Part1Port, 0x37,
1552 (unsigned short) (temp2 & 0xff));
1553 xgifb_reg_set(pVBInfo->Part1Port, 0x36,
1554 (unsigned short) ((temp2 >> 8) & 0xff));
1555
1556 tempbx = (unsigned short) (temp2 >> 16);
1557 tempax = tempbx & 0x03;
1558
1559 tempbx = pVBInfo->VGAVDE;
1560 if (tempbx == pVBInfo->VDE)
1561 tempax |= 0x04;
1562
1563 xgifb_reg_set(pVBInfo->Part1Port, 0x35, tempax);
1564
1565 if (pVBInfo->VBType & VB_XGI301C) {
1566 temp2 = push3;
1567 xgifb_reg_set(pVBInfo->Part4Port,
1568 0x3c,
1569 (unsigned short) (temp2 & 0xff));
1570 xgifb_reg_set(pVBInfo->Part4Port,
1571 0x3b,
1572 (unsigned short) ((temp2 >> 8) &
1573 0xff));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001574 tempbx = (unsigned short) (temp2 >> 16);
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001575 xgifb_reg_and_or(pVBInfo->Part4Port, 0x3a,
1576 ~0xc0,
1577 (unsigned short) ((tempbx &
1578 0xff) << 6));
Aaro Koskinena35cd0b2011-08-31 21:45:56 +03001579
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001580 tempcx = pVBInfo->VGAVDE;
1581 if (tempcx == pVBInfo->VDE)
1582 xgifb_reg_and_or(pVBInfo->Part4Port,
1583 0x30, ~0x0c, 0x00);
1584 else
1585 xgifb_reg_and_or(pVBInfo->Part4Port,
1586 0x30, ~0x0c, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301587 }
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001588
1589 tempcx = pVBInfo->VGAHDE;
1590 tempbx = pVBInfo->HDE;
1591
1592 temp1 = tempcx << 16;
1593
1594 tempax = (unsigned short) (temp1 / tempbx);
1595
1596 if ((tempbx & 0xffff) == (tempcx & 0xffff))
1597 tempax = 65535;
1598
1599 temp3 = tempax;
1600 temp1 = pVBInfo->VGAHDE << 16;
1601
1602 temp1 /= temp3;
1603 temp3 = temp3 << 16;
1604 temp1 -= 1;
1605
1606 temp3 = (temp3 & 0xffff0000) + (temp1 & 0xffff);
1607
1608 tempax = (unsigned short) (temp3 & 0xff);
1609 xgifb_reg_set(pVBInfo->Part1Port, 0x1f, tempax);
1610
1611 temp1 = pVBInfo->VGAVDE << 18;
1612 temp1 = temp1 / push3;
1613 tempbx = (unsigned short) (temp1 & 0xffff);
1614
Peter Huewe255aabd2012-02-09 21:11:44 +01001615 if (pVBInfo->LCDResInfo == Panel_1024x768)
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03001616 tempbx -= 1;
1617
1618 tempax = ((tempbx >> 8) & 0xff) << 3;
1619 tempax |= (unsigned short) ((temp3 >> 8) & 0x07);
1620 xgifb_reg_set(pVBInfo->Part1Port, 0x20,
1621 (unsigned short) (tempax & 0xff));
1622 xgifb_reg_set(pVBInfo->Part1Port, 0x21,
1623 (unsigned short) (tempbx & 0xff));
1624
1625 temp3 = temp3 >> 16;
1626
1627 if (modeflag & HalfDCLK)
1628 temp3 = temp3 >> 1;
1629
1630 xgifb_reg_set(pVBInfo->Part1Port, 0x22,
1631 (unsigned short) ((temp3 >> 8) & 0xff));
1632 xgifb_reg_set(pVBInfo->Part1Port, 0x23,
1633 (unsigned short) (temp3 & 0xff));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001634}
1635
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001636/* --------------------------------------------------------------------- */
1637/* Function : XGI_GETLCDVCLKPtr */
1638/* Input : */
1639/* Output : al -> VCLK Index */
1640/* Description : */
1641/* --------------------------------------------------------------------- */
1642static void XGI_GetLCDVCLKPtr(unsigned char *di_0, unsigned char *di_1,
1643 struct vb_device_info *pVBInfo)
1644{
1645 unsigned short index;
1646
Peter Huewea3d675c2012-02-09 21:11:47 +01001647 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001648 index = XGI_GetLCDCapPtr1(pVBInfo);
1649
1650 if (pVBInfo->VBInfo & SetCRT2ToLCD) { /* LCDB */
1651 *di_0 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData1;
1652 *di_1 = pVBInfo->LCDCapList[index].LCUCHAR_VCLKData2;
1653 } else { /* LCDA */
1654 *di_0 = pVBInfo->LCDCapList[index].LCDA_VCLKData1;
1655 *di_1 = pVBInfo->LCDCapList[index].LCDA_VCLKData2;
1656 }
1657 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001658}
1659
1660static unsigned char XGI_GetVCLKPtr(unsigned short RefreshRateTableIndex,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001661 unsigned short ModeIdIndex, struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001662{
1663
1664 unsigned short index, modeflag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001665 unsigned char tempal;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001666
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03001667 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02001668 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001669
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001670 if ((pVBInfo->SetFlag & ProgrammingCRT2) &&
1671 (!(pVBInfo->LCDInfo & EnableScalingLCD))) { /* {LCDA/LCDB} */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001672 index = XGI_GetLCDCapPtr(pVBInfo);
1673 tempal = pVBInfo->LCDCapList[index].LCD_VCLK;
1674
Peter Huewea3d675c2012-02-09 21:11:47 +01001675 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001676 return tempal;
1677
1678 /* {TV} */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001679 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01001680 (VB_SIS301B |
1681 VB_SIS302B |
1682 VB_SIS301LV |
1683 VB_SIS302LV |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001684 VB_XGI301C)) {
Peter Huewe599801f2012-02-09 21:11:45 +01001685 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001686 tempal = TVCLKBASE_315 + HiTVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001687 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001688 tempal = TVCLKBASE_315 + HiTVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001689 if (pVBInfo->TVInfo & TVSimuMode) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001690 tempal = TVCLKBASE_315 + HiTVSimuVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001691 if (!(modeflag & Charx8Dot))
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001692 tempal = TVCLKBASE_315 +
1693 HiTVTextVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001694
1695 }
1696 return tempal;
1697 }
1698
Peter Huewe599801f2012-02-09 21:11:45 +01001699 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Peter Huewea3d675c2012-02-09 21:11:47 +01001700 tempal = XGI_YPbPr750pVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001701 return tempal;
1702 }
1703
Peter Huewe599801f2012-02-09 21:11:45 +01001704 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001705 tempal = YPbPr525pVCLK;
1706 return tempal;
1707 }
1708
1709 tempal = NTSC1024VCLK;
1710
1711 if (!(pVBInfo->TVInfo & NTSC1024x768)) {
Peter Hueweccc8cb22012-02-09 21:11:48 +01001712 tempal = TVCLKBASE_315 + TVVCLKDIV2;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001713 if (!(pVBInfo->TVInfo & RPLLDIV2XO))
Peter Hueweccc8cb22012-02-09 21:11:48 +01001714 tempal = TVCLKBASE_315 + TVVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001715 }
1716
1717 if (pVBInfo->VBInfo & SetCRT2ToTV)
1718 return tempal;
1719 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001720 } /* {End of VB} */
1721
Peter Huewe516354e2013-02-15 20:37:11 +01001722 inb((pVBInfo->P3ca + 0x02));
Aaro Koskinena39325d2012-11-04 21:14:53 +02001723 tempal = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRTVCLK;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001724 return tempal;
1725}
1726
1727static void XGI_GetVCLKLen(unsigned char tempal, unsigned char *di_0,
1728 unsigned char *di_1, struct vb_device_info *pVBInfo)
1729{
Peter Huewe6896b942012-02-09 21:11:46 +01001730 if (pVBInfo->VBType & (VB_SIS301 | VB_SIS301B | VB_SIS302B
1731 | VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02001732 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
1733 (pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinene8cb03d2012-09-11 00:15:31 +03001734 *di_0 = XGI_VBVCLKData[tempal].Part4_A;
Aaro Koskinena7e46d8b2012-09-11 00:15:32 +03001735 *di_1 = XGI_VBVCLKData[tempal].Part4_B;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02001736 }
1737 } else {
1738 *di_0 = XGI_VCLKData[tempal].SR2B;
1739 *di_1 = XGI_VCLKData[tempal].SR2C;
1740 }
1741}
1742
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001743static void XGI_SetCRT2ECLK(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301744 unsigned short RefreshRateTableIndex,
1745 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001746{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301747 unsigned char di_0, di_1, tempal;
1748 int i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001749
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001750 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301751 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
1752 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001753
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301754 for (i = 0; i < 4; i++) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001755 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, ~0x30,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301756 (unsigned short) (0x10 * i));
Peter Huewea3d675c2012-02-09 21:11:47 +01001757 if ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301758 && (!(pVBInfo->VBInfo & SetInSlaveMode))) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001759 xgifb_reg_set(pVBInfo->P3c4, 0x2e, di_0);
1760 xgifb_reg_set(pVBInfo->P3c4, 0x2f, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301761 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02001762 xgifb_reg_set(pVBInfo->P3c4, 0x2b, di_0);
1763 xgifb_reg_set(pVBInfo->P3c4, 0x2c, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301764 }
1765 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001766}
1767
Aaro Koskinenb053af12013-07-16 23:13:28 +03001768static void XGI_UpdateModeInfo(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001769{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301770 unsigned short tempcl, tempch, temp, tempbl, tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001771
Peter Huewe6896b942012-02-09 21:11:46 +01001772 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
1773 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301774 tempcl = 0;
1775 tempch = 0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02001776 temp = xgifb_reg_get(pVBInfo->P3c4, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001777
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301778 if (!(temp & 0x20)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001779 temp = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301780 if (temp & 0x80) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001781 temp = xgifb_reg_get(pVBInfo->P3d4, 0x53);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301782 if (!(temp & 0x40))
1783 tempcl |= ActiveCRT1;
1784 }
1785 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001786
Aaro Koskinen58839b02011-03-13 12:26:23 +02001787 temp = xgifb_reg_get(pVBInfo->Part1Port, 0x2e);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301788 temp &= 0x0f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001789
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301790 if (!(temp == 0x08)) {
Miguel Gómez949eb0a2012-07-06 12:40:36 +02001791 /* Check ChannelA */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001792 tempax = xgifb_reg_get(pVBInfo->Part1Port, 0x13);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301793 if (tempax & 0x04)
1794 tempcl = tempcl | ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001795
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301796 temp &= 0x05;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001797
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301798 if (!(tempcl & ActiveLCD))
1799 if (temp == 0x01)
1800 tempcl |= ActiveCRT2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001801
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301802 if (temp == 0x04)
1803 tempcl |= ActiveLCD;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001804
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301805 if (temp == 0x05) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001806 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001807
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301808 if (!(temp & 0x08))
1809 tempch |= ActiveAVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001810
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301811 if (!(temp & 0x04))
1812 tempch |= ActiveSVideo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001813
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301814 if (temp & 0x02)
1815 tempch |= ActiveSCART;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001816
Peter Huewe599801f2012-02-09 21:11:45 +01001817 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301818 if (temp & 0x01)
1819 tempch |= ActiveHiTV;
1820 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001821
Peter Huewe599801f2012-02-09 21:11:45 +01001822 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02001823 temp = xgifb_reg_get(
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301824 pVBInfo->Part2Port,
1825 0x4d);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001826
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301827 if (temp & 0x10)
1828 tempch |= ActiveYPbPr;
1829 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001830
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301831 if (tempch != 0)
1832 tempcl |= ActiveTV;
1833 }
1834 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001835
Aaro Koskinen58839b02011-03-13 12:26:23 +02001836 temp = xgifb_reg_get(pVBInfo->P3d4, 0x3d);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301837 if (tempcl & ActiveLCD) {
1838 if ((pVBInfo->SetFlag & ReserveTVOption)) {
1839 if (temp & ActiveTV)
1840 tempcl |= ActiveTV;
1841 }
1842 }
1843 temp = tempcl;
Peter Huewea3d675c2012-02-09 21:11:47 +01001844 tempbl = ~XGI_ModeSwitchStatus;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02001845 xgifb_reg_and_or(pVBInfo->P3d4, 0x3d, tempbl, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001846
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301847 if (!(pVBInfo->SetFlag & ReserveTVOption))
Aaro Koskinen8104e322011-03-13 12:26:22 +02001848 xgifb_reg_set(pVBInfo->P3d4, 0x3e, tempch);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301849 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001850}
1851
Bill Pemberton80adad82010-06-17 13:10:51 -04001852void XGI_GetVBType(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001853{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301854 unsigned short flag, tempbx, tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001855
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001856 tempbx = VB_SIS302B;
1857 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x00);
1858 if (flag == 0x02)
1859 goto finish;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001860
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001861 tempbx = VB_SIS301;
1862 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x01);
1863 if (flag < 0xB0)
1864 goto finish;
1865
1866 tempbx = VB_SIS301B;
1867 if (flag < 0xC0)
1868 goto bigger_than_0xB0;
1869
1870 tempbx = VB_XGI301C;
1871 if (flag < 0xD0)
1872 goto bigger_than_0xB0;
1873
1874 tempbx = VB_SIS301LV;
1875 if (flag < 0xE0)
1876 goto bigger_than_0xB0;
1877
1878 tempbx = VB_SIS302LV;
1879 tempah = xgifb_reg_get(pVBInfo->Part4Port, 0x39);
1880 if (tempah != 0xFF)
1881 tempbx = VB_XGI301C;
1882
1883bigger_than_0xB0:
1884 if (tempbx & (VB_SIS301B | VB_SIS302B)) {
1885 flag = xgifb_reg_get(pVBInfo->Part4Port, 0x23);
1886 if (!(flag & 0x02))
1887 tempbx = tempbx | VB_NoLCD;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301888 }
Miguel Gómez7eec23a2012-07-06 12:40:47 +02001889
1890finish:
1891 pVBInfo->VBType = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001892}
1893
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03001894static void XGI_GetVBInfo(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301895 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001896{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301897 unsigned short tempax, push, tempbx, temp, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001898
Aaro Koskinenb3979922012-11-04 21:14:52 +02001899 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301900 pVBInfo->SetFlag = 0;
Peter Huewe6896b942012-02-09 21:11:46 +01001901 pVBInfo->ModeType = modeflag & ModeTypeMask;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301902 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001903
Miguel Gómezf9317352012-07-06 12:40:48 +02001904 if (!(pVBInfo->VBType & 0xFFFF))
1905 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001906
Miguel Gómezf9317352012-07-06 12:40:48 +02001907 /* Check Display Device */
1908 temp = xgifb_reg_get(pVBInfo->P3d4, 0x30);
1909 tempbx = tempbx | temp;
1910 temp = xgifb_reg_get(pVBInfo->P3d4, 0x31);
1911 push = temp;
1912 push = push << 8;
1913 tempax = temp << 8;
1914 tempbx = tempbx | tempax;
1915 temp = (SetCRT2ToDualEdge | SetCRT2ToYPbPr525750 | XGI_SetCRT2ToLCDA
1916 | SetInSlaveMode | DisableCRT2Display);
1917 temp = 0xFFFF ^ temp;
1918 tempbx &= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001919
Miguel Gómezf9317352012-07-06 12:40:48 +02001920 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001921
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001922 if (pVBInfo->VBType & (VB_SIS302B | VB_SIS301LV | VB_SIS302LV |
1923 VB_XGI301C)) {
1924 if (temp & EnableDualEdge) {
1925 tempbx |= SetCRT2ToDualEdge;
1926 if (temp & SetToLCDA)
1927 tempbx |= XGI_SetCRT2ToLCDA;
Miguel Gómezf9317352012-07-06 12:40:48 +02001928 }
1929 }
1930
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03001931 if (pVBInfo->VBType & (VB_SIS301LV|VB_SIS302LV|VB_XGI301C)) {
1932 if (temp & SetYPbPr) {
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001933 /* shampoo add for new scratch */
1934 temp = xgifb_reg_get(pVBInfo->P3d4, 0x35);
1935 temp &= YPbPrMode;
1936 tempbx |= SetCRT2ToHiVision;
Miguel Gómezf9317352012-07-06 12:40:48 +02001937
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001938 if (temp != YPbPrMode1080i) {
1939 tempbx &= (~SetCRT2ToHiVision);
1940 tempbx |= SetCRT2ToYPbPr525750;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301941 }
1942 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001943 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001944
Miguel Gómezf9317352012-07-06 12:40:48 +02001945 tempax = push; /* restore CR31 */
1946
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001947 temp = 0x09FC;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001948
Miguel Gómezf9317352012-07-06 12:40:48 +02001949 if (!(tempbx & temp)) {
1950 tempax |= DisableCRT2Display;
1951 tempbx = 0;
1952 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001953
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03001954 if (!(pVBInfo->VBType & VB_NoLCD)) {
1955 if (tempbx & XGI_SetCRT2ToLCDA) {
1956 if (tempbx & SetSimuScanMode)
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001957 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03001958 SwitchCRT2));
1959 else
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001960 tempbx &= (~(SetCRT2ToLCD | SetCRT2ToRAMDAC |
1961 SetCRT2ToTV | SwitchCRT2));
Miguel Gómezf9317352012-07-06 12:40:48 +02001962 }
1963 }
1964
1965 /* shampoo add */
1966 /* for driver abnormal */
1967 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode))) {
Aaro Koskinenee768752013-05-29 23:59:16 +03001968 if (tempbx & SetCRT2ToRAMDAC) {
1969 tempbx &= (0xFF00 | SetCRT2ToRAMDAC |
1970 SwitchCRT2 | SetSimuScanMode);
1971 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301972 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001973 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001974
Miguel Gómezf9317352012-07-06 12:40:48 +02001975 if (!(pVBInfo->VBType & VB_NoLCD)) {
1976 if (tempbx & SetCRT2ToLCD) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001977 tempbx &= (0xFF00 | SetCRT2ToLCD | SwitchCRT2 |
Kenji Toyama1d7f6562011-04-23 19:36:49 +08001978 SetSimuScanMode);
Peter Huewe599801f2012-02-09 21:11:45 +01001979 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05301980 }
Miguel Gómezf9317352012-07-06 12:40:48 +02001981 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001982
Miguel Gómezf9317352012-07-06 12:40:48 +02001983 if (tempbx & SetCRT2ToSCART) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02001984 tempbx &= (0xFF00 | SetCRT2ToSCART | SwitchCRT2 |
Miguel Gómezf9317352012-07-06 12:40:48 +02001985 SetSimuScanMode);
1986 tempbx &= (0x00FF | (~SetCRT2ToYPbPr525750));
1987 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001988
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03001989 if (tempbx & SetCRT2ToYPbPr525750)
1990 tempbx &= (0xFF00 | SwitchCRT2 | SetSimuScanMode);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001991
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03001992 if (tempbx & SetCRT2ToHiVision)
1993 tempbx &= (0xFF00 | SetCRT2ToHiVision | SwitchCRT2 |
1994 SetSimuScanMode);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02001995
Miguel Gómezf9317352012-07-06 12:40:48 +02001996 if (tempax & DisableCRT2Display) { /* Set Display Device Info */
1997 if (!(tempbx & (SwitchCRT2 | SetSimuScanMode)))
1998 tempbx = DisableCRT2Display;
1999 }
2000
2001 if (!(tempbx & DisableCRT2Display)) {
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002002 if ((!(tempbx & DriverMode)) || (!(modeflag & CRT2Mode))) {
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03002003 if (!(tempbx & XGI_SetCRT2ToLCDA))
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002004 tempbx |= (SetInSlaveMode | SetSimuScanMode);
Miguel Gómezf9317352012-07-06 12:40:48 +02002005 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002006
Miguel Gómezf9317352012-07-06 12:40:48 +02002007 /* LCD+TV can't support in slave mode
2008 * (Force LCDA+TV->LCDB) */
Aaro Koskinen1b149ed2013-02-09 00:03:44 +02002009 if ((tempbx & SetInSlaveMode) && (tempbx & XGI_SetCRT2ToLCDA)) {
2010 tempbx ^= (SetCRT2ToLCD | XGI_SetCRT2ToLCDA |
Miguel Gómezf9317352012-07-06 12:40:48 +02002011 SetCRT2ToDualEdge);
2012 pVBInfo->SetFlag |= ReserveTVOption;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302013 }
2014 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002015
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302016 pVBInfo->VBInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002017}
2018
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002019static void XGI_GetTVInfo(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302020 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002021{
Peter Huewe5fc699f2013-02-03 04:08:45 +01002022 unsigned short tempbx = 0, resinfo = 0, modeflag, index1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002023
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302024 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002025 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2026 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002027
Peter Huewe5fc699f2013-02-03 04:08:45 +01002028 tempbx = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2029 if (tempbx & TVSetPAL) {
2030 tempbx &= (SetCHTVOverScan |
2031 TVSetPALM |
2032 TVSetPALN |
2033 TVSetPAL);
2034 if (tempbx & TVSetPALM)
2035 /* set to NTSC if PAL-M */
2036 tempbx &= ~TVSetPAL;
2037 } else
2038 tempbx &= (SetCHTVOverScan |
2039 TVSetNTSCJ |
2040 TVSetPAL);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002041
Aaro Koskinena8b35292013-02-09 00:03:45 +02002042 if (pVBInfo->VBInfo & SetCRT2ToSCART)
2043 tempbx |= TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002044
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002045 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2046 index1 = xgifb_reg_get(pVBInfo->P3d4, 0x35);
2047 index1 &= YPbPrMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002048
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002049 if (index1 == YPbPrMode525i)
2050 tempbx |= TVSetYPbPr525i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002051
Aaro Koskinena4ce0e72013-05-29 23:59:14 +03002052 if (index1 == YPbPrMode525p)
2053 tempbx = tempbx | TVSetYPbPr525p;
2054 if (index1 == YPbPrMode750p)
2055 tempbx = tempbx | TVSetYPbPr750p;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302056 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002057
Aaro Koskinenaee0ac92013-05-29 23:59:15 +03002058 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
2059 tempbx = tempbx | TVSetHiVision | TVSetPAL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002060
Aaro Koskinena8b35292013-02-09 00:03:45 +02002061 if ((pVBInfo->VBInfo & SetInSlaveMode) &&
2062 (!(pVBInfo->VBInfo & SetNotSimuMode)))
2063 tempbx |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002064
Aaro Koskinena8b35292013-02-09 00:03:45 +02002065 if (!(tempbx & TVSetPAL) && (modeflag > 13) && (resinfo == 8))
2066 /* NTSC 1024x768, */
2067 tempbx |= NTSC1024x768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002068
Aaro Koskinena8b35292013-02-09 00:03:45 +02002069 tempbx |= RPLLDIV2XO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002070
Aaro Koskinena8b35292013-02-09 00:03:45 +02002071 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
2072 if (pVBInfo->VBInfo & SetInSlaveMode)
2073 tempbx &= (~RPLLDIV2XO);
2074 } else if (tempbx & (TVSetYPbPr525p | TVSetYPbPr750p)) {
2075 tempbx &= (~RPLLDIV2XO);
2076 } else if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B |
2077 VB_SIS301LV | VB_SIS302LV |
2078 VB_XGI301C))) {
2079 if (tempbx & TVSimuMode)
2080 tempbx &= (~RPLLDIV2XO);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302081 }
2082 }
2083 pVBInfo->TVInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002084}
2085
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002086static unsigned char XGI_GetLCDInfo(unsigned short ModeIdIndex,
2087 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002088{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002089 unsigned short temp, tempax, tempbx, resinfo = 0, LCDIdIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002090
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302091 pVBInfo->LCDResInfo = 0;
2092 pVBInfo->LCDTypeInfo = 0;
2093 pVBInfo->LCDInfo = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002094
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002095 /* si+Ext_ResInfo // */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002096 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinen58839b02011-03-13 12:26:23 +02002097 temp = xgifb_reg_get(pVBInfo->P3d4, 0x36); /* Get LCD Res.Info */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302098 tempbx = temp & 0x0F;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002099
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302100 if (tempbx == 0)
Peter Huewe255aabd2012-02-09 21:11:44 +01002101 tempbx = Panel_1024x768; /* default */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002102
Miguel Gómez949eb0a2012-07-06 12:40:36 +02002103 /* LCD75 */
Peter Huewe255aabd2012-02-09 21:11:44 +01002104 if ((tempbx == Panel_1024x768) || (tempbx == Panel_1280x1024)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302105 if (pVBInfo->VBInfo & DriverMode) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02002106 tempax = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Peter Huewea3d675c2012-02-09 21:11:47 +01002107 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302108 tempax &= 0x0F;
2109 else
2110 tempax = tempax >> 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002111
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302112 if ((resinfo == 6) || (resinfo == 9)) {
2113 if (tempax >= 3)
2114 tempbx |= PanelRef75Hz;
2115 } else if ((resinfo == 7) || (resinfo == 8)) {
2116 if (tempax >= 4)
2117 tempbx |= PanelRef75Hz;
2118 }
2119 }
2120 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002121
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302122 pVBInfo->LCDResInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002123
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302124 /* End of LCD75 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002125
Peter Huewea3d675c2012-02-09 21:11:47 +01002126 if (!(pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302127 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002128
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302129 tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002130
Aaro Koskinen58839b02011-03-13 12:26:23 +02002131 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002132
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302133 temp &= (ScalingLCD | LCDNonExpanding | LCDSyncBit | SetPWDEnable);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002134
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302135 tempbx |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002136
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302137 LCDIdIndex = XGI_GetLCDCapPtr1(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002138
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302139 tempax = pVBInfo->LCDCapList[LCDIdIndex].LCD_Capability;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002140
Aaro Koskinen718e7152013-02-09 00:03:46 +02002141 if (((pVBInfo->VBType & VB_SIS302LV) ||
2142 (pVBInfo->VBType & VB_XGI301C)) && (tempax & XGI_LCDDualLink))
2143 tempbx |= SetLCDDualLink;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002144
Aaro Koskinen718e7152013-02-09 00:03:46 +02002145 if ((pVBInfo->LCDResInfo == Panel_1400x1050) &&
2146 (pVBInfo->VBInfo & SetCRT2ToLCD) && (resinfo == 9) &&
2147 (!(tempbx & EnableScalingLCD)))
2148 /*
2149 * set to center in 1280x1024 LCDB
2150 * for Panel_1400x1050
2151 */
2152 tempbx |= SetLCDtoNonExpanding;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002153
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302154 if (pVBInfo->VBInfo & SetInSlaveMode) {
2155 if (pVBInfo->VBInfo & SetNotSimuMode)
Peter Huewea3d675c2012-02-09 21:11:47 +01002156 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302157 } else {
Peter Huewea3d675c2012-02-09 21:11:47 +01002158 tempbx |= XGI_LCDVESATiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302159 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002160
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302161 pVBInfo->LCDInfo = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002162
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302163 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002164}
2165
Bill Pemberton108afbf2010-06-17 13:10:47 -04002166unsigned char XGI_SearchModeID(unsigned short ModeNo,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302167 unsigned short *ModeIdIndex, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002168{
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002169 for (*ModeIdIndex = 0;; (*ModeIdIndex)++) {
Aaro Koskinenb3979922012-11-04 21:14:52 +02002170 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == ModeNo)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002171 break;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002172 if (XGI330_EModeIDTable[*ModeIdIndex].Ext_ModeID == 0xFF)
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002173 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302174 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002175
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302176 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002177}
2178
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002179static unsigned char XG21GPIODataTransfer(unsigned char ujDate)
2180{
2181 unsigned char ujRet = 0;
2182 unsigned char i = 0;
2183
2184 for (i = 0; i < 8; i++) {
2185 ujRet = ujRet << 1;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002186 ujRet |= (ujDate >> i) & 1;
2187 }
2188
2189 return ujRet;
2190}
2191
2192/*----------------------------------------------------------------------------*/
2193/* output */
2194/* bl[5] : LVDS signal */
2195/* bl[1] : LVDS backlight */
2196/* bl[0] : LVDS VDD */
2197/*----------------------------------------------------------------------------*/
2198static unsigned char XGI_XG21GetPSCValue(struct vb_device_info *pVBInfo)
2199{
2200 unsigned char CR4A, temp;
2201
Aaro Koskinen58839b02011-03-13 12:26:23 +02002202 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002203 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x23); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002204
Aaro Koskinen58839b02011-03-13 12:26:23 +02002205 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002206
2207 temp = XG21GPIODataTransfer(temp);
2208 temp &= 0x23;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002209 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002210 return temp;
2211}
2212
2213/*----------------------------------------------------------------------------*/
2214/* output */
2215/* bl[5] : LVDS signal */
2216/* bl[1] : LVDS backlight */
2217/* bl[0] : LVDS VDD */
2218/*----------------------------------------------------------------------------*/
2219static unsigned char XGI_XG27GetPSCValue(struct vb_device_info *pVBInfo)
2220{
2221 unsigned char CR4A, CRB4, temp;
2222
Aaro Koskinen58839b02011-03-13 12:26:23 +02002223 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
Aaro Koskinendc505562011-03-13 12:26:26 +02002224 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~0x0C); /* enable GPIO write */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002225
Aaro Koskinen58839b02011-03-13 12:26:23 +02002226 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002227
2228 temp &= 0x0C;
2229 temp >>= 2;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002230 xgifb_reg_set(pVBInfo->P3d4, 0x4A, CR4A);
Aaro Koskinen58839b02011-03-13 12:26:23 +02002231 CRB4 = xgifb_reg_get(pVBInfo->P3d4, 0xB4);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002232 temp |= ((CRB4 & 0x04) << 3);
2233 return temp;
2234}
2235
Aaro Koskinen0ebf5382011-11-27 23:03:09 +02002236/*----------------------------------------------------------------------------*/
2237/* input */
2238/* bl[5] : 1;LVDS signal on */
2239/* bl[1] : 1;LVDS backlight on */
2240/* bl[0] : 1:LVDS VDD on */
2241/* bh: 100000b : clear bit 5, to set bit5 */
2242/* 000010b : clear bit 1, to set bit1 */
2243/* 000001b : clear bit 0, to set bit0 */
2244/*----------------------------------------------------------------------------*/
2245static void XGI_XG21BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2246 struct vb_device_info *pVBInfo)
2247{
2248 unsigned char CR4A, temp;
2249
2250 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2251 tempbh &= 0x23;
2252 tempbl &= 0x23;
2253 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2254
2255 if (tempbh & 0x20) {
2256 temp = (tempbl >> 4) & 0x02;
2257
2258 /* CR B4[1] */
2259 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2260
2261 }
2262
2263 temp = xgifb_reg_get(pVBInfo->P3d4, 0x48);
2264
2265 temp = XG21GPIODataTransfer(temp);
2266 temp &= ~tempbh;
2267 temp |= tempbl;
2268 xgifb_reg_set(pVBInfo->P3d4, 0x48, temp);
2269}
2270
Aaro Koskinen776115a2011-11-27 23:03:10 +02002271static void XGI_XG27BLSignalVDD(unsigned short tempbh, unsigned short tempbl,
2272 struct vb_device_info *pVBInfo)
2273{
2274 unsigned char CR4A, temp;
2275 unsigned short tempbh0, tempbl0;
2276
2277 tempbh0 = tempbh;
2278 tempbl0 = tempbl;
2279 tempbh0 &= 0x20;
2280 tempbl0 &= 0x20;
2281 tempbh0 >>= 3;
2282 tempbl0 >>= 3;
2283
2284 if (tempbh & 0x20) {
2285 temp = (tempbl >> 4) & 0x02;
2286
2287 /* CR B4[1] */
2288 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~0x02, temp);
2289
2290 }
2291 xgifb_reg_and_or(pVBInfo->P3d4, 0xB4, ~tempbh0, tempbl0);
2292
2293 CR4A = xgifb_reg_get(pVBInfo->P3d4, 0x4A);
2294 tempbh &= 0x03;
2295 tempbl &= 0x03;
2296 tempbh <<= 2;
2297 tempbl <<= 2; /* GPIOC,GPIOD */
2298 xgifb_reg_and(pVBInfo->P3d4, 0x4A, ~tempbh); /* enable GPIO write */
2299 xgifb_reg_and_or(pVBInfo->P3d4, 0x48, ~tempbh, tempbl);
2300}
2301
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002302static void XGI_DisplayOn(struct xgifb_video_info *xgifb_info,
2303 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302304 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002305{
2306
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002307 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302308 if (pXGIHWDE->jChipType == XG21) {
2309 if (pVBInfo->IF_DEF_LVDS == 1) {
2310 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002311 /* LVDS VDD on */
2312 XGI_XG21BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002313 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302314 }
2315 if (!(XGI_XG21GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002316 /* LVDS signal on */
2317 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002318 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002319 /* LVDS backlight on */
2320 XGI_XG21BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302321 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002322 /* DVO/DVI signal on */
2323 XGI_XG21BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302324 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002325
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302326 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002327
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302328 if (pXGIHWDE->jChipType == XG27) {
2329 if (pVBInfo->IF_DEF_LVDS == 1) {
2330 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x1)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002331 /* LVDS VDD on */
2332 XGI_XG27BLSignalVDD(0x01, 0x01, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002333 mdelay(xgifb_info->lvds_data.PSC_S2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302334 }
2335 if (!(XGI_XG27GetPSCValue(pVBInfo) & 0x20))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002336 /* LVDS signal on */
2337 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002338 mdelay(xgifb_info->lvds_data.PSC_S3);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002339 /* LVDS backlight on */
2340 XGI_XG27BLSignalVDD(0x02, 0x02, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302341 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002342 /* DVO/DVI signal on */
2343 XGI_XG27BLSignalVDD(0x20, 0x20, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302344 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002345
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302346 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002347}
2348
Aaro Koskinenfab04b92011-12-06 00:10:45 +02002349void XGI_DisplayOff(struct xgifb_video_info *xgifb_info,
2350 struct xgi_hw_device_info *pXGIHWDE,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302351 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002352{
2353
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302354 if (pXGIHWDE->jChipType == XG21) {
2355 if (pVBInfo->IF_DEF_LVDS == 1) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002356 /* LVDS backlight off */
2357 XGI_XG21BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002358 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302359 } else {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002360 /* DVO/DVI signal off */
2361 XGI_XG21BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302362 }
2363 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002364
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302365 if (pXGIHWDE->jChipType == XG27) {
2366 if ((XGI_XG27GetPSCValue(pVBInfo) & 0x2)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002367 /* LVDS backlight off */
2368 XGI_XG27BLSignalVDD(0x02, 0x00, pVBInfo);
Aaro Koskinen886230c2012-09-11 00:15:13 +03002369 mdelay(xgifb_info->lvds_data.PSC_S3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302370 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002371
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302372 if (pVBInfo->IF_DEF_LVDS == 0)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002373 /* DVO/DVI signal off */
2374 XGI_XG27BLSignalVDD(0x20, 0x00, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302375 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002376
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002377 xgifb_reg_and_or(pVBInfo->P3c4, 0x01, 0xDF, 0x20);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002378}
2379
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002380static void XGI_WaitDisply(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002381{
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002382 while ((inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302383 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002384
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02002385 while (!(inb(pVBInfo->P3da) & 0x01))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302386 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002387}
2388
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002389static void XGI_AutoThreshold(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002390{
Aaro Koskinen09cb8e52011-08-31 21:46:12 +03002391 xgifb_reg_or(pVBInfo->Part1Port, 0x01, 0x40);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002392}
2393
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002394static void XGI_SaveCRT2Info(unsigned short ModeNo,
2395 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002396{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302397 unsigned short temp1, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002398
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002399 /* reserve CR34 for CRT1 Mode No */
2400 xgifb_reg_set(pVBInfo->P3d4, 0x34, ModeNo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302401 temp1 = (pVBInfo->VBInfo & SetInSlaveMode) >> 8;
2402 temp2 = ~(SetInSlaveMode >> 8);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002403 xgifb_reg_and_or(pVBInfo->P3d4, 0x31, temp2, temp1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002404}
2405
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002406static void XGI_GetCRT2ResInfo(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002407 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002408{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302409 unsigned short xres, yres, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002410
Aaro Koskinenb3979922012-11-04 21:14:52 +02002411 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02002412 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
2413 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002414 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002415 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002416
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002417 if (modeflag & HalfDCLK)
2418 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002419
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002420 if (modeflag & DoubleScanMode)
2421 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002422
Miguel Gómez3339db82012-07-06 12:40:49 +02002423 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
2424 goto exit;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002425
Aaro Koskinen22006832013-02-09 00:03:47 +02002426 if (pVBInfo->LCDResInfo == Panel_1600x1200) {
2427 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2428 if (yres == 1024)
2429 yres = 1056;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302430 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002431 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002432
Aaro Koskinen22006832013-02-09 00:03:47 +02002433 if (pVBInfo->LCDResInfo == Panel_1280x1024) {
2434 if (yres == 400)
2435 yres = 405;
2436 else if (yres == 350)
2437 yres = 360;
Miguel Gómez3339db82012-07-06 12:40:49 +02002438
Aaro Koskinen22006832013-02-09 00:03:47 +02002439 if (pVBInfo->LCDInfo & XGI_LCDVESATiming) {
2440 if (yres == 360)
2441 yres = 375;
Miguel Gómez3339db82012-07-06 12:40:49 +02002442 }
Aaro Koskinen22006832013-02-09 00:03:47 +02002443 }
Miguel Gómez3339db82012-07-06 12:40:49 +02002444
Aaro Koskinen22006832013-02-09 00:03:47 +02002445 if (pVBInfo->LCDResInfo == Panel_1024x768) {
2446 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
2447 if (!(pVBInfo->LCDInfo & LCDNonExpanding)) {
2448 if (yres == 350)
2449 yres = 357;
2450 else if (yres == 400)
2451 yres = 420;
2452 else if (yres == 480)
2453 yres = 525;
Miguel Gómez3339db82012-07-06 12:40:49 +02002454 }
2455 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302456 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002457
Miguel Gómez3339db82012-07-06 12:40:49 +02002458 if (xres == 720)
2459 xres = 640;
2460
2461exit:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302462 pVBInfo->VGAHDE = xres;
2463 pVBInfo->HDE = xres;
2464 pVBInfo->VGAVDE = yres;
2465 pVBInfo->VDE = yres;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002466}
2467
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002468static unsigned char XGI_IsLCDDualLink(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002469{
2470
Peter Huewea3d675c2012-02-09 21:11:47 +01002471 if ((pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) &&
Dan Carpentera65fd092011-01-04 09:02:27 +03002472 (pVBInfo->LCDInfo & SetLCDDualLink)) /* shampoo0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302473 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002474
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302475 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002476}
2477
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002478static void XGI_GetRAMDAC2DATA(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002479 unsigned short RefreshRateTableIndex,
2480 struct vb_device_info *pVBInfo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002481{
2482 unsigned short tempax, tempbx, temp1, temp2, modeflag = 0, tempcx,
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002483 CRT1Index;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002484
2485 pVBInfo->RVBHCMAX = 1;
2486 pVBInfo->RVBHCFACT = 1;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002487 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002488 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002489 CRT1Index &= IndexMask;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002490 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[0];
2491 temp2 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[5];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002492 tempax = (temp1 & 0xFF) | ((temp2 & 0x03) << 8);
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002493 tempbx = (unsigned short) XGI_CRT1Table[CRT1Index].CR[8];
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002494 tempcx = (unsigned short)
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002495 XGI_CRT1Table[CRT1Index].CR[14] << 8;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002496 tempcx &= 0x0100;
2497 tempcx = tempcx << 2;
2498 tempbx |= tempcx;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002499 temp1 = (unsigned short) XGI_CRT1Table[CRT1Index].CR[9];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002500
2501 if (temp1 & 0x01)
2502 tempbx |= 0x0100;
2503
2504 if (temp1 & 0x20)
2505 tempbx |= 0x0200;
2506 tempax += 5;
2507
2508 if (modeflag & Charx8Dot)
2509 tempax *= 8;
2510 else
2511 tempax *= 9;
2512
2513 pVBInfo->VGAHT = tempax;
2514 pVBInfo->HT = tempax;
2515 tempbx++;
2516 pVBInfo->VGAVT = tempbx;
2517 pVBInfo->VT = tempbx;
2518}
2519
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002520static void XGI_GetCRT2Data(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302521 unsigned short RefreshRateTableIndex,
2522 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002523{
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02002524 unsigned short tempax = 0, tempbx = 0, modeflag, resinfo;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002525
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02002526 struct SiS_LCDData const *LCDPtr = NULL;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002527
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002528 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002529 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2530 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302531 pVBInfo->NewFlickerMode = 0;
2532 pVBInfo->RVBHRS = 50;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002533
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302534 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002535 XGI_GetRAMDAC2DATA(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302536 return;
2537 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002538
Peter Huewea3d675c2012-02-09 21:11:47 +01002539 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002540 LCDPtr = XGI_GetLcdPtr(XGI_LCDDataTable, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03002541 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002542
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302543 pVBInfo->RVBHCMAX = LCDPtr->RVBHCMAX;
2544 pVBInfo->RVBHCFACT = LCDPtr->RVBHCFACT;
2545 pVBInfo->VGAHT = LCDPtr->VGAHT;
2546 pVBInfo->VGAVT = LCDPtr->VGAVT;
2547 pVBInfo->HT = LCDPtr->LCDHT;
2548 pVBInfo->VT = LCDPtr->LCDVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002549
Peter Huewe255aabd2012-02-09 21:11:44 +01002550 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302551 tempax = 1024;
2552 tempbx = 768;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002553
Peter Huewea3d675c2012-02-09 21:11:47 +01002554 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302555 if (pVBInfo->VGAVDE == 357)
2556 tempbx = 527;
2557 else if (pVBInfo->VGAVDE == 420)
2558 tempbx = 620;
2559 else if (pVBInfo->VGAVDE == 525)
2560 tempbx = 775;
2561 else if (pVBInfo->VGAVDE == 600)
2562 tempbx = 775;
Peter Huewe7580d7f2013-05-18 00:19:54 +02002563 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002564 } else if (pVBInfo->LCDResInfo == Panel_1024x768x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302565 tempax = 1024;
2566 tempbx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01002567 } else if (pVBInfo->LCDResInfo == Panel_1280x1024) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302568 tempax = 1280;
2569 if (pVBInfo->VGAVDE == 360)
2570 tempbx = 768;
2571 else if (pVBInfo->VGAVDE == 375)
2572 tempbx = 800;
2573 else if (pVBInfo->VGAVDE == 405)
2574 tempbx = 864;
2575 else
2576 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002577 } else if (pVBInfo->LCDResInfo == Panel_1280x1024x75) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302578 tempax = 1280;
2579 tempbx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01002580 } else if (pVBInfo->LCDResInfo == Panel_1280x960) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302581 tempax = 1280;
2582 if (pVBInfo->VGAVDE == 350)
2583 tempbx = 700;
2584 else if (pVBInfo->VGAVDE == 400)
2585 tempbx = 800;
2586 else if (pVBInfo->VGAVDE == 1024)
2587 tempbx = 960;
2588 else
2589 tempbx = 960;
Peter Huewe255aabd2012-02-09 21:11:44 +01002590 } else if (pVBInfo->LCDResInfo == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302591 tempax = 1400;
2592 tempbx = 1050;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002593
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302594 if (pVBInfo->VGAVDE == 1024) {
2595 tempax = 1280;
2596 tempbx = 1024;
2597 }
Peter Huewe255aabd2012-02-09 21:11:44 +01002598 } else if (pVBInfo->LCDResInfo == Panel_1600x1200) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302599 tempax = 1600;
2600 tempbx = 1200; /* alan 10/14/2003 */
Peter Huewea3d675c2012-02-09 21:11:47 +01002601 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302602 if (pVBInfo->VGAVDE == 350)
2603 tempbx = 875;
2604 else if (pVBInfo->VGAVDE == 400)
2605 tempbx = 1000;
2606 }
2607 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002608
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302609 if (pVBInfo->LCDInfo & LCDNonExpanding) {
2610 tempax = pVBInfo->VGAHDE;
2611 tempbx = pVBInfo->VGAVDE;
2612 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002613
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302614 pVBInfo->HDE = tempax;
2615 pVBInfo->VDE = tempbx;
2616 return;
2617 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002618
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302619 if (pVBInfo->VBInfo & (SetCRT2ToTV)) {
Aaro Koskinen24572542012-09-11 00:15:21 +03002620 struct SiS_TVData const *TVPtr;
2621
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002622 TVPtr = XGI_GetTVPtr(ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinen24572542012-09-11 00:15:21 +03002623 pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002624
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302625 pVBInfo->RVBHCMAX = TVPtr->RVBHCMAX;
2626 pVBInfo->RVBHCFACT = TVPtr->RVBHCFACT;
2627 pVBInfo->VGAHT = TVPtr->VGAHT;
2628 pVBInfo->VGAVT = TVPtr->VGAVT;
2629 pVBInfo->HDE = TVPtr->TVHDE;
2630 pVBInfo->VDE = TVPtr->TVVDE;
2631 pVBInfo->RVBHRS = TVPtr->RVBHRS;
2632 pVBInfo->NewFlickerMode = TVPtr->FlickerMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002633
Peter Huewe599801f2012-02-09 21:11:45 +01002634 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302635 if (resinfo == 0x08)
2636 pVBInfo->NewFlickerMode = 0x40;
2637 else if (resinfo == 0x09)
2638 pVBInfo->NewFlickerMode = 0x40;
2639 else if (resinfo == 0x12)
2640 pVBInfo->NewFlickerMode = 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002641
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302642 if (pVBInfo->VGAVDE == 350)
2643 pVBInfo->TVInfo |= TVSimuMode;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002644
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302645 tempax = ExtHiTVHT;
2646 tempbx = ExtHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002647
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302648 if (pVBInfo->VBInfo & SetInSlaveMode) {
2649 if (pVBInfo->TVInfo & TVSimuMode) {
2650 tempax = StHiTVHT;
2651 tempbx = StHiTVVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002652
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302653 if (!(modeflag & Charx8Dot)) {
2654 tempax = StHiTextTVHT;
2655 tempbx = StHiTextTVVT;
2656 }
2657 }
2658 }
Peter Huewe599801f2012-02-09 21:11:45 +01002659 } else if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
2660 if (pVBInfo->TVInfo & TVSetYPbPr750p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302661 tempax = YPbPrTV750pHT; /* Ext750pTVHT */
2662 tempbx = YPbPrTV750pVT; /* Ext750pTVVT */
2663 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002664
Peter Huewe599801f2012-02-09 21:11:45 +01002665 if (pVBInfo->TVInfo & TVSetYPbPr525p) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302666 tempax = YPbPrTV525pHT; /* Ext525pTVHT */
2667 tempbx = YPbPrTV525pVT; /* Ext525pTVVT */
Peter Huewe599801f2012-02-09 21:11:45 +01002668 } else if (pVBInfo->TVInfo & TVSetYPbPr525i) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302669 tempax = YPbPrTV525iHT; /* Ext525iTVHT */
2670 tempbx = YPbPrTV525iVT; /* Ext525iTVVT */
2671 if (pVBInfo->TVInfo & NTSC1024x768)
2672 tempax = NTSC1024x768HT;
2673 }
2674 } else {
2675 tempax = PALHT;
2676 tempbx = PALVT;
Peter Huewe599801f2012-02-09 21:11:45 +01002677 if (!(pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302678 tempax = NTSCHT;
2679 tempbx = NTSCVT;
2680 if (pVBInfo->TVInfo & NTSC1024x768)
2681 tempax = NTSC1024x768HT;
2682 }
2683 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002684
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302685 pVBInfo->HT = tempax;
2686 pVBInfo->VT = tempbx;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302687 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002688}
2689
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002690static void XGI_SetCRT2VCLK(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302691 unsigned short RefreshRateTableIndex,
2692 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002693{
Bill Pemberton108afbf2010-06-17 13:10:47 -04002694 unsigned char di_0, di_1, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002695
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002696 tempal = XGI_GetVCLKPtr(RefreshRateTableIndex, ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302697 XGI_GetVCLKLen(tempal, &di_0, &di_1, pVBInfo);
2698 XGI_GetLCDVCLKPtr(&di_0, &di_1, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002699
Peter Huewe6896b942012-02-09 21:11:46 +01002700 if (pVBInfo->VBType & VB_SIS301) { /* shampoo 0129 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302701 /* 301 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002702 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, 0x10);
2703 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
2704 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302705 } else { /* 301b/302b/301lv/302lv */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002706 xgifb_reg_set(pVBInfo->Part4Port, 0x0A, di_0);
2707 xgifb_reg_set(pVBInfo->Part4Port, 0x0B, di_1);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302708 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002709
Aaro Koskinen8104e322011-03-13 12:26:22 +02002710 xgifb_reg_set(pVBInfo->Part4Port, 0x00, 0x12);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002711
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302712 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002713 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x28);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302714 else
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02002715 xgifb_reg_or(pVBInfo->Part4Port, 0x12, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002716}
2717
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002718static unsigned short XGI_GetColorDepth(unsigned short ModeIdIndex,
2719 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002720{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002721 unsigned short ColorDepth[6] = { 1, 2, 4, 4, 6, 8 };
2722 short index;
2723 unsigned short modeflag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302724
Aaro Koskinenb3979922012-11-04 21:14:52 +02002725 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01002726 index = (modeflag & ModeTypeMask) - ModeEGA;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302727
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002728 if (index < 0)
2729 index = 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302730
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002731 return ColorDepth[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302732}
2733
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002734static unsigned short XGI_GetOffset(unsigned short ModeNo,
2735 unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302736 unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302737 struct vb_device_info *pVBInfo)
2738{
2739 unsigned short temp, colordepth, modeinfo, index, infoflag,
2740 ColorDepth[] = { 0x01, 0x02, 0x04 };
2741
Aaro Koskinenb3979922012-11-04 21:14:52 +02002742 modeinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeInfo;
Aaro Koskinena39325d2012-11-04 21:14:53 +02002743 infoflag = XGI330_RefIndex[RefreshRateTableIndex].Ext_InfoFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302744
2745 index = (modeinfo >> 8) & 0xFF;
2746
Aaro Koskinen224114c2012-11-04 21:14:59 +02002747 temp = XGI330_ScreenOffset[index];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302748
2749 if (infoflag & InterlaceMode)
2750 temp = temp << 1;
2751
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002752 colordepth = XGI_GetColorDepth(ModeIdIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302753
2754 if ((ModeNo >= 0x7C) && (ModeNo <= 0x7E)) {
2755 temp = ModeNo - 0x7C;
2756 colordepth = ColorDepth[temp];
2757 temp = 0x6B;
2758 if (infoflag & InterlaceMode)
2759 temp = temp << 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302760 }
Peter Huewe053004b2013-02-15 20:37:12 +01002761 return temp * colordepth;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302762}
2763
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002764static void XGI_SetCRT2Offset(unsigned short ModeNo,
2765 unsigned short ModeIdIndex,
2766 unsigned short RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002767 struct vb_device_info *pVBInfo)
2768{
2769 unsigned short offset;
2770 unsigned char temp;
2771
2772 if (pVBInfo->VBInfo & SetInSlaveMode)
2773 return;
2774
2775 offset = XGI_GetOffset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinenb053af12013-07-16 23:13:28 +03002776 pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002777 temp = (unsigned char) (offset & 0xFF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002778 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002779 temp = (unsigned char) ((offset & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002780 xgifb_reg_set(pVBInfo->Part1Port, 0x09, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002781 temp = (unsigned char) (((offset >> 3) & 0xFF) + 1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002782 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002783}
2784
Randy Dunlap89229672010-08-10 08:46:44 -07002785static void XGI_SetCRT2FIFO(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002786{
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002787 /* threshold high ,disable auto threshold */
2788 xgifb_reg_set(pVBInfo->Part1Port, 0x01, 0x3B);
2789 /* threshold low default 04h */
2790 xgifb_reg_and_or(pVBInfo->Part1Port, 0x02, ~(0x3F), 0x04);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002791}
2792
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002793static void XGI_PreSetGroup1(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302794 unsigned short RefreshRateTableIndex,
2795 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002796{
Peter Hueweef9a6b92013-02-03 04:08:43 +01002797 u8 tempcx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002798
Aaro Koskinenb053af12013-07-16 23:13:28 +03002799 XGI_SetCRT2Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302800 XGI_SetCRT2FIFO(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002801
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302802 for (tempcx = 4; tempcx < 7; tempcx++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02002803 xgifb_reg_set(pVBInfo->Part1Port, tempcx, 0x0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002804
Aaro Koskinen8104e322011-03-13 12:26:22 +02002805 xgifb_reg_set(pVBInfo->Part1Port, 0x50, 0x00);
2806 xgifb_reg_set(pVBInfo->Part1Port, 0x02, 0x44); /* temp 0206 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002807}
2808
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03002809static void XGI_SetGroup1(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302810 unsigned short RefreshRateTableIndex,
2811 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002812{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302813 unsigned short temp = 0, tempax = 0, tempbx = 0, tempcx = 0,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002814 pushbx = 0, CRT1Index, modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002815
Aaro Koskinena39325d2012-11-04 21:14:53 +02002816 CRT1Index = XGI330_RefIndex[RefreshRateTableIndex].Ext_CRT1CRTC;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002817 CRT1Index &= IndexMask;
Aaro Koskinenb3979922012-11-04 21:14:52 +02002818 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002819
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302820 /* bainy change table name */
2821 if (modeflag & HalfDCLK) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002822 /* BTVGA2HT 0x08,0x09 */
2823 temp = (pVBInfo->VGAHT / 2 - 1) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002824 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302825 temp = (((pVBInfo->VGAHT / 2 - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002826 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002827 /* BTVGA2HDEE 0x0A,0x0C */
2828 temp = (pVBInfo->VGAHDE / 2 + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002829 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302830 tempcx = ((pVBInfo->VGAHT - pVBInfo->VGAHDE) / 2) >> 2;
2831 pushbx = pVBInfo->VGAHDE / 2 + 16;
2832 tempcx = tempcx >> 1;
2833 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2834 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002835
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302836 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002837 tempbx = XGI_CRT1Table[CRT1Index].CR[4];
2838 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[14] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002839 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302840 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002841 tempcx = XGI_CRT1Table[CRT1Index].CR[5];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302842 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002843 temp = XGI_CRT1Table[CRT1Index].CR[15];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302844 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2845 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2846 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002847
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302848 tempbx += 4;
2849 tempcx += 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002850
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302851 if (tempcx > (pVBInfo->VGAHT / 2))
2852 tempcx = pVBInfo->VGAHT / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002853
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302854 temp = tempbx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002855
Aaro Koskinen8104e322011-03-13 12:26:22 +02002856 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302857 } else {
2858 temp = (pVBInfo->VGAHT - 1) & 0x0FF; /* BTVGA2HT 0x08,0x09 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002859 xgifb_reg_set(pVBInfo->Part1Port, 0x08, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302860 temp = (((pVBInfo->VGAHT - 1) & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002861 xgifb_reg_and_or(pVBInfo->Part1Port, 0x09, ~0x0F0, temp);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002862 /* BTVGA2HDEE 0x0A,0x0C */
2863 temp = (pVBInfo->VGAHDE + 16) & 0x0FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002864 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302865 tempcx = (pVBInfo->VGAHT - pVBInfo->VGAHDE) >> 2; /* cx */
2866 pushbx = pVBInfo->VGAHDE + 16;
2867 tempcx = tempcx >> 1;
2868 tempbx = pushbx + tempcx; /* bx BTVGA@HRS 0x0B,0x0C */
2869 tempcx += tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002870
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302871 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002872 tempbx = XGI_CRT1Table[CRT1Index].CR[3];
2873 tempbx |= ((XGI_CRT1Table[CRT1Index].CR[5] &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002874 0xC0) << 2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302875 tempbx = (tempbx - 3) << 3; /* (VGAHRS-3)*8 */
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002876 tempcx = XGI_CRT1Table[CRT1Index].CR[4];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302877 tempcx &= 0x1F;
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002878 temp = XGI_CRT1Table[CRT1Index].CR[6];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302879 temp = (temp & 0x04) << (5 - 2); /* VGAHRE D[5] */
2880 tempcx = ((tempcx | temp) - 3) << 3; /* (VGAHRE-3)*8 */
2881 tempbx += 16;
2882 tempcx += 16;
2883 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002884
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302885 if (tempcx > pVBInfo->VGAHT)
2886 tempcx = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002887
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302888 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002889 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302890 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002891
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302892 tempax = (tempax & 0x00FF) | (tempbx & 0xFF00);
2893 tempbx = pushbx;
2894 tempbx = (tempbx & 0x00FF) | ((tempbx & 0xFF00) << 4);
2895 tempax |= (tempbx & 0xFF00);
2896 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002897 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302898 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002899 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302900 tempcx = (pVBInfo->VGAVT - 1);
2901 temp = tempcx & 0x00FF;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002902
Aaro Koskinen8104e322011-03-13 12:26:22 +02002903 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302904 tempbx = pVBInfo->VGAVDE - 1;
2905 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002906 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302907 temp = ((tempbx & 0xFF00) << 3) >> 8;
2908 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02002909 xgifb_reg_set(pVBInfo->Part1Port, 0x12, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002910
Kenji Toyama1d7f6562011-04-23 19:36:49 +08002911 /* BTVGA2VRS 0x10,0x11 */
2912 tempbx = (pVBInfo->VGAVT + pVBInfo->VGAVDE) >> 1;
2913 /* BTVGA2VRE 0x11 */
2914 tempcx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) >> 4) + tempbx + 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002915
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302916 if (pVBInfo->VBInfo & SetCRT2ToRAMDAC) {
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002917 tempbx = XGI_CRT1Table[CRT1Index].CR[10];
2918 temp = XGI_CRT1Table[CRT1Index].CR[9];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002919
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302920 if (temp & 0x04)
2921 tempbx |= 0x0100;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002922
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302923 if (temp & 0x080)
2924 tempbx |= 0x0200;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002925
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002926 temp = XGI_CRT1Table[CRT1Index].CR[14];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002927
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302928 if (temp & 0x08)
2929 tempbx |= 0x0400;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002930
Aaro Koskinen7853bce2012-11-04 21:14:54 +02002931 temp = XGI_CRT1Table[CRT1Index].CR[11];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302932 tempcx = (tempcx & 0xFF00) | (temp & 0x00FF);
2933 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002934
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302935 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002936 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302937 temp = ((tempbx & 0xFF00) >> 8) << 4;
2938 temp = ((tempcx & 0x000F) | (temp));
Aaro Koskinen8104e322011-03-13 12:26:22 +02002939 xgifb_reg_set(pVBInfo->Part1Port, 0x11, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302940 tempax = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002941
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302942 if (modeflag & DoubleScanMode)
2943 tempax |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002944
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302945 if (modeflag & HalfDCLK)
2946 tempax |= 0x40;
2947
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02002948 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2C, ~0x0C0, tempax);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002949}
2950
Aaro Koskinencc1e2392011-03-13 12:26:07 +02002951static unsigned short XGI_GetVGAHT2(struct vb_device_info *pVBInfo)
2952{
2953 unsigned long tempax, tempbx;
2954
2955 tempbx = ((pVBInfo->VGAVT - pVBInfo->VGAVDE) * pVBInfo->RVBHCMAX)
2956 & 0xFFFF;
2957 tempax = (pVBInfo->VT - pVBInfo->VDE) * pVBInfo->RVBHCFACT;
2958 tempax = (tempax * pVBInfo->HT) / tempbx;
2959
2960 return (unsigned short) tempax;
2961}
2962
Aaro Koskinen063b9c42011-03-08 22:16:13 +02002963static void XGI_SetLockRegs(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302964 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002965{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302966 unsigned short push1, push2, tempax, tempbx = 0, tempcx, temp, resinfo,
Peter Hueweef9a6b92013-02-03 04:08:43 +01002967 modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002968
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03002969 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02002970 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
2971 resinfo = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002972
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302973 if (!(pVBInfo->VBInfo & SetInSlaveMode))
2974 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002975
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302976 temp = 0xFF; /* set MAX HT */
Aaro Koskinen8104e322011-03-13 12:26:22 +02002977 xgifb_reg_set(pVBInfo->Part1Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302978 tempcx = 0x08;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002979
Peter Huewe6896b942012-02-09 21:11:46 +01002980 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302981 modeflag |= Charx8Dot;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002982
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302983 tempax = pVBInfo->VGAHDE; /* 0x04 Horizontal Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002984
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302985 if (modeflag & HalfDCLK)
2986 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002987
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302988 tempax = (tempax / tempcx) - 1;
2989 tempbx |= ((tempax & 0x00FF) << 8);
2990 temp = tempax & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02002991 xgifb_reg_set(pVBInfo->Part1Port, 0x04, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002992
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302993 temp = (tempbx & 0xFF00) >> 8;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002994
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302995 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe6896b942012-02-09 21:11:46 +01002996 if (!(pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
2997 | VB_SIS302LV | VB_XGI301C)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05302998 temp += 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02002999
Aaro Koskinen31fb40f2012-09-11 00:15:15 +03003000 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) &&
3001 !(pVBInfo->VBType & VB_SIS301LV) && (resinfo == 7))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303002 temp -= 2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303003 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003004
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003005 /* 0x05 Horizontal Display Start */
3006 xgifb_reg_set(pVBInfo->Part1Port, 0x05, temp);
3007 /* 0x06 Horizontal Blank end */
3008 xgifb_reg_set(pVBInfo->Part1Port, 0x06, 0x03);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003009
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303010 if (!(pVBInfo->VBInfo & DisableCRT2Display)) { /* 030226 bainy */
3011 if (pVBInfo->VBInfo & SetCRT2ToTV)
3012 tempax = pVBInfo->VGAHT;
3013 else
3014 tempax = XGI_GetVGAHT2(pVBInfo);
3015 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003016
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303017 if (tempax >= pVBInfo->VGAHT)
3018 tempax = pVBInfo->VGAHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003019
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303020 if (modeflag & HalfDCLK)
3021 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003022
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303023 tempax = (tempax / tempcx) - 5;
3024 tempcx = tempax; /* 20030401 0x07 horizontal Retrace Start */
Peter Huewe599801f2012-02-09 21:11:45 +01003025 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303026 temp = (tempbx & 0x00FF) - 1;
3027 if (!(modeflag & HalfDCLK)) {
3028 temp -= 6;
3029 if (pVBInfo->TVInfo & TVSimuMode) {
3030 temp -= 4;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003031 temp -= 10;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303032 }
3033 }
3034 } else {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303035 tempbx = (tempbx & 0xFF00) >> 8;
3036 tempcx = (tempcx + tempbx) >> 1;
3037 temp = (tempcx & 0x00FF) + 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003038
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303039 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3040 temp -= 1;
3041 if (!(modeflag & HalfDCLK)) {
3042 if ((modeflag & Charx8Dot)) {
3043 temp += 4;
3044 if (pVBInfo->VGAHDE >= 800)
3045 temp -= 6;
3046 }
3047 }
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003048 } else if (!(modeflag & HalfDCLK)) {
3049 temp -= 4;
Peter Huewe255aabd2012-02-09 21:11:44 +01003050 if (pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003051 pVBInfo->VGAHDE >= 800) {
3052 temp -= 7;
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003053 if (pVBInfo->VGAHDE >= 1280 &&
Peter Huewe255aabd2012-02-09 21:11:44 +01003054 pVBInfo->LCDResInfo != Panel_1280x960 &&
Aaro Koskinen6596fc02011-11-27 23:03:19 +02003055 (pVBInfo->LCDInfo & LCDNonExpanding))
3056 temp += 28;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303057 }
3058 }
3059 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003060
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003061 /* 0x07 Horizontal Retrace Start */
3062 xgifb_reg_set(pVBInfo->Part1Port, 0x07, temp);
3063 /* 0x08 Horizontal Retrace End */
3064 xgifb_reg_set(pVBInfo->Part1Port, 0x08, 0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003065
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303066 if (pVBInfo->VBInfo & SetCRT2ToTV) {
3067 if (pVBInfo->TVInfo & TVSimuMode) {
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003068 if (ModeNo == 0x50) {
Peter Huewe85b38472013-05-13 23:41:49 +02003069 if (pVBInfo->TVInfo == SetNTSCTV) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003070 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303071 0x07, 0x30);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003072 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303073 0x08, 0x03);
3074 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003075 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303076 0x07, 0x2f);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003077 xgifb_reg_set(pVBInfo->Part1Port,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303078 0x08, 0x02);
3079 }
3080 }
3081 }
3082 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003083
Aaro Koskinen8104e322011-03-13 12:26:22 +02003084 xgifb_reg_set(pVBInfo->Part1Port, 0x18, 0x03); /* 0x18 SR0B */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003085 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0xF0, 0x00);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003086 xgifb_reg_set(pVBInfo->Part1Port, 0x09, 0xFF); /* 0x09 Set Max VT */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003087
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303088 tempbx = pVBInfo->VGAVT;
3089 push1 = tempbx;
3090 tempcx = 0x121;
3091 tempbx = pVBInfo->VGAVDE; /* 0x0E Virtical Display End */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003092
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303093 if (tempbx == 357)
3094 tempbx = 350;
3095 if (tempbx == 360)
3096 tempbx = 350;
3097 if (tempbx == 375)
3098 tempbx = 350;
3099 if (tempbx == 405)
3100 tempbx = 400;
3101 if (tempbx == 525)
3102 tempbx = 480;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003103
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303104 push2 = tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003105
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303106 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
Peter Huewe255aabd2012-02-09 21:11:44 +01003107 if (pVBInfo->LCDResInfo == Panel_1024x768) {
Peter Huewea3d675c2012-02-09 21:11:47 +01003108 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303109 if (tempbx == 350)
3110 tempbx += 5;
3111 if (tempbx == 480)
3112 tempbx += 5;
3113 }
3114 }
3115 }
3116 tempbx--;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303117 tempbx--;
3118 temp = tempbx & 0x00FF;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003119 /* 0x10 vertical Blank Start */
3120 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303121 tempbx = push2;
3122 tempbx--;
3123 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003124 xgifb_reg_set(pVBInfo->Part1Port, 0x0E, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003125
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303126 if (tempbx & 0x0100)
3127 tempcx |= 0x0002;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003128
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303129 tempax = 0x000B;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003130
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303131 if (modeflag & DoubleScanMode)
3132 tempax |= 0x08000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003133
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303134 if (tempbx & 0x0200)
3135 tempcx |= 0x0040;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003136
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303137 temp = (tempax & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003138 xgifb_reg_set(pVBInfo->Part1Port, 0x0B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003139
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303140 if (tempbx & 0x0400)
3141 tempcx |= 0x0600;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003142
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003143 /* 0x11 Vertival Blank End */
3144 xgifb_reg_set(pVBInfo->Part1Port, 0x11, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303145
3146 tempax = push1;
3147 tempax -= tempbx; /* 0x0C Vertical Retrace Start */
3148 tempax = tempax >> 2;
3149 push1 = tempax; /* push ax */
3150
3151 if (resinfo != 0x09) {
3152 tempax = tempax << 1;
3153 tempbx += tempax;
3154 }
3155
Peter Huewe599801f2012-02-09 21:11:45 +01003156 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Miguel Gómez470c5332012-07-06 12:40:50 +02003157 if ((pVBInfo->VBType & VB_SIS301LV) &&
3158 !(pVBInfo->TVInfo & TVSetHiVision)) {
3159 if ((pVBInfo->TVInfo & TVSimuMode) &&
3160 (pVBInfo->TVInfo & TVSetPAL)) {
3161 if (!(pVBInfo->VBType & VB_SIS301LV) ||
3162 !(pVBInfo->TVInfo &
3163 (TVSetYPbPr525p |
3164 TVSetYPbPr750p |
3165 TVSetHiVision)))
3166 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303167 }
3168 } else {
3169 tempbx -= 10;
3170 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003171 } else if (pVBInfo->TVInfo & TVSimuMode) {
3172 if (pVBInfo->TVInfo & TVSetPAL) {
3173 if (pVBInfo->VBType & VB_SIS301LV) {
3174 if (!(pVBInfo->TVInfo &
3175 (TVSetYPbPr525p |
3176 TVSetYPbPr750p |
3177 TVSetHiVision)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303178 tempbx += 40;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003179 } else {
3180 tempbx += 40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303181 }
3182 }
3183 }
3184 tempax = push1;
3185 tempax = tempax >> 2;
3186 tempax++;
3187 tempax += tempbx;
3188 push1 = tempax; /* push ax */
3189
Peter Huewe599801f2012-02-09 21:11:45 +01003190 if ((pVBInfo->TVInfo & TVSetPAL)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303191 if (tempbx <= 513) {
3192 if (tempax >= 513)
3193 tempbx = 513;
3194 }
3195 }
3196
3197 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003198 xgifb_reg_set(pVBInfo->Part1Port, 0x0C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303199 tempbx--;
3200 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003201 xgifb_reg_set(pVBInfo->Part1Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303202
3203 if (tempbx & 0x0100)
3204 tempcx |= 0x0008;
3205
3206 if (tempbx & 0x0200)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003207 xgifb_reg_and_or(pVBInfo->Part1Port, 0x0B, 0x0FF, 0x20);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303208
3209 tempbx++;
3210
3211 if (tempbx & 0x0100)
3212 tempcx |= 0x0004;
3213
3214 if (tempbx & 0x0200)
3215 tempcx |= 0x0080;
3216
3217 if (tempbx & 0x0400)
3218 tempcx |= 0x0C00;
3219
3220 tempbx = push1; /* pop ax */
3221 temp = tempbx & 0x00FF;
3222 temp &= 0x0F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003223 /* 0x0D vertical Retrace End */
3224 xgifb_reg_set(pVBInfo->Part1Port, 0x0D, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303225
3226 if (tempbx & 0x0010)
3227 tempcx |= 0x2000;
3228
3229 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003230 xgifb_reg_set(pVBInfo->Part1Port, 0x0A, temp); /* 0x0A CR07 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303231 temp = (tempcx & 0x0FF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003232 xgifb_reg_set(pVBInfo->Part1Port, 0x17, temp); /* 0x17 SR0A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303233 tempax = modeflag;
3234 temp = (tempax & 0xFF00) >> 8;
3235
3236 temp = (temp >> 1) & 0x09;
3237
Peter Huewe6896b942012-02-09 21:11:46 +01003238 if (pVBInfo->VBType & (VB_SIS301LV | VB_SIS302LV | VB_XGI301C))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303239 temp |= 0x01;
3240
Aaro Koskinen8104e322011-03-13 12:26:22 +02003241 xgifb_reg_set(pVBInfo->Part1Port, 0x16, temp); /* 0x16 SR01 */
3242 xgifb_reg_set(pVBInfo->Part1Port, 0x0F, 0); /* 0x0F CR14 */
3243 xgifb_reg_set(pVBInfo->Part1Port, 0x12, 0); /* 0x12 CR17 */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303244
3245 if (pVBInfo->LCDInfo & LCDRGB18Bit)
3246 temp = 0x80;
3247 else
3248 temp = 0x00;
3249
Aaro Koskinen8104e322011-03-13 12:26:22 +02003250 xgifb_reg_set(pVBInfo->Part1Port, 0x1A, temp); /* 0x1A SR0E */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003251}
3252
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003253static void XGI_SetGroup2(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303254 struct vb_device_info *pVBInfo)
3255{
3256 unsigned short i, j, tempax, tempbx, tempcx, temp, push1, push2,
Peter Hueweef9a6b92013-02-03 04:08:43 +01003257 modeflag;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003258 unsigned char const *TimingPoint;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303259
3260 unsigned long longtemp, tempeax, tempebx, temp2, tempecx;
3261
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003262 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003263 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303264
3265 tempax = 0;
3266
3267 if (!(pVBInfo->VBInfo & SetCRT2ToAVIDEO))
3268 tempax |= 0x0800;
3269
3270 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3271 tempax |= 0x0400;
3272
3273 if (pVBInfo->VBInfo & SetCRT2ToSCART)
3274 tempax |= 0x0200;
3275
Peter Huewe599801f2012-02-09 21:11:45 +01003276 if (!(pVBInfo->TVInfo & TVSetPAL))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303277 tempax |= 0x1000;
3278
Peter Huewe599801f2012-02-09 21:11:45 +01003279 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303280 tempax |= 0x0100;
3281
Peter Huewe599801f2012-02-09 21:11:45 +01003282 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303283 tempax &= 0xfe00;
3284
3285 tempax = (tempax & 0xff00) >> 8;
3286
Aaro Koskinen8104e322011-03-13 12:26:22 +02003287 xgifb_reg_set(pVBInfo->Part2Port, 0x0, tempax);
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003288 TimingPoint = XGI330_NTSCTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303289
Peter Huewe599801f2012-02-09 21:11:45 +01003290 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003291 TimingPoint = XGI330_PALTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303292
Peter Huewe599801f2012-02-09 21:11:45 +01003293 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003294 TimingPoint = XGI330_HiTVExtTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303295
3296 if (pVBInfo->VBInfo & SetInSlaveMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003297 TimingPoint = XGI330_HiTVSt2Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303298
3299 if (pVBInfo->SetFlag & TVSimuMode)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003300 TimingPoint = XGI330_HiTVSt1Timing;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303301
3302 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003303 TimingPoint = XGI330_HiTVTextTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303304 }
3305
Peter Huewe599801f2012-02-09 21:11:45 +01003306 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3307 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003308 TimingPoint = XGI330_YPbPr525iTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303309
Peter Huewe599801f2012-02-09 21:11:45 +01003310 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003311 TimingPoint = XGI330_YPbPr525pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303312
Peter Huewe599801f2012-02-09 21:11:45 +01003313 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003314 TimingPoint = XGI330_YPbPr750pTiming;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303315 }
3316
3317 for (i = 0x01, j = 0; i <= 0x2D; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003318 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303319
3320 for (i = 0x39; i <= 0x45; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003321 /* di->temp2[j] */
3322 xgifb_reg_set(pVBInfo->Part2Port, i, TimingPoint[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303323
3324 if (pVBInfo->VBInfo & SetCRT2ToTV)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003325 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303326
3327 temp = pVBInfo->NewFlickerMode;
3328 temp &= 0x80;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003329 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xFF, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303330
Peter Huewe599801f2012-02-09 21:11:45 +01003331 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303332 tempax = 520;
3333 else
3334 tempax = 440;
3335
3336 if (pVBInfo->VDE <= tempax) {
3337 tempax -= pVBInfo->VDE;
3338 tempax = tempax >> 2;
3339 tempax = (tempax & 0x00FF) | ((tempax & 0x00FF) << 8);
3340 push1 = tempax;
3341 temp = (tempax & 0xFF00) >> 8;
3342 temp += (unsigned short) TimingPoint[0];
3343
Peter Huewe6896b942012-02-09 21:11:46 +01003344 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3345 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303346 if (pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3347 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003348 | SetCRT2ToYPbPr525750)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303349 tempcx = pVBInfo->VGAHDE;
3350 if (tempcx >= 1024) {
3351 temp = 0x17; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003352 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303353 temp = 0x19; /* PAL */
3354 }
3355 }
3356 }
3357
Aaro Koskinen8104e322011-03-13 12:26:22 +02003358 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303359 tempax = push1;
3360 temp = (tempax & 0xFF00) >> 8;
3361 temp += TimingPoint[1];
3362
Peter Huewe6896b942012-02-09 21:11:46 +01003363 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3364 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303365 if ((pVBInfo->VBInfo & (SetCRT2ToAVIDEO
3366 | SetCRT2ToSVIDEO | SetCRT2ToSCART
Peter Huewe599801f2012-02-09 21:11:45 +01003367 | SetCRT2ToYPbPr525750))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303368 tempcx = pVBInfo->VGAHDE;
3369 if (tempcx >= 1024) {
3370 temp = 0x1D; /* NTSC */
Peter Huewe599801f2012-02-09 21:11:45 +01003371 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303372 temp = 0x52; /* PAL */
3373 }
3374 }
3375 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003376 xgifb_reg_set(pVBInfo->Part2Port, 0x02, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303377 }
3378
3379 /* 301b */
3380 tempcx = pVBInfo->HT;
3381
3382 if (XGI_IsLCDDualLink(pVBInfo))
3383 tempcx = tempcx >> 1;
3384
3385 tempcx -= 2;
3386 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003387 xgifb_reg_set(pVBInfo->Part2Port, 0x1B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303388
3389 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003390 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303391
3392 tempcx = pVBInfo->HT >> 1;
3393 push1 = tempcx; /* push cx */
3394 tempcx += 7;
3395
Peter Huewe599801f2012-02-09 21:11:45 +01003396 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303397 tempcx -= 4;
3398
3399 temp = tempcx & 0x00FF;
3400 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003401 xgifb_reg_and_or(pVBInfo->Part2Port, 0x22, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303402
3403 tempbx = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3404 tempbx += tempcx;
3405 push2 = tempbx;
3406 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003407 xgifb_reg_set(pVBInfo->Part2Port, 0x24, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303408 temp = (tempbx & 0xFF00) >> 8;
3409 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003410 xgifb_reg_and_or(pVBInfo->Part2Port, 0x25, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303411
3412 tempbx = push2;
3413 tempbx = tempbx + 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003414 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303415 tempbx = tempbx - 4;
3416 tempcx = tempbx;
3417 }
3418
3419 temp = (tempbx & 0x00FF) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003420 xgifb_reg_and_or(pVBInfo->Part2Port, 0x29, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303421
3422 j += 2;
3423 tempcx += (TimingPoint[j] | ((TimingPoint[j + 1]) << 8));
3424 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003425 xgifb_reg_set(pVBInfo->Part2Port, 0x27, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303426 temp = ((tempcx & 0xFF00) >> 8) << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003427 xgifb_reg_and_or(pVBInfo->Part2Port, 0x28, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303428
3429 tempcx += 8;
Peter Huewe599801f2012-02-09 21:11:45 +01003430 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303431 tempcx -= 4;
3432
3433 temp = tempcx & 0xFF;
3434 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003435 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2A, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303436
3437 tempcx = push1; /* pop cx */
3438 j += 2;
3439 temp = TimingPoint[j] | ((TimingPoint[j + 1]) << 8);
3440 tempcx -= temp;
3441 temp = tempcx & 0x00FF;
3442 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003443 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2D, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303444
3445 tempcx -= 11;
3446
3447 if (!(pVBInfo->VBInfo & SetCRT2ToTV)) {
3448 tempax = XGI_GetVGAHT2(pVBInfo);
3449 tempcx = tempax - 1;
3450 }
3451 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003452 xgifb_reg_set(pVBInfo->Part2Port, 0x2E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303453
3454 tempbx = pVBInfo->VDE;
3455
3456 if (pVBInfo->VGAVDE == 360)
3457 tempbx = 746;
3458 if (pVBInfo->VGAVDE == 375)
3459 tempbx = 746;
3460 if (pVBInfo->VGAVDE == 405)
3461 tempbx = 853;
3462
3463 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003464 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01003465 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003466 if (!(pVBInfo->TVInfo &
Peter Huewe599801f2012-02-09 21:11:45 +01003467 (TVSetYPbPr525p | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303468 tempbx = tempbx >> 1;
3469 } else
3470 tempbx = tempbx >> 1;
3471 }
3472
3473 tempbx -= 2;
3474 temp = tempbx & 0x00FF;
3475
Peter Huewe599801f2012-02-09 21:11:45 +01003476 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Peter Huewe6896b942012-02-09 21:11:46 +01003477 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003478 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303479 if (pVBInfo->VBInfo & SetInSlaveMode) {
3480 if (ModeNo == 0x2f)
3481 temp += 1;
3482 }
3483 }
Aaro Koskinend3ae5762012-09-11 00:15:27 +03003484 } else if (pVBInfo->VBInfo & SetInSlaveMode) {
3485 if (ModeNo == 0x2f)
3486 temp += 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303487 }
3488 }
3489
Aaro Koskinen8104e322011-03-13 12:26:22 +02003490 xgifb_reg_set(pVBInfo->Part2Port, 0x2F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303491
3492 temp = (tempcx & 0xFF00) >> 8;
3493 temp |= ((tempbx & 0xFF00) >> 8) << 6;
3494
Peter Huewe599801f2012-02-09 21:11:45 +01003495 if (!(pVBInfo->VBInfo & SetCRT2ToHiVision)) {
Peter Huewe6896b942012-02-09 21:11:46 +01003496 if (pVBInfo->VBType & VB_SIS301LV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003497 if (pVBInfo->TVInfo & TVSetHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303498 temp |= 0x10;
3499
3500 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3501 temp |= 0x20;
3502 }
3503 } else {
3504 temp |= 0x10;
3505 if (!(pVBInfo->VBInfo & SetCRT2ToSVIDEO))
3506 temp |= 0x20;
3507 }
3508 }
3509
Aaro Koskinen8104e322011-03-13 12:26:22 +02003510 xgifb_reg_set(pVBInfo->Part2Port, 0x30, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303511
Peter Huewe6896b942012-02-09 21:11:46 +01003512 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3513 | VB_SIS302LV | VB_XGI301C)) { /* TV gatingno */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303514 tempbx = pVBInfo->VDE;
3515 tempcx = tempbx - 2;
3516
3517 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Peter Huewe599801f2012-02-09 21:11:45 +01003518 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p
3519 | TVSetYPbPr750p)))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303520 tempbx = tempbx >> 1;
3521 }
3522
Peter Huewe6896b942012-02-09 21:11:46 +01003523 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303524 temp = 0;
3525 if (tempcx & 0x0400)
3526 temp |= 0x20;
3527
3528 if (tempbx & 0x0400)
3529 temp |= 0x40;
3530
Aaro Koskinen8104e322011-03-13 12:26:22 +02003531 xgifb_reg_set(pVBInfo->Part4Port, 0x10, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303532 }
3533
3534 temp = (((tempbx - 3) & 0x0300) >> 8) << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003535 xgifb_reg_set(pVBInfo->Part2Port, 0x46, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303536 temp = (tempbx - 3) & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003537 xgifb_reg_set(pVBInfo->Part2Port, 0x47, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303538 }
3539
3540 tempbx = tempbx & 0x00FF;
3541
3542 if (!(modeflag & HalfDCLK)) {
3543 tempcx = pVBInfo->VGAHDE;
3544 if (tempcx >= pVBInfo->HDE) {
3545 tempbx |= 0x2000;
3546 tempax &= 0x00FF;
3547 }
3548 }
3549
3550 tempcx = 0x0101;
3551
3552 if (pVBInfo->VBInfo & SetCRT2ToTV) { /*301b*/
3553 if (pVBInfo->VGAHDE >= 1024) {
3554 tempcx = 0x1920;
3555 if (pVBInfo->VGAHDE >= 1280) {
3556 tempcx = 0x1420;
3557 tempbx = tempbx & 0xDFFF;
3558 }
3559 }
3560 }
3561
3562 if (!(tempbx & 0x2000)) {
3563 if (modeflag & HalfDCLK)
3564 tempcx = (tempcx & 0xFF00) | ((tempcx & 0x00FF) << 1);
3565
3566 push1 = tempbx;
3567 tempeax = pVBInfo->VGAHDE;
3568 tempebx = (tempcx & 0xFF00) >> 8;
3569 longtemp = tempeax * tempebx;
3570 tempecx = tempcx & 0x00FF;
3571 longtemp = longtemp / tempecx;
3572
3573 /* 301b */
3574 tempecx = 8 * 1024;
3575
Peter Huewe6896b942012-02-09 21:11:46 +01003576 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3577 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303578 tempecx = tempecx * 8;
3579 }
3580
3581 longtemp = longtemp * tempecx;
3582 tempecx = pVBInfo->HDE;
3583 temp2 = longtemp % tempecx;
3584 tempeax = longtemp / tempecx;
3585 if (temp2 != 0)
3586 tempeax += 1;
3587
3588 tempax = (unsigned short) tempeax;
3589
3590 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01003591 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
3592 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303593 tempcx = ((tempax & 0xFF00) >> 5) >> 8;
3594 }
3595 /* end 301b */
3596
3597 tempbx = push1;
3598 tempbx = (unsigned short) (((tempeax & 0x0000FF00) & 0x1F00)
3599 | (tempbx & 0x00FF));
3600 tempax = (unsigned short) (((tempeax & 0x000000FF) << 8)
3601 | (tempax & 0x00FF));
3602 temp = (tempax & 0xFF00) >> 8;
3603 } else {
3604 temp = (tempax & 0x00FF) >> 8;
3605 }
3606
Aaro Koskinen8104e322011-03-13 12:26:22 +02003607 xgifb_reg_set(pVBInfo->Part2Port, 0x44, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303608 temp = (tempbx & 0xFF00) >> 8;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003609 xgifb_reg_and_or(pVBInfo->Part2Port, 0x45, ~0x03F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303610 temp = tempcx & 0x00FF;
3611
3612 if (tempbx & 0x2000)
3613 temp = 0;
3614
3615 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3616 temp |= 0x18;
3617
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003618 xgifb_reg_and_or(pVBInfo->Part2Port, 0x46, ~0x1F, temp);
Peter Huewe599801f2012-02-09 21:11:45 +01003619 if (pVBInfo->TVInfo & TVSetPAL) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303620 tempbx = 0x0382;
3621 tempcx = 0x007e;
3622 } else {
3623 tempbx = 0x0369;
3624 tempcx = 0x0061;
3625 }
3626
3627 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003628 xgifb_reg_set(pVBInfo->Part2Port, 0x4b, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303629 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003630 xgifb_reg_set(pVBInfo->Part2Port, 0x4c, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303631
3632 temp = ((tempcx & 0xFF00) >> 8) & 0x03;
3633 temp = temp << 2;
3634 temp |= ((tempbx & 0xFF00) >> 8) & 0x03;
3635
Peter Huewe599801f2012-02-09 21:11:45 +01003636 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303637 temp |= 0x10;
3638
Peter Huewe599801f2012-02-09 21:11:45 +01003639 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303640 temp |= 0x20;
3641
Peter Huewe599801f2012-02-09 21:11:45 +01003642 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303643 temp |= 0x60;
3644 }
3645
Aaro Koskinen8104e322011-03-13 12:26:22 +02003646 xgifb_reg_set(pVBInfo->Part2Port, 0x4d, temp);
Aaro Koskinen58839b02011-03-13 12:26:23 +02003647 temp = xgifb_reg_get(pVBInfo->Part2Port, 0x43); /* 301b change */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003648 xgifb_reg_set(pVBInfo->Part2Port, 0x43, (unsigned short) (temp - 3));
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303649
Peter Huewe599801f2012-02-09 21:11:45 +01003650 if (!(pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303651 if (pVBInfo->TVInfo & NTSC1024x768) {
3652 TimingPoint = XGI_NTSC1024AdjTime;
3653 for (i = 0x1c, j = 0; i <= 0x30; i++, j++) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003654 xgifb_reg_set(pVBInfo->Part2Port, i,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303655 TimingPoint[j]);
3656 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02003657 xgifb_reg_set(pVBInfo->Part2Port, 0x43, 0x72);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303658 }
3659 }
3660
Miguel Gómez949eb0a2012-07-06 12:40:36 +02003661 /* Modify for 301C PALM Support */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303662 if (pVBInfo->VBType & VB_XGI301C) {
Peter Huewe599801f2012-02-09 21:11:45 +01003663 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003664 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x08,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303665 0x08); /* PALM Mode */
3666 }
3667
Peter Huewe599801f2012-02-09 21:11:45 +01003668 if (pVBInfo->TVInfo & TVSetPALM) {
Peter Huewe9388ad92013-02-15 20:37:10 +01003669 tempax = xgifb_reg_get(pVBInfo->Part2Port, 0x01);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303670 tempax--;
Aaro Koskinendc505562011-03-13 12:26:26 +02003671 xgifb_reg_and(pVBInfo->Part2Port, 0x01, tempax);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303672
Aaro Koskinendc505562011-03-13 12:26:26 +02003673 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xEF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303674 }
3675
Peter Huewe599801f2012-02-09 21:11:45 +01003676 if (pVBInfo->VBInfo & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303677 if (!(pVBInfo->VBInfo & SetInSlaveMode))
Aaro Koskinen8104e322011-03-13 12:26:22 +02003678 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303679 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303680}
3681
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003682static void XGI_SetLCDRegs(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303683 struct vb_device_info *pVBInfo)
3684{
Peter Hueweef9a6b92013-02-03 04:08:43 +01003685 unsigned short pushbx, tempax, tempbx, tempcx, temp, tempah,
3686 tempbh, tempch;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303687
Aaro Koskinenbdc9eb12012-11-04 21:14:47 +02003688 struct XGI_LCDDesStruct const *LCDBDesPtr = NULL;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303689
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003690 /* si+Ext_ResInfo */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303691 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
3692 return;
3693
3694 tempbx = pVBInfo->HDE; /* RHACTE=HDE-1 */
3695
3696 if (XGI_IsLCDDualLink(pVBInfo))
3697 tempbx = tempbx >> 1;
3698
3699 tempbx -= 1;
3700 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003701 xgifb_reg_set(pVBInfo->Part2Port, 0x2C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303702 temp = (tempbx & 0xFF00) >> 8;
3703 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003704 xgifb_reg_and_or(pVBInfo->Part2Port, 0x2B, 0x0F, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303705 temp = 0x01;
3706
Aaro Koskinen8104e322011-03-13 12:26:22 +02003707 xgifb_reg_set(pVBInfo->Part2Port, 0x0B, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303708 tempbx = pVBInfo->VDE; /* RTVACTEO=(VDE-1)&0xFF */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303709 tempbx--;
3710 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003711 xgifb_reg_set(pVBInfo->Part2Port, 0x03, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303712 temp = ((tempbx & 0xFF00) >> 8) & 0x07;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003713 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0C, ~0x07, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303714
3715 tempcx = pVBInfo->VT - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303716 temp = tempcx & 0x00FF; /* RVTVT=VT-1 */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003717 xgifb_reg_set(pVBInfo->Part2Port, 0x19, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303718 temp = (tempcx & 0xFF00) >> 8;
3719 temp = temp << 5;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003720 xgifb_reg_set(pVBInfo->Part2Port, 0x1A, temp);
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003721 xgifb_reg_and_or(pVBInfo->Part2Port, 0x09, 0xF0, 0x00);
3722 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0xF0, 0x00);
3723 xgifb_reg_and_or(pVBInfo->Part2Port, 0x17, 0xFB, 0x00);
3724 xgifb_reg_and_or(pVBInfo->Part2Port, 0x18, 0xDF, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303725
Justin P. Mattock558f7582012-10-02 21:17:11 -07003726 /* Customized LCDB Does not add */
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003727 if ((pVBInfo->VBType & VB_SIS301LV) || (pVBInfo->VBType & VB_SIS302LV))
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003728 LCDBDesPtr = XGI_GetLcdPtr(xgifb_lcddldes, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03003729 pVBInfo);
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003730 else
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003731 LCDBDesPtr = XGI_GetLcdPtr(XGI_LCDDesDataTable, ModeIdIndex,
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03003732 pVBInfo);
Aaro Koskinen9d1c6292012-11-04 21:14:46 +02003733
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303734 tempah = pVBInfo->LCDResInfo;
3735 tempah &= PanelResInfo;
3736
Peter Huewe255aabd2012-02-09 21:11:44 +01003737 if ((tempah == Panel_1024x768) || (tempah == Panel_1024x768x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303738 tempbx = 1024;
3739 tempcx = 768;
Peter Huewe255aabd2012-02-09 21:11:44 +01003740 } else if ((tempah == Panel_1280x1024) ||
3741 (tempah == Panel_1280x1024x75)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303742 tempbx = 1280;
3743 tempcx = 1024;
Peter Huewe255aabd2012-02-09 21:11:44 +01003744 } else if (tempah == Panel_1400x1050) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303745 tempbx = 1400;
3746 tempcx = 1050;
3747 } else {
3748 tempbx = 1600;
3749 tempcx = 1200;
3750 }
3751
3752 if (pVBInfo->LCDInfo & EnableScalingLCD) {
3753 tempbx = pVBInfo->HDE;
3754 tempcx = pVBInfo->VDE;
3755 }
3756
3757 pushbx = tempbx;
3758 tempax = pVBInfo->VT;
3759 pVBInfo->LCDHDES = LCDBDesPtr->LCDHDES;
3760 pVBInfo->LCDHRS = LCDBDesPtr->LCDHRS;
3761 pVBInfo->LCDVDES = LCDBDesPtr->LCDVDES;
3762 pVBInfo->LCDVRS = LCDBDesPtr->LCDVRS;
3763 tempbx = pVBInfo->LCDVDES;
3764 tempcx += tempbx;
3765
3766 if (tempcx >= tempax)
3767 tempcx -= tempax; /* lcdvdes */
3768
3769 temp = tempbx & 0x00FF; /* RVEQ1EQ=lcdvdes */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003770 xgifb_reg_set(pVBInfo->Part2Port, 0x05, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303771 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003772 xgifb_reg_set(pVBInfo->Part2Port, 0x06, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303773 tempch = ((tempcx & 0xFF00) >> 8) & 0x07;
3774 tempbh = ((tempbx & 0xFF00) >> 8) & 0x07;
3775 tempah = tempch;
3776 tempah = tempah << 3;
3777 tempah |= tempbh;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003778 xgifb_reg_set(pVBInfo->Part2Port, 0x02, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303779
3780 /* getlcdsync() */
3781 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3782 tempcx = tempbx;
3783 tempax = pVBInfo->VT;
3784 tempbx = pVBInfo->LCDVRS;
3785
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303786 tempcx += tempbx;
3787 if (tempcx >= tempax)
3788 tempcx -= tempax;
3789
3790 temp = tempbx & 0x00FF; /* RTVACTEE=lcdvrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003791 xgifb_reg_set(pVBInfo->Part2Port, 0x04, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303792 temp = (tempbx & 0xFF00) >> 8;
3793 temp = temp << 4;
3794 temp |= (tempcx & 0x000F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02003795 xgifb_reg_set(pVBInfo->Part2Port, 0x01, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303796 tempcx = pushbx;
3797 tempax = pVBInfo->HT;
3798 tempbx = pVBInfo->LCDHDES;
3799 tempbx &= 0x0FFF;
3800
3801 if (XGI_IsLCDDualLink(pVBInfo)) {
3802 tempax = tempax >> 1;
3803 tempbx = tempbx >> 1;
3804 tempcx = tempcx >> 1;
3805 }
3806
Peter Huewe6896b942012-02-09 21:11:46 +01003807 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303808 tempbx += 1;
3809
3810 if (pVBInfo->VBType & VB_XGI301C) /* tap4 */
3811 tempbx += 1;
3812
3813 tempcx += tempbx;
3814
3815 if (tempcx >= tempax)
3816 tempcx -= tempax;
3817
3818 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003819 xgifb_reg_set(pVBInfo->Part2Port, 0x1F, temp); /* RHBLKE=lcdhdes */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303820 temp = ((tempbx & 0xFF00) >> 8) << 4;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003821 xgifb_reg_set(pVBInfo->Part2Port, 0x20, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303822 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003823 xgifb_reg_set(pVBInfo->Part2Port, 0x23, temp); /* RHEQPLE=lcdhdee */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303824 temp = (tempcx & 0xFF00) >> 8;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003825 xgifb_reg_set(pVBInfo->Part2Port, 0x25, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303826
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303827 XGI_GetLCDSync(&tempax, &tempbx, pVBInfo);
3828 tempcx = tempax;
3829 tempax = pVBInfo->HT;
3830 tempbx = pVBInfo->LCDHRS;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303831 if (XGI_IsLCDDualLink(pVBInfo)) {
3832 tempax = tempax >> 1;
3833 tempbx = tempbx >> 1;
3834 tempcx = tempcx >> 1;
3835 }
3836
Peter Huewe6896b942012-02-09 21:11:46 +01003837 if (pVBInfo->VBType & VB_SIS302LV)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303838 tempbx += 1;
3839
3840 tempcx += tempbx;
3841
3842 if (tempcx >= tempax)
3843 tempcx -= tempax;
3844
3845 temp = tempbx & 0x00FF; /* RHBURSTS=lcdhrs */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003846 xgifb_reg_set(pVBInfo->Part2Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303847
3848 temp = (tempbx & 0xFF00) >> 8;
3849 temp = temp << 4;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02003850 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1D, ~0x0F0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303851 temp = tempcx & 0x00FF; /* RHSYEXP2S=lcdhre */
Aaro Koskinen8104e322011-03-13 12:26:22 +02003852 xgifb_reg_set(pVBInfo->Part2Port, 0x21, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303853
Peter Huewea3d675c2012-02-09 21:11:47 +01003854 if (!(pVBInfo->LCDInfo & XGI_LCDVESATiming)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303855 if (pVBInfo->VGAVDE == 525) {
Peter Huewe6896b942012-02-09 21:11:46 +01003856 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3857 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303858 | VB_XGI301C)) {
3859 temp = 0xC6;
3860 } else
3861 temp = 0xC4;
3862
Aaro Koskinen8104e322011-03-13 12:26:22 +02003863 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
3864 xgifb_reg_set(pVBInfo->Part2Port, 0x30, 0xB3);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303865 }
3866
3867 if (pVBInfo->VGAVDE == 420) {
Peter Huewe6896b942012-02-09 21:11:46 +01003868 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B
3869 | VB_SIS301LV | VB_SIS302LV
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303870 | VB_XGI301C)) {
3871 temp = 0x4F;
3872 } else
3873 temp = 0x4E;
Aaro Koskinen8104e322011-03-13 12:26:22 +02003874 xgifb_reg_set(pVBInfo->Part2Port, 0x2f, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303875 }
3876 }
3877}
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003878
3879/* --------------------------------------------------------------------- */
3880/* Function : XGI_GetTap4Ptr */
3881/* Input : */
3882/* Output : di -> Tap4 Reg. Setting Pointer */
3883/* Description : */
3884/* --------------------------------------------------------------------- */
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003885static struct XGI301C_Tap4TimingStruct const
3886*XGI_GetTap4Ptr(unsigned short tempcx, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003887{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303888 unsigned short tempax, tempbx, i;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003889 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003890
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303891 if (tempcx == 0) {
3892 tempax = pVBInfo->VGAHDE;
3893 tempbx = pVBInfo->HDE;
3894 } else {
3895 tempax = pVBInfo->VGAVDE;
3896 tempbx = pVBInfo->VDE;
3897 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003898
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003899 if (tempax <= tempbx)
3900 return &xgifb_tap4_timing[0];
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303901 else
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003902 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing; /* NTSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003903
Peter Huewe599801f2012-02-09 21:11:45 +01003904 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303905 Tap4TimingPtr = PALTap4Timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003906
Peter Huewe599801f2012-02-09 21:11:45 +01003907 if (pVBInfo->VBInfo & SetCRT2ToYPbPr525750) {
3908 if ((pVBInfo->TVInfo & TVSetYPbPr525i) ||
3909 (pVBInfo->TVInfo & TVSetYPbPr525p))
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003910 Tap4TimingPtr = xgifb_ntsc_525_tap4_timing;
Peter Huewe599801f2012-02-09 21:11:45 +01003911 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303912 Tap4TimingPtr = YPbPr750pTap4Timing;
3913 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003914
Peter Huewe599801f2012-02-09 21:11:45 +01003915 if (pVBInfo->VBInfo & SetCRT2ToHiVision)
Aaro Koskinen11fbdcd2011-08-31 21:46:10 +03003916 Tap4TimingPtr = xgifb_tap4_timing;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003917
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303918 i = 0;
3919 while (Tap4TimingPtr[i].DE != 0xFFFF) {
3920 if (Tap4TimingPtr[i].DE == tempax)
3921 break;
3922 i++;
3923 }
3924 return &Tap4TimingPtr[i];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003925}
3926
Aaro Koskinen063b9c42011-03-08 22:16:13 +02003927static void XGI_SetTap4Regs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003928{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303929 unsigned short i, j;
Aaro Koskinen1cccd9e2012-11-04 21:15:06 +02003930 struct XGI301C_Tap4TimingStruct const *Tap4TimingPtr;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003931
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303932 if (!(pVBInfo->VBType & VB_XGI301C))
3933 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003934
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303935 Tap4TimingPtr = XGI_GetTap4Ptr(0, pVBInfo); /* Set Horizontal Scaling */
3936 for (i = 0x80, j = 0; i <= 0xBF; i++, j++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02003937 xgifb_reg_set(pVBInfo->Part2Port, i, Tap4TimingPtr->Reg[j]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003938
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003939 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01003940 (!(pVBInfo->VBInfo & SetCRT2ToHiVision))) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003941 /* Set Vertical Scaling */
3942 Tap4TimingPtr = XGI_GetTap4Ptr(1, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303943 for (i = 0xC0, j = 0; i < 0xFF; i++, j++)
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003944 xgifb_reg_set(pVBInfo->Part2Port,
3945 i,
3946 Tap4TimingPtr->Reg[j]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303947 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003948
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003949 if ((pVBInfo->VBInfo & SetCRT2ToTV) &&
Peter Huewe599801f2012-02-09 21:11:45 +01003950 (!(pVBInfo->VBInfo & SetCRT2ToHiVision)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003951 /* Enable V.Scaling */
3952 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x04);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303953 else
Kenji Toyama1d7f6562011-04-23 19:36:49 +08003954 /* Enable H.Scaling */
3955 xgifb_reg_and_or(pVBInfo->Part2Port, 0x4E, ~0x14, 0x10);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003956}
3957
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03003958static void XGI_SetGroup3(unsigned short ModeIdIndex,
3959 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003960{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303961 unsigned short i;
Aaro Koskinend21222d2012-09-11 00:15:29 +03003962 unsigned char const *tempdi;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303963 unsigned short modeflag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003964
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03003965 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02003966 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003967
Aaro Koskinen8104e322011-03-13 12:26:22 +02003968 xgifb_reg_set(pVBInfo->Part3Port, 0x00, 0x00);
Peter Huewe599801f2012-02-09 21:11:45 +01003969 if (pVBInfo->TVInfo & TVSetPAL) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003970 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
3971 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303972 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003973 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xF5);
3974 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xB7);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303975 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003976
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303977 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
3978 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003979
Peter Huewe599801f2012-02-09 21:11:45 +01003980 if (pVBInfo->TVInfo & TVSetPALM) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02003981 xgifb_reg_set(pVBInfo->Part3Port, 0x13, 0xFA);
3982 xgifb_reg_set(pVBInfo->Part3Port, 0x14, 0xC8);
3983 xgifb_reg_set(pVBInfo->Part3Port, 0x3D, 0xA8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303984 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003985
Peter Huewe599801f2012-02-09 21:11:45 +01003986 if ((pVBInfo->VBInfo & SetCRT2ToHiVision) || (pVBInfo->VBInfo
3987 & SetCRT2ToYPbPr525750)) {
3988 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303989 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003990
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003991 tempdi = XGI330_HiTVGroup3Data;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303992 if (pVBInfo->SetFlag & TVSimuMode) {
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003993 tempdi = XGI330_HiTVGroup3Simu;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303994 if (!(modeflag & Charx8Dot))
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003995 tempdi = XGI330_HiTVGroup3Text;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05303996 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02003997
Peter Huewe599801f2012-02-09 21:11:45 +01003998 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03003999 tempdi = XGI330_Ren525pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004000
Peter Huewe599801f2012-02-09 21:11:45 +01004001 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Aaro Koskinen073b61e2012-09-11 00:15:28 +03004002 tempdi = XGI330_Ren750pGroup3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004003
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304004 for (i = 0; i <= 0x3E; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004005 xgifb_reg_set(pVBInfo->Part3Port, i, tempdi[i]);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004006
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304007 if (pVBInfo->VBType & VB_XGI301C) { /* Marcovision */
Peter Huewe599801f2012-02-09 21:11:45 +01004008 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Aaro Koskinen8104e322011-03-13 12:26:22 +02004009 xgifb_reg_set(pVBInfo->Part3Port, 0x28, 0x3f);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304010 }
4011 }
Aaro Koskinen2351d1f2013-05-29 23:59:13 +03004012}
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304013
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004014static void XGI_SetGroup4(unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304015 unsigned short RefreshRateTableIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304016 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004017{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304018 unsigned short tempax, tempcx, tempbx, modeflag, temp, temp2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004019
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304020 unsigned long tempebx, tempeax, templong;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004021
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004022 /* si+Ext_ResInfo */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004023 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304024 temp = pVBInfo->RVBHCFACT;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004025 xgifb_reg_set(pVBInfo->Part4Port, 0x13, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004026
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304027 tempbx = pVBInfo->RVBHCMAX;
4028 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004029 xgifb_reg_set(pVBInfo->Part4Port, 0x14, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304030 temp2 = ((tempbx & 0xFF00) >> 8) << 7;
4031 tempcx = pVBInfo->VGAHT - 1;
4032 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004033 xgifb_reg_set(pVBInfo->Part4Port, 0x16, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004034
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304035 temp = ((tempcx & 0xFF00) >> 8) << 3;
4036 temp2 |= temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004037
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304038 tempcx = pVBInfo->VGAVT - 1;
4039 if (!(pVBInfo->VBInfo & SetCRT2ToTV))
4040 tempcx -= 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004041
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304042 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004043 xgifb_reg_set(pVBInfo->Part4Port, 0x17, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304044 temp = temp2 | ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004045 xgifb_reg_set(pVBInfo->Part4Port, 0x15, temp);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004046 xgifb_reg_or(pVBInfo->Part4Port, 0x0D, 0x08);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304047 tempcx = pVBInfo->VBInfo;
4048 tempbx = pVBInfo->VGAHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004049
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304050 if (modeflag & HalfDCLK)
4051 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004052
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304053 if (XGI_IsLCDDualLink(pVBInfo))
4054 tempbx = tempbx >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004055
Peter Huewe599801f2012-02-09 21:11:45 +01004056 if (tempcx & SetCRT2ToHiVision) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304057 temp = 0;
4058 if (tempbx <= 1024)
4059 temp = 0xA0;
4060 if (tempbx == 1280)
4061 temp = 0xC0;
4062 } else if (tempcx & SetCRT2ToTV) {
4063 temp = 0xA0;
4064 if (tempbx <= 800)
4065 temp = 0x80;
4066 } else {
4067 temp = 0x80;
4068 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4069 temp = 0;
4070 if (tempbx > 800)
4071 temp = 0x60;
4072 }
4073 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004074
Peter Huewe599801f2012-02-09 21:11:45 +01004075 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304076 temp = 0x00;
4077 if (pVBInfo->VGAHDE == 1280)
4078 temp = 0x40;
4079 if (pVBInfo->VGAHDE == 1024)
4080 temp = 0x20;
4081 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004082 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0E, ~0xEF, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004083
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304084 tempebx = pVBInfo->VDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004085
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304086 tempcx = pVBInfo->RVBHRS;
4087 temp = tempcx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004088 xgifb_reg_set(pVBInfo->Part4Port, 0x18, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004089
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304090 tempeax = pVBInfo->VGAVDE;
4091 tempcx |= 0x04000;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004092
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304093 if (tempeax <= tempebx) {
4094 tempcx = (tempcx & (~0x4000));
4095 tempeax = pVBInfo->VGAVDE;
4096 } else {
4097 tempeax -= tempebx;
4098 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004099
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304100 templong = (tempeax * 256 * 1024) % tempebx;
4101 tempeax = (tempeax * 256 * 1024) / tempebx;
4102 tempebx = tempeax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004103
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304104 if (templong != 0)
4105 tempebx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004106
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304107 temp = (unsigned short) (tempebx & 0x000000FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004108 xgifb_reg_set(pVBInfo->Part4Port, 0x1B, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004109
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304110 temp = (unsigned short) ((tempebx & 0x0000FF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004111 xgifb_reg_set(pVBInfo->Part4Port, 0x1A, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304112 tempbx = (unsigned short) (tempebx >> 16);
4113 temp = tempbx & 0x00FF;
4114 temp = temp << 4;
4115 temp |= ((tempcx & 0xFF00) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004116 xgifb_reg_set(pVBInfo->Part4Port, 0x19, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004117
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304118 /* 301b */
Peter Huewe6896b942012-02-09 21:11:46 +01004119 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4120 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304121 temp = 0x0028;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004122 xgifb_reg_set(pVBInfo->Part4Port, 0x1C, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304123 tempax = pVBInfo->VGAHDE;
4124 if (modeflag & HalfDCLK)
4125 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004126
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304127 if (XGI_IsLCDDualLink(pVBInfo))
4128 tempax = tempax >> 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004129
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304130 if (pVBInfo->VBInfo & SetCRT2ToLCD) {
4131 if (tempax > 800)
4132 tempax -= 800;
Aaro Koskinend3ae5762012-09-11 00:15:27 +03004133 } else if (pVBInfo->VGAHDE > 800) {
4134 if (pVBInfo->VGAHDE == 1024)
4135 tempax = (tempax * 25 / 32) - 1;
4136 else
4137 tempax = (tempax * 20 / 32) - 1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304138 }
4139 tempax -= 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004140
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304141 temp = (tempax & 0xFF00) >> 8;
4142 temp = ((temp & 0x0003) << 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004143 xgifb_reg_set(pVBInfo->Part4Port, 0x1E, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304144 temp = (tempax & 0x00FF);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004145 xgifb_reg_set(pVBInfo->Part4Port, 0x1D, temp);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004146
Peter Huewe599801f2012-02-09 21:11:45 +01004147 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToHiVision)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304148 if (pVBInfo->VGAHDE > 800)
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004149 xgifb_reg_or(pVBInfo->Part4Port, 0x1E, 0x08);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004150
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304151 }
4152 temp = 0x0036;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004153
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304154 if (pVBInfo->VBInfo & SetCRT2ToTV) {
4155 if (!(pVBInfo->TVInfo & (NTSC1024x768
Peter Huewe599801f2012-02-09 21:11:45 +01004156 | TVSetYPbPr525p | TVSetYPbPr750p
4157 | TVSetHiVision))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304158 temp |= 0x0001;
4159 if ((pVBInfo->VBInfo & SetInSlaveMode)
4160 && (!(pVBInfo->TVInfo
4161 & TVSimuMode)))
4162 temp &= (~0x0001);
4163 }
4164 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004165
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004166 xgifb_reg_and_or(pVBInfo->Part4Port, 0x1F, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304167 tempbx = pVBInfo->HT;
4168 if (XGI_IsLCDDualLink(pVBInfo))
4169 tempbx = tempbx >> 1;
4170 tempbx = (tempbx >> 1) - 2;
4171 temp = ((tempbx & 0x0700) >> 8) << 3;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004172 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, 0x00C0, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304173 temp = tempbx & 0x00FF;
Aaro Koskinen8104e322011-03-13 12:26:22 +02004174 xgifb_reg_set(pVBInfo->Part4Port, 0x22, temp);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304175 }
4176 /* end 301b */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004177
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004178 XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004179}
4180
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004181static void XGINew_EnableCRT2(struct vb_device_info *pVBInfo)
4182{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004183 xgifb_reg_and_or(pVBInfo->P3c4, 0x1E, 0xFF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004184}
4185
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004186static void XGI_SetGroup5(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004187{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304188 if (pVBInfo->ModeType == ModeVGA) {
4189 if (!(pVBInfo->VBInfo & (SetInSlaveMode | LoadDACFlag
Peter Huewe6896b942012-02-09 21:11:46 +01004190 | DisableCRT2Display))) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304191 XGINew_EnableCRT2(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304192 }
4193 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004194}
4195
Aaro Koskinenb053af12013-07-16 23:13:28 +03004196static void XGI_DisableGatingCRT(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004197{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004198 xgifb_reg_and_or(pVBInfo->P3d4, 0x63, 0xBF, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004199}
4200
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004201static unsigned char XGI_XG21CheckLVDSMode(struct xgifb_video_info *xgifb_info,
4202 unsigned short ModeNo, unsigned short ModeIdIndex,
4203 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004204{
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004205 unsigned short xres, yres, colordepth, modeflag, resindex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004206
Aaro Koskinenb3979922012-11-04 21:14:52 +02004207 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004208 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4209 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004210 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004211 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004212
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304213 if (!(modeflag & Charx8Dot)) {
4214 xres /= 9;
4215 xres *= 8;
4216 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004217
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004218 if ((ModeNo > 0x13) && (modeflag & HalfDCLK))
4219 xres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004220
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004221 if ((ModeNo > 0x13) && (modeflag & DoubleScanMode))
4222 yres *= 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004223
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004224 if (xres > xgifb_info->lvds_data.LVDSHDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304225 return 0;
Bill Pembertondda08c52010-06-17 13:10:42 -04004226
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004227 if (yres > xgifb_info->lvds_data.LVDSVDE)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304228 return 0;
4229
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004230 if (xres != xgifb_info->lvds_data.LVDSHDE ||
4231 yres != xgifb_info->lvds_data.LVDSVDE) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004232 colordepth = XGI_GetColorDepth(ModeIdIndex, pVBInfo);
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004233 if (colordepth > 2)
4234 return 0;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304235 }
4236 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004237}
4238
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004239static void xgifb_set_lvds(struct xgifb_video_info *xgifb_info,
4240 int chip_id,
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004241 unsigned short ModeIdIndex,
4242 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004243{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304244 unsigned char temp, Miscdata;
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004245 unsigned short xres, yres, modeflag, resindex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304246 unsigned short LVDSHT, LVDSHBS, LVDSHRS, LVDSHRE, LVDSHBE;
4247 unsigned short LVDSVT, LVDSVBS, LVDSVRS, LVDSVRE, LVDSVBE;
4248 unsigned short value;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004249
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004250 temp = (unsigned char) ((xgifb_info->lvds_data.LVDS_Capability &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004251 (LCDPolarity << 8)) >> 8);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304252 temp &= LCDPolarity;
Peter Huewe9388ad92013-02-15 20:37:10 +01004253 Miscdata = inb(pVBInfo->P3cc);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004254
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004255 outb((Miscdata & 0x3F) | temp, pVBInfo->P3c2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004256
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004257 temp = xgifb_info->lvds_data.LVDS_Capability & LCDPolarity;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004258 /* SR35[7] FP VSync polarity */
4259 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x80, temp & 0x80);
4260 /* SR30[5] FP HSync polarity */
4261 xgifb_reg_and_or(pVBInfo->P3c4, 0x30, ~0x20, (temp & 0x40) >> 1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004262
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004263 if (chip_id == XG27)
4264 XGI_SetXG27FPBits(pVBInfo);
4265 else
4266 XGI_SetXG21FPBits(pVBInfo);
4267
Aaro Koskinenb3979922012-11-04 21:14:52 +02004268 resindex = XGI330_EModeIDTable[ModeIdIndex].Ext_RESINFO;
Aaro Koskinene8e6c752012-11-04 21:15:00 +02004269 xres = XGI330_ModeResInfo[resindex].HTotal; /* xres->ax */
4270 yres = XGI330_ModeResInfo[resindex].VTotal; /* yres->bx */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004271 /* si+St_ModeFlag */
Aaro Koskinenb3979922012-11-04 21:14:52 +02004272 modeflag = XGI330_EModeIDTable[ModeIdIndex].Ext_ModeFlag;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004273
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304274 if (!(modeflag & Charx8Dot))
4275 xres = xres * 8 / 9;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004276
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004277 LVDSHT = xgifb_info->lvds_data.LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004278
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004279 LVDSHBS = xres + (xgifb_info->lvds_data.LVDSHDE - xres) / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004280
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304281 if (LVDSHBS > LVDSHT)
4282 LVDSHBS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004283
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004284 LVDSHRS = LVDSHBS + xgifb_info->lvds_data.LVDSHFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304285 if (LVDSHRS > LVDSHT)
4286 LVDSHRS -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004287
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004288 LVDSHRE = LVDSHRS + xgifb_info->lvds_data.LVDSHSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304289 if (LVDSHRE > LVDSHT)
4290 LVDSHRE -= LVDSHT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004291
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004292 LVDSHBE = LVDSHBS + LVDSHT - xgifb_info->lvds_data.LVDSHDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004293
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004294 LVDSVT = xgifb_info->lvds_data.LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004295
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004296 LVDSVBS = yres + (xgifb_info->lvds_data.LVDSVDE - yres) / 2;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004297 if (modeflag & DoubleScanMode)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304298 LVDSVBS += yres / 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004299
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304300 if (LVDSVBS > LVDSVT)
4301 LVDSVBS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004302
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004303 LVDSVRS = LVDSVBS + xgifb_info->lvds_data.LVDSVFP;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304304 if (LVDSVRS > LVDSVT)
4305 LVDSVRS -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004306
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004307 LVDSVRE = LVDSVRS + xgifb_info->lvds_data.LVDSVSYNC;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304308 if (LVDSVRE > LVDSVT)
4309 LVDSVRE -= LVDSVT;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004310
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004311 LVDSVBE = LVDSVBS + LVDSVT - xgifb_info->lvds_data.LVDSVDE;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004312
Peter Huewe9388ad92013-02-15 20:37:10 +01004313 temp = xgifb_reg_get(pVBInfo->P3d4, 0x11);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004314 xgifb_reg_set(pVBInfo->P3d4, 0x11, temp & 0x7f); /* Unlock CRTC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004315
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304316 if (!(modeflag & Charx8Dot))
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004317 xgifb_reg_or(pVBInfo->P3c4, 0x1, 0x1);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004318
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304319 /* HT SR0B[1:0] CR00 */
4320 value = (LVDSHT >> 3) - 5;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004321 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004322 xgifb_reg_set(pVBInfo->P3d4, 0x0, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004323
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304324 /* HBS SR0B[5:4] CR02 */
4325 value = (LVDSHBS >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004326 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0x30, (value & 0x300) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004327 xgifb_reg_set(pVBInfo->P3d4, 0x2, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004328
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304329 /* HBE SR0C[1:0] CR05[7] CR03[4:0] */
4330 value = (LVDSHBE >> 3) - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004331 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x03, (value & 0xC0) >> 6);
4332 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x80, (value & 0x20) << 2);
4333 xgifb_reg_and_or(pVBInfo->P3d4, 0x03, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004334
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304335 /* HRS SR0B[7:6] CR04 */
4336 value = (LVDSHRS >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004337 xgifb_reg_and_or(pVBInfo->P3c4, 0x0B, ~0xC0, (value & 0x300) >> 2);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004338 xgifb_reg_set(pVBInfo->P3d4, 0x4, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004339
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304340 /* Panel HRS SR2F[1:0] SR2E[7:0] */
4341 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004342 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0x03, (value & 0x300) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004343 xgifb_reg_set(pVBInfo->P3c4, 0x2E, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004344
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304345 /* HRE SR0C[2] CR05[4:0] */
4346 value = (LVDSHRE >> 3) + 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004347 xgifb_reg_and_or(pVBInfo->P3c4, 0x0C, ~0x04, (value & 0x20) >> 3);
4348 xgifb_reg_and_or(pVBInfo->P3d4, 0x05, ~0x1F, value & 0x1F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004349
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304350 /* Panel HRE SR2F[7:2] */
4351 value--;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004352 xgifb_reg_and_or(pVBInfo->P3c4, 0x2F, ~0xFC, value << 2);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004353
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304354 /* VT SR0A[0] CR07[5][0] CR06 */
4355 value = LVDSVT - 2;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004356 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x01, (value & 0x400) >> 10);
4357 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x20, (value & 0x200) >> 4);
4358 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x01, (value & 0x100) >> 8);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004359 xgifb_reg_set(pVBInfo->P3d4, 0x06, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004360
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304361 /* VBS SR0A[2] CR09[5] CR07[3] CR15 */
4362 value = LVDSVBS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004363 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x04, (value & 0x400) >> 8);
4364 xgifb_reg_and_or(pVBInfo->P3d4, 0x09, ~0x20, (value & 0x200) >> 4);
4365 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x08, (value & 0x100) >> 5);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004366 xgifb_reg_set(pVBInfo->P3d4, 0x15, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004367
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304368 /* VBE SR0A[4] CR16 */
4369 value = LVDSVBE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004370 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x10, (value & 0x100) >> 4);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004371 xgifb_reg_set(pVBInfo->P3d4, 0x16, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004372
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304373 /* VRS SR0A[3] CR7[7][2] CR10 */
4374 value = LVDSVRS - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004375 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x08, (value & 0x400) >> 7);
4376 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x80, (value & 0x200) >> 2);
4377 xgifb_reg_and_or(pVBInfo->P3d4, 0x07, ~0x04, (value & 0x100) >> 6);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004378 xgifb_reg_set(pVBInfo->P3d4, 0x10, (value & 0xFF));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004379
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004380 if (chip_id == XG27) {
4381 /* Panel VRS SR35[2:0] SR34[7:0] */
4382 xgifb_reg_and_or(pVBInfo->P3c4, 0x35, ~0x07,
4383 (value & 0x700) >> 8);
4384 xgifb_reg_set(pVBInfo->P3c4, 0x34, value & 0xFF);
4385 } else {
4386 /* Panel VRS SR3F[1:0] SR34[7:0] SR33[0] */
4387 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0x03,
4388 (value & 0x600) >> 9);
4389 xgifb_reg_set(pVBInfo->P3c4, 0x34, (value >> 1) & 0xFF);
4390 xgifb_reg_and_or(pVBInfo->P3d4, 0x33, ~0x01, value & 0x01);
4391 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004392
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304393 /* VRE SR0A[5] CR11[3:0] */
4394 value = LVDSVRE - 1;
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004395 xgifb_reg_and_or(pVBInfo->P3c4, 0x0A, ~0x20, (value & 0x10) << 1);
4396 xgifb_reg_and_or(pVBInfo->P3d4, 0x11, ~0x0F, value & 0x0F);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004397
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304398 /* Panel VRE SR3F[7:2] */
Aaro Koskinen64db29f2011-08-31 21:46:01 +03004399 if (chip_id == XG27)
4400 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4401 (value << 2) & 0xFC);
4402 else
4403 /* SR3F[7] has to be 0, h/w bug */
4404 xgifb_reg_and_or(pVBInfo->P3c4, 0x3F, ~0xFC,
4405 (value << 2) & 0x7C);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004406
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304407 for (temp = 0, value = 0; temp < 3; temp++) {
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004408
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004409 xgifb_reg_and_or(pVBInfo->P3c4, 0x31, ~0x30, value);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004410 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004411 0x2B, xgifb_info->lvds_data.VCLKData1);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004412 xgifb_reg_set(pVBInfo->P3c4,
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004413 0x2C, xgifb_info->lvds_data.VCLKData2);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304414 value += 0x10;
4415 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004416
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304417 if (!(modeflag & Charx8Dot)) {
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004418 inb(pVBInfo->P3da); /* reset 3da */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004419 outb(0x13, pVBInfo->P3c0); /* set index */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004420 /* set data, panning = 0, shift left 1 dot*/
4421 outb(0x00, pVBInfo->P3c0);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004422
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004423 inb(pVBInfo->P3da); /* Enable Attribute */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02004424 outb(0x20, pVBInfo->P3c0);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304425
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02004426 inb(pVBInfo->P3da); /* reset 3da */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304427 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004428
4429}
4430
4431/* --------------------------------------------------------------------- */
4432/* Function : XGI_IsLCDON */
4433/* Input : */
Bill Pembertondda08c52010-06-17 13:10:42 -04004434/* Output : 0 : Skip PSC Control */
4435/* 1: Disable PSC */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004436/* Description : */
4437/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004438static unsigned char XGI_IsLCDON(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004439{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304440 unsigned short tempax;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004441
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304442 tempax = pVBInfo->VBInfo;
4443 if (tempax & SetCRT2ToDualEdge)
4444 return 0;
Peter Huewe6896b942012-02-09 21:11:46 +01004445 else if (tempax & (DisableCRT2Display | SwitchCRT2 | SetSimuScanMode))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304446 return 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004447
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304448 return 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004449}
4450
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004451static void XGI_DisableBridge(struct xgifb_video_info *xgifb_info,
4452 struct xgi_hw_device_info *HwDeviceExtension,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304453 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004454{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02004455 unsigned short tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004456
Peter Huewe6896b942012-02-09 21:11:46 +01004457 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4458 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304459 tempah = 0x3F;
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004460 if (!(pVBInfo->VBInfo &
4461 (DisableCRT2Display | SetSimuScanMode))) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004462 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinen41fc5f02013-05-29 23:59:12 +03004463 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304464 tempah = 0x7F; /* Disable Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304465 }
4466 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004467
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004468 /* disable part4_1f */
4469 xgifb_reg_and(pVBInfo->Part4Port, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004470
Peter Huewe6896b942012-02-09 21:11:46 +01004471 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004472 if (((pVBInfo->VBInfo &
Peter Huewe06cc47b2013-02-03 22:54:38 +01004473 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))) ||
Peter Huewe06cc47b2013-02-03 22:54:38 +01004474 (XGI_IsLCDON(pVBInfo)))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004475 /* LVDS Driver power down */
4476 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304477 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004478
Aaro Koskinend1724632013-05-29 23:59:09 +03004479 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA |
4480 SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004481 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004482
Aaro Koskinen41fc5f02013-05-29 23:59:12 +03004483 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
4484 /* Power down */
4485 xgifb_reg_and(pVBInfo->Part1Port, 0x1e, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004486
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004487 /* disable TV as primary VGA swap */
4488 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004489
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304490 if ((pVBInfo->VBInfo & (SetSimuScanMode | SetCRT2ToDualEdge)))
Aaro Koskinendc505562011-03-13 12:26:26 +02004491 xgifb_reg_and(pVBInfo->Part2Port, 0x00, 0xdf);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004492
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03004493 if ((pVBInfo->VBInfo &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004494 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004495 ((!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) &&
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004496 (pVBInfo->VBInfo &
4497 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004498 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004499
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03004500 if ((pVBInfo->VBInfo &
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004501 (DisableCRT2Display | SetSimuScanMode)) ||
Peter Huewea3d675c2012-02-09 21:11:47 +01004502 (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) ||
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004503 (pVBInfo->VBInfo &
4504 (SetCRT2ToRAMDAC | SetCRT2ToLCD | SetCRT2ToTV))) {
4505 /* save Part1 index 0 */
4506 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
4507 /* BTDAC = 1, avoid VB reset */
4508 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x10);
4509 /* disable CRT2 */
4510 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4511 /* restore Part1 index 0 */
4512 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304513 }
4514 } else { /* {301} */
4515 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004516 xgifb_reg_or(pVBInfo->Part1Port, 0x00, 0x80);
4517 /* Disable CRT2 */
4518 xgifb_reg_and(pVBInfo->Part1Port, 0x1E, 0xDF);
4519 /* Disable TV asPrimary VGA swap */
4520 xgifb_reg_and(pVBInfo->P3c4, 0x32, 0xDF);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304521 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004522
Peter Huewea3d675c2012-02-09 21:11:47 +01004523 if (pVBInfo->VBInfo & (DisableCRT2Display | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304524 | SetSimuScanMode))
Aaro Koskinenfab04b92011-12-06 00:10:45 +02004525 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304526 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004527}
4528
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004529/* --------------------------------------------------------------------- */
4530/* Function : XGI_GetTVPtrIndex */
4531/* Input : */
4532/* Output : */
4533/* Description : bx 0 : ExtNTSC */
4534/* 1 : StNTSC */
4535/* 2 : ExtPAL */
4536/* 3 : StPAL */
4537/* 4 : ExtHiTV */
4538/* 5 : StHiTV */
4539/* 6 : Ext525i */
4540/* 7 : St525i */
4541/* 8 : Ext525p */
4542/* 9 : St525p */
4543/* A : Ext750p */
4544/* B : St750p */
4545/* --------------------------------------------------------------------- */
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004546static unsigned short XGI_GetTVPtrIndex(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004547{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304548 unsigned short tempbx = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004549
Peter Huewe599801f2012-02-09 21:11:45 +01004550 if (pVBInfo->TVInfo & TVSetPAL)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304551 tempbx = 2;
Peter Huewe599801f2012-02-09 21:11:45 +01004552 if (pVBInfo->TVInfo & TVSetHiVision)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304553 tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004554 if (pVBInfo->TVInfo & TVSetYPbPr525i)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304555 tempbx = 6;
Peter Huewe599801f2012-02-09 21:11:45 +01004556 if (pVBInfo->TVInfo & TVSetYPbPr525p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304557 tempbx = 8;
Peter Huewe599801f2012-02-09 21:11:45 +01004558 if (pVBInfo->TVInfo & TVSetYPbPr750p)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304559 tempbx = 10;
4560 if (pVBInfo->TVInfo & TVSimuMode)
4561 tempbx++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004562
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304563 return tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004564}
4565
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004566/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004567/* Function : XGI_GetTVPtrIndex2 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004568/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004569/* Output : bx 0 : NTSC */
4570/* 1 : PAL */
4571/* 2 : PALM */
4572/* 3 : PALN */
4573/* 4 : NTSC1024x768 */
4574/* 5 : PAL-M 1024x768 */
4575/* 6-7: reserved */
4576/* cl 0 : YFilter1 */
4577/* 1 : YFilter2 */
4578/* ch 0 : 301A */
4579/* 1 : 301B/302B/301LV/302LV */
4580/* Description : */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004581/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004582static void XGI_GetTVPtrIndex2(unsigned short *tempbx, unsigned char *tempcl,
4583 unsigned char *tempch, struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004584{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004585 *tempbx = 0;
4586 *tempcl = 0;
4587 *tempch = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004588
Peter Huewe599801f2012-02-09 21:11:45 +01004589 if (pVBInfo->TVInfo & TVSetPAL)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004590 *tempbx = 1;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004591
Peter Huewe599801f2012-02-09 21:11:45 +01004592 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004593 *tempbx = 2;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004594
Peter Huewe599801f2012-02-09 21:11:45 +01004595 if (pVBInfo->TVInfo & TVSetPALN)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004596 *tempbx = 3;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004597
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004598 if (pVBInfo->TVInfo & NTSC1024x768) {
4599 *tempbx = 4;
Peter Huewe599801f2012-02-09 21:11:45 +01004600 if (pVBInfo->TVInfo & TVSetPALM)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004601 *tempbx = 5;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304602 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004603
Peter Huewe6896b942012-02-09 21:11:46 +01004604 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4605 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004606 if ((!(pVBInfo->VBInfo & SetInSlaveMode)) || (pVBInfo->TVInfo
4607 & TVSimuMode)) {
4608 *tempbx += 8;
4609 *tempcl += 1;
4610 }
4611 }
4612
Peter Huewe6896b942012-02-09 21:11:46 +01004613 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4614 | VB_SIS302LV | VB_XGI301C))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004615 (*tempch)++;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004616}
4617
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004618static void XGI_SetDelayComp(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004619{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304620 unsigned char tempah, tempbl, tempbh;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004621
Peter Huewe6896b942012-02-09 21:11:46 +01004622 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4623 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01004624 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304625 | SetCRT2ToTV | SetCRT2ToRAMDAC)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304626 tempbh = 0;
Peter Huewe03f76fc2012-06-14 00:21:50 +02004627 tempbl = XGI301TVDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004628
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304629 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
4630 tempbl = tempbl >> 4;
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004631 if (pVBInfo->VBInfo &
4632 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Peter Huewe03f76fc2012-06-14 00:21:50 +02004633 tempbh = XGI301LCDDelay;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004634
Peter Huewea3d675c2012-02-09 21:11:47 +01004635 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304636 tempbl = tempbh;
4637 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004638
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304639 tempbl &= 0x0F;
4640 tempbh &= 0xF0;
Aaro Koskinen58839b02011-03-13 12:26:23 +02004641 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2D);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004642
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304643 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToLCD
4644 | SetCRT2ToTV)) { /* Channel B */
4645 tempah &= 0xF0;
4646 tempah |= tempbl;
4647 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004648
Miguel Gómez3bcc2462012-07-06 12:40:53 +02004649 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4650 /* Channel A */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304651 tempah &= 0x0F;
4652 tempah |= tempbh;
4653 }
Aaro Koskinen8104e322011-03-13 12:26:22 +02004654 xgifb_reg_set(pVBInfo->Part1Port, 0x2D, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304655 }
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304656 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004657}
4658
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004659static void XGI_SetLCDCap_A(unsigned short tempcx,
4660 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004661{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304662 unsigned short temp;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004663
Aaro Koskinen58839b02011-03-13 12:26:23 +02004664 temp = xgifb_reg_get(pVBInfo->P3d4, 0x37);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004665
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304666 if (temp & LCDRGB18Bit) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004667 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004668 /* Enable Dither */
4669 (unsigned short) (0x20 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004670 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x80);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304671 } else {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004672 xgifb_reg_and_or(pVBInfo->Part1Port, 0x19, 0x0F,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304673 (unsigned short) (0x30 | (tempcx & 0x00C0)));
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004674 xgifb_reg_and_or(pVBInfo->Part1Port, 0x1A, 0x7F, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304675 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004676}
4677
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004678/* --------------------------------------------------------------------- */
4679/* Function : XGI_SetLCDCap_B */
4680/* Input : cx -> LCD Capability */
4681/* Output : */
4682/* Description : */
4683/* --------------------------------------------------------------------- */
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004684static void XGI_SetLCDCap_B(unsigned short tempcx,
4685 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004686{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304687 if (tempcx & EnableLCD24bpp) /* 24bits */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004688 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304689 (unsigned short) (((tempcx & 0x00ff) >> 6)
4690 | 0x0c));
4691 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004692 xgifb_reg_and_or(pVBInfo->Part2Port, 0x1A, 0xE0,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304693 (unsigned short) (((tempcx & 0x00ff) >> 6)
4694 | 0x18)); /* Enable Dither */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004695}
4696
Aaro Koskinen7f04ec32011-11-27 23:03:05 +02004697static void XGI_LongWait(struct vb_device_info *pVBInfo)
4698{
4699 unsigned short i;
4700
4701 i = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
4702
4703 if (!(i & 0xC0)) {
4704 for (i = 0; i < 0xFFFF; i++) {
4705 if (!(inb(pVBInfo->P3da) & 0x08))
4706 break;
4707 }
4708
4709 for (i = 0; i < 0xFFFF; i++) {
4710 if ((inb(pVBInfo->P3da) & 0x08))
4711 break;
4712 }
4713 }
4714}
4715
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004716static void SetSpectrum(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004717{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304718 unsigned short index;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004719
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304720 index = XGI_GetLCDCapPtr(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004721
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004722 /* disable down spectrum D[4] */
4723 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x8F);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304724 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004725 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x20); /* reset spectrum */
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304726 XGI_LongWait(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004727
Aaro Koskinen8104e322011-03-13 12:26:22 +02004728 xgifb_reg_set(pVBInfo->Part4Port, 0x31,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304729 pVBInfo->LCDCapList[index].Spectrum_31);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004730 xgifb_reg_set(pVBInfo->Part4Port, 0x32,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304731 pVBInfo->LCDCapList[index].Spectrum_32);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004732 xgifb_reg_set(pVBInfo->Part4Port, 0x33,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304733 pVBInfo->LCDCapList[index].Spectrum_33);
Aaro Koskinen8104e322011-03-13 12:26:22 +02004734 xgifb_reg_set(pVBInfo->Part4Port, 0x34,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304735 pVBInfo->LCDCapList[index].Spectrum_34);
4736 XGI_LongWait(pVBInfo);
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02004737 xgifb_reg_or(pVBInfo->Part4Port, 0x30, 0x40); /* enable spectrum */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004738}
4739
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004740static void XGI_SetLCDCap(struct vb_device_info *pVBInfo)
4741{
4742 unsigned short tempcx;
4743
4744 tempcx = pVBInfo->LCDCapList[XGI_GetLCDCapPtr(pVBInfo)].LCD_Capability;
4745
Peter Huewef951dd02013-02-05 00:29:47 +01004746 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV |
4747 VB_SIS302LV | VB_XGI301C)) {
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004748 if (pVBInfo->VBType &
Peter Huewe6896b942012-02-09 21:11:46 +01004749 (VB_SIS301LV | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004750 /* Set 301LV Capability */
Aaro Koskinen8104e322011-03-13 12:26:22 +02004751 xgifb_reg_set(pVBInfo->Part4Port, 0x24,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004752 (unsigned char) (tempcx & 0x1F));
4753 }
4754 /* VB Driving */
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004755 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004756 ~((EnableVBCLKDRVLOW | EnablePLLSPLOW) >> 8),
4757 (unsigned short) ((tempcx & (EnableVBCLKDRVLOW
4758 | EnablePLLSPLOW)) >> 8));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004759
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004760 if (pVBInfo->VBInfo & SetCRT2ToLCD)
4761 XGI_SetLCDCap_B(tempcx, pVBInfo);
Peter Huewea3d675c2012-02-09 21:11:47 +01004762 else if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004763 XGI_SetLCDCap_A(tempcx, pVBInfo);
4764
Peter Huewe6896b942012-02-09 21:11:46 +01004765 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004766 if (tempcx & EnableSpectrum)
4767 SetSpectrum(pVBInfo);
4768 }
4769 } else {
4770 /* LVDS,CH7017 */
4771 XGI_SetLCDCap_A(tempcx, pVBInfo);
4772 }
4773}
4774
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004775/* --------------------------------------------------------------------- */
4776/* Function : XGI_SetAntiFlicker */
4777/* Input : */
4778/* Output : */
4779/* Description : Set TV Customized Param. */
4780/* --------------------------------------------------------------------- */
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004781static void XGI_SetAntiFlicker(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004782{
Aaro Koskinen36ae0352012-04-07 01:14:08 +03004783 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004784
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304785 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004786
Peter Huewe599801f2012-02-09 21:11:45 +01004787 if (pVBInfo->TVInfo & (TVSetYPbPr525p | TVSetYPbPr750p))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304788 return;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004789
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304790 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4791 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304792 tempah = TVAntiFlickList[tempbx];
4793 tempah = tempah << 4;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004794
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004795 xgifb_reg_and_or(pVBInfo->Part2Port, 0x0A, 0x8F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004796}
4797
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004798static void XGI_SetEdgeEnhance(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004799{
Aaro Koskinen354f49f2012-04-07 01:14:09 +03004800 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004801
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304802 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004803
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304804 tempbx = XGI_GetTVPtrIndex(pVBInfo);
4805 tempbx &= 0xFE;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304806 tempah = TVEdgeList[tempbx];
4807 tempah = tempah << 5;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004808
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02004809 xgifb_reg_and_or(pVBInfo->Part2Port, 0x3A, 0x1F, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004810}
4811
Aaro Koskinen063b9c42011-03-08 22:16:13 +02004812static void XGI_SetPhaseIncr(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004813{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304814 unsigned short tempbx;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004815
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304816 unsigned char tempcl, tempch;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004817
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304818 unsigned long tempData;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004819
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304820 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
4821 tempData = TVPhaseList[tempbx];
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004822
Aaro Koskinen8104e322011-03-13 12:26:22 +02004823 xgifb_reg_set(pVBInfo->Part2Port, 0x31, (unsigned short) (tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304824 & 0x000000FF));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004825 xgifb_reg_set(pVBInfo->Part2Port, 0x32, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304826 & 0x0000FF00) >> 8));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004827 xgifb_reg_set(pVBInfo->Part2Port, 0x33, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304828 & 0x00FF0000) >> 16));
Aaro Koskinen8104e322011-03-13 12:26:22 +02004829 xgifb_reg_set(pVBInfo->Part2Port, 0x34, (unsigned short) ((tempData
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304830 & 0xFF000000) >> 24));
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004831}
4832
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004833static void XGI_SetYFilter(unsigned short ModeIdIndex,
4834 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004835{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304836 unsigned short tempbx, index;
Aaro Koskinena68292f2012-11-04 21:15:07 +02004837 unsigned char const *filterPtr;
4838 unsigned char tempcl, tempch, tempal;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004839
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304840 XGI_GetTVPtrIndex2(&tempbx, &tempcl, &tempch, pVBInfo); /* bx, cl, ch */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004841
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304842 switch (tempbx) {
4843 case 0x00:
4844 case 0x04:
4845 filterPtr = NTSCYFilter1;
4846 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004847
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304848 case 0x01:
4849 filterPtr = PALYFilter1;
4850 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004851
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304852 case 0x02:
4853 case 0x05:
4854 case 0x0D:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304855 case 0x03:
Aaro Koskinen2555e942011-08-31 21:46:06 +03004856 filterPtr = xgifb_palmn_yfilter1;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304857 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004858
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304859 case 0x08:
4860 case 0x0C:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304861 case 0x0A:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304862 case 0x0B:
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304863 case 0x09:
Aaro Koskinen80f86f82011-08-31 21:46:05 +03004864 filterPtr = xgifb_yfilter2;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304865 break;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004866
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304867 default:
4868 return;
4869 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004870
Aaro Koskinenb3979922012-11-04 21:14:52 +02004871 tempal = XGI330_EModeIDTable[ModeIdIndex].VB_ExtTVYFilterIndex;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304872 if (tempcl == 0)
4873 index = tempal * 4;
4874 else
4875 index = tempal * 7;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004876
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304877 if ((tempcl == 0) && (tempch == 1)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004878 xgifb_reg_set(pVBInfo->Part2Port, 0x35, 0);
4879 xgifb_reg_set(pVBInfo->Part2Port, 0x36, 0);
4880 xgifb_reg_set(pVBInfo->Part2Port, 0x37, 0);
4881 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304882 } else {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004883 xgifb_reg_set(pVBInfo->Part2Port, 0x35, filterPtr[index++]);
4884 xgifb_reg_set(pVBInfo->Part2Port, 0x36, filterPtr[index++]);
4885 xgifb_reg_set(pVBInfo->Part2Port, 0x37, filterPtr[index++]);
4886 xgifb_reg_set(pVBInfo->Part2Port, 0x38, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304887 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004888
Peter Huewe6896b942012-02-09 21:11:46 +01004889 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
4890 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen8104e322011-03-13 12:26:22 +02004891 xgifb_reg_set(pVBInfo->Part2Port, 0x48, filterPtr[index++]);
4892 xgifb_reg_set(pVBInfo->Part2Port, 0x49, filterPtr[index++]);
4893 xgifb_reg_set(pVBInfo->Part2Port, 0x4A, filterPtr[index++]);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304894 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004895}
4896
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004897/* --------------------------------------------------------------------- */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004898/* Function : XGI_OEM310Setting */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004899/* Input : */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004900/* Output : */
4901/* Description : Customized Param. for 301 */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004902/* --------------------------------------------------------------------- */
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004903static void XGI_OEM310Setting(unsigned short ModeIdIndex,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08004904 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004905{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004906 XGI_SetDelayComp(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004907
Peter Huewea3d675c2012-02-09 21:11:47 +01004908 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004909 XGI_SetLCDCap(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004910
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004911 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02004912 XGI_SetPhaseIncr(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03004913 XGI_SetYFilter(ModeIdIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004914 XGI_SetAntiFlicker(pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004915
Peter Huewe6896b942012-02-09 21:11:46 +01004916 if (pVBInfo->VBType & VB_SIS301)
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03004917 XGI_SetEdgeEnhance(pVBInfo);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304918 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004919}
4920
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004921/* --------------------------------------------------------------------- */
4922/* Function : XGI_SetCRT2ModeRegs */
4923/* Input : */
4924/* Output : */
4925/* Description : Origin code for crt2group */
4926/* --------------------------------------------------------------------- */
Aaro Koskinenb053af12013-07-16 23:13:28 +03004927static void XGI_SetCRT2ModeRegs(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004928{
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304929 unsigned short tempbl;
4930 short tempcl;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004931
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304932 unsigned char tempah;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004933
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304934 tempah = 0;
4935 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02004936 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x00);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304937 tempah &= ~0x10; /* BTRAMDAC */
4938 tempah |= 0x40; /* BTRAM */
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004939
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304940 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV
4941 | SetCRT2ToLCD)) {
4942 tempah = 0x40; /* BTDRAM */
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03004943 tempcl = pVBInfo->ModeType;
4944 tempcl -= ModeVGA;
4945 if (tempcl >= 0) {
4946 /* BT Color */
4947 tempah = (0x008 >> tempcl);
4948 if (tempah == 0)
4949 tempah = 1;
4950 tempah |= 0x040;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304951 }
4952 if (pVBInfo->VBInfo & SetInSlaveMode)
4953 tempah ^= 0x50; /* BTDAC */
4954 }
4955 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004956
Aaro Koskinen8104e322011-03-13 12:26:22 +02004957 xgifb_reg_set(pVBInfo->Part1Port, 0x00, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304958 tempah = 0x08;
4959 tempbl = 0xf0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004960
Miguel Gómeze123e462012-07-06 12:40:52 +02004961 if (pVBInfo->VBInfo & DisableCRT2Display)
4962 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004963
Miguel Gómeze123e462012-07-06 12:40:52 +02004964 tempah = 0x00;
4965 tempbl = 0xff;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004966
Miguel Gómeze123e462012-07-06 12:40:52 +02004967 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV |
4968 SetCRT2ToLCD | XGI_SetCRT2ToLCDA)))
4969 goto reg_and_or;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004970
Miguel Gómeze123e462012-07-06 12:40:52 +02004971 if ((pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
4972 (!(pVBInfo->VBInfo & SetSimuScanMode))) {
4973 tempbl &= 0xf7;
4974 tempah |= 0x01;
4975 goto reg_and_or;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05304976 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02004977
Miguel Gómeze123e462012-07-06 12:40:52 +02004978 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
4979 tempbl &= 0xf7;
4980 tempah |= 0x01;
4981 }
4982
4983 if (!(pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD)))
4984 goto reg_and_or;
4985
4986 tempbl &= 0xf8;
4987 tempah = 0x01;
4988
4989 if (!(pVBInfo->VBInfo & SetInSlaveMode))
4990 tempah |= 0x02;
4991
4992 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
4993 tempah = tempah ^ 0x05;
4994 if (!(pVBInfo->VBInfo & SetCRT2ToLCD))
4995 tempah = tempah ^ 0x01;
4996 }
4997
4998 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
4999 tempah |= 0x08;
5000
5001reg_and_or:
5002 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2e, tempbl, tempah);
5003
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305004 if (pVBInfo->VBInfo & (SetCRT2ToRAMDAC | SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005005 | XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305006 tempah &= (~0x08);
5007 if ((pVBInfo->ModeType == ModeVGA) && (!(pVBInfo->VBInfo
5008 & SetInSlaveMode))) {
5009 tempah |= 0x010;
5010 }
5011 tempah |= 0x080;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005012
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305013 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305014 tempah |= 0x020;
Aaro Koskinen34c13ee2012-04-07 01:14:01 +03005015 if (pVBInfo->VBInfo & DriverMode)
5016 tempah = tempah ^ 0x20;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305017 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005018
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005019 xgifb_reg_and_or(pVBInfo->Part4Port, 0x0D, ~0x0BF, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305020 tempah = 0;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005021
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305022 if (pVBInfo->LCDInfo & SetLCDDualLink)
5023 tempah |= 0x40;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005024
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305025 if (pVBInfo->VBInfo & SetCRT2ToTV) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305026 if (pVBInfo->TVInfo & RPLLDIV2XO)
5027 tempah |= 0x40;
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305028 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005029
Peter Huewe255aabd2012-02-09 21:11:44 +01005030 if ((pVBInfo->LCDResInfo == Panel_1280x1024)
5031 || (pVBInfo->LCDResInfo == Panel_1280x1024x75))
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305032 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005033
Peter Huewe255aabd2012-02-09 21:11:44 +01005034 if (pVBInfo->LCDResInfo == Panel_1280x960)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305035 tempah |= 0x80;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005036
Aaro Koskinen8104e322011-03-13 12:26:22 +02005037 xgifb_reg_set(pVBInfo->Part4Port, 0x0C, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305038 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005039
Peter Huewe6896b942012-02-09 21:11:46 +01005040 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5041 | VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305042 tempah = 0;
5043 tempbl = 0xfb;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005044
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305045 if (pVBInfo->VBInfo & SetCRT2ToDualEdge) {
5046 tempbl = 0xff;
Peter Huewea3d675c2012-02-09 21:11:47 +01005047 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305048 tempah |= 0x04; /* shampoo 0129 */
5049 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005050
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005051 xgifb_reg_and_or(pVBInfo->Part1Port, 0x13, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305052 tempah = 0x00;
5053 tempbl = 0xcf;
5054 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5055 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5056 tempah |= 0x30;
5057 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005058
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005059 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2c, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305060 tempah = 0;
5061 tempbl = 0x3f;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005062
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305063 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5064 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
5065 tempah |= 0xc0;
5066 }
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005067 xgifb_reg_and_or(pVBInfo->Part4Port, 0x21, tempbl, tempah);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305068 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005069
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305070 tempah = 0;
5071 tempbl = 0x7f;
Peter Huewea3d675c2012-02-09 21:11:47 +01005072 if (!(pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305073 tempbl = 0xff;
5074 if (!(pVBInfo->VBInfo & SetCRT2ToDualEdge))
5075 tempah |= 0x80;
5076 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005077
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005078 xgifb_reg_and_or(pVBInfo->Part4Port, 0x23, tempbl, tempah);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005079
Peter Huewe6896b942012-02-09 21:11:46 +01005080 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305081 if (pVBInfo->LCDInfo & SetLCDDualLink) {
Aaro Koskinenb9bf6e42011-03-13 12:26:24 +02005082 xgifb_reg_or(pVBInfo->Part4Port, 0x27, 0x20);
5083 xgifb_reg_or(pVBInfo->Part4Port, 0x34, 0x10);
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305084 }
5085 }
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005086}
5087
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005088
Aaro Koskinenb053af12013-07-16 23:13:28 +03005089void XGI_UnLockCRT2(struct vb_device_info *pVBInfo)
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305090{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005091 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2f, 0xFF, 0x01);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005092}
5093
Aaro Koskinenb053af12013-07-16 23:13:28 +03005094void XGI_LockCRT2(struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005095{
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005096 xgifb_reg_and_or(pVBInfo->Part1Port, 0x2F, 0xFE, 0x00);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005097}
5098
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005099unsigned short XGI_GetRatePtrCRT2(struct xgi_hw_device_info *pXGIHWDE,
5100 unsigned short ModeNo, unsigned short ModeIdIndex,
5101 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005102{
Peter Huewef2c22602013-02-03 22:54:30 +01005103 const u8 LCDARefreshIndex[] = {
5104 0x00, 0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x00 };
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005105
Peter Hueweef9a6b92013-02-03 04:08:43 +01005106 unsigned short RefreshRateTableIndex, i, index, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005107
Aaro Koskinen58839b02011-03-13 12:26:23 +02005108 index = xgifb_reg_get(pVBInfo->P3d4, 0x33);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005109 index = index >> pVBInfo->SelectCRT2Rate;
5110 index &= 0x0F;
5111
5112 if (pVBInfo->LCDInfo & LCDNonExpanding)
5113 index = 0;
5114
5115 if (index > 0)
5116 index--;
5117
5118 if (pVBInfo->SetFlag & ProgrammingCRT2) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005119 if (pVBInfo->VBInfo & (SetCRT2ToLCD | XGI_SetCRT2ToLCDA)) {
Aaro Koskinenb0b4a8a2013-05-29 23:59:04 +03005120 temp = LCDARefreshIndex[pVBInfo->LCDResInfo & 0x07];
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005121
Aaro Koskinenb0b4a8a2013-05-29 23:59:04 +03005122 if (index > temp)
5123 index = temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005124 }
5125 }
5126
Aaro Koskinenb3979922012-11-04 21:14:52 +02005127 RefreshRateTableIndex = XGI330_EModeIDTable[ModeIdIndex].REFindex;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005128 ModeNo = XGI330_RefIndex[RefreshRateTableIndex].ModeID;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005129 if (pXGIHWDE->jChipType >= XG20) { /* for XG20, XG21, XG27 */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005130 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 800) &&
5131 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 600)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005132 index++;
5133 }
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005134 /* do the similar adjustment like XGISearchCRT1Rate() */
Aaro Koskinena39325d2012-11-04 21:14:53 +02005135 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1024) &&
5136 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 768)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005137 index++;
5138 }
Aaro Koskinena39325d2012-11-04 21:14:53 +02005139 if ((XGI330_RefIndex[RefreshRateTableIndex].XRes == 1280) &&
5140 (XGI330_RefIndex[RefreshRateTableIndex].YRes == 1024)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005141 index++;
5142 }
5143 }
5144
5145 i = 0;
5146 do {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005147 if (XGI330_RefIndex[RefreshRateTableIndex + i].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005148 ModeID != ModeNo)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005149 break;
Aaro Koskinena39325d2012-11-04 21:14:53 +02005150 temp = XGI330_RefIndex[RefreshRateTableIndex + i].Ext_InfoFlag;
Peter Huewe6896b942012-02-09 21:11:46 +01005151 temp &= ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005152 if (temp < pVBInfo->ModeType)
5153 break;
5154 i++;
5155 index--;
5156
5157 } while (index != 0xFFFF);
5158 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC)) {
5159 if (pVBInfo->VBInfo & SetInSlaveMode) {
Aaro Koskinena39325d2012-11-04 21:14:53 +02005160 temp = XGI330_RefIndex[RefreshRateTableIndex + i - 1].
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005161 Ext_InfoFlag;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005162 if (temp & InterlaceMode)
5163 i++;
5164 }
5165 }
5166 i--;
5167 if ((pVBInfo->SetFlag & ProgrammingCRT2)) {
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005168 temp = XGI_AjustCRT2Rate(ModeIdIndex, RefreshRateTableIndex,
5169 &i, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005170 }
Aaro Koskinen9a0b2952011-11-27 23:03:16 +02005171 return RefreshRateTableIndex + i;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005172}
5173
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005174static void XGI_SetLCDAGroup(unsigned short ModeNo, unsigned short ModeIdIndex,
Prashant P. Shah21df8fc2010-09-03 22:12:12 +05305175 struct xgi_hw_device_info *HwDeviceExtension,
5176 struct vb_device_info *pVBInfo)
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005177{
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005178 unsigned short RefreshRateTableIndex;
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005179
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005180 pVBInfo->SetFlag |= ProgrammingCRT2;
5181 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5182 ModeIdIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005183 XGI_GetLVDSResInfo(ModeIdIndex, pVBInfo);
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03005184 XGI_GetLVDSData(ModeIdIndex, pVBInfo);
5185 XGI_ModCRT1Regs(ModeIdIndex, HwDeviceExtension, pVBInfo);
5186 XGI_SetLVDSRegs(ModeIdIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005187 XGI_SetCRT2ECLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
apatard@mandriva.comd7636e02010-05-19 10:44:14 +02005188}
5189
Aaro Koskinenfac2cc92011-11-27 23:03:13 +02005190static unsigned char XGI_SetCRT2Group301(unsigned short ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005191 struct xgi_hw_device_info *HwDeviceExtension,
5192 struct vb_device_info *pVBInfo)
5193{
Peter Huewea9e29e62013-02-03 04:08:44 +01005194 unsigned short ModeIdIndex, RefreshRateTableIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005195
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005196 pVBInfo->SetFlag |= ProgrammingCRT2;
5197 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5198 pVBInfo->SelectCRT2Rate = 4;
5199 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5200 ModeIdIndex, pVBInfo);
5201 XGI_SaveCRT2Info(ModeNo, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005202 XGI_GetCRT2ResInfo(ModeIdIndex, pVBInfo);
5203 XGI_GetCRT2Data(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005204 XGI_PreSetGroup1(ModeNo, ModeIdIndex, RefreshRateTableIndex, pVBInfo);
5205 XGI_SetGroup1(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinen88a3dfd2013-07-16 23:13:29 +03005206 XGI_SetLockRegs(ModeNo, ModeIdIndex, pVBInfo);
5207 XGI_SetGroup2(ModeNo, ModeIdIndex, pVBInfo);
5208 XGI_SetLCDRegs(ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005209 XGI_SetTap4Regs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005210 XGI_SetGroup3(ModeIdIndex, pVBInfo);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005211 XGI_SetGroup4(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005212 XGI_SetCRT2VCLK(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005213 XGI_SetGroup5(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005214 XGI_AutoThreshold(pVBInfo);
5215 return 1;
5216}
5217
5218void XGI_SenseCRT1(struct vb_device_info *pVBInfo)
5219{
5220 unsigned char CRTCData[17] = { 0x5F, 0x4F, 0x50, 0x82, 0x55, 0x81,
5221 0x0B, 0x3E, 0xE9, 0x0B, 0xDF, 0xE7, 0x04, 0x00, 0x00,
5222 0x05, 0x00 };
5223
5224 unsigned char SR01 = 0, SR1F = 0, SR07 = 0, SR06 = 0;
5225
5226 unsigned char CR17, CR63, SR31;
5227 unsigned short temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005228
5229 int i;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005230 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005231
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005232 /* to fix XG42 single LCD sense to CRT+LCD */
Aaro Koskinen8104e322011-03-13 12:26:22 +02005233 xgifb_reg_set(pVBInfo->P3d4, 0x57, 0x4A);
Peter Huewe9388ad92013-02-15 20:37:10 +01005234 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005235 pVBInfo->P3d4, 0x53) | 0x02));
5236
Peter Huewe9388ad92013-02-15 20:37:10 +01005237 SR31 = xgifb_reg_get(pVBInfo->P3c4, 0x31);
5238 CR63 = xgifb_reg_get(pVBInfo->P3d4, 0x63);
5239 SR01 = xgifb_reg_get(pVBInfo->P3c4, 0x01);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005240
Aaro Koskinen8104e322011-03-13 12:26:22 +02005241 xgifb_reg_set(pVBInfo->P3c4, 0x01, (unsigned char) (SR01 & 0xDF));
5242 xgifb_reg_set(pVBInfo->P3d4, 0x63, (unsigned char) (CR63 & 0xBF));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005243
Peter Huewe9388ad92013-02-15 20:37:10 +01005244 CR17 = xgifb_reg_get(pVBInfo->P3d4, 0x17);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005245 xgifb_reg_set(pVBInfo->P3d4, 0x17, (unsigned char) (CR17 | 0x80));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005246
Peter Huewe9388ad92013-02-15 20:37:10 +01005247 SR1F = xgifb_reg_get(pVBInfo->P3c4, 0x1F);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005248 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) (SR1F | 0x04));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005249
Peter Huewe9388ad92013-02-15 20:37:10 +01005250 SR07 = xgifb_reg_get(pVBInfo->P3c4, 0x07);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005251 xgifb_reg_set(pVBInfo->P3c4, 0x07, (unsigned char) (SR07 & 0xFB));
Peter Huewe9388ad92013-02-15 20:37:10 +01005252 SR06 = xgifb_reg_get(pVBInfo->P3c4, 0x06);
Aaro Koskinen8104e322011-03-13 12:26:22 +02005253 xgifb_reg_set(pVBInfo->P3c4, 0x06, (unsigned char) (SR06 & 0xC3));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005254
Aaro Koskinen8104e322011-03-13 12:26:22 +02005255 xgifb_reg_set(pVBInfo->P3d4, 0x11, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005256
5257 for (i = 0; i < 8; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005258 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) i, CRTCData[i]);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005259
5260 for (i = 8; i < 11; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005261 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 8),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005262 CRTCData[i]);
5263
5264 for (i = 11; i < 13; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005265 xgifb_reg_set(pVBInfo->P3d4, (unsigned short) (i + 4),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005266 CRTCData[i]);
5267
5268 for (i = 13; i < 16; i++)
Aaro Koskinen8104e322011-03-13 12:26:22 +02005269 xgifb_reg_set(pVBInfo->P3c4, (unsigned short) (i - 3),
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005270 CRTCData[i]);
5271
Aaro Koskinen8104e322011-03-13 12:26:22 +02005272 xgifb_reg_set(pVBInfo->P3c4, 0x0E, (unsigned char) (CRTCData[16]
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005273 & 0xE0));
5274
Aaro Koskinen8104e322011-03-13 12:26:22 +02005275 xgifb_reg_set(pVBInfo->P3c4, 0x31, 0x00);
5276 xgifb_reg_set(pVBInfo->P3c4, 0x2B, 0x1B);
5277 xgifb_reg_set(pVBInfo->P3c4, 0x2C, 0xE1);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005278
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005279 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005280
Peter Huewe771f3ee2013-02-15 20:37:13 +01005281 for (i = 0; i < 256 * 3; i++) {
5282 outb(0x0F, (pVBInfo->P3c8 + 1)); /* DAC_TEST_PARMS */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005283 }
5284
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005285 mdelay(1);
5286
5287 XGI_WaitDisply(pVBInfo);
Aaro Koskinend8ad0a62011-03-13 12:26:18 +02005288 temp = inb(pVBInfo->P3c2);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005289
5290 if (temp & 0x10)
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005291 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005292 else
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005293 xgifb_reg_and_or(pVBInfo->P3d4, 0x32, 0xDF, 0x00);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005294
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005295 /* avoid display something, set BLACK DAC if not restore DAC */
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005296 outb(0x00, pVBInfo->P3c8);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005297
Peter Huewe771f3ee2013-02-15 20:37:13 +01005298 for (i = 0; i < 256 * 3; i++) {
Aaro Koskinenefdf4ee2011-03-13 12:26:20 +02005299 outb(0, (pVBInfo->P3c8 + 1));
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005300 }
5301
Aaro Koskinen8104e322011-03-13 12:26:22 +02005302 xgifb_reg_set(pVBInfo->P3c4, 0x01, SR01);
5303 xgifb_reg_set(pVBInfo->P3d4, 0x63, CR63);
5304 xgifb_reg_set(pVBInfo->P3c4, 0x31, SR31);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005305
Peter Huewe9388ad92013-02-15 20:37:10 +01005306 xgifb_reg_set(pVBInfo->P3d4, 0x53, (xgifb_reg_get(
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005307 pVBInfo->P3d4, 0x53) & 0xFD));
Aaro Koskinen8104e322011-03-13 12:26:22 +02005308 xgifb_reg_set(pVBInfo->P3c4, 0x1F, (unsigned char) SR1F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005309}
5310
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005311static void XGI_EnableBridge(struct xgifb_video_info *xgifb_info,
5312 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005313 struct vb_device_info *pVBInfo)
5314{
Aaro Koskinenfd0ad472011-03-13 12:26:09 +02005315 unsigned short tempah;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005316
Peter Huewe6896b942012-02-09 21:11:46 +01005317 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5318 | VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinena2526d12013-05-29 23:59:10 +03005319 if (pVBInfo->VBInfo & SetCRT2ToDualEdge)
Aaro Koskinend1724632013-05-29 23:59:09 +03005320 /* Power on */
5321 xgifb_reg_set(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005322
Aaro Koskinenb8e34b32013-05-29 23:59:08 +03005323 if (pVBInfo->VBInfo & (SetCRT2ToLCD | SetCRT2ToTV |
5324 SetCRT2ToRAMDAC)) {
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005325 tempah = xgifb_reg_get(pVBInfo->P3c4, 0x32);
5326 tempah &= 0xDF;
5327 if (pVBInfo->VBInfo & SetInSlaveMode) {
5328 if (!(pVBInfo->VBInfo & SetCRT2ToRAMDAC))
5329 tempah |= 0x20;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005330 }
Aaro Koskinenc4f9c312013-05-29 23:59:07 +03005331 xgifb_reg_set(pVBInfo->P3c4, 0x32, tempah);
5332 xgifb_reg_or(pVBInfo->P3c4, 0x1E, 0x20);
5333
5334 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
5335
5336 if (!(tempah & 0x80))
5337 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
5338 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005339 }
5340
Aaro Koskinena2526d12013-05-29 23:59:10 +03005341 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
Aaro Koskinenec9e5d32011-03-13 12:26:25 +02005342 xgifb_reg_and_or(pVBInfo->Part2Port, 0x00, ~0xE0,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005343 0x20); /* shampoo 0129 */
Peter Huewe6896b942012-02-09 21:11:46 +01005344 if (pVBInfo->VBType & (VB_SIS302LV | VB_XGI301C)) {
Aaro Koskinen056b5402013-05-29 23:59:11 +03005345 if (pVBInfo->VBInfo &
5346 (SetCRT2ToLCD | XGI_SetCRT2ToLCDA))
5347 /* LVDS PLL power on */
5348 xgifb_reg_and(pVBInfo->Part4Port, 0x2A,
5349 0x7F);
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005350 /* LVDS Driver power on */
5351 xgifb_reg_and(pVBInfo->Part4Port, 0x30, 0x7F);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005352 }
5353 }
5354
5355 tempah = 0x00;
5356
5357 if (!(pVBInfo->VBInfo & DisableCRT2Display)) {
5358 tempah = 0xc0;
5359
Miguel Gómezb1bf9982012-07-06 12:40:51 +02005360 if (!(pVBInfo->VBInfo & SetSimuScanMode) &&
5361 (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) &&
5362 (pVBInfo->VBInfo & SetCRT2ToDualEdge)) {
5363 tempah = tempah & 0x40;
5364 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA)
5365 tempah = tempah ^ 0xC0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005366 }
5367 }
5368
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005369 /* EnablePart4_1F */
5370 xgifb_reg_or(pVBInfo->Part4Port, 0x1F, tempah);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005371
Aaro Koskinenb053af12013-07-16 23:13:28 +03005372 XGI_DisableGatingCRT(pVBInfo);
Aaro Koskinend1724632013-05-29 23:59:09 +03005373 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005374 } /* 301 */
5375 else { /* LVDS */
5376 if (pVBInfo->VBInfo & (SetCRT2ToTV | SetCRT2ToLCD
Peter Huewea3d675c2012-02-09 21:11:47 +01005377 | XGI_SetCRT2ToLCDA))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005378 /* enable CRT2 */
5379 xgifb_reg_or(pVBInfo->Part1Port, 0x1E, 0x20);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005380
Peter Huewe9388ad92013-02-15 20:37:10 +01005381 tempah = xgifb_reg_get(pVBInfo->Part1Port, 0x2E);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005382 if (!(tempah & 0x80))
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005383 xgifb_reg_or(pVBInfo->Part1Port, 0x2E, 0x80);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005384
Aaro Koskinendc505562011-03-13 12:26:26 +02005385 xgifb_reg_and(pVBInfo->Part1Port, 0x00, 0x7F);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005386 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005387 } /* End of VB */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005388}
5389
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005390static void XGI_SetCRT1Group(struct xgifb_video_info *xgifb_info,
5391 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005392 unsigned short ModeNo, unsigned short ModeIdIndex,
5393 struct vb_device_info *pVBInfo)
5394{
Aaro Koskinena1579612012-04-07 01:14:05 +03005395 unsigned short RefreshRateTableIndex, temp;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005396
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005397 XGI_SetSeqRegs(pVBInfo);
Aaro Koskinen3625c9a2012-11-04 21:14:51 +02005398 outb(XGI330_StandTable.MISC, pVBInfo->P3c2);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005399 XGI_SetCRTCRegs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005400 XGI_SetATTRegs(ModeIdIndex, pVBInfo);
Aaro Koskinena1579612012-04-07 01:14:05 +03005401 XGI_SetGRCRegs(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005402 XGI_ClearExt1Regs(pVBInfo);
5403
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005404 if (HwDeviceExtension->jChipType == XG27) {
5405 if (pVBInfo->IF_DEF_LVDS == 0)
5406 XGI_SetDefaultVCLK(pVBInfo);
5407 }
5408
5409 temp = ~ProgrammingCRT2;
5410 pVBInfo->SetFlag &= temp;
5411 pVBInfo->SelectCRT2Rate = 0;
5412
Peter Huewe6896b942012-02-09 21:11:46 +01005413 if (pVBInfo->VBType & (VB_SIS301B | VB_SIS302B | VB_SIS301LV
5414 | VB_SIS302LV | VB_XGI301C)) {
Peter Huewea3d675c2012-02-09 21:11:47 +01005415 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005416 | SetInSlaveMode)) {
5417 pVBInfo->SetFlag |= ProgrammingCRT2;
5418 }
5419 }
5420
5421 RefreshRateTableIndex = XGI_GetRatePtrCRT2(HwDeviceExtension, ModeNo,
5422 ModeIdIndex, pVBInfo);
5423 if (RefreshRateTableIndex != 0xFFFF) {
5424 XGI_SetSync(RefreshRateTableIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005425 XGI_SetCRT1CRTC(ModeIdIndex, RefreshRateTableIndex,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005426 pVBInfo, HwDeviceExtension);
Aaro Koskinenb053af12013-07-16 23:13:28 +03005427 XGI_SetCRT1DE(ModeIdIndex, RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005428 XGI_SetCRT1Offset(ModeNo, ModeIdIndex, RefreshRateTableIndex,
5429 HwDeviceExtension, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005430 XGI_SetCRT1VCLK(ModeIdIndex, HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005431 RefreshRateTableIndex, pVBInfo);
5432 }
5433
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005434 if (HwDeviceExtension->jChipType >= XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005435 temp = xgifb_reg_get(pVBInfo->P3d4, 0x38);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005436 if (temp & 0xA0) {
5437
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005438 if (HwDeviceExtension->jChipType == XG27)
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005439 XGI_SetXG27CRTC(RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005440 else
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005441 XGI_SetXG21CRTC(RefreshRateTableIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005442
5443 XGI_UpdateXG21CRTC(ModeNo, pVBInfo,
5444 RefreshRateTableIndex);
5445
Aaro Koskinen105d8d02011-08-31 21:46:00 +03005446 xgifb_set_lcd(HwDeviceExtension->jChipType,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005447 pVBInfo, RefreshRateTableIndex);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005448
Aaro Koskinen64db29f2011-08-31 21:46:01 +03005449 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005450 xgifb_set_lvds(xgifb_info,
5451 HwDeviceExtension->jChipType,
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005452 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005453 }
5454 }
5455
5456 pVBInfo->SetFlag &= (~ProgrammingCRT2);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005457 XGI_SetCRT1FIFO(HwDeviceExtension, pVBInfo);
5458 XGI_SetCRT1ModeRegs(HwDeviceExtension, ModeIdIndex,
5459 RefreshRateTableIndex, pVBInfo);
Aaro Koskinen6b6e6a32013-07-16 23:13:27 +03005460 XGI_LoadDAC(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005461}
5462
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005463unsigned char XGISetModeNew(struct xgifb_video_info *xgifb_info,
5464 struct xgi_hw_device_info *HwDeviceExtension,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005465 unsigned short ModeNo)
5466{
5467 unsigned short ModeIdIndex;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005468 struct vb_device_info VBINF;
5469 struct vb_device_info *pVBInfo = &VBINF;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005470 pVBInfo->IF_DEF_LVDS = 0;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005471
Aaro Koskinenee768752013-05-29 23:59:16 +03005472 if (HwDeviceExtension->jChipType >= XG20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005473 pVBInfo->VBType = 0; /*set VBType default 0*/
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005474
Aaro Koskinen56810a92013-01-21 02:57:47 +02005475 XGIRegInit(pVBInfo, xgifb_info->vga_base);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005476
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005477 /* for x86 Linux, XG21 LVDS */
5478 if (HwDeviceExtension->jChipType == XG21) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005479 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005480 pVBInfo->IF_DEF_LVDS = 1;
5481 }
5482 if (HwDeviceExtension->jChipType == XG27) {
Aaro Koskinen58839b02011-03-13 12:26:23 +02005483 if ((xgifb_reg_get(pVBInfo->P3d4, 0x38) & 0xE0) == 0xC0) {
5484 if (xgifb_reg_get(pVBInfo->P3d4, 0x30) & 0x20)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005485 pVBInfo->IF_DEF_LVDS = 1;
5486 }
5487 }
5488
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005489 InitTo330Pointer(HwDeviceExtension->jChipType, pVBInfo);
Aaro Koskinenef497f42011-11-27 23:03:21 +02005490 if (ModeNo & 0x80)
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005491 ModeNo = ModeNo & 0x7F;
Aaro Koskinen8104e322011-03-13 12:26:22 +02005492 xgifb_reg_set(pVBInfo->P3c4, 0x05, 0x86);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005493
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005494 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinenb053af12013-07-16 23:13:28 +03005495 XGI_UnLockCRT2(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005496
5497 XGI_SearchModeID(ModeNo, &ModeIdIndex, pVBInfo);
5498
Miguel Gómez949eb0a2012-07-06 12:40:36 +02005499 if (HwDeviceExtension->jChipType < XG20) {
Aaro Koskinenb053af12013-07-16 23:13:28 +03005500 XGI_GetVBInfo(ModeIdIndex, pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005501 XGI_GetTVInfo(ModeIdIndex, pVBInfo);
5502 XGI_GetLCDInfo(ModeIdIndex, pVBInfo);
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005503 XGI_DisableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005504
Peter Huewee44adfd2013-02-03 22:54:39 +01005505 if (pVBInfo->VBInfo & (SetSimuScanMode | XGI_SetCRT2ToLCDA) ||
5506 (!(pVBInfo->VBInfo & SwitchCRT2))) {
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005507 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005508 ModeIdIndex, pVBInfo);
5509
Peter Huewea3d675c2012-02-09 21:11:47 +01005510 if (pVBInfo->VBInfo & XGI_SetCRT2ToLCDA) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005511 XGI_SetLCDAGroup(ModeNo, ModeIdIndex,
5512 HwDeviceExtension, pVBInfo);
5513 }
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005514 }
5515
Peter Huewe6896b942012-02-09 21:11:46 +01005516 if (pVBInfo->VBInfo & (SetSimuScanMode | SwitchCRT2)) {
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005517 switch (HwDeviceExtension->ujVBChipID) {
Peter Huewee44adfd2013-02-03 22:54:39 +01005518 case VB_CHIP_301: /* fall through */
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005519 case VB_CHIP_302:
5520 XGI_SetCRT2Group301(ModeNo, HwDeviceExtension,
5521 pVBInfo); /*add for CRT2 */
5522 break;
5523
5524 default:
5525 break;
5526 }
5527 }
5528
Aaro Koskinenb053af12013-07-16 23:13:28 +03005529 XGI_SetCRT2ModeRegs(pVBInfo);
Aaro Koskinen3d05f66f2013-07-16 23:13:26 +03005530 XGI_OEM310Setting(ModeIdIndex, pVBInfo); /*0212*/
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005531 XGI_EnableBridge(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005532 } /* !XG20 */
5533 else {
5534 if (pVBInfo->IF_DEF_LVDS == 1)
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005535 if (!XGI_XG21CheckLVDSMode(xgifb_info, ModeNo,
Kenji Toyama1d7f6562011-04-23 19:36:49 +08005536 ModeIdIndex,
5537 pVBInfo))
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005538 return 0;
5539
Aaro Koskinenb3979922012-11-04 21:14:52 +02005540 pVBInfo->ModeType = XGI330_EModeIDTable[ModeIdIndex].
Peter Huewe6896b942012-02-09 21:11:46 +01005541 Ext_ModeFlag & ModeTypeMask;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005542
5543 pVBInfo->SetFlag = 0;
Aaro Koskinen83f76a92011-08-31 21:45:58 +03005544 pVBInfo->VBInfo = DisableCRT2Display;
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005545
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005546 XGI_DisplayOff(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005547
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005548 XGI_SetCRT1Group(xgifb_info, HwDeviceExtension, ModeNo,
5549 ModeIdIndex, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005550
Aaro Koskinenfab04b92011-12-06 00:10:45 +02005551 XGI_DisplayOn(xgifb_info, HwDeviceExtension, pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005552 }
5553
Aaro Koskinenb053af12013-07-16 23:13:28 +03005554 XGI_UpdateModeInfo(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005555
Miguel Gómez3bcc2462012-07-06 12:40:53 +02005556 if (HwDeviceExtension->jChipType < XG20)
Aaro Koskinenb053af12013-07-16 23:13:28 +03005557 XGI_LockCRT2(pVBInfo);
Aaro Koskinencc1e2392011-03-13 12:26:07 +02005558
5559 return 1;
5560}